Mercurial > wow > reaction
diff ReAction.lua @ 1:c11ca1d8ed91
Version 0.1
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Tue, 20 Mar 2007 21:03:57 +0000 |
parents | |
children | 8e0ff8ae4c08 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ReAction.lua Tue Mar 20 21:03:57 2007 +0000 @@ -0,0 +1,260 @@ +-- 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" + +-- ReAction addon setup via Ace 2 +ReAction = AceLibrary("AceAddon-2.0"):new( + "AceConsole-2.0", + "AceEvent-2.0", + "AceDB-2.0", + "FuBarPlugin-2.0" +) + +-- FuBar plugin setup +ReAction.hasIcon = false +ReAction.hasNoColor = true +ReAction.defaultPosition = "RIGHT" +ReAction.defaultMinimapPosition = 240 -- degrees +ReAction.OnMenuRequest = 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") + + AceLibrary("Dewdrop-2.0"):InjectAceOptionsTable(self, ReActionProfileMenuOptions) +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 + else + self:SetupBars() + end +end + +function ReAction:OnDisable() + self:Lock() +end + +function ReAction:OnProfileEnable() + -- handle profile switching + self:SetupBars() + self:Lock() +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 ) + self.locked = lock and true or false -- force data integrity + if not self.locked then + self:Print("Buttons disabled while unlocked") + end + for _, bar in ipairs(self.bars) do + if self.locked then bar:HideControls() else bar:ShowControls() 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 ) + self.db.profile.hideArt = hide and true or false -- force data integrity + self:HideArt() +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:Hide() + f:ClearAllPoints() + f:SetParent(ReActionButtonRecycler) + f:UnregisterAllEvents() + end +end + + +-- Reset bars to defaults +function ReAction:ResetBars() + self.db.profile.bars = ReActionProfileDefaults.bars + self:SetupBars() +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 + for id, info in ipairs(self.db.profile.bars) do + if self.bars[id] then self.bars[id]:Destroy() end -- remove old version of bar if switching profiles + self.bars[id] = ReBar:new(info, id) + end + + -- remove excess bars + while #self.bars > #self.db.profile.bars do + table.remove(self.bars):Destroy() + 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 ipairs(self.bars) do + bar:ApplyAnchor() + end +end + + +function ReAction:NewBar() + local c = ReActionBarConfigDefaults + table.insert(self.bars, ReBar:new(c, #self.bars + 1)) + table.insert(self.db.profile.bars, c) + self:Unlock() +end + + +function ReAction:DeleteBar(id) + if self.bars[id] then + table.remove(self.bars, id):Destroy() + table.remove( self.db.profile.bars, id ) + 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", "ReAction bar lock", "text2", self.locked and "|cffcc0000Locked|r" or "|cff00cc00Unlocked|r") + tablet:SetHint("|cffcc6600Shift-Click|r to toggle action bar lock. Right-click for options.") +end + +function ReAction:OnClick(button) + if IsShiftKeyDown() then + self:ToggleLocked() + end + self:UpdateDisplay() +end