Mercurial > wow > reaction
comparison classes/ReAction_PetActionDisplay.lua @ 7:f920db5fc6b1
version 0.3
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Tue, 20 Mar 2007 21:25:29 +0000 |
parents | |
children | c05fd3e18b4f |
comparison
equal
deleted
inserted
replaced
6:2da5089ab7ff | 7:f920db5fc6b1 |
---|---|
1 -- The ReAction.PetActionDisplay mixin defines 'regular' action button display functionality | |
2 -- and is an implementation of the ReAction.IDisplay and ReAction.ActionType.IDisplay interfaces. | |
3 -- | |
4 -- This Mixin assumes that it has been mixed in with a ReAction-derived class which implements | |
5 -- the ReAction.IActionType and ReAction.IColorScheme interfaces. | |
6 -- | |
7 -- This mixin uses properties of self.config to define display elements: | |
8 -- | |
9 -- self.config = { | |
10 -- keyBindLoc = "POSITION", -- keybind anchor location | |
11 -- showKeyBind = true/false, -- show keybind labels | |
12 -- showGrid = true/false, -- always show empty buttons | |
13 -- } | |
14 -- | |
15 | |
16 local AceOO = AceLibrary("AceOO-2.0") | |
17 | |
18 ReAction.PetActionDisplay = AceOO.Mixin { | |
19 -- ReAction.IDisplay interface | |
20 "SetupDisplay", | |
21 "UpdateDisplay", | |
22 "TempShow", | |
23 "GetActionFrame", | |
24 "GetBaseButtonSize", | |
25 "DisplayID", | |
26 "DisplayHotkey", | |
27 | |
28 -- ReAction.PetActionType.IDisplay interface | |
29 "DisplayAutoCast", | |
30 "DisplayAutoCastable", | |
31 "DisplayInUse", | |
32 "DisplayUsable", | |
33 "DisplayIcon", | |
34 "DisplayCooldown", | |
35 | |
36 -- Event handlers | |
37 "PreClick", | |
38 "PostClick", | |
39 "OnDragStart", | |
40 "OnReceiveDrag", | |
41 "OnEnter", | |
42 "OnLeave", | |
43 | |
44 -- internal functions | |
45 "ApplyLayout", | |
46 "ApplyStyle", | |
47 "DisplayVisibility", | |
48 } | |
49 | |
50 local RAPAD = ReAction.PetActionDisplay | |
51 | |
52 | |
53 -- private constants | |
54 local _G = getfenv(0) | |
55 | |
56 local actionIDColor = { r=1.00, g=0.82, b=0.00, a=1.00 } -- gold | |
57 | |
58 | |
59 -- private functions | |
60 -- extract and return color fields from a table, to be fed into SetVertexColor()/SetTextColor() | |
61 local function tcolor(c) | |
62 return c.r, c.g, c.b, c.a | |
63 end | |
64 | |
65 | |
66 ----------------------------------- | |
67 -- Interface Implementation Methods | |
68 ----------------------------------- | |
69 function RAPAD:SetupDisplay( name ) | |
70 -- create the button widget | |
71 local b = CreateFrame("CheckButton", name, nil, "ActionButtonTemplate, SecureActionButtonTemplate") | |
72 b:EnableMouse() | |
73 b:RegisterForDrag("LeftButton", "RightButton") | |
74 b:RegisterForClicks("AnyUp") | |
75 b:SetScript("PreClick", function(arg1) self:PreClick(arg1) end) | |
76 b:SetScript("PostClick", function(arg1) self:PostClick(arg1) end) | |
77 b:SetScript("OnDragStart", function(arg1) self:OnDragStart(arg1) end) | |
78 b:SetScript("OnReceiveDrag", function() self:OnReceiveDrag() end) | |
79 b:SetScript("OnEnter", function() self:OnEnter() end) | |
80 b:SetScript("OnLeave", function() self:OnLeave() end) | |
81 | |
82 | |
83 b:SetWidth(30) | |
84 b:SetHeight(30) | |
85 | |
86 local tx = b:GetNormalTexture() | |
87 tx:ClearAllPoints() | |
88 tx:SetWidth(54) | |
89 tx:SetHeight(54) | |
90 tx:SetPoint("CENTER",0,-1) | |
91 | |
92 local autoCastable = b:CreateTexture(nil, "OVERLAY") | |
93 autoCastable:SetTexture("Interface\\Buttons\\UI-AutoCastableOverlay") | |
94 autoCastable:SetWidth(58) | |
95 autoCastable:SetHeight(58) | |
96 autoCastable:SetPoint("CENTER") | |
97 autoCastable:Hide() | |
98 | |
99 local autoCast = CreateFrame("Model",nil,b) | |
100 autoCast:SetModel("Interface\\Buttons\\UI-AutoCastButton.mdx") | |
101 autoCast:SetScale(1.2) | |
102 autoCast:SetAllPoints() | |
103 autoCast:SetSequence(0) | |
104 autoCast:SetSequenceTime(0,0) | |
105 autoCast:SetFrameStrata("HIGH") -- Otherwise it won't appear on top of the icon for some reason | |
106 autoCast:Hide() | |
107 | |
108 | |
109 local cd = _G[name.."Cooldown"] | |
110 cd:SetScale(1); | |
111 cd:ClearAllPoints(); | |
112 cd:SetWidth(33); | |
113 cd:SetHeight(33); | |
114 cd:SetPoint("CENTER", -2, -1); | |
115 | |
116 -- store references to the various sub-frames of ActionButtonTemplate so we don't have to look it up all the time | |
117 self.frames = { | |
118 button = b, | |
119 autoCastable = autoCastable, --_G[name.."AutoCastable"], | |
120 autoCast = autoCast, --_G[name.."AutoCast"], | |
121 hotkey = _G[name.."HotKey"], | |
122 cooldown = cd, | |
123 icon = _G[name.."Icon"], | |
124 normalTexture = tx, --_G[name.."NormalTexture2"], | |
125 actionID = nil, -- defer creating actionID font string until it's actually requested | |
126 } | |
127 | |
128 self.tmpShow_ = 0 | |
129 end | |
130 | |
131 function RAPAD:UpdateDisplay() | |
132 self:ApplyLayout() | |
133 self:ApplyStyle() | |
134 self:DisplayVisibility() | |
135 -- refresh the action ID display | |
136 if ReAction.showIDs_ then | |
137 self:DisplayID(self:GetID()) | |
138 end | |
139 end | |
140 | |
141 function RAPAD:TempShow( visible ) | |
142 visible = visible and true or false -- force data integrity | |
143 self.showTmp_ = max(0, (self.showTmp_ or 0) + (visible and 1 or -1)) | |
144 self:DisplayVisibility() | |
145 end | |
146 | |
147 function RAPAD:GetActionFrame() | |
148 return self.frames.button | |
149 end | |
150 | |
151 function RAPAD:GetBaseButtonSize() | |
152 return 30 | |
153 end | |
154 | |
155 function RAPAD:DisplayID( id ) | |
156 local f = self.frames.actionID | |
157 if id then | |
158 if not f then | |
159 -- create the actionID label | |
160 f = self.frames.button:CreateFontString(nil,"ARTWORK","NumberFontNormalSmall") | |
161 f:SetPoint("BOTTOMLEFT") | |
162 f:SetTextColor( tcolor(actionIDColor) ) | |
163 self.frames.actionID = f | |
164 end | |
165 f:SetText(tostring(id)) | |
166 f:Show() | |
167 elseif f then | |
168 f:Hide() | |
169 end | |
170 end | |
171 | |
172 function RAPAD:DisplayHotkey(txt) | |
173 self.frames.hotkey:SetText(string.upper(txt or "")) | |
174 end | |
175 | |
176 function RAPAD:DisplayInUse( inUse ) | |
177 self.frames.button:SetChecked( inUse and 1 or 0 ) | |
178 end | |
179 | |
180 function RAPAD:DisplayUsable( usable ) | |
181 SetDesaturation(self.frames.icon, (not usable) and 1 or nil) -- argument is backward | |
182 self.frames.hotkey:SetTextColor(self:GetHotkeyColor(usable, false, false, self.frames.hotkey:GetText()) ) | |
183 end | |
184 | |
185 function RAPAD:DisplayAutoCast( show ) | |
186 if show then | |
187 self.frames.autoCast:Show() | |
188 else | |
189 self.frames.autoCast:Hide() | |
190 end | |
191 end | |
192 | |
193 function RAPAD:DisplayAutoCastable( show ) | |
194 if show then | |
195 self.frames.autoCastable:Show() | |
196 else | |
197 self.frames.autoCastable:Hide() | |
198 end | |
199 end | |
200 | |
201 function RAPAD:DisplayIcon( texture ) | |
202 local f = self.frames.button | |
203 local icon = self.frames.icon | |
204 if texture then | |
205 icon:SetTexture(texture) | |
206 icon:Show() | |
207 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2") | |
208 else | |
209 f:SetScript("OnUpdate",nil) | |
210 icon:Hide() | |
211 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot") | |
212 end | |
213 self:DisplayVisibility() | |
214 end | |
215 | |
216 function RAPAD:DisplayCooldown( start, duration, enable ) | |
217 CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enable) | |
218 end | |
219 | |
220 | |
221 | |
222 | |
223 | |
224 | |
225 ---------------------- | |
226 -- Event Handlers | |
227 ---------------------- | |
228 function RAPAD:PreClick() | |
229 -- not sure why we have to do this | |
230 self.frames.button:SetChecked(0) | |
231 end | |
232 | |
233 function RAPAD:PostClick() | |
234 self:UpdateAction() | |
235 end | |
236 | |
237 function RAPAD:OnDragStart() | |
238 if LOCK_ACTIONBAR ~= "1" or IsShiftKeyDown() then | |
239 self:PickupAction() | |
240 end | |
241 end | |
242 | |
243 function RAPAD:OnReceiveDrag() | |
244 self:PlaceAction() | |
245 end | |
246 | |
247 function RAPAD:OnEnter() | |
248 self:SetTooltip() -- from ReAction base class | |
249 end | |
250 | |
251 function RAPAD:OnLeave() | |
252 self:ClearTooltip() -- from ReAction base class | |
253 end | |
254 | |
255 | |
256 | |
257 ---------------------- | |
258 -- Internal methods | |
259 ---------------------- | |
260 | |
261 local function placeLabel( label, anchor ) | |
262 local top = string.match(anchor,"TOP") | |
263 local bottom = string.match(anchor, "BOTTOM") | |
264 label:ClearAllPoints() | |
265 label:SetWidth(40) | |
266 label:SetPoint(top or bottom,0,top and 2 or -2) | |
267 local j | |
268 if string.match(anchor,"LEFT") then | |
269 j = "LEFT" | |
270 elseif string.match(anchor,"RIGHT") then | |
271 j = "RIGHT" | |
272 else | |
273 j = "CENTER" | |
274 end | |
275 label:SetJustifyH(j) | |
276 end | |
277 | |
278 | |
279 function RAPAD:ApplyLayout() | |
280 local f = self.frames | |
281 | |
282 if self.config.keyBindLoc then | |
283 placeLabel(f.hotkey, self.config.keyBindLoc) | |
284 end | |
285 | |
286 if self.config.showKeyBind then | |
287 f.hotkey:Show() | |
288 else | |
289 f.hotkey:Hide() | |
290 end | |
291 | |
292 if self.config.showBorder then | |
293 f.normalTexture:SetAlpha(1) | |
294 else | |
295 f.normalTexture:SetAlpha(0) | |
296 end | |
297 end | |
298 | |
299 function RAPAD:ApplyStyle() | |
300 | |
301 end | |
302 | |
303 function RAPAD:DisplayVisibility() | |
304 local b = self.frames.button | |
305 | |
306 -- can't hide/show in combat | |
307 if not InCombatLockdown() then | |
308 if b:GetAttribute("statehidden") then | |
309 b:Hide() | |
310 elseif not self:IsActionEmpty() then | |
311 b:GetNormalTexture():SetAlpha(1.0) | |
312 b:Show() | |
313 elseif self.showTmp_ and self.showTmp_ > 0 or self.config.showGrid then | |
314 b:GetNormalTexture():SetAlpha(0.5) | |
315 self.frames.cooldown:Hide() | |
316 b:Show() | |
317 else | |
318 b:Hide() | |
319 end | |
320 end | |
321 end | |
322 |