diff modules/ReAction_PossessBar/ReAction_PossessBar.lua @ 57:b85118b61564

Added possess bar control buttons (no configurability yet)
author Flick <flickerstreak@gmail.com>
date Fri, 25 Apr 2008 23:42:33 +0000
parents 8b81d4b3e73d
children 7430a8dd4e90
line wrap: on
line diff
--- a/modules/ReAction_PossessBar/ReAction_PossessBar.lua	Fri Apr 25 23:40:03 2008 +0000
+++ b/modules/ReAction_PossessBar/ReAction_PossessBar.lua	Fri Apr 25 23:42:33 2008 +0000
@@ -56,6 +56,7 @@
   if bar.config.type == moduleID then
     bar:GetFrame():SetParent(PossessBarFrame)
     bar.config.parent = "PossessBarFrame"
+    self:CreatePossessControlButtons(bar)
   end
   self:RefreshBar(bar)
 end
@@ -180,6 +181,74 @@
 end
 
 
+-- possess-bar control buttons (shows buff, cancel buff)
+function module:CreatePossessControlButton(bar,id,name)
+  -- guard against taint by reusing global variable frames
+  -- instead of nilling them out (e.g. create bar, delete bar, create bar with same name)
+  name = name or ("ReAction_%s_PossessCtrlButton%d"):format(bar:GetName(),id)
+  local b = name and _G[name]
+  if b then 
+    b:SetParent(bar:GetFrame())
+  else
+    b = CreateFrame("CheckButton", name, bar:GetFrame(), "PossessButtonTemplate")
+  end
+  b:SetID(id)
+
+  b:RegisterEvent("PLAYER_AURAS_CHANGED");
+
+  local icon = _G[("%sIcon"):format(name)]
+  local cooldown = _G[("%sCooldown"):format(name)]
+  local nTex = _G[("%sNormalTexture"):format(name)]
+  nTex:SetWidth(54)
+  nTex:SetHeight(54)
+
+  local function update()
+    local texture = GetPossessInfo(id);
+    icon:SetTexture(texture);
+    icon:Show()
+    cooldown:Hide();
+    b:SetChecked(0);
+    icon:SetVertexColor(1.0, 1.0, 1.0);
+  end
+  update()
+
+  b:HookScript("OnClick", function() b:SetChecked(0) end)
+  b:SetScript("OnEvent", update)
+  b:SetScript("OnShow", update)
+
+  return b
+end
+
+function module:CreatePossessControlButtons(bar)
+  if not bar.possessButtons then
+    bar.possessButtons = { }
+    bar.config.possessFrameNames = bar.config.possessFrameNames or { }
+    local previous
+    local n = NUM_POSSESS_SLOTS
+    for i = 1, n do
+      local name = bar.config.possessFrameNames[i]
+      local f = self:CreatePossessControlButton(bar,i,name)
+      bar.possessButtons[i] = f
+      bar.config.possessFrameNames[i] = f:GetName()
+
+      local r, c, s = bar:GetButtonGrid()
+      local w, h = bar:GetButtonSize()
+
+      local scale = ((h - (n-1)*s)/n)/30
+      f:SetScale(scale)
+
+      if previous then
+        f:SetPoint("TOP", previous, "BOTTOM", 0, -s/scale)
+      else
+        f:SetPoint("TOPRIGHT", bar:GetFrame(), "TOPLEFT", -s/scale, 0)
+      end
+      f:Show()
+      previous = f
+    end
+  end
+end
+
+
 
 -- use-count of action IDs
 local minActionID = 121
@@ -224,7 +293,7 @@
 
   local barFrame = bar:GetFrame()
 
-  config.name = config.name or "ReAction_"..bar:GetName().."_Possess_"..idx
+  config.name = config.name or ("ReAction_%s_Possess_%d"):format(bar:GetName(),idx)
   self.name = config.name
   config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured