annotate classes/ReAction_PetActionDisplay.lua @ 10:f3a7bfebc283

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