flickerstreak@134: --[[ flickerstreak@134: ReAction Stance button module flickerstreak@134: flickerstreak@134: --]] flickerstreak@134: flickerstreak@134: -- local imports flickerstreak@134: local ReAction = ReAction flickerstreak@134: local L = ReAction.L flickerstreak@134: local _G = _G flickerstreak@134: flickerstreak@134: -- Stance button flickerstreak@134: local Button = ReAction.Button.Stance flickerstreak@134: flickerstreak@134: -- module declaration flickerstreak@134: local moduleID = "Stance" flickerstreak@134: local module = ReAction:NewModule( moduleID flickerstreak@134: -- mixins go here flickerstreak@134: ) flickerstreak@134: flickerstreak@134: -- libraries flickerstreak@134: local KB = LibStub("LibKeyBound-1.0") flickerstreak@134: flickerstreak@134: -- handlers flickerstreak@134: function module:OnInitialize() flickerstreak@134: self.db = ReAction.db:RegisterNamespace( moduleID, flickerstreak@134: { flickerstreak@134: profile = { flickerstreak@134: buttons = { } flickerstreak@134: } flickerstreak@134: } flickerstreak@134: ) flickerstreak@134: flickerstreak@134: self.buttons = { } flickerstreak@134: flickerstreak@134: ReAction:RegisterOptions(self, self:GetOptions()) flickerstreak@134: flickerstreak@134: ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnDestroyBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnRefreshBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnEraseBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnRenameBar") flickerstreak@134: ReAction.RegisterCallback(self, "OnConfigModeChanged") flickerstreak@134: flickerstreak@134: KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED") flickerstreak@134: KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED") flickerstreak@134: KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED") flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnEnable() flickerstreak@134: ReAction:RegisterBarType(L["Stance Bar"], flickerstreak@134: { flickerstreak@134: type = moduleID , flickerstreak@134: defaultButtonSize = 36, flickerstreak@134: defaultBarRows = 1, flickerstreak@134: defaultBarCols = 8, flickerstreak@134: defaultBarSpacing = 3 flickerstreak@134: }) flickerstreak@134: flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnDisable() flickerstreak@134: ReAction:UnregisterBarType(L["Stance Bar"]) flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnDestroyBar(event, bar, name) flickerstreak@134: local btns = self.buttons[bar] flickerstreak@134: if btns then flickerstreak@134: for _,b in pairs(btns) do flickerstreak@134: if b then flickerstreak@134: b:Destroy() flickerstreak@134: end flickerstreak@134: end flickerstreak@134: self.buttons[bar] = nil flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnRefreshBar(event, bar, name) flickerstreak@134: if bar.config.type == moduleID then flickerstreak@134: local btns = self.buttons[bar] flickerstreak@134: if btns == nil then flickerstreak@134: btns = { } flickerstreak@134: self.buttons[bar] = btns flickerstreak@134: end flickerstreak@134: local profile = self.db.profile flickerstreak@134: if profile.buttons[name] == nil then flickerstreak@134: profile.buttons[name] = {} flickerstreak@134: end flickerstreak@134: local btnCfg = profile.buttons[name] flickerstreak@134: flickerstreak@134: local r, c = bar:GetButtonGrid() flickerstreak@134: local n = r*c flickerstreak@134: for i = 1, n do flickerstreak@134: if btnCfg[i] == nil then flickerstreak@134: btnCfg[i] = {} flickerstreak@134: end flickerstreak@134: if btns[i] == nil then flickerstreak@134: local success, r = pcall(Button.New,Button,i,profile,bar,i>1 and btnCfg[i-1].stanceID) flickerstreak@134: if success and r then flickerstreak@134: btns[i] = r flickerstreak@134: bar:AddButton(i,r) flickerstreak@134: else flickerstreak@134: n = i - 1 flickerstreak@134: bar:ClipNButtons(n) flickerstreak@134: break flickerstreak@134: end flickerstreak@134: end flickerstreak@134: btns[i]:Refresh() flickerstreak@134: end flickerstreak@134: for i = n+1, #btns do flickerstreak@134: if btns[i] then flickerstreak@134: bar:RemoveButton(btns[i]) flickerstreak@134: btns[i] = btns[i]:Destroy() flickerstreak@134: if btnCfg[i] then flickerstreak@134: btnCfg[i] = nil flickerstreak@134: end flickerstreak@134: end flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnEraseBar(event, bar, name) flickerstreak@134: self.db.profile.buttons[name] = nil flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnRenameBar(event, bar, oldName, newName) flickerstreak@134: local b = self.db.profile.buttons flickerstreak@134: b[newname], b[oldname] = b[oldname], nil flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:OnConfigModeChanged(event, mode) flickerstreak@134: for bar in pairs(self.buttons) do flickerstreak@134: for b in bar:IterateButtons() do flickerstreak@134: b:UpdateActionIDLabel(mode) flickerstreak@134: end flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:LIBKEYBOUND_ENABLED(evt) flickerstreak@134: for _, buttons in pairs(self.buttons) do flickerstreak@134: for _, b in pairs(buttons) do flickerstreak@134: b:SetKeybindMode(true) flickerstreak@134: end flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:LIBKEYBOUND_DISABLED(evt) flickerstreak@134: for _, buttons in pairs(self.buttons) do flickerstreak@134: for _, b in pairs(buttons) do flickerstreak@134: b:SetKeybindMode(false) flickerstreak@134: end flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: function module:RefreshAll() flickerstreak@134: for bar in pairs(self.buttons) do flickerstreak@134: self:OnRefreshBar(nil,bar,bar:GetName()) flickerstreak@134: end flickerstreak@134: end flickerstreak@134: flickerstreak@134: flickerstreak@134: ---- options ---- flickerstreak@134: function module:GetOptions() flickerstreak@134: return { flickerstreak@134: stance = flickerstreak@134: { flickerstreak@134: name = L["Stance Buttons"], flickerstreak@134: type = "group", flickerstreak@134: args = { flickerstreak@134: showAspects = { flickerstreak@134: name = L["Show Aspects"], flickerstreak@134: desc = L["Show Hunter aspects as stances"], flickerstreak@134: order = 1, flickerstreak@134: width = "double", flickerstreak@134: type = "toggle", flickerstreak@134: set = function(info,value) self.db.profile.showHunterAspects = value; self:RefreshAll() end, flickerstreak@134: get = function() return self.db.profile.showHunterAspects end, flickerstreak@134: }, flickerstreak@134: hideMonkeyHawk = { flickerstreak@134: name = L["Auto-hide Monkey/Hawk"], flickerstreak@134: desc = L["Hide Aspect of the Monkey and Aspect of the Hawk, only when the hunter knows Aspect of the Dragonhawk"], flickerstreak@134: order = 2, flickerstreak@134: width = "double", flickerstreak@134: type = "toggle", flickerstreak@134: set = function(info,value) self.db.profile.hideMonkeyHawk = value; self:RefreshAll() end, flickerstreak@134: get = function() return self.db.profile.hideMonkeyHawk end, flickerstreak@134: disabled = function() return self.db.profile.showHunterAspects == false end, flickerstreak@134: }, flickerstreak@134: hidePresences = { flickerstreak@134: name = L["Hide Presences"], flickerstreak@134: desc = L["Do not show Death Knight Presences as stances"], flickerstreak@134: order = 3, flickerstreak@134: width = "double", flickerstreak@134: type = "toggle", flickerstreak@134: set = function(info,value) self.db.profile.hideDKPresences = value; self:RefreshAll() end, flickerstreak@134: get = function() return self.db.profile.hideDKPresences end, flickerstreak@134: }, flickerstreak@134: hideAuras = { flickerstreak@134: name = L["Hide Auras"], flickerstreak@134: desc = L["Do not show Paladin Auras as stances"], flickerstreak@134: order = 4, flickerstreak@134: width = "double", flickerstreak@134: type = "toggle", flickerstreak@134: set = function(info,value) self.db.profile.hidePaladinAuras = value; self:RefreshAll() end, flickerstreak@134: get = function() return self.db.profile.hidePaladinAuras end, flickerstreak@134: }, flickerstreak@134: } flickerstreak@134: } flickerstreak@134: } flickerstreak@134: end