View Single Post
10-22-20, 07:45 AM   #29
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
And after some more tests with the different action bar change requirements and found this allowed things to work in all scenarios so far found:

Lua Code:
  1. nUI_ActionBar:SetAttribute(
  2.             "_onstate-page",
  3.             [[
  4.            
  5.                 if not newstate then return end
  6.                 newstate = tonumber(newstate)
  7.            
  8.                 if HasVehicleActionBar() then
  9.                     newPage = GetVehicleBarIndex() or 0
  10.                 elseif HasOverrideActionBar() then
  11.                     newPage = GetOverrideBarIndex() or 0
  12.                 elseif HasTempShapeshiftActionBar() then
  13.                     newPage = GetTempShapeshiftBarIndex() or 0
  14.                 elseif HasBonusActionBar() and GetActionBarPage() == 1 then
  15.                     newPage = GetBonusBarIndex() or 0        
  16.                 else
  17.                     newPage = 0
  18.                 end
  19.            
  20.                 if ( newPage == 0 ) then
  21.                     newstate = GetActionBarPage()
  22.                 end
  23.            
  24.         self:SetAttribute( "actionpage", tonumber( newstate ) );
  25.                
  26.            
  27.                 -- Update the buttons
  28.                 for id = 1, #ActionButtons do
  29.                     local button = ActionButtons[id]
  30.             if not button:GetAttribute( "nUI_ActionButtonOverlay" ) then
  31.             button:SetAttribute( "touch", nil )
  32.                         button:SetAttribute('actionpage', newstate)
  33.                     end
  34.                 end
  35.  
  36.         ]]
  37.     );

In addition to these event watching additions

Lua Code:
  1. elseif event == "UPDATE_VEHICLE_ACTIONBAR" then
  2.         nUI_ActionBar:Execute(([[   self:SetAttribute('state-page',GetVehicleBarIndex())  ]]))
  3.     elseif event == "UPDATE_OVERRIDE_ACTIONBAR" then
  4.         nUI_ActionBar:Execute(([[   self:SetAttribute('state-page',GetOverrideBarIndex())  ]]))


