diff modules/ReAction_Action/ReAction_Action.lua @ 75:06cd74bdc7da

- Cleaned up Bar interface - Move all attribute setting from Bar into State - Separated Moonkin and Tree of Life - Removed PossessBar module - Added some infrastructure for paged/mind control support to Action
author Flick <flickerstreak@gmail.com>
date Mon, 16 Jun 2008 18:46:08 +0000
parents 768be7eb22a0
children da8ba8783924
line wrap: on
line diff
--- a/modules/ReAction_Action/ReAction_Action.lua	Tue Jun 10 22:25:15 2008 +0000
+++ b/modules/ReAction_Action/ReAction_Action.lua	Mon Jun 16 18:46:08 2008 +0000
@@ -17,12 +17,28 @@
 local moduleID = "Action"
 local module = ReAction:NewModule( moduleID )
 
+-- private --
+local function GetBarConfig(bar)
+  return module.db.profile.bars[bar:GetName()]
+end
+
+local function RefreshLite(bar)
+  local btns = module.buttons[bar]
+  if btns then
+    for _, b in ipairs(btns) do
+      b:Refresh()
+    end
+  end
+end
+
+
 -- module methods
 function module:OnInitialize()
   self.db = ReAction.db:RegisterNamespace( moduleID,
     { 
       profile = {
-        buttons = { }
+        buttons = { },
+        bars = { },
       }
     }
   )
@@ -79,7 +95,11 @@
     if profile.buttons[name] == nil then
       profile.buttons[name] = {}
     end
+    if profile.bars[name] == nil then
+      profile.bars[name] = {}
+    end
     local btnCfg = profile.buttons[name]
+    local barCfg = profile.bars[name]
 
     local r, c = bar:GetButtonGrid()
     local n = r*c
@@ -88,22 +108,23 @@
         btnCfg[i] = {}
       end
       if btns[i] == nil then
-        local ok, b = pcall(self.BtnClass.new, self.BtnClass, bar, i, btnCfg[i])
+        local ok, b = pcall(self.BtnClass.New, self.BtnClass, bar, i, btnCfg[i], barCfg)
         if ok and b then
           btns[i] = b
+          bar:AddButton(i,b)
         end
-      else
-        btns[i]:Refresh(bar,i)
       end
     end
     for i = n+1, #btns do
       if btns[i] then
+        bar:RemoveButton(btns[i])
         btns[i] = btns[i]:Destroy()
         if btnCfg[i] then
           btnCfg[i] = nil
         end
       end
     end
+    RefreshLite(bar)
   end
 end
 
@@ -121,11 +142,15 @@
 
 function module:OnEraseBar(event, bar, name)
   self.db.profile.buttons[name] = nil
+  self.db.profile.bars[name] = nil
 end
 
 function module:OnRenameBar(event, bar, oldname, newname)
   local b = self.db.profile.buttons
   b[newname], b[oldname] = b[oldname], nil
+
+  b = self.db.profile.bars
+  b[newname], b[oldname] = b[oldname], nil
 end
 
 function module:SetHideEmptyButtons(hide)
@@ -163,13 +188,20 @@
 
 function module:showActionIDLabel(button)
   if not button.actionIDLabel and button:GetActionID() then
-    local label = button:GetFrame():CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
+    local f = button:GetFrame()
+    local label = f:CreateFontString(nil,"OVERLAY","GameFontNormalLarge")
     label:SetAllPoints()
     label:SetJustifyH("CENTER")
     label:SetShadowColor(0,0,0,1)
     label:SetShadowOffset(2,-2)
     label:SetText(tostring(button:GetActionID()))
     button.actionIDLabel = label
+    f:HookScript("OnAttributeChanged", 
+      function(frame, attr, value)
+        if attr == "state-parent" then
+          label:SetText(tostring(button:GetActionID()))
+        end
+      end)
   end
   button.actionIDLabel:Show()
 end
@@ -230,27 +262,33 @@
 ------ Button class ------
 local Button = { }
 
-local function Constructor( self, bar, idx, config )
-  self.bar, self.idx, self.config = bar, idx, config
+local function Constructor( self, bar, idx, config, barConfig )
+  self.bar, self.idx, self.config, self.barConfig = bar, idx, config, barConfig
 
   local barFrame = bar:GetFrame()
 
   config.name = config.name or ("ReAction_%s_%d"):format(bar:GetName(),idx)
   self.name = config.name
   config.actionID = ActionIDList[config.actionID] -- gets a free one if none configured
+  self.nPages = 1
   
   local f = CreateFrame("CheckButton", self.name, barFrame, "ActionBarButtonTemplate")
 
   -- TODO: re-implement ActionButton event handlers that don't do secure stuff
 
-  -- this will probably cause taint, using right now for display/debugging purposes
+  -- this will probably cause taint and/or performance problems, using right now for display/debugging purposes
   f:SetScript("OnAttributeChanged", ActionButton_UpdateAction)
+
   f:SetAttribute("action", config.actionID)
+  -- install mind control action support for all buttons here just for simplicity
+  if self.idx <= 12 then
+    f:SetAttribute("action-mc", 120 + self.idx)
+  end
 
   barFrame:SetAttribute("addchild",f)
 
   self.frame = f
-  self:Refresh(bar,idx)
+  self:Refresh()
 
   if not module.db.profile.hideEmptyButtons then
     ActionButton_ShowGrid(self.frame)
@@ -274,13 +312,23 @@
   if self.config.actionID then
     ActionIDList[self.config.actionID] = nil
   end
+  if self.config.pages then
+    for _, id in ipairs(self.config.pages) do
+      ActionIDList[id] = nil
+    end
+  end
   self.frame = nil
   self.config = nil
   self.bar = nil
 end
 
-function Button:Refresh(bar,idx)
-  bar:PlaceButton(self.frame, idx, 36, 36)
+function Button:Refresh()
+  local f = self.frame
+  self.bar:PlaceButton(self, 36, 36)
+  if self.barConfig.mckeybinds then
+    f:SetAttribute("bindings-mc", self.barConfig.mckeybinds[self.idx])
+  end
+  self:RefreshPages()
 end
 
 function Button:GetFrame()
@@ -292,13 +340,36 @@
 end
 
 function Button:GetActionID()
-  return self.config.actionID
+  return SecureButton_GetModifiedAttribute(self.frame, "action")
 end
 
+function Button:RefreshPages()
+  local nPages = 1 --self.bar:GetNumPages()
+  if nPages ~= self.nPages then
+    local f = self:GetFrame()
+    local c = self.config.pages
+    if nPages > 1 and not c then
+      c = { }
+      self.config.pages = c
+    end
+    for i = 1, nPages do
+      c[i] = ActionIDList[c[i]] -- gets a free one if none configured
+      f:SetAttribute(("action-page%d"):format(i))
+    end
+    for i = nPages+1, #c do
+      ActionIDList[c[i]] = nil
+      c[i] = nil
+      f:SetAttribute(("action-page%d"):format(i))
+    end
+
+    -- TODO:
+    -- apply next-page, prev-page, and direct-page keybinds (via bar:SetStateKeybind abstraction)
+  end
+end
 
 -- export as a class-factory to module
 module.BtnClass = {
-  new = function(self, ...)
+  New = function(self, ...)
     local x = { }
     for k,v in pairs(Button) do
       x[k] = v