forked from Hydra9268/ZGESO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuideMenu.lua
1468 lines (1185 loc) · 39.6 KB
/
GuideMenu.lua
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
local ZGV = _G.ZGV
-----------------------------------------
-- INFORMATION
-- :SetPoint(POINT ORIGIN, UI reference, X, Y)
-----------------------------------------
-----------------------------------------
-- LOCAL REFERENCES
-----------------------------------------
local tinsert,tremove,sort,min,max,floor,type,pairs,ipairs,class = table.insert,table.remove,table.sort,math.min,math.max,math.floor,type,pairs,ipairs,_G.class
local print = ZGV.print
local CHAIN = ZGV.Utils.ChainCall
local ui = ZGV.UI
local wm = _G.WINDOW_MANAGER
local L = ZGV.L
local GuiRoot = _G.GuiRoot
local titlebar = _G.titlebar
local TOPLEFT, TOPRIGHT, BOTTOMLEFT, BOTTOMRIGHT, CENTER = _G.TOPLEFT, _G.TOPRIGHT, _G.BOTTOMLEFT, _G.BOTTOMRIGHT, _G.CENTER
local TOP, RIGHT, BOTTOM, LEFT = _G.TOP, _G.RIGHT, _G.BOTTOM, _G.LEFT
-----------------------------------------
-- LOCAL VARIABLES
-----------------------------------------
local Menu = {}
local Settings = {
opt_groups = {},
OptionUI = {},
}
local GuideMenu = {}
local BUTTON_HIGHLIGHT_TEXTURE = {1,1,1,.2}
local name = "ZygorMenu"
local GUIDEMENU_TAB_ID = "guides"
local SETTINGS_TAB_ID = "settings"
local DEFAULT_WIDTH = 800
local DEFAULT_HEIGHT = 500
local HEADER_HEIGHT = 60
local FOOTER_HEIGHT = 25
local LEFT_COLUMN_WIDTH = 250
local SCROLL_WIDTH = 15
local GUIDE_IMAGE_WIDTH = 512
local GUIDE_IMAGE_HEIGHT = 256
local OPTIONS_LEFT_OFFSET = 15
local OPTIONS_VERT_OFFSET = 5
local DEFAULT_ANCHOR= { CENTER, }
local MAX_LINES = 18
local GuideStatusColor = {
["SUGGESTED"] = "FFCC40",
["VALID"] = "40BF40",
["COMPLETE"] = "808080",
["INVALID"] = "E60000",
["HEADER"] = "FFFFFF",
["FOLDER"] = "FFFFFF",
}
-----------------------------------------
-- METATABLE SETUP
-----------------------------------------
setmetatable(Settings.OptionUI, {
__index = function(me,tab)
error(("Option Type %s is not available."):format(tostring(tab)))
end
})
-----------------------------------------
-- SAVED REFERENCES
-----------------------------------------
ZGV.Menu = Menu
ZGV.Settings = Settings
ZGV.GuideMenu = GuideMenu
Menu.Settings = Settings
Menu.GuideMenu = GuideMenu
-----------------------------------------
-- LOCAL FUNCTIONS
-----------------------------------------
local function GetOpinionFrame(parent,name,opt,notooltip)
local tooltip = ZGV.Tooltip.Frame
local opt_frame = CHAIN(ui:Create("InvisFrame", parent, name))
:SetResizeToFitDescendents(true)
:SetMouseEnabled(true)
.__END
if not notooltip then
opt_frame:AddTooltip(opt.title,opt.desc)
end
-- Just need an invisble backdrop so that ResizeToFitDescendents works to maintain desired width with adjusting height dynamically.
opt_frame.bd = CHAIN(ui:Create("SecBackdrop",opt_frame,name and name.."_BD"))
:SetBackdropColor(1,0,0,0)
:SetExcludeFromResizeToFitExtents(false)
.__END
return opt_frame
end
local function GetInlineDesc(parent,name)
local desc = CHAIN(ui:Create("Label",parent,name,11))
:SetCanWrap(true)
.__END
return desc
end
local function SetTextureBlock(tex,nh,nv,h,v)
tex:SetTextureCoords((nh-1)/h,nh/h,(nv-1)/v,nv/v)
tex:SetTextureCoords((nh-1)/h,nh/h,(nv-1)/v,nv/v)
end
local function SetIcon(self,nh,nv,h,v,sec,big)
local icon = sec and self.iconover or self.icon
if nh>0 then
icon:Show()
else
icon:Hide()
end
icon:SetTexture(ZGV.DIR.."/Viewer/Skins/Stealth/guideicons-small.dds")
SetTextureBlock(icon,nh,nv,h,v)
end
-----------------------------------------
-- CREATE MENU FUNCTIONS
-----------------------------------------
function Menu:CreateBaseMenu()
if self.Frame then return end
-- main window
local frame = CHAIN(ui:Create("Frame",GuiRoot,name))
:SetPoint(unpack(DEFAULT_ANCHOR))
:SetCanDrag(1)
:SetSize(DEFAULT_WIDTH,DEFAULT_HEIGHT)
:SetMouseEnabled(true)
:Hide()
.__END
self.Frame = frame
-- Guide version, lower left
frame.version = CHAIN(ui:Create("Label",frame,name.."_VerTitle",12,"bold"))
:SetPoint(BOTTOMLEFT,frame,BOTTOMLEFT,10,-8) -- TODO y vert distance does not keep centered in footer if footer size changes.
:SetText("VER:")
.__END
frame.versionNum = CHAIN(ui:Create("Label",frame,name.."_VerNum",12))
:SetPoint(LEFT,frame.version,RIGHT,3,0)
:SetText(ZGV.version)
.__END
-- Close button, upper right
frame.close = CHAIN(ui:Create("GuideButton",frame,name.."_Close","Close"))
:SetPoint(TOPRIGHT, titlebar, -5, 5 )
:SetHandler("OnClicked",function(me)
Menu:Hide()
end)
.__END
-- Guide title
frame.tabhandler = CHAIN(ui:Create(
"Tabs",
frame,
name,
{
{
id = GUIDEMENU_TAB_ID,
name="Home",
size = {120,40},
fontsize = 25,
point = { TOPLEFT, -12, 9},
handler = function()
Menu:SetTab(GUIDEMENU_TAB_ID)
end
},
{
id = SETTINGS_TAB_ID,
name="",
size = { 120, 40 },
fontsize = 25,
handler=function()
Menu:SetTab(SETTINGS_TAB_ID)
end
},
}
))
.__END
-- Settings Gear button, bottom right
frame.settings = CHAIN(ui:Create("GuideButton",frame,name.."_Settings","Settings"))
:SetPoint(BOTTOMRIGHT,frame,BOTTOMRIGHT,-5,-5)
.__END
frame.mainBackdrop = CHAIN(ui:Create("SecFrame", frame, name.. "_mainBackdrop"))
:SetPoint( TOPLEFT,frame, TOPLEFT,1,HEADER_HEIGHT)
:SetPoint(BOTTOMRIGHT,frame,BOTTOMRIGHT,-1,-FOOTER_HEIGHT)
.__END
self:SetTab(GUIDEMENU_TAB_ID) -- Set the default tab
end
-----------------------------------------
-- GUIDEMENU UI FUNCTIONS
-----------------------------------------
function GuideMenu:Create()
if not Menu.Frame then
Menu:CreateBaseMenu()
end
if self.Frame then return end
local gmname = name.. "_GuideMenu"
local HEADER_PADDING = 5
local frame = CHAIN(ui:Create("InvisFrame", Menu.Frame.mainBackdrop,gmname))
:SetAllPoints()
:Hide()
.__END
self.Frame = frame
frame.guideBox = CHAIN(ui:Create("InvisFrame", frame, gmname.. "_GuideBox"))
:SetPoint(TOPLEFT) :SetPoint(BOTTOMLEFT)
:SetWidth(LEFT_COLUMN_WIDTH)
.__END
frame.guideBoxScroll = CHAIN(wm:CreateControl(name.."_Slider",frame,_G.CT_SLIDER))
:SetMouseEnabled(true)
:SetThumbTexture(_G.tex,_G.tex,_G.tex,SCROLL_WIDTH,50,0,0,1,1)
:SetThumbFlushWithExtents(true)
:SetValue(0)
:SetValueStep(1)
:SetWidth(SCROLL_WIDTH)
:SetAnchor(TOPLEFT,frame.guideBox,TOPRIGHT)
:SetAnchor(BOTTOMLEFT,frame.guideBox,BOTTOMRIGHT)
:SetOrientation(_G.ORIENTATION_VERTICAL)
:SetHandler("OnValueChanged",function(self,value,eventReason)
GuideMenu.offset = value
GuideMenu:RefreshUI()
end)
.__END
frame.guideBoxScrollBack = CHAIN(ui:Create("SecFrame", frame, gmname.. "_ScrollBack"))
:SetPoint(TOPLEFT,frame.guideBoxScroll,TOPLEFT)
:SetPoint(BOTTOMRIGHT,frame.guideBoxScroll,BOTTOMRIGHT)
:SetBackdropColor(.4,.4,.4,1)
.__END
frame.guideInfoBox = CHAIN(ui:Create("InvisFrame", frame, gmname.. "_GuideInfoBox"))
:SetPoint(TOPLEFT,frame.guideBoxScroll,TOPRIGHT)
:SetPoint(BOTTOMRIGHT)
:SetWidth(LEFT_COLUMN_WIDTH)
.__END
frame.header = CHAIN(ui:Create("Label",frame,gmname.."_Header",15,"bold"))
:SetPoint(TOPLEFT,frame,TOPLEFT,HEADER_PADDING,6)
:SetText (ZGV.Utils.faction_names_short[ZGV.Utils.GetFaction()]:upper() .. (ZGV.VETERAN_FACTION and " VETERAN" or "") .. " LEVELING")
.__END
------------------------------
-- Setup Left column buttons
-----------------------------
frame.buttons={}
local rows = MAX_LINES
local ROWHEIGHT = 22 -- TODO calculate these based on height of Guide Menu?
for i=1,rows do
local butname = gmname.."_But"..i
-- Copy ZGESO_DumpFrameBasic layout. Has working scrollbar.
local but = CHAIN(ui:Create("SecButton",frame.guideBox,butname))
:SetHeight(ROWHEIGHT)
:SetHandler("OnMouseEnter",function(me)
me.highlight:Show()
end)
:SetHandler("OnMouseExit",function(me)
me.highlight:Hide()
end)
:SetHandler("OnClicked",function(me,but) GuideMenu:MenuButton_OnClick(me,but) end)
:SetHandler("OnMouseDoubleClick",function(me,but)
if me.target.type=="folder" then
else
GuideMenu:SetCurrentGuide(me.target)
end
end)
.__END
-- Texture for when the button is hovered over.
but.highlight = CHAIN(ui:Create("Texture",but,butname.."_Highlight"))
:SetColor(unpack(BUTTON_HIGHLIGHT_TEXTURE))
:SetPoint(but)
:Hide()
.__END
if i == 1 then
CHAIN(but)
:SetPoint(RIGHT) -- Set the right point first so it gets the width
:SetPoint(TOPLEFT,frame.header,BOTTOMLEFT,-HEADER_PADDING,0)
else
local prevBut = frame.buttons[i-1]
CHAIN(but)
:SetPoint(TOPLEFT,prevBut,BOTTOMLEFT)
:SetPoint(TOPRIGHT,prevBut,BOTTOMRIGHT)
end
but.icon = CHAIN(ui:Create("Texture",but,butname.."_Icon"))
:SetPoint(LEFT,but,LEFT,10,0)
:SetSize(17,17)
:SetTexture(ZGV.DIR.."/Viewer/Skins/Stealth/guideicons-small.dds")
.__END
-- TODO blinking star on guide animation?
but.label = CHAIN(ui:Create("Label",but,butname.."_Label",13))
:SetPoint(LEFT,but.icon,RIGHT,5,0)
:SetPoint(RIGHT)
:SetText("No label?!!?")
.__END
but.SetIcon=SetIcon
frame.buttons[i]=but
end
------------------------------
-- Setup Right information panel
-----------------------------
frame.GuideTitle = CHAIN(ui:Create("Label",frame.guideInfoBox,gmname.."_GuideTitle",17,"bold"))
:SetPoint(TOPLEFT,frame.guideInfoBox,20,20)
:SetWidth(GUIDE_IMAGE_WIDTH-20)
.__END
frame.GuideImage = CHAIN(ui:Create("Texture",frame.guideInfoBox,gmname.."_GuideTexture"))
:SetPoint(TOPLEFT,frame.GuideTitle,0,30)
:SetPoint(BOTTOMRIGHT,frame.GuideTitle,0,256)
:SetSize(GUIDE_IMAGE_WIDTH,GUIDE_IMAGE_HEIGHT)
:Hide()
.__END
-- TODO scrollbar for information panel on the right? Create a scrollbox for the rest of the information.
frame.GuideData = CHAIN(ui:Create("Label",frame.guideInfoBox,gmname.."_GuideData",14))
:SetPoint(TOPLEFT,frame.GuideImage,0,200)
:SetPoint(BOTTOMRIGHT,-20,-10)
:SetVerticalAlignment(_G.TEXT_ALIGN_TOP)
.__END
-- Button isn't in the scrollframe either
frame.OkButton = CHAIN(ui:Create("Button",frame.guideBox,gmname.."_OkButton"))
:SetPoint(BOTTOMRIGHT,frame.guideInfoBox,BOTTOMRIGHT,-20,-10)
:SetSize(80,20)
:SetText("Start Guide")
:SetFontSize(14)
:SetHandler("OnClicked",function(but)
GuideMenu:SetCurrentGuide(GuideMenu.selectedguide)
end)
.__END
end
function GuideMenu:RefreshUI()
if not self.Frame then
self:Create()
end
local frame = self.Frame
local buts = frame.buttons
local folders = {}
local guides = {}
if not self.folder then
self.folder = ""
end
if self.folder then
if #self.folder>0 then
local parentfolder = self.folder:match("(.+)/[^/]+")
table.insert(folders,{type="folder",title=parentfolder,title_short="( up )"})
end
local topfolders_seen = {}
local folderslash = self.folder=="" and "" or self.folder.."/"
for gn,guide in pairs(ZGV.registeredguides) do
local wholefolder,topfolder = guide.title:match("LEVELING/("..folderslash.."([^/]+))/.+")
if topfolder then
if not topfolders_seen[topfolder] then
topfolders_seen[topfolder] = true
table.insert(folders,{type="folder",title=wholefolder,title_short=topfolder})
end
end
end
for gn,guide in pairs(ZGV.registeredguides) do
if (guide.title:match("^LEVELING/"..folderslash.."[^/]+$")) then
table.insert(guides,guide)
end
end
end
frame.header:SetText ( self.folder=="" and "All Guides" or self.folder or "Leveling Guides" )
-- Sort guides by startlevel, place at end if there is no startlevel.
table.sort(guides, function(a, b)
if (a.startlevel or math.huge) < (b.startlevel or math.huge) then return true end
if (a.startlevel or math.huge) > (b.startlevel or math.huge) then return false end
if (a.endlevel or math.huge) < (b.endlevel or math.huge) then return true end
if (a.endlevel or math.huge) > (b.endlevel or math.huge) then return false end
return (a.title < b.title)
end)
for i,f in ipairs(folders) do
table.insert(guides,i,f)
end
local zo_min, zo_max = _G.zo_min, _G.zo_max
self.offset = self.offset and zo_min(#guides,zo_max(0,self.offset)) or 0
frame.guideBoxScroll:SetMinMax(0, #guides-MAX_LINES) -- code works but there's no scrolling
local hei = zo_min(1,MAX_LINES / #guides) if hei==1 then
hei = 0
end
local tex = _G.tex
frame.guideBoxScroll:SetThumbTexture(tex,tex,tex,SCROLL_WIDTH,frame.guideBoxScroll:GetHeight() * hei,0,0,1,1)
-------------------------------
-- UPDATE THE BUTTONS
-------------------------------
for i,but in ipairs(buts) do
local guide = guides[i+self.offset]
if guide then
-- guide/folder, doesn't matter
but.target = guide
--but.isguide=true
local status = guide.GetStatus and guide:GetStatus() or ""
if guide.type=="folder" then
but:SetIcon(1,1,2,2)
else
but:SetIcon(2,1,2,2)
end
-- TODO icon stuffz
--[[
if g.icon and Menu.path == "RECENT" and Menu.simpleList then
if type(g.icon[3]) == "string" then -- icon in get_icon() format
local x,y = g.icon[1],g.icon[2] --get_icon(g.header)
if x then
but:SetIcon(x,y,4,4,false,true)
--but.label:SetPoint("TOPLEFT",but,"TOPLEFT",32,2)
end
end
but:SetIcon(0,0,2,2,true)
else
but:SetIcon(2,1,2,2)
if status=="SUGGESTED" then
but:SetIcon(1,2,2,2,true)
--but.iconover.anim:Play()
else
but:SetIcon(0,0,2,2,true)
end
end
--]]
but.icon:Show()
local statuscolor = GuideStatusColor[status] or "ffffff"
if self.selectedguide and self.selectedguide==guide then
local r,g,b = _G.HTMLColor("#"..statuscolor)
but:SetBackdropColor(r,g,b,1)
but.bd:Show()
statuscolor = "ffffff" -- status text is always white when we hover over it to not conflict with the backdrop.
else
but.bd:Hide()
end
but.label:SetText("|c"..statuscolor..(guide.title_short or "")..(guide.parse_error and "-|cff0000ERROR|r" or "") )
but:Show()
else
but:Hide()
end
end
-------------------------------
-- DISPLAY THE GUIDE
-------------------------------
if self.selectedguide then
local g = self.selectedguide
local imageWidth, imageHeight = GUIDE_IMAGE_WIDTH, GUIDE_IMAGE_HEIGHT
local formatLevel = _G.formatLevel
frame.GuideTitle:SetText(g.title_short)
frame.GuideImage:SetTexture(_G.image)
frame.GuideData:SetText(g.desc)
frame.GuideData:SetPoint(TOPLEFT,frame.GuideImage,0,200)
local s="\n"
if g.startlevel and g.startlevel>0 then
local formatLevel = ZGV.Utils.FormatLevel
if g.endlevel and g.endlevel>0 then
s = s .. "|cffeebbLevels:|r ".. formatLevel(g.startlevel) .." to ".. formatLevel(g.endlevel) .. "\n"
else
s = s .. "|cffeebbRequired level:|r ".. formatLevel(g.startlevel) .."\n"
end
else
if g.endlevel and g.endlevel>0 then
s = s .. "|cffffeebbEnding level:|r ".. formatLevel(g.endlevel) .."\n"
end
end
if g.next then
s = s .. "|cffeebbNext guide:|r ".. g.next:match(".+/(.-)$") .."\n"
end
s = s .. "\n"
local status,msg = g:GetStatus()
local color = GuideStatusColor[status]
if status=="COMPLETE" and g.type=="LEVELING" then
status=status.."_lev"
end
s = s .. "\n"
s = s .. (g.description or "")
frame.GuideData:SetText(s)
frame.OkButton:Show()
if g.image then
CHAIN(frame.GuideImage)
:SetTexture(g.image)
:Show()
else
CHAIN(frame.GuideImage)
:SetHeight(0) -- Make it disappear! well kinda
:Hide()
end
if g.parse_error then
ZGV:Print(g.parse_error)
end
else
frame.GuideTitle:SetText("Welcome to the Zygor Community Guide for ESO")
frame.GuideImage:SetTexture(ZGV.DIR.."/Viewer/Skins/Stealth/zgeso-elsweyr.dds")
frame.GuideData:SetText("Original guide authored by Zygor Guides\nSummerset, Murkmire and Elsweyr guides authored by Hydra9268\nMinor bug fixes and improvements by Hydra9268")
frame.GuideData:SetPoint(TOPLEFT,frame.GuideImage,0,265)
frame.GuideImage:Show()
frame.OkButton:Hide()
end
frame:Show()
end
-----------------------------------------
-- SETTINGS UI FUNCTIONS
-----------------------------------------
function Settings:Create()
if not Menu.Frame then
Menu:CreateBaseMenu()
end
if self.Frame then return end
local setname = name.. "_SettingsMenu"
local HEADER_PADDING = 5
local frame = CHAIN(ui:Create("InvisFrame", Menu.Frame.mainBackdrop,setname))
:SetAllPoints()
:Hide()
.__END
self.Frame = frame
frame.optionTypesBox = CHAIN(ui:Create("InvisFrame", frame, setname.. "_OptionsBox"))
:SetPoint(TOPLEFT) :SetPoint(BOTTOMLEFT)
:SetWidth(LEFT_COLUMN_WIDTH)
.__END
frame.optionTypesScroll = CHAIN(ui:Create("SecFrame", frame, setname.. "_Scroll")) -- TODO A real scroll bar for the left Panel
:SetPoint(TOPLEFT,frame.optionTypesBox,TOPRIGHT)
:SetPoint(BOTTOMLEFT,frame.optionTypesBox,BOTTOMRIGHT)
:SetWidth(SCROLL_WIDTH)
:SetBackdropColor(.4,.4,.4,1)
.__END
frame.optionsBox = CHAIN(ui:Create("InvisFrame", frame, setname.. "_GuideInfoBox"))
:SetPoint(TOPLEFT,frame.optionTypesScroll,TOPRIGHT)
:SetPoint(BOTTOMRIGHT)
:SetWidth(LEFT_COLUMN_WIDTH)
.__END
-- Used to say "Options"
frame.header = CHAIN(ui:Create("Label",frame,setname.."_Header",0,"bold"))
:SetPoint(TOPLEFT,frame,TOPLEFT,HEADER_PADDING,2)
:SetText("")
.__END
------------------------------
-- Setup Left column buttons
-----------------------------
frame.buttons={}
local rows = MAX_LINES
local ROWHEIGHT = 22 -- TODO calculate these based on height of Guide Menu?
for i = 1,rows do
local butname = setname.."_But"..i
local but = CHAIN(ui:Create("SecButton",frame.optionTypesBox,butname))
:SetHeight(ROWHEIGHT)
:SetHandler("OnMouseEnter",function(me)
me.highlight:Show()
end)
:SetHandler("OnMouseExit",function(me)
me.highlight:Hide()
end)
:SetHandler("OnClicked",function(me,but) Settings:MenuButton_OnClick(me,but)
end)
.__END
-- Texture for when the button is hovered over.
but.highlight = CHAIN(ui:Create("Texture",but,butname.."_Highlight"))
:SetColor(unpack(BUTTON_HIGHLIGHT_TEXTURE))
:SetPoint(but)
:Hide()
.__END
if i == 1 then
CHAIN(but)
:SetPoint(RIGHT) -- Set the right point first so it gets the width
:SetPoint(TOPLEFT,frame.header,BOTTOMLEFT,-HEADER_PADDING,0)
else
local prevBut = frame.buttons[i-1]
CHAIN(but)
:SetPoint(TOPLEFT,prevBut,BOTTOMLEFT)
:SetPoint(TOPRIGHT,prevBut,BOTTOMRIGHT)
end
but.icon = CHAIN(ui:Create("Texture",but,butname.."_Icon"))
:SetPoint(LEFT,but,LEFT,10,0)
:SetSize(17,17)
:SetTexture(ZGV.DIR.."/Viewer/Skins/Stealth/guideicons-small.dds")
.__END
-- TODO blinking star on guide animation?
but.label = CHAIN(ui:Create("Label",but,butname.."_Label",15))
:SetPoint(LEFT,but.icon,RIGHT,5,0)
:SetPoint(RIGHT)
:SetText("No label?!!?")
.__END
but.SetIcon = SetIcon
frame.buttons[i]=but
end
------------------------------
-- Setup Right information panel
-----------------------------
frame.OptionTitle = CHAIN(ui:Create("Label",frame.optionsBox,setname.."_GroupTitle",17))
:SetPoint(TOPLEFT,frame.guideInfoBox,TOPLEFT,HEADER_PADDING,2)
:SetPoint(TOPRIGHT,frame.guideInfoBox,TOPRIGHT,-HEADER_PADDING,0)
:SetText("Options")
.__END
frame.OptionDesc = CHAIN(ui:Create("Label",frame.optionsBox,setname.."_GroupDesc",12))
:SetPoint(TOPRIGHT,frame.OptionTitle,TOPRIGHT)
:SetPoint(TOPLEFT,frame.OptionTitle,BOTTOMLEFT,5,5)
:SetCanWrap(true)
:SetText("Desc")
.__END
-- Button isn't in the scrollframe either
local ButtonHortPad = 10
frame.OkButton = CHAIN(ui:Create("Button",frame.optionsBox,setname.."_OkButton"))
:SetPoint(BOTTOMRIGHT,frame.guideInfoBox,BOTTOMRIGHT,-ButtonHortPad,-5)
:SetText("Accept")
:SetFontSize(14)
:SetHandler("OnClicked",function(but)
Menu:Hide()
end)
.__END
frame.DefaultButton = CHAIN(ui:Create("Button",frame.optionsBox,setname.."_DefaultButton"))
:SetPoint(BOTTOMLEFT,frame.guideInfoBox,BOTTOMLEFT,ButtonHortPad,-5)
:SetText("Default")
:SetFontSize(14)
:SetHandler("OnClicked",function(but)
Settings:ShowDefaultPopup()
end)
.__END
frame.OptionsScrollBase = CHAIN(ui:Create("InvisFrame", frame.optionsBox, setname.. "_OptionsScrollChild")) -- Base for the option UI for each individual group
:SetPoint(TOPLEFT,frame.OptionDesc,BOTTOMLEFT,-HEADER_PADDING,0)
:SetPoint(BOTTOMRIGHT,frame.OkButton,TOPRIGHT,_G.OkButtonHortPad,0)
.__END
end
function Settings:CreateDefaultPopup()
if self.DefaultPopup then return end
local popup = CHAIN(ZGV.Popup:New("Zygor_Settings_Reset_Default_Popup"))
:SetText(L['static_options'])
:SetDimensionConstraints(375) -- Force minWidth to 375 for the buttons to fit nicely
.__END
-- No settings button for settings popup. That would be silly
popup.settings:Hide()
-- Need a third button for cancel
popup.cancelbutton = CHAIN(ui:Create("Button",popup,popup:GetName().."_Cancel"))
:SetPoint(TOP,popup.text,BOTTOM,0,10) -- 10 is BUT_Y_OFFSET from Popup.lua
:SetWidth(105)
:SetText(L['static_cancel'])
:SetFontSize(ZGV.db.profile.fontsize,true) -- TODO change size dynamically?
:SetHandler("OnClicked",function(me)
local pop = me:GetParent() -- Just hide the popup
pop.private:Hide(pop)
end)
.__END
-- Accept button is all Settings to Default
CHAIN(popup.acceptbutton)
:ClearAllPoints()
:SetWidth(105)
:SetPoint(RIGHT,popup.cancelbutton,LEFT,-5,0)
:SetText(L['static_allsetting'])
-- Decline button is these settings to default
CHAIN(popup.declinebutton)
:ClearAllPoints()
:SetWidth(105)
:SetPoint(LEFT,popup.cancelbutton,RIGHT,5,0)
:SetText(L['static_thesesetting'])
popup.OnAccept = function(me)
-- All option groups to default!
for i,opt_groups in ipairs(Settings.opt_groups) do
opt_groups:SetToDefault()
end
end
popup.OnDecline = function(me)
-- Currently shown option group to default!
Settings.selectedgroup:SetToDefault()
end
self.DefaultPopup = popup
end
function Settings:ShowDefaultPopup()
if not self.DefaultPopup then
self:CreateDefaultPopup()
end
self.DefaultPopup:Show()
end
-- Create the UI for a options group from all the options. Puts the frame with all the options in group.frame
function Settings:CreateOptionsUI(group)
if group.frame then return end
local name = "ZygorOptionPanel_Group_"..group.title
local lastobj, lastfrontobj
local frame = CHAIN(ui:Create("InvisFrame", self.Frame.OptionsScrollBase, name)) -- Frame that contains all option UI components for this group --TODO make it scrollie
:SetPoint(TOPLEFT) :SetPoint(BOTTOMRIGHT)
.__END
for i,option in ipairs(group.options) do
local data = option.data
local typ = data.type
local obj = self.OptionUI[typ](self,option,frame) -- This obj is a frame that contains the actual option UI
if typ ~= "execute" -- Execute buttons are unnecessary, they run a function on clicked
and typ ~= "header" -- headers are dumber
and typ ~= "desc" -- desc ^^^^
then
assert(obj.SetValue,"All option objects must have a :SetValue method")
obj:SetValue(option:GetValue())
end
option.frame = obj
obj.option = option
local frameWidth = frame:GetWidth()
if not lastfrontobj then
-- This is the first option so it goes at the top of the frame
obj:SetPoint(TOPLEFT,frame,TOPLEFT,0,OPTIONS_VERT_OFFSET)
obj:SetWidth(frameWidth)
lastfrontobj = obj
elseif not data.column or data.column == "one" then
-- First column, just put it on the next row.
obj:SetPoint(TOPLEFT,lastfrontobj,BOTTOMLEFT,0,OPTIONS_VERT_OFFSET)
obj:SetWidth(frameWidth)
lastfrontobj = obj
elseif data.column == "two" then
-- The lastobj was the obj at the front of the row. Half it's size.
local half = frameWidth/2
lastobj:SetWidth(half)
obj:SetPoint(TOPLEFT,lastobj,TOPRIGHT)
obj:SetWidth(half)
elseif data.column == "three" then
-- Need to make the first and second column 1/3 the full size.
local third = frameWidth/3
lastfrontobj:SetWidth(third)
lastobj:SetWidth(third)
obj:SetPoint(TOPLEFT,lastobj,TOPRIGHT)
obj:SetWidth(third)
else
error("Column can only be nil/one/two/three")
end
lastobj = obj
end
group.frame = frame
end
function Settings:RefreshUI()
if not self.Frame then
self:Create()
end
local frame = self.Frame
local buts = frame.buttons
local opt_groups = self.opt_groups
if #opt_groups > #buts then
error("More option groups than buttons in Settings! Tell Dev Team")
end
-------------------------------
-- UPDATE THE BUTTONS
-------------------------------
for i,but in ipairs(buts) do
local group = opt_groups[i]
if group then
-- guide
but.group = group
but:SetIcon(1,1,2,2)
-- TODO icons
--[[
if g.icon and Menu.path == "RECENT" and Menu.simpleList then
if type(g.icon[3]) == "string" then -- icon in get_icon() format
local x,y = g.icon[1],g.icon[2] --get_icon(g.header)
if x then
but:SetIcon(x,y,4,4,false,true)
--but.label:SetPoint("TOPLEFT",but,"TOPLEFT",32,2)
end
end
but:SetIcon(0,0,2,2,true)
else
but:SetIcon(2,1,2,2)
if status=="SUGGESTED" then
but:SetIcon(1,2,2,2,true)
but.iconover.anim:Play()
else
but:SetIcon(0,0,2,2,true)
end
end
--]]
but.icon:Show()
if self.selectedgroup and self.selectedgroup==group then
local mult = 0.7
local r,g,b = .6,.6,.6 -- HTMLColor("#0000ff")-- TODO more interesting color.
but:SetBackdropColor(r*mult,g*mult,b*mult,1)
but.bd:Show()
else
but.bd:Hide()
end
but.label:SetText(group.title)
but:Show()
else
but:Hide()
end
end
-------------------------------
-- DISPLAY THE OPTION GROUP
-------------------------------
for i,group in ipairs(opt_groups) do
if group.frame then
group.frame:Hide()
end -- Hide all the frames, then only show when needed
end
if self.selectedgroup then -- Should always be a selectedgroup hopefully
local g = self.selectedgroup
frame.OptionTitle:SetText(g.title)
frame.OptionDesc:SetText(g.desc or "")
if not g.frame then
self:CreateOptionsUI(g) -- Need to create the UI for this group from the options it has.
end
g.frame:Show()
frame.DefaultButton:Show()
frame.OkButton:Show()
else
frame.OptionTitle:SetText("")
frame.OptionDesc:SetText("")
frame.DefaultButton:Hide()
frame.OkButton:Hide()
end
if self.DefaultPopup and self.DefaultPopup:IsShown() then
self.DefaultPopup:Hide()
end -- Hide popup if it is visible
frame:Show()
end
-----------------------------------------
-- VARIOUS DIFFERENT SETTINGS UIS
-----------------------------------------
Settings.OptionUI["dropdown"] = function(self,option,parent)
local name = parent:GetName().."_Option"..option.num
local opt_frame = GetOpinionFrame(parent, name, option)
local label = CHAIN(ui:Create("Label",opt_frame,name.."_Label"))
:SetPoint(TOPLEFT,OPTIONS_LEFT_OFFSET,0)
:SetText(option.title)
.__END
local dropdown = CHAIN(ui:Create("Dropdown",opt_frame,name.."_Dropdown"))
:SetPoint(TOPLEFT,label,BOTTOMLEFT)
:AddTooltip(option.title,option.desc,opt_frame)
:SetDefaultText(option.data.defaultext)
.__END
if option.data.width then
dropdown:SetWidth(option.data.width)
end
-- Change the parent of the pullout so that the opt_frame doesn't resize when it is opened. If the pullout is parented to the dropdown then opt_frame will resize when it is opened.
dropdown.pullout:SetParent(parent)
if option:GetDescStyle() == "inline" then
local desc = CHAIN(GetInlineDesc(opt_frame,name.."_InlineDesc"))
-- Get creative with Points. Can't anchor to bottomright of opt_frame because it resizes to fit descendents. Parent to topRight then overwrite top with a topleft and get the
:SetPoint(TOPRIGHT,opt_frame,TOPRIGHT,-5,0)
:SetPoint(TOPLEFT,dropdown,BOTTOMLEFT)
:SetText(option.desc)
.__END
opt_frame.desc = desc
end
opt_frame.label = label
opt_frame.dropdown = dropdown
-- Stow away a reference
dropdown.option = option
opt_frame.option = option
-- Going to call set value on the frame, make a wrapper to the thing that needs to actually get the value set.
opt_frame.SetValue = function(me,value)
me.dropdown:SetValue(value)
end
local valuetbl = option.data.values
if type(valuetbl)=="function" then
valuetbl = valuetbl(dropdown)
end
assert(type(valuetbl)=="table", "Dropdown values must be a table or a function. Not: "..type(valuetbl))