annotate modules/Stance.lua @ 177:5c01c0d3bf79

updated LibShowGrid reference
author Flick <flickerstreak@gmail.com>
date Wed, 20 Oct 2010 18:30:24 +0000
parents df68b5a40490
children bf64e71701e2
rev   line source
flickerstreak@134 1 --[[
flickerstreak@134 2 ReAction Stance button module
flickerstreak@134 3
flickerstreak@134 4 --]]
flickerstreak@134 5
flickerstreak@134 6 -- local imports
flickerstreak@175 7 local addonName, addonTable = ...
flickerstreak@175 8 local ReAction = addonTable.ReAction
flickerstreak@134 9 local L = ReAction.L
flickerstreak@134 10 local _G = _G
flickerstreak@134 11
flickerstreak@134 12 -- Stance button
flickerstreak@134 13 local Button = ReAction.Button.Stance
flickerstreak@134 14
flickerstreak@134 15 -- module declaration
flickerstreak@134 16 local moduleID = "Stance"
flickerstreak@134 17 local module = ReAction:NewModule( moduleID
flickerstreak@134 18 -- mixins go here
flickerstreak@134 19 )
flickerstreak@134 20
flickerstreak@134 21 -- handlers
flickerstreak@134 22 function module:OnInitialize()
flickerstreak@134 23 self.db = ReAction.db:RegisterNamespace( moduleID,
flickerstreak@134 24 {
flickerstreak@134 25 profile = {
flickerstreak@134 26 buttons = { }
flickerstreak@134 27 }
flickerstreak@134 28 }
flickerstreak@134 29 )
flickerstreak@134 30
flickerstreak@134 31 self.buttons = { }
flickerstreak@134 32
flickerstreak@134 33 ReAction:RegisterOptions(self, self:GetOptions())
flickerstreak@134 34
flickerstreak@134 35 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
flickerstreak@134 36 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@134 37 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@134 38 ReAction.RegisterCallback(self, "OnEraseBar")
flickerstreak@134 39 ReAction.RegisterCallback(self, "OnRenameBar")
flickerstreak@134 40 end
flickerstreak@134 41
flickerstreak@134 42 function module:OnEnable()
flickerstreak@134 43 ReAction:RegisterBarType(L["Stance Bar"],
flickerstreak@134 44 {
flickerstreak@134 45 type = moduleID ,
flickerstreak@134 46 defaultButtonSize = 36,
flickerstreak@134 47 defaultBarRows = 1,
flickerstreak@134 48 defaultBarCols = 8,
flickerstreak@134 49 defaultBarSpacing = 3
flickerstreak@134 50 })
flickerstreak@134 51
flickerstreak@134 52 end
flickerstreak@134 53
flickerstreak@134 54 function module:OnDisable()
flickerstreak@134 55 ReAction:UnregisterBarType(L["Stance Bar"])
flickerstreak@134 56 end
flickerstreak@134 57
flickerstreak@134 58 function module:OnDestroyBar(event, bar, name)
flickerstreak@134 59 local btns = self.buttons[bar]
flickerstreak@134 60 if btns then
flickerstreak@134 61 for _,b in pairs(btns) do
flickerstreak@134 62 if b then
flickerstreak@134 63 b:Destroy()
flickerstreak@134 64 end
flickerstreak@134 65 end
flickerstreak@134 66 self.buttons[bar] = nil
flickerstreak@134 67 end
flickerstreak@134 68 end
flickerstreak@134 69
flickerstreak@134 70 function module:OnRefreshBar(event, bar, name)
flickerstreak@134 71 if bar.config.type == moduleID then
flickerstreak@134 72 local btns = self.buttons[bar]
flickerstreak@134 73 if btns == nil then
flickerstreak@134 74 btns = { }
flickerstreak@134 75 self.buttons[bar] = btns
flickerstreak@134 76 end
flickerstreak@134 77 local profile = self.db.profile
flickerstreak@134 78 if profile.buttons[name] == nil then
flickerstreak@134 79 profile.buttons[name] = {}
flickerstreak@134 80 end
flickerstreak@134 81 local btnCfg = profile.buttons[name]
flickerstreak@134 82
flickerstreak@134 83 local r, c = bar:GetButtonGrid()
flickerstreak@134 84 local n = r*c
flickerstreak@134 85 for i = 1, n do
flickerstreak@134 86 if btnCfg[i] == nil then
flickerstreak@134 87 btnCfg[i] = {}
flickerstreak@134 88 end
flickerstreak@134 89 if btns[i] == nil then
flickerstreak@134 90 local success, r = pcall(Button.New,Button,i,profile,bar,i>1 and btnCfg[i-1].stanceID)
flickerstreak@134 91 if success and r then
flickerstreak@134 92 btns[i] = r
flickerstreak@134 93 bar:AddButton(i,r)
flickerstreak@134 94 else
flickerstreak@134 95 n = i - 1
flickerstreak@134 96 bar:ClipNButtons(n)
flickerstreak@134 97 break
flickerstreak@134 98 end
flickerstreak@134 99 end
flickerstreak@134 100 btns[i]:Refresh()
flickerstreak@134 101 end
flickerstreak@134 102 for i = n+1, #btns do
flickerstreak@134 103 if btns[i] then
flickerstreak@134 104 bar:RemoveButton(btns[i])
flickerstreak@134 105 btns[i] = btns[i]:Destroy()
flickerstreak@134 106 if btnCfg[i] then
flickerstreak@134 107 btnCfg[i] = nil
flickerstreak@134 108 end
flickerstreak@134 109 end
flickerstreak@134 110 end
flickerstreak@134 111 end
flickerstreak@134 112
flickerstreak@134 113 end
flickerstreak@134 114
flickerstreak@134 115 function module:OnEraseBar(event, bar, name)
flickerstreak@134 116 self.db.profile.buttons[name] = nil
flickerstreak@134 117 end
flickerstreak@134 118
flickerstreak@134 119 function module:OnRenameBar(event, bar, oldName, newName)
flickerstreak@134 120 local b = self.db.profile.buttons
flickerstreak@134 121 b[newname], b[oldname] = b[oldname], nil
flickerstreak@134 122 end
flickerstreak@134 123
flickerstreak@134 124 function module:RefreshAll()
flickerstreak@134 125 for bar in pairs(self.buttons) do
flickerstreak@134 126 self:OnRefreshBar(nil,bar,bar:GetName())
flickerstreak@134 127 end
flickerstreak@134 128 end
flickerstreak@134 129
flickerstreak@134 130
flickerstreak@134 131 ---- options ----
flickerstreak@134 132 function module:GetOptions()
flickerstreak@134 133 return {
flickerstreak@134 134 stance =
flickerstreak@134 135 {
flickerstreak@134 136 name = L["Stance Buttons"],
flickerstreak@134 137 type = "group",
flickerstreak@134 138 args = {
flickerstreak@134 139 showAspects = {
flickerstreak@134 140 name = L["Show Aspects"],
flickerstreak@134 141 desc = L["Show Hunter aspects as stances"],
flickerstreak@134 142 order = 1,
flickerstreak@134 143 width = "double",
flickerstreak@134 144 type = "toggle",
flickerstreak@134 145 set = function(info,value) self.db.profile.showHunterAspects = value; self:RefreshAll() end,
flickerstreak@134 146 get = function() return self.db.profile.showHunterAspects end,
flickerstreak@134 147 },
flickerstreak@134 148 hideMonkeyHawk = {
flickerstreak@134 149 name = L["Auto-hide Monkey/Hawk"],
flickerstreak@134 150 desc = L["Hide Aspect of the Monkey and Aspect of the Hawk, only when the hunter knows Aspect of the Dragonhawk"],
flickerstreak@134 151 order = 2,
flickerstreak@134 152 width = "double",
flickerstreak@134 153 type = "toggle",
flickerstreak@134 154 set = function(info,value) self.db.profile.hideMonkeyHawk = value; self:RefreshAll() end,
flickerstreak@134 155 get = function() return self.db.profile.hideMonkeyHawk end,
flickerstreak@134 156 disabled = function() return self.db.profile.showHunterAspects == false end,
flickerstreak@134 157 },
flickerstreak@134 158 hidePresences = {
flickerstreak@134 159 name = L["Hide Presences"],
flickerstreak@134 160 desc = L["Do not show Death Knight Presences as stances"],
flickerstreak@134 161 order = 3,
flickerstreak@134 162 width = "double",
flickerstreak@134 163 type = "toggle",
flickerstreak@134 164 set = function(info,value) self.db.profile.hideDKPresences = value; self:RefreshAll() end,
flickerstreak@134 165 get = function() return self.db.profile.hideDKPresences end,
flickerstreak@134 166 },
flickerstreak@134 167 hideAuras = {
flickerstreak@134 168 name = L["Hide Auras"],
flickerstreak@134 169 desc = L["Do not show Paladin Auras as stances"],
flickerstreak@134 170 order = 4,
flickerstreak@134 171 width = "double",
flickerstreak@134 172 type = "toggle",
flickerstreak@134 173 set = function(info,value) self.db.profile.hidePaladinAuras = value; self:RefreshAll() end,
flickerstreak@134 174 get = function() return self.db.profile.hidePaladinAuras end,
flickerstreak@134 175 },
flickerstreak@134 176 }
flickerstreak@134 177 }
flickerstreak@134 178 }
flickerstreak@134 179 end