forked from LoneGazebo/Community-Patch-DLL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPK.UI.ControlPool.Simple.lua
More file actions
120 lines (92 loc) · 2.16 KB
/
CPK.UI.ControlPool.Simple.lua
File metadata and controls
120 lines (92 loc) · 2.16 KB
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
local lua_setmetatable = setmetatable
local lua_next = next
--- @class SimpleControlPool
--- @field protected instName string
--- @field protected rootName string
--- @field protected parent Control
--- @field protected free table<Control, boolean>
--- @field protected used table<Control, boolean>
local SimpleControlPoolImpl = {}
--- @return Control
function SimpleControlPoolImpl:AcquireOne()
local inst = lua_next(self.free)
if inst then
self.free[inst] = nil
self.used[inst] = true
inst:SetHide(true)
return inst
end
inst = ContextPtr:BuildInstanceForControl(
self.instName,
self.rootName,
self.parent
)
inst:SetHide(true)
self.used[inst] = true
return inst
end
--- @param inst Control
function SimpleControlPoolImpl:RecycleOne(inst)
if not self.used[inst] then
return
end
inst:SetHide(true)
self.used[inst] = nil
self.free[inst] = true
end
--- comment
function SimpleControlPoolImpl:RecycleAll()
local used = self.used
local free = self.free
for inst in lua_next, used do
inst:SetHide(true)
used[inst] = nil
free[inst] = true
end
end
--- comment
--- @param inst Control
function SimpleControlPoolImpl:DestroyOne(inst)
if self.used[inst] then
self.used[inst] = nil
elseif self.free[inst] then
self.free[inst] = nil
else
return
end
inst:SetHide(true)
self.parent:DestroyChild(inst)
end
--- comment
function SimpleControlPoolImpl:DestroyAll()
local free = self.free
local used = self.used
local parent = self.parent
for inst in lua_next, used do
inst:SetHide(true)
used[inst] = nil
parent:DestroyChild(inst)
end
for inst in lua_next, free do
inst:SetHide(true)
free[inst] = nil
parent:DestroyChild(inst)
end
end
local SimpleControlPoolMeta = {}
SimpleControlPoolMeta.__index = SimpleControlPoolImpl
--- @param instName string
--- @param rootName string
--- @param parent Control | nil
--- @return SimpleControlPool
function SimpleControlPoolMeta.New(instName, rootName, parent)
local this = {
instName = instName,
rootName = rootName,
parent = parent or ContextPtr,
free = {},
used = {},
}
return lua_setmetatable(this, SimpleControlPoolMeta)
end
CPK.UI.ControlPool.Simple = SimpleControlPoolMeta