annotate modules/Totem.lua @ 178:2e2abdaad2e5

refix shadow dance and demon form states
author Flick <flickerstreak@gmail.com>
date Wed, 20 Oct 2010 18:58:36 +0000
parents df68b5a40490
children c8777ae7d460
rev   line source
flickerstreak@161 1 --[[
flickerstreak@161 2 ReAction Totem button module
flickerstreak@161 3
flickerstreak@161 4 --]]
flickerstreak@161 5
flickerstreak@161 6 -- local imports
flickerstreak@175 7 local addonName, addonTable = ...
flickerstreak@175 8 local ReAction = addonTable.ReAction
flickerstreak@161 9 local L = ReAction.L
flickerstreak@161 10 local _G = _G
flickerstreak@161 11
flickerstreak@161 12 -- button
flickerstreak@161 13 local Button = ReAction.Button.MultiCast
flickerstreak@161 14
flickerstreak@161 15 -- module declaration
flickerstreak@161 16 local moduleID = "Totem"
flickerstreak@161 17 local module = ReAction:NewModule( moduleID,
flickerstreak@161 18 "AceEvent-3.0"
flickerstreak@161 19 -- mixins go here
flickerstreak@161 20 )
flickerstreak@161 21
flickerstreak@161 22 -- handlers
flickerstreak@161 23 function module:OnInitialize()
flickerstreak@161 24 self.db = ReAction.db:RegisterNamespace( moduleID,
flickerstreak@161 25 {
flickerstreak@161 26 profile = {
flickerstreak@161 27 buttons = { }
flickerstreak@161 28 }
flickerstreak@161 29 }
flickerstreak@161 30 )
flickerstreak@161 31
flickerstreak@161 32 self.buttons = { }
flickerstreak@161 33
flickerstreak@161 34 ReAction:RegisterOptions(self, self:GetOptions())
flickerstreak@161 35
flickerstreak@161 36 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
flickerstreak@161 37 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@161 38 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@161 39 ReAction.RegisterCallback(self, "OnEraseBar")
flickerstreak@161 40 ReAction.RegisterCallback(self, "OnRenameBar")
flickerstreak@161 41
flickerstreak@162 42 self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR","PLAYER_ENTERING_WORLD")
flickerstreak@161 43 end
flickerstreak@161 44
flickerstreak@161 45 function module:OnEnable()
flickerstreak@161 46 ReAction:RegisterBarType(L["Totem Bar"],
flickerstreak@161 47 {
flickerstreak@161 48 type = moduleID ,
flickerstreak@161 49 defaultButtonSize = 36,
flickerstreak@161 50 defaultBarRows = 1,
flickerstreak@161 51 defaultBarCols = 6,
flickerstreak@161 52 defaultBarSpacing = 3
flickerstreak@161 53 })
flickerstreak@161 54
flickerstreak@161 55 end
flickerstreak@161 56
flickerstreak@161 57 function module:OnDisable()
flickerstreak@161 58 ReAction:UnregisterBarType(L["Totem Bar"])
flickerstreak@161 59 end
flickerstreak@161 60
flickerstreak@161 61 function module:OnDestroyBar(event, bar, name)
flickerstreak@161 62 local btns = self.buttons[bar]
flickerstreak@161 63 if btns then
flickerstreak@161 64 for _,b in pairs(btns) do
flickerstreak@161 65 if b then
flickerstreak@161 66 b:Destroy()
flickerstreak@161 67 end
flickerstreak@161 68 end
flickerstreak@161 69 self.buttons[bar] = nil
flickerstreak@161 70 end
flickerstreak@161 71 end
flickerstreak@161 72
flickerstreak@161 73 function module:OnRefreshBar(event, bar, name)
flickerstreak@161 74 if bar.config.type == moduleID then
flickerstreak@161 75 local btns = self.buttons[bar]
flickerstreak@161 76 if btns == nil then
flickerstreak@161 77 btns = { }
flickerstreak@161 78 self.buttons[bar] = btns
flickerstreak@161 79 end
flickerstreak@161 80 local profile = self.db.profile
flickerstreak@161 81 if profile.buttons[name] == nil then
flickerstreak@161 82 profile.buttons[name] = {}
flickerstreak@161 83 end
flickerstreak@161 84 local btnCfg = profile.buttons[name]
flickerstreak@161 85
flickerstreak@161 86 local r, c = bar:GetButtonGrid()
flickerstreak@163 87 local n = min(r*c,6)
flickerstreak@163 88 Button.SetupBarHeader(bar)
flickerstreak@161 89 for i = 1, n do
flickerstreak@161 90 if btnCfg[i] == nil then
flickerstreak@161 91 btnCfg[i] = {}
flickerstreak@161 92 end
flickerstreak@164 93 if not btns[i] then
flickerstreak@161 94 local success, r = pcall(Button.New,Button,i,btnCfg,bar)
flickerstreak@163 95 if success then
flickerstreak@161 96 btns[i] = r
flickerstreak@163 97 if r then
flickerstreak@163 98 bar:AddButton(i,r)
flickerstreak@163 99 end
flickerstreak@161 100 else
flickerstreak@161 101 geterrorhandler()(r)
flickerstreak@161 102 n = i - 1
flickerstreak@161 103 bar:ClipNButtons(n)
flickerstreak@161 104 break
flickerstreak@161 105 end
flickerstreak@161 106 end
flickerstreak@163 107 if btns[i] then
flickerstreak@163 108 btns[i]:Refresh()
flickerstreak@163 109 end
flickerstreak@161 110 end
flickerstreak@161 111 for i = n+1, #btns do
flickerstreak@161 112 if btns[i] then
flickerstreak@161 113 bar:RemoveButton(btns[i])
flickerstreak@161 114 btns[i] = btns[i]:Destroy()
flickerstreak@161 115 if btnCfg[i] then
flickerstreak@161 116 btnCfg[i] = nil
flickerstreak@161 117 end
flickerstreak@161 118 end
flickerstreak@161 119 end
flickerstreak@161 120 end
flickerstreak@161 121
flickerstreak@161 122 end
flickerstreak@161 123
flickerstreak@161 124 function module:OnEraseBar(event, bar, name)
flickerstreak@161 125 self.db.profile.buttons[name] = nil
flickerstreak@161 126 end
flickerstreak@161 127
flickerstreak@161 128 function module:OnRenameBar(event, bar, oldName, newName)
flickerstreak@161 129 local b = self.db.profile.buttons
flickerstreak@161 130 b[newname], b[oldname] = b[oldname], nil
flickerstreak@161 131 end
flickerstreak@161 132
flickerstreak@161 133 function module:RefreshAll()
flickerstreak@161 134 for bar in pairs(self.buttons) do
flickerstreak@161 135 self:OnRefreshBar(nil,bar,bar:GetName())
flickerstreak@161 136 end
flickerstreak@161 137 end
flickerstreak@161 138
flickerstreak@162 139 function module:UPDATE_MULTI_CAST_ACTIONBAR()
flickerstreak@162 140 if not InCombatLockdown() then
flickerstreak@162 141 for bar in pairs(self.buttons) do
flickerstreak@162 142 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
flickerstreak@162 143 end
flickerstreak@162 144 end
flickerstreak@162 145 end
flickerstreak@162 146
flickerstreak@162 147 function module:PLAYER_ENTERING_WORLD()
flickerstreak@162 148 for bar in pairs(self.buttons) do
flickerstreak@162 149 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
flickerstreak@162 150 end
flickerstreak@162 151 end
flickerstreak@162 152
flickerstreak@161 153
flickerstreak@161 154 ---- options ----
flickerstreak@161 155 function module:GetOptions()
flickerstreak@161 156 return {
flickerstreak@161 157 stance =
flickerstreak@161 158 {
flickerstreak@161 159 name = L["Totem Buttons"],
flickerstreak@161 160 type = "group",
flickerstreak@161 161 args = {
flickerstreak@161 162 -- TODO
flickerstreak@161 163 }
flickerstreak@161 164 }
flickerstreak@161 165 }
flickerstreak@161 166 end