-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSUPConfig.lua
More file actions
368 lines (321 loc) · 14.3 KB
/
Copy pathSUPConfig.lua
File metadata and controls
368 lines (321 loc) · 14.3 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
local addonName, SUP = ...
local L = SUP.Locals
function SUP.CreateConfigFrame()
SUP.DebugPrint("Starting config frame creation...")
-- Create main config frame
local frame = L.CreateFrame("Frame", "SUPConfigFrame", UIParent, "SUPConfigFrameTemplate")
if not frame then
SUP.DebugPrint("Failed to create config frame!")
return
end
SUP.DebugPrint("Config frame created successfully")
-- Add these near the start of the function after creating the frame
local notificationsContent = SUP.Utils.GetElement(frame, "notificationsContent")
local trackerContent = SUP.Utils.GetElement(frame, "trackerContent")
local notificationsTab = SUP.Utils.GetElement(frame, "tabContainer.notificationsTab")
local trackerTab = SUP.Utils.GetElement(frame, "tabContainer.trackerTab")
local positionTab = SUP.Utils.GetElement(frame, "tabContainer.positionTab")
-- Add debug prints to help diagnose any issues
SUP.DebugPrint("Notifications Content:", notificationsContent)
SUP.DebugPrint("Tracker Content:", trackerContent)
SUP.DebugPrint("Notifications Tab:", notificationsTab)
SUP.DebugPrint("Tracker Tab:", trackerTab)
-- Function to handle position button clicks based on current tab
local function HandlePositionButton(self, currentTab)
-- Set the button text size to match tab text
local buttonText = self:GetFontString()
if buttonText then
buttonText:SetFontObject("GameFontNormalSmall")
end
if currentTab == "notifications" then
-- Handle notifications anchor
if not SUP.anchorFrame then
SUP.positionButton = self
SUP.anchorFrame = SUP.CreateAnchorFrame()
end
SUP.anchorFrame:UpdateSize()
if not SUP.anchorFrame:IsShown() then
SUP.anchorFrame:Show()
self:SetText("Save Anchor")
else
SUP.anchorFrame:Hide()
self:SetText("Edit Anchor")
end
else
-- Handle tracker display visibility
if SUP.skillTrackerDisplay then
if not SUP.skillTrackerDisplay:IsShown() then
SUP.DebugPrint("Showing tracker display")
SUP.skillTrackerDisplay:Show()
SUPConfig.trackerDisplayVisible = true
self:SetText("Hide Tracker")
else
SUP.DebugPrint("Hiding tracker display")
SUP.skillTrackerDisplay:Hide()
SUPConfig.trackerDisplayVisible = false
self:SetText("Show Tracker")
end
end
end
end
-- Modify the SwitchTab function to update the position button state
local function SwitchTab(selectedTab)
SUP.DebugPrint("Switching to tab:", selectedTab)
if selectedTab == "notifications" then
notificationsContent:Show()
trackerContent:Hide()
notificationsTab:SetEnabled(false)
trackerTab:SetEnabled(true)
-- Always reset position button to Edit Anchor for notifications tab
positionTab:SetText("Edit Anchor")
else -- tracker tab
notificationsContent:Hide()
trackerContent:Show()
notificationsTab:SetEnabled(true)
trackerTab:SetEnabled(false)
-- Hide anchor frame if it exists and is shown
if SUP.anchorFrame and SUP.anchorFrame:IsShown() then
SUP.anchorFrame:Hide()
end
-- Set position button text based on current tracker visibility
if SUP.skillTrackerDisplay then
positionTab:SetText(SUPConfig.trackerDisplayVisible and "Hide Tracker" or "Show Tracker")
end
SUP.UpdateSkillList(trackerContent.scrollFrame.content)
end
SUP.DebugPrint("Tab switch complete. Tracker visible:", SUPConfig.trackerDisplayVisible)
end
-- Set up position button click handler
positionTab:SetScript("OnClick", function(self)
if notificationsContent:IsShown() then
HandlePositionButton(self, "notifications")
else
HandlePositionButton(self, "tracker")
end
end)
-- Set initial button text based on saved state
if trackerContent:IsShown() then
positionTab:SetText(SUPConfig.trackerDisplayVisible and "Hide Tracker" or "Show Tracker")
end
-- Set up tab button scripts
if notificationsTab then
notificationsTab:SetScript("OnClick", function()
SwitchTab("notifications")
end)
end
if trackerTab then
trackerTab:SetScript("OnClick", function()
SwitchTab("tracker")
end)
end
-- Show notifications tab by default
SwitchTab("notifications")
SUP.configFrame = frame
-- Set frame properties
frame:SetFrameStrata("DIALOG")
frame:ClearAllPoints()
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
frame:Show()
-- Make frame movable
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
-- Initialize font slider
local fontSlider = SUP.Utils.GetSettingsElement(frame, "FontSlider")
if fontSlider then
fontSlider:SetValue(_G.SUPConfig.fontSize or 12)
fontSlider:SetScript("OnValueChanged", function(self, value)
_G.SUPConfig.fontSize = value
self.Text:SetText(string.format("Font Size (%d)", value))
SUP.DebugPrint("Font size set to:", value)
-- Update any active notifications
for _, notification in ipairs(SUP.activeNotifications or {}) do
local fontPath = notification.text:GetFont()
notification.text:SetFont(fontPath, value)
notification.icon:SetSize(value * 1.7, value * 1.7)
end
if SUP.anchorFrame then
SUP.anchorFrame:UpdateFontSize(value)
end
end)
end
-- Set initial text values
local fontSliderText = SUP.Utils.GetSettingsElement(frame, "FontSlider.Text")
if fontSliderText then
fontSliderText:SetText(string.format("Font Size (%d)", _G.SUPConfig.fontSize or 12))
end
-- Initialize duration slider
local durationSlider = SUP.Utils.GetSettingsElement(frame, "DurationSlider")
if durationSlider then
durationSlider:SetValue(_G.SUPConfig.duration or 1.5)
-- Set initial text value
durationSlider.Text:SetText(string.format("Duration (%.1fs)", _G.SUPConfig.duration or 1.5))
durationSlider:SetScript("OnValueChanged", function(self, value)
_G.SUPConfig.duration = value
self.Text:SetText(string.format("Duration (%.1fs)", value))
SUP.DebugPrint("Duration set to:", value)
end)
end
-- Initialize checkboxes
local iconCheckbox = SUP.Utils.GetSettingsElement(frame, "checkboxContainer.iconCheckbox")
local soundCheckbox = SUP.Utils.GetSettingsElement(frame, "checkboxContainer.soundCheckbox")
if iconCheckbox then
iconCheckbox:SetChecked(_G.SUPConfig.showIcon)
iconCheckbox:SetScript("OnClick", function(self)
_G.SUPConfig.showIcon = self:GetChecked()
SUP.DebugPrint("Icon checkbox clicked. New state:", _G.SUPConfig.showIcon)
end)
end
if soundCheckbox then
soundCheckbox:SetChecked(_G.SUPConfig.playSound)
soundCheckbox:SetScript("OnClick", function(self)
_G.SUPConfig.playSound = self:GetChecked()
SUP.DebugPrint("Sound checkbox clicked. New state:", _G.SUPConfig.playSound)
end)
end
-- Setup test button
local testButton = SUP.Utils.GetSettingsElement(frame, "TestButton")
if testButton then
testButton:SetScript("OnClick", function()
if #SUP.trackableSkills > 0 then
local randomSkill = SUP.trackableSkills[math.random(#SUP.trackableSkills)]
local randomLevel = math.random(1, 300)
SUP.ShowNotification(randomSkill, randomLevel)
SUP.DebugPrint("Test notification shown for:", randomSkill, "Level:", randomLevel)
else
SUP.DebugPrint("No trackable skills found for test notification")
end
end)
end
-- Set version text
local versionText = SUP.Utils.GetFrameElement(frame, "$parentVersion")
if versionText then
local version = L.GetAddOnMetadata(addonName, "Version") or "Unknown"
versionText:SetText("v" .. version)
-- Add debug prints to help diagnose the issue
SUP.DebugPrint("Version text element found:", versionText)
SUP.DebugPrint("Setting version text to:", "v" .. version)
else
SUP.DebugPrint("Could not find version text element")
-- Add additional debug info
SUP.DebugPrint("Frame elements available:", frame:GetChildren())
end
-- Initialize sound dropdown
local soundDropdown = SUP.Utils.GetSettingsElement(frame, "checkboxContainer.soundDropdown")
if soundDropdown then
L.UIDropDownMenu_SetWidth(soundDropdown, 120)
L.UIDropDownMenu_Initialize(soundDropdown, function(self, level)
local info = L.UIDropDownMenu_CreateInfo()
for soundName in pairs(SUP.SOUND_OPTIONS) do
info.text = soundName
info.value = soundName
info.func = function(self)
_G.SUPConfig.sound = self.value
L.UIDropDownMenu_SetSelectedValue(soundDropdown, self.value)
-- Play sound preview
if SUP.SOUND_OPTIONS[self.value] then
L.PlaySound(SUP.SOUND_OPTIONS[self.value], "Master")
end
end
info.checked = (_G.SUPConfig.sound == soundName)
L.UIDropDownMenu_AddButton(info)
end
end)
L.UIDropDownMenu_SetSelectedValue(soundDropdown, _G.SUPConfig.sound or "Skill Up")
else
SUP.DebugPrint("Sound dropdown not found")
end
end
-- Add this function after SUP.CreateConfigFrame()
function SUP.UpdateSkillList(scrollChild)
-- Clear existing content
for _, child in pairs({ scrollChild:GetChildren() }) do
child:Hide()
child:SetParent(nil)
end
local currentSkills = SUP.SkillTracker.ScanSkills()
local yOffset = -5
local rowHeight = 24
-- Helper function to create skill row
local function CreateSkillRow(skillName, skillData)
local row = CreateFrame("Frame", nil, scrollChild)
row:SetSize(320, rowHeight)
row:SetPoint("TOPLEFT", scrollChild, "TOPLEFT", 5, yOffset)
local checkbox = CreateFrame("CheckButton", nil, row, "UICheckButtonTemplate")
checkbox:SetPoint("LEFT", row, "LEFT", 0, 0)
checkbox:SetSize(24, 24)
local icon = row:CreateTexture(nil, "ARTWORK")
icon:SetSize(20, 20)
icon:SetPoint("LEFT", checkbox, "RIGHT", 5, 0)
icon:SetTexture(SUP.skillIcons[skillName] or "Interface\\Icons\\INV_Misc_QuestionMark")
local nameText = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
nameText:SetPoint("LEFT", icon, "RIGHT", 5, 0)
nameText:SetText(skillName)
local levelText = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
levelText:SetPoint("LEFT", nameText, "RIGHT", 6, 0)
levelText:SetText(string.format("(%d/%d)", skillData.rank, skillData.max))
levelText:SetTextColor(0.7, 0.7, 0.7, 1)
checkbox:SetChecked(_G.SUPTrackedSkills[skillName] or false)
checkbox:SetScript("OnClick", function(self)
local isChecked = self:GetChecked()
_G.SUPTrackedSkills[skillName] = isChecked
if SUP.skillTrackerDisplay then
SUP.skillTrackerDisplay:UpdateDisplay()
end
end)
yOffset = yOffset - rowHeight - 2
end
-- Add category headers and skills using skillOrder
local function AddCategoryHeader(text)
local headerFrame = CreateFrame("Frame", nil, scrollChild)
headerFrame:SetPoint("TOPLEFT", scrollChild, "TOPLEFT", 0, yOffset)
headerFrame:SetSize(320, rowHeight)
local bg = headerFrame:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetColorTexture(0.1, 0.1, 0.1, 0.8)
local header = headerFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
header:SetPoint("LEFT", headerFrame, "LEFT", 5, 0)
header:SetText(text)
yOffset = yOffset - rowHeight
end
-- Track current category
local currentCategory = nil
local categoryHasSkills = false
-- Helper function to determine category
local function GetSkillCategory(skillName)
if skillName == "Defense" or skillName == "Axes" or skillName == "Bows" or
skillName == "Crossbows" or skillName == "Daggers" or skillName == "Fist Weapons" or
skillName == "Guns" or skillName == "Maces" or skillName == "Polearms" or
skillName == "Staves" or skillName == "Swords" or skillName == "Thrown" or
skillName == "Two-Handed Axes" or skillName == "Two-Handed Maces" or
skillName == "Two-Handed Swords" or skillName == "Unarmed" or skillName == "Wands" then
return "Weapon Skills"
elseif skillName == "Cooking" or skillName == "First Aid" or skillName == "Fishing" then
return "Secondary Professions"
else
return "Primary Professions"
end
end
-- Process skills in order from SUP.skillOrder
for _, skillName in ipairs(SUP.skillOrder) do
local skillData = currentSkills[skillName]
if skillData then
local category = GetSkillCategory(skillName)
-- Add category header if needed
if currentCategory ~= category then
if currentCategory and categoryHasSkills then
yOffset = yOffset - 10 -- Add spacing between categories
end
AddCategoryHeader(category)
currentCategory = category
categoryHasSkills = false
end
CreateSkillRow(skillName, skillData)
categoryHasSkills = true
end
end
-- Update scroll child height
scrollChild:SetHeight(math.abs(yOffset) + 5)
end