diff 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
line wrap: on
line diff
--- a/modules/PetAction.lua	Fri Jan 23 23:40:13 2009 +0000
+++ b/modules/PetAction.lua	Fri Jan 23 23:44:55 2009 +0000
@@ -296,90 +296,22 @@
 
 local frameRecycler = {}
 local trash = CreateFrame("Frame")
-local KBAttach, GetActionName, GetHotkey, SetKey, FreeKey, ClearBindings, GetBindings, OnEnter, OnLeave
-do
-  local buttonLookup = setmetatable({},{__mode="kv"})
 
-  -- Use KeyBound-1.0 for binding, but use Override bindings instead of
-  -- regular bindings to support multiple profile use. This is a little
-  -- weird with the KeyBound dialog box (which has per-char selector as well
-  -- as an OK/Cancel box) but it's the least amount of effort to implement.
-  function GetActionName(f)
-    local b = buttonLookup[f]
-    if b then
-      return format("%s:%s", b.bar:GetName(), b.idx)
-    end
+local function GetActionName(f)
+  local b = f and f._reactionButton
+  if b then
+    return format("%s:%s", b.bar:GetName(), b.idx)
   end
+end
 
-  function GetHotkey(f)
-    local b = buttonLookup[f]
-    if b then
-      return KB:ToShortKey(b:GetConfig().hotkey)
-    end
-  end
+local function GetHotkey(f)
+  return KB:ToShortKey(GetBindingKey(format("CLICK %s:LeftButton",f:GetName())))
+end
 
-  function SetKey(f, key)
-    local b = buttonLookup[f]
-    if b then
-      local c = b:GetConfig()
-      if c.hotkey then
-        SetOverrideBinding(f, false, c.hotkey, nil)
-      end
-      if key then
-        SetOverrideBindingClick(f, false, key, f:GetName(), nil)
-      end
-      c.hotkey = key
-      b:DisplayHotkey(GetHotkey(f))
-    end
-  end
-
-  function FreeKey(f, key)
-    local b = buttonLookup[f]
-    if b then
-      local c = b:GetConfig()
-      if c.hotkey == key then
-        local action = f:GetActionName()
-        SetOverrideBinding(f, false, c.hotkey, nil)
-        c.hotkey = nil
-        b:DisplayHotkey(nil)
-        return action
-      end
-    end
-    return ReAction:FreeOverrideHotkey(key)
-  end
-
-  function ClearBindings(f)
-    SetKey(f, nil)
-  end
-
-  function GetBindings(f)
-    local b = buttonLookup[f]
-    if b then
-      return b:GetConfig().hotkey
-    end
-  end
-
-  function KBAttach( button )
-    local f = button:GetFrame()
-    f.GetActionName = GetActionName
-    f.GetHotkey     = GetHotkey
-    f.SetKey        = SetKey
-    f.FreeKey       = FreeKey
-    f.ClearBindings = ClearBindings
-    f.GetBindings   = GetBindings
-    buttonLookup[f] = button
-    f:SetKey(button:GetConfig().hotkey)
-    ReAction:RegisterKeybindFrame(f)
-    if ReAction:GetKeybindMode() then
-      button.border:SetVertexColor(KB:GetColorKeyBoundMode())
-      button.border:Show()
-    end
-  end
-
-  function OnEnter( self )
-    if not self.tooltipName then
-      return;
-    end
+local function OnEnter( self )
+  if ReAction:GetKeybindMode() then
+    KB:Set(self)
+  elseif self.tooltipName then
     local uber = GetCVar("UberTooltips")
     if self.isToken or (uber == "0") then
       if uber == "0" then
@@ -387,12 +319,7 @@
       else
         GameTooltip_SetDefaultAnchor(GameTooltip, self)
       end
-      local tooltip = self.tooltipName
-      local k = GetBindings(self)
-      if k then
-        tooltip = tooltip .. format(" %s(%s)%s", NORMAL_FONT_COLOR_CODE, k, FONT_COLOR_CODE_CLOSE)
-      end
-      GameTooltip:SetText(tooltip)
+      GameTooltip:SetText(self.tooltipName)
       if self.tooltipSubtext then
         GameTooltip:AddLine(self.tooltipSubtext, "", 0.5, 0.5, 0.5)
       end
@@ -402,11 +329,10 @@
       GameTooltip:SetPetAction(self:GetID())
     end
   end
+end
 
-  function OnLeave()
-    GameTooltip:Hide()
-  end
-
+local function OnLeave()
+  GameTooltip:Hide()
 end
 
 local meta = { __index = Button }
