-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGeminiGUI.lua
1589 lines (1301 loc) · 45.5 KB
/
GeminiGUI.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
-----------------------------------------------------------------------------------------------------------------------
-- GeminiGUI
-- Formerly DaiGUI
-- @author daihenka
-- GUI Widget Creation Library for WildStar.
-----------------------------------------------------------------------------------------------------------------------
local MAJOR, MINOR = "Gemini:GUI-1.0", 4
local Lib = Apollo.GetPackage("Gemini:GUI-1.0") and Apollo.GetPackage("Gemini:GUI-1.0").tPackage or {}
if Lib and (Lib._VERSION or 0) >= MINOR then
return -- no upgrade is needed
end
local assert, tostring, error, pcall = assert, tostring, error, pcall
local getmetatable, setmetatable, rawset, rawget, pairs = getmetatable, setmetatable, rawset, rawget, pairs
local strlen, strformat = string.len, string.format
local tinsert, tsort = table.insert, table.sort
local type, next = type, next
-- Wildstar APIs
local Apollo, XmlDoc = Apollo, XmlDoc
Lib._VERSION = MINOR
Lib.WidgetRegistry = Lib.WidgetRegistry or {}
Lib.WidgetVersions = Lib.WidgetVersions or {}
-- local upvalues
local WidgetRegistry = Lib.WidgetRegistry
local WidgetVersions = Lib.WidgetVersions
-- Create a widget prototype object
-- @param strType (Optional) Widget type. If not provided it will look at tOptions for
-- a WidgetType value. If no widget type is found, defaults to "Window".
-- @param tOptions Options table for the widget (see below usages)
-- @returns (table) Widget Prototype Object
--
-- @usage
-- local btnProto = GeminiGUI:Create("PushButton", {
-- AnchorCenter = { 100, 30 },
-- Text = "Push Me",
-- Events = { ButtonSignal = function() Print("You pushed me!") end },
-- })
-- local wndBtn = btnProto:GetInstance()
--
-- @usage #2
-- local myEventHandler = { OnClick = function() Print("You pushed me!") end }
--
-- local btnProto = GeminiGUI:Create({
-- WidgetType = "PushButton",
-- AnchorCenter = { 100, 30 },
-- Text = "Push Me",
-- Events = { ButtonSignal = "OnClick" },
-- })
-- local wndBtn = btnProto:GetInstance(myEventHandler)
function Lib:Create(strType, tOptions)
-- check if passed a function to generate the tOptions
if type(strType) == "function" then
tOptions = strType()
strType = tOptions.WidgetType or "Window"
elseif type(strType) == "string" and type(tOptions) == "function" then
tOptions = tOptions()
strType = strType or tOptions.WidgetType or "Window"
-- check if passed a table without a strType
elseif type(strType) == "table" then
tOptions = strType
strType = tOptions.WidgetType or "Window"
end
if type(strType) ~= "string" then
error(("Usage: Create([strType,] tOptions): 'strType' - string expected got '%s'."):format(type(strType)), 2)
end
if type(tOptions) ~= "table" then
error(("Usage: Create([strType,] tOptions): 'tOptions' - table expected got '%s'."):format(type(tOptions)), 2)
end
-- check if tOptions is already a widget prototype
if tOptions.__IsGeminiGuiPrototype == true then
return tOptions
end
strType = strType or "Window"
-- if not, check if the widget type is valid
if WidgetRegistry[strType] then
-- create the widget
local widget = WidgetRegistry[strType]()
widget.WidgetVersion = WidgetVersions[strType]
if tOptions ~= nil and type(tOptions) == "table" then
widget:SetOptions(tOptions)
end
widget.__IsGeminiGuiPrototype = true
return widget
end
end
-- Register a widget constructor that will return a new prototype of the widget
-- @param strType Name of the widget
-- @param fnConstructor Widget constructor function
-- @param nVersion Version of the widget
function Lib:RegisterWidgetType(strType, fnConstructor, nVersion)
assert(type(fnConstructor) == "function")
assert(type(nVersion) == "number")
local oldVersion = WidgetVersions[strType]
if oldVersion and oldVersion >= nVersion then return end
WidgetVersions[strType] = nVersion
WidgetRegistry[strType] = fnConstructor
end
-- Return the version of the currently registered widget type
-- @param strType Name of the widget
-- @returns (number) Version of the widget
function Lib:GetWidgetVersion(strType)
return WidgetVersions[strType]
end
function Lib:OnLoad()
end
function Lib:OnDependencyError(strDep, strError)
return false
end
Apollo.RegisterPackage(Lib, MAJOR, MINOR, {})
--[[ Widgets ]]--
local GeminiGUI = Lib
--[[ File: widgets/ControlBase.lua ]]--
do
GeminiGUI.ControlBase = {}
local Control = GeminiGUI.ControlBase
local kstrDefaultName = "GeminiGUIControl"
local pairs, ipairs, type, unpack, error = pairs, ipairs, type, unpack, error
local setmetatable, tostring = setmetatable, tostring
local ktAnchorPoints = {
TOPLEFT = { 0, 0, 0, 0 },
TOPRIGHT = { 1, 0, 1, 0 },
BOTTOMLEFT = { 0, 1, 0, 1 },
BOTTOMRIGHT = { 1, 1, 1, 1 },
CENTER = { 0.5, 0.5, 0.5, 0.5 },
VCENTER = { 0, 0.5, 0, 0.5 },
HCENTER = { 0.5, 0, 0.5, 0 },
VCENTERRIGHT = { 1, 0.5, 1, 0.5 },
HCENTERBOTTOM = { 0.5, 1, 0.5, 1 },
FILL = { 0, 0, 1, 1 },
HFILL = { 0, 0, 1, 0 },
VFILL = { 0, 0, 0, 1 },
VFILLRIGHT = { 1, 0, 1, 1 },
HFILLBOTTOM = { 0, 1, 1, 1 },
}
local function TranslateAnchorPoint(s, tOptions, v)
if type(v) == "string" then
tOptions.LAnchorPoint, tOptions.TAnchorPoint, tOptions.RAnchorPoint, tOptions.BAnchorPoint = unpack(ktAnchorPoints[v])
elseif type(v) == "table" then
tOptions.LAnchorPoint, tOptions.TAnchorPoint, tOptions.RAnchorPoint, tOptions.BAnchorPoint = unpack(v)
end
end
local function SetupWhiteFillMe(self, tOptions, v)
if v ~= true then return end
tOptions.Picture = true
tOptions.Sprite = "ClientSprites:WhiteFill"
tOptions.BGColor = "white"
end
local kSpecialFields = {
AnchorOffsets = function(s, tOptions, v)
tOptions.LAnchorOffset, tOptions.TAnchorOffset, tOptions.RAnchorOffset, tOptions.BAnchorOffset = unpack(v)
end,
AnchorPoints = TranslateAnchorPoint,
Anchor = TranslateAnchorPoint,
IncludeEdgeAnchors = function(s, tOptions, v)
if type(v) ~= "string" and (s.options.Name == nil or strlen(s.options.Name) == 0) then
error("IncludeEdgeAnchors requires a string or the control name to be set", 2)
end
local strPrefix = ((type(v) == "string") and v or s.options.Name)
tOptions.LeftEdgeControlsAnchor, tOptions.TopEdgeControlsAnchor, tOptions.RightEdgeControlsAnchor, tOptions.BottomEdgeControlsAnchor = strPrefix .. "_Left", strPrefix .. "_Top", strPrefix .. "_Right", strPrefix .. "_Bottom"
end,
AnchorCenter = function(s, tOptions, v)
if type(v) ~= "table" or #v ~= 2 then return end
local nWidth, nHeight = unpack(v)
tOptions.LAnchorPoint, tOptions.TAnchorPoint, tOptions.RAnchorPoint, tOptions.BAnchorPoint = unpack(ktAnchorPoints["CENTER"])
tOptions.LAnchorOffset, tOptions.TAnchorOffset, tOptions.RAnchorOffset, tOptions.BAnchorOffset = nWidth / 2 * -1, nHeight / 2 * -1, nWidth / 2, nHeight / 2
end,
AnchorFill = function(s, tOptions, v)
local nPadding = (type(v) == "number") and v or 0
tOptions.LAnchorPoint, tOptions.TAnchorPoint, tOptions.RAnchorPoint, tOptions.BAnchorPoint = unpack(ktAnchorPoints["FILL"])
tOptions.LAnchorOffset, tOptions.TAnchorOffset, tOptions.RAnchorOffset, tOptions.BAnchorOffset = nPadding, nPadding, -nPadding, -nPadding
end,
PosSize = function(s, tOptions, v)
if type(v) ~= "table" or #v ~= 4 then return end
local nLeft, nTop, nWidth, nHeight = unpack(v)
tOptions.LAnchorPoint, tOptions.TAnchorPoint, tOptions.RAnchorPoint, tOptions.BAnchorPoint = unpack(ktAnchorPoints["TOPLEFT"])
tOptions.LAnchorOffset, tOptions.TAnchorOffset, tOptions.RAnchorOffset, tOptions.BAnchorOffset = nLeft, nTop, nLeft + nWidth, nTop + nHeight
end,
UserData = function(s, tOptions, v)
s:SetData(v)
end,
LuaData = function(s, tOptions, v)
s:SetData(v)
end,
Events = function(s, tOptions, v)
if type(v) == "table" then
for strEventName, oHandler in pairs(v) do
if type(strEventName) == "number" and type(oHandler) == "table" then -- handle the old style
s:AddEvent(unpack(oHandler))
elseif type(strEventName) == "string" and (type(oHandler) == "string" or type(oHandler) == "function") then
s:AddEvent(strEventName, oHandler)
end
end
end
end,
Pixies = function(s, tOptions, v)
if type(v) == "table" then
for _, tPixie in ipairs(v) do
s:AddPixie(tPixie)
end
end
end,
Children = function(s, tOptions, v)
if type(v) == "table" then
for _, tChild in ipairs(v) do
local strWidgetType = "Window"
if type(tChild.WidgetType) == "string" then
strWidgetType = tChild.WidgetType
end
s:AddChild(GeminiGUI:Create(strWidgetType, tChild))
end
end
end,
}
function Control:new(o)
o = o or {}
o.events = {}
o.children = {}
o.pixies = {}
o.options = {}
setmetatable(o, self)
self.__index = self
return o
end
-- Set an option on the widget prototype
-- @param strOptionName the option name
-- @param value the value to set
function Control:SetOption(key, value)
self.options[key] = value
end
-- Set multiple options on the widget prototype
-- @param tOptions the options table
function Control:SetOptions(tOptions)
for k,v in pairs(tOptions) do
self.options[k] = v
end
end
-- pixie mapping table
local ktPixieMapping = {
strText = "Text",
strFont = "Font",
bLine = "Line",
fWidth = "Width",
strSprite = "Sprite",
cr = "BGColor",
crText = "TextColor",
fRotation = "Rotation",
strTextId = "TextId",
nTextId = "TextId",
loc = { fPoints = "AnchorPoints", nOffsets = "AnchorOffsets" },
flagsText = { DT_CENTER = "DT_CENTER", DT_VCENTER = "DT_VCENTER", DT_RIGHT = "DT_RIGHT", DT_BOTTOM = "DT_BOTTOM",
DT_WORDBREAK = "DT_WORDBREAK", DT_SINGLELINE = "DT_SINGLELINE" },
}
-- Add a pixie to the widget prototype
-- @param tPixie a table with pixie options
function Control:AddPixie(tPixie)
if tPixie == nil then return end
-- in case someone uses the C++ Window:AddPixie() format. Preference to the XML format over the C++ Window:AddPixie() format.
for oldKey, newKey in pairs(ktPixieMapping) do
if tPixie[oldKey] ~= nil then
if type(tPixie[oldKey]) == "table" and type(newKey) == "table" then
for oldKey2, newKey2 in pairs(tPixie[oldKey]) do
if tPixie[oldKey][oldKey2] ~= nil then
tPixie[newKey[oldKey2] or newKey2] = tPixie[newKey2] or tPixie[oldKey][oldKey2]
end
end
else
tPixie[newKey] = tPixie[newKey] or tPixie[oldKey]
end
end
end
if type(tPixie.AnchorOffsets) == "table" then
tPixie.LAnchorOffset, tPixie.TAnchorOffset, tPixie.RAnchorOffset, tPixie.BAnchorOffset = unpack(tPixie.AnchorOffsets)
tPixie.AnchorOffsets = nil
end
if tPixie.AnchorPoints ~= nil or tPixie.Anchor ~= nil then
local tAnchorPoints = tPixie.AnchorPoints or tPixie.Anchor
if type(tAnchorPoints) == "string" then
tPixie.LAnchorPoint, tPixie.TAnchorPoint, tPixie.RAnchorPoint, tPixie.BAnchorPoint = unpack(ktAnchorPoints[tAnchorPoints])
else
tPixie.LAnchorPoint, tPixie.TAnchorPoint, tPixie.RAnchorPoint, tPixie.BAnchorPoint = unpack(tAnchorPoints)
end
tPixie.AnchorPoints = nil
tPixie.Anchor = nil
end
if tPixie.AnchorFill ~= nil then
tPixie.LAnchorPoint, tPixie.TAnchorPoint, tPixie.RAnchorPoint, tPixie.BAnchorPoint = unpack(ktAnchorPoints["FILL"])
if type(self.options.AnchorFill) == "number" then
local nPadding = tPixie.AnchorFill
tPixie.LAnchorOffset, tPixie.TAnchorOffset, tPixie.RAnchorOffset, tPixie.BAnchorOffset = nPadding, nPadding, -nPadding, -nPadding
elseif type(self.options.AnchorFill) == "boolean" then
tPixie.LAnchorOffset, tPixie.TAnchorOffset, tPixie.RAnchorOffset, tPixie.BAnchorOffset = 0,0,0,0
end
tPixie.AnchorFill = nil
end
if type(tPixie.AnchorCenter) == "table" then
local nWidth, nHeight = unpack(tPixie.AnchorCenter)
tPixie.LAnchorPoint, tPixie.TAnchorPoint, tPixie.RAnchorPoint, tPixie.BAnchorPoint = unpack(ktAnchorPoints["CENTER"])
tPixie.LAnchorOffset, tPixie.TAnchorOffset, tPixie.RAnchorOffset, tPixie.BAnchorOffset = nWidth / 2 * -1, nHeight / 2 * -1, nWidth / 2, nHeight / 2
tPixie.AnchorCenter = nil
end
if type(tPixie.PosSize) == "table" then
local nLeft, nTop, nWidth, nHeight = unpack(tPixie.PosSize)
tPixie.LAnchorPoint, tPixie.TAnchorPoint, tPixie.RAnchorPoint, tPixie.BAnchorPoint = unpack(ktAnchorPoints["TOPLEFT"])
tPixie.LAnchorOffset, tPixie.TAnchorOffset, tPixie.RAnchorOffset, tPixie.BAnchorOffset = nLeft, nTop, nLeft + nWidth, nTop + nHeight
tPixie.PosSize = nil
end
tPixie.LAnchorOffset = tPixie.LAnchorOffset or 0
tPixie.RAnchorOffset = tPixie.RAnchorOffset or 0
tPixie.TAnchorOffset = tPixie.TAnchorOffset or 0
tPixie.BAnchorOffset = tPixie.BAnchorOffset or 0
tPixie.LAnchorPoint = tPixie.LAnchorPoint or 0
tPixie.RAnchorPoint = tPixie.RAnchorPoint or 0
tPixie.TAnchorPoint = tPixie.TAnchorPoint or 0
tPixie.BAnchorPoint = tPixie.BAnchorPoint or 0
-- ensure that pixie booleans are properly converted to 1/0
for k,v in pairs(tPixie) do
if type(v) == "boolean" then
tPixie[k] = v and "1" or "0"
end
end
tinsert(self.pixies, tPixie)
end
-- Add a child widget prototype to the widget prototype
-- @param tChild The child widget to add -- NOTE: Must be a GeminiGUI:Create() blessed prototype
function Control:AddChild(tChild)
if tChild == nil then return end
tinsert(self.children, tChild)
end
local function WrapCallback(func)
if Apollo.GetPackage("Gemini:LibError-1.0") and Apollo.GetPackage("Gemini:LibError-1.0").tPackage then
return function(...) local a = arg; xpcall(function() func(unpack(a)) end, Apollo.GetPackage("Gemini:LibError-1.0").tPackage.Error) end
end
return func
end
-- Add an event handler to the widget prototype
-- @param strName The event name to be handled
-- @param strFunction (Optional) The function name on the event handler table
-- @param fnInline (Optional) The anonymous function to handle the event
--
-- @usage myPrototype:AddEvent("ButtonSignal", "OnButtonClick") -- when the event is fired, it will call OnButtonClick on the event handler table
-- @usage myPrototype:AddEvent("ButtonSignal", function() Print("Clicked!") end) -- when the event is fired, the anonymous function will be called
function Control:AddEvent(strName, strFunction, fnInline)
if type(strFunction) == "function" then
fnInline = WrapCallback(strFunction)
strFunction = "On" .. strName .. tostring(fnInline):gsub("function: ", "_")
end
tinsert(self.events, {strName = strName, strFunction = strFunction, fnInline = fnInline })
end
-- Set the data the widget is to store
-- @param oData the lua data object
function Control:SetData(oData)
self.oData = oData
end
-- Parses the options table for the widget
-- Internal use only
function Control:ParseOptions()
local tOptions = {}
for k, fn in pairs(kSpecialFields) do
if self.options[k] ~= nil then
fn(self, tOptions, self.options[k])
end
end
for k,v in pairs(self.options) do
if not kSpecialFields[k] or k == "WhiteFillMe" then
tOptions[k] = v
end
end
SetupWhiteFillMe(self, tOptions, self.options.WhiteFillMe) -- for debug purposes ;)
-- if picture hasn't been set but a sprite has been, enable picture
if tOptions.Sprite ~= nil and tOptions.Picture == nil then
tOptions.Picture = true
end
for k,v in pairs(tOptions) do
if type(v) == "boolean" then
tOptions[k] = v and "1" or "0"
end
end
return tOptions
end
-- Creates an XmlDoc Table of the widget prototype
function Control:ToXmlDocTable(bIsForm)
local tInlineFunctions = {}
local tForm = self:ParseOptions()
-- setup defaults and necessary values
tForm.__XmlNode = bIsForm and "Form" or "Control"
tForm.Font = tForm.Font or "Default"
tForm.Template = tForm.Template or "Default"
tForm.TooltipType = tForm.TooltipType or "OnCursor"
if not tForm.PosX or not tForm.PosY or not tForm.Height or not tForm.Width then
tForm.TAnchorOffset = tForm.TAnchorOffset or 0
tForm.LAnchorOffset = tForm.LAnchorOffset or 0
tForm.BAnchorOffset = tForm.BAnchorOffset or 0
tForm.RAnchorOffset = tForm.RAnchorOffset or 0
tForm.BAnchorPoint = tForm.BAnchorPoint or 0
tForm.RAnchorPoint = tForm.RAnchorPoint or 0
tForm.TAnchorPoint = tForm.TAnchorPoint or 0
tForm.LAnchorPoint = tForm.LAnchorPoint or 0
end
if self.AddSubclassFields ~= nil and type(self.AddSubclassFields) == "function" then
self:AddSubclassFields(tForm)
end
tForm.Name = tForm.Name or kstrDefaultName
tForm.Class = tForm.Class or "Window"
local tAliasEvents = {}
local tInlineLookup = {}
for _, tEvent in ipairs(self.events) do
if tEvent.strName and tEvent.strFunction and tEvent.strName ~= "" then
if tEvent.strFunction:match("^Event::") then
tinsert(tAliasEvents, tEvent)
elseif tEvent.strFunction ~= "" then
tinsert(tForm, { __XmlNode = "Event", Function = tEvent.strFunction, Name = tEvent.strName })
if tEvent.fnInline ~= nil then
tInlineLookup[tEvent.strName] = tEvent.strFunction
tInlineFunctions[tEvent.strFunction] = tEvent.fnInline
end
end
end
end
-- check if an event would like to reference an another event handler's inline function
for _, tEvent in ipairs(tAliasEvents) do
local strFunctionName = tInlineLookup[tEvent.strFunction:gsub("^Event::", "")]
if strFunctionName then
tinsert(tForm, { __XmlNode = "Event", Function = strFunctionName, Name = tEvent.strName })
end
end
for _, tPixie in ipairs(self.pixies) do
local tPixieNode = { __XmlNode = "Pixie", }
for k,v in pairs(tPixie) do
tPixieNode[k] = v
end
tinsert(tForm, tPixieNode)
end
for _, tChild in ipairs(self.children) do
if tChild.ToXmlDocTable and type(tChild.ToXmlDocTable) == "function" then
local tXd, tIf = tChild:ToXmlDocTable()
tinsert(tForm, tXd)
for k,v in pairs(tIf) do
tInlineFunctions[k] = tInlineFunctions[k] or v
end
end
end
if self.oData ~= nil then
tForm.__GEMINIGUI_LUADATA = self.oData
end
if bIsForm then
tForm = { __XmlNode = "Forms", tForm }
end
return tForm, tInlineFunctions
end
-- Collect window name, data and text from the XmlDoc table (recursively)
-- and give each window a unique name for it's layer
local kstrTempName = "GeminiGUIWindow."
local function CollectNameData(tXml, tData, strNamespace)
if type(tXml) ~= "table" then return end
local nCount = 0
tData = tData or {}
strNamespace = strNamespace or ""
for i, t in ipairs(tXml) do
if t.__XmlNode == "Control" then -- only process controls (aka children)
nCount = nCount + 1
local strName = strformat("%s.%s",(t.Name or "GeminiGUIWindow"), nCount)
local strNS = strformat("%s%s%s", strNamespace, strNamespace:len() > 0 and ":" or "", strName)
local strFinalName = t.Name or strName
-- collect the info for the window/control
tData[strNS] = { strNS = strNS, strName = strName, strFinalName = strFinalName, luaData = t.__GEMINIGUI_LUADATA, strText = t.Text, bIsMLWindow = t.Class == "MLWindow" }
-- rename the window to the unique layered name
t.Name = strName
-- clean up XmlDoc table by removing unnecessary elements
t.__GEMINIGUI_LUADATA = nil
CollectNameData(t, tData, strNS)
elseif t.__XmlNode == "Form" or t.__XmlNode == "Forms" then
CollectNameData(t, tData, "")
end
end
return tData
end
-- Process each window and it's children and assign data, AML
-- and rename the window back to what the consumer wants.
local function FinalizeWindow(wnd, tData)
-- collect a list of keys and sort them in order
-- of how deep they are overall (# of :) (>^o^)>
local tChildOrder = {}
for strNS, _ in pairs(tData) do
local _, nCount = strNS:gsub(":", "")
tinsert(tChildOrder, { strNS, nCount })
end
tsort(tChildOrder, function(a,b) return a[2] > b[2] end)
-- process child windows in depth order, setting their data, AML and
-- renaming them back to what they are intended to be
for i = 1, #tChildOrder do
local tWndData = tData[tChildOrder[i][1]]
local wndChild = wnd:FindChild(tWndData.strNS)
if wndChild then
if tWndData.luaData then
wndChild:SetData(tWndData.luaData)
end
if tWndData.bIsMLWindow and tWndData.strText then
wndChild:SetAML(tWndData.strText)
end
if tWndData.strFinalName ~= tWndData.strName then
wndChild:SetName(tWndData.strFinalName)
end
end
end
end
function Control:Initialize()
self.events = {}
self.children = {}
self.pixies = {}
end
-- Gets an instance of the widget
-- @param eventHandler The eventHandler of the widget
-- @param wndParent The parent of the widget
-- @returns (userdata) The userdata version of the widget
function Control:GetInstance(eventHandler, wndParent)
eventHandler = eventHandler or {}
if type(eventHandler) ~= "table" then
error("Usage: EventHandler is not valid. Must be a table.")
end
self:Initialize()
local xdt, tInlines = self:ToXmlDocTable(true)
for k,v in pairs(tInlines) do
eventHandler[k] = eventHandler[k] or v
end
-- collect names and reassign them to something generic
-- collect any lua data and if AML needs to be set
local tChildData = CollectNameData(xdt)
-- create the XmlDoc and C++ window
local xd = XmlDoc.CreateFromTable(xdt)
local strFormName = self.options.Name or kstrDefaultName
local wnd = Apollo.LoadForm(xd, strFormName, wndParent, eventHandler)
if wnd then
-- set the lua data and aml followed by name for all child widgets
FinalizeWindow(wnd, tChildData)
if self.oData then
wnd:SetData(self.oData)
end
else
-- Print("GeminiGUI failed to create window")
end
return wnd, eventHandler
end
end
--[[ File: widgets/Window.lua ]]--
do
local WidgetType, Version = "Window", 1
local function Constructor()
local ctrl = GeminiGUI.ControlBase:new()
ctrl:SetOptions{
Class = WidgetType,
Name = "GeminiGUI" .. WidgetType,
RelativeToClient = true,
Font = "Default",
Template = "Default",
TooltipType = "OnCursor",
}
return ctrl
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/Button.lua ]]--
do
local WidgetType, Version = "Button", 1
local Button = GeminiGUI.ControlBase:new()
local function GetTextTheme(strTheme)
return {
NormalTextColor = strTheme .. "Normal",
PressedTextColor = strTheme .. "Pressed",
PressedFlybyTextColor = strTheme .. "PressedFlyby",
FlybyTextColor = strTheme .. "Flyby",
DisabledTextColor = strTheme .. "Disabled"
}
end
local function GetTextColorTheme(strColor)
return {
NormalTextColor = strColor,
PressedTextColor = strColor,
PressedFlybyTextColor = strColor,
FlybyTextColor = strColor,
DisabledTextColor = strColor
}
end
function Button:SetTextThemeToColor(strColor)
self:SetOptions(GetTextColorTheme(strColor))
end
function Button:SetTextTheme(strTheme)
self:SetOptions(GetTextTheme(strTheme))
end
function Button:AddSubclassFields(tForm)
if self.options.TextThemeColor ~= nil then
local tTheme = GetTextColorTheme(self.options.TextThemeColor)
for k,v in pairs(tTheme) do
tForm[k] = v
end
if tForm.TextThemeColor ~= nil then
tForm.TextThemeColor = nil
end
end
if self.options.TextTheme ~= nil then
local tTheme = GetTextTheme(self.options.TextTheme)
for k,v in pairs(tTheme) do
tForm[k] = v
end
if tForm.TextTheme ~= nil then
tForm.TextTheme = nil
end
end
end
local function Constructor()
local ctrl = Button:new()
ctrl:SetOptions{
Name = "GeminiGUI" .. WidgetType,
Class = WidgetType,
ButtonType = "PushButton",
RadioGroup = "",
Font = "Thick",
DT_VCENTER = true,
DT_CENTER = true,
}
return ctrl
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/PushButton.lua ]]--
do
local WidgetType, Version = "PushButton", 1
local function Constructor()
local btn = GeminiGUI:Create('Button', {
Name = "GeminiGUI" .. WidgetType,
ButtonType = "PushButton",
DT_VCENTER = true,
DT_CENTER = true,
Base = "CRB_Basekit:kitBtn_Holo",
Font = "CRB_InterfaceMedium",
})
btn:SetTextTheme("UI_BtnTextHolo")
return btn
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/Buzzer.lua ]]--
do
local WidgetType, Version = "Buzzer", 1
local function Constructor()
local btn = GeminiGUI:Create('Button', {
Name = "GeminiGUI" .. WidgetType,
ButtonType = "Buzzer",
DT_VCENTER = true,
DT_CENTER = true,
Base = "CRB_Basekit:kitBtn_Holo",
Font = "CRB_InterfaceMedium",
BuzzerFrequency = 15,
})
btn:SetTextTheme("UI_BtnTextHolo")
return btn
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/CheckBox.lua ]]--
do
local WidgetType, Version = "CheckBox", 1
local function Constructor()
local checkbox = GeminiGUI:Create('Button', {
Name = "GeminiGUI" .. WidgetType,
DrawAsCheckbox = true,
DT_CENTER = false,
DT_VCENTER = true,
ButtonType = "Check",
Font = "CRB_InterfaceMedium",
Base = "CRB_Basekit:kitBtn_Holo_RadioRound",
TextColor = "White",
})
return checkbox
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/ActionBarButton.lua ]]--
do
local WidgetType, Version = "ActionBarButton", 1
local function Constructor()
local btn = GeminiGUI.ControlBase:new()
btn:SetOptions{
Class = WidgetType,
Name = "GeminiGUI" .. WidgetType,
Base = "ClientSprites:Button_ActionBarBlank",
RelativeToClient = true,
IfHoldNoSignal = true,
DT_VCENTER = true,
DT_CENTER = true,
NeverBringToFront = true,
WindowSoundTemplate = "ActionBarButton",
ProcessRightClick = true,
Font = "CRB_InterfaceLarge_O",
IgnoreTooltipDelay = true,
RechargeBarLAnchorPoint = 1,
RechargeBarLAnchorOffset = -8,
RechargeBarTAnchorPoint = 0,
RechargeBarTAnchorOffset = 4,
RechargeBarRAnchorPoint = 1,
RechargeBarRAnchorOffset = 4,
RechargeBarBAnchorPoint = 1,
RechargeBarBAnchorOffset = -14,
RechargeBarEmptyColorAttribute = "Black",
RechargeBarFullColorAttribute = "ffffffff",
RechargeBarEmptyAttribute = "WhiteFill",
RechargeBarFullAttribute = "sprStalker_VerticalGooPulse",
TooltipType = "DynamicFloater",
ShortHotkeyFontAttribute = "CRB_InterfaceLarge_BO",
LongHotkeyFontAttribute = "CRB_InterfaceSmall_O",
CountFontAttribute = "CRB_InterfaceSmall_O",
CooldownFontAttribute = "CRB_HeaderLarge",
}
return btn
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/TreeControl.lua ]]--
do
local WidgetType, Version = "TreeControl", 1
local function Constructor()
local wnd = GeminiGUI.ControlBase:new()
wnd:SetOptions{
Class = WidgetType,
Name = "GeminiGUI" .. WidgetType,
Font = "CRB_Pixel",
Template = "CRB_Hologram",
UseTemplateBG = true,
Picture = true,
Border = true,
RelativeToClient = true,
}
return wnd
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/ComboBox.lua ]]--
do
local WidgetType, Version = "ComboBox", 1
local ComboBox = GeminiGUI.ControlBase:new()
function ComboBox:AddSubclassFields(tForm)
if self.options.UseTheme == true then
-- if windowload is set, it will respect that
-- apply the theme then call the windowload set
-- by the consumer. Otherwise it will setup
-- its own windowload event
-- todo: probably needs a refactor
local windowLoadEvent
for k,v in pairs(self.events) do
if v.strName == "WindowLoad" then
windowLoadEvent = v
break
end
end
if windowLoadEvent ~= nil then
local strFont = self.options.Font or "CRB_InterfaceMedium"
local strBtnBase = self.options.DropdownBtnBase or "Collections_TEMP:sprCollections_TEMP_RightAlignDropdown"
local nBtnWidth = self.options.DropdownBtnWidth
local fOldWindowLoad = windowLoadEvent.fnInline
local strOldWindowLoad = windowLoadEvent.strFunction
if windowLoadEvent.fnInline == nil then
fOldWindowLoad = windowLoadEvent.strFunction
end
local fNewWindowLoad = function(self, wndHandler, wndControl)
if wndHandler == wndControl then
local cbBtnSkin = GeminiGUI:Create({ Class="Button", Base=strBtnBase }):GetInstance()
if nBtnWidth then
wndControl:GetButton():SetAnchorOffsets(-nBtnWidth,0,0,0)
end
wndControl:GetButton():ChangeArt(cbBtnSkin)
wndControl:GetGrid():SetStyle("AutoHideScroll", true)
wndControl:GetGrid():SetStyle("TransitionShowHide", true)
wndControl:GetGrid():SetFont(strFont)
end
if type(fOldWindowLoad) == "function" then
fOldWindowLoad(self, wndHandler, wndControl)
elseif type(fOldWindowLoad) == "string" and type(self[fOldWindowLoad]) == "function" then
self[fOldWindowLoad](self, wndHandler, wndControl)
end
end
windowLoadEvent.fnInline = fNewWindowLoad
windowLoadEvent.strFunction = "OnWindowLoad_" .. tostring(windowLoadEvent.fnInline):gsub("function: ", "_")
end
if tForm.UseTheme ~= nil then
tForm.UseTheme = nil
end
end
end
local function Constructor()
local cbo = ComboBox:new()
cbo:SetOptions{
Class = WidgetType,
Name = "GeminiGUI" .. WidgetType,
Font = "CRB_InterfaceMedium",
DT_VCENTER = true,
RelativeToClient = true,
Overlapped = true,
AutoSize = true,
Template = "HologramControl2",
UseTemplateBG = true,
Picture = true,
Border = true,
UseTheme = true,
-- DropdownBtnBase = "CRB_Basekit:kitBtn_ScrollHolo_DownLarge",
-- DropdownBtnWidth = 20,
}
return cbo
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/Slider.lua ]]--
do
local WidgetType, Version = "SliderBar", 1
local function Constructor()
local ctrl = GeminiGUI.ControlBase:new()
ctrl:SetOptions{
Class = WidgetType,
Name = "GeminiGUI" .. WidgetType,
Template = "CRB_Scroll_HoloLarge",
Middle = "CRB_Basekit:kitScrollbase_Horiz_Holo",
UseButtons = true,
Min = 1,
Max = 100,
TickAmount = 1,
RelativeToClient = true,
}
return ctrl
end
GeminiGUI:RegisterWidgetType(WidgetType, Constructor, Version)
end
--[[ File: widgets/ProgressBar.lua ]]--
do
local WidgetType, Version = "ProgressBar", 1
local function Constructor()
local ctrl = GeminiGUI.ControlBase:new()
ctrl:SetOptions{
Class = WidgetType,
Name = "GeminiGUI" .. WidgetType,
ProgressEmpty = "BlackFill",
ProgressFull = "CRB_Raid:sprRaid_ShieldProgBar",
UseTemplateBG = true,
Template = "CRB_Hologram",
Border = true,