annotate modules/PetAction.lua @ 226:76932cdb3d57

Removed tag 1.1 Beta 1
author Flick
date Sat, 19 Mar 2011 10:23:34 -0700
parents c4b134512c50
children 0e20f65375d5
rev   line source
flickerstreak@28 1 --[[
flickerstreak@53 2 ReAction Pet Action button module
flickerstreak@53 3
flickerstreak@53 4 The button module implements standard action button functionality by wrapping Blizzard's
flickerstreak@77 5 PetActionButton frame and associated functions.
flickerstreak@28 6
flickerstreak@28 7 --]]
flickerstreak@28 8
flickerstreak@28 9 -- local imports
flickerstreak@175 10 local addonName, addonTable = ...
flickerstreak@175 11 local ReAction = addonTable.ReAction
flickerstreak@28 12 local L = ReAction.L
flickerstreak@28 13 local _G = _G
flickerstreak@53 14 local CreateFrame = CreateFrame
flickerstreak@95 15 local format = string.format
flickerstreak@28 16
flickerstreak@28 17 -- module declaration
flickerstreak@28 18 local moduleID = "PetAction"
flickerstreak@28 19 local module = ReAction:NewModule( moduleID )
flickerstreak@28 20
flickerstreak@130 21 -- Button class
flickerstreak@130 22 local Button = ReAction.Button.PetAction
flickerstreak@77 23
flickerstreak@102 24 -- private
flickerstreak@102 25 local function UpdateButtonLock(bar)
flickerstreak@102 26 local f = bar:GetFrame()
flickerstreak@102 27 f:SetAttribute("lockbuttons",bar.config.lockButtons)
flickerstreak@102 28 f:SetAttribute("lockbuttonscombat",bar.config.lockButtonsCombat)
flickerstreak@102 29 f:Execute(
flickerstreak@102 30 [[
flickerstreak@102 31 lockButtons = self:GetAttribute("lockbuttons")
flickerstreak@102 32 lockButtonsCombat = self:GetAttribute("lockbuttonscombat")
flickerstreak@102 33 ]])
flickerstreak@102 34 end
flickerstreak@102 35
flickerstreak@28 36 -- module methods
flickerstreak@28 37 function module:OnInitialize()
flickerstreak@53 38 self.buttons = { }
flickerstreak@63 39
flickerstreak@63 40 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
flickerstreak@63 41
flickerstreak@63 42 ReAction.RegisterCallback(self, "OnCreateBar")
flickerstreak@63 43 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@63 44 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@28 45 end
flickerstreak@28 46
flickerstreak@63 47 function module:OnCreateBar(event, bar, name)
flickerstreak@53 48 if bar.config.type == moduleID then
flickerstreak@53 49 -- auto show/hide when pet exists
flickerstreak@148 50 bar:RegisterUnitWatch("pet",true)
flickerstreak@63 51 self:OnRefreshBar(event, bar, name)
flickerstreak@28 52 end
flickerstreak@28 53 end
flickerstreak@28 54
flickerstreak@63 55 function module:OnRefreshBar(event, bar, name)
flickerstreak@222 56 local config = bar:GetConfig()
flickerstreak@222 57 if config.type == moduleID then
flickerstreak@53 58 if self.buttons[bar] == nil then
flickerstreak@53 59 self.buttons[bar] = { }
flickerstreak@53 60 end
flickerstreak@53 61 local btns = self.buttons[bar]
flickerstreak@222 62 if not config.buttons then
flickerstreak@222 63 config.buttons = { }
flickerstreak@53 64 end
flickerstreak@222 65 local btnCfg = config.buttons
flickerstreak@53 66
flickerstreak@53 67 local r, c = bar:GetButtonGrid()
flickerstreak@53 68 local n = r*c
flickerstreak@53 69 for i = 1, n do
flickerstreak@53 70 if btnCfg[i] == nil then
flickerstreak@53 71 btnCfg[i] = {}
flickerstreak@53 72 end
flickerstreak@53 73 if btns[i] == nil then
flickerstreak@130 74 local success, r = pcall(Button.New,Button,i,btnCfg[i],bar,i>1 and btnCfg[i-1].actionID)
flickerstreak@94 75 if success and r then
flickerstreak@94 76 btns[i] = r
flickerstreak@94 77 bar:AddButton(i,r)
flickerstreak@94 78 else
flickerstreak@94 79 n = i - 1
flickerstreak@94 80 bar:ClipNButtons(n)
flickerstreak@94 81 break
flickerstreak@94 82 end
flickerstreak@53 83 end
flickerstreak@77 84 btns[i]:Refresh()
flickerstreak@53 85 end
flickerstreak@53 86 for i = n+1, #btns do
flickerstreak@53 87 if btns[i] then
flickerstreak@77 88 bar:RemoveButton(btns[i])
flickerstreak@53 89 btns[i] = btns[i]:Destroy()
flickerstreak@53 90 if btnCfg[i] then
flickerstreak@53 91 btnCfg[i] = nil
flickerstreak@53 92 end
flickerstreak@53 93 end
flickerstreak@53 94 end
flickerstreak@102 95 UpdateButtonLock(bar)
flickerstreak@53 96 end
flickerstreak@53 97 end
flickerstreak@53 98
flickerstreak@63 99 function module:OnDestroyBar(event, bar, name)
flickerstreak@53 100 if self.buttons[bar] then
flickerstreak@53 101 local btns = self.buttons[bar]
flickerstreak@53 102 for _,b in pairs(btns) do
flickerstreak@53 103 if b then
flickerstreak@53 104 b:Destroy()
flickerstreak@53 105 end
flickerstreak@53 106 end
flickerstreak@53 107 self.buttons[bar] = nil
flickerstreak@53 108 end
flickerstreak@53 109 end
flickerstreak@53 110
flickerstreak@53 111
flickerstreak@53 112
flickerstreak@60 113 ---- Options ----
flickerstreak@102 114 local Handler = { }
flickerstreak@102 115 local meta = { __index = Handler }
flickerstreak@102 116
flickerstreak@102 117 function Handler:New(bar)
flickerstreak@102 118 return setmetatable(
flickerstreak@102 119 {
flickerstreak@102 120 bar = bar,
flickerstreak@102 121 config = bar.config
flickerstreak@102 122 }, meta)
flickerstreak@102 123 end
flickerstreak@102 124
flickerstreak@102 125 function Handler:GetLockButtons()
flickerstreak@130 126 return self.config.lockButtons
flickerstreak@102 127 end
flickerstreak@102 128
flickerstreak@102 129 function Handler:SetLockButtons(info, value)
flickerstreak@102 130 self.config.lockButtons = value
flickerstreak@102 131 UpdateButtonLock(self.bar)
flickerstreak@102 132 end
flickerstreak@102 133
flickerstreak@102 134 function Handler:GetLockButtonsCombat()
flickerstreak@102 135 return self.config.lockButtonsCombat
flickerstreak@102 136 end
flickerstreak@102 137
flickerstreak@102 138 function Handler:SetLockButtonsCombat(info, value)
flickerstreak@102 139 self.config.lockButtonsCombat = value
flickerstreak@102 140 UpdateButtonLock(self.bar)
flickerstreak@102 141 end
flickerstreak@102 142
flickerstreak@102 143 function Handler:LockButtonsCombatDisabled()
flickerstreak@130 144 return not self.config.lockButtons
flickerstreak@102 145 end
flickerstreak@102 146
flickerstreak@102 147
flickerstreak@60 148 function module:GetBarOptions(bar)
flickerstreak@91 149 if bar.config.type == moduleID then
flickerstreak@91 150 return {
flickerstreak@91 151 type = "group",
flickerstreak@91 152 name = L["Pet Buttons"],
flickerstreak@102 153 handler = Handler:New(bar),
flickerstreak@91 154 args = {
flickerstreak@102 155 lockButtons = {
flickerstreak@102 156 name = L["Lock Buttons"],
flickerstreak@147 157 desc = L["Prevents picking up/dragging actions (use SHIFT to override this behavior)"],
flickerstreak@102 158 order = 2,
flickerstreak@102 159 type = "toggle",
flickerstreak@102 160 get = "GetLockButtons",
flickerstreak@102 161 set = "SetLockButtons",
flickerstreak@102 162 },
flickerstreak@102 163 lockOnlyCombat = {
flickerstreak@102 164 name = L["Only in Combat"],
flickerstreak@102 165 desc = L["Only lock the buttons when in combat"],
flickerstreak@102 166 order = 3,
flickerstreak@102 167 type = "toggle",
flickerstreak@102 168 disabled = "LockButtonsCombatDisabled",
flickerstreak@102 169 get = "GetLockButtonsCombat",
flickerstreak@102 170 set = "SetLockButtonsCombat",
flickerstreak@102 171 },
flickerstreak@91 172 }
flickerstreak@60 173 }
flickerstreak@91 174 end
flickerstreak@59 175 end
flickerstreak@59 176
flickerstreak@53 177