annotate main.lua @ 19:52a1252bce0d

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