annotate main.lua @ 21:90bf38d48efd

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