-
Notifications
You must be signed in to change notification settings - Fork 0
/
window.lua
1158 lines (1037 loc) · 36.2 KB
/
window.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 addon, dark_addon = ...
local builder = { }
local DiesalTools = LibStub("DiesalTools-1.0")
local DiesalStyle = LibStub("DiesalStyle-1.0")
local DiesalGUI = LibStub("DiesalGUI-1.0")
local DiesalMenu = LibStub("DiesalMenu-1.0")
local SharedMedia = LibStub("LibSharedMedia-3.0")
local Colors = DiesalStyle.Colors
local HSL, ShadeColor, TintColor = DiesalTools.HSL, DiesalTools.ShadeColor, DiesalTools.TintColor
local buttonStyleSheet = {
['frame-color'] = {
type = 'texture',
layer = 'BACKGROUND',
color = '2f353b',
offset = 0,
},
['frame-highlight'] = {
type = 'texture',
layer = 'BORDER',
gradient = 'VERTICAL',
color = 'FFFFFF',
alpha = 0,
alphaEnd = .1,
offset = -1,
},
['frame-outline'] = {
type = 'outline',
layer = 'BORDER',
color = '000000',
offset = 0,
},
['frame-inline'] = {
type = 'outline',
layer = 'BORDER',
gradient = 'VERTICAL',
color = 'ffffff',
alpha = .02,
alphaEnd = .09,
offset = -1,
},
['frame-hover'] = {
type = 'texture',
layer = 'HIGHLIGHT',
color = 'ffffff',
alpha = .1,
offset = 0,
},
['text-color'] = {
type = 'Font',
color = 'b8c2cc',
},
}
local buttonStyleSheetGreen = {
['frame-color'] = {
type = 'texture',
layer = 'BACKGROUND',
color = '336d38',
offset = 0,
},
['frame-highlight'] = {
type = 'texture',
layer = 'BORDER',
gradient = 'VERTICAL',
color = 'FFFFFF',
alpha = 0,
alphaEnd = .1,
offset = -1,
},
['frame-outline'] = {
type = 'outline',
layer = 'BORDER',
color = '000000',
offset = 0,
},
['frame-inline'] = {
type = 'outline',
layer = 'BORDER',
gradient = 'VERTICAL',
color = 'ffffff',
alpha = .02,
alphaEnd = .09,
offset = -1,
},
['frame-hover'] = {
type = 'texture',
layer = 'HIGHLIGHT',
color = 'ffffff',
alpha = .1,
offset = 0,
},
['text-color'] = {
type = 'Font',
color = 'c4ffc9',
},
}
local buttonStyleSheetOrange = {
['frame-color'] = {
type = 'texture',
layer = 'BACKGROUND',
color = 'b57c13',
offset = 0,
},
['frame-highlight'] = {
type = 'texture',
layer = 'BORDER',
gradient = 'VERTICAL',
color = 'FFFFFF',
alpha = 0,
alphaEnd = .1,
offset = -1,
},
['frame-outline'] = {
type = 'outline',
layer = 'BORDER',
color = '000000',
offset = 0,
},
['frame-inline'] = {
type = 'outline',
layer = 'BORDER',
gradient = 'VERTICAL',
color = 'ffffff',
alpha = .02,
alphaEnd = .09,
offset = -1,
},
['frame-hover'] = {
type = 'texture',
layer = 'HIGHLIGHT',
color = 'ffffff',
alpha = .1,
offset = 0,
},
['text-color'] = {
type = 'Font',
color = 'ffd6c6',
},
}
local buttonStyleSheetRed = {
['frame-color'] = {
type = 'texture',
layer = 'BACKGROUND',
color = '682f2f',
offset = 0,
},
['frame-highlight'] = {
type = 'texture',
layer = 'BORDER',
gradient = 'VERTICAL',
color = 'FFFFFF',
alpha = 0,
alphaEnd = .1,
offset = -1,
},
['frame-outline'] = {
type = 'outline',
layer = 'BORDER',
color = '000000',
offset = 0,
},
['frame-inline'] = {
type = 'outline',
layer = 'BORDER',
gradient = 'VERTICAL',
color = 'ffffff',
alpha = .02,
alphaEnd = .09,
offset = -1,
},
['frame-hover'] = {
type = 'texture',
layer = 'HIGHLIGHT',
color = 'ffffff',
alpha = .1,
offset = 0,
},
['text-color'] = {
type = 'Font',
color = 'ffbcbc',
},
}
local spinnerStyleSheet = {
['frame-background'] = {
type = 'texture',
layer = 'BACKGROUND',
color = '000000',
alpha = .6,
},
['frame-inline'] = {
type = 'outline',
layer = 'BORDER',
color = '000000',
alpha = .6,
},
['frame-outline'] = {
type = 'outline',
layer = 'BORDER',
color = 'FFFFFF',
alpha = .02,
position = 1,
},
['frame-hover'] = {
type = 'outline',
layer = 'HIGHLIGHT',
color = 'FFFFFF',
alpha = .25,
position = -1,
},
['editBox-font'] = {
type = 'Font',
color = Colors.UI_TEXT,
},
['bar-background'] = {
type = 'texture',
layer = 'BACKGROUND',
gradient = {'VERTICAL',Colors.UI_A100,ShadeColor(Colors.UI_A100,.1)},
},
['bar-inline'] = {
type = 'outline',
layer = 'BORDER',
gradient = {'VERTICAL','FFFFFF','FFFFFF'},
alpha = {.07,.02},
},
['bar-outline'] = {
type = 'texture',
layer = 'ARTWORK',
color = '000000',
alpha = .7,
width = 1,
position = {nil,1,0,0},
}
}
local createButtonStyle = {
type = 'texture',
layer = 'ARTWORK',
image = {'DiesalGUIcons', {1,6,16,256,128}},
alpha = .7,
position = {-2,nil,-2,nil},
width = 16,
height = 16,
}
local deleteButtonStyle = {
type = 'texture',
texFile = 'DiesalGUIcons',
texCoord = {2,6,16,256,128},
alpha = .7,
offset = {-2,nil,-2,nil},
width = 16,
height = 16,
}
local ButtonNormal = {
type = 'texture',
texColor = 'ffffff',
alpha = .7,
}
local ButtonOver = {
type = 'texture',
alpha = 1,
}
local ButtonClicked = {
type = 'texture',
alpha = .3,
}
local WindowStylesheet = {
['frame-outline'] = {
type = 'outline',
layer = 'BACKGROUND',
color = '000000',
},
['frame-shadow'] = {
type = 'shadow',
},
['titleBar-color'] = {
type = 'texture',
layer = 'BACKGROUND',
color = '0b0c0f',
alpha = .95,
},
['titletext-Font'] = {
type = 'font',
color = 'd8d8d8',
},
['closeButton-icon'] = {
type = 'texture',
layer = 'ARTWORK',
image = {'DiesalGUIcons', {9,5,16,256,128}},
alpha = .3,
position = {-2,nil,-1,nil},
width = 16,
height = 16,
},
['closeButton-iconHover'] = {
type = 'texture',
layer = 'HIGHLIGHT',
image = {'DiesalGUIcons', {9,5,16,256,128}, '4da6ff'},
alpha = 1,
position = {-2,nil,-1,nil},
width = 16,
height = 16,
},
['header-background'] = {
type = 'texture',
layer = 'BACKGROUND',
gradient = {'VERTICAL','4da6ff',Colors.UI_400_GR[2]},
alpha = .95,
position = {0,0,0,-1},
},
['header-inline'] = {
type = 'outline',
layer = 'BORDER',
gradient = {'VERTICAL','ffffff','ffffff'},
alpha = {.05,.02},
position = {0,0,0,-1},
},
['header-divider'] = {
type = 'texture',
layer = 'BORDER',
color = '000000',
alpha = 1,
position = {0,0,nil,0},
height = 1,
},
['content-background'] = {
type = 'texture',
layer = 'BACKGROUND',
color = '1a1d23',
alpha = .90,
},
['content-outline'] = {
type = 'outline',
layer = 'BORDER',
color = 'FFFFFF',
alpha = .01
},
['footer-background'] = {
type = 'texture',
layer = 'BACKGROUND',
gradient = {'VERTICAL',Colors.UI_400_GR[1],Colors.UI_400_GR[2]},
alpha = .95,
position = {0,0,-1,0},
},
['footer-divider'] = {
type = 'texture',
layer = 'BACKGROUND',
color = '000000',
position = {0,0,0,nil},
height = 1,
},
['footer-inline'] = {
type = 'outline',
layer = "BORDER",
gradient = {'VERTICAL','ffffff','ffffff'},
alpha = {.05,.02},
position = {0,0,-1,0},
debug = true,
},
}
local checkBoxStyle = {
base = {
type = 'texture',
layer = 'ARTWORK',
color = '00FF00',
position = -3,
},
disabled = {
type = 'texture',
color = '00FFFF',
},
enabled = {
type = 'texture',
color = Colors.UI_A400,
},
}
DiesalGUI:RegisterObjectConstructor("FontString", function()
local self = DiesalGUI:CreateObjectBase(Type)
local frame = CreateFrame('Frame',nil,UIParent)
local fontString = frame:CreateFontString(nil, "OVERLAY", 'DiesalFontNormal')
self.frame = frame
self.fontString = fontString
self.SetParent = function(self, parent)
self.frame:SetParent(parent)
end
self.OnRelease = function(self)
self.fontString:SetText('')
end
self.OnAcquire = function(self)
self:Show()
end
self.type = "FontString"
return self
end, 1)
DiesalGUI:RegisterObjectConstructor("Rule", function()
local self = DiesalGUI:CreateObjectBase(Type)
local frame = CreateFrame('Frame',nil,UIParent)
self.frame = frame
frame:SetHeight(1)
frame.texture = frame:CreateTexture()
frame.texture:SetColorTexture(0,0,0,0.5)
frame.texture:SetAllPoints(frame)
self.SetParent = function(self, parent)
self.frame:SetParent(parent)
end
self.OnRelease = function(self)
self:Hide()
end
self.OnAcquire = function(self)
self:Show()
end
self.type = "Rule"
return self
end, 1)
local function buildElements(table, parent)
local offset = -5
for _, element in ipairs(table.template) do
local push, pull = 0, 0
if element.type == 'header' then
local tmp = DiesalGUI:Create("FontString")
tmp:SetParent(parent.content)
parent:AddChild(tmp)
tmp = tmp.fontString
tmp:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset)
tmp:SetText(element.text)
if element.justify then
tmp:SetJustifyH(element.justify)
else
tmp:SetJustifyH('LEFT')
end
tmp:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 13)
tmp:SetWidth(parent.content:GetWidth()-10)
if element.align then
tmp:SetJustifyH(strupper(element.align))
end
if element.key then
table.window.elements[element.key] = tmp
end
elseif element.type == 'text' then
local tmp = DiesalGUI:Create("FontString")
tmp:SetParent(parent.content)
parent:AddChild(tmp)
tmp = tmp.fontString
tmp:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset)
tmp:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset)
tmp:SetText(element.text)
tmp:SetJustifyH('LEFT')
tmp:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), element.size or 10)
tmp:SetWidth(parent.content:GetWidth()-10)
if not element.offset then
element.offset = tmp:GetStringHeight()
end
if element.align then
tmp:SetJustifyH(strupper(element.align))
end
if element.key then
table.window.elements[element.key] = tmp
end
elseif element.type == 'rule' then
local tmp = DiesalGUI:Create('Rule')
parent:AddChild(tmp)
tmp:SetParent(parent.content)
tmp.frame:SetPoint('TOPLEFT', parent.content, 'TOPLEFT', 5, offset-3)
tmp.frame:SetPoint('BOTTOMRIGHT', parent.content, 'BOTTOMRIGHT', -5, offset-3)
if element.key then
table.window.elements[element.key] = tmp
end
elseif element.type == 'texture' then
local tmp = CreateFrame('Frame')
tmp:SetParent(parent.content)
if element.center then
tmp:SetPoint('CENTER', parent.content, 'CENTER', (element.x or 0), offset-(element.y or 0))
else
tmp:SetPoint('TOPLEFT', parent.content, 'TOPLEFT', 5+(element.x or 0), offset-3+(element.y or 0))
end
tmp:SetWidth(parent:GetWidth()-10)
tmp:SetHeight(element.height)
tmp:SetWidth(element.width)
tmp.texture = tmp:CreateTexture()
tmp.texture:SetTexture(element.texture)
tmp.texture:SetAllPoints(tmp)
if element.key then
table.window.elements[element.key] = tmp
end
elseif element.type == 'checkbox' then
local tmp = DiesalGUI:Create('Toggle')
parent:AddChild(tmp)
tmp:SetParent(parent.content)
tmp:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset)
tmp:SetEventListener('OnValueChanged', function(this, event, checked)
dark_addon.settings.store(table.key .. '_' .. element.key, checked)
end)
tmp.checkBoxStyle = checkBoxStyle
tmp:SetChecked(dark_addon.settings.fetch(table.key .. '_' .. element.key, element.default or false))
tmp:SetText(element.text)
if element.desc then
local tmp_desc = DiesalGUI:Create("FontString")
tmp_desc:SetParent(parent.content)
parent:AddChild(tmp_desc)
tmp_desc = tmp_desc.fontString
tmp_desc:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-15)
tmp_desc:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset-15)
tmp_desc:SetText(element.desc)
tmp_desc:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 9)
tmp_desc:SetWidth(parent.content:GetWidth()-10)
tmp_desc:SetJustifyH('LEFT')
push = tmp_desc:GetStringHeight() + 5
end
if element.key then
table.window.elements[element.key..'Text'] = tmp_text
table.window.elements[element.key] = tmp
end
elseif element.type == 'spinner' then
local tmp_spin = DiesalGUI:Create('Spinner')
parent:AddChild(tmp_spin)
tmp_spin:SetParent(parent.content)
tmp_spin:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset)
tmp_spin:SetNumber(
dark_addon.settings.fetch(table.key .. '_' .. element.key, element.default)
)
if element.width then
tmp_spin.settings.width = element.width
end
if element.min then
tmp_spin.settings.min = element.min
end
if element.max then
tmp_spin.settings.max = element.max
end
if element.step then
tmp_spin.settings.step = element.step
end
if element.shiftStep then
tmp_spin.settings.shiftStep = element.shiftStep
end
tmp_spin:ApplySettings()
if tmp_spin.SetStylesheet then tmp_spin:SetStylesheet(spinnerStyleSheet) end
tmp_spin:SetEventListener('OnValueChanged', function(this, event, userInput, number)
if not userInput then return end
dark_addon.settings.store(table.key .. '_' .. element.key, tonumber(number))
end)
local tmp_text = DiesalGUI:Create("FontString")
tmp_text:SetParent(parent.content)
parent:AddChild(tmp_text)
tmp_text = tmp_text.fontString
tmp_text:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-4)
tmp_text:SetText(element.text)
tmp_text:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 10)
tmp_text:SetJustifyH('LEFT')
tmp_text:SetWidth(parent.content:GetWidth()-10)
if element.desc then
local tmp_desc = DiesalGUI:Create("FontString")
tmp_desc:SetParent(parent.content)
parent:AddChild(tmp_desc)
tmp_desc = tmp_desc.fontString
tmp_desc:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-18)
tmp_desc:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset-18)
tmp_desc:SetText(element.desc)
tmp_desc:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 10)
tmp_desc:SetWidth(parent.content:GetWidth()-10)
tmp_desc:SetJustifyH('LEFT')
push = tmp_desc:GetStringHeight() + 5
end
if element.key then
table.window.elements[element.key..'Text'] = tmp_text
table.window.elements[element.key] = tmp_spin
end
elseif element.type == 'checkspin' then
local tmp_spin = DiesalGUI:Create('Spinner')
parent:AddChild(tmp_spin)
tmp_spin:SetParent(parent.content)
tmp_spin:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset)
if element.width then
tmp_spin.settings.width = element.width
end
if element.min then
tmp_spin.settings.min = element.min
end
if element.max then
tmp_spin.settings.max = element.max
end
if element.step then
tmp_spin.settings.step = element.step
end
if element.shiftStep then
tmp_spin.settings.shiftStep = element.shiftStep
end
tmp_spin:SetNumber(
dark_addon.settings.fetch(table.key .. '_' .. element.key .. '.spin', element.default_spin or 0)
)
if tmp_spin.SetStylesheet then tmp_spin:SetStylesheet(spinnerStyleSheet) end
tmp_spin:ApplySettings()
tmp_spin:SetEventListener('OnValueChanged', function(this, event, userInput, number)
if not userInput then return end
dark_addon.settings.store(table.key .. '_' .. element.key .. '.spin', tonumber(number))
end)
local tmp_check = DiesalGUI:Create('Toggle')
parent:AddChild(tmp_check)
tmp_check:SetParent(parent.content)
tmp_check:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset - 2)
tmp_check.checkBoxStyle = checkBoxStyle
tmp_check:SetEventListener('OnValueChanged', function(this, event, checked)
dark_addon.settings.store(table.key .. '_' .. element.key .. '.check', checked)
end)
tmp_check:SetChecked(dark_addon.settings.fetch(table.key .. '_' .. element.key .. '.check', element.default_check or false))
tmp_check:SetText(element.text)
if element.desc then
local tmp_desc = DiesalGUI:Create("FontString")
tmp_desc:SetParent(parent.content)
parent:AddChild(tmp_desc)
tmp_desc = tmp_desc.fontString
tmp_desc:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-18)
tmp_desc:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset-18)
tmp_desc:SetText(element.desc)
tmp_desc:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 9)
tmp_desc:SetWidth(parent.content:GetWidth()-10)
tmp_desc:SetJustifyH('LEFT')
push = tmp_desc:GetStringHeight() + 5
end
if element.key then
table.window.elements[element.key..'Text'] = tmp_text
table.window.elements[element.key..'Check'] = tmp_check
table.window.elements[element.key..'Spin'] = tmp_spin
end
elseif element.type == 'combo' or element.type == 'dropdown' then
local tmp_list = DiesalGUI:Create('Dropdown')
if element.width then tmp_list.settings.width = element.width end
parent:AddChild(tmp_list)
tmp_list:SetParent(parent.content)
tmp_list:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset)
local orderdKeys = { }
local list = { }
for i, value in pairs(element.list) do
orderdKeys[i] = value.key
list[value.key] = value.text
end
tmp_list:SetList(list, orderdKeys)
tmp_list:SetEventListener('OnValueChanged', function(this, event, value)
dark_addon.settings.store(table.key .. '_' .. element.key, value)
end)
tmp_list:SetValue(dark_addon.settings.fetch(table.key .. '_' .. element.key, element.default))
local tmp_text = DiesalGUI:Create("FontString")
tmp_text:SetParent(parent.content)
parent:AddChild(tmp_text)
tmp_text = tmp_text.fontString
tmp_text:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-3)
tmp_text:SetText(element.text)
tmp_text:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 10)
tmp_text:SetJustifyH('LEFT')
tmp_text:SetWidth(parent.content:GetWidth()-10)
if element.desc then
local tmp_desc = DiesalGUI:Create("FontString")
tmp_desc:SetParent(parent.content)
parent:AddChild(tmp_desc)
tmp_desc = tmp_desc.fontString
tmp_desc:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-18)
tmp_desc:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset-18)
tmp_desc:SetText(element.desc)
tmp_desc:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 9)
tmp_desc:SetWidth(parent.content:GetWidth()-10)
tmp_desc:SetJustifyH('LEFT')
push = tmp_desc:GetStringHeight() + 5
end
if element.key then
table.window.elements[element.key..'Text'] = tmp_text
table.window.elements[element.key] = tmp_list
end
elseif element.type == 'button' then
local tmp = DiesalGUI:Create("Button")
element.height = element.height or 20
parent:AddChild(tmp)
tmp:SetParent(parent.content)
tmp:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5 + (element.offset_y and element.offset_y or 0), offset)
tmp:SetText(element.text)
tmp:SetWidth(element.width or parent:GetWidth() - 10)
tmp:SetHeight(element.height or 20)
tmp.buttonStyleSheetGreen = buttonStyleSheetGreen
tmp.buttonStyleSheetRed = buttonStyleSheetRed
tmp.buttonStyleSheetOrange = buttonStyleSheetOrange
if tmp.SetStylesheet then tmp:SetStylesheet(buttonStyleSheet) end
if element.call then
element.callback(tmp, 'OnStyle')
end
tmp:SetEventListener("OnClick", element.callback)
if element.desc then
local tmp_desc = DiesalGUI:Create("FontString")
tmp_desc:SetParent(parent.content)
parent:AddChild(tmp_desc)
tmp_desc = tmp_desc.fontString
tmp_desc:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-element.height-3)
tmp_desc:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset-element.height-3)
tmp_desc:SetText(element.desc)
tmp_desc:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 9)
tmp_desc:SetWidth(parent.content:GetWidth()-10)
tmp_desc:SetJustifyH('LEFT')
push = tmp_desc:GetStringHeight() + 5
end
if element.align then
tmp:SetJustifyH(strupper(element.align))
end
if element.key then
table.window.elements[element.key] = tmp
end
elseif element.type == "input" then
local tmp_input = DiesalGUI:Create('Input')
parent:AddChild(tmp_input)
tmp_input:SetParent(parent.content)
tmp_input:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset)
if element.width then
tmp_input:SetWidth(element.width)
end
tmp_input:SetText(dark_addon.settings.fetch(table.key .. '_' .. element.key, element.default or ''))
tmp_input:SetEventListener('OnEditFocusLost', function(this)
dark_addon.settings.store(table.key .. '_' .. element.key, this:GetText())
end)
local tmp_text = DiesalGUI:Create("FontString")
tmp_text:SetParent(parent.content)
parent:AddChild(tmp_text)
tmp_text = tmp_text.fontString
tmp_text:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-3)
tmp_text:SetText(element.text)
tmp_text:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 10)
tmp_text:SetJustifyH('LEFT')
if element.desc then
local tmp_desc = DiesalGUI:Create("FontString")
tmp_desc:SetParent(parent.content)
parent:AddChild(tmp_desc)
tmp_desc = tmp_desc.fontString
tmp_desc:SetPoint("TOPLEFT", parent.content, "TOPLEFT", 5, offset-18)
tmp_desc:SetPoint("TOPRIGHT", parent.content, "TOPRIGHT", -5, offset-18)
tmp_desc:SetText(element.desc)
tmp_desc:SetFont(SharedMedia:Fetch('font', 'Calibri Bold'), 9)
tmp_desc:SetWidth(parent.content:GetWidth()-10)
tmp_desc:SetJustifyH('LEFT')
push = tmp_desc:GetStringHeight() + 5
end
if element.key then
table.window.elements[element.key..'Text'] = tmp_text
table.window.elements[element.key] = tmp_input
end
elseif element.type == 'spacer' then
-- NOTHING!
end
if element.type == 'rule' then
offset = offset + -10
elseif element.type == 'spinner' or element.type == 'checkspin' then
offset = offset + -19
elseif element.type == 'combo' or element.type == 'dropdown' then
offset = offset + -20
elseif element.type == 'texture' then
offset = offset + -(element.offset or 0)
elseif element.type == "text" then
offset = offset + -(element.offset) - (element.size or 10)
elseif element.type == 'button' then
offset = offset + -20
elseif element.type == 'spacer' then
offset = offset + -(element.size or 10)
else
offset = offset + -16
end
if element.push then
push = push + element.push
end
if element.pull then
pull = pull + element.pull
end
offset = offset + -(push)
offset = offset + pull
end
end
function builder.buildGUI(template)
local parent = DiesalGUI:Create('Window')
parent:SetStylesheet(WindowStylesheet)
parent:SetWidth(template.width or 200)
parent:SetHeight(template.height or 300)
if not template.key_orig then
template.key_orig = template.key
end
if template.profiles == true and template.key_orig then
parent.settings.footer = true
local createButton = DiesalGUI:Create('Button')
parent:AddChild(createButton)
createButton:SetParent(parent.footer)
createButton:SetPoint('TOPLEFT',17,-1)
createButton:SetSettings({
width = 20,
height = 20,
}, true)
createButton:SetText('+')
createButton:SetStylesheet(createButtonStyle)
createButton:SetEventListener('OnClick', function()
local newWindow = DiesalGUI:Create('Window')
parent:AddChild(newWindow)
newWindow:SetTitle("Create Profile")
newWindow.settings.width = 200
newWindow.settings.height = 75
newWindow.settings.minWidth = newWindow.settings.width
newWindow.settings.minHeight = newWindow.settings.height
newWindow.settings.maxWidth = newWindow.settings.width
newWindow.settings.maxHeight = newWindow.settings.height
newWindow:ApplySettings()
local profileInput = DiesalGUI:Create('Input')
newWindow:AddChild(profileInput)
profileInput:SetParent(newWindow.content)
profileInput:SetPoint("TOPLEFT", newWindow.content, "TOPLEFT", 5, -5)
profileInput:SetPoint("BOTTOMRIGHT", newWindow.content, "TOPRIGHT", -5, -25)
profileInput:SetText("New Profile Name")
local profileButton = DiesalGUI:Create('Button')
newWindow:AddChild(profileButton)
profileButton:SetParent(newWindow.content)
profileButton:SetPoint("TOPLEFT", newWindow.content, "TOPLEFT", 5, -30)
profileButton:SetPoint("BOTTOMRIGHT", newWindow.content, "TOPRIGHT", -5, -50)
if profileButton.SetStylesheet then profileButton:SetStylesheet(buttonStyleSheet) end
profileButton:SetText("Create New Profile")
profileButton:SetEventListener('OnClick', function()
local profiles = dark_addon.settings.fetch(template.key_orig .. '_' .. 'profiles', {{key='default',text='Default'}})
local profileName = profileInput:GetText()
local pkey = string.gsub(profileName, "%s+", "")
if profileName ~= '' then
for _,p in ipairs(profiles) do
if p.key == pkey then
profileButton:SetText('|cffff3300Profile with that name exists!|r')
C_Timer.NewTicker(2, function()
profileButton:SetText("Create New Profile")
end, 1)
return false
end
end
table.insert(profiles, { key = pkey, text = profileName })
dark_addon.settings.store(template.key_orig .. '_' .. 'profiles', profiles)
dark_addon.settings.store(template.key_orig .. '_' .. 'profile', pkey)
newWindow:Hide()
parent:Hide()
parent:Release()
builder.buildGUI(template)
end
end)
profileInput:SetEventListener("OnEnterPressed", function()
local profiles = dark_addon.settings.fetch(template.key_orig .. '_' .. 'profiles', {{key='default',text='Default'}})
local profileName = profileInput:GetText()
local pkey = string.gsub(profileName, "%s+", "")
if profileName ~= '' then
for _,p in ipairs(profiles) do
if p.key == pkey then
profileButton:SetText('|cffff3300Profile with that name exists!|r')
C_Timer.NewTicker(2, function()
profileButton:SetText("Create New Profile")
end, 1)
return false
end
end
table.insert(profiles, { key = pkey, text = profileName })
dark_addon.settings.store(template.key_orig .. '_' .. 'profiles', profiles)
dark_addon.settings.store(template.key_orig .. '_' .. 'profile', pkey)
newWindow:Hide()
parent:Hide()
parent:Release()
builder.buildGUI(template)
end
end)
end)
createButton:SetEventListener('OnEnter', function()
createButton:SetStyle('frame', ButtonOver)
end)
createButton:SetEventListener('OnLeave', function()
createButton:SetStyle('frame', ButtonNormal)
end)
createButton.frame:SetScript('OnMouseDown', function()
createButton:SetStyle('frame', ButtonNormal)
end)
createButton.frame:SetScript('OnMouseUp', function()
createButton:SetStyle('frame', ButtonOver)
end)
local deleteButton = DiesalGUI:Create('Button')
parent:AddChild(deleteButton)
deleteButton:SetParent(parent.footer)
deleteButton:SetPoint('TOPLEFT',0,-1)
deleteButton:SetSettings({
width = 20,
height = 20,
}, true)
deleteButton:SetText('-')
deleteButton:SetStylesheet(deleteButtonStyle)
deleteButton:SetEventListener('OnEnter', function()
deleteButton:SetStyle('frame', ButtonOver)
end)
deleteButton:SetEventListener('OnLeave', function()
deleteButton:SetStyle('frame', ButtonNormal)
end)
deleteButton.frame:SetScript('OnMouseDown', function()
deleteButton:SetStyle('frame', ButtonNormal)
end)
deleteButton.frame:SetScript('OnMouseUp', function()
deleteButton:SetStyle('frame', ButtonOver)
end)
deleteButton:SetEventListener('OnClick', function()
local selectedProfile = dark_addon.settings.fetch(template.key_orig .. '_' .. 'profile', 'Default Profile')
local profiles = dark_addon.settings.fetch(template.key_orig .. '_' .. 'profiles', {{key='default',text='Default'}})
if selectedProfile ~= 'default' then
for i,p in ipairs(profiles) do
if p.key == selectedProfile then
profiles[i] = nil
dark_addon.settings.store(template.key_orig .. '_' .. 'profiles', profiles)
dark_addon.settings.store(template.key_orig .. '_' .. 'profile', 'default')