-
Notifications
You must be signed in to change notification settings - Fork 0
/
SezzUnitFrame.lua
284 lines (228 loc) · 7.84 KB
/
SezzUnitFrame.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
--[[
s:UI Unit Frame
TODO:
Interrupt Armor
Power Bar
Remove the layout code
Events:
local tRewardUpdateEvents = {
"QuestObjectiveUpdated", "QuestStateChanged", "ChallengeAbandon", "ChallengeLeftArea",
"ChallengeFailTime", "ChallengeFailArea", "ChallengeActivate", "ChallengeCompleted",
"ChallengeFailGeneric", "PublicEventObjectiveUpdate", "PublicEventUnitUpdate",
"PlayerPathMissionUpdate", "FriendshipAdd", "FriendshipPostRemove", "FriendshipUpdate"
}
Martin Karer / Sezz, 2014
http://www.sezz.at
--]]
local MAJOR, MINOR = "Sezz:UnitFrame-0.2", 1;
local APkg = Apollo.GetPackage(MAJOR);
if (APkg and (APkg.nVersion or 0) >= MINOR) then return; end
local UnitFrame = APkg and APkg.tPackage or {};
local log, ToolTips, GeminiGUI, UnitFrameController;
-----------------------------------------------------------------------------
-- Tags
-----------------------------------------------------------------------------
local EnableTags = function(self)
if (#self.tTagControls == 0 and self.tControls.Text) then
for _, wndControl in ipairs(self.tControls.Text) do
self:Tag(wndControl, wndControl:GetData());
end
end
end
local UpdateTags = function(self)
for _, tControl in ipairs(self.tTagControls) do
tControl:UpdateTag();
end
end
local DisableTags = function(self)
for _, tControl in ipairs(self.tTagControls) do
self:Untag(tControl);
end
end
-----------------------------------------------------------------------------
-- Handle Mouse Clicks
-----------------------------------------------------------------------------
local OnMouseClick = function(self, wndHandler, wndControl, eMouseButton, x, y)
if (wndHandler ~= wndControl) then return; end
if (eMouseButton == GameLib.CodeEnumInputMouse.Left) then
if (self.unit.__proto__) then
GameLib.SetTargetUnit(self.unit.__proto__);
end
return false;
elseif (eMouseButton == GameLib.CodeEnumInputMouse.Right) then
-- Right Click
Event_FireGenericEvent("GenericEvent_NewContextMenuPlayerDetailed", nil, self.unit:GetName(), self.unit.__proto__ or self.unit);
return true;
end
return false;
end
------------------------------------------------------------------------------
-- Unit Tooltips
-----------------------------------------------------------------------------
function UnitFrame:OnGenerateTooltip()
ToolTips:UnitTooltipGen(self.wndMain, self.unit.__proto__ or self.unit, "");
end
-----------------------------------------------------------------------------
-- Elements
-----------------------------------------------------------------------------
function UnitFrame:RegisterElement(tElement)
local tElement = tElement:New(self);
if (tElement) then
table.insert(self.tElements, tElement);
end
end
local UpdateElements = function(self)
if (not self.bEnabled) then return; end
for _, tElement in ipairs(self.tElements) do
if (tElement.bUpdateOnUnitFrameFrameCount) then
tElement:Update();
end
end
end
local EnableElements = function(self)
for _, tElement in ipairs(self.tElements) do
tElement:Enable();
end
end
local DisableElements = function(self)
for _, tElement in ipairs(self.tElements) do
tElement:Disable();
end
end
----------------------------------------------------------------------------
-- Units
-----------------------------------------------------------------------------
local Update = function(self)
UpdateElements(self);
end
local Disable = function(self)
self:Hide();
DisableElements(self);
DisableTags(self);
self.unit = nil;
self.bEnabled = false;
end
local Enable = function(self)
self.bEnabled = true;
EnableElements(self);
EnableTags(self);
UpdateTags(self);
Update(self);
self.wndMain:SetTooltip("");
self:Show();
end
local SetUnit = function(self, unit)
-- Invalid Unit
if (not unit or (unit and not unit:IsValid())) then
-- log:debug("[%s] Unit Invalid!", self.strUnit);
self:Disable();
return false;
end
-- Update Unit
if (not self.unit or (self.unit and self.unit:GetId() ~= unit:GetId())) then
-- log:debug("[%s] Updated Unit: %s", self.strUnit, unit:GetName());
self.unit = unit;
self:Enable();
elseif (self.unit and not self.unit:IsRealUnit() and self.unit.bUpdated) then
-- GroupLib Unit, Enable/Update
if (not self.bEnabled) then
self:Enable();
else
self:Update();
end
elseif (self.unit and self.unit.nMemberIdx and self.unit:IsRealUnit() and self.unit:GetId() == unit:GetId()) then
-- Update Unit Reference (in case tFlags changed, should only affect "Player" an other non-raid/non-group units)
-- TODO: Add those units to UnitWrapper Cache?
self.unit = unit;
end
end
-----------------------------------------------------------------------------
-- Forms
-----------------------------------------------------------------------------
local FindElementControls;
FindElementControls = function(wndControl, tControls)
local tData = wndControl:GetData();
if (tData and type(tData) == "table" and tData.Element) then
if (tData.Element == "Text" and not tControls.Text) then
tControls.Text = {};
end
if (tControls[tData.Element]) then
assert(tData.Element == "Text", string.format("Adding multiple elements of type %s is not supported!", tData.Element));
table.insert(tControls[tData.Element], wndControl);
else
tControls[tData.Element] = wndControl;
end
end
for _, wndChild in ipairs(wndControl:GetChildren()) do
tControls = FindElementControls(wndChild, tControls);
end
return tControls;
end
local Spawn = function(self)
-- Create Window
self.wndMain = self.tPrototype:GetInstance(self);
self.tControls = FindElementControls(self.wndMain, {});
self.wndMain:Show(false, true);
-- Enable OnClick Handler (Targetting)
self.wndMain:AddEventHandler("MouseButtonDown", "OnMouseClick", self);
-- Enable Unit Tooltips
if (ToolTips) then
self.wndMain:AddEventHandler("GenerateTooltip", "OnGenerateTooltip", self);
end
-- Return
return self.wndMain;
end
local Show = function(self)
self.wndMain:Show(true, true);
end
local Hide = function(self)
self.wndMain:Show(false, true);
end
-----------------------------------------------------------------------------
-- Constructor
-----------------------------------------------------------------------------
function UnitFrame:New(tUnitFrameController, strUnit, tWindowDefinition)
self = setmetatable({}, { __index = UnitFrame });
-- Properties
self.tPrototype = GeminiGUI:Create(tWindowDefinition);
self.strUnit = strUnit;
self.bEnabled = false;
self.tElements = {};
self.tColors = setmetatable(self.tColors or {}, { __index = tUnitFrameController.tColors });
-- Tags
self.tTagControls = {};
self.Tag = tUnitFrameController.Tag;
self.Untag = tUnitFrameController.Untag;
-- Expose Methods
self.Spawn = Spawn;
self.OnMouseClick = OnMouseClick;
self.Show = Show;
self.Hide = Hide;
self.SetUnit = SetUnit;
self.Enable = Enable;
self.Disable = Disable;
self.Update = Update;
-- Done
return self;
end
-----------------------------------------------------------------------------
function UnitFrame:OnLoad()
local GeminiLogging = Apollo.GetPackage("Gemini:Logging-1.2") and Apollo.GetAddon("GeminiConsole") and Apollo.GetPackage("Gemini:Logging-1.2").tPackage;
if (GeminiLogging) then
log = GeminiLogging:GetLogger({
level = GeminiLogging.DEBUG,
pattern = "%d %n %c %l - %m",
appender ="GeminiConsole"
});
else
log = setmetatable({}, { __index = function() return function(self, ...) local args = #{...}; if (args > 1) then Print(string.format(...)); elseif (args == 1) then Print(tostring(...)); end; end; end });
end
ToolTips = Apollo.GetAddon("ToolTips");
GeminiGUI = Apollo.GetPackage("Gemini:GUI-1.0").tPackage;
UnitFrameController = Apollo.GetPackage("Sezz:UnitFrameController-0.2").tPackage;
end
function UnitFrame:OnDependencyError(strDep, strError)
return false;
end
-----------------------------------------------------------------------------
Apollo.RegisterPackage(UnitFrame, MAJOR, MINOR, { "Gemini:GUI-1.0" });