-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.lua
More file actions
2523 lines (2170 loc) · 99.1 KB
/
UI.lua
File metadata and controls
2523 lines (2170 loc) · 99.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
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- HealIQ UI.lua
-- Renders suggestion icons and manages configuration display
local addonName, HealIQ = ...
HealIQ.UI = {}
local UI = HealIQ.UI
-- UI Frame references
local mainFrame = nil
local iconFrame = nil
local spellNameText = nil
local cooldownFrame = nil
local queueFrame = nil
local queueIcons = {}
local isDragging = false
local minimapButton = nil
local optionsFrame = nil
-- Constants
local FRAME_SIZE = 64
local ICON_SIZE = 48
local OPTIONS_FRAME_HEIGHT = 700 -- Increased height to prevent content overflow
local TOOLTIP_LINE_LENGTH = 45
-- Minimap button positioning
local MINIMAP_BUTTON_PIXEL_BUFFER = 2
-- UI Border colors (configurable for accessibility)
local BORDER_COLORS = {
positioning = {0, 1, 1, 1.0}, -- Bright cyan for positioning aid
locked = {1, 0, 0, 0.5}, -- Red when UI is locked
unlocked = {0, 1, 0, 0.5}, -- Green when UI is unlocked
targeting = {0, 0, 0, 0.8} -- Dark border for targeting indicators
}
-- Helper function to validate database availability for UI operations
-- Consolidates repeated database validation logic across UI functions
local function validateDatabase(functionName, requireUISection)
if not HealIQ.db then
HealIQ:DebugLog(functionName .. ": Database not ready, skipping operation", "WARN")
return false
end
if requireUISection ~= false and not HealIQ.db.ui then
HealIQ:DebugLog(functionName .. ": UI database section not ready, skipping operation", "WARN")
return false
end
return true
end
-- Helper function to safely update UI settings with database validation
-- Consolidates the common pattern of checking database before updating settings
local function updateUISetting(settingName, value, callback)
if HealIQ.db and HealIQ.db.ui then
HealIQ.db.ui[settingName] = value
if callback and type(callback) == "function" then
callback()
end
return true
end
return false
end
-- Helper function to create standardized checkboxes with consistent styling
-- Reduces code duplication for UI options checkboxes
local function createCheckbox(parent, name, text, yOffset, onClick, tooltip)
local checkbox = CreateFrame("CheckButton", name, parent, "UICheckButtonTemplate")
checkbox:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, yOffset)
checkbox.text = checkbox:CreateFontString(nil, "OVERLAY", "GameFontNormal")
checkbox.text:SetPoint("LEFT", checkbox, "RIGHT", 5, 0)
checkbox.text:SetText(text)
if onClick then
checkbox:SetScript("OnClick", onClick)
end
if tooltip and UI.AddTooltip then
UI:AddTooltip(checkbox, tooltip.title, tooltip.description)
end
return checkbox
end
-- Helper function to create standardized sliders with consistent styling
-- Reduces code duplication for UI options sliders
local function createSlider(parent, name, yOffset, minVal, maxVal, step, labelText, onValueChanged, tooltip)
local slider = CreateFrame("Slider", name, parent, "OptionsSliderTemplate")
slider:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, yOffset)
slider:SetMinMaxValues(minVal, maxVal)
slider:SetValueStep(step)
slider:SetObeyStepOnDrag(true)
if tooltip then
slider.tooltipText = tooltip.description
end
_G[slider:GetName() .. "Low"]:SetText(tostring(minVal))
_G[slider:GetName() .. "High"]:SetText(tostring(maxVal))
_G[slider:GetName() .. "Text"]:SetText(labelText)
if onValueChanged then
slider:SetScript("OnValueChanged", onValueChanged)
end
if tooltip and UI.AddTooltip then
UI:AddTooltip(slider, tooltip.title, tooltip.description)
end
return slider
end
function UI:Initialize()
HealIQ:SafeCall(function()
-- Check if database is ready before initializing UI components
if not validateDatabase("Initialize") then
return
end
self:CreateMainFrame()
self:CreateMinimapButton()
self:CreateOptionsFrame()
self:SetupEventHandlers()
HealIQ:Print("UI initialized")
end)
end
function UI:EnsureInitialized()
-- Defensive function to ensure UI components are created
-- Only attempt creation if WoW API is available
if not CreateFrame then
HealIQ:DebugLog("CreateFrame not available, skipping UI initialization", "WARN")
return
end
-- Call Initialize() if components haven't been created yet
-- Initialize() now has proper database checking
if not mainFrame then
HealIQ:DebugLog("Main frame not found, calling Initialize", "INFO")
self:Initialize()
return -- Initialize() will handle creating all components
end
-- Individual component checks for edge cases where Initialize() was called
-- but some components failed to create
if not minimapButton and validateDatabase("EnsureInitialized-MinimapButton") then
HealIQ:DebugLog("Minimap button not found, creating it", "INFO")
self:CreateMinimapButton()
end
if not optionsFrame and validateDatabase("EnsureInitialized-OptionsFrame", false) then
HealIQ:DebugLog("Options frame not found, creating it", "INFO")
self:CreateOptionsFrame()
end
end
function UI:CreateMainFrame()
HealIQ:SafeCall(function()
-- Ensure database is available
if not validateDatabase("CreateMainFrame") then
return
end
-- Determine total frame size based on queue settings
local queueSize = HealIQ.db.ui.queueSize or 3
local queueLayout = HealIQ.db.ui.queueLayout or "horizontal"
local queueSpacing = HealIQ.db.ui.queueSpacing or 8
local queueScale = HealIQ.db.ui.queueScale or 0.75
local queueIconSize = math.floor(ICON_SIZE * queueScale) -- Use same calculation as CreateQueueFrame
local padding = 8 -- Consistent padding for all elements
local frameWidth = FRAME_SIZE + (padding * 2)
local frameHeight = FRAME_SIZE + (padding * 2)
if HealIQ.db.ui.showQueue then
if queueLayout == "horizontal" then
-- Fix: Add spacing between icon and queue, plus queue width
local queueWidth = (queueSize - 1) * queueIconSize + math.max(0, queueSize - 2) * queueSpacing
frameWidth = frameWidth + queueSpacing + queueWidth
else
-- Account for spell name text in vertical layout
local spellNameHeight = HealIQ.db.ui.showSpellName and 25 or 0 -- Match CreateQueueFrame offset
-- Fix: Add spacing between icon and queue, plus queue height
local queueHeight = (queueSize - 1) * queueIconSize + math.max(0, queueSize - 2) * queueSpacing
frameHeight = frameHeight + queueSpacing + spellNameHeight + queueHeight
end
end
-- Create main container frame
mainFrame = CreateFrame("Frame", "HealIQMainFrame", UIParent)
mainFrame:SetSize(frameWidth, frameHeight)
mainFrame:SetPoint("CENTER", UIParent, "CENTER", HealIQ.db.ui.x, HealIQ.db.ui.y)
mainFrame:SetFrameStrata("MEDIUM")
mainFrame:SetFrameLevel(100)
-- Create background with improved styling that covers the entire frame for mouse events
local bg = mainFrame:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints(mainFrame) -- Cover the entire frame area
bg:SetColorTexture(0, 0, 0, 0.4)
bg:SetAlpha(0.6)
-- Create border for better visual definition with consistent padding
local border = mainFrame:CreateTexture(nil, "BORDER")
border:SetPoint("TOPLEFT", mainFrame, "TOPLEFT", padding - 2, -(padding - 2))
border:SetPoint("BOTTOMRIGHT", mainFrame, "BOTTOMRIGHT", -(padding - 2), padding - 2)
border:SetColorTexture(0.3, 0.3, 0.3, 0.8)
-- Store border reference for ToggleLock function
mainFrame.border = border
-- Create primary spell icon frame (current suggestion) with consistent padding
iconFrame = CreateFrame("Button", "HealIQIconFrame", mainFrame)
iconFrame:SetSize(ICON_SIZE, ICON_SIZE)
iconFrame:SetPoint("LEFT", mainFrame, "LEFT", padding + (FRAME_SIZE - ICON_SIZE) / 2, 0)
-- Store current suggestion for tooltip display
iconFrame.currentSuggestion = nil
-- Create spell icon texture with improved styling
local iconTexture = iconFrame:CreateTexture(nil, "ARTWORK")
iconTexture:SetAllPoints()
iconTexture:SetTexCoord(0.1, 0.9, 0.1, 0.9) -- Crop edges for cleaner look
iconFrame.icon = iconTexture
-- Create targeting indicator (small icon in corner)
local targetingIcon = CreateFrame("Frame", "HealIQTargetingIcon", iconFrame)
targetingIcon:SetSize(16, 16)
targetingIcon:SetPoint("BOTTOMRIGHT", iconFrame, "BOTTOMRIGHT", -2, 2)
local targetingTexture = targetingIcon:CreateTexture(nil, "OVERLAY")
targetingTexture:SetAllPoints()
targetingTexture:SetTexCoord(0.1, 0.9, 0.1, 0.9)
targetingIcon.icon = targetingTexture
-- Create targeting indicator border
local targetingBorder = targetingIcon:CreateTexture(nil, "BORDER")
targetingBorder:SetSize(18, 18)
targetingBorder:SetPoint("CENTER")
targetingBorder:SetColorTexture(unpack(BORDER_COLORS.targeting))
targetingIcon.border = targetingBorder
iconFrame.targetingIcon = targetingIcon
-- Create glow effect for primary icon
local glow = iconFrame:CreateTexture(nil, "OVERLAY")
glow:SetSize(ICON_SIZE + 8, ICON_SIZE + 8)
glow:SetPoint("CENTER")
glow:SetColorTexture(1, 1, 0, 0.4) -- Yellow glow
glow:SetBlendMode("ADD")
iconFrame.glow = glow
-- Create pulsing animation for the glow (with defensive API check)
if glow.CreateAnimationGroup then
local glowAnimation = glow:CreateAnimationGroup()
glowAnimation:SetLooping("BOUNCE")
local fadeIn = glowAnimation:CreateAnimation("Alpha")
fadeIn:SetFromAlpha(0.2)
fadeIn:SetToAlpha(0.6)
fadeIn:SetDuration(1.0)
fadeIn:SetSmoothing("IN_OUT")
local fadeOut = glowAnimation:CreateAnimation("Alpha")
fadeOut:SetFromAlpha(0.6)
fadeOut:SetToAlpha(0.2)
fadeOut:SetDuration(1.0)
fadeOut:SetSmoothing("IN_OUT")
glowAnimation:Play()
iconFrame.glowAnimation = glowAnimation
end
-- Add click handler for viewing spell information (removed casting functionality)
iconFrame:SetScript("OnClick", function(self, button)
-- Spell casting removed due to Blizzard restrictions
if self.currentSuggestion then
HealIQ:Print("Suggested: " .. self.currentSuggestion.name)
end
end)
-- Add tooltip functionality for the main icon
iconFrame:SetScript("OnEnter", function(self)
if self.currentSuggestion then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(self.currentSuggestion.name, 1, 1, 1)
GameTooltip:AddLine("Suggested spell for current situation", 0.7, 0.7, 0.7)
if self.currentSuggestion.priority then
GameTooltip:AddLine("Priority: " .. self.currentSuggestion.priority, 0.5, 0.8, 1)
end
-- Add targeting suggestions
if HealIQ.Engine then
local targetText = HealIQ.Engine:GetTargetingSuggestionsText(self.currentSuggestion)
local targetDesc = HealIQ.Engine:GetTargetingSuggestionsDescription(self.currentSuggestion)
if targetText then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Suggested Target: " .. targetText, 1, 0.8, 0)
if targetDesc then
GameTooltip:AddLine(targetDesc, 0.8, 0.8, 0.8)
end
end
end
GameTooltip:Show()
end
end)
iconFrame:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
-- Create spell name text with consistent spacing
spellNameText = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
spellNameText:SetPoint("TOP", iconFrame, "BOTTOM", 0, -4) -- Consistent spacing
spellNameText:SetTextColor(1, 1, 1, 1)
if spellNameText.SetShadowColor then
spellNameText:SetShadowColor(0, 0, 0, 1)
spellNameText:SetShadowOffset(1, -1)
end
if spellNameText.SetJustifyH then
spellNameText:SetJustifyH("CENTER") -- Center-align the text
end
if spellNameText.SetJustifyV then
spellNameText:SetJustifyV("TOP") -- Top-align for multi-line support
end
if spellNameText.SetWidth then
spellNameText:SetWidth(120) -- Set a max width to prevent overflow
end
if spellNameText.SetWordWrap then
spellNameText:SetWordWrap(true) -- Enable word wrapping for long spell names
end
-- Create cooldown frame
cooldownFrame = CreateFrame("Cooldown", "HealIQCooldownFrame", iconFrame, "CooldownFrameTemplate")
cooldownFrame:SetAllPoints()
if cooldownFrame.SetDrawEdge then
cooldownFrame:SetDrawEdge(false)
end
if cooldownFrame.SetDrawSwipe then
cooldownFrame:SetDrawSwipe(true)
end
if cooldownFrame.SetReverse then
cooldownFrame:SetReverse(true)
end
-- Create queue frame
self:CreateQueueFrame()
-- Make frame draggable
self:MakeFrameDraggable()
-- Update position border based on current settings
-- This call is necessary here because the frame border needs to be initialized
-- after all frame components are created and the database is available
self:UpdatePositionBorder()
-- Initially hide the frame
mainFrame:Hide()
end)
end
-- Helper function for minimap button positioning
function UI:CalculateMinimapButtonRadius()
if not minimapButton then
return 1
end
local minimapRadius = (Minimap and Minimap:GetWidth() or 140) / 2 -- Fallback to default minimap size
local buttonRadius = (minimapButton:GetWidth() or 20) / 2 -- Fallback to default button size
-- Fixed: Use minimapRadius + MINIMAP_BUTTON_PIXEL_BUFFER to place button ON the edge
local radius = minimapRadius + MINIMAP_BUTTON_PIXEL_BUFFER
if radius <= 0 then
radius = 1 -- Ensure a minimum positive radius
end
return radius
end
function UI:CreateMinimapButton()
-- Ensure database is available
if not validateDatabase("CreateMinimapButton") then
return
end
-- Create minimap button
minimapButton = CreateFrame("Button", "HealIQMinimapButton", Minimap)
minimapButton:SetSize(32, 32)
minimapButton:SetFrameStrata("MEDIUM")
minimapButton:SetFrameLevel(8)
-- Create simple button background
local bg = minimapButton:CreateTexture(nil, "BACKGROUND")
bg:SetSize(28, 28)
bg:SetPoint("CENTER")
bg:SetColorTexture(0.2, 0.2, 0.2, 0.8) -- Dark background
-- Create button icon
local icon = minimapButton:CreateTexture(nil, "ARTWORK")
icon:SetSize(20, 20)
icon:SetPoint("CENTER")
icon:SetTexture("Interface\\Icons\\Spell_Nature_Rejuvenation")
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92) -- Standard icon crop
-- Create simple border
local border = minimapButton:CreateTexture(nil, "OVERLAY")
border:SetSize(30, 30)
border:SetPoint("CENTER")
border:SetColorTexture(0.8, 0.8, 0.8, 1.0) -- Light border
border:SetDrawLayer("OVERLAY", 1)
minimapButton.icon = icon
minimapButton.border = border -- Store reference for potential updates
-- Position on minimap using angle-based positioning
local savedAngle = HealIQ.db.ui.minimapAngle or -math.pi/4 -- Default to top-right
local radius = self:CalculateMinimapButtonRadius()
-- Fixed: Position relative to Minimap center, not UIParent
local x = radius * math.cos(savedAngle)
local y = radius * math.sin(savedAngle)
minimapButton:SetPoint("CENTER", Minimap, "CENTER", x, y)
-- Make it draggable around minimap
minimapButton:SetMovable(true)
minimapButton:EnableMouse(true)
minimapButton:RegisterForDrag("LeftButton")
minimapButton:SetScript("OnDragStart", function(self)
self:StartMoving()
-- Store original border visibility
if self.icon then
self.originalAlpha = self.icon:GetAlpha()
end
end)
minimapButton:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
-- Keep button on minimap edge and save position
local dragX, dragY = self:GetCenter()
local mapX, mapY = Minimap:GetCenter()
local angle = math.atan2(dragY - mapY, dragX - mapX)
-- Use helper method for radius calculation
local finalRadius = UI:CalculateMinimapButtonRadius()
-- Fixed: Position relative to Minimap center, not UIParent
local newX = finalRadius * math.cos(angle)
local newY = finalRadius * math.sin(angle)
self:ClearAllPoints()
self:SetPoint("CENTER", Minimap, "CENTER", newX, newY)
-- Restore icon visibility if it was affected
if self.icon and self.originalAlpha then
self.icon:SetAlpha(self.originalAlpha)
end
-- Save minimap button position as angle for consistency
if HealIQ.db and HealIQ.db.ui then
HealIQ.db.ui.minimapAngle = angle
end
end)
-- Click handler
minimapButton:SetScript("OnClick", function(self, button)
if button == "LeftButton" then
UI:ToggleOptionsFrame()
elseif button == "RightButton" then
UI:Toggle()
end
end)
-- Tooltip
minimapButton:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine("HealIQ v" .. HealIQ.version, 1, 1, 1)
GameTooltip:AddLine("Smart healing suggestions for Restoration Druids", 0.8, 0.8, 0.8)
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Left-click: Open Options", 0.7, 0.7, 0.7)
GameTooltip:AddLine("Right-click: Toggle Display", 0.7, 0.7, 0.7)
GameTooltip:AddLine("Drag: Move Button", 0.7, 0.7, 0.7)
GameTooltip:Show()
end)
minimapButton:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
-- Set initial visibility based on showIcon setting
self:UpdateMinimapButtonVisibility()
end
function UI:UpdateMinimapButtonVisibility()
if not validateDatabase("UpdateMinimapButtonVisibility") then
return
end
if not minimapButton then
-- If minimap button doesn't exist yet, create it
HealIQ:DebugLog("Minimap button not created yet, creating it now", "INFO")
self:CreateMinimapButton()
end
if minimapButton then
if HealIQ.db.ui.showIcon then
minimapButton:Show()
else
minimapButton:Hide()
end
end
end
function UI:CreateQueueFrame()
-- Ensure database is available
if not validateDatabase("CreateQueueFrame") then
return
end
local queueSize = HealIQ.db.ui.queueSize or 3
local queueLayout = HealIQ.db.ui.queueLayout or "horizontal"
local queueSpacing = HealIQ.db.ui.queueSpacing or 8
local queueIconSize = math.floor(ICON_SIZE * (HealIQ.db.ui.queueScale or 0.75)) -- Configurable queue icon size
local padding = 8 -- Consistent with main frame padding
-- Create queue container frame (always create, but conditionally show)
queueFrame = CreateFrame("Frame", "HealIQQueueFrame", mainFrame)
if queueLayout == "horizontal" then
-- Fix: Adjust frame size calculation to account for proper spacing
local totalWidth = (queueSize - 1) * queueIconSize + math.max(0, queueSize - 2) * queueSpacing
queueFrame:SetSize(totalWidth, queueIconSize)
queueFrame:SetPoint("LEFT", iconFrame, "RIGHT", queueSpacing, 0)
else
-- Fix: Adjust frame size calculation for vertical layout
local totalHeight = (queueSize - 1) * queueIconSize + math.max(0, queueSize - 2) * queueSpacing
queueFrame:SetSize(queueIconSize, totalHeight)
-- Better vertical positioning that accounts for spell name text and padding
local verticalOffset = HealIQ.db.ui.showSpellName and -(queueSpacing + 25) or -(queueSpacing + padding)
queueFrame:SetPoint("TOP", iconFrame, "BOTTOM", 0, verticalOffset)
end
-- Create queue icons
queueIcons = {}
for i = 1, queueSize - 1 do -- -1 because primary icon is separate
local queueIcon = CreateFrame("Frame", "HealIQQueueIcon" .. i, queueFrame)
queueIcon:SetSize(queueIconSize, queueIconSize)
if queueLayout == "horizontal" then
queueIcon:SetPoint("LEFT", queueFrame, "LEFT", (i - 1) * (queueIconSize + queueSpacing), 0)
else
queueIcon:SetPoint("TOP", queueFrame, "TOP", 0, -(i - 1) * (queueIconSize + queueSpacing))
end
-- Create icon texture
local texture = queueIcon:CreateTexture(nil, "ARTWORK")
texture:SetAllPoints()
texture:SetTexCoord(0.1, 0.9, 0.1, 0.9)
texture:SetAlpha(0.7) -- Slightly transparent for queue items
queueIcon.icon = texture
-- Create border for queue items with improved visibility
local border = queueIcon:CreateTexture(nil, "BORDER")
border:SetSize(queueIconSize + 2, queueIconSize + 2)
border:SetPoint("CENTER")
border:SetColorTexture(0.3, 0.6, 1, 0.8) -- Blue border for queue items
queueIcon.border = border
-- Add subtle shadow effect
local shadow = queueIcon:CreateTexture(nil, "BACKGROUND")
shadow:SetSize(queueIconSize + 4, queueIconSize + 4)
shadow:SetPoint("CENTER", queueIcon, "CENTER", 2, -2)
shadow:SetColorTexture(0, 0, 0, 0.5)
queueIcon.shadow = shadow
-- Add position number overlay with better positioning for vertical layout
local positionText = queueIcon:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
if queueLayout == "vertical" then
positionText:SetPoint("LEFT", queueIcon, "RIGHT", 6, 0) -- Consistent spacing
else
positionText:SetPoint("BOTTOMRIGHT", queueIcon, "BOTTOMRIGHT", -2, 2)
end
positionText:SetTextColor(1, 1, 1, 0.9)
if positionText.SetText then
positionText:SetText(tostring(i + 1)) -- +1 because primary is position 1
end
if positionText.SetShadowColor then
positionText:SetShadowColor(0, 0, 0, 1)
positionText:SetShadowOffset(1, -1)
end
queueIcon.positionText = positionText
-- Initially hide queue icons
queueIcon:Hide()
table.insert(queueIcons, queueIcon)
end
-- Show/hide queue frame based on settings
if HealIQ.db.ui.showQueue then
queueFrame:Show()
else
queueFrame:Hide()
end
end
function UI:CreateOptionsFrame()
-- Ensure database is available
if not validateDatabase("CreateOptionsFrame", false) then
return
end
-- Create main options frame
optionsFrame = CreateFrame("Frame", "HealIQOptionsFrame", UIParent, "BasicFrameTemplateWithInset")
optionsFrame:SetSize(400, OPTIONS_FRAME_HEIGHT) -- Increased height to accommodate all content without overflow
optionsFrame:SetPoint("CENTER")
optionsFrame:SetFrameStrata("DIALOG")
optionsFrame:SetMovable(true)
optionsFrame:EnableMouse(true)
optionsFrame:RegisterForDrag("LeftButton")
optionsFrame:SetScript("OnDragStart", optionsFrame.StartMoving)
optionsFrame:SetScript("OnDragStop", optionsFrame.StopMovingOrSizing)
-- Add icon to title bar
local titleIcon = optionsFrame:CreateTexture(nil, "ARTWORK")
titleIcon:SetSize(16, 16)
titleIcon:SetPoint("LEFT", optionsFrame.TitleBg, "LEFT", 8, 0)
titleIcon:SetTexture("Interface\\Icons\\Spell_Nature_Rejuvenation")
titleIcon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
-- Title
optionsFrame.title = optionsFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightLarge")
optionsFrame.title:SetPoint("LEFT", titleIcon, "RIGHT", 5, 0)
optionsFrame.title:SetText("HealIQ Options")
-- Version display
optionsFrame.version = optionsFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
optionsFrame.version:SetPoint("RIGHT", optionsFrame.TitleBg, "RIGHT", -5, 0)
optionsFrame.version:SetText("v" .. HealIQ.version)
optionsFrame.version:SetTextColor(0.7, 0.7, 0.7, 1)
-- Content area
local content = optionsFrame.Inset or optionsFrame
-- Create tab system
self:CreateOptionsTabs(content)
-- Close button
local closeButton = CreateFrame("Button", "HealIQCloseButton", content, "UIPanelButtonTemplate")
closeButton:SetSize(80, 22)
closeButton:SetPoint("BOTTOMRIGHT", content, "BOTTOMRIGHT", -10, 10)
closeButton:SetText("Close")
closeButton:SetScript("OnClick", function()
optionsFrame:Hide()
end)
-- Initially hide
optionsFrame:Hide()
-- Update options with current values once frame is created
self:UpdateOptionsFrame()
end
function UI:CreateOptionsTabs(parent)
-- Create navigation sidebar and content area
local navWidth = 110 -- Width of the left navigation sidebar
local navButtonHeight = 28
local navButtonSpacing = 2
local tabs = {
{name = "General", id = "general"},
{name = "Display", id = "display"},
{name = "Rules", id = "rules"},
{name = "Strategy", id = "strategy"},
{name = "Queue", id = "queue"},
{name = "Statistics", id = "statistics"}
}
optionsFrame.tabs = {}
optionsFrame.tabPanels = {}
optionsFrame.activeTab = nil -- Initialize activeTab to avoid nil reference issues
-- Create navigation background with responsive sizing
local navBackground = CreateFrame("Frame", "HealIQNavBackground", parent, "BackdropTemplate")
navBackground:SetPoint("TOPLEFT", parent, "TOPLEFT", 10, -10)
-- Make navigation height responsive to frame height
local parentHeight = parent:GetHeight() or OPTIONS_FRAME_HEIGHT -- Get parent height, fallback to default
local navHeight = parentHeight - 80 -- Navigation height adjusted for content fit
navBackground:SetSize(navWidth, navHeight)
navBackground:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 8,
edgeSize = 8,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
})
navBackground:SetBackdropColor(0.05, 0.05, 0.1, 0.8)
navBackground:SetBackdropBorderColor(0.3, 0.3, 0.4, 0.8)
for i, tab in ipairs(tabs) do
-- Create navigation button
local navButton = CreateFrame("Button", "HealIQNav" .. tab.id, navBackground, "UIPanelButtonTemplate")
navButton:SetSize(navWidth - 10, navButtonHeight)
navButton:SetPoint("TOP", navBackground, "TOP", 0, -5 - (i-1) * (navButtonHeight + navButtonSpacing))
navButton:SetText(tab.name)
navButton.tabId = tab.id
-- Style the navigation button for sidebar appearance
navButton:SetNormalFontObject("GameFontNormal")
navButton:SetHighlightFontObject("GameFontHighlight")
navButton:SetDisabledFontObject("GameFontDisable")
-- Set initial inactive appearance
navButton:SetAlpha(0.8)
-- Add hover effects
navButton:SetScript("OnEnter", function(self)
if not optionsFrame.activeTab or self.tabId ~= optionsFrame.activeTab then
self:SetAlpha(0.95)
end
end)
navButton:SetScript("OnLeave", function(self)
if not optionsFrame.activeTab or self.tabId ~= optionsFrame.activeTab then
self:SetAlpha(0.8)
end
end)
navButton:SetScript("OnClick", function(self)
UI:ShowOptionsTab(self.tabId)
end)
optionsFrame.tabs[tab.id] = navButton
-- Create content panel - positioned to the right of navigation with responsive sizing
-- Increased top margin to -35 to ensure proper clearance of header bar
local panel = CreateFrame("Frame", "HealIQPanel" .. tab.id, parent)
panel:SetPoint("TOPLEFT", parent, "TOPLEFT", navWidth + 20, -35)
panel:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", -10, 40)
panel:Hide()
optionsFrame.tabPanels[tab.id] = panel
end
-- Create content for each tab
self:CreateGeneralTab(optionsFrame.tabPanels.general)
self:CreateDisplayTab(optionsFrame.tabPanels.display)
self:CreateRulesTab(optionsFrame.tabPanels.rules)
self:CreateStrategyTab(optionsFrame.tabPanels.strategy)
self:CreateQueueTab(optionsFrame.tabPanels.queue)
self:CreateStatisticsTab(optionsFrame.tabPanels.statistics)
-- Show first tab by default
self:ShowOptionsTab("general")
end
function UI:ShowOptionsTab(tabId)
-- Hide all panels and reset navigation button states
for id, panel in pairs(optionsFrame.tabPanels) do
panel:Hide()
-- Reset button appearance for inactive navigation items
local navButton = optionsFrame.tabs[id]
navButton:SetAlpha(0.8)
navButton:SetNormalFontObject("GameFontNormal")
end
-- Show selected panel and mark navigation item as active
if optionsFrame.tabPanels[tabId] then
optionsFrame.tabPanels[tabId]:Show()
-- Highlight the active navigation button
local activeButton = optionsFrame.tabs[tabId]
activeButton:SetAlpha(1.0)
activeButton:SetNormalFontObject("GameFontHighlight")
-- Track the active tab for hover effects
optionsFrame.activeTab = tabId
end
end
function UI:CreateGeneralTab(panel)
local yOffset = -5 -- Reduced from -10 to provide more space at top
-- General Settings Section
local generalHeader = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
generalHeader:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
generalHeader:SetText("General Settings")
generalHeader:SetTextColor(1, 0.8, 0, 1)
yOffset = yOffset - 35
-- Enable/Disable checkbox
local enableCheck = createCheckbox(panel, "HealIQEnableCheck", "Enable HealIQ", yOffset,
function(self)
if HealIQ.db then
HealIQ.db.enabled = self:GetChecked()
if HealIQ.UI then
HealIQ.UI:SetEnabled(HealIQ.db.enabled)
end
end
end,
{title = "Enable HealIQ", description = "Enable or disable the entire HealIQ addon.\nWhen disabled, no suggestions will be shown."}
)
optionsFrame.enableCheck = enableCheck
yOffset = yOffset - 30
-- Debug mode checkbox
local debugCheck = createCheckbox(panel, "HealIQDebugCheck", "Enable Debug Mode", yOffset,
function(self)
if HealIQ.db then
HealIQ.db.debug = self:GetChecked()
HealIQ.debug = HealIQ.db.debug
if HealIQ.debug then
HealIQ:Print("Debug mode enabled")
else
HealIQ:Print("Debug mode disabled")
end
end
end,
{title = "Enable Debug Mode", description = "Enable additional debug output and test features.\nUseful for troubleshooting issues."}
)
optionsFrame.debugCheck = debugCheck
yOffset = yOffset - 30
-- Session stats checkbox
local statsCheck = CreateFrame("CheckButton", "HealIQStatsCheck", panel, "UICheckButtonTemplate")
statsCheck:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
statsCheck.text = statsCheck:CreateFontString(nil, "OVERLAY", "GameFontNormal")
statsCheck.text:SetPoint("LEFT", statsCheck, "RIGHT", 5, 0)
statsCheck.text:SetText("Session Statistics")
statsCheck:SetScript("OnClick", function(self)
local enabled = self:GetChecked()
if enabled then
if not HealIQ.sessionStats then
HealIQ.sessionStats = {
startTime = time(),
suggestions = 0,
rulesProcessed = 0,
errorsLogged = 0,
eventsHandled = 0,
}
elseif not HealIQ.sessionStats.startTime then
HealIQ.sessionStats.startTime = time()
end
HealIQ:Message("Session statistics enabled")
else
if HealIQ.sessionStats then
HealIQ.sessionStats.startTime = nil
end
HealIQ:Message("Session statistics disabled")
end
end)
self:AddTooltip(statsCheck, "Session Statistics", "Track session statistics like suggestions generated, rules processed, etc.\nView statistics with /healiq status or /healiq dump.")
optionsFrame.statsCheck = statsCheck
yOffset = yOffset - 50
-- UI Position Section
local positionHeader = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
positionHeader:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
positionHeader:SetText("Position Settings")
positionHeader:SetTextColor(1, 0.8, 0, 1)
yOffset = yOffset - 35
-- UI Position buttons
local resetPosButton = CreateFrame("Button", "HealIQResetPosButton", panel, "UIPanelButtonTemplate")
resetPosButton:SetSize(120, 22)
resetPosButton:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
resetPosButton:SetText("Reset UI Position")
resetPosButton:SetScript("OnClick", function()
if HealIQ.UI then
HealIQ.UI:ResetPosition()
end
end)
self:AddTooltip(resetPosButton, "Reset UI Position", "Moves the main HealIQ display back to the center of the screen.")
yOffset = yOffset - 30
local lockButton = CreateFrame("Button", "HealIQLockButton", panel, "UIPanelButtonTemplate")
lockButton:SetSize(100, 22)
lockButton:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
lockButton:SetText("Lock UI")
lockButton:SetScript("OnClick", function()
if HealIQ.UI then
HealIQ.UI:ToggleLock()
UI:UpdateOptionsFrame()
end
end)
self:AddTooltip(lockButton, "Lock/Unlock UI Position", "When unlocked, you can drag the main UI to move it.\nRight-click the main UI to toggle lock state.")
optionsFrame.lockButton = lockButton
yOffset = yOffset - 30
-- Frame positioning indicator checkbox
local showFrameCheck = CreateFrame("CheckButton", "HealIQShowFrameCheck", panel, "UICheckButtonTemplate")
showFrameCheck:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
showFrameCheck.text = showFrameCheck:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showFrameCheck.text:SetPoint("LEFT", showFrameCheck, "RIGHT", 5, 0)
showFrameCheck.text:SetText("Show frame positioning border")
showFrameCheck:SetScript("OnClick", function(self)
updateUISetting("showPositionBorder", self:GetChecked(), function()
if HealIQ.UI then
HealIQ.UI:UpdatePositionBorder()
end
end)
end)
self:AddTooltip(showFrameCheck, "Show Frame Position Border", "Shows a visible border around the main frame for easier positioning.\nHelpful when arranging the UI layout.")
optionsFrame.showFrameCheck = showFrameCheck
yOffset = yOffset - 30
-- Minimap button reset
local minimapResetButton = CreateFrame("Button", "HealIQMinimapResetButton", panel, "UIPanelButtonTemplate")
minimapResetButton:SetSize(140, 22)
minimapResetButton:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
minimapResetButton:SetText("Reset Minimap Icon")
minimapResetButton:SetScript("OnClick", function()
if HealIQ.UI then
HealIQ.UI:ResetMinimapPosition()
end
end)
self:AddTooltip(minimapResetButton, "Reset Minimap Icon Position", "Moves the minimap icon back to its default position.")
end
function UI:CreateDisplayTab(panel)
local yOffset = -5 -- Reduced from -10 to provide more space at top
-- Display Settings Section
local displayHeader = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
displayHeader:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
displayHeader:SetText("Display Settings")
displayHeader:SetTextColor(1, 0.8, 0, 1)
yOffset = yOffset - 35
-- UI Scale slider (Main UI)
local scaleSlider = createSlider(panel, "HealIQScaleSlider", yOffset, 0.5, 2.0, 0.1, "Main UI Scale",
function(self, value)
if HealIQ.UI then
HealIQ.UI:SetScale(value)
end
end,
{title = "Main UI Scale", description = "Adjust the scale of the main HealIQ display (0.5-2.0)."}
)
optionsFrame.scaleSlider = scaleSlider
yOffset = yOffset - 40
-- Display options
local showNameCheck = CreateFrame("CheckButton", "HealIQShowNameCheck", panel, "UICheckButtonTemplate")
showNameCheck:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
showNameCheck.text = showNameCheck:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showNameCheck.text:SetPoint("LEFT", showNameCheck, "RIGHT", 5, 0)
showNameCheck.text:SetText("Show spell names")
showNameCheck:SetScript("OnClick", function(self)
updateUISetting("showSpellName", self:GetChecked(), function()
if HealIQ.UI then
HealIQ.UI:SetShowSpellName(self:GetChecked())
end
end)
end)
self:AddTooltip(showNameCheck, "Show Spell Names", "Display the name of the suggested spell below the icon.")
optionsFrame.showNameCheck = showNameCheck
yOffset = yOffset - 30
local showCooldownCheck = CreateFrame("CheckButton", "HealIQShowCooldownCheck", panel, "UICheckButtonTemplate")
showCooldownCheck:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
showCooldownCheck.text = showCooldownCheck:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showCooldownCheck.text:SetPoint("LEFT", showCooldownCheck, "RIGHT", 5, 0)
showCooldownCheck.text:SetText("Show cooldown spirals")
showCooldownCheck:SetScript("OnClick", function(self)
updateUISetting("showCooldown", self:GetChecked(), function()
if HealIQ.UI then
HealIQ.UI:SetShowCooldown(self:GetChecked())
end
end)
end)
self:AddTooltip(showCooldownCheck, "Show Cooldown Spirals", "Display cooldown sweep animations on suggestion icons.")
optionsFrame.showCooldownCheck = showCooldownCheck
yOffset = yOffset - 30
local showIconCheck = CreateFrame("CheckButton", "HealIQShowIconCheck", panel, "UICheckButtonTemplate")
showIconCheck:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
showIconCheck.text = showIconCheck:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showIconCheck.text:SetPoint("LEFT", showIconCheck, "RIGHT", 5, 0)
showIconCheck.text:SetText("Show minimap icon")
showIconCheck:SetScript("OnClick", function(self)
updateUISetting("showIcon", self:GetChecked(), function()
if HealIQ.UI then
HealIQ.UI:UpdateMinimapButtonVisibility()
end
end)
end)
self:AddTooltip(showIconCheck, "Show Minimap Icon", "Display the HealIQ minimap button.")
optionsFrame.showIconCheck = showIconCheck
yOffset = yOffset - 30
-- Targeting display options
local showTargetingCheck = CreateFrame("CheckButton", "HealIQShowTargetingCheck", panel, "UICheckButtonTemplate")
showTargetingCheck:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, yOffset)
showTargetingCheck.text = showTargetingCheck:CreateFontString(nil, "OVERLAY", "GameFontNormal")
showTargetingCheck.text:SetPoint("LEFT", showTargetingCheck, "RIGHT", 5, 0)
showTargetingCheck.text:SetText("Show targeting suggestions")
showTargetingCheck:SetScript("OnClick", function(self)
updateUISetting("showTargeting", self:GetChecked(), function()