Mercurial > wow > reaction
comparison 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 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 3:f5607e135c37 | 4:dfd829db3ad0 | 
|---|---|
| 1 -- ReAction.lua | |
| 2 -- | |
| 3 -- Top-level file for the ReAction Action Bar add-on | |
| 4 -- | |
| 5 -- ReAction is implemented in terms of the Ace 2 library: http://www.wowace.com | |
| 6 -- | |
| 7 | |
| 8 -- key binding label constants | |
| 9 BINDING_HEADER_REACTION = "ReAction" | |
| 10 BINDING_NAME_REACTION_TOGGLELOCK = "Lock/Unlock ReAction Bars" | |
| 11 BINDING_NAME_REBINDER_TOGGLEBINDINGMODE = "Toggle ReAction keybinding mode" | |
| 12 | |
| 13 -- ReAction addon setup via Ace 2 | |
| 14 ReAction = AceLibrary("AceAddon-2.0"):new( | |
| 15 "AceConsole-2.0", | |
| 16 "AceEvent-2.0", | |
| 17 "AceDB-2.0", | |
| 18 "FuBarPlugin-2.0" | |
| 19 ) | |
| 20 | |
| 21 local function tcopy(t) | |
| 22 local r = { } | |
| 23 for k, v in pairs(t) do | |
| 24 r[k] = (type(v) == "table" and tcopy(v) or v) | |
| 25 end | |
| 26 return r | |
| 27 end | |
| 28 | |
| 29 -- FuBar plugin setup | |
| 30 ReAction.hasIcon = false | |
| 31 ReAction.hasNoColor = true | |
| 32 ReAction.hideMenuTitle = true | |
| 33 ReAction.defaultPosition = "RIGHT" | |
| 34 ReAction.defaultMinimapPosition = 240 -- degrees | |
| 35 ReAction.OnMenuRequest = tcopy(ReActionGlobalMenuOptions) | |
| 36 | |
| 37 -- initial non-persistent state | |
| 38 ReAction.locked = true | |
| 39 | |
| 40 -- localization | |
| 41 -- local L = AceLibrary("AceLocale-2.0"):new("ReAction") | |
| 42 | |
| 43 | |
| 44 | |
| 45 -- Event handling | |
| 46 function ReAction:OnInitialize() | |
| 47 self:RegisterChatCommand( {"/reaction", "/rxn"}, ReActionConsoleOptions, "REACTION" ) | |
| 48 | |
| 49 self:RegisterDB("ReActionDB","ReActionDBPC") | |
| 50 self:RegisterDefaults("profile", ReActionProfileDefaults) | |
| 51 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown") | |
| 52 self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars") | |
| 53 end | |
| 54 | |
| 55 function ReAction:OnEnable() | |
| 56 if self.db.profile.firstRunDone ~= true then | |
| 57 -- Do some "first-run" setup | |
| 58 self.db.profile.firstRunDone = true | |
| 59 elseif self.db.profile.disabled == true then | |
| 60 -- print some kind of a warning | |
| 61 end | |
| 62 self:SetupBars() | |
| 63 end | |
| 64 | |
| 65 function ReAction:OnDisable() | |
| 66 self:Lock() | |
| 67 end | |
| 68 | |
| 69 function ReAction:OnProfileEnable() | |
| 70 -- handle profile switching | |
| 71 self:Lock() | |
| 72 self:SetupBars() | |
| 73 end | |
| 74 | |
| 75 function ReAction:CombatLockdown() | |
| 76 if not self:IsLocked() then | |
| 77 self:Lock() | |
| 78 UIErrorsFrame:AddMessage("ReAction bars locked when in combat") | |
| 79 end | |
| 80 end | |
| 81 | |
| 82 | |
| 83 -- lock/unlock ReAction | |
| 84 function ReAction:SetLocked( lock ) | |
| 85 if lock ~= self.locked then | |
| 86 if not lock then | |
| 87 self:Print("Buttons disabled while unlocked") | |
| 88 end | |
| 89 if not lock and InCombatLockdown() then | |
| 90 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | |
| 91 else | |
| 92 self.locked = lock and true or false -- force data integrity | |
| 93 for _, bar in pairs(self.bars) do | |
| 94 if self.locked then bar:HideControls() else bar:ShowControls() end | |
| 95 end | |
| 96 end | |
| 97 end | |
| 98 end | |
| 99 | |
| 100 function ReAction:IsLocked() | |
| 101 return self.locked | |
| 102 end | |
| 103 | |
| 104 function ReAction:Lock() | |
| 105 self:SetLocked(true) | |
| 106 end | |
| 107 | |
| 108 function ReAction:Unlock() | |
| 109 self:SetLocked(false) | |
| 110 end | |
| 111 | |
| 112 function ReAction:ToggleLocked() | |
| 113 ReAction:SetLocked( not(self.locked) ) | |
| 114 end | |
| 115 | |
| 116 | |
| 117 | |
| 118 -- Hide the default Blizzard main bar artwork | |
| 119 function ReAction:HideArt() | |
| 120 if self.db.profile.hideArt then | |
| 121 MainMenuBar:Hide() -- this also hides the bags, xp bar, lag meter, and micro menu buttons. | |
| 122 else | |
| 123 MainMenuBar:Show() | |
| 124 end | |
| 125 end | |
| 126 | |
| 127 function ReAction:IsArtHidden() | |
| 128 return self.db.profile.hideArt | |
| 129 end | |
| 130 | |
| 131 function ReAction:SetHideArt( hide ) | |
| 132 if InCombatLockdown() then | |
| 133 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | |
| 134 else | |
| 135 self.db.profile.hideArt = hide and true or false -- force data integrity | |
| 136 self:HideArt() | |
| 137 end | |
| 138 end | |
| 139 | |
| 140 function ReAction:ToggleHideArt() | |
| 141 self:SetHideArt( not self:IsArtHidden() ) | |
| 142 end | |
| 143 | |
| 144 | |
| 145 | |
| 146 -- Keybinding color coding | |
| 147 function ReAction:SetKeyColorCoding( cc ) | |
| 148 self.db.profile.keyColorCode = cc | |
| 149 end | |
| 150 | |
| 151 function ReAction:IsKeyColorCodeEnabled() | |
| 152 return self.db.profile.keyColorCode | |
| 153 end | |
| 154 | |
| 155 function ReAction:ToggleKeyColorCoding() | |
| 156 self:SetKeyColorCoding(not self.db.profile.keyColorCode) | |
| 157 end | |
| 158 | |
| 159 | |
| 160 | |
| 161 -- Hide default Blizzard bars | |
| 162 local blizzDefaultBars = { | |
| 163 ActionButton1, | |
| 164 ActionButton2, | |
| 165 ActionButton3, | |
| 166 ActionButton4, | |
| 167 ActionButton5, | |
| 168 ActionButton6, | |
| 169 ActionButton7, | |
| 170 ActionButton8, | |
| 171 ActionButton9, | |
| 172 ActionButton10, | |
| 173 ActionButton11, | |
| 174 ActionButton12, | |
| 175 BonusActionBarFrame, | |
| 176 MultiBarLeft, | |
| 177 MultiBarRight, | |
| 178 MultiBarBottomLeft, | |
| 179 MultiBarBottomRight | |
| 180 } | |
| 181 | |
| 182 function ReAction:HideDefaultBars() | |
| 183 for _, f in pairs(blizzDefaultBars) do | |
| 184 f:UnregisterAllEvents() | |
| 185 f:Hide() | |
| 186 f:SetParent(ReActionButtonRecycler) -- I mean it! | |
| 187 f:ClearAllPoints() -- no, I really mean it! | |
| 188 end | |
| 189 end | |
| 190 | |
| 191 | |
| 192 -- Reset bars to defaults | |
| 193 function ReAction:ResetBars() | |
| 194 if InCombatLockdown() then | |
| 195 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | |
| 196 else | |
| 197 self.db.profile.bars = ReActionProfileDefaults.bars | |
| 198 self:SetupBars() | |
| 199 end | |
| 200 end | |
| 201 | |
| 202 | |
| 203 -- re-sync action IDs | |
| 204 function ReAction:ResyncActionIDs() | |
| 205 -- TODO | |
| 206 end | |
| 207 | |
| 208 | |
| 209 | |
| 210 -- Bar manipulation | |
| 211 ReAction.bars = { } | |
| 212 | |
| 213 function ReAction:SetupBars() | |
| 214 -- hide the default Blizzard art, if configued | |
| 215 self:HideArt() | |
| 216 -- hide the default Blizzard bars | |
| 217 self:HideDefaultBars() | |
| 218 | |
| 219 -- set up the bars from the profile | |
| 220 -- note the use of table.maxn rather than # or ipairs: | |
| 221 -- our array of bars can in fact contain holes | |
| 222 for id = 1, table.maxn(self.db.profile.bars) do | |
| 223 local config = self.db.profile.bars[id] | |
| 224 if self.bars[id] then | |
| 225 self.bars[id]:Destroy() -- remove old version of bar if switching profiles | |
| 226 end | |
| 227 if config then | |
| 228 self.bars[id] = ReBar:new(config, id) | |
| 229 end | |
| 230 end | |
| 231 | |
| 232 -- remove excess bars | |
| 233 for id = table.maxn(self.db.profile.bars) + 1, table.maxn(self.bars) do | |
| 234 if self.bars[id] then | |
| 235 self.bars[id]:Destroy() | |
| 236 self.bars[id] = nil | |
| 237 end | |
| 238 end | |
| 239 | |
| 240 -- anchor the bars, have to do this in a second pass because | |
| 241 -- they might be anchored to each other in a non-ordered way | |
| 242 for _, bar in pairs(self.bars) do | |
| 243 bar:ApplyAnchor() | |
| 244 end | |
| 245 end | |
| 246 | |
| 247 | |
| 248 function ReAction:NewBar() | |
| 249 if InCombatLockdown() then | |
| 250 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | |
| 251 else | |
| 252 local c = tcopy(ReActionBarConfigDefaults) | |
| 253 local bar = ReBar:new(c, #self.bars+1) | |
| 254 table.insert(self.bars, bar) | |
| 255 table.insert(self.db.profile.bars, c) | |
| 256 if not self.locked then | |
| 257 bar:ShowControls() | |
| 258 end | |
| 259 end | |
| 260 end | |
| 261 | |
| 262 | |
| 263 function ReAction:DeleteBar(id) | |
| 264 if InCombatLockdown() then | |
| 265 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT) | |
| 266 else | |
| 267 if self.bars[id] then | |
| 268 -- we can't do tremove because each bar ID is encoded into the | |
| 269 -- frame names as they're created. Need a nil entry in the table. | |
| 270 -- The nice thing is that table.insert in NewBar() will automatically | |
| 271 -- find the first nil slot. | |
| 272 self.bars[id]:Destroy() | |
| 273 self.bars[id] = nil | |
| 274 self.db.profile.bars[id] = nil | |
| 275 end | |
| 276 end | |
| 277 end | |
| 278 | |
| 279 function ReAction:ToggleActionID() | |
| 280 if self.showActionIDs then | |
| 281 ReActionButton:HideAllActionIDs() | |
| 282 else | |
| 283 ReActionButton:ShowAllActionIDs() | |
| 284 end | |
| 285 self.showActionIDs = not self.showActionIDs | |
| 286 end | |
| 287 | |
| 288 function ReAction:IsActionIDVisible() | |
| 289 return self.showActionIDs | |
| 290 end | |
| 291 | |
| 292 | |
| 293 | |
| 294 -- FuBar plugin methods | |
| 295 local tablet = AceLibrary("Tablet-2.0") | |
| 296 | |
| 297 function ReAction:OnTooltipUpdate() | |
| 298 local c = tablet:AddCategory("columns", 2) | |
| 299 c:AddLine("text", "Bar lock", "text2", self.locked and "|cffcc0000Locked|r" or "|cff00cc00Unlocked|r") | |
| 300 c:AddLine("text", "Button lock", "text2", LOCK_ACTIONBAR == "1" and "|cffcc0000Locked|r" or "|cff00cc00Unlocked|r") | |
| 301 c:AddLine("text", "Kebinding mode", "text2", ReBinder:IsEnabled() and "|cff33ff33On|r" or "|cffffcc00Off|r") | |
| 302 tablet:SetHint("|cffffcc00Shift-Click|r for bar lock|n".. | |
| 303 "|cff33ff33Alt-Click|r for keybindings|n".. | |
| 304 "Right-click for menu") | |
| 305 end | |
| 306 | |
| 307 function ReAction:OnClick(button) | |
| 308 if IsShiftKeyDown() then | |
| 309 self:ToggleLocked() | |
| 310 self:UpdateDisplay() | |
| 311 elseif IsAltKeyDown() then | |
| 312 ReBinder:ToggleEnabled() | |
| 313 end | |
| 314 end | 
