Thread Tools Display Modes
04-14-14, 06:46 AM   #1
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
Making Actionbars

So looking into this I ran across this script here for making actionbars. It actually works but I'm wondering if there's a more efficient way to do this 5 more times so I can make 5 more bars in addition to having the default 5.

Lua Code:
  1. local addonName, addonTable = ...
  2.  
  3. addonTable.Funcs = {}
  4.  
  5. local MyFuncs = addonTable.Funcs
  6.  
  7. local f = CreateFrame("Frame", nil, UIParent)
  8.  
  9. function MyFuncs.OnEvent(self, event, ...)
  10.     if event == "ACTIONBAR_PAGE_CHANGED" then
  11.         if GetActionBarPage() ~= 1 then ChangeActionBarPage(1) end
  12.     elseif event == "ADDON_LOADED" and ... == addonName then
  13.         ActionBarUpButton:Disable()
  14.         ActionBarDownButton:Disable()
  15.     end
  16. end
  17.  
  18. f:SetScript("OnEvent", MyFuncs.OnEvent)
  19. f:SetScript("OnUpdate", function(self, elapsed)
  20.     for i=1,12,1 do
  21.         if not UnitAffectingCombat("player") then
  22.             if MainMenuBar:IsShown() == 1 and _G["ExtraBarButton"..i]:IsShown() == nil then
  23.                 _G["ExtraBarButton"..i]:Show()
  24.             elseif MainMenuBar:IsShown() == nil and _G["ExtraBarButton"..i]:IsShown() == 1 then
  25.                 _G["ExtraBarButton"..i]:Hide()
  26.             end
  27.         end
  28.     end
  29. end)
  30. f:RegisterEvent("ACTIONBAR_PAGE_CHANGED")
  31. f:RegisterEvent("ADDON_LOADED")
  32. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  33. f:RegisterEvent("PLAYER_LOGIN")
  34.  
  35. for id=13,24 do
  36.     local b = CreateFrame("CheckButton", "ExtraBarButton"..(id-12), UIParent, "ActionBarButtonTemplate")
  37.  
  38.     b:SetSize(36*UIParent:GetScale(), 36*UIParent:GetScale())
  39.     b:SetAttribute("action", id)
  40.     b:SetID(id)
  41.     b:SetPoint("CENTER", _G["MultiBarBottomRightButton"..(id-12)], "CENTER", 0, 200)
  42.     b:Show()
  43. end
__________________
Tweets YouTube Website
  Reply With Quote
04-15-14, 03:25 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Well, I don't know about the general idea, but these parts will definitely not work while in combat. You will get "action blocked" errors and the default action bars may even stop working.

Code:
ChangeActionBarPage(1)
ActionBarUpButton:Disable()
ActionBarDownButton:Disable()
_G["ExtraBarButton"..i]:Show()
_G["ExtraBarButton"..i]:Hide()
You can't hide, show, or disable secure/protected frames while in combat, and you can't change action bar pages while in combat, except in response to specific Blizzard-approved conditions (eg. the same ones you can check for in a macro) and using specific Blizzard-approved secure methods.

On top of that, using an OnUpdate script to hide things in combat is quite possibly the most inefficient way to do that. Here is a better way:

Code:
local f = CreateFrame("Frame") -- or use the one you already have
f:RegisterEvent("PLAYER_REGEN_DISABLED")
f:RegisterEvent("PLAYER_REGEN_ENABLED")
f:SetScript("OnEvent", function(self, event, ...) -- or add to the one you already have
     if InCombatLockdown() then return end -- safety check, not needed if frames are insecure
     SOME_OTHER_FRAME:SetShown(not UnitAffectingCombat("player")) -- hide OOC, remove "not" to show OOC instead
end)
This should work for both secure and insecure frames, since when PLAYER_REGEN_DISABLED fires to indicate entering combat, the UI isn't yet locked down, to allow addons to make changes beforehand, and when PLAYER_REGEN_ENABLED to indicate leaving combat, the UI lockdown has already been released.

Your other option would be to use a state driver:

Code:
local f = CreateFrame("Frame", "MyCombatHider", UIParent, "SecureHandlerStateTemplate")
f:SetAllPoints(true) -- not *really* needed but makes child placement easier
RegisterStateDriver(self, "visibility", "[combat] hide; show")
-- parent your other frames to MyCombatHider instead of UIParent
For swapping actionbar pages, you just can't automate that. While in combat, a hardware event (key press or mouse click) is required to change pages.

Disabling the pageup/down buttons should be safe, but only if you do it out of combat. There's no need to wait for ADDON_LOADED; you can just do it in the main chunk.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-15-14, 06:10 AM   #3
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Furthermore there is only a fixed number of action IDs available (120 or 130 or something). And almost all of them are in use.
That means you can't create additional action bars this way.
  Reply With Quote
04-15-14, 09:57 AM   #4
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
Originally Posted by Duugu View Post
Furthermore there is only a fixed number of action IDs available (120 or 130 or something). And almost all of them are in use.
That means you can't create additional action bars this way.
Figured it was something like that.

Also Phanx as always thanks for the input
__________________
Tweets YouTube Website
  Reply With Quote
04-15-14, 10:41 AM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Here's an overview on what I found out about action IDs:

1 - 12 MainMenuBar stance 2+4
13 - 19 MainMenuBar Page 2
20 - 24 Bags
25 - 36 MultiBarRight
37 - 48 MultiBarLeft
49 - 60 MultiBarBottomRight
61 - 72 MultiBarBottomLeft
73 - 84 MainMenuBar Stance 3
85 - 96 ??
97 - 108 MainMenuBar Stance 1
109- 120 ??

Don't know if the two ?? are free. One of them could be the pet bar.

I guess a class without any stances could use 73-84 and 97-108 as additional action buttons.

[e]
Afaik Geist uses this approach. It lists the action IDs as this:

1-12 Main Bar (Unused by Warriors or Monks)
13-24 Second Bar
25-36 Side Bar 1
37-48 Side Bar 2
49-60 Bottom Right Bar
61-72 Bottom Left Bar
73-84 Warrior Battle, Druid Cat, Rogue Stealth, Priest Shadowform
85-96 Warrior Defensive, Druid Tree
97-108 Warrior Berserker, Druid Bear
109-120 Druid Moonkin
121-132 Possess Bar (Unusable)

Last edited by Duugu : 04-15-14 at 10:49 AM.
  Reply With Quote
04-15-14, 04:26 PM   #6
10leej
A Molten Giant
 
10leej's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2011
Posts: 583
Ah though we had access to at least one more bar without affecting the stances. Guess not
__________________
Tweets YouTube Website
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Making Actionbars


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off