flickerstreak@1: -- ReAction.lua flickerstreak@1: -- flickerstreak@1: -- Top-level file for the ReAction Action Bar add-on flickerstreak@1: -- flickerstreak@1: -- ReAction is implemented in terms of the Ace 2 library: http://www.wowace.com flickerstreak@1: -- flickerstreak@1: flickerstreak@1: -- key binding label constants flickerstreak@2: BINDING_HEADER_REACTION = "ReAction" flickerstreak@2: BINDING_NAME_REACTION_TOGGLELOCK = "Lock/Unlock ReAction Bars" flickerstreak@2: BINDING_NAME_REBINDER_TOGGLEBINDINGMODE = "Toggle ReAction keybinding mode" flickerstreak@1: flickerstreak@1: -- ReAction addon setup via Ace 2 flickerstreak@1: ReAction = AceLibrary("AceAddon-2.0"):new( flickerstreak@1: "AceConsole-2.0", flickerstreak@1: "AceEvent-2.0", flickerstreak@1: "AceDB-2.0", flickerstreak@1: "FuBarPlugin-2.0" flickerstreak@1: ) flickerstreak@1: flickerstreak@2: local function tcopy(t) flickerstreak@2: local r = { } flickerstreak@2: for k, v in pairs(t) do flickerstreak@2: r[k] = (type(v) == "table" and tcopy(v) or v) flickerstreak@2: end flickerstreak@2: return r flickerstreak@2: end flickerstreak@2: flickerstreak@1: -- FuBar plugin setup flickerstreak@1: ReAction.hasIcon = false flickerstreak@1: ReAction.hasNoColor = true flickerstreak@2: ReAction.hideMenuTitle = true flickerstreak@1: ReAction.defaultPosition = "RIGHT" flickerstreak@1: ReAction.defaultMinimapPosition = 240 -- degrees flickerstreak@2: ReAction.OnMenuRequest = tcopy(ReActionGlobalMenuOptions) flickerstreak@1: flickerstreak@1: -- initial non-persistent state flickerstreak@1: ReAction.locked = true flickerstreak@1: flickerstreak@1: -- localization flickerstreak@1: -- local L = AceLibrary("AceLocale-2.0"):new("ReAction") flickerstreak@1: flickerstreak@1: flickerstreak@1: flickerstreak@1: -- Event handling flickerstreak@1: function ReAction:OnInitialize() flickerstreak@1: self:RegisterChatCommand( {"/reaction", "/rxn"}, ReActionConsoleOptions, "REACTION" ) flickerstreak@1: flickerstreak@1: self:RegisterDB("ReActionDB","ReActionDBPC") flickerstreak@1: self:RegisterDefaults("profile", ReActionProfileDefaults) flickerstreak@1: self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown") flickerstreak@2: self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars") flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:OnEnable() flickerstreak@1: if self.db.profile.firstRunDone ~= true then flickerstreak@1: -- Do some "first-run" setup flickerstreak@1: self.db.profile.firstRunDone = true flickerstreak@1: elseif self.db.profile.disabled == true then flickerstreak@1: -- print some kind of a warning flickerstreak@1: end flickerstreak@2: self:SetupBars() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:OnDisable() flickerstreak@1: self:Lock() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:OnProfileEnable() flickerstreak@1: -- handle profile switching flickerstreak@2: self:Lock() flickerstreak@1: self:SetupBars() flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:CombatLockdown() flickerstreak@1: if not self:IsLocked() then flickerstreak@1: self:Lock() flickerstreak@1: UIErrorsFrame:AddMessage("ReAction bars locked when in combat") flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: -- lock/unlock ReAction flickerstreak@1: function ReAction:SetLocked( lock ) flickerstreak@2: if lock ~= self.locked then flickerstreak@2: if not lock then flickerstreak@2: self:Print("Buttons disabled while unlocked") flickerstreak@2: end flickerstreak@2: if not lock and InCombatLockdown() then flickerstreak@2: UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) flickerstreak@2: else flickerstreak@2: self.locked = lock and true or false -- force data integrity flickerstreak@2: for _, bar in pairs(self.bars) do flickerstreak@2: if self.locked then bar:HideControls() else bar:ShowControls() end flickerstreak@2: end flickerstreak@2: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:IsLocked() flickerstreak@1: return self.locked flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:Lock() flickerstreak@1: self:SetLocked(true) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:Unlock() flickerstreak@1: self:SetLocked(false) flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:ToggleLocked() flickerstreak@1: ReAction:SetLocked( not(self.locked) ) flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: flickerstreak@1: -- Hide the default Blizzard main bar artwork flickerstreak@1: function ReAction:HideArt() flickerstreak@1: if self.db.profile.hideArt then flickerstreak@1: MainMenuBar:Hide() -- this also hides the bags, xp bar, lag meter, and micro menu buttons. flickerstreak@1: else flickerstreak@1: MainMenuBar:Show() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:IsArtHidden() flickerstreak@1: return self.db.profile.hideArt flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:SetHideArt( hide ) flickerstreak@2: if InCombatLockdown() then flickerstreak@2: UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) flickerstreak@2: else flickerstreak@2: self.db.profile.hideArt = hide and true or false -- force data integrity flickerstreak@2: self:HideArt() flickerstreak@2: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:ToggleHideArt() flickerstreak@1: self:SetHideArt( not self:IsArtHidden() ) flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: flickerstreak@1: -- Keybinding color coding flickerstreak@1: function ReAction:SetKeyColorCoding( cc ) flickerstreak@1: self.db.profile.keyColorCode = cc flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:IsKeyColorCodeEnabled() flickerstreak@1: return self.db.profile.keyColorCode flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:ToggleKeyColorCoding() flickerstreak@1: self:SetKeyColorCoding(not self.db.profile.keyColorCode) flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: flickerstreak@1: -- Hide default Blizzard bars flickerstreak@1: local blizzDefaultBars = { flickerstreak@1: ActionButton1, flickerstreak@1: ActionButton2, flickerstreak@1: ActionButton3, flickerstreak@1: ActionButton4, flickerstreak@1: ActionButton5, flickerstreak@1: ActionButton6, flickerstreak@1: ActionButton7, flickerstreak@1: ActionButton8, flickerstreak@1: ActionButton9, flickerstreak@1: ActionButton10, flickerstreak@1: ActionButton11, flickerstreak@1: ActionButton12, flickerstreak@1: BonusActionBarFrame, flickerstreak@1: MultiBarLeft, flickerstreak@1: MultiBarRight, flickerstreak@1: MultiBarBottomLeft, flickerstreak@1: MultiBarBottomRight flickerstreak@1: } flickerstreak@1: flickerstreak@1: function ReAction:HideDefaultBars() flickerstreak@1: for _, f in pairs(blizzDefaultBars) do flickerstreak@2: f:UnregisterAllEvents() flickerstreak@1: f:Hide() flickerstreak@2: f:SetParent(ReActionButtonRecycler) -- I mean it! flickerstreak@2: f:ClearAllPoints() -- no, I really mean it! flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: -- Reset bars to defaults flickerstreak@1: function ReAction:ResetBars() flickerstreak@2: if InCombatLockdown() then flickerstreak@2: UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) flickerstreak@2: else flickerstreak@2: self.db.profile.bars = ReActionProfileDefaults.bars flickerstreak@2: self:SetupBars() flickerstreak@2: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: -- re-sync action IDs flickerstreak@1: function ReAction:ResyncActionIDs() flickerstreak@1: -- TODO flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: flickerstreak@1: -- Bar manipulation flickerstreak@1: ReAction.bars = { } flickerstreak@1: flickerstreak@1: function ReAction:SetupBars() flickerstreak@1: -- hide the default Blizzard art, if configued flickerstreak@1: self:HideArt() flickerstreak@1: -- hide the default Blizzard bars flickerstreak@1: self:HideDefaultBars() flickerstreak@1: flickerstreak@1: -- set up the bars from the profile flickerstreak@2: -- note the use of table.maxn rather than # or ipairs: flickerstreak@2: -- our array of bars can in fact contain holes flickerstreak@2: for id = 1, table.maxn(self.db.profile.bars) do flickerstreak@2: local config = self.db.profile.bars[id] flickerstreak@2: if self.bars[id] then flickerstreak@2: self.bars[id]:Destroy() -- remove old version of bar if switching profiles flickerstreak@2: end flickerstreak@2: if config then flickerstreak@2: self.bars[id] = ReBar:new(config, id) flickerstreak@2: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: -- remove excess bars flickerstreak@2: for id = table.maxn(self.db.profile.bars) + 1, table.maxn(self.bars) do flickerstreak@2: if self.bars[id] then flickerstreak@2: self.bars[id]:Destroy() flickerstreak@2: self.bars[id] = nil flickerstreak@2: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: -- anchor the bars, have to do this in a second pass because flickerstreak@1: -- they might be anchored to each other in a non-ordered way flickerstreak@2: for _, bar in pairs(self.bars) do flickerstreak@1: bar:ApplyAnchor() flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: function ReAction:NewBar() flickerstreak@2: if InCombatLockdown() then flickerstreak@2: UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) flickerstreak@2: else flickerstreak@2: local c = tcopy(ReActionBarConfigDefaults) flickerstreak@2: local bar = ReBar:new(c, #self.bars+1) flickerstreak@2: table.insert(self.bars, bar) flickerstreak@2: table.insert(self.db.profile.bars, c) flickerstreak@2: if not self.locked then flickerstreak@2: bar:ShowControls() flickerstreak@2: end flickerstreak@2: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: function ReAction:DeleteBar(id) flickerstreak@2: if InCombatLockdown() then flickerstreak@2: UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) flickerstreak@2: else flickerstreak@2: if self.bars[id] then flickerstreak@2: -- we can't do tremove because each bar ID is encoded into the flickerstreak@2: -- frame names as they're created. Need a nil entry in the table. flickerstreak@2: -- The nice thing is that table.insert in NewBar() will automatically flickerstreak@2: -- find the first nil slot. flickerstreak@2: self.bars[id]:Destroy() flickerstreak@2: self.bars[id] = nil flickerstreak@2: self.db.profile.bars[id] = nil flickerstreak@2: end flickerstreak@1: end flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:ToggleActionID() flickerstreak@1: if self.showActionIDs then flickerstreak@1: ReActionButton:HideAllActionIDs() flickerstreak@1: else flickerstreak@1: ReActionButton:ShowAllActionIDs() flickerstreak@1: end flickerstreak@1: self.showActionIDs = not self.showActionIDs flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:IsActionIDVisible() flickerstreak@1: return self.showActionIDs flickerstreak@1: end flickerstreak@1: flickerstreak@1: flickerstreak@1: flickerstreak@1: -- FuBar plugin methods flickerstreak@1: local tablet = AceLibrary("Tablet-2.0") flickerstreak@1: flickerstreak@1: function ReAction:OnTooltipUpdate() flickerstreak@1: local c = tablet:AddCategory("columns", 2) flickerstreak@2: c:AddLine("text", "Bar lock", "text2", self.locked and "|cffcc0000Locked|r" or "|cff00cc00Unlocked|r") flickerstreak@2: c:AddLine("text", "Button lock", "text2", LOCK_ACTIONBAR == "1" and "|cffcc0000Locked|r" or "|cff00cc00Unlocked|r") flickerstreak@2: c:AddLine("text", "Kebinding mode", "text2", ReBinder:IsEnabled() and "|cff33ff33On|r" or "|cffffcc00Off|r") flickerstreak@2: tablet:SetHint("|cffffcc00Shift-Click|r for bar lock|n".. flickerstreak@2: "|cff33ff33Alt-Click|r for keybindings|n".. flickerstreak@2: "Right-click for menu") flickerstreak@1: end flickerstreak@1: flickerstreak@1: function ReAction:OnClick(button) flickerstreak@1: if IsShiftKeyDown() then flickerstreak@1: self:ToggleLocked() flickerstreak@2: self:UpdateDisplay() flickerstreak@2: elseif IsAltKeyDown() then flickerstreak@2: ReBinder:ToggleEnabled() flickerstreak@2: end flickerstreak@1: end