So, Blizzard was kind enough introduce
StanceButton1:SetPoint(...) inside
StanceBar.lua:StanceBar_Update()
Code:
function StanceBar_Update ()
local numForms = GetNumShapeshiftForms();
if ( numForms > 0 and not IsPossessBarVisible()) then
--Setup the Stance bar to display the appropriate number of slots
if ( numForms == 1 ) then
StanceBarMiddle:Hide();
StanceBarRight:SetPoint("LEFT", "StanceBarLeft", "LEFT", 12, 0);
StanceButton1:SetPoint("BOTTOMLEFT", "StanceBarFrame", "BOTTOMLEFT", 12, 3);
elseif ( numForms == 2 ) then
StanceBarMiddle:Hide();
StanceBarRight:SetPoint("LEFT", "StanceBarLeft", "RIGHT", 0, 0);
else
StanceBarMiddle:Show();
StanceBarMiddle:SetPoint("LEFT", "StanceBarLeft", "RIGHT", 0, 0);
StanceBarMiddle:SetWidth(37 * (numForms-2));
StanceBarMiddle:SetTexCoord(0, numForms-2, 0, 1);
StanceBarRight:SetPoint("LEFT", "StanceBarMiddle", "RIGHT", 0, 0);
end
StanceBarFrame:Show();
StanceBar_UpdateState();
else
StanceBarFrame:Hide();
end
UIParent_ManageFramePositions();
end
The problem I'm having is that I set
StanceButton1:SetMovable(true) and
StanceButton1:SetUserPlaced(true). However,
StanceBar_Update() gets executed after whatever code that does user placement rendering it useless.
So I tried a couple of hacks to prevent
StanceBar_Update() from moving
StanceButton1:
1. I just override Blizzard's function, however this obviously caused taint issues.
lua Code:
function StanceBar_Update()
local numForms = GetNumShapeshiftForms()
if (numForms > 0 and not IsPossessBarVisible()) then
StanceBarFrame:Show()
securecall('StanceBar_UpdateState')
else
StanceBarFrame:Hide()
end
securecall('UIParent_ManageFramePositions')
end
2. I figured I could force the statement
numForms == 1 to always be false, because that's the only time they re-position. I figured this was a golden solution, however, it also caused taint
lua Code:
StanceBarFrame.numForms = GetNumShapeshiftForms()
3. Now I tried to save the position of
StanceButton1 before
StanceBar_Update() moves it, and do a
hooksecurefunc('StanceBar_Update', ...) and move it after that. Also taint, apparently, you can't do
StanceButton1:ClearAllPoints() from inside that hook (WTF?):
lua Code:
local point, relativeTo, relativePoint, xOffset, yOffset = StanceButton1:GetPoint()
hooksecurefunc('StanceBar_Update', function()
if (GetNumShapeshiftForms() == 1) then
StanceButton1:ClearAllPoints()
StanceButton1:SetPoint(point, relativeTo, relativePoint, xOffset, yOffset)
end
end
4. Next, I came up with the idea of just calling
StanceBar_Update() immediately in my code to have it execute before the user position got set. This oddly enough also caused taint
lua Code:
securecall('StanceBar_Update')
5. This works, but is ugly as hell and some quirks appear from time to time:
lua Code:
local point, relativeTo, relativePoint, xOffset, yOffset
local f = CreateFrame('Frame')
f:RegisterEvent('VARIABLES_LOADED')
f:RegisterEvent('PLAYER_ALIVE')
f:SetScript('OnEvent', function(self, event, ...)
if (event == 'VARIABLES_LOADED') then
point, relativeTo, relativePoint, xOffset, yOffset = StanceButton1:GetPoint()
self:UnregisterEvent('VARIABLES_LOADED')
end
if (event == 'PLAYER_ALIVE') then
if (point) then
StanceButton1:ClearAllPoints()
StanceButton1:SetPoint(point, relativeTo, relativePoint, xOffset, yOffset)
end
self:UnregisterEvent('PLAYER_ALIVE')
end
end)
The taint causes a interface blocked action thingie when trying to do action bar switching when in combat, and blocked it from switching. Anyone have any thoughts? I find it weird that
StanceButton1:ClearAllPoints() sometimes causes taint, and sometimes it doesn't.
Oh yeah, the addon is
nMainbar and here's the MoP source:
https://github.com/renstrom/NeavUI/b.../stancebar.lua.