annotate modules/Totem.lua @ 181:c8777ae7d460

remove unused Totem module options
author Flick <flickerstreak@gmail.com>
date Wed, 20 Oct 2010 23:42:40 +0000
parents df68b5a40490
children e63aefb8a555
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.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
flickerstreak@161 35 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@161 36 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@161 37 ReAction.RegisterCallback(self, "OnEraseBar")
flickerstreak@161 38 ReAction.RegisterCallback(self, "OnRenameBar")
flickerstreak@161 39
flickerstreak@162 40 self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR","PLAYER_ENTERING_WORLD")
flickerstreak@161 41 end
flickerstreak@161 42
flickerstreak@161 43 function module:OnEnable()
flickerstreak@161 44 ReAction:RegisterBarType(L["Totem Bar"],
flickerstreak@161 45 {
flickerstreak@161 46 type = moduleID ,
flickerstreak@161 47 defaultButtonSize = 36,
flickerstreak@161 48 defaultBarRows = 1,
flickerstreak@161 49 defaultBarCols = 6,
flickerstreak@161 50 defaultBarSpacing = 3
flickerstreak@161 51 })
flickerstreak@161 52
flickerstreak@161 53 end
flickerstreak@161 54
flickerstreak@161 55 function module:OnDisable()
flickerstreak@161 56 ReAction:UnregisterBarType(L["Totem Bar"])
flickerstreak@161 57 end
flickerstreak@161 58
flickerstreak@161 59 function module:OnDestroyBar(event, bar, name)
flickerstreak@161 60 local btns = self.buttons[bar]
flickerstreak@161 61 if btns then
flickerstreak@161 62 for _,b in pairs(btns) do
flickerstreak@161 63 if b then
flickerstreak@161 64 b:Destroy()
flickerstreak@161 65 end
flickerstreak@161 66 end
flickerstreak@161 67 self.buttons[bar] = nil
flickerstreak@161 68 end
flickerstreak@161 69 end
flickerstreak@161 70
flickerstreak@161 71 function module:OnRefreshBar(event, bar, name)
flickerstreak@161 72 if bar.config.type == moduleID then
flickerstreak@161 73 local btns = self.buttons[bar]
flickerstreak@161 74 if btns == nil then
flickerstreak@161 75 btns = { }
flickerstreak@161 76 self.buttons[bar] = btns
flickerstreak@161 77 end
flickerstreak@161 78 local profile = self.db.profile
flickerstreak@161 79 if profile.buttons[name] == nil then
flickerstreak@161 80 profile.buttons[name] = {}
flickerstreak@161 81 end
flickerstreak@161 82 local btnCfg = profile.buttons[name]
flickerstreak@161 83
flickerstreak@161 84 local r, c = bar:GetButtonGrid()
flickerstreak@163 85 local n = min(r*c,6)
flickerstreak@163 86 Button.SetupBarHeader(bar)
flickerstreak@161 87 for i = 1, n do
flickerstreak@161 88 if btnCfg[i] == nil then
flickerstreak@161 89 btnCfg[i] = {}
flickerstreak@161 90 end
flickerstreak@164 91 if not btns[i] then
flickerstreak@161 92 local success, r = pcall(Button.New,Button,i,btnCfg,bar)
flickerstreak@163 93 if success then
flickerstreak@161 94 btns[i] = r
flickerstreak@163 95 if r then
flickerstreak@163 96 bar:AddButton(i,r)
flickerstreak@163 97 end
flickerstreak@161 98 else
flickerstreak@161 99 geterrorhandler()(r)
flickerstreak@161 100 n = i - 1
flickerstreak@161 101 bar:ClipNButtons(n)
flickerstreak@161 102 break
flickerstreak@161 103 end
flickerstreak@161 104 end
flickerstreak@163 105 if btns[i] then
flickerstreak@163 106 btns[i]:Refresh()
flickerstreak@163 107 end
flickerstreak@161 108 end
flickerstreak@161 109 for i = n+1, #btns do
flickerstreak@161 110 if btns[i] then
flickerstreak@161 111 bar:RemoveButton(btns[i])
flickerstreak@161 112 btns[i] = btns[i]:Destroy()
flickerstreak@161 113 if btnCfg[i] then
flickerstreak@161 114 btnCfg[i] = nil
flickerstreak@161 115 end
flickerstreak@161 116 end
flickerstreak@161 117 end
flickerstreak@161 118 end
flickerstreak@161 119
flickerstreak@161 120 end
flickerstreak@161 121
flickerstreak@161 122 function module:OnEraseBar(event, bar, name)
flickerstreak@161 123 self.db.profile.buttons[name] = nil
flickerstreak@161 124 end
flickerstreak@161 125
flickerstreak@161 126 function module:OnRenameBar(event, bar, oldName, newName)
flickerstreak@161 127 local b = self.db.profile.buttons
flickerstreak@161 128 b[newname], b[oldname] = b[oldname], nil
flickerstreak@161 129 end
flickerstreak@161 130
flickerstreak@161 131 function module:RefreshAll()
flickerstreak@161 132 for bar in pairs(self.buttons) do
flickerstreak@161 133 self:OnRefreshBar(nil,bar,bar:GetName())
flickerstreak@161 134 end
flickerstreak@161 135 end
flickerstreak@161 136
flickerstreak@162 137 function module:UPDATE_MULTI_CAST_ACTIONBAR()
flickerstreak@162 138 if not InCombatLockdown() then
flickerstreak@162 139 for bar in pairs(self.buttons) do
flickerstreak@162 140 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
flickerstreak@162 141 end
flickerstreak@162 142 end
flickerstreak@162 143 end
flickerstreak@162 144
flickerstreak@162 145 function module:PLAYER_ENTERING_WORLD()
flickerstreak@162 146 for bar in pairs(self.buttons) do
flickerstreak@162 147 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
flickerstreak@162 148 end
flickerstreak@162 149 end
flickerstreak@162 150
flickerstreak@161 151