-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathfunctions.lua
1336 lines (1251 loc) · 50.3 KB
/
functions.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
dgsLogLuaMemory()
local loadstring = loadstring
---------------Speed Up
local tableInsert,tableRemove,tableFind = table.insert,table.remove,table.find
local dgsTriggerEvent = dgsTriggerEvent
local type,assert = type,assert
local isElement = isElement
local setElementData = setElementData
local destroyElement = destroyElement
local dgsSetProperty = dgsSetProperty
local guiBlur = guiBlur or function()
destroyElement(guiCreateLabel(0,0,0,0,"",false))
end
local guiFocus = guiBringToFront
function insertResource(res,dgsEle)
if res and isElement(dgsEle) then
boundResource[res] = boundResource[res] or {}
boundResource[res][dgsEle] = true
setElementData(dgsEle,"resource",res)
dgsSetProperty(dgsEle,"resource",res)
end
end
function dgsGetElementPositionOnScreen(dgsEle,relativeTo)
if relativeTo == dgsEle then return 0,0 end
if relativeTo == true then relativeTo = "screen" end
local parentList = {count=0,[0]=dgsEle}
while(true) do
local currentElement = parentList[#parentList]
local parent = dgsElementData[currentElement].parent
if isElement(parent) and parent ~= relativeTo then
parentList.count = parentList.count+1
parentList[parentList.count] = parent
else
break
end
end
local x,y = 0,0
local OffsetX,OffsetY = 0,0
local ScaleX,ScaleY = 1,1
for i=#parentList,0,-1 do
dgsEle = parentList[i]
parent = parentList[i+1]
local eleData = dgsElementData[dgsEle]
local eleType = dgsElementType[dgsEle]
--Process Position Alignment
local eleTypeP,eleDataP
local elePAlignH,elePAlignV
if parent then
eleTypeP,eleDataP = dgsElementType[parent],dgsElementData[parent]
elePAlignH,elePAlignV = dgsElementData[parent].contentPositionAlignment[1],dgsElementData[parent].contentPositionAlignment[2]
end
local absX,absY,absW,absH
local absPos,absSize = eleData.absPos,eleData.absSize
if not absPos then absX,absY = 0,0 else absX,absY = absPos[1],absPos[2] end
if not absSize then absW,absH = 0,0 else absW,absH = absSize[1],absSize[2] end
local PosX,PosY = absX,absY
local w,h
local eleAlign = eleData.positionAlignment
local eleAlignH,eleAlignV = eleAlign[1] or elePAlignH, eleAlign[2] or elePAlignV
if eleAlignH == "right" then --Horizontal
local pWidth = parent and eleDataP.absSize[1] or sW
PosX = pWidth-PosX-eleData.absSize[1]
elseif eleAlignH == "center" then
local pWidth = parent and eleDataP.absSize[1] or sW
PosX = PosX+pWidth/2-eleData.absSize[1]/2
end
if eleAlignV == "bottom" then --Vertical
local pHeight = parent and eleDataP.absSize[2] or sH
PosY = pHeight-PosY-eleData.absSize[2]
elseif eleAlignV == "center" then
local pHeight = parent and eleDataP.absSize[2] or sH
PosY = PosY+pHeight/2-eleData.absSize[2]/2
end
if eleTypeP == "dgs-dxwindow" and eleData.ignoreParentTitle then OffsetY = 0 end
x,y = x+(OffsetX+PosX)*ScaleX,y+(OffsetY+PosY)*ScaleY
OffsetX,OffsetY = 0,0
if i == 0 then break end
if eleType == "dgs-dxwindow" then
if not eleData.ignoreTitle then
OffsetY = eleData.titleHeight
end
elseif eleType == "dgs-dxtab" then
h = eleDataP.absSize[2]
OffsetY = eleDataP.tabHeight[2] and eleDataP.tabHeight[1]*h or eleDataP.tabHeight[1]
elseif eleType == "dgs-dxscrollpane" then
OffsetX,OffsetY = eleData.horizontalMoveOffset,eleData.verticalMoveOffset
elseif eleType == "dgs-dxscalepane" then
OffsetX,OffsetY = eleData.horizontalMoveOffset,eleData.verticalMoveOffset
local scale = eleData.scale
ScaleX,ScaleY = ScaleX*scale[1],ScaleY*scale[2]
elseif eleType == "dgs-dxgridlist" then
local child = parentList[i-1]
if child then
local eleDataC = dgsElementData[child]
if eleDataC.attachedToGridList then
local data = eleDataC.attachedToGridList --GridList,Row,Column
local gridList = data[1] --Grid List
local scbThickV = dgsElementData[eleData.scrollbars[1]].visible and eleData.scrollBarThick or 0
local columnData = eleData.columnData
local rowData = eleData.rowData
local columnOffset = rowData[data[2]][-4] or eleData.columnOffset
local columnMoveOffset = eleData.columnMoveOffsetTemp
local rowHeight = eleData.rowHeight
local leading = eleData.leading
w = eleData.absSize[1]
OffsetX,OffsetY = columnMoveOffset+columnOffset+columnData[data[3]][3]*(eleData.columnRelative and (w-scbThickV) or 1),eleData.rowMoveOffsetTemp+(data[2]-1)*(leading+rowHeight)+eleData.columnHeight
end
end
end
end
return x,y
end
function dgsGetPosition(dgsEle,relative,relativeTo)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetPosition",1,"dgs-dxelement")) end
if relativeTo then
local posX,posY,startElement,brokenElement = dgsGetElementPositionOnScreen(dgsEle,relativeTo)
if brokenElement then error("Bad argument @'dgsGetPosition', Found an infinite loop under "..tostring(brokenElement).."("..dgsGetType(brokenElement).."), start from element "..tostring(startElement).."("..dgsGetType(startElement)..")") end
if relative then
return posX/sW,posY/sH
else
return posX,posY
end
else
local pos = dgsElementData[dgsEle][relative and "rltPos" or "absPos"]
if not pos then return false end
return pos[1],pos[2]
end
end
function dgsSetPosition(dgsEle,x,y,relative,...)
if (x and type(x) ~= "number") then error(dgsGenAsrt(x,"dgsSetPosition",2,"nil/number")) end
if (y and type(y) ~= "number") then error(dgsGenAsrt(y,"dgsSetPosition",3,"nil/number")) end
if type(dgsEle) == "table" then
for index,dgsEleItem in pairs(dgsEle) do
if not(dgsIsType(dgsEleItem)) then error(dgsGenAsrt(dgsEleItem,"dgsSetPosition",1,"dgs-dxelement",_,_,"at table index "..i)) end
dgsSetPosition(dgsEleItem,x,y,relative,...)
end
return true
else
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetPosition",1,"dgs-dxelement")) end
local pos = relative and dgsElementData[dgsEle].rltPos or dgsElementData[dgsEle].absPos
x,y = x or pos[1],y or pos[2]
local pivot = dgsElementData[dgsEle].posPivot
if select("#",...) == 2 or pivot then
local pivotX,pivotY
if select("#",...) == 2 then
pivotX,pivotY = ...
else
pivotX,pivotY = pivot[1],pivot[2]
end
if (type(pivotX) ~= "number") then error(dgsGenAsrt(pivotX,"dgsSetPosition",5,"number")) end
if (type(pivotY) ~= "number") then error(dgsGenAsrt(pivotY,"dgsSetPosition",6,"number")) end
local size = dgsElementData[dgsEle].absSize
calculateGuiPositionSize(dgsEle,x-size[1]*pivotX,y-size[2]*pivotX,relative)
else
local isCenterPosition = ...
if isCenterPosition then
local size = dgsElementData[dgsEle][relative and "rltSize" or "absSize"]
calculateGuiPositionSize(dgsEle,x-size[1]/2,y-size[2]/2,relative)
else
calculateGuiPositionSize(dgsEle,x,y,relative)
end
end
return true
end
end
function dgsCenterElement(dgsEle,remainX,remainY)
if type(dgsEle) == "table" then
for index,dgsEleItem in pairs(dgsEle) do
if not(dgsIsType(dgsEleItem)) then error(dgsGenAsrt(dgsEleItem,"dgsCenterElement",1,"dgs-dxelement",_,_,"at table index "..i)) end
dgsCenterElement(dgsEleItem,remainX,remainY)
end
return true
else
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsCenterElement",1,"dgs-dxelement")) end
local rlt = dgsElementData[dgsEle].relative[1]
if rlt then
local remainPos = dgsElementData[dgsEle].rltPos
local size = dgsElementData[dgsEle].rltSize
return dgsSetPosition(dgsEle,remainX and remainPos[1] or 0.5-size[1]/2,remainY and remainPos[2] or 0.5-size[2]/2,true)
else
local parent = dgsGetParent(dgsEle)
local windowSize = parent and dgsElementData[parent].absSize or {sW,sH}
local remainPos = dgsElementData[dgsEle].absPos
local size = dgsElementData[dgsEle].absSize
return dgsSetPosition(dgsEle,remainX and remainPos[1] or windowSize[1]/2-size[1]/2,remainY and remainPos[2] or windowSize[2]/2-size[2]/2,false)
end
end
end
function dgsGetSize(dgsEle,relative)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetSize",1,"dgs-dxelement")) end
local size = dgsElementData[dgsEle][relative and "rltSize" or "absSize"]
if size then return size[1],size[2] end
return 0,0
end
function dgsSetSize(dgsEle,w,h,relative,...)
if (w and type(w) ~= "number") then error(dgsGenAsrt(w,"dgsSetSize",2,"nil/number")) end
if (h and type(h) ~= "number") then error(dgsGenAsrt(h,"dgsSetSize",3,"nil/number")) end
if relative then
if w and (w > 10 or w < -10) then error(dgsGenAsrt(w,"dgsSetSize",2,"float between [0, 1]")) end
if h and (h > 10 or h < -10) then error(dgsGenAsrt(h,"dgsSetSize",3,"float between [0, 1]")) end
end
if type(dgsEle) == "table" then
for index,dgsEleItem in pairs(dgsEle) do
if not(dgsIsType(dgsEleItem)) then error(dgsGenAsrt(dgsEleItem,"dgsSetSize",1,"dgs-dxelement",_,_,"at table index "..i)) end
dgsSetSize(dgsEleItem,w,h,relative,...)
end
return true
else
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsCenterElement",1,"dgs-dxelement")) end
local size = relative and dgsElementData[dgsEle].rltSize or dgsElementData[dgsEle].absSize
w,h = w or size[1], h or size[2]
local pivot = dgsElementData[dgsEle].sizePivot
if select("#",...) == 2 or pivot then
local pivotX,pivotY
if select("#",...) == 2 then
pivotX,pivotY = ...
else
pivotX,pivotY = pivot[1],pivot[2]
end
if (type(pivotX) ~= "number") then error(dgsGenAsrt(pivotX,"dgsSetSize",5,"number")) end
if (type(pivotY) ~= "number") then error(dgsGenAsrt(pivotY,"dgsSetSize",6,"number")) end
local oldSize = relative and dgsElementData[dgsEle].rltSize or dgsElementData[dgsEle].absSize
calculateGuiPositionSize(dgsEle,_,_,_,w,h,relative or false)
local oldPos = relative and dgsElementData[dgsEle].rltPos or dgsElementData[dgsEle].absPos
local newSize = relative and dgsElementData[dgsEle].rltSize or dgsElementData[dgsEle].absSize
calculateGuiPositionSize(dgsEle,oldPos[1]-(newSize[1]-oldSize[1])*pivotX,oldPos[2]-(newSize[2]-oldSize[2])*pivotY,relative)
else
calculateGuiPositionSize(dgsEle,_,_,_,w,h,relative or false)
end
end
return true
end
function dgsAttachElements(dgsEle,attachTo,offsetX,offsetY,offsetW,offsetH,relativePos,relativeSize)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsAttachElements",1,"dgs-dxelement")) end
if dgsGetParent(dgsEle) then error(dgsGenAsrt(dgsEle,"dgsAttachElements",1,_,_,"source dgs element shouldn't have a parent")) end
if not(dgsIsType(attachTo)) then error(dgsGenAsrt(attachTo,"dgsAttachElements",2,"dgs-dxelement")) end
dgsDetachElements(dgsEle)
relativeSize = relativeSize == nil and relativePos or relativeSize
if not offsetW or not offsetH then
local size = dgsElementData[dgsEle].absSize
offsetW,offsetH = size[1],size[2]
relativeSize = false
end
offsetX,offsetY = offsetX or 0,offsetY or 0
local attachedTable = {attachTo,offsetX,offsetY,relativePos,offsetW,offsetH,relativeSize}
dgsElementData[attachTo] = dgsElementData[attachTo] or {}
dgsElementData[attachTo].attachedBy = dgsElementData[attachTo].attachedBy or {}
local attachedBy = dgsElementData[attachTo].attachedBy
tableInsert(attachedBy,dgsEle)
dgsSetData(attachTo,"attachedBy",attachedBy)
dgsSetData(dgsEle,"attachedTo",attachedTable)
local absx,absy = dgsGetPosition(attachTo,false,true)
local absw,absh = dgsElementData[attachTo].absSize[1],dgsElementData[attachTo].absSize[2]
offsetX,offsetY = relativePos and (absx+absw*offsetX)/sW or offsetX+absx, relativePos and (absy+absh*offsetY)/sH or offsetY+absy
offsetW,offsetH = relativeSize and absw*offsetW/sW or offsetW, relativeSize and absh*offsetH/sH or offsetH
calculateGuiPositionSize(dgsEle,offsetX,offsetY,relativePos,offsetW,offsetH,relativeSize)
return true
end
function dgsElementIsAttached(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsElementIsAttached",1,"dgs-dxelement")) end
return dgsElementData[dgsEle].attachedTo and true or false
end
function dgsDetachElements(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsDetachElements",1,"dgs-dxelement")) end
local attachedTable = dgsElementData[dgsEle].attachedTo or {}
if isElement(attachedTable[1]) then
local attachedBy = dgsElementData[attachedTable[1]].attachedBy
local id = tableFind(attachedBy or {},dgsEle)
if id then
tableRemove(attachedBy,dgsEle)
end
end
return dgsSetData(dgsEle,"attachedTo",false)
end
function dgsApplyDetectArea(dgsEle,da)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsApplyDetectArea",1,"dgs-dxelement")) end
if not(dgsGetType(da) == "dgs-dxdetectarea") then error(dgsGenAsrt(da,"dgsApplyDetectArea",2,"dgs-dxdetectarea")) end
return dgsSetData(dgsEle,"dgsCollider",da)
end
function dgsRemoveDetectArea(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsRemoveDetectArea",1,"dgs-dxelement")) end
return dgsSetData(dgsEle,"dgsCollider",nil)
end
function dgsGetDetectArea(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetDetectArea",1,"dgs-dxelement")) end
return dgsElementData[dgsEle].dgsCollider or false
end
function dgsApplyEnabledInherited(parent,enabled)
local children = dgsElementData[parent].children
for k,child in ipairs(children) do
dgsElementData[child].enabledInherited = enabled
dgsApplyEnabledInherited(child,dgsElementData[child].enabledInherited)
end
end
function dgsSetEnabled(dgsEle,enabled)
enabled = enabled and true or false
if type(dgsEle) == "table" then
for index,dgsEleItem in pairs(dgsEle) do
if not(dgsIsType(dgsEleItem)) then error(dgsGenAsrt(dgsEleItem,"dgsSetEnabled",1,"dgs-dxelement",_,_,"at table index "..i)) end
dgsSetEnabled(dgsEleItem,enabled)
end
return true
else
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetEnabled",1,"dgs-dxelement")) end
local originalEnabled = dgsElementData[dgsEle].enabled
if enabled == originalEnabled then return true end
local parentInherited = true
local parent = dgsGetParent(dgsEle)
if parent then parentInherited = dgsElementData[parent].enabledInherited and dgsElementData[parent].enabled end
dgsElementData[dgsEle].enabledInherited = parentInherited
dgsApplyEnabledInherited(dgsEle,enabled and dgsElementData[dgsEle].enabledInherited)
return dgsSetData(dgsEle,"enabled",enabled)
end
end
function dgsGetEnabled(dgsEle,selfOnly)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetEnabled",1,"dgs-dxelement")) end
if selfOnly then return dgsElementData[dgsEle].enabled end
return dgsElementData[dgsEle].enabledInherited and dgsElementData[dgsEle].enabled
end
function dgsApplyVisibleInherited(parent,visible)
local children = dgsElementData[parent].children
for i=1,#children do
local child = children[i]
dgsElementData[child].visibleInherited = visible
local eleType = dgsElementType[child]
if dgsOnVisibilityChange[eleType] then dgsOnVisibilityChange[eleType](child) end
if not visible and MouseData.focused == child then dgsBlur(child) end
dgsApplyVisibleInherited(child,dgsElementData[child].visibleInherited)
end
end
function dgsSetVisible(dgsEle,visible)
visible = visible and true or false
if type(dgsEle) == "table" then
local result = true
for index,dgsEleItem in pairs(dgsEle) do
if not(dgsIsType(dgsEleItem)) then error(dgsGenAsrt(dgsEleItem,"dgsSetVisible",1,"dgs-dxelement",_,_,"at table index "..i)) end
dgsSetVisible(dgsEleItem,visible)
end
return true
else
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetVisible",1,"dgs-dxelement")) end
local originalVisible = dgsElementData[dgsEle].visible
if visible == originalVisible then return true end
local parentInherited = true
local parent = dgsGetParent(dgsEle)
if parent then parentInherited = dgsElementData[parent].visibleInherited and dgsElementData[parent].visible end
dgsElementData[dgsEle].visibleInherited = parentInherited
local eleType = dgsElementType[dgsEle]
if dgsOnVisibilityChange[eleType] then dgsOnVisibilityChange[eleType](dgsEle) end
if not visible and MouseData.focused == dgsEle then dgsBlur(dgsEle) end
return dgsSetData(dgsEle,"visible",visible)
end
end
function dgsGetVisible(dgsEle,selfOnly)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetVisible",1,"dgs-dxelement")) end
if selfOnly then return dgsElementData[dgsEle].visible end
return dgsElementData[dgsEle].visibleInherited and dgsElementData[dgsEle].visible
end
function dgsSetPositionAlignment(dgsEle,horizontal,vertical)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetPositionAlignment",1,"dgs-dxelement")) end
local eleAlign = dgsElementData[dgsEle].positionAlignment
eleAlign[1] = horizontal or eleAlign[1]
eleAlign[2] = vertical or eleAlign[2]
return dgsSetData(dgsEle,"positionAlignment",eleAlign)
end
function dgsGetPositionAlignment(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetPositionAlignment",1,"dgs-dxelement")) end
return dgsElementData[dgsEle].positionAlignment[1] or "left",dgsElementData[dgsEle].positionAlignment[2] or "top"
end
function configPosSize(dgsEle,pos,size)
local eleData = dgsElementData[dgsEle]
local rlt = eleData.relative
local x,y,rltPos,w,h,rltSize
if pos then
pos = rlt[1] and eleData.rltPos or eleData.absPos
x,y,rltPos = pos[1],pos[2],rlt[1]
end
if size then
size = rlt[1] and eleData.rltSize or eleData.absSize
w,h,rltSize = size[1],size[2],rlt[2]
end
calculateGuiPositionSize(dgsEle,x,y,rltPos,w,h,rltSize)
end
function calculateGuiPositionSize(dgsEle,x,y,relativep,sx,sy,relatives,notrigger)
if not dgsElementData[dgsEle] then dgsElementData[dgsEle] = {} end
local eleData = dgsElementData[dgsEle]
local parent = eleData.parent
local psx,psy = sW,sH
local relt = eleData.relative
local oldRelativePos,oldRelativeSize
if relt then
oldRelativePos,oldRelativeSize = relt[1],relt[2]
else
oldRelativePos,oldRelativeSize = relativep,relatives
end
local titleOffset = 0
if isElement(parent) then
local parentData = dgsElementData[parent]
if dgsElementType[parent] == "dgs-dxtab" then
local tabpanel = parentData.parent
local size = dgsElementData[tabpanel].absSize
psx,psy = size[1],size[2]
local height = dgsElementData[tabpanel].tabHeight[2] and dgsElementData[tabpanel].tabHeight[1]*psy or dgsElementData[tabpanel].tabHeight[1]
psy = psy-height
else
local size = parentData.absSize or parentData.resolution
psx,psy = size[1],size[2]
end
if not eleData.ignoreParentTitle and parentData.ignoreTitle then
titleOffset = parentData.titleHeight or 0
end
end
if x and y then
if not eleData.absPos then eleData.absPos = {} end
if not eleData.rltPos then eleData.rltPos = {} end
local absPos = eleData.absPos
local oldPosAbsx,oldPosAbsy = absPos[1],absPos[2]
local rltPos = eleData.rltPos
local oldPosRltx,oldPosRlty = rltPos[1],rltPos[2]
x,y = relativep and x*psx or x,relativep and y*psy or y
local abx,aby,relatx,relaty = x,y,x/psx,y/psy
if psx == 0 then relatx = 0 end
if psy == 0 then relaty = 0 end
dgsSetData(dgsEle,"absPos",{abx,aby})
dgsSetData(dgsEle,"rltPos",{relatx,relaty})
dgsSetData(dgsEle,"relative",{relativep,oldRelativeSize})
if not notrigger then
dgsTriggerEvent("onDgsPositionChange",dgsEle,oldPosAbsx,oldPosAbsy,oldPosRltx,oldPosRlty)
end
end
if sx and sy then
if not eleData.absSize then eleData.absSize = {} end
if not eleData.rltSize then eleData.rltSize = {} end
local absSize = eleData.absSize
local oldSizeAbsx,oldSizeAbsy = absSize[1],absSize[2]
local rltSize = eleData.rltSize
local oldSizeRltx,oldSizeRlty = rltSize[1],rltSize[2]
sx,sy = relatives and sx*psx or sx,relatives and sy*(psy-titleOffset) or sy
local absx,absy,relatsx,relatsy = sx,sy,sx/psx,sy/(psy-titleOffset)
if psx == 0 then relatsx = 0 end
if psy-titleOffset == 0 then relatsy = 0 end
dgsSetData(dgsEle,"absSize",{absx,absy})
dgsSetData(dgsEle,"rltSize",{relatsx,relatsy})
dgsSetData(dgsEle,"relative",{oldRelativePos,relatives})
if not notrigger then
dgsTriggerEvent("onDgsSizeChange",dgsEle,oldSizeAbsx,oldSizeAbsy,oldSizeRltx,oldSizeRlty)
end
end
return true
end
function dgsSetAlpha(dgsEle,alpha,absolute)
if not(type(alpha) == "number") then error(dgsGenAsrt(alpha,"dgsSetAlpha",2,"number")) end
if type(dgsEle) == "table" then
for index,dgsEleItem in pairs(dgsEle) do
if not(dgsIsType(dgsEleItem)) then error(dgsGenAsrt(dgsEleItem,"dgsSetAlpha",1,"dgs-dxelement",_,_,"at table index "..i)) end
dgsSetAlpha(dgsEleItem,alpha,absolute)
end
return true
else
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetAlpha",1,"dgs-dxelement")) end
alpha = absolute and alpha/255 or alpha
return dgsSetData(dgsEle,"alpha",(alpha > 1 and 1) or (alpha < 0 and 0) or alpha)
end
end
function dgsGetAlpha(dgsEle,absolute,includeParent)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetAlpha",1,"dgs-dxelement")) end
if includeParent then
local alp = 1
local p = dgsEle
for i=1,5000 do
if not p then return absolute and alp*255 or alp end
alp = alp*(dgsElementData[p].alpha or 1)
p = dgsElementData[p].parent
end
else
local alp = dgsElementData[dgsEle].alpha
return absolute and alp*255 or alp
end
end
function dgsCreateFont(path,size,bold,quality)
if not(type(path) == "string") then error(dgsGenAsrt(path,"dgsCreateFont",1,"string")) end
if not path:find(":") then
local resname = getResourceName(sourceResource or resource)
path = ":"..resname.."/"..path
end
if not fileExists(path) then error(dgsGenAsrt(path,"dgsCreateFont",1,_,_,_,"Couldn't find such file '"..path.."'")) end
return dxCreateFont(path,size,bold,quality)
end
function dgsSetFont(dgsEle,font)
if type(dgsEle) == "table" then
for index,dgsEleItem in pairs(dgsEle) do
if not(dgsIsType(dgsEleItem)) then error(dgsGenAsrt(dgsEleItem,"dgsSetFont",1,"dgs-dxelement",_,_,"at table index "..i)) end
dgsSetFont(dgsEleItem,font)
end
return true
else
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetFont",1,"dgs-dxelement")) end
local fontType = dgsGetType(font)
if fontType == "string" then
if not(fontBuiltIn[font]) then error(dgsGenAsrt(font,"dgsSetFont",2,_,_,_,"font "..font.." doesn't exist")) end
elseif fontType == "table" then
--nothing (xLive, Do not delete this line)
elseif fontType ~= "dx-font" then
error(dgsGenAsrt(font,"dgsSetFont",2,"string/dx-font/table"))
end
dgsSetData(dgsEle,"font",font)
return true
end
end
function dgsGetFont(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetFont",1,"dgs-dxelement")) end
return dgsElementData[dgsEle].font
end
function dgsGetSystemFont(sres)
local res = sres or sourceResource or "global"
local style = styleManager.styles[res]
style = style.loaded[style.using]
local systemFont = style.systemFontElement
return systemFont
end
function dgsSetSystemFont(font,size,bold,quality,styleName,sres)
if not(type(font) == "string") then error(dgsGenAsrt(font,"dgsSetSystemFont",1,"string")) end
res = sres or sourceResource or "global"
local style = styleManager.styles[res]
style = style.loaded[styleName or style.using]
local systemFont = style.systemFontElement
if isElement(systemFont) then
destroyElement(systemFont)
style.systemFontElement = "default"
end
local sResource = sourceResource or resource
if fontBuiltIn[font] then
style.systemFontElement = font
return true
else
local path = font:find(":") and font or ":"..getResourceName(sResource).."/"..font
if not fileExists(path) then error(dgsGenAsrt(path,"dgsSetSystemFont",1,_,_,_,"Couldn't find such file '"..path.."'")) end
font = dxCreateFont(path,size,bold,quality)
if isElement(font) then
style.systemFontElement = font
end
end
return false
end
function dgsSetText(dgsEle,text)
if type(dgsEle) == "table" then
for index,dgsEleItem in pairs(dgsEle) do
if not(dgsIsType(dgsEleItem)) then error(dgsGenAsrt(dgsEleItem,"dgsSetText",1,"dgs-dxelement",_,_,"at table index "..i)) end
dgsSetText(dgsEleItem,text)
end
return true
else
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetText",1,"dgs-dxelement")) end
return dgsSetData(dgsEle,"text",text)
end
end
function dgsGetText(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetText",1,"dgs-dxelement")) end
local dxtype = dgsGetType(dgsEle)
if dxtype == "dgs-dxmemo" then
return dgsMemoGetPartOfText(dgsEle)
else
return dgsElementData[dgsEle].text
end
end
function dgsSetClickingSound(dgsEle,soundPath,volume,button,state)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetClickingSound",1,"dgs-dxelement")) end
if not(type(soundPath) == "string") then error(dgsGenAsrt(soundPath,"dgsSetClickingSound",2,"string")) end
if sourceResource then
if not soundPath:find(":") then
soundPath = ":"..getResourceName(sourceResource).."/"..soundPath
end
end
if not fileExists(soundPath) then error(dgsGenAsrt(soundPath,"dgsSetClickingSound",2,_,_,_,"Couldn't find such file '"..soundPath.."'")) end
button = button or "left"
state = state or "down"
local eleData = dgsElementData[dgsEle]
if not eleData.clickingSound then eleData.clickingSound = {} end
if not eleData.clickingSound[button] then eleData.clickingSound[button] = {} end
eleData.clickingSound[button][state] = soundPath
if not eleData.clickingSoundVolume then eleData.clickingSoundVolume = {} end
if not eleData.clickingSoundVolume[button] then eleData.clickingSoundVolume[button] = {} end
eleData.clickingSoundVolume[button][state] = tonumber(volume)
return true
end
function dgsGetClickingSound(dgsEle,button,state)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetClickingSound",1,"dgs-dxelement")) end
button = button or "left"
state = state or "down"
local eleData = dgsElementData[dgsEle]
if not eleData.clickingSound then return false end
if not eleData.clickingSound[button] then return false end
return eleData.clickingSound[button][state] or false
end
function dgsSetClickingSoundVolume(dgsEle,volume,button,state)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetClickingSoundVolume",1,"dgs-dxelement")) end
if type(volume) ~= "number" then error(dgsGenAsrt(volume,"dgsSetClickingSoundVolume",2,"number")) end
button = button or "left"
state = state or "down"
local eleData = dgsElementData[dgsEle]
if not eleData.clickingSoundVolume then eleData.clickingSoundVolume = {} end
if not eleData.clickingSoundVolume[button] then eleData.clickingSoundVolume[button] = {} end
eleData.clickingSoundVolume[button][state] = volume
return true
end
function dgsGetClickingSoundVolume(dgsEle,button,state)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetClickingSound",1,"dgs-dxelement")) end
button = button or "left"
state = state or "down"
local eleData = dgsElementData[dgsEle]
if not eleData.clickingSoundVolume then return 1 end
if not eleData.clickingSoundVolume[button] then return 1 end
return eleData.clickingSoundVolume[button][state] or 1
end
function dgsSetPostGUI(dgsEle,state)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsSetPostGUI",1,"dgs-dxelement")) end
return dgsSetProperty(dgsEle,"postGUI",state)
end
function dgsGetPostGUI(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsGetPostGUI",1,"dgs-dxelement")) end
return dgsElementData[dgsEle].postGUI
end
function dgsSimulateClick(dgsGUI,button)
local x,y = dgsGetPosition(dgsGUI,false)
local sx,sy = dgsGetSize(dgsGUI,false)
x,y = x+sx*0.5,y+sy*0.5
dgsTriggerEvent("onDgsMouseClick",dgsGUI,button,"down",x,y)
dgsTriggerEvent("onDgsMouseClick",dgsGUI,button,"up",x,y)
end
function dgsGetMouseClickGUI(button)
if button == "left" then
return MouseData.click.left
elseif button == "middle" then
return MouseData.click.middle
else
return MouseData.click.right
end
end
function dgsIsMouseWithinGUI(ele)
if type(ele) == "table" then
local result = {}
if isCursorShowing() then
for key,e in pairs(ele) do
result[e] = MouseData.WithinElements[e] and true or nil
end
end
return result
else
return (isCursorShowing() and MouseData.WithinElements[ele]) and true or false
end
end
function dgsGetMouseEnterGUI() return MouseData.entered end
function dgsGetMouseLeaveGUI() return MouseData.left end
function dgsGetFocusedGUI() return MouseData.focused end
function dgsGetScreenSize() return guiGetScreenSize() end
function dgsSetInputEnabled(...) return guiSetInputEnabled(...) end
function dgsGetInputEnabled(...) return guiGetInputEnabled(...) end
function dgsSetInputMode(...) return guiSetInputMode(...) end
function dgsGetInputMode(...) return guiGetInputMode(...) end
function dgsGetBrowser(b) return b end
function dgsGetRootElement() return resourceRoot end
function dgsFocus(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsFocus",1,"dgs-dxelement")) end
local nFocusedChain = {}
local oFocusedChain = MouseData.focusedChain
local logEle = dgsEle
repeat
nFocusedChain[logEle] = true
nFocusedChain[#nFocusedChain+1] = logEle
logEle = dgsElementData[logEle].parent
until not logEle
for index=#oFocusedChain,1,-1 do
local ele = oFocusedChain[index]
if oFocusedChain[ele] and not nFocusedChain[ele] then --Blur if new focused chain doesn't include
dgsTriggerEvent("onDgsBlur",oFocusedChain[index])
end
end
for index=#nFocusedChain,1,-1 do
local ele = nFocusedChain[index]
if nFocusedChain[ele] and not oFocusedChain[ele] then --Focus if old focused chain doesn't include
dgsTriggerEvent("onDgsFocus",nFocusedChain[index])
end
end
MouseData.focusedChain = nFocusedChain
MouseData.focused = dgsEle
return true
end
function dgsBlur(dgsEle)
if not dgsEle then
dgsEle = MouseData.focusedChain[#MouseData.focusedChain] --Just blur all
end
local oFocusedChain = MouseData.focusedChain
if oFocusedChain[dgsEle] then --If found
local index = tableFind(oFocusedChain,dgsEle) --Get index
local blurredEle = {}
for i=index,1,-1 do
local dgsEleToBlur = oFocusedChain[i]
if MouseData.focused == dgsEleToBlur then --If the blurred element is MouseData.focused
MouseData.focused = oFocusedChain[i+1] --Select its parent, nil if no focused
end
blurredEle[#blurredEle+1] = dgsEleToBlur
oFocusedChain[dgsEleToBlur] = nil
table.remove(oFocusedChain,i) --Remove
end
for i=1,#blurredEle do
if isElement(blurredEle[i]) then
dgsTriggerEvent("onDgsBlur",blurredEle[i])
end
end
end
return true
end
function dgsIsFocused(dgsEle)
return MouseData.focusedChain[dgsEle]
end
------------------Cursor Management
local CursorPosX,CursorPosY = sW/2,sH/2
local CursorPosXVisible,CursorPosYVisible = CursorPosX,CursorPosY
if isCursorShowing() then
local cx,cy = getCursorPosition()
CursorPosX,CursorPosY = cx*sW,cy*sH
CursorPosXVisible,CursorPosYVisible = CursorPosX,CursorPosY
end
function dgsGetCursorVisible()
return (isCursorShowing() or isChatBoxInputActive() or isConsoleActive()) and not isMainMenuActive() --Is visible in game
end
--to enhance cursor in scale pane
function dgsGetCursorPosition(rltEle,rlt,forceOnScreen)
if dgsGetCursorVisible() then
if rltEle and dgsIsType(rltEle) then --relative to element has higher priority
local cursorX,cursorY = CursorPosXVisible,CursorPosYVisible
local has3DInterface = false
local parent = rltEle
while(parent) do
if dgsGetType(parent) == "dgs-dx3dinterface" then has3DInterface = parent break end
parent = dgsGetParent(parent)
end
if has3DInterface then --For 3d interface, recalculate position and ignore "forceOnScreen"
local hitX,hitY,px,py,pz,isHit = dgs3DInterfaceCalculateMousePosition(has3DInterface)
local resolution = dgsElementData[has3DInterface].resolution
if rltEle == has3DInterface then
if rlt then return hitX, hitY end
return hitX*resolution[1], hitY*resolution[2]
end
cursorX,cursorY = hitX*resolution[1], hitY*resolution[2]
end
local posX,posY = dgsGetElementPositionOnScreen(rltEle)
if rlt then
local sizeX, sizeY = false,false
parent = rltEle
while(parent) do
local size = dgsElementData[parent].absSize
if size then
sizeX, sizeY = size[1], size[2]
break
end
parent = dgsGetParent(parent)
end
if sizeX and sizeY then
return (cursorX-posX)/sizeX, (cursorY-posY)/sizeY
else
return (cursorX-posX)/scW, (cursorY-posY)/scH
end
else
return cursorX-posX, cursorY-posY
end
elseif MouseData.lock3DInterface and not forceOnScreen then --If no rltEle and there is a 3d interface locked, for 3d interface using calculated position
local absX,absY = dgsElementData[MouseData.lock3DInterface].cursorPosition[1],dgsElementData[MouseData.lock3DInterface].cursorPosition[2]
local resolution = dgsElementData[MouseData.lock3DInterface].resolution
if rlt then
return absX/resolution[1],absY/resolution[2]
else
return absX,absY
end
else
if rlt then
return CursorPosXVisible/sW,CursorPosYVisible/sH
else
return CursorPosXVisible,CursorPosYVisible
end
end
end
return false
end
addEventHandler("onClientCursorMove",root,function(_,_,x,y)
CursorPosX,CursorPosY = x,y
if dgsGetCursorVisible() then
CursorPosXVisible,CursorPosYVisible = CursorPosX,CursorPosY
end
end)
--Multi Click Interval
function dgsGetMultiClickInterval() return multiClick.Interval end
function dgsSetMultiClickInterval(interval)
if not(type(interval) == "number") then error(dgsGenAsrt(interval,"dgsSetClickInterval",1,"number")) end
multiClick.Interval = interval
return true
end
--Mouse Stay Delay
function dgsGetMouseStayDelay() return mouseStay.delay end
function dgsSetMouseStayDelay(delay)
if not(type(delay) == "number") then error(dgsGenAsrt(delay,"dgsSetMouseStayDelay",1,"number")) end
mouseStay.delay = delay
return true
end
------------Move Scale Handler
function dgsAddMoveHandler(dgsEle,x,y,w,h,xRel,yRel,wRel,hRel,forceReplace)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsAddMoveHandler",1,"dgs-dxelement")) end
x,y,xRel,yRel = x or 0,y or 0,xRel ~= false and true,yRel ~= false and true
w,h,wRel,hRel = w or 1,h or 1,wRel ~= false and true,hRel ~= false and true
local moveData = dgsElementData[dgsEle].moveHandlerData
if not moveData or forceReplace then
dgsSetData(dgsEle,"moveHandlerData",{x,y,w,h,xRel,yRel,wRel,hRel})
end
end
function dgsRemoveMoveHandler(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsRemoveMoveHandler",1,"dgs-dxelement")) end
local moveData = dgsElementData[dgsEle].moveHandlerData
if moveData then
dgsSetData(dgsEle,"moveHandlerData",nil)
end
end
function dgsIsMoveHandled(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsIsMoveHandled",1,"dgs-dxelement")) end
return dgsElementData[dgsEle].moveHandlerData and true or false
end
function dgsAddSizeHandler(dgsEle,left,right,top,bottom,leftRel,rightRel,topRel,bottomRel,forceReplace)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsAddSizeHandler",1,"dgs-dxelement")) end
left = left or 0
right = right or left
top = top or right
bottom = bottom or top
leftRel = leftRel ~= false and true
rightRel = rightRel ~= false and true
topRel = topRel ~= false and true
bottomRel = bottomRel ~= false and true
local sizeData = dgsElementData[dgsEle].sizeHandlerData
if not sizeData or forceReplace then
dgsSetData(dgsEle,"sizeHandlerData",{left,right,top,bottom,leftRel,rightRel,topRel,bottomRel})
end
end
function dgsRemoveSizeHandler(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsRemoveSizeHandler",1,"dgs-dxelement")) end
local sizeData = dgsElementData[dgsEle].sizeHandlerData
if sizeData then
dgsSetData(dgsEle,"sizeHandlerData",nil)
end
end
function dgsIsSizeHandled(dgsEle)
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsIsSizeHandled",1,"dgs-dxelement")) end
return dgsElementData[dgsEle].sizeHandlerData and true or false
end
dgsDragDropBoard = {
[0] = false,
data = {}, --The data you want to transfer
lock = false,
preview = nil, --The preview you want to show
previewColor = nil,
previewOffsetX = nil,
previewOffsetY = nil,
previewWidth = nil,
previewHeight = nil,
previewAlignment = nil,
}
function dgsSendDragNDropData(dragData,preview,previewColor,previewOffsetX,previewOffsetY,previewWidth,previewHeight,previewHorizontalAlign,previewVerticalAlign)
dgsDragDropBoard[0] = true
dgsDragDropBoard.data = dragData
dgsDragDropBoard.preview = preview
dgsDragDropBoard.previewColor = previewColor
dgsDragDropBoard.previewOffsetX = previewOffsetX
dgsDragDropBoard.previewOffsetY = previewOffsetY
dgsDragDropBoard.previewWidth = previewWidth
dgsDragDropBoard.previewHeight = previewHeight
dgsDragDropBoard.previewAlignment = {previewHorizontalAlign,previewVerticalAlign}
return true
end
function dgsRetrieveDragNDropData(retainState)
if dgsDragDropBoard[0] then
if not retainState then
dgsDragDropBoard[0] = false
end
return dgsDragDropBoard.data
end
end
function dgsIsDragNDropData()
return dgsDragDropBoard[0]
end
function dgsAddDragHandler(dgsEle,...)
--dragData,preview,previewColor,previewOffsetX,previewOffsetY,previewWidth,previewHeight,previewHorizontalAlign,previewVerticalAlign
return dgsSetData(dgsEle,"dragHandler",{...})
end
function dgsRemoveDragHandler(dgsEle)
return dgsSetData(dgsEle,"dragHandler",nil)
end
------------Auto Destroy
function dgsAttachToAutoDestroy(element,dgsEle,index)
if not isElement(element) then return true end
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsAttachToAutoDestroy",2,"dgs-dxelement")) end
local eleData = dgsElementData[dgsEle]
eleData.autoDestroyList = eleData.autoDestroyList or {}
if not index then
tableInsert(eleData.autoDestroyList,element)
else
eleData.autoDestroyList[index] = element
end
return true
end
function dgsDetachFromAutoDestroy(element,dgsEle)
if not(isElement(element)) then error(dgsGenAsrt(element,"dgsDetachFromAutoDestroy",1,"element")) end
if not(dgsIsType(dgsEle)) then error(dgsGenAsrt(dgsEle,"dgsDetachFromAutoDestroy",2,"dgs-dxelement")) end
local id = tableFind(dgsElementData[dgsEle].autoDestroyList or {},element)
if id then tableRemove(dgsElementData[dgsEle].autoDestroyList,id) end
return true
end
----------------------------------Multi Language Support
function dgsTranslationTableExists(name)
if not(type(name) == "string") then error(dgsGenAsrt(name,"dgsTranslationTableExists",1,"string")) end
return LanguageTranslation[name] and true or false
end
function dgsSetTranslationTable(name,tab)
if not(type(name) == "string") then error(dgsGenAsrt(name,"dgsSetTranslationTable",1,"string")) end
if not(not table or type(tab) == "table") then error(dgsGenAsrt(tab,"dgsSetTranslationTable",1,"table/nil")) end
if tab then
LanguageTranslation[name] = tab
if not LanguageTranslationAttach[name] then LanguageTranslationAttach[name] = {} end
dgsApplyLanguageChange(name,LanguageTranslation[name],LanguageTranslationAttach[name])
triggerEvent("onDgsTranslationTableChange",sourceResourceRoot or resourceRoot,name)
elseif dgsTranslationTableExists(name) then
LanguageTranslation[name] = false
for k,v in ipairs(LanguageTranslationAttach[name]) do
dgsSetData(v,"_translang",nil)
end
LanguageTranslation[name] = nil
LanguageTranslationAttach[name] = nil
end