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