-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLazyFrame.lua
2499 lines (2131 loc) · 67.1 KB
/
LazyFrame.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
--#region 基类-原型对象构造定义
---- lua 模拟C#类
--- [链接](https://blog.csdn.net/YuAnHandSome/article/details/105809559)
--- 已做修改添加Getter和Setter机制
local mt = {
clsName = "mt",
__get__ = {},
__set__ = {},
}
---建构一个新的类
---@param clsName string 类名
---@param base table? 基类
---@return table
local function NewClass(clsName, base)
base = base or mt
local cls = {}
cls.__get__ = (base.__get__ and setmetatable({}, { __index = base.__get__ }) or {})
cls.__set__ = (base.__set__ and setmetatable({}, { __index = base.__set__ }) or {})
setmetatable(cls, { __index = base })
cls.clsName = clsName or "default"
cls.base = base
cls.__index = cls
--- 类实例化
cls.new = function(...)
--- 原型对象实例
local cls_instance = {}
cls_instance.getset_values = {}
local BaseCls = cls
local cls_instance_mt = {
--- Getter 实现
__index = function(t, k)
if BaseCls[k] then
return BaseCls[k]
end
--- 如果有getter ,则执行getter
if t.__get__[k] then
t.__get__[k](t) -- 执行
return t.getset_values[k]
end
end,
--- Setter 实现
__newindex = function(t, k, v)
if t.__set__[k] then
t.__set__[k](t, v) -- 执行获取器
cls_instance.getset_values[k] = v --储存值
return
end
--没有获取器
rawset(t, k, v)
-- t[k] = v -- 会一直触发__index 函数
end
}
setmetatable(cls_instance, cls_instance_mt)
if cls_instance.onCreate then
cls_instance:onCreate(...) -- 为什么这里执行函数不会触发__newindex函数
-- 同样会触发,只不过,由于__index函数内的设定没有设定getter的属性会被rawset函数设置
end
return cls_instance
end
--- 设置类 的Setter和Getter
cls.SetSetter = function(self, Prop_t)
self.__set__ = setmetatable(Prop_t, { __index = self.base.__set__ or {} })
end
cls.SetGetter = function(self, Prop_t)
self.__get__ = setmetatable(Prop_t, { __index = self.base.__get__ or {} })
end
return cls
end
local function InitSetter_t(Prop_t)
Prop_t.__index = Prop_t
return Prop_t
end
local function InitGetterFromSetter(Prop_t)
local tmp_t = {}
for key, value in pairs(Prop_t) do
tmp_t[key] = function(self) end
end
tmp_t.__index = tmp_t
return tmp_t
end
--#endregion
--#region 自定义函数
do
local JobName_t = setmetatable({
[1] = "战士",
[2] = "法师",
[3] = "术士",
}, {
__index = function(t, k)
dbg("查找职业名字出错: " .. k)
return ""
end
})
function GetJobName(job)
return JobName_t[job]
end
end
function dbginfo(message)
-- 获取调用者的信息
local level = 2
local info
while true do
info = debug.getinfo(level, "Slfn")
if not info then break end
if info.what ~= "C" and info.what ~= "tail" then
-- 找到了有效的调用者信息
local source = info.short_src -- 一个“可打印”版本的 source ,用于错误信息中
local line = info.currentline -- 给定函数执行到的行数
local funcName = info.name or "unknown"
dbg(string.format("DBG: %s:%d in function <%s>: %s", source, line, funcName, message))
return
end
level = level + 1
end
-- 如果没有找到有效的调用者信息,打印默认信息
dbg(string.format("DBG: unknown location: %s", message))
end
function Tacit(obj)
return function(fn, ...)
if fn == nil then
return obj
end
return Tacit(fn(obj, ...))
end
end
---@type { [string] : true }
local Color_t = {
["WHITE"] = true,
["ORANGE"] = true,
["YELLOW"] = true,
["BLUE"] = true,
["SKYBLUE"] = true,
["DBLUE"] = true,
["GREENG"] = true,
["DGREENG"] = true,
["BGREENG"] = true,
["RED"] = true,
["MAGENTA"] = true,
["BROWN"] = true,
["GOLD"] = true,
["DARKGOLD"] = true,
["PURPLE"] = true,
["GRAY"] = true,
["PINK"] = true,
["BLACK"] = true,
["LIGHTBROWN"] = true,
["BROWN2"] = true,
["GOLD2"] = true,
["DARKGREY"] = true,
["DARK"] = true,
}
---转换颜色
---@param Color (string | integer)?
function TransColor(Color)
local type_S = type(Color)
if type_S == "string" then
if Color:find("#%x%x%x%x%x%x") == 1 or Color:find("#%x%x%x%x%x%x%x%x") == 1 then
return CL:GetColor(Color)
elseif Color_t[Color] == true then
return CL:GetColor(Color)
end
elseif type_S == "number" and tostring(Color):find("%d%d%d%d%d%d%d%d%d%d") == 1 then
return Color
end
end
local WndType_t = {
[1] = { "image" },
[2] = { "button" },
[3] = { "check" },
[4] = { "edit" },
[5] = { "combobox" },
[6] = { "" },
[7] = { "" },
[8] = { "static" },
[9] = { "" },
[10] = { "" },
[11] = { "" },
[12] = { "richedit" },
[13] = { "itemctrl" },
[14] = { "wnd" },
}
function Print_f(...)
local s = ""
local arg = { ... }
s = table.concat(arg, "\t")
CL:Log(s)
end
---打印窗体控件相对于窗口的坐标
---@param _Handle int
function PrintWndPos4Parent(_Handle)
if not GUI:WndIsLive(_Handle) then
local info = debug.getinfo(2, "SLl")
CL:Log(string.format("Error: Called form : %s:%d", info.short_src, info.currentline))
end
if GUI:WndGetPosM(_Handle) then
Print_f("Wnd Name: <" .. GUI:WndGetIDM(_Handle) .. " : (Parent" ..
serialize(GUI:WndGetIDM(GUI:WndGetParentM(_Handle))) ..
")> for Parent [ PosX : (" .. LuaRet[1] .. ") PosY : (" .. LuaRet[2] .. ") ]")
end
end
---打印窗体控件相对于窗口的坐标
---@param _Handle int
function PrintWndPos4Screen(_Handle)
if not GUI:WndIsLive(_Handle) then
local info = debug.getinfo(2, "SLl")
CL:Log(string.format("Called from: %s:%d", info.short_src, info.currentline or 0))
end
if GUI:WndGetScreenPos(_Handle) then
Print_f("Wnd Name: <" .. GUI:WndGetIDM(_Handle) .. " : (Parent:" ..
serialize(GUI:WndGetIDM(GUI:WndGetParentM(_Handle))) ..
")> for Screen [ PosX : (" .. LuaRet[1] .. ") PosY : (" .. LuaRet[2] .. ") ]")
end
end
function PrintSize(_Handle)
if GUI:WndGetSizeM(_Handle) then
Print_f("Wnd Name: <" .. GUI:WndGetIDM(_Handle) .. " : " ..
serialize(GUI:WndGetIDM(GUI:WndGetParentM(_Handle)))
.. "> SizeX : (" .. LuaRet[1] .. ") SizeY : (" .. LuaRet[2] .. ")")
end
end
--#region xml
---迭代xml表节点,迭代 深度为1
---@param xml Xml
---@return function
function XmlIter(xml)
local xml = xml
local root = xml:Root()
local firstEle = xml:FirstChild(root)
local ele = firstEle
---迭代xml表节点
---@return integer # xml节点描述
local iter = function()
local nowele = ele
ele = xml:NextSibling(ele)
return nowele
end
return iter
end
--#endregion
--#region 系统
--#region 特效
---画圆函数
---@param xc int
---@param yc int
---@param x int
---@param y int
---@param eid int
---@param elist_t int[]
function DrawCircle(xc, yc, x, y, eid, elist_t)
local elist_t = elist_t
local lgw, lgh = CL:GetLogicGridWidth(), CL:GetLogicGridHeight()
---@type [int,int][]
local positions = {
{ xc + x, yc + y },
{ xc - x, yc + y },
{ xc + x, yc - y },
{ xc - x, yc - y },
{ xc + y, yc + x },
{ xc - y, yc + x },
{ xc + y, yc - x },
{ xc - y, yc - x },
}
local eeid = 0
local insert = table.insert
for _, pos in ipairs(positions) do
local x_pos = pos[1] * lgw + lgw / 2
local y_pos = pos[2] * lgh + lgh / 2
eeid = CL:AddMagicToPoint(eid, x_pos, y_pos, 0, 0)
insert(elist_t, eeid)
end
end
---
---@param xc int
---@param yc int
---@param r int
---@param eid int
---@param elist_t int[]
function CircleBres(xc, yc, r, eid, elist_t)
local x, y, d = 0, r, (1 - r)
DrawCircle(xc, yc, x, y, eid, elist_t)
while y >= x do
DrawCircle(xc, yc, x, y, eid, elist_t)
if d < 0 then
d = d + 2 * x + 3
else
d = d + 2 * (x - y) + 5
y = y - 1
end
x = x + 1
end
end
---画正方形
---@param xs int
---@param ys int
---@param size int
---@param eid int
---@return int[]
function SquareBres(xs, ys, size, eid)
local elist_t = {}
local insert = table.insert
local lgw, lgh = CL:GetLogicGridWidth(), CL:GetLogicGridHeight()
local x_pos, y_pos = 0, 0
local eeid = 0
y_pos = ys * lgh + lgh / 2
for i = xs, xs + size - 1 do
x_pos = i * lgw + lgw / 2
eeid = CL:AddMagicToPoint(eid, x_pos, y_pos, 0, 0)
insert(elist_t, eeid)
end
y_pos = (ys + size - 1) * lgh + lgh / 2
for i = xs, xs + size - 1 do
x_pos = i * lgw + lgw / 2
eeid = CL:AddMagicToPoint(eid, x_pos, y_pos, 0, 0)
insert(elist_t, eeid)
end
x_pos = xs * lgw + lgw / 2
for i = ys + 1, ys + size - 2 do
y_pos = i * lgh + lgh / 2
eeid = CL:AddMagicToPoint(eid, x_pos, y_pos, 0, 0)
insert(elist_t, eeid)
end
x_pos = (xs + size - 1) * lgw + lgw / 2
for i = ys + 1, ys + size - 2 do
y_pos = i * lgh + lgh / 2
eeid = CL:AddMagicToPoint(eid, x_pos, y_pos, 0, 0)
insert(elist_t, eeid)
end
return elist_t
end
---按照中心点绘制正方向
---@param xs int
---@param ys int
---@param rs int
---@param eid int
---@return integer[]
function SquareBresWithCenter(xs, ys, rs, eid)
local posx = xs - rs
local posy = ys - rs
-- dbg("posx: " .. posx .. " posu: " .. posy)
return SquareBres(posx, posy, rs * 2 + 1, eid)
end
--#endregion
--#region 坐标
--#region 检测
---检测一个点是否在一个正方形内
---@param xs int
---@param ys int
---@param size int
---@param px int
---@param py int
---@return bool
function CheckPosIsInSquare(xs, ys, size, px, py)
xs = tonumber(xs)
ys = tonumber(ys)
px = tonumber(px)
py = tonumber(py)
return px > xs and py > ys and px < xs + size - 1 and py < ys + size - 1
end
---检测一个点是否在一个正方形内
---@param xs int
---@param ys int
---@param rs int
---@param px int
---@param py int
---@return bool
function CheckPosIsInSquareWithCenter(xs, ys, rs, px, py)
return px > (xs - rs) and py > (ys - rs) and px < (xs + rs) and py < (ys + rs)
end
--#endregion
--#region 转换
---转换场景坐标到逻辑格坐标
---@param posx int
---@param posy int
---@return int
---@return int
function ConvertSencePos2LogicPos(posx, posy)
local w = CL:GetLogicGridWidth() --获取当前地图逻辑格宽度
local h = CL:GetLogicGridHeight() --获取当前地图逻辑格高度
return ((posx - w / 2) / w), ((posy - h / 2) / h)
end
---转逻辑格坐标到场景坐标
---@param posx int
---@param posy int
---@return int
---@return int
function ConvertLogicPos2SencePos(posx, posy)
local w = CL:GetLogicGridWidth() --获取当前地图逻辑格宽度
local h = CL:GetLogicGridHeight() --获取当前地图逻辑格高度
return (posx * w + w / 2), (posy * h + h / 2)
end
--#endregion
--#endregion
--#endregion
--#region 玩家
--#region 获取
--#region 自定义变量
---获取服务器传回的个人自定义`int`变量
---@param _DataKey string
---@return integer
function GetSelfInt(_DataKey)
return CL:GetPlayerCustomIntData(CL:GetPlayerSelfGUID(), _DataKey)
end
---获取服务器传回的个人自定义`string`变量
---@param _DataKey string
---@return string
function GetSelfStr(_DataKey)
return CL:GetPlayerCustomStringData(CL:GetPlayerSelfGUID(), _DataKey)
end
--#endregion
--#region 位置
---获取玩家自身的位置
---@return integer
---@return integer
function GetPlayerSelfPos()
local posx = CL:GetPlayerSelfPropBase(ROLE_PROP_POSX) and LuaRet or 0 --[[@as int]]
local posy = CL:GetPlayerSelfPropBase(ROLE_PROP_POSY) and LuaRet or 0 --[[@as int]]
return posx, posy
end
--#endregion
--#region 职业
--#endregion
--#region 战斗力
local MainPropList_t = {
{ ROLE_PROP32_MAX_PHY_DEF, 1, },
{ ROLE_PROP32_MIN_PHY_DEF, 1, },
{ ROLE_PROP32_MAX_MAG_DEF, 1, },
{ ROLE_PROP32_MIN_MAG_DEF, 1, },
{ ROLE_PROP32_MAX_PHY_ATK, 1, },
{ ROLE_PROP32_MIN_PHY_ATK, 1, },
{ ROLE_PROP32_MAX_MAG_ATK, 1, },
{ ROLE_PROP32_MIN_MAG_ATK, 1, },
{ ROLE_PROP32_MAX_TAO_ATK, 1, },
{ ROLE_PROP32_MIN_TAO_ATK, 1, },
}
---获取战斗力
---@param GUID string
---@return integer
GetCombatPower = function(GUID)
dbg("name: " .. (CL:GetPlayerPropBase(GUID, ROLE_PROP_ROLENAME) and LuaRet or ""))
local sum = 0
for index, value in ipairs(MainPropList_t) do
if CL:GetPlayerProperty32(GUID, value[1]) then
dbg("num : " .. LuaRet)
sum = sum + (LuaRet --[[@as int]] * (value[2] or 1))
dbg("sum: " .. sum)
end
end
return sum
end
--#endregion
--#endregion
--#endregion
--#region 字符串
function StrSplit(inputstr, sep)
if sep == nil then
sep = "%s" -- 默认为任意空白字符
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end
--#endregion
--#region 打印
--#endregion
--#endregion
--#region Wnd
--#region Class Define
---@alias Parent Wnd|Image|Button|Edit|ItemCtrl|int
---@class Wnd
---@field clsName "Wnd"
---@field Base table
---@field PosX int
---@field PosY int
---@field Name string
---@field Type 14
---@field Visible bool?
---@field Enable bool?
---@field Param uint?
---@field IDParam uint?
---@field IsESC bool?
---@field CanRevMsg bool?
---@field MoveWithLBM bool?
---@field SizeX int?
---@field SizeY int?
---@field Hint string?
---@field MagicUI int? # `1` 有`MagicUI`特效 </br> `0` 无`MagicUI`特效
---@field new fun(arg:WndCreateArg) : Wnd
---@field __set__ table
---@field __get__ table
---@field SetSetter fun(self:Wnd,Prop_t:table)
---@field SetGetter fun(self:Wnd,Prop_t:table)
Wnd = NewClass("Wnd")
--#endregion
--#region Wnd New
---@class WndCreateArg
---@field Parent Parent
---@field Name string
---@field ImgID int?
---@field PosX int?
---@field PosY int?
---@field SizeX int?
---@field SizeY int?
---创建并初始化
---@param self Wnd
---@param arg WndCreateArg
Wnd.onCreate = function(self, arg)
local Parent = 0
if type(arg.Parent) == "table" then
Parent = arg.Parent:GetHandle() --[[@as int]]
elseif type(arg.Parent) == "number" then
Parent = arg.Parent --[[@as int]]
end
local Name = arg.Name or "default"
local ImgID = arg.ImgID or 0
self.Handle = GUI:WndCreateWnd(Parent or 0, Name, ImgID, 0, 0)
self.PosX = arg.PosX or 0
self.PosY = arg.PosY or 0
self.Name = Name
self.SizeX = arg.SizeX or 0
self.SizeY = arg.SizeY or 0
self.Type = 14
end
---创建窗口
---@param arg WndCreateArg
---@return Wnd
function Wnd:New(arg)
return Wnd.new(arg)
end
---创建窗口
---@param Parent int|Parent
---@param Name string
---@param ImgID int?
---@param PosX int?
---@param PosY int?
---@return Wnd
function Wnd:Create(Parent, Name, ImgID, PosX, PosY)
return Wnd.new { Parent = Parent, Name = Name, ImgID = ImgID, PosX = PosX or 0, PosY = PosY or 0 }
end
---创建窗口
---@param Parent int|Parent
---@param Name string
---@param ImgID int?
---@param PosX int?
---@param PosY int?
---@return Wnd
function Wnd:CreateMainWnd(Parent, Name, ImgID, PosX, PosY)
local wnd = Wnd.new { Parent = Parent, Name = Name, ImgID = ImgID, PosX = PosX or 0, PosY = PosY or 0 }
wnd.IsESC = true
wnd.MoveWithLBM = true
if ImgID ~= nil then
wnd:SetWndSize(CL:GetTextureWidth(ImgID), CL:GetTextureHeight(ImgID))
end
return wnd
end
--#endregion
--#region Wnd Setter,Getter
---@class WndSetter
---@field Pos {PosX:int, PosY:int}?
---@field PosX int?
---@field PosY int?
---@field Enable boolean?
---@field Hint string?
---@field IDParam int?
---@field IsESC bool?
---@field MagicUI int?
---@field MoveWithLBM bool?
---@field Name string?
---@field Param int?
---@field SizeX int?
---@field SizeY int?
---@field Visible boolean?
---@field CanRevMsg boolean?
local tSet_t = {
---改变窗口位置
---@param self Wnd
---@param arg WndPos
["Pos"] = function(self, arg)
if self.Handle == nil then return end
self.PosX = arg.PosX
self.PosY = arg.PosY
end,
---改变窗口位置
---@param self Wnd
---@param arg int
["PosX"] = function(self, arg)
if self.Handle == nil then return end
if GUI:WndGetPosM(self.Handle) then
GUI:WndSetPosM(self.Handle, arg, LuaRet[2])
end
end,
---改变窗口位置
---@param self Wnd
---@param arg int
["PosY"] = function(self, arg)
if self.Handle == nil then return end
if GUI:WndGetPosM(self.Handle) then
GUI:WndSetPosM(self.Handle, LuaRet[1], arg)
end
end,
---改变窗口 名称
---@param self Wnd
---@param Name string
["Name"] = function(self, Name)
GUI:WndSetIDM(self.Handle, Name)
end,
---设置 窗体控件是否 可见
---@param self Wnd
---@param Visible bool
["Visible"] = function(self, Visible)
GUI:WndSetVisible(self.Handle, Visible)
end,
--- 设置窗体控件的自定义参数
---@param self Wnd
---@param Param uint
["IDParam"] = function(self, Param)
GUI:WndSetIDParam(self.Handle, Param)
end,
--- 设置窗体控件的自定义参数
---@param self Wnd
---@param Param uint
["Param"] = function(self, Param)
GUI:WndSetParam(self.Handle, Param)
end,
--- 设置窗口Esc关闭属性
---@param self Wnd
---@param IsESC bool
["IsESC"] = function(self, IsESC)
GUI:WndSetIsESCClose(self.Handle, IsESC)
end,
--- 设置窗口是否可用
---@param self Wnd
---@param Enable bool
["Enable"] = function(self, Enable)
GUI:WndSetEnableM(self.Handle, Enable)
end,
--- 设置窗口是否响应操作
---@param self Wnd
---@param CanRevMsg bool
["CanRevMsg"] = function(self, CanRevMsg)
GUI:WndSetCanRevMsg(self.Handle, CanRevMsg)
end,
["MoveWithLBM"] = function(self, MoveWithLBM)
if MoveWithLBM == true then
return GUI:WndSetMoveWithLBM(self.Handle)
end
end,
["SizeX"] = function(self, SizeX)
if self.Handle == nil then return end
if GUI:WndGetSizeM(self.Handle) then
GUI:WndSetSizeM(self.Handle, SizeX or 0, LuaRet[2])
end
end,
["SizeY"] = function(self, SizeY)
if self.Handle == nil then return end
if GUI:WndGetSizeM(self.Handle) then
GUI:WndSetSizeM(self.Handle, LuaRet[1], SizeY or 0)
end
end,
["Hint"] = function(self, _HintInof)
return GUI:WndSetHint(self.Handle, _HintInof)
end,
["MagicUI"] = function(self, _Type)
if type(_Type) ~= "number" then return end
return GUI:WndSetMagicUI(self.Handle, _Type == 0 and 0 or 1)
end
}
local WndPropSetList_t = InitSetter_t(tSet_t)
local WndPropGetList_t = InitSetter_t(tSet_t)
Wnd:SetSetter(WndPropSetList_t)
Wnd:SetGetter(WndPropGetList_t)
--#endregion
--#region Wnd method
--#region 类属性
---设置类属性
---@param arg WndSetter
function Wnd:SetProp(arg)
if type(self) ~= "table" then return end
if self:GetHandle() == 0 then return end
local __set__ = self.__set__
local t
for key, value in pairs(arg) do
t = __set__[key]
if t ~= nil then
t(self, value)
end
end
end
--#endregion
---移出窗口所有子控件
function Wnd:Clear()
if type(self) ~= "table" then
CL:Log("类型不合")
return
end
if self.clsName ~= "Wnd" then
Print_f("Class: " .. self.clsName .. " be call")
return
end
GUI:WndDlgClear(self:GetHandle())
end
--#region 窗口句柄
---获取窗口句柄
---@return int
function Wnd:GetHandle()
return self.Handle
end
--- 设置对象句柄
---@param _Handle int
function Wnd:SetHandle(_Handle)
self.Handle = _Handle
end
--#endregion
---@class WndSize
---@field SizeX int
---@field SizeY int
---改变窗口大小
---@param arg WndSize
function Wnd:SetSize(arg)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndSetSizeM(WND_H, arg.SizeX or 0, arg.SizeY or 0)
end
return false
end
---改变窗口大小
---@param SizeX int
---@param SizeY int
---@return nil
function Wnd:SetWndSize(SizeX, SizeY)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndSetSizeM(WND_H, SizeX or 0, SizeY or 0)
end
return false
end
---@class WndPos
---@field PosX int
---@field PosY int
---改变窗口位置
---@param arg WndPos
function Wnd:SetPos(arg)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndSetPosM(WND_H, arg.PosX or 0, arg.PosY or 0)
end
return false
end
---设置窗口参数
---@param param int
function Wnd:SetParam(param)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndSetParam(WND_H, param or 0)
end
return false
end
---获取窗口参数
---@return integer
function Wnd:GetParam()
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndGetParam(WND_H)
end
return 0
end
---@class SetWndArg
---@field Visible bool?
---@field Enable bool? # 是否可用
---@field CanRevMsg bool? # 是否可接受消息
---@field Param int? # 设置参数
---改变窗口共有属性
---@param arg SetWndArg
function Wnd:SetWnd(arg)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if arg.Visible ~= nil then GUI:WndSetVisible(WND_H, arg.Visible) end
if arg.Enable ~= nil then GUI:WndSetEnableM(WND_H, arg.Enable) end
if arg.CanRevMsg ~= nil then GUI:WndSetCanRevMsg(WND_H, arg.CanRevMsg) end
dbg("设置窗口来源于Lazyframe")
if arg.Param ~= nil then GUI:WndSetParam(WND_H, arg.Param) end
end
--#region 自定义属性
--#region 添加
---为窗体控件添加自定义属性
---@param _Key string @ 属性名
---@param _Val string@ 属性值
function Wnd:AddProperty(_Key, _Val)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndAddProperty(WND_H, _Key, _Val)
end
return false
end
--#endregion
--#region 获取
---获取窗口自定义属性
---@param self Wnd | int
---@param _Key string @ 属性名
---@return string
function Wnd.GetProperty(self, _Key)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndGetProperty(WND_H, _Key)
end
return ""
end
--#endregion
--#region 删除
---删除窗口自定义属性
---@param self Wnd | int
---@param _Key string @ 属性名
function Wnd:DelProperty(_Key)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndDelProperty(WND_H, _Key)
end
return false
end
--#endregion
--#endregion
--#region 标记
function Wnd:SetFlags(_Flag)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndSetFlagsM(WND_H, _Flag)
end
return false
end
--#endregion
--#region 窗体回调函数
--#region 注册窗体控件的事件回调函数
--- 注册窗体控件的事件回调函数
---@param self Wnd | int
---@param _Msg int
---@param _FuncName string
---@return bool
function Wnd:AddRe(_Msg, _FuncName)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndRegistScript(WND_H, _Msg, _FuncName)
end
return false
end
---注册窗体控件的事件回调函数(扩展)
---@param _Msg int @制定窗体控件的事件ID
---@param _FuncName string @回调函数名
---@param _Param string @预设的回调参数,将传递至回调函数的第5个参数
---@return bool @true:控件存在,fasle:控件不存在
function Wnd:AddReEx(_Msg, _FuncName, _Param)
local WND_H = (type(self) == "number" and self or self:GetHandle())
if WND_H ~= 0 then
return GUI:WndRegistScriptEx(WND_H, _Msg, _FuncName, _Param)
end
return false
end
---添加左键点击函数
---@param _FuncName string
function Wnd:AddReLBClick(_FuncName)
return Wnd.AddRe(self, RDWndBaseCL_mouse_lbClick, _FuncName)
end
---添加左键点击函数Ex
---@param _FuncName string
function Wnd:AddReLBClickEx(_FuncName, cParam)
return Wnd.AddReEx(self, RDWndBaseCL_mouse_lbClick, _FuncName, cParam)
end
---添加右键点击函数
---@param _FuncName string
function Wnd:AddReRBClick(_FuncName)