Mercurial > wow > reaction
comparison modules/PetAction.lua @ 116:fb48811a8736
Convert to standard keybindings
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Fri, 23 Jan 2009 23:44:55 +0000 |
parents | 410d036c43b2 |
children | 6e4a11b9d290 |
comparison
equal
deleted
inserted
replaced
115:af0172ed7037 | 116:fb48811a8736 |
---|---|
294 end | 294 end |
295 }) | 295 }) |
296 | 296 |
297 local frameRecycler = {} | 297 local frameRecycler = {} |
298 local trash = CreateFrame("Frame") | 298 local trash = CreateFrame("Frame") |
299 local KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings, OnEnter, OnLeave | 299 |
300 do | 300 local function GetActionName(f) |
301 local buttonLookup = setmetatable({},{__mode="kv"}) | 301 local b = f and f._reactionButton |
302 | 302 if b then |
303 -- Use KeyBound-1.0 for binding, but use Override bindings instead of | 303 return format("%s:%s", b.bar:GetName(), b.idx) |
304 -- regular bindings to support multiple profile use. This is a little | 304 end |
305 -- weird with the KeyBound dialog box (which has per-char selector as well | 305 end |
306 -- as an OK/Cancel box) but it's the least amount of effort to implement. | 306 |
307 function GetActionName(f) | 307 local function GetHotkey(f) |
308 local b = buttonLookup[f] | 308 return KB:ToShortKey(GetBindingKey(format("CLICK %s:LeftButton",f:GetName()))) |
309 if b then | 309 end |
310 return format("%s:%s", b.bar:GetName(), b.idx) | 310 |
311 end | 311 local function OnEnter( self ) |
312 end | 312 if ReAction:GetKeybindMode() then |
313 | 313 KB:Set(self) |
314 function GetHotkey(f) | 314 elseif self.tooltipName then |
315 local b = buttonLookup[f] | |
316 if b then | |
317 return KB:ToShortKey(b:GetConfig().hotkey) | |
318 end | |
319 end | |
320 | |
321 function SetKey(f, key) | |
322 local b = buttonLookup[f] | |
323 if b then | |
324 local c = b:GetConfig() | |
325 if c.hotkey then | |
326 SetOverrideBinding(f, false, c.hotkey, nil) | |
327 end | |
328 if key then | |
329 SetOverrideBindingClick(f, false, key, f:GetName(), nil) | |
330 end | |
331 c.hotkey = key | |
332 b:DisplayHotkey(GetHotkey(f)) | |
333 end | |
334 end | |
335 | |
336 function FreeKey(f, key) | |
337 local b = buttonLookup[f] | |
338 if b then | |
339 local c = b:GetConfig() | |
340 if c.hotkey == key then | |
341 local action = f:GetActionName() | |
342 SetOverrideBinding(f, false, c.hotkey, nil) | |
343 c.hotkey = nil | |
344 b:DisplayHotkey(nil) | |
345 return action | |
346 end | |
347 end | |
348 return ReAction:FreeOverrideHotkey(key) | |
349 end | |
350 | |
351 function ClearBindings(f) | |
352 SetKey(f, nil) | |
353 end | |
354 | |
355 function GetBindings(f) | |
356 local b = buttonLookup[f] | |
357 if b then | |
358 return b:GetConfig().hotkey | |
359 end | |
360 end | |
361 | |
362 function KBAttach( button ) | |
363 local f = button:GetFrame() | |
364 f.GetActionName = GetActionName | |
365 f.GetHotkey = GetHotkey | |
366 f.SetKey = SetKey | |
367 f.FreeKey = FreeKey | |
368 f.ClearBindings = ClearBindings | |
369 f.GetBindings = GetBindings | |
370 buttonLookup[f] = button | |
371 f:SetKey(button:GetConfig().hotkey) | |
372 ReAction:RegisterKeybindFrame(f) | |
373 if ReAction:GetKeybindMode() then | |
374 button.border:SetVertexColor(KB:GetColorKeyBoundMode()) | |
375 button.border:Show() | |
376 end | |
377 end | |
378 | |
379 function OnEnter( self ) | |
380 if not self.tooltipName then | |
381 return; | |
382 end | |
383 local uber = GetCVar("UberTooltips") | 315 local uber = GetCVar("UberTooltips") |
384 if self.isToken or (uber == "0") then | 316 if self.isToken or (uber == "0") then |
385 if uber == "0" then | 317 if uber == "0" then |
386 GameTooltip:SetOwner(self, "ANCHOR_RIGHT") | 318 GameTooltip:SetOwner(self, "ANCHOR_RIGHT") |
387 else | 319 else |
388 GameTooltip_SetDefaultAnchor(GameTooltip, self) | 320 GameTooltip_SetDefaultAnchor(GameTooltip, self) |
389 end | 321 end |
390 local tooltip = self.tooltipName | 322 GameTooltip:SetText(self.tooltipName) |
391 local k = GetBindings(self) | |
392 if k then | |
393 tooltip = tooltip .. format(" %s(%s)%s", NORMAL_FONT_COLOR_CODE, k, FONT_COLOR_CODE_CLOSE) | |
394 end | |
395 GameTooltip:SetText(tooltip) | |
396 if self.tooltipSubtext then | 323 if self.tooltipSubtext then |
397 GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5) | 324 GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5) |
398 end | 325 end |
399 GameTooltip:Show() | 326 GameTooltip:Show() |
400 else | 327 else |
401 GameTooltip_SetDefaultAnchor(GameTooltip, self) | 328 GameTooltip_SetDefaultAnchor(GameTooltip, self) |
402 GameTooltip:SetPetAction(self:GetID()) | 329 GameTooltip:SetPetAction(self:GetID()) |
403 end | 330 end |
404 end | 331 end |
405 | 332 end |
406 function OnLeave() | 333 |
407 GameTooltip:Hide() | 334 local function OnLeave() |
408 end | 335 GameTooltip:Hide() |
409 | |
410 end | 336 end |
411 | 337 |
412 local meta = { __index = Button } | 338 local meta = { __index = Button } |
413 | 339 |
414 function Button:New( bar, idx, config ) | 340 function Button:New( bar, idx, config ) |
422 | 348 |
423 local name = config.name or ("ReAction_%s_%s_%d"):format(bar:GetName(),moduleID,idx) | 349 local name = config.name or ("ReAction_%s_%s_%d"):format(bar:GetName(),moduleID,idx) |
424 config.name = name | 350 config.name = name |
425 self.name = name | 351 self.name = name |
426 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured | 352 config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured |
427 | 353 |
428 -- have to recycle frames with the same name: | 354 -- have to recycle frames with the same name: |
429 -- otherwise you either get references to old textures because named CreateFrame() | 355 -- otherwise you either get references to old textures because named CreateFrame() |
430 -- doesn't overwrite existing globals. Can't set them to nil in the global table, | 356 -- doesn't overwrite existing globals. Can't set them to nil in the global table, |
431 -- as it causes taint. | 357 -- as it causes taint. |
432 local parent = bar:GetFrame() | 358 local parent = bar:GetFrame() |
461 self.acModel = _G[("%sShine"):format(name)] | 387 self.acModel = _G[("%sShine"):format(name)] |
462 self.cooldown = _G[("%sCooldown"):format(name)] | 388 self.cooldown = _G[("%sCooldown"):format(name)] |
463 self.hotkey = f.hotkey | 389 self.hotkey = f.hotkey |
464 self.border = _G[("%sBorder"):format(name)] | 390 self.border = _G[("%sBorder"):format(name)] |
465 | 391 |
466 | 392 f._reactionButton = self |
467 f:RegisterEvent("PLAYER_CONTROL_LOST"); | 393 |
468 f:RegisterEvent("PLAYER_CONTROL_GAINED"); | 394 f:RegisterEvent("PLAYER_CONTROL_LOST") |
469 f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED"); | 395 f:RegisterEvent("PLAYER_CONTROL_GAINED") |
470 f:RegisterEvent("UNIT_PET"); | 396 f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED") |
471 f:RegisterEvent("UNIT_FLAGS"); | 397 f:RegisterEvent("UNIT_PET") |
472 f:RegisterEvent("UNIT_AURA"); | 398 f:RegisterEvent("UNIT_FLAGS") |
473 f:RegisterEvent("PET_BAR_UPDATE"); | 399 f:RegisterEvent("UNIT_AURA") |
474 f:RegisterEvent("PET_BAR_UPDATE_COOLDOWN"); | 400 f:RegisterEvent("PET_BAR_UPDATE") |
401 f:RegisterEvent("PET_BAR_UPDATE_COOLDOWN") | |
475 | 402 |
476 f:SetScript("OnEvent", | 403 f:SetScript("OnEvent", |
477 function(event,arg1) | 404 function(event,arg1) |
478 if event =="PET_BAR_UPDATE_COOLDOWN" then | 405 if event =="PET_BAR_UPDATE_COOLDOWN" then |
479 self:UpdateCooldown() | 406 self:UpdateCooldown() |
491 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then | 418 if lockButtons and (PlayerInCombat() or not lockButtonsCombat) and not IsModifiedClick("PICKUPACTION") then |
492 return "clear" | 419 return "clear" |
493 end | 420 end |
494 ]]) | 421 ]]) |
495 | 422 |
496 KBAttach(self) | |
497 | |
498 -- attach to skinner | 423 -- attach to skinner |
499 bar:SkinButton(self, | 424 bar:SkinButton(self, |
500 { | 425 { |
501 HotKey = self.hotkey, | 426 HotKey = self.hotkey, |
502 } | 427 } |
503 ) | 428 ) |
504 | 429 |
505 self:Refresh() | 430 self:Refresh() |
431 self:UpdateHotkey() | |
506 self:SetKeybindMode(ReAction:GetKeybindMode()) | 432 self:SetKeybindMode(ReAction:GetKeybindMode()) |
507 | 433 |
508 return self | 434 return self |
509 end | 435 end |
510 | 436 |
519 _G[self.name] = nil | 445 _G[self.name] = nil |
520 end | 446 end |
521 if self.config.actionID then | 447 if self.config.actionID then |
522 ActionIDList[self.config.actionID] = nil | 448 ActionIDList[self.config.actionID] = nil |
523 end | 449 end |
450 f._reactionButton = nil | |
524 self.frame = nil | 451 self.frame = nil |
525 self.config = nil | 452 self.config = nil |
526 self.bar = nil | 453 self.bar = nil |
527 end | 454 end |
528 | 455 |
549 return self.config.actionID | 476 return self.config.actionID |
550 end | 477 end |
551 | 478 |
552 function Button:Update() | 479 function Button:Update() |
553 local id = self.frame:GetID() | 480 local id = self.frame:GetID() |
554 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id); | 481 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id) |
555 local f = self.frame | 482 local f = self.frame |
556 --ReAction:Print(("id %d: '%s', '%s', '%s', '%s', '%s', '%s', '%s'"):format(tostring(id), tostring(name),tostring(subtext),tostring(texture),tostring(isToken),tostring(isActive),tostring(autoCastAllowed),tostring(autoCastEnabled))) | |
557 | 483 |
558 if isToken then | 484 if isToken then |
559 self.icon:SetTexture(_G[texture]); | 485 self.icon:SetTexture(_G[texture]) |
560 f.tooltipName = _G[name]; | 486 f.tooltipName = _G[name] |
561 else | 487 else |
562 self.icon:SetTexture(texture); | 488 self.icon:SetTexture(texture) |
563 f.tooltipName = name; | 489 f.tooltipName = name |
564 end | 490 end |
565 | 491 |
566 f.isToken = isToken; | 492 f.isToken = isToken |
567 f.tooltipSubtext = subtext; | 493 f.tooltipSubtext = subtext |
568 f:SetChecked( isActive and 1 or 0); | 494 f:SetChecked( isActive and 1 or 0) |
569 | 495 |
570 if autoCastAllowed then | 496 if autoCastAllowed then |
571 self.acTex:Show(); | 497 self.acTex:Show() |
572 else | 498 else |
573 self.acTex:Hide(); | 499 self.acTex:Hide() |
574 end | 500 end |
575 | 501 |
576 if autoCastEnabled then | 502 if autoCastEnabled then |
577 AutoCastShine_AutoCastStart(self.acModel) | 503 AutoCastShine_AutoCastStart(self.acModel) |
578 else | 504 else |
583 if GetPetActionSlotUsable(id) then | 509 if GetPetActionSlotUsable(id) then |
584 SetDesaturation(self.icon,nil) | 510 SetDesaturation(self.icon,nil) |
585 else | 511 else |
586 SetDesaturation(self.icon,1) | 512 SetDesaturation(self.icon,1) |
587 end | 513 end |
588 self.icon:Show(); | 514 self.icon:Show() |
589 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2"); | 515 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2") |
590 else | 516 else |
591 self.icon:Hide(); | 517 self.icon:Hide() |
592 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot"); | 518 f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot") |
593 end | 519 end |
594 | 520 |
595 self:UpdateCooldown() | 521 self:UpdateCooldown() |
596 end | 522 end |
597 | 523 |
598 function Button:UpdateCooldown() | 524 function Button:UpdateCooldown() |
599 local start, duration, enable = GetPetActionCooldown(self.frame:GetID()); | 525 local start, duration, enable = GetPetActionCooldown(self.frame:GetID()) |
600 CooldownFrame_SetTimer(self.cooldown, start, duration, enable); | 526 CooldownFrame_SetTimer(self.cooldown, start, duration, enable) |
601 end | 527 end |
602 | 528 |
603 function Button:UpdateHotkey() | 529 function Button:UpdateHotkey() |
604 self:DisplayHotkey(GetHotkey(self.frame)) | 530 self.hotkey:SetText(GetHotkey(self.frame) or "") |
605 end | 531 end |
606 | 532 |
607 function Button:ShowActionIDLabel(show) | 533 function Button:ShowActionIDLabel(show) |
608 if show then | 534 if show then |
609 -- store the action ID label in the frame due to frame recycling | 535 -- store the action ID label in the frame due to frame recycling |
623 end | 549 end |
624 | 550 |
625 | 551 |
626 function Button:SetKeybindMode(mode) | 552 function Button:SetKeybindMode(mode) |
627 if mode then | 553 if mode then |
554 local f = self.frame | |
555 f.GetActionName = GetActionName | |
556 f.GetHotkey = GetHotkey | |
628 self.border:SetVertexColor(KB:GetColorKeyBoundMode()) | 557 self.border:SetVertexColor(KB:GetColorKeyBoundMode()) |
629 self.border:Show() | 558 self.border:Show() |
630 else | 559 else |
631 self.border:Hide() | 560 self.border:Hide() |
632 end | 561 end |
633 end | 562 end |
634 | 563 |
635 function Button:DisplayHotkey( key ) | |
636 self.hotkey:SetText(key or "") | |
637 end |