Thread Tools Display Modes
11-13-10, 11:32 AM   #1
Virance
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 12
Custom ActionBar paging script, not correct on login?

Hello again everyone,

I'm working on a small script that makes the MultiBarBottomLeft page with player stance; it works great except one minor problem. When the player zones (either on first login or on entering instance) it randomly is set to the wrong bar. For characters with stances (warrior/druid/rogue) simply switching stances fixes it; for everyone else you have to /reload until it fixes (almost always the first reload).

Not a major issue really, I'm just curious as to what I'm doing wrong

Thanks in advance!

EDIT:
If it helps, it appears as though when it's "broken" it's set to bar 6, which I believe is the default bar for MultiBarBottomLeft perhaps? It's strange though, I have it printing whenever GetBar() is called; it's being called 3 times when you first log in, so you'd imagine that it was actually working.

Is there some self:ForceUpdatePage() I can call on login to ensure that it works proper?

EDIT 2:
Can't seem to figure this one out still; I just switched it to be based out of bar 6 instead of bar 2 which "fixed" it in the sense that when it's not working it's still correct.

Code:
if not TukuiCF["actionbar"].enable == true then return end

---------------------------------------------------------------------------
-- Setup Main Action Bar.
-- Now used for stances, Bonus, Vehicle at the same time.
-- Since t12, it's also working for druid cat stealth. (a lot requested)
---------------------------------------------------------------------------

local bar = CreateFrame("Frame", "TukuiBar2", TukuiActionBarBackground, "SecureHandlerStateTemplate")
bar:ClearAllPoints()
bar:SetAllPoints(TukuiActionBarBackground)
bar:SetFrameLevel(12)
MultiBarBottomLeft:SetParent(bar)

--[[ 
	Bonus bar classes id

	DRUID: Caster: 0, Cat: 1, Tree of Life: 2, Bear: 3, Moonkin: 4
	WARRIOR: Battle Stance: 1, Defensive Stance: 2, Berserker Stance: 3 
	ROGUE: Normal: 0, Stealthed: 1
	PRIEST: Normal: 0, Shadowform: 1
	
	When Possessing a Target: 5
]]--

local Page = {
	["DRUID"] = "[bonusbar:1] 8; [bonusbar:2] 2; [bonusbar:3] 10; [bonusbar:4] 2;",
	["WARRIOR"] = "[bonusbar:1] 2; [bonusbar:2] 8; [bonusbar:3] 10;",
	["ROGUE"] = "[bonusbar:1] 8;",
	["DEFAULT"] = "[bonusbar:0] 2;[bar:2] 2; [bar:3] 2; [bar:4] 2; [bar:5] 2; [bar:6] 2; [bonusbar:5] 2;",
}

local function GetBar()
	local condition = Page["DEFAULT"]
	local class = TukuiDB.myclass
	local page = Page[class]
	if page then
		condition = condition.." "..page
	end
	condition = condition.." 2"
	print(condition)
	return condition
end

bar:RegisterEvent("PLAYER_LOGIN")
bar:RegisterEvent("PLAYER_ENTERING_WORLD")
bar:RegisterEvent("PLAYER_TALENT_UPDATE")
bar:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
bar:RegisterEvent("KNOWN_CURRENCY_TYPES_UPDATE")
bar:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
bar:RegisterEvent("BAG_UPDATE")
bar:SetScript("OnEvent", function(self, event, ...)
	if event == "PLAYER_LOGIN" then
		local button
		for i = 1, NUM_ACTIONBAR_BUTTONS do
			button = _G["MultiBarBottomLeftButton"..i]
			self:SetFrameRef("MultiBarBottomLeftButton"..i, button)
		end	

		self:Execute([[
			buttons = table.new()
			for i = 1, 12 do
				table.insert(buttons, self:GetFrameRef("MultiBarBottomLeftButton"..i))
			end
		]])

		self:SetAttribute("_onstate-page", [[ 
			control:ChildUpdate("state", newstate)
			for i, button in ipairs(buttons) do
				button:SetAttribute("actionpage", tonumber(newstate))
			end
		]])

		
		RegisterStateDriver(self, "page", GetBar())
	elseif event == "PLAYER_ENTERING_WORLD" then
		--MainMenuBar_UpdateKeyRing()
		local button
		for i = 1, 12 do
			local b = _G["MultiBarBottomLeftButton"..i]
			local b2 = _G["MultiBarBottomLeftButton"..i-1]
			b:ClearAllPoints()
			
			if i == 1 then
				if TukuiDB.lowversion and TukuiCF.actionbar.bottomrows == 2 then
					b:SetPoint("BOTTOM", ActionButton1, "TOP", 0, TukuiDB.Scale(4))
				else
					b:SetPoint("LEFT", ActionButton12, "RIGHT", TukuiDB.Scale(4), 0)
				end
			else
				b:SetPoint("LEFT", b2, "RIGHT", TukuiDB.buttonspacing, 0)
			end
		end
	elseif event == "PLAYER_TALENT_UPDATE" or event == "ACTIVE_TALENT_GROUP_CHANGED" then
		if not InCombatLockdown() then -- Just to be safe
			RegisterStateDriver(self, "page", GetBar())
			-- Due to some odd reason these bars (MultiBarRight, MultiBarLeft) are changing position after you spent a talent point, and switch spec,
			-- I couldn't watch the exact event that does it even by using ':RegisterAllEvents()', until I'll figure it out, here is an awful hack. 
			if event == "ACTIVE_TALENT_GROUP_CHANGED" then 
				local t = 0
				self:SetScript("OnUpdate", function(self, elapsed)
					t = t + elapsed
					MainMenuBar:Hide()
					UIParent_ManageFramePositions()
					if t > 5 then
						t = 0
						self:SetScript("OnUpdate", nil)
					end
				end)
			end
		end
	else
		MainMenuBar_OnEvent(self, event, ...)
	end
end)

