1 QuestHelper
.used_tables
= 0
2 QuestHelper
.free_tables
= {}
4 QuestHelper
.used_textures
= 0
5 QuestHelper
.free_textures
= {}
7 QuestHelper
.used_text
= 0
8 QuestHelper
.free_text
= {}
10 QuestHelper
.used_frames
= 0
11 QuestHelper
.free_frames
= {}
13 function QuestHelper
:CreateTable()
14 self
.used_tables
= self
.used_tables
+ 1
15 return table.remove(self
.free_tables
) or {}
18 function QuestHelper
:ReleaseTable(tbl
)
19 assert(type(tbl
) == "table")
20 for i
,t
in ipairs(self
.free_tables
) do assert(t
~= tbl
) end
22 for key
in pairs(tbl
) do
26 self
.used_tables
= self
.used_tables
- 1
27 table.insert(self
.free_tables
, tbl
)
30 function QuestHelper
:CreateFrame(parent
)
31 self
.used_frames
= self
.used_frames
+ 1
32 local frame
= table.remove(self
.free_frames
)
35 frame
:SetParent(parent
)
37 frame
= CreateFrame("Button", string.format("QuestHelperFrame%d",self
.used_frames
), parent
)
40 frame
:SetFrameLevel((parent
or UIParent
):GetFrameLevel()+1)
41 frame
:SetFrameStrata("MEDIUM")
72 function QuestHelper
:ReleaseFrame(frame
)
73 assert(type(frame
) == "table")
74 for i
,t
in ipairs(self
.free_frames
) do assert(t
~= frame
) end
76 for key
in pairs(frame
) do
77 -- Remove all keys except 0, which seems to hold some special data.
83 for i
, script
in ipairs(frameScripts
) do
84 frame
:SetScript(script
, nil)
89 frame
:ClearAllPoints()
90 frame
:SetMovable(false)
91 frame
:RegisterForDrag()
92 frame
:RegisterForClicks()
96 self
.used_frames
= self
.used_frames
- 1
97 table.insert(self
.free_frames
, frame
)
100 function QuestHelper
:CreateText(parent
, text_str
, text_size
, text_font
, r
, g
, b
, a
)
101 self
.used_text
= self
.used_text
+ 1
102 local text
= table.remove(self
.free_text
)
105 text
:SetParent(parent
)
107 text
= parent
:CreateFontString()
110 text
:SetFont(text_font
or QuestHelper
.font
.sans
or ChatFontNormal
:GetFont(), text_size
or 12)
111 text
:SetDrawLayer("OVERLAY")
112 text
:SetJustifyH("CENTER")
113 text
:SetJustifyV("MIDDLE")
114 text
:SetTextColor(r
or 1, g
or 1, b
or 1, a
or 1)
115 text
:SetText(text_str
or "")
116 text
:SetShadowColor(0, 0, 0, 0.3)
117 text
:SetShadowOffset(1, -1)
123 function QuestHelper
:ReleaseText(text
)
124 assert(type(text
) == "table")
125 for i
,t
in ipairs(self
.free_text
) do assert(t
~= text
) end
127 for key
in pairs(text
) do
128 -- Remove all keys except 0, which seems to hold some special data.
136 text
:ClearAllPoints()
137 self
.used_text
= self
.used_text
- 1
138 table.insert(self
.free_text
, text
)
141 function QuestHelper
:CreateTexture(parent
, r
, g
, b
, a
)
142 self
.used_textures
= self
.used_textures
+ 1
143 local tex
= table.remove(self
.free_textures
)
146 tex
:SetParent(parent
)
148 tex
= parent
:CreateTexture()
151 if not tex
:SetTexture(r
, g
, b
, a
) and
152 not tex
:SetTexture("Interface\\Icons\\Temp.blp") then
153 tex
:SetTexture(1, 0, 1, 0.5)
157 tex
:SetTexCoord(0, 1, 0, 1)
158 tex
:SetVertexColor(1, 1, 1, 1)
159 tex
:SetDrawLayer("ARTWORK")
160 tex
:SetBlendMode("BLEND")
168 function QuestHelper
:CreateIconTexture(parent
, id
)
169 local icon
= self
:CreateTexture(parent
, "Interface\\AddOns\\QuestHelper\\Art\\Icons.tga")
171 local w
, h
= 1/8, 1/8
172 local x
, y
= ((id
-1)%8)*w
, math
.floor((id
-1)/8)*h
174 icon
:SetTexCoord(x
, x
+w
, y
, y
+h
)
179 function QuestHelper
:CreateDotTexture(parent
)
180 local icon
= self
:CreateIconTexture(parent
, 13)
183 icon
:SetVertexColor(0, 0, 0, 0.35)
187 function QuestHelper
:CreateGlowTexture(parent
)
188 local tex
= self
:CreateTexture(parent
, "Interface\\Addons\\QuestHelper\\Art\\Glow.tga")
190 local angle
= math
.random()*6.28318530717958647692528676655900576839433879875021164
191 local x
, y
= math
.cos(angle
)*0.707106781186547524400844362104849039284835937688474036588339869,
192 math
.sin(angle
)*0.707106781186547524400844362104849039284835937688474036588339869
194 -- Randomly rotate the texture, so they don't all look the same.
195 tex
:SetTexCoord(x
+0.5, y
+0.5, y
+0.5, 0.5-x
, 0.5-y
, x
+0.5, 0.5-x
, 0.5-y
)
201 function QuestHelper
:ReleaseTexture(tex
)
202 assert(type(tex
) == "table")
203 for i
,t
in ipairs(self
.free_textures
) do assert(t
~= tex
) end
205 for key
in pairs(tex
) do
206 -- Remove all keys except 0, which seems to hold some special data.
215 self
.used_textures
= self
.used_textures
- 1
216 table.insert(self
.free_textures
, tex
)