@@ -424,7 +350,7 @@
   config.name = name
   self.name = name
   config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured
-  
+
   -- have to recycle frames with the same name:
   -- otherwise you either get references to old textures because named CreateFrame()
   -- doesn't overwrite existing globals. Can't set them to nil in the global table, 
@@ -463,15 +389,16 @@
   self.hotkey   = f.hotkey
   self.border   = _G[("%sBorder"):format(name)]
 
+  f._reactionButton = self
 
-  f:RegisterEvent("PLAYER_CONTROL_LOST");
-	f:RegisterEvent("PLAYER_CONTROL_GAINED");
-	f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED");
-	f:RegisterEvent("UNIT_PET");
-	f:RegisterEvent("UNIT_FLAGS");
-	f:RegisterEvent("UNIT_AURA");
-	f:RegisterEvent("PET_BAR_UPDATE");
-	f:RegisterEvent("PET_BAR_UPDATE_COOLDOWN");
+  f:RegisterEvent("PLAYER_CONTROL_LOST")
+	f:RegisterEvent("PLAYER_CONTROL_GAINED")
+	f:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED")
+	f:RegisterEvent("UNIT_PET")
+	f:RegisterEvent("UNIT_FLAGS")
+	f:RegisterEvent("UNIT_AURA")
+	f:RegisterEvent("PET_BAR_UPDATE")
+	f:RegisterEvent("PET_BAR_UPDATE_COOLDOWN")
 
   f:SetScript("OnEvent",
     function(event,arg1)
@@ -493,8 +420,6 @@
       end
     ]])
 
-  KBAttach(self)
-
   -- attach to skinner
   bar:SkinButton(self,
     {
@@ -503,6 +428,7 @@
   )
 
   self:Refresh()
+  self:UpdateHotkey()
   self:SetKeybindMode(ReAction:GetKeybindMode())
 
   return self
@@ -521,6 +447,7 @@
   if self.config.actionID then
     ActionIDList[self.config.actionID] = nil
   end
+  f._reactionButton = nil
   self.frame = nil
   self.config = nil
   self.bar = nil
@@ -551,26 +478,25 @@
 
 function Button:Update()
   local id = self.frame:GetID()
-  local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id);
+  local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(id)
   local f = self.frame
-  --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)))
 
   if isToken then
-    self.icon:SetTexture(_G[texture]);
-    f.tooltipName = _G[name];
+    self.icon:SetTexture(_G[texture])
+    f.tooltipName = _G[name]
   else
-    self.icon:SetTexture(texture);
-    f.tooltipName = name;
+    self.icon:SetTexture(texture)
+    f.tooltipName = name
   end
 
-  f.isToken = isToken;
-	f.tooltipSubtext = subtext;
-  f:SetChecked( isActive and 1 or 0);
+  f.isToken = isToken
+	f.tooltipSubtext = subtext
+  f:SetChecked( isActive and 1 or 0)
 
   if autoCastAllowed then
-    self.acTex:Show();
+    self.acTex:Show()
   else
-    self.acTex:Hide();
+    self.acTex:Hide()
   end
 
   if autoCastEnabled then
@@ -585,23 +511,23 @@
     else
       SetDesaturation(self.icon,1)
     end
-    self.icon:Show();
-    f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2");
+    self.icon:Show()
+    f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot2")
   else
-    self.icon:Hide();
-    f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot");
+    self.icon:Hide()
+    f:SetNormalTexture("Interface\\Buttons\\UI-Quickslot")
   end
 
   self:UpdateCooldown()
 end
 
 function Button:UpdateCooldown()
-	local start, duration, enable = GetPetActionCooldown(self.frame:GetID());
-  CooldownFrame_SetTimer(self.cooldown, start, duration, enable);
+	local start, duration, enable = GetPetActionCooldown(self.frame:GetID())
+  CooldownFrame_SetTimer(self.cooldown, start, duration, enable)
 end
 
 function Button:UpdateHotkey()
-  self:DisplayHotkey(GetHotkey(self.frame))
+  self.hotkey:SetText(GetHotkey(self.frame) or "")
 end
 
 function Button:ShowActionIDLabel(show)
@@ -625,6 +551,9 @@
 
 function Button:SetKeybindMode(mode)
   if mode then
+    local f = self.frame
+    f.GetActionName = GetActionName
+    f.GetHotkey     = GetHotkey
     self.border:SetVertexColor(KB:GetColorKeyBoundMode())
     self.border:Show()
   else
@@ -632,6 +561,3 @@
   end
 end
 
-function Button:DisplayHotkey( key )
-  self.hotkey:SetText(key or "")
-end