Back to Home

ESO Lua File v100032

libraries/zo_templates/objectpooltemplates.lua

[◄ back to folders ]
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
--[[
Animation Pool
--]]
ZO_AnimationPool = ZO_ObjectPool:Subclass()
do
    local function Reset(animation, pool)
        animation:Stop()
        if pool.customResetBehavior then
            pool.customResetBehavior(animation)
        end
    end
    function ZO_AnimationPool:New(templateName)
        local function AnimationFactory(pool)
            local timeline = ANIMATION_MANAGER:CreateTimelineFromVirtual(templateName)
            if pool.customFactoryBehavior then
                pool.customFactoryBehavior(timeline)
            end
            return timeline
        end
        return ZO_ObjectPool.New(self, AnimationFactory, Reset)
    end
end
function ZO_AnimationPool:SetCustomResetBehavior(customResetBehavior)
end
function ZO_AnimationPool:SetCustomFactoryBehavior(customFactoryBehavior)
end
--[[
Control Pool
--]]
ZO_ControlPool = ZO_ObjectPool:Subclass()
local function ControlFactory(pool, objectKey)
    local control = ZO_ObjectPool_CreateNamedControl(pool.name, pool.templateName, pool, pool.parent)
    if pool.customFactoryBehavior then
        pool.customFactoryBehavior(control, objectKey)
    end
    return control
end
local function ControlReset(control, pool)
    control:SetHidden(true)
    if pool.customResetBehavior then
        pool.customResetBehavior(control)
    end
end
function ZO_ControlPool:New(templateName, parent, overrideName)
    local pool = ZO_ObjectPool.New(self, ControlFactory, ControlReset)
    local controlName = overrideName or templateName
    if parent then
        controlName = parent:GetName() .. controlName
    else
        parent = GuiRoot
    end
    pool.name = controlName
    pool.parent = parent
    pool.templateName = templateName
    return pool
end
end
function ZO_ControlPool:SetCustomResetBehavior(customResetBehavior)
end
function ZO_ControlPool:AcquireObject(objectKey)
    local control, key = ZO_ObjectPool.AcquireObject(self, objectKey)
    if control then
        control:SetHidden(false)
    end
    return control, key
end
--[[
Meta Pool
]]
--
ZO_MetaPool = ZO_Object:Subclass()
function ZO_MetaPool:New(sourcePool)
    local pool = ZO_Object.New(self)
    pool.sourcePool = sourcePool
    pool.activeObjects = {}
    return pool
end
function ZO_MetaPool:AcquireObject()
    local object, key = self.sourcePool:AcquireObject()
    self.activeObjects[key] = object
    if self.customAcquireBehavior then
        self.customAcquireBehavior(object)
    end
    return object, key
end
function ZO_MetaPool:GetActiveObject(objectKey)
    return self.activeObjects[objectKey]
end
function ZO_MetaPool:GetActiveObjectCount()
    return NonContiguousCount(self.activeObjects)
end
function ZO_MetaPool:HasActiveObjects()
    return next(self.activeObjects) ~= nil
end
function ZO_MetaPool:GetActiveObjects()
    return self.activeObjects
end
function ZO_MetaPool:ActiveObjectIterator(filterFunctions)
    return ZO_FilteredNonContiguousTableIterator(self.activeObjects, filterFunctions)
end
function ZO_MetaPool:ReleaseAllObjects()
    for key, object in pairs(self.activeObjects) do
        if self.customResetBehavior then
            self.customResetBehavior(object)
        end
        self.sourcePool:ReleaseObject(key)
    end
    ZO_ClearTable(self.activeObjects)
end
function ZO_MetaPool:ReleaseObject(objectKey)
    local object = self.activeObjects[objectKey]
    if self.customResetBehavior then
        self.customResetBehavior(object)
    end
    self.sourcePool:ReleaseObject(objectKey)
    self.activeObjects[objectKey] = nil
end
end
function ZO_MetaPool:SetCustomResetBehavior(customeResetBehavior)
    self.customResetBehavior = customeResetBehavior
end