Mercurial > wow > reaction
comparison classes/ReAction.lua @ 4:dfd829db3ad0
(none)
| author | Flick <flickerstreak@gmail.com> |
|---|---|
| date | Tue, 20 Mar 2007 21:19:34 +0000 |
| parents | Button.lua@8e0ff8ae4c08 |
| children | f920db5fc6b1 |
comparison
equal
deleted
inserted
replaced
| 3:f5607e135c37 | 4:dfd829db3ad0 |
|---|---|
| 1 -- private constants | |
| 2 local namePrefix = "ReActionButton" | |
| 3 local _G = getfenv(0) | |
| 4 local ACTION_FREE = { } | |
| 5 local MAX_ACTIONS = 120 | |
| 6 | |
| 7 local hotKeyDefaultColor = { r=1.0, g=1.0, b=1.0, a=1.0 } | |
| 8 local hotKeyDisabledColor = { r=0.6, g=0.6, b=0.6, a=1.0 } | |
| 9 local hotKeyOutOfRangeColor = { r=1.0, g=0.2, b=0.2, a=1.0 } | |
| 10 | |
| 11 local hotKeyModifierColors = { | |
| 12 S = { r=0.6, g=0.6, b=1.0, a=1.0 }, -- shift | |
| 13 C = { r=1.0, g=0.82, b=0, a=1.0 }, -- ctrl | |
| 14 A = { r=0.1, g=1.0, b=0.1, a=1.0 }, -- alt | |
| 15 } | |
| 16 | |
| 17 -- TODO: localize these key names with GetBindingText(KEY_) | |
| 18 local keybindAbbreviations = { | |
| 19 ["Mouse Button "] = "M-", | |
| 20 ["Spacebar"] = "Sp", | |
| 21 ["Num Pad "] = "Num-", | |
| 22 ["Page Up"] = "PgUp", | |
| 23 ["Page Down"] = "PgDn", | |
| 24 [" Arrow"] = "", | |
| 25 } | |
| 26 | |
| 27 local equippedActionBorderColor = { r=0, g=1.0, b=0, a=0.35 } | |
| 28 | |
| 29 local actionUsableColor = { r=1.0, g=1.0, b=1.0, a=1.0 } | |
| 30 local actionNotUsableColor = { r=0.4, g=0.4, b=0.4, a=1.0 } | |
| 31 local actionNotEnoughManaColor = { r=0.2, g=0.2, b=0.7, a=1.0 } | |
| 32 local actionOutOfRangeColor = { r=1.0, g=0.2, b=0.2, a=1.0 } | |
| 33 | |
| 34 -- private variables | |
| 35 local kbValidate = AceLibrary("AceConsole-2.0").keybindingValidateFunc | |
| 36 local actionButtonTbl = { } | |
| 37 | |
| 38 | |
| 39 | |
| 40 -- ReActionButton is a class prototype object. | |
| 41 ReActionButton = AceLibrary("AceOO-2.0").Class("AceEvent-2.0") | |
| 42 | |
| 43 ------------------- | |
| 44 -- Class methods | |
| 45 ------------------- | |
| 46 | |
| 47 -- In addition to supporting the 'new' creation method (in which case an action ID must be specified directly), | |
| 48 -- ReActionButton supports the 'acquire'/'release' creation method, which recycles objects and manages actionID assignment. | |
| 49 | |
| 50 function ReActionButton:acquire(parent, config, barIdx) | |
| 51 local id = nil | |
| 52 for i = 1, MAX_ACTIONS do | |
| 53 if actionButtonTbl[i] == nil or actionButtonTbl[i].inUse == false then | |
| 54 id = i | |
| 55 break | |
| 56 end | |
| 57 end | |
| 58 | |
| 59 if id == nil then return nil end -- all buttons and action ids are in use | |
| 60 | |
| 61 local hint = config.actionIDs[barIdx] | |
| 62 if hint and (actionButtonTbl[hint] == nil or actionButtonTbl[hint].inUse == false) then | |
| 63 id = hint | |
| 64 end | |
| 65 | |
| 66 if actionButtonTbl[id] == nil then | |
| 67 actionButtonTbl[id] = { } | |
| 68 end | |
| 69 local t = actionButtonTbl[id] | |
| 70 | |
| 71 t.inUse = true | |
| 72 if t.button then | |
| 73 t.button:Configure(parent,config,barIdx) | |
| 74 else | |
| 75 t.button = self:new(parent,config,barIdx,id) | |
| 76 end | |
| 77 | |
| 78 -- fix screwy config with overlapping IDs | |
| 79 config.actionIDs[barIdx] = id | |
| 80 return t.button | |
| 81 end | |
| 82 | |
| 83 function ReActionButton:release( b ) | |
| 84 if b then | |
| 85 actionButtonTbl[b:GetActionID()].inUse = false | |
| 86 b:Recycle() | |
| 87 end | |
| 88 end | |
| 89 | |
| 90 | |
| 91 | |
| 92 function ReActionButton:ShowAllActionIDs() | |
| 93 for _, b in ipairs(actionButtonTbl) do | |
| 94 b:ShowActionID() | |
| 95 end | |
| 96 end | |
| 97 | |
| 98 function ReActionButton:HideAllActionIDs() | |
| 99 for _, b in ipairs(actionButtonTbl) do | |
| 100 b:HideActionID() | |
| 101 end | |
| 102 end | |
| 103 | |
| 104 | |
| 105 ---------------------- | |
| 106 -- Instance methods | |
| 107 ---------------------- | |
| 108 function ReActionButton.prototype:init( parentFrame, config, barIdx, id ) | |
| 109 ReActionButton.super.prototype.init(self) | |
| 110 | |
| 111 -- create the button widget | |
| 112 self.name = namePrefix..id | |
| 113 self.button = CreateFrame("CheckButton", self.name, parentFrame, "ReActionButtonTemplate") | |
| 114 | |
| 115 -- store references to the various sub-frames so we don't have to look it up all the time | |
| 116 self.frames = { | |
| 117 hotkey = _G[self.name.."HotKey"], | |
| 118 count = _G[self.name.."Count"], | |
| 119 cooldown = _G[self.name.."Cooldown"], | |
| 120 -- nCooldown = _G[self.name.."CooldownNumeric"], | |
| 121 macro = _G[self.name.."Name"], | |
| 122 icon = _G[self.name.."Icon"], | |
| 123 border = _G[self.name.."Border"], | |
| 124 normalTexture = _G[self.name.."NormalTexture"], | |
| 125 flash = _G[self.name.."Flash"], | |
| 126 actionID = _G[self.name.."ActionID"], | |
| 127 } | |
| 128 | |
| 129 -- provide a reference back to this object for the frame to use in event handlers | |
| 130 self.button.rxnBtn = self | |
| 131 | |
| 132 -- set the action ID | |
| 133 self:SetActionID(id) | |
| 134 | |
| 135 -- register button with ReBinder for keybinding | |
| 136 ReBinder:AddKeybindTarget(self.button) | |
| 137 | |
| 138 -- initialize | |
| 139 self:Configure(parentFrame, config, barIdx) | |
| 140 end | |
| 141 | |
| 142 local function tcopy(t) | |
| 143 local r = { } | |
| 144 for k, v in pairs(t) do | |
| 145 r[k] = (type(v) == "table" and tcopy(v) or v) | |
| 146 end | |
| 147 return r | |
| 148 end | |
| 149 | |
| 150 function ReActionButton.prototype:Recycle() | |
| 151 local b = self.button | |
| 152 | |
| 153 self:SetKeyBinding(nil) | |
| 154 self:UpdateDisplay() | |
| 155 b:UnregisterAllEvents() | |
| 156 b:SetParent(ReActionButtonRecycleFrame) | |
| 157 b:ClearAllPoints() | |
| 158 b:SetPoint("TOPLEFT",0,0) | |
| 159 b:Hide() | |
| 160 self.config = tcopy(self.config) -- ew, but necessary | |
| 161 end | |
| 162 | |
| 163 function ReActionButton.prototype:BarUnlocked() | |
| 164 self:ShowGridTmp() | |
| 165 end | |
| 166 | |
| 167 function ReActionButton.prototype:BarLocked() | |
| 168 self:HideGridTmp() | |
| 169 end | |
| 170 | |
| 171 | |
| 172 -- set the button location | |
| 173 function ReActionButton.prototype:PlaceButton(point, x, y, sz) | |
| 174 local b = self.button | |
| 175 local scale = sz / 36 | |
| 176 b:ClearAllPoints() | |
| 177 b:SetScale( scale ) | |
| 178 b:SetPoint(point,x/scale,y/scale) | |
| 179 end | |
| 180 | |
| 181 | |
| 182 function ReActionButton.prototype:ShowActionID() | |
| 183 self.frames.actionID:Show() | |
| 184 end | |
| 185 | |
| 186 function ReActionButton.prototype:HideActionID() | |
| 187 self.frames.actionID:Hide() | |
| 188 end | |
| 189 | |
| 190 | |
| 191 | |
| 192 -- configuration and setup | |
| 193 function ReActionButton.prototype:Configure( parentFrame, config, barIdx ) | |
| 194 self.config = config | |
| 195 self.barIdx = barIdx | |
| 196 self.showGridTmp_ = 0 | |
| 197 | |
| 198 self.button:ClearAllPoints() | |
| 199 self.button:SetParent(parentFrame) | |
| 200 | |
| 201 self:SetupAttributes() | |
| 202 self:RegisterStaticEvents() | |
| 203 | |
| 204 self:ApplyLayout() | |
| 205 self:ApplyStyle() | |
| 206 | |
| 207 self:UpdateDisplay() | |
| 208 end | |
| 209 | |
| 210 function ReActionButton.prototype:SetupAttributes() | |
| 211 local b = self.button | |
| 212 b:SetAttribute("type", "action") | |
| 213 b:SetAttribute("shift-type*", ATTRIBUTE_NOOP) | |
| 214 b:SetAttribute("checkselfcast", true) | |
| 215 b:SetAttribute("useparent-unit", true) | |
| 216 end | |
| 217 | |
| 218 function ReActionButton.prototype:RegisterStaticEvents() | |
| 219 self:RegisterEvent("PLAYER_ENTERING_WORLD") | |
| 220 self:RegisterEvent("ACTIONBAR_SLOT_CHANGED") | |
| 221 self:RegisterEvent("UPDATE_BINDINGS") | |
| 222 self:RegisterEvent("ACTIONBAR_SHOWGRID") | |
| 223 self:RegisterEvent("ACTIONBAR_HIDEGRID") | |
| 224 end | |
| 225 | |
| 226 function ReActionButton.prototype:RegisterActionEvents() | |
| 227 self:RegisterEvent("ACTIONBAR_UPDATE_STATE") | |
| 228 self:RegisterEvent("ACTIONBAR_UPDATE_USABLE") | |
| 229 self:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN", "ACTIONBAR_UPDATE_USABLE") | |
| 230 self:RegisterEvent("UPDATE_INVENTORY_ALERTS", "ACTIONBAR_UPDATE_USABLE") | |
| 231 self:RegisterEvent("PLAYER_AURAS_CHANGED", "ACTIONBAR_UPDATE_USABLE") | |
| 232 self:RegisterEvent("PLAYER_TARGET_CHANGED", "ACTIONBAR_UPDATE_USABLE") | |
| 233 self:RegisterEvent("UNIT_INVENTORY_CHANGED") | |
| 234 self:RegisterEvent("CRAFT_SHOW") | |
| 235 self:RegisterEvent("CRAFT_CLOSE", "CRAFT_SHOW") | |
| 236 self:RegisterEvent("TRADE_SKILL_SHOW", "CRAFT_SHOW") | |
| 237 self:RegisterEvent("TRADE_SKILL_CLOSE", "CRAFT_SHOW") | |
| 238 self:RegisterEvent("PLAYER_ENTER_COMBAT", "CRAFT_SHOW") | |
| 239 self:RegisterEvent("PLAYER_LEAVE_COMBAT") | |
| 240 self:RegisterEvent("START_AUTOREPEAT_SPELL") | |
| 241 self:RegisterEvent("STOP_AUTOREPEAT_SPELL") | |
| 242 | |
| 243 self.button:SetScript("OnUpdate", function() self:OnUpdate(arg1) end) | |
| 244 self.actionEventsRegistered = true | |
| 245 end | |
| 246 | |
| 247 function ReActionButton.prototype:UnregisterActionEvents() | |
| 248 self:UnregisterEvent("ACTIONBAR_UPDATE_STATE") | |
| 249 self:UnregisterEvent("ACTIONBAR_UPDATE_USABLE") | |
| 250 self:UnregisterEvent("ACTIONBAR_UPDATE_COOLDOWN") | |
| 251 self:UnregisterEvent("UPDATE_INVENTORY_ALERTS") | |
| 252 self:UnregisterEvent("PLAYER_AURAS_CHANGED") | |
| 253 self:UnregisterEvent("PLAYER_TARGET_CHANGED") | |
| 254 self:UnregisterEvent("UNIT_INVENTORY_CHANGED") | |
| 255 self:UnregisterEvent("CRAFT_SHOW") | |
| 256 self:UnregisterEvent("CRAFT_CLOSE") | |
| 257 self:UnregisterEvent("TRADE_SKILL_SHOW") | |
| 258 self:UnregisterEvent("TRADE_SKILL_CLOSE") | |
| 259 self:UnregisterEvent("PLAYER_ENTER_COMBAT") | |
| 260 self:UnregisterEvent("PLAYER_LEAVE_COMBAT") | |
| 261 self:UnregisterEvent("START_AUTOREPEAT_SPELL") | |
| 262 self:UnregisterEvent("STOP_AUTOREPEAT_SPELL") | |
| 263 | |
| 264 self.button:SetScript("OnUpdate", nil) | |
| 265 self.actionEventsRegistered = false | |
| 266 end | |
| 267 | |
| 268 | |
| 269 -- event handlers | |
| 270 function ReActionButton.prototype:ACTIONBAR_SLOT_CHANGED() | |
| 271 if arg1 == 0 or arg1 == self:GetActionID() then | |
| 272 self:UpdateDisplay() | |
| 273 end | |
| 274 end | |
| 275 | |
| 276 function ReActionButton.prototype:PLAYER_ENTERING_WORLD() | |
| 277 self:UpdateDisplay() | |
| 278 end | |
| 279 | |
| 280 function ReActionButton.prototype:UPDATE_BINDINGS() | |
| 281 self:UpdateDisplay() | |
| 282 end | |
| 283 | |
| 284 function ReActionButton.prototype:ACTIONBAR_SHOWGRID() | |
| 285 self:ShowGridTmp() | |
| 286 end | |
| 287 | |
| 288 function ReActionButton.prototype:ACTIONBAR_HIDEGRID() | |
| 289 self:HideGridTmp() | |
| 290 end | |
| 291 | |
| 292 function ReActionButton.prototype:ACTIONBAR_UPDATE_STATE() | |
| 293 self:UpdateCheckedState() | |
| 294 end | |
| 295 | |
| 296 function ReActionButton.prototype:ACTIONBAR_UPDATE_USABLE() | |
| 297 self:UpdateUsable() | |
| 298 self:UpdateCooldown() | |
| 299 self:ColorHotKey() | |
| 300 end | |
| 301 | |
| 302 function ReActionButton.prototype:UNIT_INVENTORY_CHANGED() | |
| 303 if arg1 == "player" then | |
| 304 self:UpdateDisplay() | |
| 305 end | |
| 306 end | |
| 307 | |
| 308 function ReActionButton.prototype:CRAFT_SHOW() | |
| 309 self:UpdateCheckedState() | |
| 310 end | |
| 311 | |
| 312 function ReActionButton.prototype:PLAYER_ENTER_COMBAT() | |
| 313 if IsAttackAction(self:GetActionID()) then | |
| 314 self:StartFlash() | |
| 315 end | |
| 316 end | |
| 317 | |
| 318 function ReActionButton.prototype:PLAYER_LEAVE_COMBAT() | |
| 319 if IsAttackAction(self:GetActionID()) then | |
| 320 self:StopFlash() | |
| 321 end | |
| 322 end | |
| 323 | |
| 324 function ReActionButton.prototype:START_AUTOREPEAT_SPELL() | |
| 325 if IsAutoRepeatAction(self:GetActionID()) then | |
| 326 self:StartFlash() | |
| 327 end | |
| 328 end | |
| 329 | |
| 330 function ReActionButton.prototype:STOP_AUTOREPEAT_SPELL() | |
| 331 if self:IsFlashing() and not IsAttackAction(self:GetActionID()) then | |
| 332 self:StopFlash() | |
| 333 end | |
| 334 end | |
| 335 | |
| 336 | |
| 337 -- OnUpdate handler | |
| 338 function ReActionButton.prototype:OnUpdate(elapsed) | |
| 339 local action = self:GetActionID() | |
| 340 local f = self.frames | |
| 341 | |
| 342 -- handle flashing | |
| 343 if self:IsFlashing() then | |
| 344 self.flashtime = self.flashtime - elapsed | |
| 345 if self.flashtime <= 0 then | |
| 346 local overtime = -self.flashtime | |
| 347 if overtime >= ATTACK_BUTTON_FLASH_TIME then | |
| 348 overtime = 0 | |
| 349 end | |
| 350 self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime | |
| 351 | |
| 352 if f.flash:IsVisible() then | |
| 353 f.flash:Hide() | |
| 354 else | |
| 355 f.flash:Show() | |
| 356 end | |
| 357 end | |
| 358 end | |
| 359 | |
| 360 -- Handle range indicator | |
| 361 if self.rangeTimer then | |
| 362 self.rangeTimer = self.rangeTimer - elapsed | |
| 363 if self.rangeTimer <= 0 then | |
| 364 self:ColorHotKey() | |
| 365 self:UpdateUsable() | |
| 366 self.rangeTimer = TOOLTIP_UPDATE_TIME | |
| 367 end | |
| 368 end | |
| 369 | |
| 370 -- handle toltip update | |
| 371 if self.tooltipTime then | |
| 372 self.tooltipTime = self.tooltipTime - elapsed | |
| 373 if self.tooltipTime <= 0 then | |
| 374 if GameTooltip:IsOwned(self.button) then | |
| 375 self:UpdateTooltip() | |
| 376 else | |
| 377 self.tooltipTime = nil | |
| 378 end | |
| 379 end | |
| 380 end | |
| 381 end | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 -- keybinding functions | |
| 387 function ReActionButton.prototype:SetKeyBinding( k ) | |
| 388 if k == nil or kbValidate(k) then | |
| 389 local current = self:GetKeyBinding() | |
| 390 ClearOverrideBindings(self.button) | |
| 391 if current then | |
| 392 SetBinding(current,nil) | |
| 393 end | |
| 394 if k then | |
| 395 SetBindingClick(k, self.name, "LeftButton") | |
| 396 end | |
| 397 end | |
| 398 end | |
| 399 | |
| 400 function ReActionButton.prototype:GetKeyBinding() | |
| 401 return GetBindingKey("CLICK "..self.name..":LeftButton") | |
| 402 end | |
| 403 | |
| 404 -- action ID functions | |
| 405 function ReActionButton.prototype:SetActionID( id ) | |
| 406 self.actionID = tonumber(id) -- force data integrity | |
| 407 self:ApplyActionID() | |
| 408 end | |
| 409 | |
| 410 function ReActionButton.prototype:GetActionID() | |
| 411 return self.actionID | |
| 412 end | |
| 413 | |
| 414 function ReActionButton.prototype:ApplyActionID() | |
| 415 local action = tonumber(self:GetActionID()) | |
| 416 self.button:SetAttribute("action",action) | |
| 417 self.frames.actionID:SetText(action or "") | |
| 418 end | |
| 419 | |
| 420 function ReActionButton.prototype:ShowActionID() | |
| 421 self.frames.actionID:Show() | |
| 422 end | |
| 423 | |
| 424 function ReActionButton.prototype:HideActionID() | |
| 425 self.frames.actionID:Hide() | |
| 426 end | |
| 427 | |
| 428 function ReActionButton:ShowAllActionIDs() -- class-wide function | |
| 429 for _, tbl in pairs(actionButtonTbl) do | |
| 430 if tbl.button then tbl.button:ShowActionID() end | |
| 431 end | |
| 432 end | |
| 433 | |
| 434 function ReActionButton:HideAllActionIDs() -- class-wide function | |
| 435 for _, tbl in pairs(actionButtonTbl) do | |
| 436 if tbl.button then tbl.button:HideActionID() end | |
| 437 end | |
| 438 end | |
| 439 | |
| 440 | |
| 441 -- action transfer functions | |
| 442 function ReActionButton.prototype:ShouldPickupAction(mouseButton) | |
| 443 return IsShiftKeyDown() and not SecureButton_GetModifiedAttribute(self.button, "type", mouseButton) | |
| 444 end | |
| 445 | |
| 446 function ReActionButton.prototype:ShowGridTmp() | |
| 447 self.showGridTmp_ = self.showGridTmp_ + 1 | |
| 448 self:UpdateVisibility() | |
| 449 end | |
| 450 | |
| 451 function ReActionButton.prototype:HideGridTmp() | |
| 452 self.showGridTmp_ = self.showGridTmp_ - 1 | |
| 453 self:UpdateVisibility() | |
| 454 end | |
| 455 | |
| 456 function ReActionButton.prototype:ShowGrid() | |
| 457 self.config.showGrid = true | |
| 458 self:UpdateVisibility() | |
| 459 end | |
| 460 | |
| 461 function ReActionButton.prototype:HideGrid() | |
| 462 self.config.showGrid = false | |
| 463 self:UpdateVisibility() | |
| 464 end | |
| 465 | |
| 466 | |
| 467 | |
| 468 -- layout & style functions | |
| 469 function ReActionButton.prototype:ApplyLayout() | |
| 470 local f = self.frames | |
| 471 | |
| 472 if self.config.keyBindLoc then | |
| 473 local h = f.hotkey | |
| 474 local loc = self.config.keyBindLoc | |
| 475 local top = string.match(loc,"TOP") | |
| 476 local bottom = string.match(loc, "BOTTOM") | |
| 477 h:ClearAllPoints() | |
| 478 h:SetWidth(40) | |
| 479 h:SetPoint(top or bottom,0,top and 2 or -2) | |
| 480 local j | |
| 481 if string.match(loc,"LEFT") then | |
| 482 j = "LEFT" | |
| 483 elseif string.match(loc,"RIGHT") then | |
| 484 j = "RIGHT" | |
| 485 else | |
| 486 j = "CENTER" | |
| 487 end | |
| 488 h:SetJustifyH(j) | |
| 489 end | |
| 490 | |
| 491 if self.config.stackCountLoc then | |
| 492 local c = f.count | |
| 493 local loc = self.config.stackCountLoc | |
| 494 local top = string.match(loc,"TOP") | |
| 495 local bottom = string.match(loc, "BOTTOM") | |
| 496 c:ClearAllPoints() | |
| 497 c:SetWidth(40) | |
| 498 c:SetPoint(top or bottom,0,top and 2 or -2) | |
| 499 local j | |
| 500 if string.match(loc,"LEFT") then | |
| 501 j = "LEFT" | |
| 502 elseif string.match(loc,"RIGHT") then | |
| 503 j = "RIGHT" | |
| 504 else | |
| 505 j = "CENTER" | |
| 506 end | |
| 507 c:SetJustifyH(j) | |
| 508 end | |
| 509 | |
| 510 if self.config.showKeyBind then | |
| 511 f.hotkey:Show() | |
| 512 else | |
| 513 f.hotkey:Hide() | |
| 514 end | |
| 515 | |
| 516 if self.config.showStackCount then | |
| 517 f.count:Show() | |
| 518 else | |
| 519 f.count:Hide() | |
| 520 end | |
| 521 | |
| 522 --[[ | |
| 523 if self.config.showNumericCooldown then | |
| 524 f.nCooldown:Show() | |
| 525 else | |
| 526 f.nCooldown:Hide() | |
| 527 end | |
| 528 ]] | |
| 529 | |
| 530 if self.config.showMacroName then | |
| 531 f.macro:Show() | |
| 532 else | |
| 533 f.macro:Hide() | |
| 534 end | |
| 535 end | |
| 536 | |
| 537 function ReActionButton.prototype:ApplyStyle() | |
| 538 local f = self.frames | |
| 539 -- for now, just a static style | |
| 540 f.hotkey:SetFontObject(NumberFontNormal) | |
| 541 f.count:SetFontObject(NumberFontNormalYellow) | |
| 542 end | |
| 543 | |
| 544 | |
| 545 | |
| 546 -- start/stop flashing | |
| 547 function ReActionButton.prototype:StartFlash() | |
| 548 self.flashing = true | |
| 549 self.flashtime = 0 | |
| 550 self:UpdateCheckedState() | |
| 551 end | |
| 552 | |
| 553 function ReActionButton.prototype:StopFlash() | |
| 554 self.flashing = false | |
| 555 self.frames.flash:Hide() | |
| 556 self:UpdateCheckedState() | |
| 557 end | |
| 558 | |
| 559 function ReActionButton.prototype:IsFlashing() | |
| 560 return self.flashing | |
| 561 end | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 -- set the tooltip | |
| 568 function ReActionButton.prototype:SetTooltip() | |
| 569 GameTooltip_SetDefaultAnchor(GameTooltip, self.button) | |
| 570 self:UpdateTooltip() | |
| 571 end | |
| 572 | |
| 573 function ReActionButton.prototype:ClearTooltip() | |
| 574 tooltipTime = nil | |
| 575 GameTooltip:Hide() | |
| 576 end | |
| 577 | |
| 578 | |
| 579 | |
| 580 -- colorize the hotkey | |
| 581 function ReActionButton.prototype:ColorHotKey() | |
| 582 local action = self:GetActionID() | |
| 583 local c = hotKeyDefaultColor | |
| 584 | |
| 585 if action and HasAction(action) then | |
| 586 if IsActionInRange(action) == 0 then | |
| 587 c = hotKeyOutOfRangeColor | |
| 588 elseif self.config.keyBindColorCode then | |
| 589 local modKey = string.match( self.frames.hotkey:GetText() or "", "([ACS])%-") | |
| 590 c = modKey and hotKeyModifierColors[modKey] or c | |
| 591 end | |
| 592 else | |
| 593 c = hotKeyDisabledColor | |
| 594 end | |
| 595 | |
| 596 self.frames.hotkey:SetTextColor(c.r, c.g, c.b) | |
| 597 end | |
| 598 | |
| 599 | |
| 600 | |
| 601 | |
| 602 -- display update functions | |
| 603 function ReActionButton.prototype:UpdateDisplay() | |
| 604 self:UpdateIcon() | |
| 605 self:UpdateHotkey() | |
| 606 self:UpdateCount() | |
| 607 self:UpdateMacroText() | |
| 608 self:UpdateUsable() | |
| 609 self:UpdateCooldown() | |
| 610 self:UpdateFlash() | |
| 611 self:UpdateEvents() | |
| 612 self:UpdateVisibility() | |
| 613 self:UpdateTooltip() | |
| 614 end | |
| 615 | |
| 616 function ReActionButton.prototype:UpdateIcon() | |
| 617 local f = self.frames | |
| 618 local b = self.button | |
| 619 | |
| 620 local action = self:GetActionID() | |
| 621 local texture = action and GetActionTexture(action) | |
| 622 | |
| 623 if action and texture then | |
| 624 f.icon:SetTexture(texture) | |
| 625 f.icon:Show() | |
| 626 self.rangeTimer = -1 | |
| 627 b:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2") | |
| 628 else | |
| 629 f.icon:Hide() | |
| 630 f.cooldown:Hide() | |
| 631 self.rangeTimer = nil | |
| 632 b:SetNormalTexture("Interface\\Buttons\\UI-Quickslot") | |
| 633 end | |
| 634 | |
| 635 self:UpdateCheckedState() | |
| 636 | |
| 637 -- Add a green border if action is an equipped item | |
| 638 if action and IsEquippedAction(action) then | |
| 639 local c = equippedActionBorderColor | |
| 640 f.border:SetVertexColor(c.r, c.g, c.b, c.a or 1) | |
| 641 f.border:Show() | |
| 642 else | |
| 643 f.border:Hide() | |
| 644 end | |
| 645 end | |
| 646 | |
| 647 function ReActionButton.prototype:UpdateCheckedState() | |
| 648 local action = self:GetActionID() | |
| 649 if action and (IsCurrentAction(action) or IsAutoRepeatAction(action)) then | |
| 650 self.button:SetChecked(1) | |
| 651 else | |
| 652 self.button:SetChecked(0) | |
| 653 end | |
| 654 end | |
| 655 | |
| 656 | |
| 657 function ReActionButton.prototype:UpdateHotkey() | |
| 658 local action = self:GetActionID() | |
| 659 local b = self.button | |
| 660 local f = self.frames | |
| 661 local key = self:GetKeyBinding() | |
| 662 local txt = GetBindingText(key, "KEY_",1) | |
| 663 | |
| 664 -- abbreviate long key names | |
| 665 for pat, rep in pairs(keybindAbbreviations) do | |
| 666 txt = string.gsub(txt,pat,rep) | |
| 667 end | |
| 668 | |
| 669 if txt then | |
| 670 f.hotkey:SetText(string.upper(txt)) | |
| 671 self:ColorHotKey() | |
| 672 else | |
| 673 f.hotkey:SetText("") | |
| 674 end | |
| 675 end | |
| 676 | |
| 677 function ReActionButton.prototype:UpdateCount() | |
| 678 local action = self:GetActionID() | |
| 679 if action and (IsConsumableAction(action) or IsStackableAction(action)) then | |
| 680 self.frames.count:SetText(GetActionCount(action)) | |
| 681 else | |
| 682 self.frames.count:SetText("") | |
| 683 end | |
| 684 end | |
| 685 | |
| 686 function ReActionButton.prototype:UpdateMacroText() | |
| 687 local action = self:GetActionID() | |
| 688 self.frames.macro:SetText(action and GetActionText(action) or "") | |
| 689 end | |
| 690 | |
| 691 function ReActionButton.prototype:UpdateUsable() | |
| 692 local f = self.frames | |
| 693 local action = self:GetActionID() | |
| 694 local isUsable, notEnoughMana | |
| 695 if action then | |
| 696 isUsable, notEnoughMana = IsUsableAction(action) | |
| 697 end | |
| 698 if isUsable then | |
| 699 local c = actionUsableColor | |
| 700 if IsActionInRange(action) == 0 then | |
| 701 c = actionOutOfRangeColor | |
| 702 else | |
| 703 f.normalTexture:SetVertexColor(c.r, c.g, c.b, c.a) | |
| 704 end | |
| 705 f.icon:SetVertexColor(c.r, c.g, c.b, c.a) | |
| 706 elseif notEnoughMana then | |
| 707 local c = actionNotEnoughManaColor | |
| 708 f.icon:SetVertexColor(c.r, c.g, c.b, c.a) | |
| 709 f.normalTexture:SetVertexColor(c.r, c.g, c.b, c.a) | |
| 710 else | |
| 711 local c = actionNotUsableColor | |
| 712 f.icon:SetVertexColor(c.r, c.g, c.b, c.a) | |
| 713 f.normalTexture:SetVertexColor(1.0, 1.0, 1.0) | |
| 714 end | |
| 715 end | |
| 716 | |
| 717 function ReActionButton.prototype:UpdateCooldown() | |
| 718 local action = self:GetActionID() | |
| 719 if action then | |
| 720 local start, duration, enable = GetActionCooldown(self:GetActionID()) | |
| 721 CooldownFrame_SetTimer(self.frames.cooldown, start, duration, enable) | |
| 722 -- do numeric cooldown stuff here | |
| 723 end | |
| 724 end | |
| 725 | |
| 726 function ReActionButton.prototype:UpdateFlash() | |
| 727 local b = self.button | |
| 728 local action = self:GetActionID() | |
| 729 if action and ((IsAttackAction(action) and IsCurrentAction(action)) or IsAutoRepeatAction(action)) then | |
| 730 self:StartFlash() | |
| 731 else | |
| 732 self:StopFlash() | |
| 733 end | |
| 734 end | |
| 735 | |
| 736 function ReActionButton.prototype:UpdateVisibility() | |
| 737 local action = self:GetActionID() | |
| 738 local b = self.button | |
| 739 | |
| 740 if b:GetAttribute("statehidden") then | |
| 741 b:Hide() | |
| 742 elseif action and HasAction(action) then | |
| 743 b:GetNormalTexture():SetAlpha(1.0) | |
| 744 b:Show() | |
| 745 elseif self.showGridTmp_ > 0 or self.config.showGrid then | |
| 746 b:GetNormalTexture():SetAlpha(0.5) | |
| 747 self.frames.cooldown:Hide() | |
| 748 b:Show() | |
| 749 else | |
| 750 b:Hide() | |
| 751 end | |
| 752 end | |
| 753 | |
| 754 function ReActionButton.prototype:UpdateEvents() | |
| 755 local action = self:GetActionID() | |
| 756 if action and HasAction(action) then | |
| 757 self:RegisterActionEvents() | |
| 758 elseif self.actionEventsRegistered then | |
| 759 self:UnregisterActionEvents() | |
| 760 end | |
| 761 end | |
| 762 | |
| 763 function ReActionButton.prototype:UpdateTooltip() | |
| 764 local action = self:GetActionID() | |
| 765 if GameTooltip:IsOwned(self.button) and action and GameTooltip:SetAction(action) then | |
| 766 self.tooltipTime = TOOLTIP_UPDATE_TIME | |
| 767 else | |
| 768 self.tooltipTime = nil | |
| 769 end | |
| 770 end | |
| 771 | |
| 772 | |
| 773 |