Last edited by Virance : 11-13-10 at 01:10 PM.
  Reply With Quote
11-14-10, 02:06 AM   #2
Taroven
A Cyclonian
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 49
GetShapeshiftForm() sometimes returns a bogus value before the UI is completely loaded. I've had the same problems myself, and similar issues with glyphs.

There's two ways to work around it.

1) Check against GetShapeshiftForm() against GetNumShapeshiftForms() when changing the page:
Code:
local stance = GetShapeshiftForm()
if stance > GetNumShapeshiftForms then return end -- check it later
GetNumShapeshiftForms() for Demo Warlocks (and probably Resto Druids these days) will return 1 even though they have an extra form, which may or may not be an issue for you. Easy to work around though.

2) Check only after the load process is complete and the game world is shown. There's three events which I use for that.

LFG_LOCK_INFO_RECEIVED will fire twice directly after the loading screen completes and the game world is shown. It also fires every time you open the LFG window, which makes it easy to use as a force-fix if all else fails.

ZONE_CHANGED_INDOORS will fire about a quarter second after a new-area loading screen finishes (about the same time as LFG_LOCK_INFO_RECEIVED). ZONE_CHANGED_NEW_AREA makes for a useful backup, though it doesn't have much to do with the load process.

I've noticed some irks with these events in battlegrounds, but then again I haven't really looked into PvP fixes. Shouldn't be a huge deal though.
__________________
Former author of EventHorizon Continued and Other Releases.
  Reply With Quote
11-14-10, 09:29 AM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Based on that code you want the bar to change pages for druids, rogues, and warriors in a few cases. That should be covered by:
Code:
local _, class = UnitClass('player')
local paging
if class == 'DRUID' then
	paging = "[bonusbar:1] 8; [bonusbar:3] 10; 2;",
elseif class == 'ROGUE' then
	paging = "[bonusbar:1] 8; 2",
elseif class == 'WARRIOR' then
	paging = "[bonusbar:2] 8; [bonusbar:3] 10; 2",
end
if paging then
	local header = CreateFrame('Frame', nil, UIParent, 'SecureHandlerStateTemplate')
	header:Hide()

	local name
	for id = 1, NUM_ACTIONBAR_BUTTONS do
		name = 'MultiBarBottomLeftButton' .. id
		header:SetFrameRef(name, _G[name])
	end	

	header:Execute(([[
		buttons = table.new()
		for id = 1, %s do
			buttons[id] = self:GetFrameRef('MultiBarBottomLeftButton' .. id)
		end
	]]):format(NUM_ACTIONBAR_BUTTONS))

	header:SetAttribute('_onstate-page', ([[ 
		newstate = tonumber(newstate)
		for id = 1, %s do
			buttons[id]:SetAttribute('actionpage', newstate)
		end
	]]):format(NUM_ACTIONBAR_BUTTONS))

	RegisterStateDriver(header, 'page', paging)
end
That will set up your paging for the cases where it is desired but skip it otherwise (saves a lot of background processing).

Last edited by Vrul : 11-14-10 at 10:38 AM. Reason: Typo
  Reply With Quote
11-14-10, 06:06 PM   #4
Virance
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 12
Thanks for the responses guys! I've been out of my house for a couple of days, but I'll be home and working on it tomorrow evening to test.

Tyvm for the suggestions though!
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Custom ActionBar paging script, not correct on login?


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