-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.lua
More file actions
377 lines (323 loc) · 12.1 KB
/
Config.lua
File metadata and controls
377 lines (323 loc) · 12.1 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
369
370
371
372
373
374
375
376
377
-- Config.lua
-- Minimap button with rotation mode dropdown for PriorityHelper (3.3.5a, no dependencies)
local DH = PriorityHelper
if not DH then return end
local ns = DH.ns
-- ============================================================================
-- ROTATION MODE SYSTEM
-- Class modules register available modes via DH:RegisterMode() (defined in PriorityHelper.lua)
-- ============================================================================
-- Get the active mode data
function DH:GetActiveMode()
local modeKey = self.db and self.db.mode or nil
for _, mode in ipairs(ns.registered.modes) do
if mode.key == modeKey then
return mode
end
end
-- Fallback to first registered mode
return ns.registered.modes[1]
end
-- ============================================================================
-- DROPDOWN MENU
-- ============================================================================
local dropdownFrame = CreateFrame("Frame", "PriorityHelperDropdown", UIParent, "UIDropDownMenuTemplate")
local function BuildDropdown(self, level)
level = level or 1
if level ~= 1 then return end
local info = UIDropDownMenu_CreateInfo()
local currentMode = DH.db and DH.db.mode or nil
-- Title
info.text = "PriorityHelper"
info.isTitle = true
info.notCheckable = true
UIDropDownMenu_AddButton(info, level)
-- Separator
info = UIDropDownMenu_CreateInfo()
info.text = ""
info.disabled = true
info.notCheckable = true
UIDropDownMenu_AddButton(info, level)
-- Rotation modes
for _, mode in ipairs(ns.registered.modes) do
info = UIDropDownMenu_CreateInfo()
info.text = mode.name
info.icon = mode.icon
info.checked = (currentMode == mode.key)
info.func = function()
DH.db.mode = mode.key
DH:Print("Mode: " .. mode.name)
-- Update minimap button icon to match selected mode
if ns.MinimapButton and mode.icon then
ns.MinimapButton.icon:SetTexture(mode.icon)
end
DH:UpdateRecommendations()
end
UIDropDownMenu_AddButton(info, level)
end
-- Separator
info = UIDropDownMenu_CreateInfo()
info.text = ""
info.disabled = true
info.notCheckable = true
UIDropDownMenu_AddButton(info, level)
-- Toggle enable/disable
info = UIDropDownMenu_CreateInfo()
info.text = DH.db.enabled and "Disable" or "Enable"
info.notCheckable = true
info.func = function()
DH.db.enabled = not DH.db.enabled
DH:Print("PriorityHelper " .. (DH.db.enabled and "enabled" or "disabled"))
if not DH.db.enabled then DH:HideUI() end
end
UIDropDownMenu_AddButton(info, level)
-- Lock display
info = UIDropDownMenu_CreateInfo()
info.text = DH.db.locked and "Unlock Display" or "Lock Display"
info.notCheckable = true
info.func = function()
DH.db.locked = not DH.db.locked
DH:Print("Display " .. (DH.db.locked and "locked" or "unlocked"))
if ns.UI.MainFrame then
ns.UI.MainFrame:EnableMouse(not DH.db.locked)
end
end
UIDropDownMenu_AddButton(info, level)
end
-- ============================================================================
-- MINIMAP BUTTON
-- ============================================================================
local function CreateMinimapButton()
local button = CreateFrame("Button", "PriorityHelperMinimapButton", Minimap)
button:SetSize(31, 31)
button:SetFrameStrata("MEDIUM")
button:SetFrameLevel(8)
button:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
button:SetMovable(true)
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:RegisterForDrag("LeftButton")
-- Border overlay
local overlay = button:CreateTexture(nil, "OVERLAY")
overlay:SetSize(53, 53)
overlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
overlay:SetPoint("TOPLEFT")
-- Background
local bg = button:CreateTexture(nil, "BACKGROUND")
bg:SetSize(20, 20)
bg:SetTexture("Interface\\Minimap\\UI-Minimap-Background")
bg:SetPoint("CENTER")
-- Icon (will be set to active mode's icon)
local icon = button:CreateTexture(nil, "ARTWORK")
icon:SetSize(20, 20)
icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
icon:SetPoint("CENTER")
button.icon = icon
-- Set icon to current mode
local activeMode = DH:GetActiveMode()
if activeMode and activeMode.icon then
icon:SetTexture(activeMode.icon)
end
-- Position around minimap
local function UpdatePosition(angle)
local rad = math.rad(angle or 225)
local x = math.cos(rad) * 80
local y = math.sin(rad) * 80
button:ClearAllPoints()
button:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
-- Dragging
button:SetScript("OnDragStart", function(self)
if DH.db and DH.db.minimap and DH.db.minimap.locked then return end
self:SetScript("OnUpdate", function(self)
local mx, my = Minimap:GetCenter()
local cx, cy = GetCursorPosition()
local scale = Minimap:GetEffectiveScale()
cx, cy = cx / scale, cy / scale
local angle = math.deg(math.atan2(cy - my, cx - mx))
if DH.db and DH.db.minimap then
DH.db.minimap.position = angle
end
UpdatePosition(angle)
end)
end)
button:SetScript("OnDragStop", function(self)
self:SetScript("OnUpdate", nil)
end)
-- Click: open dropdown
button:SetScript("OnClick", function(self, btn)
GameTooltip:Hide()
UIDropDownMenu_Initialize(dropdownFrame, BuildDropdown, "MENU")
ToggleDropDownMenu(1, nil, dropdownFrame, self, 0, 0)
end)
-- Tooltip
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine("PriorityHelper v" .. DH.Version)
local activeMode = DH:GetActiveMode()
if activeMode then
GameTooltip:AddLine("Mode: |cFF00FF00" .. activeMode.name .. "|r", 1, 1, 1)
end
GameTooltip:AddLine("|cFFFFFFFFClick|r to select rotation mode", 0.7, 0.7, 0.7)
GameTooltip:Show()
end)
button:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
ns.MinimapButton = button
-- Apply saved position
local pos = DH.db and DH.db.minimap and DH.db.minimap.position or 225
UpdatePosition(pos)
if DH.db and DH.db.minimap and DH.db.minimap.hide then
button:Hide()
end
return button
end
-- ============================================================================
-- OVERRIDE ROTATION DISPATCH
-- Use the selected mode's rotation instead of spec-based dispatch
-- ============================================================================
-- Smoothing: Rec1 always shows the sim's top pick (no smoothing on slot 1).
-- Slots 2-3 resist changing for SMOOTH_LOCK_DURATION to prevent stutter,
-- unless the old ability is no longer in the recommendations at all.
local smoothState = {
abilities = {}, -- { [slot] = abilityKey }
changeTime = {}, -- { [slot] = GetTime() when this slot last changed }
}
local SMOOTH_LOCK_DURATION = 0.5
local function SmoothRecommendations(newRecs)
local now = GetTime()
local smoothed = {}
for i = 1, 3 do
local newAbility = newRecs[i] and newRecs[i].ability or nil
local oldAbility = smoothState.abilities[i]
local lastChange = smoothState.changeTime[i] or 0
local locked = (now - lastChange) < SMOOTH_LOCK_DURATION
-- Slot 1: always follow the sim — this is what to press NOW
if i == 1 or newAbility == oldAbility or not oldAbility or not locked then
smoothed[i] = newRecs[i]
if newAbility ~= oldAbility then
smoothState.abilities[i] = newAbility
smoothState.changeTime[i] = now
end
else
-- Slots 2-3 locked: keep old ability if it's still recommended somewhere
local oldStillValid = false
for j = 1, #newRecs do
if newRecs[j].ability == oldAbility then
oldStillValid = true
break
end
end
if oldStillValid then
for j = 1, #newRecs do
if newRecs[j].ability == oldAbility then
smoothed[i] = newRecs[j]
break
end
end
else
smoothed[i] = newRecs[i]
smoothState.abilities[i] = newAbility
smoothState.changeTime[i] = now
end
end
end
return smoothed
end
function DH:UpdateRecommendations()
if not self.db or not self.db.enabled then return end
if not UnitExists("target") and not ns.inCombat then return end
self:UpdateState()
local mode = self:GetActiveMode()
local recommendations = {}
if mode and mode.rotation then
recommendations = mode.rotation(self)
end
-- Apply smoothing to prevent stutter
recommendations = SmoothRecommendations(recommendations)
ns.recommendations = recommendations
self:UpdateUI()
if #recommendations > 0 then
self:ShowUI()
end
end
-- ============================================================================
-- INITIALIZATION
-- ============================================================================
-- No more hook chaining — Config.lua directly handles its setup at the bottom of the file
-- Slash command to toggle minimap visibility
DH:RegisterSlashCommand("minimap", function(cmd)
if DH.db.minimap then
DH.db.minimap.hide = not DH.db.minimap.hide
if ns.MinimapButton then
if DH.db.minimap.hide then
ns.MinimapButton:Hide()
else
ns.MinimapButton:Show()
end
end
DH:Print("Minimap button: " .. (DH.db.minimap.hide and "hidden" or "shown"))
end
end, "minimap - Toggle minimap button visibility")
-- ============================================================================
-- DIRECT INITIALIZATION
-- Config.lua is the last file in the TOC. ADDON_LOADED may fire before all
-- files are loaded, so hook chaining is unreliable. Instead, inject our
-- defaults and run setup directly here.
-- ============================================================================
-- Inject minimap defaults
local configDefaults = {
minimap = {
hide = false,
locked = false,
position = 225,
},
mode = nil,
}
for k, v in pairs(configDefaults) do
ns.registered.defaults[k] = ns.registered.defaults[k] or v
end
-- If OnInitialize already ran (ADDON_LOADED fired early), re-merge defaults
if DH.db then
local function MergeIfMissing(saved, defaults)
for k, v in pairs(defaults) do
if saved[k] == nil then
if type(v) == "table" then
saved[k] = {}
MergeIfMissing(saved[k], v)
else
saved[k] = v
end
elseif type(v) == "table" and type(saved[k]) == "table" then
MergeIfMissing(saved[k], v)
end
end
end
MergeIfMissing(DH.db, configDefaults)
end
-- Auto-select first mode if none saved
if DH.db and not DH.db.mode and #ns.registered.modes > 0 then
DH.db.mode = ns.registered.modes[1].key
end
-- If OnEnable already ran, create minimap button now
-- If not, hook OnEnable to add our setup
local origOnEnable = DH.OnEnable
function DH:OnEnable()
origOnEnable(self)
if not self.db.mode and #ns.registered.modes > 0 then
self.db.mode = ns.registered.modes[1].key
end
CreateMinimapButton()
end
-- If OnEnable already ran (db exists, UI exists), create minimap button directly
if DH.db and ns.UI.MainFrame then
CreateMinimapButton()
end
-- Force initialization if it hasn't happened yet
-- Config.lua is the last TOC file, so everything is registered by now
if not DH.db then
DH:OnInitialize()
end
if not ns.UI.MainFrame then
DH:OnEnable()
end