-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.lua
More file actions
1696 lines (1520 loc) · 68.8 KB
/
ui.lua
File metadata and controls
1696 lines (1520 loc) · 68.8 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
-- UI logic functions moved from core.lua
local ADDON_NAME, private = ...
---@type MyCheatSheet
local MyCheatSheet = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME);
---@type AceLocale-3.0
local AceLocale = LibStub("AceLocale-3.0")
---@type table<string, string>
local L = AceLocale:GetLocale(ADDON_NAME)
-- =============================
-- Creación de la UI principal
-- =============================
--- Crea la interfaz principal del cheat sheet
function MyCheatSheet:CreateCheatSheetUI()
-- BasicFrameTemplateWithInset
-- BackdropTemplateMixin and "BackdropTemplate"
local frame = CreateFrame("Frame", "MyCheatSheetFrame", UIParent, "BackdropTemplate");
-- Intentar restaurar la posición guardada
---@type FramePosition
local pos = self.db and self.db.profile and self.db.profile.ui and self.db.profile.ui.position
if pos and pos.point and pos.x and pos.y then
frame:SetPoint(pos.point, UIParent, pos.point, pos.x, pos.y)
else
frame:SetPoint("CENTER")
self:DebugPrint("No FramePosition", self.db, self.db.profile, self.db.profile.ui, self.db.profile.ui.position)
end
frame:SetSize(680, 580);
frame:Hide();
-- Aplica el fondo según la opción de fondo opaco
self.MyCheatSheetFrame = frame;
self:UpdateMainPanelBackdrop()
frame:SetMovable(true);
frame:EnableMouse(true);
frame:SetClampedToScreen(true);
frame:RegisterForDrag("LeftButton");
frame:SetScript("OnDragStart", frame.StartMoving);
frame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing();
MyCheatSheet:SaveFramePosition();
end);
if bResizableFrame then
frame:SetResizable(true);
-- Crear un tirador para redimensionar en la esquina inferior derecha
local resizeHandle = CreateFrame("Button", nil, frame);
resizeHandle:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -6, 6);
resizeHandle:SetSize(16, 16);
-- Establecer textura del tirador
local texture = resizeHandle:CreateTexture(nil, "OVERLAY");
texture:SetTexture("Interface\\Tooltips\\UI-Tooltip-Resize");
texture:SetAllPoints(true);
resizeHandle:SetScript("OnMouseDown", function(self)
if IsMouseButtonDown("LeftButton") then
self:GetParent():StartSizing();
end
end);
resizeHandle:SetScript("OnMouseUp", function(self) self:GetParent():StopMovingOrSizing(); end);
end
-- Icono del addon en la esquina superior izquierda
local iconFrame = CreateFrame("Frame", nil, frame);
iconFrame:SetSize(24, 24);
iconFrame:SetPoint("TOPLEFT", 16, -16);
local iconTexture = iconFrame:CreateTexture(nil, "ARTWORK");
iconTexture:SetAllPoints(iconFrame);
iconTexture:SetTexture("Interface\\Icons\\INV_Scroll_03");
iconTexture:SetTexCoord(0.08, 0.92, 0.08, 0.92); -- Recortar bordes para mejor apariencia
local title = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
title:SetText(L["MY_CHEAT_SHEET"]);
title:SetPoint("TOP", 0, -10);
local titleFont = CreateFont("MyCheatSheetTitleFont");
titleFont:SetFont("Fonts\\FRIZQT__.TTF", 24, "OUTLINE"); -- Tamaño aumentado
title:SetFontObject(titleFont);
local closeButton = CreateFrame("Button", "MyCheatSheetTitleCloseButton", frame, "UIPanelCloseButton");
closeButton:SetPoint("TOPRIGHT", -12, -12);
closeButton:SetScript("OnClick", function()
frame:Hide();
end);
frame.closeButton = closeButton
-- Botón de edición de layout
local editLayoutButton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate")
editLayoutButton:SetSize(90, 24)
editLayoutButton:SetText(L["EDIT_LAYOUT"])
editLayoutButton:SetWidth(editLayoutButton:GetFontString():GetStringWidth() + 24)
editLayoutButton:SetPoint("RIGHT", closeButton, "LEFT", -8, 0)
editLayoutButton:SetScript("OnClick", function()
if MyCheatSheet.isLayoutEditMode then
StaticPopup_Show("MYCHEATSHEET_CONFIRM_SAVE_LAYOUT")
else
MyCheatSheet.editLayoutButton = editLayoutButton
MyCheatSheet:ToggleLayoutEditMode()
end
end)
frame.editLayoutButton = editLayoutButton
-- Mostrar/ocultar según config
if not (MyCheatSheet.config:GetShowLayoutEditButton()) then
editLayoutButton:Hide()
else
editLayoutButton:Show()
end
-- Asegura que el texto del botón refleje el estado al mostrar la ventana
frame:HookScript("OnShow", function(self)
if self.editLayoutButton then
self.editLayoutButton:SetText(MyCheatSheet.isLayoutEditMode and L["SAVE_LAYOUT"] or L["EDIT_LAYOUT"])
if MyCheatSheet.config:GetShowLayoutEditButton() then
self.editLayoutButton:Show()
else
self.editLayoutButton:Hide()
end
end
end)
frame:SetSize(700, 680);
tinsert(UISpecialFrames, "MyCheatSheetFrame");
-- Refuerzo: asegurar que el botón esté siempre visible y habilitado al mostrar la ventana
frame:HookScript("OnShow", function(self)
if self.closeButton then
self.closeButton:Show()
self.closeButton:Enable()
end
end)
end
-- Permite actualizar el fondo del panel principal dinámicamente
function MyCheatSheet:UpdateMainPanelBackdrop()
local frame = self.MyCheatSheetFrame
if not frame then return end
if self.config:GetOpaqueBackground() then
frame:SetBackdrop({
-- Interface\\DialogFrame\UI-DialogBox-Background
-- Interface\\FrameGeneral\\UI-Background-Marble
bgFile = "Interface\\FrameGeneral\\UI-Background-Marble",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 },
})
else
frame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 },
})
end
end
-- =============================
-- Contenido y dropdowns de la UI
-- =============================
--- Crea el contenido inicial de la interfaz de usuario (dropdowns, scroll frame).
function MyCheatSheet:CreateUIContent()
local parent = self.MyCheatSheetFrame;
if parent == nil then
self:DebugPrint("CreateUIContent", "parent == nil")
return
end
local topOffset = -50;
local leftPadding = 20;
local padding = 10;
local dropdownWidth = 180;
local xOffset = padding + dropdownWidth + padding * 3;
-- Etiqueta y Dropdown de Clase
local classLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal");
classLabel:SetText(L["SELECT_CLASS"]);
classLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", leftPadding, topOffset);
classLabel:SetJustifyH("LEFT");
self.classDropdown = CreateFrame("Frame", nil, parent, "UIDropDownMenuTemplate");
self.classDropdown:SetPoint("TOPLEFT", classLabel, "BOTTOMLEFT", -20, -10); -- Espaciado reducido
UIDropDownMenu_SetWidth(self.classDropdown, dropdownWidth);
UIDropDownMenu_SetText(self.classDropdown, "");
-- Etiqueta y Dropdown de Especialización
local specLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal");
specLabel:SetText(L["SELECT_SPECIALIZATION"]);
specLabel:SetPoint("LEFT", classLabel, "LEFT", xOffset, 0);
specLabel:SetJustifyH("LEFT");
self.specDropdown = CreateFrame("Frame", nil, parent, "UIDropDownMenuTemplate");
self.specDropdown:SetPoint("TOPLEFT", specLabel, "BOTTOMLEFT", -20, -10); -- Espaciado reducido
UIDropDownMenu_SetWidth(self.specDropdown, dropdownWidth);
UIDropDownMenu_SetText(self.specDropdown, "");
-- Etiqueta y Dropdown de Contenido
local contentLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal");
contentLabel:SetText(L["SELECT_CONTENT"]);
contentLabel:SetPoint("LEFT", specLabel, "LEFT", xOffset, 0);
contentLabel:SetJustifyH("LEFT");
self.contentDropdown = CreateFrame("Frame", nil, parent, "UIDropDownMenuTemplate");
self.contentDropdown:SetPoint("TOPLEFT", contentLabel, "BOTTOMLEFT", -20, -10); -- Espaciado reducido
UIDropDownMenu_SetWidth(self.contentDropdown, dropdownWidth);
UIDropDownMenu_SetText(self.contentDropdown, "");
local scrollFrame = CreateFrame("ScrollFrame", "MyCheatSheetScrollFrame", parent, "UIPanelScrollFrameTemplate");
scrollFrame:SetPoint("TOPLEFT", self.classDropdown, "BOTTOMLEFT", leftPadding, -15);
scrollFrame:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", -35, 50);
local contentFrame = CreateFrame("Frame", "MyCheatSheetContentFrame", scrollFrame);
contentFrame:SetSize(scrollFrame:GetWidth(), scrollFrame:GetHeight());
contentFrame:SetPoint("TOPLEFT");
scrollFrame:SetScrollChild(contentFrame);
self.scrollFrame = scrollFrame;
self.contentFrame = contentFrame;
-- Import/Export Button
local importExportButton = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate");
importExportButton:SetText(L["IMPORT_EXPORT"]);
importExportButton:SetSize(140, 25);
importExportButton:SetWidth(importExportButton:GetFontString():GetStringWidth() + 24);
importExportButton:SetPoint("BOTTOMLEFT", parent, "BOTTOMLEFT", leftPadding, 20);
importExportButton:SetScript("OnClick", function() MyCheatSheet:OpenImportExportPanel(); end);
importExportButton:Show();
-- Nota sobre Import/Export
local importExportNote = parent:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
importExportNote:SetText(L["IMPORT_EXPORT_NOTE"])
importExportNote:SetTextColor(1, 0.95, 0.5, 1)
importExportNote:SetJustifyH("LEFT")
importExportNote:SetWidth(500)
importExportNote:SetHeight(50)
importExportNote:SetPoint("TOPLEFT", importExportButton, "RIGHT", 10, 25);
-- importExportNote:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", -35, 45)
--[[ Edit Button (deshabilitado para futuras versiones)
local editButton = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate");
editButton:SetText(L["EDIT"]);
editButton:SetSize(80, 25);
editButton:SetPoint("LEFT", importExportButton, "RIGHT", 10, 0);
editButton:SetScript("OnClick", function() MyCheatSheet:OpenEditPanel(); end);
editButton:Hide();
]]--
end
-- =============================
-- Dropdowns: actualización y lógica de selección
-- =============================
--- Actualiza todos los dropdowns
function MyCheatSheet:UpdateDropdowns()
self:UpdateClassDropdown();
end
--- Apply ClassDropdown selection and update related dropdowns
--- @param info UIDropDownMenuInfo
local function SelectClassDropdown(info)
if MyCheatSheet.selectedClass then
local classInfo = C_CreatureInfo.GetClassInfo(MyCheatSheet.selectedClass);
if classInfo then
UIDropDownMenu_SetText(MyCheatSheet.classDropdown, classInfo.className);
end
-- Preseleccionar primer spec
local classSpecs = MyCheatSheet.data.sheets[MyCheatSheet.selectedClass]
if classSpecs then
local firstSpec = nil
for specID in pairs(classSpecs) do
firstSpec = specID; break
end
MyCheatSheet.selectedSpec = firstSpec
-- Preseleccionar primer content
if firstSpec and classSpecs[firstSpec] then
local firstContent = nil
for contentKey in pairs(classSpecs[firstSpec]) do
firstContent = contentKey; break
end
MyCheatSheet.selectedContent = firstContent
else
MyCheatSheet.selectedContent = nil
end
else
MyCheatSheet.selectedSpec = nil
MyCheatSheet.selectedContent = nil
end
end
-- Actualizar dropdowns
MyCheatSheet:UpdateSpecDropdown();
MyCheatSheet:UpdateContentDropdown();
end
--- Actualiza el dropdown de clases
function MyCheatSheet:UpdateClassDropdown()
UIDropDownMenu_Initialize(self.classDropdown, function(frame, level, menuList)
for classID in pairs(MyCheatSheet.data.sheets) do
local classInfo = C_CreatureInfo.GetClassInfo(classID);
if classInfo then
local info = UIDropDownMenu_CreateInfo()
local classFile = classInfo.classFile
local color = RAID_CLASS_COLORS and classFile and RAID_CLASS_COLORS[classFile] or {r=1,g=1,b=1}
local colorCode = string.format("|cff%02x%02x%02x", color.r*255, color.g*255, color.b*255)
info.text = colorCode .. classInfo.className .. "|r"
info.value = classID;
info.func = function(frame, arg1, arg2)
MyCheatSheet.selectedClass = frame.value;
MyCheatSheet.selectedSpec = nil;
MyCheatSheet.selectedContent = nil;
SelectClassDropdown(frame);
end;
info.checked = (classID == MyCheatSheet.selectedClass);
UIDropDownMenu_AddButton(info, level);
end
end
end);
if self.selectedClass then
self:DebugPrint("SelectClassDefault", self.selectedClass)
local classInfo = C_CreatureInfo.GetClassInfo(self.selectedClass);
if classInfo then
UIDropDownMenu_SetText(self.classDropdown, classInfo.className);
end
end
self:UpdateSpecDropdown();
end
--- Apply SpecDropdown selection and update related dropdowns
---@param info UIDropDownMenuInfo
local function SelectSpecDropdown(info)
MyCheatSheet:DebugPrint("SelectSpecDropdown", info.value)
UIDropDownMenu_SetText(MyCheatSheet.specDropdown, info.text);
if MyCheatSheet.selectedContent == nil then
UIDropDownMenu_SetText(MyCheatSheet.contentDropdown, L["SELECT_CONTENT"]);
end
if MyCheatSheet.selectedClass and MyCheatSheet.selectedSpec then
local _, specLocal = GetSpecializationInfoByID(MyCheatSheet.selectedSpec);
if specLocal then
UIDropDownMenu_SetText(MyCheatSheet.specDropdown, specLocal);
end
end
MyCheatSheet:UpdateContentSelection();
end
--- Actualiza el dropdown de especialización
function MyCheatSheet:UpdateSpecDropdown()
UIDropDownMenu_Initialize(self.specDropdown, function(self, level, menuList)
if MyCheatSheet.selectedClass and MyCheatSheet.data.sheets[MyCheatSheet.selectedClass] then
for specID in pairs(MyCheatSheet.data.sheets[MyCheatSheet.selectedClass]) do
local _, specLocal, _, icon = GetSpecializationInfoByID(specID);
if specLocal then
local info = UIDropDownMenu_CreateInfo()
local iconMarkup = icon and ("|T"..icon..":18:18:0:0:64:64:4:60:4:60|t ") or ""
info.text = iconMarkup .. specLocal;
info.value = specID;
info.func = function(frame, arg1, arg2)
MyCheatSheet.selectedSpec = frame.value;
SelectSpecDropdown(frame);
end;
info.checked = (specID == MyCheatSheet.selectedSpec);
UIDropDownMenu_AddButton(info, level);
end
end
end
end);
if self.selectedClass and self.selectedSpec then
self:DebugPrint("SelectSpecDefault", self.selectedSpec)
local _, specLocal = GetSpecializationInfoByID(self.selectedSpec);
if specLocal then
UIDropDownMenu_SetText(self.specDropdown, specLocal);
end
end
self:UpdateContentSelection();
end
--- Actualiza el dropdown de contenido
function MyCheatSheet:UpdateContentSelection()
local selectedClass = self.selectedClass;
local selectedSpec = self.selectedSpec;
if selectedClass and selectedSpec then
local currentSpecData = self.data.sheets[selectedClass][selectedSpec];
-- Verificar si la clave de contenido actual sigue siendo válida para la nueva especialización
if not self.selectedContent or not currentSpecData.statsByContent[self.selectedContent] then
-- Si no es válida, selecciona la primera clave disponible
local firstContentKey = nil;
for contentKey in pairs(currentSpecData.statsByContent) do
firstContentKey = contentKey;
break;
end
self.selectedContent = firstContentKey;
if firstContentKey then
--**self:DebugPrint("New selected content:", firstContentKey)
end
end
end
self:UpdateContentDropdown();
end
--- Maneja la selección de contenido
--- @param info UIDropDownMenuInfo
local function SelectContentDropdown(info)
UIDropDownMenu_SetText(MyCheatSheet.contentDropdown, info.text);
MyCheatSheet:UpdateUI();
end
--- Actualiza el dropdown de contenido
function MyCheatSheet:UpdateContentDropdown()
UIDropDownMenu_Initialize(self.contentDropdown, function(self, level, menuList)
if MyCheatSheet.selectedClass and MyCheatSheet.selectedSpec and MyCheatSheet.data.sheets[MyCheatSheet.selectedClass][MyCheatSheet.selectedSpec].statsByContent then
for contentKey in pairs(MyCheatSheet.data.sheets[MyCheatSheet.selectedClass][MyCheatSheet.selectedSpec].statsByContent) do
local info = UIDropDownMenu_CreateInfo()
info.text = MyCheatSheet.contentKeysToNames[contentKey] or contentKey;
info.value = contentKey;
info.func = function(frame, arg1, arg2)
MyCheatSheet.selectedContent = frame.value;
SelectContentDropdown(info);
end;
info.checked = (contentKey == MyCheatSheet.selectedContent);
UIDropDownMenu_AddButton(info, level);
end
end
end);
if self.selectedClass and self.selectedSpec and self.selectedContent then
self:DebugPrint("SelectContentDefault", self.selectedContent)
local contentText = self.contentKeysToNames[self.selectedContent] or self.selectedContent;
UIDropDownMenu_SetText(self.contentDropdown, contentText);
end
MyCheatSheet:UpdateUI();
end
-- =============================
-- Renderizado dinámico de secciones según layout
-- =============================
--- Actualiza toda la interfaz de usuario con los datos actuales
function MyCheatSheet:UpdateUI()
local selectedClass = self.selectedClass;
local selectedSpec = self.selectedSpec;
--- @type string : contentKeysToNames
local selectedContent = self.selectedContent;
--**self:DebugPrint("UpdateUI", selectedClass, selectedSpec, selectedContent)
-- Limpiar el contenido anterior
for _, child in ipairs({ self.contentFrame:GetChildren() }) do
child:Hide();
end
local yOffset = 0;
local padding = 3;
local specData = nil;
local statData = nil;
local isCustomStats
if selectedClass and selectedSpec and MyCheatSheet.data.sheets[selectedClass] and MyCheatSheet.data.sheets[selectedClass][selectedSpec] then
specData = MyCheatSheet.data.sheets[selectedClass][selectedSpec];
if selectedContent and specData.statsByContent[selectedContent] then
statData, isCustomStats = self:GetStatsData(selectedClass, selectedSpec, selectedContent);
end
end
if not specData then
if self.textNoDataSelected == nil then
self.textNoDataSelected = self.contentFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
end
self.textNoDataSelected:SetPoint("TOPLEFT", 20, -10);
self.textNoDataSelected:SetText(L["NO_DATA_SELECTED"]);
self.textNoDataSelected:Show();
return;
else
if self.textNoDataSelected then
self.textNoDataSelected:Hide();
end
end
-- Renderizado dinámico según layout
local layout = self.db.profile.layout
local sections = layout and layout.sections
local visibleCount = MyCheatSheet:GetVisibleSectionCount()
self:SetVisibleSectionCount(visibleCount)
local pintadas = 0
for idx, section in ipairs(sections) do
if section.visible or self.isLayoutEditMode then
pintadas = pintadas + 1
local isFirst = idx == 1
local isLast = idx == #sections
local sectionYOffset = yOffset
-- Render sección según id
local sectionFrame = nil
if section.id == consts.SECTION_IDS.STATS and statData then
local sectionFrameHeight, sectionFrame = self:CreateStatPriorityRowWithCustomIcon(self.contentFrame, statData.statsPriority, yOffset, L["STAT_PRIORITY"], isCustomStats);
yOffset = yOffset + sectionFrameHeight;
if self.isLayoutEditMode and sectionFrame then
-- Si la sección está oculta, atenuar ligeramente
if not section.visible then
sectionFrame:SetAlpha(0.4)
else
sectionFrame:SetAlpha(1)
end
self:CreateSectionEditButtons(sectionFrame, 0, section.id, isFirst, isLast, section.visible)
end
yOffset = yOffset + padding;
elseif section.id == consts.SECTION_IDS.WEAPONS then
local weaponData = {};
local bestWeapons, isCustomBis = self:GetSectionData("weapons", "bestInSlot")
if bestWeapons and bestWeapons.itemIDs and #bestWeapons.itemIDs > 0 then
tinsert(weaponData, { title = L["BEST_IN_SLOT"], itemIDs = bestWeapons.itemIDs, isCustom = isCustomBis });
end
local altWeapons, isCustomAlt = self:GetSectionData("weapons", "alternatives")
if altWeapons and altWeapons.itemIDs and #altWeapons.itemIDs > 0 then
tinsert(weaponData, { title = L["ALTERNATIVES"], itemIDs = altWeapons.itemIDs, isCustom = isCustomAlt });
end
if #weaponData > 0 or self.isLayoutEditMode then
local sectionFrameHeight, frame = self:CreateItemSection(self.contentFrame, yOffset, L["WEAPONS"], weaponData);
yOffset = yOffset + sectionFrameHeight;
sectionFrame = frame
yOffset = yOffset + padding;
end
elseif section.id == consts.SECTION_IDS.TRINKETS then
local trinketData = {};
local bestTrinkets, isCustomBisTrinkets = self:GetSectionData("trinkets", "bestInSlot")
if bestTrinkets and bestTrinkets.itemIDs and #bestTrinkets.itemIDs > 0 then
tinsert(trinketData, { title = L["BEST_IN_SLOT"], itemIDs = bestTrinkets.itemIDs, isCustom = isCustomBisTrinkets });
end
local altTrinkets, isCustomAltTrinkets = self:GetSectionData("trinkets", "alternatives")
if altTrinkets and altTrinkets.itemIDs and #altTrinkets.itemIDs > 0 then
tinsert(trinketData, { title = L["ALTERNATIVES"], itemIDs = altTrinkets.itemIDs, isCustom = isCustomAltTrinkets });
end
if #trinketData > 0 or self.isLayoutEditMode then
local sectionFrameHeight, frame = self:CreateItemSection(self.contentFrame, yOffset, L["TRINKETS"], trinketData);
yOffset = yOffset + sectionFrameHeight;
sectionFrame = frame
yOffset = yOffset + padding;
end
elseif section.id == consts.SECTION_IDS.CONSUMABLES then
local consumablesItems, isCustomConsumables = self:GetSectionData("consumables")
if (consumablesItems and consumablesItems.itemIDs and #consumablesItems.itemIDs > 0) or self.isLayoutEditMode then
local consumablesData = {
{ title = "", itemIDs = consumablesItems and consumablesItems.itemIDs or {}, isCustom = isCustomConsumables },
};
local sectionFrameHeight, frame = self:CreateItemSection(self.contentFrame, yOffset, L["CONSUMABLES"], consumablesData);
yOffset = yOffset + sectionFrameHeight;
sectionFrame = frame
yOffset = yOffset + padding;
end
elseif section.id == consts.SECTION_IDS.TIER then
local tierData = {};
local bestInSlotTier, isCustomTierBis = self:GetSectionData("tier", "bestInSlot");
if bestInSlotTier and bestInSlotTier.itemIDs and #bestInSlotTier.itemIDs > 0 then
tinsert(tierData, { title = L["BEST_IN_SLOT"], itemIDs = bestInSlotTier.itemIDs, isCustom = isCustomTierBis });
end
if #tierData > 0 or self.isLayoutEditMode then
local sectionFrameHeight, frame = self:CreateItemSection(self.contentFrame, yOffset, L["TIER"], tierData);
yOffset = yOffset + sectionFrameHeight;
sectionFrame = frame
yOffset = yOffset + padding;
end
end
-- Botones de edición de layout
if self.isLayoutEditMode and sectionFrame then
-- Si la sección está oculta, atenuar ligeramente
if not section.visible then
sectionFrame:SetAlpha(0.4)
else
sectionFrame:SetAlpha(1)
end
-- Crear botones de edición para la sección
self:CreateSectionEditButtons(sectionFrame, 0, section.id, isFirst, isLast, section.visible)
end
end
end
-- Agregar información del autor y fecha de actualización al final
if specData and (specData.author or specData.updated or specData.patchVersion) then
local authorData = self:GetAuthorData(selectedClass, selectedSpec, selectedContent)
yOffset = yOffset + self:CreateSheetInfoFooter(self.contentFrame, yOffset, authorData);
end
local extraPadding = 0;
self.contentFrame:SetSize(self.scrollFrame:GetWidth() - extraPadding, yOffset);
end
--- Crea el pie de página con información del autor, fecha de actualización y más
---@param parent Frame
---@param yOffset number
---@param authorData AuthorData
---@return number footerHeight La altura del pie de página creado.
function MyCheatSheet:CreateSheetInfoFooter(parent, yOffset, authorData)
local footerHeight = 36;
local footerFrame = CreateFrame("Frame", "SheetFooterFrame", parent, "BackdropTemplate");
footerFrame:SetPoint("TOPLEFT", parent, "TOPLEFT", 10, -yOffset);
footerFrame:SetSize(parent:GetWidth() - 20, footerHeight);
footerFrame:Show();
footerFrame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
footerFrame:SetBackdropColor(0.2, 0.2, 0.2, 0.5);
-- Define tus colores
local clrBlue = "|cff4da6ff"
local clrYellow = "|cfff0d000"
local clrGreen = "|cff00ff00"
local clrWhite = "|cffffffff"
local clrReset = "|r"
local infoText = ""
local patchText = ""
-- Usar patchVersion como campo principal
if authorData.patchVersion then
local version = tostring(authorData.patchVersion)
local title = consts.PATCH_TITLES[version]
patchText = L["PATCH"] .. " " .. clrBlue .. version .. clrReset
if title and title ~= "" then
patchText = patchText .. ": " .. clrWhite .. title .. clrReset
end
end
if patchText ~= "" then
infoText = patchText
end
if authorData.author then
if infoText ~= "" then
infoText = infoText .. " | "
end
infoText = infoText .. L["AUTHOR"] .. ": " .. clrGreen .. authorData.author .. clrReset
end
if authorData.updated then
local updatedText = L["UPDATED"] .. ": " .. clrYellow .. authorData.updated .. clrReset
if infoText ~= "" then
infoText = infoText .. " | " .. updatedText
else
infoText = updatedText
end
end
if infoText ~= "" then
local infoString = footerFrame:CreateFontString("FooterFrameInfoString", "OVERLAY", "GameFontNormal")
infoString:SetText(infoText)
infoString:SetJustifyH("CENTER")
infoString:SetTextColor(0.7, 0.7, 0.7, 1)
local padding = 8
infoString:SetPoint("TOPLEFT", footerFrame, "TOPLEFT", padding, -padding)
infoString:SetPoint("BOTTOMRIGHT", footerFrame, "BOTTOMRIGHT", -padding, padding)
end
return footerHeight
end
--- Crea una fila de prioridad de estadísticas en la UI, mostrando un icono de estrella si la info es personalizada
---@param parent Frame
---@param statGroups table<number, MyCheatSheetStatGroup>
---@param yOffset number
---@param title string
---@param isCustomStats boolean Si es true, muestra el icono de estrella a la izquierda del título
---@return number rowHeight La altura de la fila creada.
---@return Frame rowFrame El frame creado para la fila.
function MyCheatSheet:CreateStatPriorityRowWithCustomIcon(parent, statGroups, yOffset, title, isCustomStats)
local rowHeight = 50;
local rowFrame = CreateFrame("Frame", nil, parent, "BackdropTemplate");
rowFrame:SetPoint("TOPLEFT", parent, "TOPLEFT", 10, -yOffset);
rowFrame:SetSize(parent:GetWidth() - 20, rowHeight);
rowFrame:Show();
rowFrame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
});
rowFrame:SetBackdropColor(0.2, 0.2, 0.2, 0.5);
local titleYOffset = -8
local titleXOffset = 4
local starIcon;
if isCustomStats then
starIcon = rowFrame:CreateTexture(nil, "OVERLAY");
starIcon:SetTexture("Interface\\COMMON\\ReputationStar-Glow");
starIcon:SetSize(20, 20);
starIcon:SetPoint("TOPLEFT", 5, -4);
starIcon:SetAlpha(1);
titleXOffset = titleXOffset + 20;
-- Tooltip
starIcon:EnableMouse(true)
starIcon:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:AddLine(L["CUSTOM_INFO"], 1, 0.82, 0, 1);
GameTooltip:Show();
end)
starIcon:SetScript("OnLeave", function(self)
GameTooltip:Hide();
end)
end
local titleString = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
titleString:SetText(title);
titleString:SetTextColor(1.0, 1.0, 1.0);
titleString:SetPoint("TOPLEFT", titleXOffset, titleYOffset);
-- Mostrar botones de edición si la configuración lo permite
if self.config:GetShowDataEditButtons() then
local editStatsButton = CreateFrame("Button", nil, rowFrame, "UIPanelButtonTemplate")
editStatsButton:SetText(L["EDIT_STATS"])
editStatsButton:SetSize(50, 20)
editStatsButton:SetPoint("TOPRIGHT", rowFrame, "TOPRIGHT", -4, -4)
editStatsButton:SetScript("OnClick", function()
self:OpenStatsEditor()
end)
end
local function GetStatName(stat, bUseAbrev)
local sText =L[stat]
if bUseAbrev then
sText = L[stat.."_ABBE"]
end
return sText
end
local xOffset = 24;
local statYOffset = -25;
local bUseAbrev = nil
for i, group in ipairs(statGroups) do
if bUseAbrev == nil then
bUseAbrev = group.percent
end
for j, stat in ipairs(group.stats) do
local statText = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
local sValue = GetStatName(stat, bUseAbrev)
statText:SetText(sValue);
statText:SetPoint("TOPLEFT", xOffset, statYOffset);
if consts.statColors[stat] then
statText:SetTextColor(consts.statColors[stat].r, consts.statColors[stat].g, consts.statColors[stat].b, consts.statColors[stat].a);
end
xOffset = xOffset + statText:GetWidth() + 5;
if j < #group.stats then
local separator = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
separator:SetText("=");
separator:SetPoint("TOPLEFT", xOffset, statYOffset);
xOffset = xOffset + separator:GetWidth() + 5;
end
end
if group.percent then
local percent = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
local sValue = string.format("(%d %%)", tonumber(group.percent))
percent:SetText(sValue);
percent:SetPoint("TOPLEFT", xOffset, statYOffset);
xOffset = xOffset + percent:GetWidth() + 5;
end
if group.operator and i < #statGroups then
local separator = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
separator:SetText(group.operator);
separator:SetPoint("TOPLEFT", xOffset, statYOffset);
xOffset = xOffset + separator:GetWidth() + 5;
end
end
return rowHeight, rowFrame;
end
--- Crea una fila de prioridad de estadísticas en la UI, mostrando un icono de estrella si la info es personalizada
---@param parent Frame
---@param statGroups table<number, MyCheatSheetStatGroup>
---@param yOffset number
---@param title string
---@return number rowHeight La altura de la fila creada.
function MyCheatSheet:CreateStatPriorityRow(parent, statGroups, yOffset, title)
local rowHeight = 50;
local rowFrame = CreateFrame("Frame", nil, parent, "BackdropTemplate");
rowFrame:SetPoint("TOPLEFT", parent, "TOPLEFT", 10, -yOffset);
rowFrame:SetSize(parent:GetWidth() - 20, rowHeight);
rowFrame:Show();
rowFrame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
});
rowFrame:SetBackdropColor(0.2, 0.2, 0.2, 0.5);
local titleString = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
titleString:SetText(title);
titleString:SetTextColor(1.0, 1.0, 1.0);
titleString:SetPoint("TOPLEFT", 5, -5);
-- Botón de edición de estadísticas
local editStatsButton = CreateFrame("Button", nil, rowFrame, "UIPanelButtonTemplate")
editStatsButton:SetText("Edit")
editStatsButton:SetSize(50, 20)
editStatsButton:SetPoint("TOPRIGHT", rowFrame, "TOPRIGHT", -10, -4)
editStatsButton:SetScript("OnClick", function()
self:OpenStatsEditor()
end)
local xOffset = 20;
local statYOffset = -25;
for i, group in ipairs(statGroups) do
for j, stat in ipairs(group.stats) do
local statText = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
statText:SetText(L[stat]);
statText:SetPoint("TOPLEFT", xOffset, statYOffset);
if self.statColors[stat] then
statText:SetTextColor(self.statColors[stat].r, self.statColors[stat].g, self.statColors[stat].b, self.statColors[stat].a);
end
xOffset = xOffset + statText:GetWidth() + 5;
if j < #group.stats then
local separator = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
separator:SetText("=");
separator:SetPoint("TOPLEFT", xOffset, statYOffset);
xOffset = xOffset + separator:GetWidth() + 5;
end
end
if group.operator and i < #statGroups then
local separator = rowFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
separator:SetText(group.operator);
separator:SetPoint("TOPLEFT", xOffset, statYOffset);
xOffset = xOffset + separator:GetWidth() + 5;
end
end
return rowHeight;
end
--- Crea una sección completa (un marco) con un título principal y subsecciones de ítems
---@param parent Frame
---@param yOffset number
---@param title string
---@param subsections table<number, table>
---@return number sectionHeight La altura de la sección creada.
---@return Frame sectionFrame Frame de la sección creada
function MyCheatSheet:CreateItemSection(parent, yOffset, title, subsections)
local itemSize = 40;
local itemPadding = 5;
local titleHeight = 0;
local subtitleHeight = 12;
local verticalPadding = 5;
local horizontalPadding = 15;
local sectionFrame = CreateFrame("Frame", nil, parent, "BackdropTemplate");
sectionFrame:SetPoint("TOPLEFT", parent, "TOPLEFT", 10, -yOffset);
sectionFrame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
});
sectionFrame:SetBackdropColor(0.2, 0.2, 0.2, 0.5);
local xOffset = 5
local titleString
local isCustom
if subsections and #subsections > 0 then
isCustom = subsections[1].isCustom
end
-- Añadir estrella si es custom
if isCustom then
local starIcon = sectionFrame:CreateTexture(nil, "OVERLAY")
starIcon:SetTexture("Interface\\COMMON\\ReputationStar-Glow")
starIcon:SetSize(20, 20)
starIcon:SetPoint("TOPLEFT", sectionFrame, "TOPLEFT", xOffset, -4)
starIcon:SetAlpha(1)
-- Tooltip
starIcon:EnableMouse(true)
starIcon:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(L["CUSTOM_INFO"], 1, 0.82, 0, 1)
GameTooltip:Show()
end)
starIcon:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
-- Dejar espacio para el icono
xOffset = xOffset + 20
end
local titleString = nil
if not MyCheatSheet.config:GetHideSectionTitles() then
titleString = sectionFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
titleString:SetText(title);
titleString:SetTextColor(1.0, 1.0, 1.0);
titleString:SetPoint("TOPLEFT", sectionFrame, "TOPLEFT", xOffset, -8)
titleHeight = 20;
end
-- Verificar si la sección tiene subsecciones
local hasSubsections = false
local hasAlternatives = false
-- Detectar si tiene estructura de subsecciones
if subsections and #subsections > 0 then
for _, subsection in ipairs(subsections) do
if subsection.title == L["BEST_IN_SLOT"] then
hasSubsections = true
elseif subsection.title == L["ALTERNATIVES"] then
hasAlternatives = true
end
end
end
-- Mostrar botones de edición si la configuración lo permite
if self.config:GetShowDataEditButtons() then
if hasSubsections then
-- SECCIONES CON SUBSECCIONES (Weapons, Trinkets, Tier)
local buttonWidth = 50
local buttonSpacing = 5
-- Botón BiS (PRIMERO)
local editBisButton = CreateFrame("Button", nil, sectionFrame, "UIPanelButtonTemplate")
editBisButton:SetText(L["BIS"])
editBisButton:SetSize(buttonWidth, 20)
editBisButton:SetPoint("TOPRIGHT", sectionFrame, "TOPRIGHT", -4, -4)
editBisButton:SetScript("OnClick", function()
self:OpenSimpleEditor(title, "bestInSlot")
end)
-- Botón Alt (SEGUNDO, solo si existe)
if hasAlternatives then
local editAltButton = CreateFrame("Button", nil, sectionFrame, "UIPanelButtonTemplate")
editAltButton:SetText(L["ALT"])
editAltButton:SetSize(buttonWidth, 20)
editAltButton:SetPoint("RIGHT", editBisButton, "LEFT", -buttonSpacing, 0)
editAltButton:SetScript("OnClick", function()
self:OpenSimpleEditor(title, "alternatives")
end)
end
else
-- SECCIONES SIN SUBSECCIONES (Consumables)
local editButton = CreateFrame("Button", nil, sectionFrame, "UIPanelButtonTemplate")
editButton:SetText(L["EDIT"])
editButton:SetSize(50, 20)
editButton:SetPoint("TOPRIGHT", sectionFrame, "TOPRIGHT", -4, -4)
editButton:SetScript("OnClick", function()
self:OpenSimpleEditor(title, "direct") -- Modo especial para consumables
end)
end
end
local currentHeight = titleHeight + verticalPadding;
local maxSubSectionHeight = 0;
local horizontalOffset = 20;
if subsections and #subsections > 0 then
for i, subSection in ipairs(subsections) do
local subSectionHeight = 0;
local currentSubYOffset = -currentHeight;
if subSection.title and subSection.title ~= "" then
local subtitleString = sectionFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal");
local subSection_title = subSection.title
if subSection.isCustom then
subSection_title = "|cffffff00*|r" .. subSection_title
end
subtitleString:SetText(subSection_title);
subtitleString:SetTextColor(0.8, 0.8, 0.8);
subtitleString:SetPoint("TOPLEFT", horizontalOffset, currentSubYOffset);
subSectionHeight = subSectionHeight + subtitleHeight + verticalPadding;
end
local itemYOffset = currentSubYOffset - subSectionHeight;
if not subSection.itemIDs or #subSection.itemIDs == 0 then
local noDataText = sectionFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall");
noDataText:SetText(L["NO_DATA_AVAILABLE"]);
noDataText:SetPoint("TOPLEFT", horizontalOffset, itemYOffset + 10);
subSectionHeight = subSectionHeight + subtitleHeight + verticalPadding;
else
for j, itemID in ipairs(subSection.itemIDs) do
local button = CreateFrame("Button", nil, sectionFrame);
button:SetSize(itemSize, itemSize);
button:SetPoint("TOPLEFT", horizontalOffset + (j-1) * (itemSize + itemPadding), itemYOffset);
local icon = button:CreateTexture(nil, "ARTWORK");
icon:SetAllPoints(button);
local _, itemType, itemSubType, itemEquipLoc, itemIcon, classID, subClassID = C_Item.GetItemInfoInstant(itemID)
icon:SetTexture(itemIcon);
button.itemID = itemID;