annotate classes/ReAction_ActionDisplay.lua @ 7:f920db5fc6b1

version 0.3
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:25:29 +0000
parents
children c05fd3e18b4f
rev   line source
flickerstreak@7 1 -- The ReAction.ActionDisplay mixin defines 'regular' action button display functionality
flickerstreak@7 2 -- and is an implementation of the ReAction.IDisplay and ReAction.ActionType.IDisplay interfaces.
flickerstreak@7 3 --
flickerstreak@7 4 -- This Mixin assumes that it has been mixed in with a ReAction-derived class which implements
flickerstreak@7 5 -- the ReAction.IActionType and ReAction.IColorScheme interfaces.
flickerstreak@7 6 --
flickerstreak@7 7 -- This mixin uses properties of self.config to define display elements:
flickerstreak@7 8 --
flickerstreak@7 9 -- self.config = {
flickerstreak@7 10 -- keyBindLoc = "POSITION", -- keybind anchor location
flickerstreak@7 11 -- stackCountLoc = "POSITION", -- stack count anchor location
flickerstreak@7 12 -- showKeyBind = true/false, -- show keybind labels
flickerstreak@7 13 -- showStackCount = true/false, -- show stack count labels
flickerstreak@7 14 -- showMacroText = true/false, -- show macro name labels
flickerstreak@7 15 -- showGrid = true/false, -- always show empty buttons
flickerstreak@7 16 -- }
flickerstreak@7 17 --
flickerstreak@7 18
flickerstreak@7 19 local AceOO = AceLibrary("AceOO-2.0")
flickerstreak@7 20
flickerstreak@7 21 ReAction.ActionDisplay = AceOO.Mixin {
flickerstreak@7 22 -- ReAction.IDisplay interface
flickerstreak@7 23 "SetupDisplay",
flickerstreak@7 24 "UpdateDisplay",
flickerstreak@7 25 "TempShow",
flickerstreak@7 26 "GetActionFrame",
flickerstreak@7 27 "GetBaseButtonSize",
flickerstreak@7 28 "DisplayID",
flickerstreak@7 29 "DisplayHotkey",
flickerstreak@7 30
flickerstreak@7 31 -- ReAction.ActionType.IDisplay interface
flickerstreak@7 32 "DisplayUsable",
flickerstreak@7 33 "DisplayEquipped",
flickerstreak@7 34 "DisplayAutoRepeat",
flickerstreak@7 35 "DisplayInUse",
flickerstreak@7 36 "DisplayIcon",
flickerstreak@7 37 "DisplayName",
flickerstreak@7 38 "DisplayCount",
flickerstreak@7 39 "DisplayCooldown",
flickerstreak@7 40
flickerstreak@7 41 -- Event handlers
flickerstreak@7 42 "PostClick",
flickerstreak@7 43 "OnDragStart",
flickerstreak@7 44 "OnReceiveDrag",
flickerstreak@7 45 "OnEnter",
flickerstreak@7 46 "OnLeave",
flickerstreak@7 47 "OnUpdate",
flickerstreak@7 48
flickerstreak@7 49 -- internal functions
flickerstreak@7 50 "ApplyLayout",
flickerstreak@7 51 "ApplyStyle",
flickerstreak@7 52 "StartFlash",
flickerstreak@7 53 "StopFlash",
flickerstreak@7 54 "IsFlashing",
flickerstreak@7 55 "DisplayVisibility",
flickerstreak@7 56 }
flickerstreak@7 57
flickerstreak@7 58 local RAAD = ReAction.ActionDisplay
flickerstreak@7 59
flickerstreak@7 60
flickerstreak@7 61 -- private constants
flickerstreak@7 62 local _G = getfenv(0)
flickerstreak@7 63
flickerstreak@7 64 local equippedActionBorderColor = { r=0.00, g=1.00, b=0.00, a=0.35 } -- transparent green
flickerstreak@7 65 local actionIDColor = { r=1.00, g=0.82, b=0.00, a=1.00 } -- gold
flickerstreak@7 66
flickerstreak@7 67 -- private functions
flickerstreak@7 68 -- extract and return color fields from a table, to be fed into SetVertexColor()/SetTextColor()
flickerstreak@7 69 local function tcolor(c)
flickerstreak@7 70 return c.r, c.g, c.b, c.a
flickerstreak@7 71 end
flickerstreak@7 72
flickerstreak@7 73
flickerstreak@7 74 -----------------------------------
flickerstreak@7 75 -- Interface Implementation Methods
flickerstreak@7 76 -----------------------------------
flickerstreak@7 77 function RAAD:SetupDisplay( name )
flickerstreak@7 78 -- create the button widget
flickerstreak@7 79 local b = CreateFrame("CheckButton", name, nil, "SecureActionButtonTemplate, ActionButtonTemplate")
flickerstreak@7 80
flickerstreak@7 81 -- store references to the various sub-frames of ActionButtonTemplate so we don't have to look it up all the time
flickerstreak@7 82 self.frames = {
flickerstreak@7 83 button = b,
flickerstreak@7 84 hotkey = _G[name.."HotKey"],
flickerstreak@7 85 count = _G[name.."Count"],
flickerstreak@7 86 cooldown = _G[name.."Cooldown"],
flickerstreak@7 87 macro = _G[name.."Name"],
flickerstreak@7 88 icon = _G[name.."Icon"],
flickerstreak@7 89 border = _G[name.."Border"],
flickerstreak@7 90 flash = _G[name.."Flash"],
flickerstreak@7 91 normalTexture = _G[name.."NormalTexture"],
flickerstreak@7 92 actionID = nil, -- defer creating actionID font string until it's actually requested
flickerstreak@7 93 }
flickerstreak@7 94
flickerstreak@7 95 -- ??? odd: why do we have to increment the cooldown frame level to get it to show?
flickerstreak@7 96 -- (otherwise it's behind the icon). The default UI doesn't have to (or at least I can't
flickerstreak@7 97 -- find where it does) but for some reason we have to here.
flickerstreak@7 98 self.frames.cooldown:SetFrameLevel(self.frames.cooldown:GetFrameLevel() + 1)
flickerstreak@7 99
flickerstreak@7 100 b:EnableMouse()
flickerstreak@7 101 b:RegisterForDrag("LeftButton", "RightButton")
flickerstreak@7 102 b:RegisterForClicks("AnyUp")
flickerstreak@7 103 b:SetScript("PostClick", function(arg1) self:PostClick(arg1) end)
flickerstreak@7 104 b:SetScript("OnDragStart", function(arg1) self:OnDragStart(arg1) end)
flickerstreak@7 105 b:SetScript("OnReceiveDrag", function() self:OnReceiveDrag() end)
flickerstreak@7 106 b:SetScript("OnEnter", function() self:OnEnter() end)
flickerstreak@7 107 b:SetScript("OnLeave", function() self:OnLeave() end)
flickerstreak@7 108 -- defer setting OnUpdate until actions are actually attached
flickerstreak@7 109
flickerstreak@7 110 self.tmpShow_ = 0
flickerstreak@7 111 end
flickerstreak@7 112
flickerstreak@7 113 function RAAD:UpdateDisplay()
flickerstreak@7 114 self:ApplyLayout()
flickerstreak@7 115 self:ApplyStyle()
flickerstreak@7 116 self:DisplayVisibility()
flickerstreak@7 117 -- refresh the action ID display
flickerstreak@7 118 if ReAction.showIDs_ then
flickerstreak@7 119 self:DisplayID(self:GetID())
flickerstreak@7 120 end
flickerstreak@7 121 end
flickerstreak@7 122
flickerstreak@7 123 function RAAD:TempShow( visible )
flickerstreak@7 124 visible = visible and true or false -- force data integrity
flickerstreak@7 125 self.showTmp_ = max(0, (self.showTmp_ or 0) + (visible and 1 or -1))
flickerstreak@7 126 self:DisplayVisibility()
flickerstreak@7 127 end
flickerstreak@7 128
flickerstreak@7 129 function RAAD:GetActionFrame()
flickerstreak@7 130 return self.frames.button
flickerstreak@7 131 end
flickerstreak@7 132
flickerstreak@7 133 function RAAD:GetBaseButtonSize()
flickerstreak@7 134 return 36
flickerstreak@7 135 end
flickerstreak@7 136
flickerstreak@7 137 function RAAD:DisplayID( id )
flickerstreak@7 138 local f = self.frames.actionID
flickerstreak@7 139 if id then
flickerstreak@7 140 if not f then
flickerstreak@7 141 -- create the actionID label
flickerstreak@7 142 f = self.frames.button:CreateFontString(nil,"ARTWORK","NumberFontNormalSmall")
flickerstreak@7 143 f:SetPoint("BOTTOMLEFT")
flickerstreak@7 144 f:SetTextColor( tcolor(actionIDColor) )
flickerstreak@7 145 self.frames.actionID = f
flickerstreak@7 146 end
flickerstreak@7 147 f:SetText(tostring(id))
flickerstreak@7 148 f:Show()
flickerstreak@7 149 elseif f then
flickerstreak@7 150 f:Hide()
flickerstreak@7 151 end
flickerstreak@7 152 end
flickerstreak@7 153
flickerstreak@7 154 function RAAD:DisplayHotkey(txt)
flickerstreak@7 155 self.frames.hotkey:SetText(string.upper(txt or ""))
flickerstreak@7 156 self:UpdateUsable()
flickerstreak@7 157 end
flickerstreak@7 158
flickerstreak@7 159 function RAAD:DisplayUsable( isUsable, notEnoughMana, outOfRange )
flickerstreak@7 160 local f = self.frames
flickerstreak@7 161 f.icon:SetVertexColor( self:GetIconColor(isUsable, notEnoughMana, outOfRange) )
flickerstreak@7 162 f.button:GetNormalTexture():SetVertexColor( self:GetBorderColor(isUsable, notEnoughMana, outOfRange) )
flickerstreak@7 163 f.hotkey:SetTextColor( self:GetHotkeyColor(isUsable, notEnoughMana, outOfRange, f.hotkey:GetText()) )
flickerstreak@7 164 end
flickerstreak@7 165
flickerstreak@7 166 function RAAD:DisplayEquipped( equipped )
flickerstreak@7 167 local b = self.frames.border
flickerstreak@7 168 if equipped then
flickerstreak@7 169 b:Show()
flickerstreak@7 170 else
flickerstreak@7 171 b:Hide()
flickerstreak@7 172 end
flickerstreak@7 173 end
flickerstreak@7 174
flickerstreak@7 175 function RAAD:DisplayAutoRepeat( r )
flickerstreak@7 176 if r then
flickerstreak@7 177 self:StartFlash()
flickerstreak@7 178 else
flickerstreak@7 179 self:StopFlash()
flickerstreak@7 180 end
flickerstreak@7 181 end
flickerstreak@7 182
flickerstreak@7 183 function RAAD:DisplayInUse( inUse )
flickerstreak@7 184 self.frames.button:SetChecked( inUse and 1 or 0 )
flickerstreak@7 185 end
flickerstreak@7 186
flickerstreak@7 187 function RAAD:DisplayIcon( texture )
flickerstreak@7 188 local f = self.frames.button
flickerstreak@7 189 local icon = self.frames.icon
flickerstreak@7 190 if texture then
flickerstreak@7 191 icon:SetTexture(texture)
flickerstreak@7 192 icon:Show()
flickerstreak@7 193 self.rangeTimer = -1
flickerstreak@7 194 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
flickerstreak@7 195 if f:GetScript("OnUpdate") == nil then
flickerstreak@7 196 f:SetScript("OnUpdate", function(frame, elapsed) self:OnUpdate(elapsed) end)
flickerstreak@7 197 end
flickerstreak@7 198 else
flickerstreak@7 199 icon:Hide()
flickerstreak@7 200 self.rangeTimer = nil
flickerstreak@7 201 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot")
flickerstreak@7 202 f:SetScript("OnUpdate",nil)
flickerstreak@7 203 end
flickerstreak@7 204 self:DisplayVisibility()
flickerstreak@7 205 end
flickerstreak@7 206
flickerstreak@7 207 function RAAD:DisplayCooldown( start, duration, enable )
flickerstreak@7 208 CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enable)
flickerstreak@7 209 end
flickerstreak@7 210
flickerstreak@7 211 function RAAD:DisplayName( name )
flickerstreak@7 212 self.frames.macro:SetText(name and tostring(name) or "")
flickerstreak@7 213 end
flickerstreak@7 214
flickerstreak@7 215 function RAAD:DisplayCount( count )
flickerstreak@7 216 self.frames.count:SetText(count and tostring(count) or "")
flickerstreak@7 217 end
flickerstreak@7 218
flickerstreak@7 219
flickerstreak@7 220
flickerstreak@7 221
flickerstreak@7 222
flickerstreak@7 223 ----------------------
flickerstreak@7 224 -- Event Handlers
flickerstreak@7 225 ----------------------
flickerstreak@7 226 function RAAD:PostClick()
flickerstreak@7 227 self:UpdateInUse()
flickerstreak@7 228 end
flickerstreak@7 229
flickerstreak@7 230 function RAAD:OnDragStart()
flickerstreak@7 231 if LOCK_ACTIONBAR ~= "1" or IsShiftKeyDown() then
flickerstreak@7 232 self:PickupAction()
flickerstreak@7 233 end
flickerstreak@7 234 end
flickerstreak@7 235
flickerstreak@7 236 function RAAD:OnReceiveDrag()
flickerstreak@7 237 self:PlaceAction()
flickerstreak@7 238 end
flickerstreak@7 239
flickerstreak@7 240 function RAAD:OnEnter()
flickerstreak@7 241 self:SetTooltip() -- from ReAction base class
flickerstreak@7 242 self.tooltipTime = TOOLTIP_UPDATE_TIME
flickerstreak@7 243 end
flickerstreak@7 244
flickerstreak@7 245 function RAAD:OnLeave()
flickerstreak@7 246 self:ClearTooltip() -- from ReAction base class
flickerstreak@7 247 self.tooltipTime = nil
flickerstreak@7 248 end
flickerstreak@7 249
flickerstreak@7 250 function RAAD:OnUpdate(elapsed)
flickerstreak@7 251 -- handle flashing
flickerstreak@7 252 if self:IsFlashing() then
flickerstreak@7 253 self.flashtime = self.flashtime - elapsed
flickerstreak@7 254 if self.flashtime <= 0 then
flickerstreak@7 255 local overtime = -self.flashtime
flickerstreak@7 256 if overtime >= ATTACK_BUTTON_FLASH_TIME then
flickerstreak@7 257 overtime = 0
flickerstreak@7 258 end
flickerstreak@7 259 self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime
flickerstreak@7 260
flickerstreak@7 261 local f = self.frames.flash
flickerstreak@7 262 if f then
flickerstreak@7 263 if f:IsVisible() then
flickerstreak@7 264 f:Hide()
flickerstreak@7 265 else
flickerstreak@7 266 f:Show()
flickerstreak@7 267 end
flickerstreak@7 268 end
flickerstreak@7 269 end
flickerstreak@7 270 end
flickerstreak@7 271
flickerstreak@7 272 -- Handle range indicator
flickerstreak@7 273 if self.rangeTimer then
flickerstreak@7 274 self.rangeTimer = self.rangeTimer - elapsed
flickerstreak@7 275 if self.rangeTimer <= 0 then
flickerstreak@7 276 self:UpdateUsable()
flickerstreak@7 277 self.rangeTimer = TOOLTIP_UPDATE_TIME
flickerstreak@7 278 end
flickerstreak@7 279 end
flickerstreak@7 280
flickerstreak@7 281 -- handle tooltip update
flickerstreak@7 282 if self.tooltipTime then
flickerstreak@7 283 self.tooltipTime = self.tooltipTime - elapsed
flickerstreak@7 284 if self.tooltipTime <= 0 then
flickerstreak@7 285 if GameTooltip:IsOwned(self.frames.button) then
flickerstreak@7 286 self:UpdateTooltip()
flickerstreak@7 287 self.tooltipTime = TOOLTIP_UPDATE_TIME
flickerstreak@7 288 else
flickerstreak@7 289 self.tooltipTime = nil
flickerstreak@7 290 end
flickerstreak@7 291 end
flickerstreak@7 292 end
flickerstreak@7 293 end
flickerstreak@7 294
flickerstreak@7 295
flickerstreak@7 296
flickerstreak@7 297 ----------------------
flickerstreak@7 298 -- Internal methods
flickerstreak@7 299 ----------------------
flickerstreak@7 300
flickerstreak@7 301 local function placeLabel( label, anchor )
flickerstreak@7 302 local top = string.match(anchor,"TOP")
flickerstreak@7 303 local bottom = string.match(anchor, "BOTTOM")
flickerstreak@7 304 label:ClearAllPoints()
flickerstreak@7 305 label:SetWidth(40)
flickerstreak@7 306 label:SetPoint(top or bottom or "CENTER",0,top and 2 or bottom and -2 or 0)
flickerstreak@7 307 local j
flickerstreak@7 308 if string.match(anchor,"LEFT") then
flickerstreak@7 309 j = "LEFT"
flickerstreak@7 310 elseif string.match(anchor,"RIGHT") then
flickerstreak@7 311 j = "RIGHT"
flickerstreak@7 312 else
flickerstreak@7 313 j = "CENTER"
flickerstreak@7 314 end
flickerstreak@7 315 label:SetJustifyH(j)
flickerstreak@7 316 end
flickerstreak@7 317
flickerstreak@7 318
flickerstreak@7 319 function RAAD:ApplyLayout()
flickerstreak@7 320 local f = self.frames
flickerstreak@7 321
flickerstreak@7 322 if self.config.keyBindLoc then
flickerstreak@7 323 placeLabel(f.hotkey, self.config.keyBindLoc)
flickerstreak@7 324 end
flickerstreak@7 325
flickerstreak@7 326 if self.config.stackCountLoc then
flickerstreak@7 327 placeLabel(f.count, self.config.stackCountLoc)
flickerstreak@7 328 end
flickerstreak@7 329
flickerstreak@7 330 if self.config.showKeyBind then
flickerstreak@7 331 f.hotkey:Show()
flickerstreak@7 332 else
flickerstreak@7 333 f.hotkey:Hide()
flickerstreak@7 334 end
flickerstreak@7 335
flickerstreak@7 336 if self.config.showStackCount then
flickerstreak@7 337 f.count:Show()
flickerstreak@7 338 else
flickerstreak@7 339 f.count:Hide()
flickerstreak@7 340 end
flickerstreak@7 341
flickerstreak@7 342 if self.config.showMacroName then
flickerstreak@7 343 f.macro:Show()
flickerstreak@7 344 else
flickerstreak@7 345 f.macro:Hide()
flickerstreak@7 346 end
flickerstreak@7 347
flickerstreak@7 348 end
flickerstreak@7 349
flickerstreak@7 350 function RAAD:ApplyStyle()
flickerstreak@7 351 local f = self.frames
flickerstreak@7 352 -- for now, just a static style
flickerstreak@7 353 f.hotkey:SetFontObject(NumberFontNormal)
flickerstreak@7 354 f.count:SetFontObject(NumberFontNormalYellow)
flickerstreak@7 355 f.border:SetVertexColor( tcolor(equippedActionBorderColor) )
flickerstreak@7 356 end
flickerstreak@7 357
flickerstreak@7 358 function RAAD:StartFlash()
flickerstreak@7 359 self.flashing = true
flickerstreak@7 360 self.flashtime = 0
flickerstreak@7 361 end
flickerstreak@7 362
flickerstreak@7 363 function RAAD:StopFlash()
flickerstreak@7 364 self.flashing = false
flickerstreak@7 365 self.frames.flash:Hide()
flickerstreak@7 366 end
flickerstreak@7 367
flickerstreak@7 368 function RAAD:IsFlashing()
flickerstreak@7 369 return self.flashing
flickerstreak@7 370 end
flickerstreak@7 371
flickerstreak@7 372 function RAAD:DisplayVisibility()
flickerstreak@7 373 local b = self.frames.button
flickerstreak@7 374
flickerstreak@7 375 if b:GetAttribute("statehidden") then
flickerstreak@7 376 -- can't hide/show in combat
flickerstreak@7 377 if not InCombatLockdown() then
flickerstreak@7 378 b:Hide()
flickerstreak@7 379 end
flickerstreak@7 380 elseif not self:IsActionEmpty() then
flickerstreak@7 381 b:GetNormalTexture():SetAlpha(1.0)
flickerstreak@7 382 b:SetAlpha(1)
flickerstreak@7 383 elseif self.showTmp_ and self.showTmp_ > 0 or self.config.showGrid then
flickerstreak@7 384 b:GetNormalTexture():SetAlpha(0.5)
flickerstreak@7 385 self.frames.cooldown:Hide()
flickerstreak@7 386 b:SetAlpha(1)
flickerstreak@7 387 else
flickerstreak@7 388 b:SetAlpha(0)
flickerstreak@7 389 end
flickerstreak@7 390 end
flickerstreak@7 391