-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.lua
More file actions
263 lines (228 loc) · 9.21 KB
/
Copy pathConfig.lua
File metadata and controls
263 lines (228 loc) · 9.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
local _, Addon = ...
local configFrame = nil
local progressionDropdownContainer = nil
local counterDropdownContainer = nil
local function ResolveDropdownOptions(options)
if type(options) == "function" then
return options()
end
return options
end
local function CreateCheckbox(parent, label, dbKey, yOffset)
local checkbox = CreateFrame("CheckButton", nil, parent, "InterfaceOptionsCheckButtonTemplate")
checkbox.Text:SetText(label)
checkbox.Text:SetFontObject("GameFontNormal")
checkbox:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, yOffset)
checkbox:SetChecked(Addon:GetSetting(dbKey))
checkbox:SetScript("OnClick", function(self)
Addon:SetSetting(dbKey, self:GetChecked())
end)
return checkbox
end
local function CreateSlider(parent, label, dbKey, minVal, maxVal, step, yOffset, formatValue)
local container = CreateFrame("Frame", nil, parent)
container:SetPoint("TOPLEFT", 0, yOffset)
container:SetPoint("TOPRIGHT", 0, yOffset)
container:SetHeight(32)
local labelText = container:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
labelText:SetPoint("LEFT", 0, 0)
labelText:SetWidth(140)
labelText:SetJustifyH("LEFT")
labelText:SetText(label)
local currentValue = Addon:GetSetting(dbKey)
if type(currentValue) ~= "number" then
currentValue = minVal
end
local sliderFrame = CreateFrame("Frame", nil, container, "MinimalSliderWithSteppersTemplate")
sliderFrame:SetPoint("LEFT", labelText, "RIGHT", 8, 0)
sliderFrame:SetPoint("RIGHT", -40, 0)
sliderFrame:SetHeight(16)
local steps = math.floor((maxVal - minVal) / step + 0.5)
local formatter = CreateMinimalSliderFormatter(
MinimalSliderWithSteppersMixin.Label.Right,
function(value)
if formatValue then
return formatValue(value)
end
if step < 1 then
return string.format("%.1f", value)
end
return tostring(math.floor(value + 0.5))
end
)
sliderFrame.initInProgress = true
sliderFrame:Init(currentValue, minVal, maxVal, steps, {
[MinimalSliderWithSteppersMixin.Label.Right] = formatter,
})
sliderFrame.initInProgress = false
if sliderFrame.MinText then sliderFrame.MinText:Hide() end
if sliderFrame.MaxText then sliderFrame.MaxText:Hide() end
if sliderFrame.Slider then
sliderFrame.Slider:HookScript("OnValueChanged", function(_, value)
if sliderFrame.initInProgress then
return
end
value = math.floor(value / step + 0.5) * step
Addon:SetSetting(dbKey, value)
end)
end
return container
end
local function GetDropdownLabel(options, value)
options = ResolveDropdownOptions(options)
for _, option in ipairs(options) do
if option.value == value then
return option.label
end
end
return options[1] and options[1].label or ""
end
local function CreateDropdown(parent, label, dbKey, options, yOffset)
local container = CreateFrame("Frame", nil, parent)
container:SetPoint("TOPLEFT", 0, yOffset)
container:SetPoint("TOPRIGHT", 0, yOffset)
container:SetHeight(52)
local labelText = container:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
labelText:SetPoint("TOPLEFT", 0, 0)
labelText:SetText(label)
local dropdown = CreateFrame("Frame", nil, container, "UIDropDownMenuTemplate")
dropdown:SetPoint("TOPLEFT", labelText, "BOTTOMLEFT", -16, -6)
UIDropDownMenu_SetWidth(dropdown, 160)
UIDropDownMenu_SetText(dropdown, GetDropdownLabel(options, Addon:GetSetting(dbKey)))
container.RefreshText = function()
UIDropDownMenu_SetText(dropdown, GetDropdownLabel(options, Addon:GetSetting(dbKey)))
end
UIDropDownMenu_Initialize(dropdown, function(self, level)
for _, option in ipairs(ResolveDropdownOptions(options)) do
local optionValue = option.value
local optionLabel = option.label
local info = UIDropDownMenu_CreateInfo()
info.text = optionLabel
info.value = optionValue
info.checked = Addon:GetSetting(dbKey) == optionValue
info.func = function()
Addon:SetSetting(dbKey, optionValue)
UIDropDownMenu_SetText(dropdown, optionLabel)
if dbKey == "orientation" and progressionDropdownContainer and progressionDropdownContainer.RefreshText then
progressionDropdownContainer:RefreshText()
end
if dbKey == "orientation" and counterDropdownContainer and counterDropdownContainer.RefreshText then
counterDropdownContainer:RefreshText()
end
end
UIDropDownMenu_AddButton(info, level)
end
end)
return container
end
local function CreateConfigFrame()
local frame = CreateFrame("Frame", "AbundanceTrackerConfigFrame", UIParent, "BasicFrameTemplateWithInset")
frame:SetSize(420, 820)
frame:SetPoint("CENTER")
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
frame:SetFrameStrata("DIALOG")
frame:SetClampedToScreen(true)
frame.TitleText:SetText("Abundance Tracker")
frame.CloseButton:SetScript("OnClick", function() frame:Hide() end)
tinsert(UISpecialFrames, "AbundanceTrackerConfigFrame")
local content = CreateFrame("Frame", nil, frame)
content:SetPoint("TOPLEFT", frame.InsetBg, "TOPLEFT", 14, -14)
content:SetPoint("BOTTOMRIGHT", frame.InsetBg, "BOTTOMRIGHT", -26, 14)
local y = 0
CreateCheckbox(content, "Lock bar position", "locked", y)
y = y - 35
CreateDropdown(content, "Visibility", "visibilityMode", {
{ label = "Always", value = "always" },
{ label = "Raid Only", value = "raid" },
}, y)
y = y - 62
CreateCheckbox(content, "Only show when you have the talent Abundance", "onlyShowWithAbundanceTalent", y)
y = y - 40
CreateDropdown(content, "Orientation", "orientation", {
{ label = "Horizontal", value = "horizontal" },
{ label = "Vertical", value = "vertical" },
}, y)
y = y - 62
progressionDropdownContainer = CreateDropdown(content, "Progression", "progressDirection", function()
if Addon:GetSetting("orientation") == "vertical" then
return {
{ label = "Top > Bottom", value = "reverse" },
{ label = "Bottom > Top", value = "forward" },
}
end
return {
{ label = "Left > Right", value = "reverse" },
{ label = "Right > Left", value = "forward" },
}
end, y)
y = y - 62
counterDropdownContainer = CreateDropdown(content, "Stack Counter", "counterPosition", function()
if Addon:GetSetting("orientation") == "vertical" then
return {
{ label = "Bottom", value = "bottom" },
{ label = "Top", value = "top" },
{ label = "Hide", value = "hide" },
}
end
return {
{ label = "Left", value = "left" },
{ label = "Right", value = "right" },
{ label = "Hide", value = "hide" },
}
end, y)
y = y - 62
CreateCheckbox(content, "Show timer labels", "showTimers", y)
y = y - 40
CreateCheckbox(content, "Show stack labels", "showStackLabels", y)
y = y - 40
CreateCheckbox(content, "Show decimal timers", "showDecimalTimers", y)
y = y - 40
CreateSlider(content, "Stack label Y offset", "stackLabelOffset", 0, 12, 1, y)
y = y - 38
CreateSlider(content, "Counter font size", "counterFontSize", 8, 24, 1, y)
y = y - 38
CreateSlider(content, "Timer font size", "timerFontSize", 6, 24, 1, y)
y = y - 38
CreateSlider(content, "Stack font size", "stackLabelFontSize", 6, 24, 1, y)
y = y - 38
CreateSlider(content, "Red below", "dangerThreshold", 1, 12, 1, y)
y = y - 38
CreateSlider(content, "Yellow below", "warningThreshold", 1, 12, 1, y)
y = y - 38
CreateSlider(content, "Scale", "scale", 0.5, 2, 0.05, y, function(value)
return string.format("%.2fx", value)
end)
y = y - 38
CreateSlider(content, "Width", "width", 120, 360, 1, y)
y = y - 38
CreateSlider(content, "Height", "height", 10, 40, 1, y)
y = y - 42
local resetButton = CreateFrame("Button", nil, content, "UIPanelButtonTemplate")
resetButton:SetSize(120, 24)
resetButton:SetPoint("TOPLEFT", content, "TOPLEFT", 0, y)
resetButton:SetText("Reset Position")
resetButton:SetScript("OnClick", function()
Addon:ResetPosition()
end)
local hint = content:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
hint:SetPoint("TOPLEFT", resetButton, "BOTTOMLEFT", 0, -12)
hint:SetText("Use /abt lock, /abt unlock, or drag the bar when unlocked.")
hint:SetTextColor(0.75, 0.82, 0.75)
return frame
end
function Addon:OpenConfig()
if not configFrame then
configFrame = CreateConfigFrame()
configFrame:Show()
return
end
if configFrame:IsShown() then
configFrame:Hide()
else
configFrame:Show()
end
end