annotate main.lua @ 15:0ea4c8ab1991

Removed redundant setting of config.id in PetActionType
author Flick <flickerstreak@gmail.com>
date Thu, 22 Mar 2007 21:07:53 +0000
parents 2735edcf9ab7
children 639282f3a0e0
rev   line source
flickerstreak@7 1 -- main.lua
flickerstreak@1 2 --
flickerstreak@1 3 -- Top-level file for the ReAction Action Bar add-on
flickerstreak@1 4 --
flickerstreak@7 5 -- implemented in terms of the Ace 2 development framework library: http://www.wowace.com
flickerstreak@1 6 --
flickerstreak@1 7
flickerstreak@7 8 -- Ace Library local object initialization
flickerstreak@7 9 local L = AceLibrary("AceLocale-2.2"):new("ReAction")
flickerstreak@7 10 local dewdrop = AceLibrary("Dewdrop-2.0")
flickerstreak@7 11 local tablet = AceLibrary("Tablet-2.0")
flickerstreak@12 12 local ReBound = AceLibrary("ReBound-1.0"):new("REACTION")
flickerstreak@1 13
flickerstreak@7 14 -- private functions
flickerstreak@2 15 local function tcopy(t)
flickerstreak@2 16 local r = { }
flickerstreak@2 17 for k, v in pairs(t) do
flickerstreak@2 18 r[k] = (type(v) == "table" and tcopy(v) or v)
flickerstreak@2 19 end
flickerstreak@2 20 return r
flickerstreak@2 21 end
flickerstreak@2 22
flickerstreak@7 23 -- private constants
flickerstreak@7 24 local EMPTY_BAR_SLOT = -1
flickerstreak@7 25
flickerstreak@7 26 -- key binding label constants
flickerstreak@7 27 BINDING_HEADER_REACTION = L["ReAction"]
flickerstreak@7 28 BINDING_NAME_REACTION_TOGGLELOCK = L["Toggle ReAction Bar Lock"]
flickerstreak@10 29 BINDING_NAME_REACTION_TOGGLEKEYBIND = L["ReAction Keybinding Mode"]
flickerstreak@7 30
flickerstreak@10 31 -- UI panel strings
flickerstreak@10 32 REACTION_KEYBIND_TITLE = L["ReAction Keybinding"]
flickerstreak@10 33 REACTION_KEYBIND_SUBTITLE = L["Click Buttons to Set Keybindings"]
flickerstreak@10 34 REACTION_KEYBIND_DONE = L["Save"]
flickerstreak@10 35 REACTION_KEYBIND_REVERT = L["Revert"]
flickerstreak@7 36
flickerstreak@10 37
flickerstreak@10 38
flickerstreak@10 39 ------------------------------
flickerstreak@10 40 -- AceAddon setup
flickerstreak@10 41 ------------------------------
flickerstreak@7 42 local main = AceLibrary("AceAddon-2.0"):new(
flickerstreak@7 43 "AceConsole-2.0",
flickerstreak@7 44 "AceEvent-2.0",
flickerstreak@7 45 "AceDB-2.0",
flickerstreak@7 46 "FuBarPlugin-2.0"
flickerstreak@7 47 )
flickerstreak@1 48
flickerstreak@10 49 function main:OnInitialize()
flickerstreak@10 50 self:RegisterChatCommand( {L["/reaction"], L["/rxn"]}, ReActionConsoleOptions, "REACTION" )
flickerstreak@10 51 self:RegisterDB("ReActionDB","ReActionDBPC")
flickerstreak@10 52 self:RegisterDefaults("profile", ReAction_DefaultProfile)
flickerstreak@10 53 self:RegisterEvent("PLAYER_REGEN_DISABLED","CombatLockdown")
flickerstreak@10 54 self:RegisterEvent("PLAYER_ENTERING_WORLD","HideDefaultBars")
flickerstreak@10 55 self:DisableDefaultKeybindings()
flickerstreak@1 56
flickerstreak@12 57 -- create update function for keybinding frame
flickerstreak@12 58 ReActionKeybindDialog:SetScript("OnHide", function(frame)
flickerstreak@12 59 main:SetKeybindMode(false)
flickerstreak@12 60 if frame.save then
flickerstreak@12 61 ReBound:SaveBindings()
flickerstreak@12 62 else
flickerstreak@12 63 ReBound:RevertBindings()
flickerstreak@12 64 end
flickerstreak@12 65 frame.save = false
flickerstreak@12 66 end )
flickerstreak@12 67
flickerstreak@10 68 -- initial non-persistent state
flickerstreak@10 69 self.locked = true
flickerstreak@10 70 self.bars = { }
flickerstreak@10 71 end
flickerstreak@7 72
flickerstreak@12 73 -- OnEnable is called at startup and when the profile is changed (via OnProfileEnable)
flickerstreak@12 74 function main:OnEnable( )
flickerstreak@10 75 if self.db.profile.firstRunDone ~= true then
flickerstreak@10 76 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars)
flickerstreak@10 77 end
flickerstreak@10 78 self:DestroyAllBars()
flickerstreak@10 79 self:SetupBars()
flickerstreak@10 80 self:UpgradeProfile()
flickerstreak@12 81 self:SetupKeybindings()
flickerstreak@10 82 if self.db.profile.firstRunDone ~= true then
flickerstreak@10 83 self:Unlock()
flickerstreak@10 84 end
flickerstreak@10 85 self.db.profile.firstRunDone = true
flickerstreak@10 86 end
flickerstreak@7 87
flickerstreak@10 88 function main:OnDisable()
flickerstreak@10 89 self:Lock()
flickerstreak@10 90 end
flickerstreak@10 91
flickerstreak@10 92 -- OnProfileEnable() is only called when switching profiles, NOT for the initial profile at load time.
flickerstreak@10 93 function main:OnProfileEnable( oldName, oldData )
flickerstreak@12 94 self:UnregisterEvent("REBOUND_BIND")
flickerstreak@12 95 self:UnregisterEvent("REBOUND_UNBIND")
flickerstreak@12 96 ReBound:ClearRegisteredBindings()
flickerstreak@12 97 self:OnEnable()
flickerstreak@10 98 end
flickerstreak@10 99
flickerstreak@10 100 function main:UpgradeProfile()
flickerstreak@10 101 if self.db.profile.firstRunDone ~= true and #self.db.profile.bindings == 0 then
flickerstreak@10 102 for _, bar in pairs(self.bars) do
flickerstreak@10 103 for _, button in pairs(bar.buttons) do
flickerstreak@10 104 local key = ReBound:GetBinding(button:GetActionFrame(),"LeftButton")
flickerstreak@10 105 if key and #key > 0 and not self.db.profile.bindings[key] then
flickerstreak@10 106 self:REBOUND_BIND(key,button:GetActionFrame():GetName(),"LeftButton")
flickerstreak@10 107 end
flickerstreak@10 108 end
flickerstreak@10 109 end
flickerstreak@10 110 end
flickerstreak@10 111 end
flickerstreak@10 112
flickerstreak@10 113
flickerstreak@10 114
flickerstreak@10 115
flickerstreak@10 116 --------------------------------------------
flickerstreak@7 117 -- FuBar plugin setup
flickerstreak@10 118 -- Even if FuBar isn't installed, the plugin
flickerstreak@10 119 -- provides a nice minimap-button interface.
flickerstreak@10 120 ---------------------------------------------
flickerstreak@7 121 main.hasIcon = "Interface\\Icons\\INV_Qiraj_JewelEncased"
flickerstreak@7 122 main.hasNoColor = true
flickerstreak@7 123 main.hideMenuTitle = true
flickerstreak@7 124 main.defaultPosition = "LEFT"
flickerstreak@7 125 main.defaultMinimapPosition = 240 -- degrees
flickerstreak@7 126 main.OnMenuRequest = tcopy(ReActionGlobalMenuOptions) -- use a copy, or bar menus will have FuBar inserted items
flickerstreak@7 127 main.independentProfile = true
flickerstreak@7 128
flickerstreak@7 129 -- set the handler for the global bar menu options
flickerstreak@7 130 -- have to do this after tcopy() above, otherwise it will try to copy the handler object (bad idea)
flickerstreak@7 131 ReActionGlobalMenuOptions.handler = main
flickerstreak@7 132
flickerstreak@7 133 function main:OnTooltipUpdate()
flickerstreak@7 134 local c = tablet:AddCategory("columns", 2)
flickerstreak@7 135 c:AddLine("text", L["Bar lock"], "text2", self.locked and ("|cffff0000"..L["Locked"].."|r") or ("|cffffcc00"..L["Unlocked"].."|r"))
flickerstreak@7 136 c:AddLine("text", L["Button lock"], "text2", LOCK_ACTIONBAR == "1" and ("|cffcc0000"..L["Locked"].."|r") or ("|cff00cc00"..L["Unlocked"].."|r"))
flickerstreak@10 137 c:AddLine("text", L["Kebinding mode"], "text2", self:GetKeybindMode() and ("|cff33ff33"..L["On"].."|r") or ("|cffffcc00"..L["Off"].."|r"))
flickerstreak@7 138 tablet:SetHint(L["|cffffcc00Shift-Click for bar lock|n|cff33ff33Alt-Click|r for keybindings|nRight-click for menu"])
flickerstreak@7 139 end
flickerstreak@7 140
flickerstreak@7 141 function main:OnClick(button)
flickerstreak@7 142 if IsShiftKeyDown() then
flickerstreak@7 143 self:ToggleLocked()
flickerstreak@7 144 self:UpdateDisplay()
flickerstreak@7 145 elseif IsAltKeyDown() then
flickerstreak@10 146 self:ToggleKeybindMode()
flickerstreak@7 147 self:UpdateDisplay()
flickerstreak@7 148 end
flickerstreak@7 149 end
flickerstreak@7 150
flickerstreak@7 151
flickerstreak@10 152
flickerstreak@10 153
flickerstreak@10 154 ------------------------------
flickerstreak@10 155 -- Key binding functions
flickerstreak@10 156 ------------------------------
flickerstreak@10 157 function main:DisableDefaultKeybindings()
flickerstreak@10 158 -- change the labels on all actionbar keybindings in the default
flickerstreak@10 159 -- interface.
flickerstreak@10 160 local label = "|cff999999("..L["Use ReAction"]..")|r"
flickerstreak@10 161 for i = 1, 12 do
flickerstreak@10 162 setglobal("BINDING_NAME_ACTIONBUTTON"..i,label)
flickerstreak@10 163 for j = 1, 4 do
flickerstreak@10 164 setglobal("BINDING_NAME_MULTIACTIONBAR"..j.."BUTTON"..i,label)
flickerstreak@10 165 end
flickerstreak@10 166 end
flickerstreak@10 167 for i = 1, 6 do
flickerstreak@10 168 setglobal("BINDING_NAME_ACTIONPAGE"..i,label)
flickerstreak@10 169 end
flickerstreak@10 170 for i = 1, 10 do
flickerstreak@10 171 setglobal("BINDING_NAME_BONUSACTIONBUTTON"..i,label)
flickerstreak@10 172 setglobal("BINDING_NAME_SHAPESHIFTBUTTON"..i,label)
flickerstreak@10 173 end
flickerstreak@10 174 BINDING_HEADER_ACTIONBAR = "|cff999999"..L["Action Bar Functions Disabled"].."|r"
flickerstreak@10 175 BINDING_HEADER_MULTIACTIONBAR = "|cff999999"..L["Multi-Action Bar Functions Disabled"].."|r"
flickerstreak@10 176 BINDING_NAME_NEXTACTIONPAGE = label
flickerstreak@10 177 BINDING_NAME_PREVIOUSACTIONPAGE = label
flickerstreak@10 178 end
flickerstreak@10 179
flickerstreak@12 180 function main:SetupKeybindings()
flickerstreak@10 181 if self.db.profile.firstRunDone ~= true then
flickerstreak@10 182 self:StealKeyBindings()
flickerstreak@10 183 else
flickerstreak@10 184 for key, binding in pairs(self.db.profile.bindings) do
flickerstreak@12 185 local target = getglobal(binding.target)
flickerstreak@12 186 if target then
flickerstreak@12 187 ReBound:SetBinding(key, target, binding.button)
flickerstreak@12 188 end
flickerstreak@10 189 end
flickerstreak@10 190 end
flickerstreak@12 191 ReBound:SaveBindings()
flickerstreak@10 192 self:RegisterEvent("REBOUND_BIND")
flickerstreak@10 193 self:RegisterEvent("REBOUND_UNBIND")
flickerstreak@10 194 end
flickerstreak@10 195
flickerstreak@10 196 function main:StealKeyBindings()
flickerstreak@10 197 -- steal the keybindings of the main action bar and assign them to rebar 1, buttons 1-12
flickerstreak@10 198 for i = 1, 12 do
flickerstreak@10 199 local key = GetBindingKey("ACTIONBUTTON"..i)
flickerstreak@10 200 if key and #key > 0 then
flickerstreak@10 201 ReBound:ClearBinding(key,nil,nil,true) -- suppress notification printouts
flickerstreak@10 202 ReBound:SetBinding(key, self.bars[1].buttons[i]:GetActionFrame(), "LeftButton")
flickerstreak@10 203 end
flickerstreak@10 204 end
flickerstreak@12 205 ReBound:SaveBindings()
flickerstreak@10 206 end
flickerstreak@10 207
flickerstreak@12 208 function main:REBOUND_BIND(id, key, target, button)
flickerstreak@12 209 if id == "REACTION" and key and target then
flickerstreak@10 210 self.db.profile.bindings[key] = { target = target, button = button }
flickerstreak@10 211 end
flickerstreak@10 212 end
flickerstreak@10 213
flickerstreak@12 214 function main:REBOUND_UNBIND(id, key)
flickerstreak@12 215 if id == "REACTION" and key then
flickerstreak@10 216 self.db.profile.bindings[key] = nil
flickerstreak@10 217 end
flickerstreak@10 218 end
flickerstreak@10 219
flickerstreak@10 220 function main:ToggleKeybindMode()
flickerstreak@10 221 self:SetKeybindMode(not self:GetKeybindMode())
flickerstreak@10 222 end
flickerstreak@10 223
flickerstreak@10 224 function main:GetKeybindMode()
flickerstreak@10 225 return self.keybindMode
flickerstreak@10 226 end
flickerstreak@10 227
flickerstreak@10 228 function main:SetKeybindMode(enabled)
flickerstreak@10 229 if not InCombatLockdown() then
flickerstreak@10 230 self.keybindMode = enabled
flickerstreak@10 231 for _, bar in pairs(self.bars) do
flickerstreak@10 232 for __, button in pairs(bar.buttons) do
flickerstreak@10 233 if button and button ~= EMPTY_BAR_SLOT then
flickerstreak@10 234 button:TempShow(enabled)
flickerstreak@10 235 end
flickerstreak@10 236 end
flickerstreak@10 237 end
flickerstreak@10 238 if enabled then
flickerstreak@12 239 ReBound:ShowFrames()
flickerstreak@10 240 ReActionKeybindDialog:Show()
flickerstreak@10 241 else
flickerstreak@12 242 ReBound:HideFrames()
flickerstreak@10 243 if ReActionKeybindDialog:IsShown() then
flickerstreak@10 244 ReActionKeybindDialog:Hide()
flickerstreak@10 245 end
flickerstreak@10 246 end
flickerstreak@10 247 else
flickerstreak@10 248 UIErrorsFrame:AddMessage(ERROR_NOT_IN_COMBAT)
flickerstreak@10 249 end
flickerstreak@10 250 end
flickerstreak@10 251
flickerstreak@10 252
flickerstreak@10 253
flickerstreak@10 254
flickerstreak@10 255 ----------------------------
flickerstreak@10 256 -- Bar lock/unlock functions
flickerstreak@10 257 ----------------------------
flickerstreak@10 258 function main:CombatLockdown()
flickerstreak@10 259 if not self:IsLocked() then
flickerstreak@10 260 self:Lock()
flickerstreak@10 261 UIErrorsFrame:AddMessage(L["ReAction bars locked when in combat"])
flickerstreak@10 262 end
flickerstreak@10 263 ReActionKeybindDialog:Hide()
flickerstreak@10 264 end
flickerstreak@10 265
flickerstreak@7 266 function main:SetLocked( lock )
flickerstreak@2 267 if lock ~= self.locked then
flickerstreak@2 268 if not lock and InCombatLockdown() then
flickerstreak@10 269 UIErrorsFrame:AddMessage(ERROR_NOT_IN_COMBAT)
flickerstreak@2 270 else
flickerstreak@2 271 self.locked = lock and true or false -- force data integrity
flickerstreak@2 272 for _, bar in pairs(self.bars) do
flickerstreak@7 273 if bar ~= EMPTY_BAR_SLOT then
flickerstreak@7 274 if self.locked then
flickerstreak@7 275 bar:HideControls()
flickerstreak@7 276 -- close any dewdrop menu owned by the bar
flickerstreak@7 277 if bar:GetControlFrame() == dewdrop:GetOpenedParent() then
flickerstreak@7 278 dewdrop:Close()
flickerstreak@7 279 end
flickerstreak@7 280 else
flickerstreak@7 281 bar:ShowControls()
flickerstreak@7 282 end
flickerstreak@7 283 end
flickerstreak@2 284 end
flickerstreak@2 285 end
flickerstreak@1 286 end
flickerstreak@1 287 end
flickerstreak@1 288
flickerstreak@7 289 function main:IsLocked()
flickerstreak@1 290 return self.locked
flickerstreak@1 291 end
flickerstreak@1 292
flickerstreak@7 293 function main:Lock()
flickerstreak@1 294 self:SetLocked(true)
flickerstreak@1 295 end
flickerstreak@1 296
flickerstreak@7 297 function main:Unlock()
flickerstreak@1 298 self:SetLocked(false)
flickerstreak@1 299 end
flickerstreak@1 300
flickerstreak@7 301 function main:ToggleLocked()
flickerstreak@7 302 main:SetLocked( not(self.locked) )
flickerstreak@1 303 end
flickerstreak@1 304
flickerstreak@1 305
flickerstreak@1 306
flickerstreak@10 307 --------------------------------------------------------
flickerstreak@10 308 -- Functions to hide the default Blizzard main bar parts
flickerstreak@10 309 --------------------------------------------------------
flickerstreak@7 310 function main:HideArt()
flickerstreak@1 311 if self.db.profile.hideArt then
flickerstreak@7 312 -- the pet bar is a child of MainMenuBar, and can't be hidden. Need to reparent it
flickerstreak@7 313 PetActionBarFrame:SetParent(UIParent)
flickerstreak@1 314 MainMenuBar:Hide() -- this also hides the bags, xp bar, lag meter, and micro menu buttons.
flickerstreak@7 315 -- these two are the pet bar background
flickerstreak@7 316 -- unfortunately UIParent_ManageFramePositions() shows and hides these too
flickerstreak@7 317 -- so they get reparented to MainMenuBar
flickerstreak@7 318 SlidingActionBarTexture0:SetParent(MainMenuBar)
flickerstreak@7 319 SlidingActionBarTexture1:SetParent(MainMenuBar)
flickerstreak@1 320 else
flickerstreak@7 321 SlidingActionBarTexture0:SetParent(PetActionBarFrame)
flickerstreak@7 322 SlidingActionBarTexture1:SetParent(PetActionBarFrame)
flickerstreak@1 323 MainMenuBar:Show()
flickerstreak@1 324 end
flickerstreak@1 325 end
flickerstreak@1 326
flickerstreak@7 327 function main:IsArtHidden()
flickerstreak@1 328 return self.db.profile.hideArt
flickerstreak@1 329 end
flickerstreak@1 330
flickerstreak@7 331 function main:SetHideArt( hide )
flickerstreak@2 332 if InCombatLockdown() then
flickerstreak@2 333 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
flickerstreak@2 334 else
flickerstreak@2 335 self.db.profile.hideArt = hide and true or false -- force data integrity
flickerstreak@2 336 self:HideArt()
flickerstreak@2 337 end
flickerstreak@1 338 end
flickerstreak@1 339
flickerstreak@7 340 function main:ToggleHideArt()
flickerstreak@1 341 self:SetHideArt( not self:IsArtHidden() )
flickerstreak@1 342 end
flickerstreak@1 343
flickerstreak@1 344 -- Hide default Blizzard bars
flickerstreak@1 345 local blizzDefaultBars = {
flickerstreak@1 346 ActionButton1,
flickerstreak@1 347 ActionButton2,
flickerstreak@1 348 ActionButton3,
flickerstreak@1 349 ActionButton4,
flickerstreak@1 350 ActionButton5,
flickerstreak@1 351 ActionButton6,
flickerstreak@1 352 ActionButton7,
flickerstreak@1 353 ActionButton8,
flickerstreak@1 354 ActionButton9,
flickerstreak@1 355 ActionButton10,
flickerstreak@1 356 ActionButton11,
flickerstreak@1 357 ActionButton12,
flickerstreak@7 358 PetActionButton1,
flickerstreak@7 359 PetActionButton2,
flickerstreak@7 360 PetActionButton3,
flickerstreak@7 361 PetActionButton4,
flickerstreak@7 362 PetActionButton5,
flickerstreak@7 363 PetActionButton6,
flickerstreak@7 364 PetActionButton7,
flickerstreak@7 365 PetActionButton8,
flickerstreak@7 366 PetActionButton9,
flickerstreak@7 367 PetActionButton10,
flickerstreak@7 368 -- NOT the PetActionBarFrame, though - we need that to auto-hide/show our pet action bars
flickerstreak@7 369 MainMenuBarPageNumber,
flickerstreak@7 370 ActionBarUpButton,
flickerstreak@7 371 ActionBarDownButton,
flickerstreak@1 372 BonusActionBarFrame,
flickerstreak@7 373 ShapeshiftBarFrame,
flickerstreak@1 374 MultiBarLeft,
flickerstreak@1 375 MultiBarRight,
flickerstreak@1 376 MultiBarBottomLeft,
flickerstreak@7 377 MultiBarBottomRight,
flickerstreak@1 378 }
flickerstreak@1 379
flickerstreak@7 380 local function disableUIOptions()
flickerstreak@7 381 -- disable the buttons to hide/show the blizzard multiaction bars
flickerstreak@7 382 -- see UIOptionsFrame.lua and .xml
flickerstreak@7 383 -- This is called every time the options panel is shown, after it is set up
flickerstreak@7 384 for _, idx in pairs( { 33, 34, 35, 36, 37, 40 } ) do
flickerstreak@7 385 local f = getglobal("UIOptionsFrameCheckButton"..idx)
flickerstreak@7 386 f.disabled = true
flickerstreak@7 387 OptionsFrame_DisableCheckBox(f)
flickerstreak@7 388 f:SetChecked(false)
flickerstreak@7 389 end
flickerstreak@7 390 end
flickerstreak@1 391
flickerstreak@7 392 function main:HideDefaultBars()
flickerstreak@7 393 for _, f in pairs(blizzDefaultBars) do
flickerstreak@7 394 f:Hide()
flickerstreak@7 395 f:ClearAllPoints()
flickerstreak@7 396 f:SetParent(ReAction.recycler)
flickerstreak@7 397 f:SetPoint("TOPLEFT")
flickerstreak@7 398 end
flickerstreak@7 399
flickerstreak@7 400 MainMenuBar:SetFrameStrata("LOW") -- otherwise it appears on top of bars, if it isn't hidden
flickerstreak@7 401 hooksecurefunc("UIOptionsFrame_Load",disableUIOptions)
flickerstreak@7 402 end
flickerstreak@7 403
flickerstreak@7 404
flickerstreak@10 405
flickerstreak@10 406
flickerstreak@10 407 ---------------------------------------
flickerstreak@10 408 -- Bar setup and manipulation functions
flickerstreak@10 409 ---------------------------------------
flickerstreak@7 410 -- Reset bars to blizzard defaults
flickerstreak@7 411 function main:ResetBars()
flickerstreak@2 412 if InCombatLockdown() then
flickerstreak@2 413 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
flickerstreak@2 414 else
flickerstreak@7 415 self:DestroyAllBars()
flickerstreak@7 416 self.db.profile.bars = tcopy(ReAction_DefaultBlizzardBars)
flickerstreak@2 417 self:SetupBars()
flickerstreak@2 418 end
flickerstreak@1 419 end
flickerstreak@1 420
flickerstreak@7 421 function main:DestroyAllBars()
flickerstreak@7 422 -- destroy any existing bars
flickerstreak@7 423 for id = 1, table.maxn(self.bars) do
flickerstreak@7 424 self:DestroyBar(id)
flickerstreak@7 425 end
flickerstreak@7 426 end
flickerstreak@7 427
flickerstreak@7 428 function main:SetupBars()
flickerstreak@1 429 -- hide the default Blizzard art, if configued
flickerstreak@1 430 self:HideArt()
flickerstreak@1 431
flickerstreak@1 432 -- set up the bars from the profile
flickerstreak@2 433 -- note the use of table.maxn rather than # or ipairs:
flickerstreak@2 434 -- our array of bars can in fact contain holes
flickerstreak@2 435 for id = 1, table.maxn(self.db.profile.bars) do
flickerstreak@2 436 local config = self.db.profile.bars[id]
flickerstreak@2 437 if config then
flickerstreak@7 438 self:CreateBar(config, id)
flickerstreak@2 439 end
flickerstreak@1 440 end
flickerstreak@1 441
flickerstreak@1 442 -- anchor the bars, have to do this in a second pass because
flickerstreak@1 443 -- they might be anchored to each other in a non-ordered way
flickerstreak@2 444 for _, bar in pairs(self.bars) do
flickerstreak@7 445 if bar ~= EMPTY_BAR_SLOT then
flickerstreak@7 446 bar:ApplyAnchor()
flickerstreak@2 447 end
flickerstreak@2 448 end
flickerstreak@1 449 end
flickerstreak@1 450
flickerstreak@7 451 function main:CreateBar( config, id )
flickerstreak@7 452 local bar = ReBar:new(config, id)
flickerstreak@7 453 local buttonType = ReAction:GetButtonType(config.btnConfig.subtype)
flickerstreak@1 454
flickerstreak@7 455 if buttonType then
flickerstreak@7 456 self.bars[id] = bar
flickerstreak@7 457 self.db.profile.bars[id] = config
flickerstreak@7 458
flickerstreak@7 459 -- initialize dewdrop menu
flickerstreak@7 460 local cf = bar:GetControlFrame()
flickerstreak@7 461 dewdrop:Register(cf,
flickerstreak@7 462 'children',
flickerstreak@7 463 function()
flickerstreak@7 464 dewdrop:FeedAceOptionsTable(ReActionGlobalMenuOptions)
flickerstreak@7 465 dewdrop:FeedAceOptionsTable(GenerateReActionBarOptions(bar,self))
flickerstreak@7 466 dewdrop:FeedAceOptionsTable(buttonType:GenerateOptionsTable(config.btnConfig, function() return bar:GetButtonList() end))
flickerstreak@7 467 end,
flickerstreak@7 468 'cursorX', true,
flickerstreak@7 469 'cursorY', true
flickerstreak@7 470 )
flickerstreak@7 471
flickerstreak@7 472 bar:GetControlFrame():SetScript("OnClick",
flickerstreak@7 473 function(btn)
flickerstreak@7 474 if btn == "RightButton" then
flickerstreak@7 475 dewdrop:Open(cf)
flickerstreak@7 476 end
flickerstreak@7 477 end
flickerstreak@7 478 )
flickerstreak@7 479
flickerstreak@12 480 -- register page up/down buttons with ReBound for keybinding
flickerstreak@12 481 ReBound:Register(bar.upArrow)
flickerstreak@12 482 ReBound:Register(bar.downArrow)
flickerstreak@12 483
flickerstreak@7 484 if not self.locked then
flickerstreak@7 485 bar:ShowControls()
flickerstreak@7 486 end
flickerstreak@7 487 return bar
flickerstreak@7 488 else
flickerstreak@7 489 if bar then
flickerstreak@7 490 bar:Destroy()
flickerstreak@7 491 end
flickerstreak@7 492 error(L["Tried to create a button of unknown type"])
flickerstreak@7 493 end
flickerstreak@7 494 end
flickerstreak@7 495
flickerstreak@7 496 function main:DestroyBar( id )
flickerstreak@7 497 local bar = self.bars[id]
flickerstreak@7 498 if bar and bar ~= EMPTY_BAR_SLOT then
flickerstreak@7 499 local cf = bar:GetControlFrame()
flickerstreak@7 500 if cf == dewdrop:GetOpenedParent() then
flickerstreak@7 501 dewdrop:Close()
flickerstreak@7 502 dewdrop:Unregister(cf)
flickerstreak@7 503 end
flickerstreak@7 504 bar:Destroy()
flickerstreak@7 505 -- we can't do tremove because each bar ID is encoded into the
flickerstreak@7 506 -- frame names as they're created. Need a blank entry in the table.
flickerstreak@7 507 -- The nice thing is that table.insert in NewBar() will automatically
flickerstreak@7 508 -- find the lowest numbered nil slot.
flickerstreak@7 509 self.bars[id] = EMPTY_BAR_SLOT
flickerstreak@7 510 end
flickerstreak@7 511 end
flickerstreak@7 512
flickerstreak@10 513 --
flickerstreak@10 514 -- this function is a wrapper for CreateBar() which looks up the bar type
flickerstreak@10 515 -- and constructs a new configuration object of the right type.
flickerstreak@7 516 function main:NewBar( type )
flickerstreak@7 517 if InCombatLockdown() then
flickerstreak@7 518 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
flickerstreak@7 519 else
flickerstreak@7 520 local t = ReAction:GetButtonType(type)
flickerstreak@7 521 if t then
flickerstreak@7 522 local c = tcopy(ReAction_DefaultBarConfig["ReAction"][type])
flickerstreak@7 523 local id = nil
flickerstreak@7 524 for i = 1, table.maxn(self.bars) + 1 do -- there may be holes, so #self.bars won't work
flickerstreak@7 525 if self.bars[i] == nil or self.bars[i] == EMPTY_BAR_SLOT then
flickerstreak@7 526 id = i
flickerstreak@7 527 break
flickerstreak@7 528 end
flickerstreak@7 529 end
flickerstreak@7 530 local bar = self:CreateBar(c, id)
flickerstreak@7 531 bar:ApplyAnchor()
flickerstreak@7 532 self:Unlock()
flickerstreak@7 533 end
flickerstreak@7 534 end
flickerstreak@7 535 end
flickerstreak@7 536
flickerstreak@10 537 --
flickerstreak@10 538 -- This function is a wrapper for DestroyBar() which does in-combat
flickerstreak@10 539 -- checking and updates the config.
flickerstreak@7 540 function main:DeleteBar(id)
flickerstreak@2 541 if InCombatLockdown() then
flickerstreak@2 542 UIErrorsFrame:AddMessage(SPELL_FAILED_AFFECTING_COMBAT)
flickerstreak@2 543 else
flickerstreak@2 544 if self.bars[id] then
flickerstreak@7 545 self:DestroyBar(id)
flickerstreak@2 546 self.db.profile.bars[id] = nil
flickerstreak@2 547 end
flickerstreak@1 548 end
flickerstreak@1 549 end
flickerstreak@1 550
flickerstreak@10 551
flickerstreak@10 552
flickerstreak@10 553
flickerstreak@10 554 -----------------
flickerstreak@10 555 -- General utility
flickerstreak@10 556 -----------------
flickerstreak@7 557 function main:ToggleIds()
flickerstreak@7 558 if self.showIds then
flickerstreak@7 559 ReAction:HideAllIds()
flickerstreak@1 560 else
flickerstreak@7 561 ReAction:ShowAllIds()
flickerstreak@1 562 end
flickerstreak@7 563 self.showIds = not self.showIds
flickerstreak@1 564 end
flickerstreak@1 565
flickerstreak@7 566 function main:AreIdsVisible()
flickerstreak@7 567 return self.showIds
flickerstreak@1 568 end
flickerstreak@1 569
flickerstreak@10 570 -- set a global variable for Bindings.xml
flickerstreak@10 571 ReActionAddOn = main
flickerstreak@1 572
flickerstreak@1 573