And for a non nUI setup for those wanting to see the basics in full
Lua Code:
  1. local addon,data = ...
  2. data = data or {}
  3. data.BlizzUI = data.BlizzUI or CreateFrame("Frame")
  4. --MainMenuBarArtFrame:SetParent(data.BlizzUI)
  5. data.BlizzUI:Hide()
  6.  
  7.  
  8. local BUTTON_SIZE, BUTTON_SPACING = 50, 1
  9.  
  10. ------------------------------------------------------
  11. --[[              Bar Setup                       ]]--
  12. ------------------------------------------------------
  13. local barFrame = CreateFrame("Frame", "XBar_Main", UIParent, "SecureHandlerStateTemplate")
  14. barFrame:SetSize((BUTTON_SIZE + BUTTON_SPACING) * NUM_ACTIONBAR_BUTTONS, BUTTON_SIZE)
  15. barFrame:SetPoint("CENTER")
  16.  
  17. local background = barFrame:CreateTexture(nil, "BACKGROUND")
  18. background:SetColorTexture(0, 0, 0, 0.5)
  19. background:SetAllPoints()
  20.  
  21. barFrame:Execute([[
  22.     ActionButtons = newtable()
  23. ]])
  24.  
  25. ------------------------------------------------------
  26. --[[                 Button Setup                 ]]--
  27. ------------------------------------------------------
  28. local buttons = { }
  29. for id = 1, NUM_ACTIONBAR_BUTTONS do
  30.     local button = CreateFrame("CheckButton", "$parent_Button" .. id, barFrame, "ActionBarButtonTemplate")
  31.     button:SetID(id)
  32.     button:SetSize(BUTTON_SIZE, BUTTON_SIZE)
  33.    
  34.     if id ~= 1 then
  35.         button:SetPoint("LEFT", buttons[id - 1], "RIGHT", BUTTON_SPACING, 0)
  36.     else
  37.         button:SetPoint("LEFT", 5, 0)
  38.     end
  39.  
  40.     local background = button:CreateTexture(nil, "BACKGROUND")
  41.     background:SetColorTexture(1, 1, 1, 0.5)
  42.     background:SetAllPoints()
  43.  
  44.     button.NormalTexture:Hide()
  45.  
  46.     barFrame:SetFrameRef("button", button)
  47.     barFrame:Execute(([[
  48.         ActionButtons[%s] = self:GetFrameRef("button")
  49.     ]]):format(id))
  50.  
  51.     buttons[id] = button
  52. end
  53. barFrame.Buttons = buttons
  54.  
  55. ------------------------------------------------------
  56. --[[                 Secure Stuff                 ]]--
  57. ------------------------------------------------------
  58. barFrame:Execute([[
  59.     self:SetAttribute("frameref-button", nil)
  60. ]])
  61.  
  62. barFrame:SetAttribute('_onstate-page', ([[
  63.     if not newstate then return end
  64.     newstate = tonumber(newstate)
  65.        
  66.     if HasVehicleActionBar() then
  67.         newPage = GetVehicleBarIndex() or 0
  68.     elseif HasOverrideActionBar() then
  69.         newPage = GetOverrideBarIndex() or 0
  70.     elseif HasTempShapeshiftActionBar() then
  71.         newPage = GetTempShapeshiftBarIndex() or 0
  72.     elseif HasBonusActionBar() and GetActionBarPage() == 1 then
  73.         newPage = GetBonusBarIndex() or 0    
  74.     else
  75.         newPage = 0
  76.     end
  77.            
  78.     if ( newPage == 0 ) then
  79.         newstate = GetActionBarPage()
  80.     end
  81.        
  82.     self:SetAttribute("actionpage", newstate)
  83.  
  84.     for id = 1, #ActionButtons do
  85.         ActionButtons[id]:SetAttribute('actionpage', newstate)
  86.     end
  87.  
  88. ]]):gsub('NUM_ACTIONBAR_BUTTONS', NUM_ACTIONBAR_BUTTONS))
  89.  
  90.  
  91.  
  92. ------------------------------------------------------
  93. --[[           Registration Stuff                 ]]--
  94. ------------------------------------------------------
  95. RegisterStateDriver(
  96.     barFrame, "page", string.format(
  97.         "[vehicleui][possessbar] %d; [vehicleui] %d; [overridebar] %d; [shapeshift] %d; " ..
  98.         "[bar:2] 2; [bar:3] 3; [bar:4] 4; [bar:5] 5; [bar:6] 6; " ..
  99.         "[bonusbar:1] 7; [bonusbar:2] 8; [bonusbar:3] 9; [bonusbar:4] 10; [bonusbar:5] 11; 1",
  100.         GetVehicleBarIndex(), GetVehicleBarIndex(), GetOverrideBarIndex(), GetTempShapeshiftBarIndex())
  101. );
  102.  
  103. OverrideActionBarLeaveFrameLeaveButton:SetParent(barFrame)
  104. OverrideActionBarLeaveFrameLeaveButton:SetAllPoints(buttons[12])
  105. RegisterStateDriver(OverrideActionBarLeaveFrameLeaveButton, "visibility", "[canexitvehicle] show; hide")
  106.  
  107. local function OnEvent(self,event,...)
  108.     if event == "UPDATE_VEHICLE_ACTIONBAR" then
  109.         barFrame:Execute(([[   self:SetAttribute('state-page',GetVehicleBarIndex())  ]]))
  110.     elseif event == "UPDATE_OVERRIDE_ACTIONBAR" then
  111.         barFrame:Execute(([[   self:SetAttribute('state-page',GetOverrideBarIndex())  ]]))        
  112.     end
  113. end
  114.  
  115. barFrame:RegisterEvent("UPDATE_VEHICLE_ACTIONBAR")
  116. barFrame:RegisterEvent("UPDATE_OVERRIDE_ACTIONBAR")
  117. barFrame:SetScript("OnEvent",OnEvent)
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote