forked from Sunder-System/Sunder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKaiSunderGui.xml
3045 lines (2858 loc) · 97.4 KB
/
KaiSunderGui.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE MudletPackage>
<MudletPackage version="1.001">
<TriggerPackage>
<TriggerGroup isActive="yes" isFolder="yes" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
<name>KaiUI</name>
<script></script>
<triggerType>0</triggerType>
<conditonLineDelta>0</conditonLineDelta>
<mStayOpen>0</mStayOpen>
<mCommand></mCommand>
<packageName>KaiUI</packageName>
<mFgColor>#ff0000</mFgColor>
<mBgColor>#ffff00</mBgColor>
<mSoundFile></mSoundFile>
<colorTriggerFgColor>#000000</colorTriggerFgColor>
<colorTriggerBgColor>#000000</colorTriggerBgColor>
<regexCodeList />
<regexCodePropertyList />
<Trigger isActive="yes" isFolder="no" isTempTrigger="no" isMultiline="no" isPerlSlashGOption="no" isColorizerTrigger="no" isFilterTrigger="no" isSoundTrigger="no" isColorTrigger="no" isColorTriggerFg="no" isColorTriggerBg="no">
<name>Logged in</name>
<script>sendGMCP([[ Core.Supports.Add [ "Comm.Channel 1" ] ]])
GUIframe.loadSettings(true)</script>
<triggerType>0</triggerType>
<conditonLineDelta>0</conditonLineDelta>
<mStayOpen>0</mStayOpen>
<mCommand></mCommand>
<packageName></packageName>
<mFgColor>#ff0000</mFgColor>
<mBgColor>#ffff00</mBgColor>
<mSoundFile></mSoundFile>
<colorTriggerFgColor>#000000</colorTriggerFgColor>
<colorTriggerBgColor>#000000</colorTriggerBgColor>
<regexCodeList>
<string>Password correct. Welcome to Aetolia.</string>
</regexCodeList>
<regexCodePropertyList>
<integer>3</integer>
</regexCodePropertyList>
</Trigger>
</TriggerGroup>
</TriggerPackage>
<TimerPackage />
<AliasPackage>
<AliasGroup isActive="yes" isFolder="yes">
<name>KaiUI</name>
<script></script>
<command></command>
<packageName>KaiUI</packageName>
<regex></regex>
<Alias isActive="yes" isFolder="no">
<name>lock UI</name>
<script>GUIframe.disable("top")
GUIframe.disable("bottom")
GUIframe.disable("right")
GUIframe.disable("left")
GUIframe.saveSettings()</script>
<command></command>
<packageName></packageName>
<regex>^klock$</regex>
</Alias>
<Alias isActive="yes" isFolder="no">
<name>unlock UI</name>
<script>GUIframe.enable("top")
GUIframe.enable("bottom")
GUIframe.enable("right")
GUIframe.enable("left")</script>
<command></command>
<packageName></packageName>
<regex>^kunlock$</regex>
</Alias>
</AliasGroup>
</AliasPackage>
<ActionPackage />
<ScriptPackage>
<ScriptGroup isActive="yes" isFolder="yes">
<name>KaiUI</name>
<packageName>KaiUI</packageName>
<script></script>
<eventHandlerList />
<Script isActive="yes" isFolder="no">
<name>KaiUI init</name>
<packageName></packageName>
<script>kaiUI = kaiUI or {}
kaiUI.hits = kaiUI.hits or 0
kaiUI.crits = kaiUI.crits or 0
kaiUI.targetName = kaiUI.targetName or "Nothing"
kaiUI.gmcp = {}
registerAnonymousEventHandler("sysConnectionEvent", "kaiUI.buildUI")</script>
<eventHandlerList />
</Script>
<ScriptGroup isActive="yes" isFolder="yes">
<name>Framework</name>
<packageName></packageName>
<script>-------------------------------------------------
-- Put your Lua functions here. --
-- --
-- Note that you can also use external scripts --
-------------------------------------------------
</script>
<eventHandlerList />
<Script isActive="yes" isFolder="no">
<name>Jor'Mox's GUIframe</name>
<packageName></packageName>
<script>-- Jor'Mox's GUIframe Script
-- 3/07/2019
-- v1.4.2
-- To resize frames or move tabs, right click and drag either the resize label or the tab
-- until the desired result is achieved.
-- To add a window to a frame for the script to manage, use the
-- GUIframe.addWindow(window, name, container, hideText) function, where the window
-- variable contains the Geyser object you want to add, the name variable contains
-- the name you want it to be referred to as, which also is used as the text printed
-- on the associated tab that is created, the container variable is a string containing
-- one of the following: bottom, top, topleft, topright, bottomleft, bottomright,
-- and the hideText variable is an optional boolean which, if true, prevents text being
-- written on the tab for this window.
-- To remove a window from GUIframe, use the GUIframe.removeWindow(name, container)
-- function, where the name variable is the same name you gave the window when adding it,
-- and the optional container variable is a string specifying which container to remove
-- the window from. If no container is specified, the window is removed regardless of
-- which container it is in.
-- Resizing of frames can be enabled or disabled using the GUIframe.enable(side) and
-- GUIframe.disable(side, hide) functions respectively. If the second argument to
-- GUIframe.disable is false, then the entire set of frames on that side is hidden, and
-- the border is adjusted as if that side had be resized to zero.
-- To save and load settings, use the GUIframe.saveSettings() and
-- GUIframe.loadSettings(redraw) functions. If the redraw argument is true, the border
-- background color is changed to black to force the area of the borders to be redrawn.
-- Additionally, the GUIframe.reinitialize() function can be used to force the script to
-- initialize itself again, going back to default settings.
-- To activate a tab without it being clicked, use the GUIframe.activate(name) function.
-- And to apply a stylesheet to a tab that is different from the default stylesheet, use
-- the GUIframe.styleTab(name, style) function, where the style variable contains a string
-- with the CSS to be applied. Since tabs are styled only when created or when this
-- function is used, there should be no concern with this styling being overwritten.
GUIframe = GUIframe or {}
local mainW, mainH = getMainWindowSize()
local halfW, halfH = math.floor(mainW / 2), math.floor(mainH / 2)
GUIframe.configs = GUIframe.configs or {}
GUIframe.defaults =
{
tabHeight = 20,
tabStyle =
[[
background-color: green;
border-width: 2px;
border-style: outset;
border-color: limegreen;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
margin-right: 1px;
margin-left: 1px;
qproperty-alignment: 'AlignCenter | AlignCenter';]],
tabEchoStyle = '<center><p style="font-size:14px; color:white">',
leftStartWidth = 50,
leftStartHeight = halfH,
rightStartWidth = 50,
rightStartHeight = halfH,
topStartHeight = 50,
bottomStartHeight = 50,
resizeHeight = 30,
resizeWidth = 30,
resizeHoverImage = "/imgs/blue_arrows.png",
resizeRestImage = "/imgs/blue_arrows_20t.png",
borderOffset = 5,
}
GUIframe.windows = GUIframe.windows or {}
GUIframe.tabs = GUIframe.tabs or {}
GUIframe.tabCoords = GUIframe.tabCoords or {}
GUIframe.sides =
GUIframe.sides or {left = 'enabled', right = 'enabled', top = 'enabled', bottom = 'enabled'}
local resize_style = "border-image: url(%s%s);"
local configs = table.update(GUIframe.defaults, GUIframe.configs)
local tabsInfo, containerInfo, resizeInfo
local container_names =
{
'topLeftContainer',
'bottomLeftContainer',
'topRightContainer',
'bottomRightContainer',
'bottomContainer',
'topContainer',
}
local tab_names =
{'topLeftTabs', 'topRightTabs', 'bottomLeftTabs', 'bottomRightTabs', 'midLeftTabs'}
local resizeLabels = {'resizeLeft', 'resizeRight', 'resizeTop', 'resizeBottom'}
local sides = {"top", "bottom", "left", "right"}
local side_containers =
{
left = {"topLeftContainer", "bottomLeftContainer", "topLeftTabs", "bottomLeftTabs"},
right = {"topRightContainer", "bottomRightContainer", "topRightTabs", "bottomRightTabs"},
top = {"topContainer"},
bottom = {"bottomContainer"},
}
local function get_window_coords(win, update)
-- gets coords for window, stores data in tabCoords table as needed
local x, y = win:get_x(), win:get_y()
local w, h = win:get_width(), win:get_height()
if update then
GUIframe.tabCoords[win.name] = {x = x, y = y, w = w, h = h}
end
return x, y, w, h
end
local function check_overlap(tab, x, y)
-- checks to see if given coords overlap tab or tab container
if type(tab) == "string" then
tab = GUIframe[tab] or GUIframe.tabs[tab]
end
if tab.hidden or tab.auto_hidden then
return false
end
local info = GUIframe.tabCoords[tab.name]
local x1, y1 = info.x, info.y
local x2, y2 = x1 + info.w, y1 + info.h
return (x >= x1 and x <= x2 and y >= y1 and y <= y2)
end
local function update_tab(tab, x, y, w, h)
-- resizes and moves tab and updates tab coords table
tab:move(x, y)
tab:resize(w, h)
local info = GUIframe.tabCoords[tab.name] or {}
info.x, info.y = tab:get_x(), tab:get_y()
info.w, info.h = tab:get_width(), tab:get_height()
if table.contains(tab_names, tab.name) then
info.container = true
end
GUIframe.tabCoords[tab.name] = info
end
local function get_containers(pos)
if type(pos) == "table" then
pos = pos.name
end
for _, w in ipairs({'right', 'left', 'container', 'tabs'}) do
pos = pos:gsub(w, w:title())
end
local con, tab
if string.find(pos, "Container") then
con = GUIframe[pos]
if not con then
return
end
tabs = con.tabs
elseif string.find(pos, "Tabs") then
tabs = GUIframe[pos]
if not tab then
return
end
con = tabs.con
else
con = GUIframe[pos .. "Container"]
tabs = GUIframe[pos .. "Tabs"]
end
return con, tabs
end
local function config()
configs = table.update(GUIframe.defaults, GUIframe.configs)
GUIframe.windows = {}
GUIframe.tabCoords = {}
tabsInfo =
{
topLeftTabs =
{
name = 'topLeftTabs',
x = 0,
y = 0,
width = configs.leftStartWidth,
height = configs.tabHeight,
},
bottomLeftTabs =
{
name = 'bottomLeftTabs',
x = 0,
y = configs.leftStartHeight,
width = configs.leftStartWidth,
height = configs.tabHeight,
},
topRightTabs =
{
name = 'topRightTabs',
x = mainW - configs.rightStartWidth,
y = 0,
width = configs.rightStartWidth,
height = configs.tabHeight,
},
bottomRightTabs =
{
name = 'bottomRightTabs',
x = mainW - configs.rightStartWidth,
y = configs.rightStartHeight,
width = configs.rightStartWidth,
height = configs.tabHeight,
},
}
containerInfo =
{
topLeftContainer =
{
name = 'topLeftContainer',
x = 0,
y = configs.tabHeight,
width = configs.leftStartWidth,
height = configs.leftStartHeight - configs.tabHeight,
},
bottomLeftContainer =
{
name = 'bottomLeftContainer',
x = 0,
y = configs.leftStartHeight + configs.tabHeight,
width = configs.leftStartWidth,
height = configs.leftStartHeight - configs.tabHeight,
},
topRightContainer =
{
name = 'topRightContainer',
x = mainW - configs.rightStartWidth,
y = configs.tabHeight,
width = configs.rightStartWidth,
height = configs.rightStartHeight - configs.tabHeight,
},
bottomRightContainer =
{
name = 'bottomRightContainer',
x = mainW - configs.rightStartWidth,
y = configs.rightStartHeight + configs.tabHeight,
width = configs.rightStartWidth,
height = configs.rightStartHeight - configs.tabHeight,
},
bottomContainer =
{
name = 'bottomContainer',
x = configs.leftStartWidth,
y = mainH - configs.bottomStartHeight,
height = configs.bottomStartHeight,
width = mainW - configs.leftStartWidth - configs.rightStartWidth,
},
topContainer =
{
name = 'topContainer',
x = configs.leftStartWidth,
y = 0,
height = configs.topStartHeight,
width = mainW - configs.leftStartWidth - configs.rightStartWidth,
},
}
resizeInfo =
{
resizeLeft =
{
name = 'resizeLeft',
x = configs.leftStartWidth,
y = configs.leftStartHeight - configs.resizeHeight / 2,
height = configs.resizeHeight,
width = configs.resizeWidth,
},
resizeRight =
{
name = 'resizeRight',
x = configs.rightStartWidth - configs.resizeWidth,
y = configs.rightStartHeight - configs.resizeHeight / 2,
height = configs.resizeHeight,
width = configs.resizeWidth,
},
resizeTop =
{
name = 'resizeTop',
x = halfW - configs.resizeWidth / 2,
y = configs.topStartHeight,
height = configs.resizeHeight,
width = configs.resizeWidth,
},
resizeBottom =
{
name = 'resizeBottom',
x = halfW - configs.resizeWidth / 2,
y = mainH - configs.bottomStartHeight - configs.resizeHeight,
height = configs.resizeHeight,
width = configs.resizeWidth,
},
}
for name, cons in pairs(containerInfo) do
GUIframe[name] = Geyser.Container:new(cons)
end
for name, cons in pairs(tabsInfo) do
GUIframe[name] = Geyser.Container:new(cons)
local cname = name:gsub("Tabs", "Container")
GUIframe[cname].tabs = GUIframe[name]
GUIframe[name].con = GUIframe[cname]
end
local style = resize_style
local path = getMudletHomeDir()
path = path:gsub("[\\/]", "/")
configs.resizeRestImage = configs.resizeRestImage:gsub("[\\/]", "/")
configs.resizeHoverImage = configs.resizeHoverImage:gsub("[\\/]", "/")
local no_image
if
not (io.exists(path .. configs.resizeHoverImage) and io.exists(path .. configs.resizeRestImage))
then
debugc("GUIframe: config: resize image(s) not found")
path = "255,20,147,"
style = "background-color: rgba(%s%s);"
no_image = true
end
for name, cons in pairs(resizeInfo) do
GUIframe[name] = Geyser.Label:new(cons)
GUIframe[name]:setColor(0, 0, 0, 0)
GUIframe[name]:setStyleSheet(
string.format(style, path, (no_image and "100") or configs.resizeRestImage)
)
GUIframe[name]:setOnEnter(
"GUIframe." .. name .. ".setStyleSheet",
GUIframe[name],
string.format(style, path, (no_image and "255") or configs.resizeHoverImage)
)
GUIframe[name]:setOnLeave(
"GUIframe." .. name .. ".setStyleSheet",
GUIframe[name],
string.format(style, path, (no_image and "100") or configs.resizeRestImage)
)
GUIframe[name]:setClickCallback("GUIframe.buttonClick", name)
GUIframe[name]:setReleaseCallback("GUIframe.buttonRelease", name)
GUIframe[name]:setMoveCallback("GUIframe.buttonMove", name)
end
setBorderLeft(configs.leftStartWidth + configs.borderOffset)
setBorderRight(configs.rightStartWidth + configs.borderOffset)
setBorderTop(configs.topStartHeight + configs.borderOffset)
setBorderBottom(configs.bottomStartHeight + configs.borderOffset)
GUIframe.initialized = true
end
local function deselectContainer(container, tabs)
-- hide all windows in container
for _, win in pairs(container.windowList) do
win:hide()
win.active = false
end
-- unhighlight all tabs in tabs container
if tabs then
for _, tab in pairs(tabs.windowList) do
local name = tab.name:gsub("Tab", "")
local show = GUIframe.windows[name].showText
if show then
tab:echo(configs.tabEchoStyle .. name)
end
end
end
end
local function adjustTabs(tabs)
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
-- remove duplicated window names
local found = {}
for k, v in ipairs(tabs.windows) do
if not table.contains(found, v) and tabs.windowList[v] and not tabs.windowList[v].isClicked then
table.insert(found, v)
end
end
-- calculate tab width and set height
local w, h = math.floor(100 / #tabs.windows), configs.tabHeight
local function wrap(num)
return tostring(num) .. "%"
end
-- resize and reposition all tabs
local shown, first
for k, v in ipairs(found) do
local tab = tabs.windowList[v]
if not first then
first = v:gsub("Tab", "")
end
if not shown and tab.active then
shown = v
elseif tab.active then
tab.active = false
end
update_tab(tab, wrap(w * (k - 1)), 0, wrap(w), h)
end
if first and not shown and GUIframe.windows[first] then
GUIframe.windows[first]:show()
end
tabs.space_pos = nil
end
local function reorderTabs(tabs, name, pos)
local windows = tabs.windows
while table.contains(windows, name) do
table.remove(windows, table.index_of(windows, name))
end
table.insert(windows, pos, name)
end
local function makeSpace(tabs, tab, pos)
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
local windows = table.deepcopy(tabs.windows)
local space_pos = tabs.space_pos
local tab_pos = table.index_of(windows, tab.name)
-- calculate tab width and set height
local num_tabs = #windows + 1
if tab_pos then
num_tabs = num_tabs - 1
if pos > tab_pos then
pos = pos - 1
end
if pos == space_pos then
pos = pos + 1
end
elseif space_pos and pos >= space_pos then
pos = pos + 1
end
local w, h = math.floor(100 / num_tabs), configs.tabHeight
local function wrap(num)
return tostring(num) .. "%"
end
-- resize and reposition all tabs
if tab_pos then
table.remove(windows, tab_pos)
end
for k, v in ipairs(windows) do
if k >= pos then
update_tab(tabs.windowList[v], wrap(w * k), 0, wrap(w), h)
else
update_tab(tabs.windowList[v], wrap(w * (k - 1)), 0, wrap(w), h)
end
end
tabs.space_pos = pos
end
local function round(num, roundTo)
local b, r = math.modf(num / roundTo)
if r >= 0.5 then
b = b + 1
end
return b * roundTo
end
local function setBorder(side, val)
local funcs =
{left = setBorderLeft, right = setBorderRight, top = setBorderTop, bottom = setBorderBottom}
val = math.max(val, 0)
funcs[side](val)
end
local function resizeContainers(side, w, h)
if table.contains({"left", "right"}, side) then
local info =
{
left =
{
resize = "resizeLeft",
cons = {"topLeftContainer", "bottomLeftContainer"},
tabs = {"topLeftTabs", "bottomLeftTabs"},
x = 0,
w = w,
},
right =
{
resize = "resizeRight",
cons = {"topRightContainer", "bottomRightContainer"},
tabs = {"topRightTabs", "bottomRightTabs"},
x = w,
w = mainW - w,
},
}
info = info[side]
-- move and resize top, bottom and tab containers
update_tab(GUIframe[info.tabs[1]], info.x, 0, info.w, configs.tabHeight)
update_tab(GUIframe[info.tabs[2]], info.x, h, info.w, configs.tabHeight)
GUIframe[info.cons[1]]:resize(info.w, h - configs.tabHeight)
GUIframe[info.cons[1]]:move(info.x, configs.tabHeight)
GUIframe[info.cons[2]]:resize(info.w, mainH - h - configs.tabHeight)
GUIframe[info.cons[2]]:move(info.x, h + configs.tabHeight)
-- adjust border size
setBorder(side, info.w + configs.borderOffset)
-- adjust width of top and bottom containers
local x, y
x = (GUIframe.sides.left ~= "hidden" and GUIframe.topLeftContainer:get_width()) or 0
w = ((GUIframe.sides.right ~= "hidden" and GUIframe.topRightContainer:get_x()) or mainW) - x
for _, con in ipairs({GUIframe.topContainer, GUIframe.bottomContainer}) do
y, h = con:get_y(), con:get_height()
con:resize(w, h)
con:move(x, y)
end
elseif table.contains({"top", "bottom"}, side) then
local x = 0
w = mainW
if GUIframe.sides.left ~= "hidden" then
w = w - GUIframe.topLeftContainer:get_width()
x = GUIframe.topLeftContainer:get_width()
end
if GUIframe.sides.right ~= "hidden" then
w = w - GUIframe.topRightContainer:get_width()
end
local info =
{
top = {con = "topContainer", y = 0, h = h},
bottom = {con = "bottomContainer", y = h, h = mainH - h},
}
local con = GUIframe[info[side].con]
con:resize(w, info[side].h)
con:move(x, info[side].y)
setBorder(side, info[side].h + configs.borderOffset)
end
end
local function refresh()
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
mainW, mainH = getMainWindowSize()
local rH, rW = configs.resizeHeight, configs.resizeWidth
local x, y, w
-- adjust bottom left and right container heights
for _, C in ipairs({GUIframe.bottomLeftContainer, GUIframe.bottomRightContainer}) do
C:resize(C:get_width(), mainH - C:get_y())
end
-- reposition right containers
w = GUIframe.topRightContainer:get_width()
for
_, C in
ipairs(
{
GUIframe.topRightContainer,
GUIframe.topRightTabs,
GUIframe.bottomRightContainer,
GUIframe.bottomRightTabs,
}
)
do
C:move(mainW - w, C:get_y())
end
-- resize and reposition bottom and top containers
w, x = mainW, 0
if GUIframe.sides.left ~= "hidden" then
w = w - GUIframe.topLeftContainer:get_width()
x = GUIframe.topLeftContainer:get_width()
end
if GUIframe.sides.right ~= "hidden" then
w = w - GUIframe.topRightContainer:get_width()
end
for _, C in ipairs({GUIframe.topContainer, GUIframe.bottomContainer}) do
C:resize(w, C:get_height())
C:move(x, C.name == "topContainer" and 0 or mainH - C:get_height())
end
-- reposition resize labels
x, y = GUIframe.topLeftContainer:get_width(), GUIframe.bottomLeftTabs:get_y()
GUIframe.resizeLeft:move(x, y - rH / 2)
x, y = GUIframe.topRightContainer:get_x(), GUIframe.bottomRightTabs:get_y()
GUIframe.resizeRight:move(x - rW, y - rH / 2)
x = (GUIframe.topContainer:get_width() - rW) / 2
if GUIframe.sides.left ~= "hidden" then
x = x + GUIframe.topLeftContainer:get_width()
end
y = GUIframe.topContainer:get_height()
GUIframe.resizeTop:move(x, y)
y = GUIframe.bottomContainer:get_y()
GUIframe.resizeBottom:move(x, y - rH)
end
-- enables the resize label for the given side and shows all associated containers if hidden
function GUIframe.enable(side)
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
if not table.contains(sides, side) then
error("GUIframe.enable: invalid side", 2)
end
local cons = side_containers[side]
for _, con in ipairs(cons) do
GUIframe[con]:show()
for _, win in pairs(GUIframe[con].windowList) do
-- loop can be removed after Geyser fix comes in
if win.active then
win:show()
end
end
end
if table.contains({"left", "right"}, side) then
setBorder(side, GUIframe[cons[1]]:get_width() + configs.borderOffset)
else
setBorder(side, GUIframe[cons[1]]:get_height() + configs.borderOffset)
end
GUIframe["resize" .. side:title()]:show()
GUIframe.sides[side] = "enabled"
refresh()
end
-- disables and hides the resize label for the given side, and hides all associated containers if indicated
function GUIframe.disable(side, hide)
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
if not table.contains(sides, side) then
error("GUIframe.disable: invalid side", 2)
end
local cons = side_containers[side]
GUIframe.sides[side] = "disabled"
if hide then
for _, con in ipairs(cons) do
GUIframe[con]:hide()
for _, win in pairs(GUIframe[con].windowList) do
-- loop can be removed after Geyser fix comes in
if win.type == "mapper" then
win:hide()
end
end
end
local border = _G["setBorder" .. side:title()]
border(0)
GUIframe.sides[side] = "hidden"
end
GUIframe["resize" .. side:title()]:hide()
refresh()
end
-- adds a Geyser window or container to the given container, with a tab showing the given name if applicable
function GUIframe.addWindow(window, name, container, hideText)
if not GUIframe.initialized then
config()
end
if type(container) == "table" then
container = container.name
end
local con, tabs = get_containers(container)
if not window then
error("GUIframe.addWindow: invalid window", 2)
end
if not con then
error("GUIframe.addWindow: invalid container name", 2)
end
if not name then
error("GUIframe.addWindow: name argument required", 2)
end
-- remove window from any containers
for _, tcon in ipairs(container_names) do
if table.contains(GUIframe[tcon].windows, window.name) then
GUIframe.removeWindow(name, tcon)
end
end
deselectContainer(con, tabs)
-- add tab for window, if applicable
if tabs then
local showText = not hideText
window.showText = showText
local lbl =
Geyser.Label:new({name = name .. "Tab", x = 0, y = 0, width = 10, height = 10}, tabs)
lbl:setStyleSheet(configs.tabStyle)
if showText then
lbl:echo(configs.tabEchoStyle .. "<b>" .. name)
end
lbl:setClickCallback("GUIframe.buttonClick", name)
lbl:setReleaseCallback("GUIframe.buttonRelease", name)
lbl:setMoveCallback("GUIframe.buttonMove", name)
GUIframe.tabs[name] = lbl
adjustTabs(tabs)
end
-- add window to container and set size and position
con:add(window)
window:resize("100%", "100%")
window:move(0, 0)
window:show()
GUIframe.windows[name] = window
raiseEvent("sysWindowResizeEvent")
end
-- removes a named Geyser window or container from the named container (using name given in GUIframe.addWindow)
function GUIframe.removeWindow(name, container)
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
if not container then
container = GUIframe.windows[name].container
end
local con, tabs = get_containers(container)
if not con or not table.contains(container_names, con.name) then
error("GUIframe.removeWindow: invalid container name", 2)
end
if not name then
error("GUIframe.removeWindow: name argument required", 2)
end
if tabs then
local lbl = tabs.windowList[name .. "Tab"]
if lbl then
tabs:remove(lbl)
adjustTabs(tabs)
lbl:hide()
end
end
local window = GUIframe.windows[name]
con:remove(window)
window:hide()
end
-- saves the current GUI setup, including the size of the different containers and what windows go in which container
function GUIframe.saveSettings()
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
local saveTbl = {}
local w, h = GUIframe.topLeftContainer:get_width(), GUIframe.bottomLeftTabs:get_y()
saveTbl.left = {w = w, h = h}
w, h = GUIframe.topRightContainer:get_width(), GUIframe.bottomRightTabs:get_y()
saveTbl.right = {w = w, h = h}
w, h = GUIframe.topContainer:get_width(), GUIframe.topContainer:get_height()
saveTbl.top = {w = w, h = h}
w, h = GUIframe.bottomContainer:get_width(), GUIframe.bottomContainer:get_height()
saveTbl.bottom = {w = w, h = h}
-- get added windows and containers they are assigned to
local windows = {}
local text = {}
for k, v in pairs(GUIframe.windows) do
local con = v.container.name
windows[con] = windows[con] or {}
table.insert(windows[con], k)
text[con] = text[con] or {}
text[con][k] = v.showText
end
-- reorder windows to match tab order for tabbed containers
for con, wins in pairs(windows) do
if con:find("Left") or con:find("Right") then
local tabs = GUIframe[con].tabs.windows
local new = {}
for k, v in ipairs(tabs) do
local wname = v:gsub("Tab", "")
table.insert(new, {wname, text[con][wname]})
end
windows[con] = new
end
end
saveTbl.windows = windows
saveTbl.sides = GUIframe.sides
table.save(getMudletHomeDir() .. "/GUIframeSave.lua", saveTbl)
end
-- loads GUI setup from a previous save
function GUIframe.loadSettings(redraw)
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
local saveTbl = {}
local path = getMudletHomeDir() .. "/GUIframeSave.lua"
path = path:gsub("\\", "/")
mainW, mainH = getMainWindowSize()
if not io.exists(path) then
debugc("GUIframe.loadSettings: save file doesn't exist.")
return
end
table.load(path, saveTbl)
resizeContainers("left", saveTbl.left.w, saveTbl.left.h)
resizeContainers("right", mainW - saveTbl.right.w, saveTbl.right.h)
resizeContainers("top", saveTbl.top.w, saveTbl.top.h)
resizeContainers("bottom", saveTbl.bottom.w, mainH - saveTbl.bottom.h)
for con, wins in pairs(saveTbl.windows) do
for _, name in ipairs(wins) do
if type(name) == "string" then
GUIframe.addWindow(GUIframe.windows[name], name, con)
else
local n, s = name[1], not name[2]
GUIframe.addWindow(GUIframe.windows[n], n, con, s)
end
end
end
for side, state in pairs(saveTbl.sides) do
if state == "enabled" then
GUIframe.enable(side)
elseif state == "disabled" then
GUIframe.disable(side, false)
elseif state == "hidden" then
GUIframe.disable(side, true)
end
end
-- force redraw of screen
if redraw then
setBackgroundColor(1, 1, 1)
setBackgroundColor(0, 0, 0)
end
end
-- can be called to force the script to run its config function again
function GUIframe.reinitialize()
config()
end
-- can be called to activate a given tab without clicking on it
function GUIframe.activate(name)
if not GUIframe.initialized then
error("GUIframe not initialized", 1)
end
local window = GUIframe.windows[name]
if window then
local con, tabs = get_containers(window.container.name)
-- hide and unhighlight other windows and tabs
deselectContainer(con, tabs)
-- show selected window
window:show()
window.active = true
-- highlight selected tab
if window.showText then
GUIframe.tabs[name]:echo(configs.tabEchoStyle .. "<b>" .. name)
end
end
end
-- can be called to apply a style to a given tab
function GUIframe.styleTab(name, style)
if not GUIframe.initialized then
error("GUIframe not initialized", 1)
end
local tab = GUIframe.tabs[name]
if tab then
tab:setStyleSheet(style)
end
end
-- internally used function to handle button click callbacks
function GUIframe.buttonClick(name, event)
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
if table.contains(resizeLabels, name) then
if event.button == "RightButton" then
local lbl = GUIframe[name]
lbl.difX, lbl.difY = event.x, event.y
lbl.savedX, lbl.savedY = getMousePosition()
GUIframe[name].isClicked = true
end
elseif event.button == "LeftButton" then
local window = GUIframe.windows[name]
local con, tabs = get_containers(window.container.name)
-- hide and unhighlight other windows and tabs
deselectContainer(con, tabs)
-- show selected window
window:show()
window.active = true
-- highlight selected tab
if window.showText then
GUIframe.tabs[name]:echo(configs.tabEchoStyle .. "<b>" .. name)
end
elseif event.button == "RightButton" then
local window, tab = GUIframe.windows[name], GUIframe.tabs[name]
tab.savedX, tab.savedY = getMousePosition()
tab.difX, tab.difY, tab.isClicked = event.x, event.y, true
-- force update of coords for all tabs and tab containers
GUIframe.tabCoords = {}
for _, name in ipairs(tab_names) do
get_window_coords(GUIframe[name], true)
for tname, tab in pairs(GUIframe[name].windowList) do
get_window_coords(tab, true)
end
end
end
raiseEvent("GUIframe.buttonClick", name, event)
end
-- internally used function to handle button release callbacks
function GUIframe.buttonRelease(name, event)
if not GUIframe.initialized then
error("GUIframe not initialized", 2)
end
if table.contains(resizeLabels, name) then
if event.button == "RightButton" then
local lbl = GUIframe[name]
lbl.savedX, lbl.savedY, lbl.difX, lbl.difY, lbl.isClicked = nil, nil, nil, nil, false
end
elseif event.button == "RightButton" then
local window, tab = GUIframe.windows[name], GUIframe.tabs[name]
local con, tabs = get_containers(window.container.name)
tab.difX, tab.difY, tab.savedX, tab.savedY, tab.isClicked = nil, nil, nil, nil, false
hideWindow("show_container")
for _, tname in ipairs(tab_names) do
local info = GUIframe[tname]
if info.mouse_over then
local pos = info.space_pos
info.mouse_over = nil
GUIframe.addWindow(window, name, tname:gsub("Tabs", ""), not window.showText)
if pos then
reorderTabs(info, tab.name, pos)