Mercurial > wow > reaction
diff ReAction.lua @ 2:8e0ff8ae4c08
Version 0.2
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Tue, 20 Mar 2007 21:08:31 +0000 |
parents | c11ca1d8ed91 |
children |
line wrap: on
line diff
--- a/ReAction.lua Tue Mar 20 21:03:57 2007 +0000 +++ b/ReAction.lua Tue Mar 20 21:08:31 2007 +0000 @@ -6,8 +6,9 @@ -- -- key binding label constants -BINDING_HEADER_REACTION = "ReAction" -BINDING_NAME_REACTION_TOGGLELOCK = "Lock/Unlock ReAction" +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( @@ -17,12 +18,21 @@ "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 = ReActionGlobalMenuOptions +ReAction.OnMenuRequest = tcopy(ReActionGlobalMenuOptions) -- initial non-persistent state ReAction.locked = true @@ -39,8 +49,7 @@ self:RegisterDB("ReActionDB","ReActionDBPC") self:RegisterDefaults("profile", ReActionProfileDefaults) self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown") - - AceLibrary("Dewdrop-2.0"):InjectAceOptionsTable(self, ReActionProfileMenuOptions) + self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars") end function ReAction:OnEnable() @@ -49,9 +58,8 @@ self.db.profile.firstRunDone = true elseif self.db.profile.disabled == true then -- print some kind of a warning - else - self:SetupBars() end + self:SetupBars() end function ReAction:OnDisable() @@ -60,8 +68,8 @@ function ReAction:OnProfileEnable() -- handle profile switching + self:Lock() self:SetupBars() - self:Lock() end function ReAction:CombatLockdown() @@ -74,12 +82,18 @@ -- 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 + 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 @@ -115,8 +129,12 @@ end function ReAction:SetHideArt( hide ) - self.db.profile.hideArt = hide and true or false -- force data integrity - self:HideArt() + 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() @@ -163,18 +181,22 @@ function ReAction:HideDefaultBars() for _, f in pairs(blizzDefaultBars) do + f:UnregisterAllEvents() f:Hide() - f:ClearAllPoints() - f:SetParent(ReActionButtonRecycler) - f:UnregisterAllEvents() + f:SetParent(ReActionButtonRecycler) -- I mean it! + f:ClearAllPoints() -- no, I really mean it! end end -- Reset bars to defaults function ReAction:ResetBars() - self.db.profile.bars = ReActionProfileDefaults.bars - self:SetupBars() + if InCombatLockdown() then + UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) + else + self.db.profile.bars = ReActionProfileDefaults.bars + self:SetupBars() + end end @@ -195,36 +217,62 @@ 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) + -- 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 - while #self.bars > #self.db.profile.bars do - table.remove(self.bars):Destroy() + 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 ipairs(self.bars) do + for _, bar in pairs(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() + 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 self.bars[id] then - table.remove(self.bars, id):Destroy() - table.remove( self.db.profile.bars, 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 @@ -248,13 +296,19 @@ 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.") + 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() - end - self:UpdateDisplay() + self:UpdateDisplay() + elseif IsAltKeyDown() then + ReBinder:ToggleEnabled() + end end