296 lines
11 KiB
Lua
296 lines
11 KiB
Lua
-- Wood and Seeds Gather: the settings window. /trees opens and closes it.
|
|
-- Lua 5.0 / client 1.12: no '#', no '%' operator, no string methods with ':'.
|
|
|
|
local ADDON = WoodAndSeedsGather
|
|
local NAME = "WoodAndSeedsGatherOptions"
|
|
local panel, survivalText
|
|
local syncing = false
|
|
local checks, sliders = {}, {}
|
|
local count = 0
|
|
-- "Start a bar" row: which seed and how many planters
|
|
local pickKey, pickCount = "berry", 1
|
|
local pickButton, pickMenu, pickCountText
|
|
|
|
local function S() return WoodAndSeedsGatherDB end
|
|
|
|
-- after any change: redraw the pins, the map boxes and the timer bars
|
|
local function Changed()
|
|
if ADDON.Refresh then ADDON.Refresh() end
|
|
if ADDON.TimerRedraw then ADDON.TimerRedraw() end
|
|
end
|
|
|
|
local function Header(text, x, y)
|
|
local fs = panel:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
|
fs:SetPoint("TOPLEFT", panel, "TOPLEFT", x, y)
|
|
fs:SetText(text)
|
|
end
|
|
|
|
local function Tip(frame, title, text)
|
|
frame:SetScript("OnEnter", function()
|
|
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
|
|
GameTooltip:AddLine(title)
|
|
GameTooltip:AddLine(text, 1, 1, 1, 1)
|
|
GameTooltip:Show()
|
|
end)
|
|
frame:SetScript("OnLeave", function() GameTooltip:Hide() end)
|
|
end
|
|
|
|
local function Check(label, x, y, get, set, tip)
|
|
count = count + 1
|
|
local name = NAME .. "Check" .. count
|
|
local b = CreateFrame("CheckButton", name, panel, "UICheckButtonTemplate")
|
|
b:SetWidth(24)
|
|
b:SetHeight(24)
|
|
b:SetPoint("TOPLEFT", panel, "TOPLEFT", x, y)
|
|
getglobal(name .. "Text"):SetText(label)
|
|
b.get = get
|
|
b:SetScript("OnClick", function()
|
|
set(this:GetChecked() and true or false)
|
|
Changed()
|
|
end)
|
|
if tip then Tip(b, label, tip) end
|
|
table.insert(checks, b)
|
|
return b
|
|
end
|
|
|
|
-- a slider built by hand (same look as the game's options sliders)
|
|
local function Slider(label, x, y, lo, hi, get, set)
|
|
count = count + 1
|
|
local s = CreateFrame("Slider", NAME .. "Slider" .. count, panel)
|
|
s:SetOrientation("HORIZONTAL")
|
|
s:SetWidth(200)
|
|
s:SetHeight(17)
|
|
s:SetPoint("TOPLEFT", panel, "TOPLEFT", x, y)
|
|
s:EnableMouse(true)
|
|
s:SetBackdrop({
|
|
bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
|
|
edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
|
|
tile = true, tileSize = 8, edgeSize = 8,
|
|
insets = { left = 3, right = 3, top = 6, bottom = 6 },
|
|
})
|
|
s:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
|
|
s:SetMinMaxValues(lo, hi)
|
|
s:SetValueStep(1)
|
|
local text = s:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
|
|
text:SetPoint("BOTTOM", s, "TOP", 0, 2)
|
|
local low = s:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
|
|
low:SetPoint("TOPLEFT", s, "BOTTOMLEFT", 2, 3)
|
|
low:SetText(lo)
|
|
local high = s:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
|
|
high:SetPoint("TOPRIGHT", s, "BOTTOMRIGHT", -2, 3)
|
|
high:SetText(hi)
|
|
s.label, s.text, s.get = label, text, get
|
|
s:SetScript("OnValueChanged", function()
|
|
local v = math.floor(this:GetValue() + 0.5)
|
|
this.text:SetText(this.label .. ": " .. v)
|
|
if not syncing then
|
|
set(v)
|
|
Changed()
|
|
end
|
|
end)
|
|
table.insert(sliders, s)
|
|
return s
|
|
end
|
|
|
|
local function Button(text, x, y, w, func, tip)
|
|
count = count + 1
|
|
local b = CreateFrame("Button", NAME .. "Button" .. count, panel, "UIPanelButtonTemplate")
|
|
b:SetWidth(w)
|
|
b:SetHeight(22)
|
|
b:SetPoint("TOPLEFT", panel, "TOPLEFT", x, y)
|
|
b:SetText(text)
|
|
b:SetScript("OnClick", func)
|
|
if tip then Tip(b, text, tip) end
|
|
return b
|
|
end
|
|
|
|
local function TypeLabel(t)
|
|
local color = string.format("|cff%02x%02x%02x", t.r * 255, t.g * 255, t.b * 255)
|
|
if t.skill then return color .. t.name .. "|r (" .. t.skill .. ")" end
|
|
if t.vendor then return color .. t.seed .. "|r (vendor)" end
|
|
return color .. t.seed .. "|r"
|
|
end
|
|
|
|
local function TypeCheck(i, x, y)
|
|
return Check(TypeLabel(ADDON.TYPES[i]), x, y,
|
|
function() return S().types[i] end,
|
|
function(v) S().types[i] = v end)
|
|
end
|
|
|
|
local function PickName(key)
|
|
local labels = ADDON.TimerLabels
|
|
if labels and labels[key] then return labels[key] end
|
|
return key
|
|
end
|
|
|
|
local function ShowPick()
|
|
if pickButton then pickButton:SetText(PickName(pickKey)) end
|
|
if pickCountText then pickCountText:SetText(pickCount) end
|
|
end
|
|
|
|
-- the list the seed button opens: every seed type, in the same order as the tick boxes
|
|
local function PickMenuInit()
|
|
local nTrees = ADDON.NUM_TREES or 6
|
|
for i = nTrees + 1, table.getn(ADDON.TYPES) do
|
|
local key = ADDON.TYPES[i].key
|
|
UIDropDownMenu_AddButton({
|
|
text = PickName(key),
|
|
checked = (key == pickKey) and 1 or nil,
|
|
func = function()
|
|
pickKey = key
|
|
ShowPick()
|
|
end,
|
|
})
|
|
end
|
|
end
|
|
|
|
local function StartRow(x, y)
|
|
Header("Start a bar by hand", x, y)
|
|
pickMenu = CreateFrame("Frame", NAME .. "PickMenu", UIParent, "UIDropDownMenuTemplate")
|
|
UIDropDownMenu_Initialize(pickMenu, PickMenuInit, "MENU")
|
|
pickButton = Button(PickName(pickKey), x - 2, y - 18, 112, function()
|
|
ToggleDropDownMenu(1, nil, pickMenu, "cursor")
|
|
end, "Click to pick the seed you planted.")
|
|
Button("-", x + 114, y - 18, 24, function()
|
|
if pickCount > 1 then pickCount = pickCount - 1 end
|
|
ShowPick()
|
|
end)
|
|
pickCountText = panel:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
|
|
pickCountText:SetPoint("TOP", panel, "TOPLEFT", x + 152, y - 22)
|
|
Button("+", x + 166, y - 18, 24, function()
|
|
if pickCount < 20 then pickCount = pickCount + 1 end
|
|
ShowPick()
|
|
end)
|
|
Button("Start", x + 192, y - 18, 52, function()
|
|
if ADDON.TimerStart then ADDON.TimerStart(pickKey, pickCount) end
|
|
end, "Starts a timer bar for each of this many planters, as if you just planted them. Use it if the timer missed your planting.")
|
|
ShowPick()
|
|
end
|
|
|
|
-- read the settings into the window
|
|
local function Sync()
|
|
if not panel then return end
|
|
syncing = true
|
|
for _, b in ipairs(checks) do
|
|
b:SetChecked(b.get() and 1 or nil)
|
|
end
|
|
for _, s in ipairs(sliders) do
|
|
local v = s.get()
|
|
s:SetValue(v)
|
|
s.text:SetText(s.label .. ": " .. v)
|
|
end
|
|
syncing = false
|
|
local skill = ADDON.Survival and ADDON.Survival()
|
|
if skill then
|
|
local color = "|cffff5050"
|
|
if skill >= 75 then color = "|cff40ff40" end
|
|
survivalText:SetText("Your Survival skill: " .. color .. skill .. "|r (planters need 75)")
|
|
else
|
|
survivalText:SetText("This character has no Survival skill yet")
|
|
end
|
|
end
|
|
|
|
local function Build()
|
|
panel = CreateFrame("Frame", NAME, UIParent)
|
|
panel:SetWidth(520)
|
|
panel:SetHeight(520)
|
|
panel:SetPoint("CENTER", UIParent, "CENTER", 0, 30)
|
|
panel:SetFrameStrata("DIALOG")
|
|
panel:SetBackdrop({
|
|
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
|
|
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
|
|
tile = true, tileSize = 32, edgeSize = 32,
|
|
insets = { left = 11, right = 12, top = 12, bottom = 11 },
|
|
})
|
|
panel:EnableMouse(true)
|
|
panel:SetMovable(true)
|
|
panel:RegisterForDrag("LeftButton")
|
|
-- moving only: no GetPoint afterwards (it can crash the 1.12 client right after a move)
|
|
panel:SetScript("OnDragStart", function() this:StartMoving() end)
|
|
panel:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
|
|
if panel.SetClampedToScreen then panel:SetClampedToScreen(true) end
|
|
table.insert(UISpecialFrames, NAME) -- Escape closes it
|
|
|
|
local header = panel:CreateTexture(nil, "ARTWORK")
|
|
header:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header")
|
|
header:SetWidth(300)
|
|
header:SetHeight(64)
|
|
header:SetPoint("TOP", panel, "TOP", 0, 12)
|
|
local title = panel:CreateFontString(nil, "OVERLAY", "GameFontNormal")
|
|
title:SetPoint("TOP", panel, "TOP", 0, -2)
|
|
title:SetText("Wood and Seeds Gather")
|
|
local close = CreateFrame("Button", NAME .. "Close", panel, "UIPanelCloseButton")
|
|
close:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -6, -6)
|
|
|
|
-- left column: map pins and tree types
|
|
local L, R = 22, 272
|
|
Header("Map pins", L, -32)
|
|
Check("Show trees", L - 2, -50, function() return S().trees end, function(v) S().trees = v end)
|
|
Check("Show seeds", L - 2, -72, function() return S().seeds end, function(v) S().seeds = v end)
|
|
Check("Show on the world map", L - 2, -94, function() return S().worldmap end, function(v) S().worldmap = v end)
|
|
Check("Show on the minimap", L - 2, -116, function() return S().minimap end, function(v) S().minimap = v end)
|
|
Check("Only trees I can chop", L - 2, -138, function() return S().onlyUsable end,
|
|
function(v) S().onlyUsable = v end, "Hide trees that need more Survival skill than you have.")
|
|
Slider("World map pin size", L + 4, -186, 8, 24, function() return S().size end, function(v) S().size = v end)
|
|
Slider("Minimap pin size", L + 4, -232, 6, 20, function() return S().minisize end, function(v) S().minisize = v end)
|
|
Header("Tree types", L, -268)
|
|
local nTrees = ADDON.NUM_TREES or 6
|
|
for i = 1, nTrees do
|
|
TypeCheck(i, L - 2, -286 - (i - 1) * 22)
|
|
end
|
|
StartRow(L, -430)
|
|
|
|
-- right column: seed types and the planter timer
|
|
Header("Seed types", R, -32)
|
|
local total = table.getn(ADDON.TYPES)
|
|
for i = nTrees + 1, total do
|
|
TypeCheck(i, R - 2, -50 - (i - nTrees - 1) * 22)
|
|
end
|
|
Header("Planter timer", R, -236)
|
|
Check("Planter timer", R - 2, -254, function() return S().timer end, function(v) S().timer = v end,
|
|
"A bar at the top of your screen counts down each planter stage and chimes when soil or water is due.")
|
|
Check("Chime when soil or water is due", R - 2, -276, function() return S().timerSound end,
|
|
function(v) S().timerSound = v end)
|
|
Check("Remind every 2 minutes", R - 2, -298, function() return S().timerRepeat end,
|
|
function(v) S().timerRepeat = v end, "Keep chiming every 2 minutes until you do the step. Plants don't spoil if you're late.")
|
|
Check("Lock the timer bars", R - 2, -320, function() return S().timerLock end,
|
|
function(v) S().timerLock = v end, "Stop the bars being dragged.")
|
|
Slider("Minutes per stage", R + 4, -368, 1, 30, function() return S().timerMinutes or 9 end,
|
|
function(v) S().timerMinutes = v end)
|
|
Button("Test timer", R - 2, -410, 74, function() if ADDON.TimerTest then ADDON.TimerTest() end end,
|
|
"Shows two test bars that chime together in 8 seconds.")
|
|
Button("Clear bars", R + 74, -410, 74, function() if ADDON.TimerClear then ADDON.TimerClear() end end,
|
|
"Removes all the planter timer bars.")
|
|
Button("Reset spot", R + 150, -410, 74, function() if ADDON.TimerReset then ADDON.TimerReset() end end,
|
|
"Moves the timer bars back to the top middle of the screen.")
|
|
local note = panel:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
|
|
note:SetPoint("TOPLEFT", panel, "TOPLEFT", R, -442)
|
|
note:SetWidth(230)
|
|
note:SetJustifyH("LEFT")
|
|
note:SetText("Each planter gets its own bar. Left-click a bar when you've done its step, right-click it for more.")
|
|
|
|
survivalText = panel:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
|
|
survivalText:SetPoint("BOTTOMLEFT", panel, "BOTTOMLEFT", L, 18)
|
|
local hint = panel:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
|
|
hint:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -22, 18)
|
|
hint:SetText("/trees help: chat commands")
|
|
|
|
panel:SetScript("OnShow", Sync)
|
|
panel:Hide()
|
|
end
|
|
|
|
function ADDON.ToggleOptions()
|
|
if not WoodAndSeedsGatherDB then return end
|
|
if not panel then Build() end
|
|
if panel:IsVisible() then
|
|
panel:Hide()
|
|
else
|
|
panel:Show()
|
|
end
|
|
end
|
|
|
|
-- keep the window right when a slash command changes something while it's open
|
|
function ADDON.SyncOptions()
|
|
if panel and panel:IsVisible() then Sync() end
|
|
end
|