annotate modules/Stance.lua @ 179:bf64e71701e2

Remove support for hunter aspects in stance bar. Remove option to disable DK/paladin auras in stance bar. (drycoded)
author Flick <flickerstreak@gmail.com>
date Wed, 20 Oct 2010 23:40:41 +0000
parents df68b5a40490
children e63aefb8a555
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.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
flickerstreak@134 34 ReAction.RegisterCallback(self, "OnDestroyBar")
flickerstreak@134 35 ReAction.RegisterCallback(self, "OnRefreshBar")
flickerstreak@134 36 ReAction.RegisterCallback(self, "OnEraseBar")
flickerstreak@134 37 ReAction.RegisterCallback(self, "OnRenameBar")
flickerstreak@134 38 end
flickerstreak@134 39
flickerstreak@134 40 function module:OnEnable()
flickerstreak@134 41 ReAction:RegisterBarType(L["Stance Bar"],
flickerstreak@134 42 {
flickerstreak@134 43 type = moduleID ,
flickerstreak@134 44 defaultButtonSize = 36,
flickerstreak@134 45 defaultBarRows = 1,
flickerstreak@179 46 defaultBarCols = 6,
flickerstreak@134 47 defaultBarSpacing = 3
flickerstreak@134 48 })
flickerstreak@134 49
flickerstreak@134 50 end
flickerstreak@134 51
flickerstreak@134 52 function module:OnDisable()
flickerstreak@134 53 ReAction:UnregisterBarType(L["Stance Bar"])
flickerstreak@134 54 end
flickerstreak@134 55
flickerstreak@134 56 function module:OnDestroyBar(event, bar, name)
flickerstreak@134 57 local btns = self.buttons[bar]
flickerstreak@134 58 if btns then
flickerstreak@134 59 for _,b in pairs(btns) do
flickerstreak@134 60 if b then
flickerstreak@134 61 b:Destroy()
flickerstreak@134 62 end
flickerstreak@134 63 end
flickerstreak@134 64 self.buttons[bar] = nil
flickerstreak@134 65 end
flickerstreak@134 66 end
flickerstreak@134 67
flickerstreak@134 68 function module:OnRefreshBar(event, bar, name)
flickerstreak@134 69 if bar.config.type == moduleID then
flickerstreak@134 70 local btns = self.buttons[bar]
flickerstreak@134 71 if btns == nil then
flickerstreak@134 72 btns = { }
flickerstreak@134 73 self.buttons[bar] = btns
flickerstreak@134 74 end
flickerstreak@134 75 local profile = self.db.profile
flickerstreak@134 76 if profile.buttons[name] == nil then
flickerstreak@134 77 profile.buttons[name] = {}
flickerstreak@134 78 end
flickerstreak@134 79 local btnCfg = profile.buttons[name]
flickerstreak@134 80
flickerstreak@134 81 local r, c = bar:GetButtonGrid()
flickerstreak@134 82 local n = r*c
flickerstreak@134 83 for i = 1, n do
flickerstreak@134 84 if btnCfg[i] == nil then
flickerstreak@134 85 btnCfg[i] = {}
flickerstreak@134 86 end
flickerstreak@134 87 if btns[i] == nil then
flickerstreak@134 88 local success, r = pcall(Button.New,Button,i,profile,bar,i>1 and btnCfg[i-1].stanceID)
flickerstreak@134 89 if success and r then
flickerstreak@134 90 btns[i] = r
flickerstreak@134 91 bar:AddButton(i,r)
flickerstreak@134 92 else
flickerstreak@134 93 n = i - 1
flickerstreak@134 94 bar:ClipNButtons(n)
flickerstreak@134 95 break
flickerstreak@134 96 end
flickerstreak@134 97 end
flickerstreak@134 98 btns[i]:Refresh()
flickerstreak@134 99 end
flickerstreak@134 100 for i = n+1, #btns do
flickerstreak@134 101 if btns[i] then
flickerstreak@134 102 bar:RemoveButton(btns[i])
flickerstreak@134 103 btns[i] = btns[i]:Destroy()
flickerstreak@134 104 if btnCfg[i] then
flickerstreak@134 105 btnCfg[i] = nil
flickerstreak@134 106 end
flickerstreak@134 107 end
flickerstreak@134 108 end
flickerstreak@134 109 end
flickerstreak@134 110
flickerstreak@134 111 end
flickerstreak@134 112
flickerstreak@134 113 function module:OnEraseBar(event, bar, name)
flickerstreak@134 114 self.db.profile.buttons[name] = nil
flickerstreak@134 115 end
flickerstreak@134 116
flickerstreak@134 117 function module:OnRenameBar(event, bar, oldName, newName)
flickerstreak@134 118 local b = self.db.profile.buttons
flickerstreak@134 119 b[newname], b[oldname] = b[oldname], nil
flickerstreak@134 120 end
flickerstreak@134 121
flickerstreak@134 122 function module:RefreshAll()
flickerstreak@134 123 for bar in pairs(self.buttons) do
flickerstreak@134 124 self:OnRefreshBar(nil,bar,bar:GetName())
flickerstreak@134 125 end
flickerstreak@134 126 end
flickerstreak@134 127