WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Castbar size on nameplates (https://www.wowinterface.com/forums/showthread.php?t=48490)

Rainrider 11-11-13 02:33 PM

Castbar size on nameplates
 
I have a small addon that modifies the unit nameplates. I can't however figure out how to make the castbar fixed size. It somehow changes size on some occasions, mostly when a castbar becomes visible mid-cast or when a cast changes to a channel. Could someone help with this please? The code can be found on github.

Resike 11-11-13 05:51 PM

Couldn't test it ingame only take a look at the code, but couldn't castbar:ClearAllPoints() cause this?

Oppugno 11-12-13 12:54 AM

Disclaimer: This is all just my observations/theory. I have no other evidence to back it up.

It seems there is some form of throttling/cut off point when recursion would occur in the "OnSizeChanged" script e.g. calling SetHeight() from within it. This prevents the bar height from being updated until a later point (in this particular case it seems your next "OnShow"). By placing a GetHeight() call in the script handler you seem to be able to force the update to occur immediately. This will of course allow the recursion to occur, but you have a statement in there to break it.

Code:

local Castbar_OnSizeChanged = function(castbar, width, height)
    if floor(height + 0.1) ~= castBarHeight then
        local healthbar = castbar.hp
        castbar:ClearAllPoints()
        castbar:SetPoint("TOPLEFT", healthbar, "BOTTOMLEFT", 0, -4)
        castbar:SetPoint("TOPRIGHT", healthbar, "BOTTOMRIGHT", 0, -4)
        castbar:SetHeight(castBarHeight)

        castbar:GetHeight()
    end
end


zork 11-12-13 02:46 AM

Hooking the OnShow event on the castbar does work for me.
http://code.google.com/p/rothui/sour...2/core.lua#187
Another option is to hook OnValueChanged but imo OnShow is enough.

Oppugno 11-12-13 05:27 AM

@zork: Unfortunately just hooking OnShow won't work for this implentation. Your nameplates and therefore castbars are hidden and shown every frame so the OnShow handler is run on every frame the cast bar is active. (I found that out the annoying way when I implemented my own like that)

As for a nicer solution than what I posted before, why not just set the two TOPLEFT and TOPRIGHT anchors and instead of setting the height of the bar set a BOTTOM anchor with the correct offset?

Rainrider 11-12-13 05:47 AM

@zork
That's why I'm curious why my code does not work. I also thought that OnShow should be sufficient but found out it isn't, that's why I hooked OnSizeChanged too. But somehow it still changes sizes and stays like that either with a visible lag (and changes then to the set height) or until the next cast or all the time for that given nameplate. So it somehow seems that my code behaves differently for the different nameplates and I just don't find any explanation for that.

However your approach is different than mine. I don't understand why you create "double" nameplates and re-parent stuff to them. You have a lot of overhead to it as you re-anchor all your double plates every second. What is the benefit of that?

@Oppugno
Doesn't make much sense but I'll try it :)

@Reslike
The reason for the size change is that the castbar gets re-anchored every OnShow (at least that's the earliest point where I can catch it) relative to the castbar border (that's castbarOverlay in my code). There is a single point set - "BOTTOMRIGHT", castbarOverlay, "BOTTOMRIGHT", xOffset, yOffset (don't know the values of the offsets off the top of my head). castbarOverlay itself is anchored to the center of the nameplate and don't seem to be movable (tried that and all SetPoint calls appear to get ignored). I need ClearAllPoints() before re-anchoring. Don't know why this should cause a problem, but well the nameplates code is C-side and hidden. I actually had tried to just replace the "BOTTOMRIGHT" anchor for the sake of optimization (thus sparing the ClearAllPoints() call) but this didn't prevent the strange resizing either.

zork 11-12-13 08:01 AM

@Oppugno
Hmm. I need to check back on that aswell. But I think if you are having the hookscript handlers on oldPlate and oldPlate.castbar and only show/hide the newPlate each frame that will not trigger the onshow scripts of oldPlate and oldPlate.castbar. Thus it should be ok. But I'm not sure. Gonna test it.

Btw...Rainrider have you read http://www.wowinterface.com/forums/s...ad.php?t=46740 ?

Currently the best practice for doing nameplates is doing sth like this:
Lua Code:
  1. --RepositionAllNamePlates func
  2.   local function RepositionAllNamePlates()
  3.     RNP:Hide()
  4.     for blizzPlate, newPlate in pairs(RNP.nameplates) do
  5.       newPlate:Hide()
  6.       if blizzPlate:IsShown() then
  7.         newPlate:SetPoint("CENTER", WorldFrame, "BOTTOMLEFT", blizzPlate:GetCenter())
  8.         newPlate:SetAlpha(blizzPlate:GetAlpha())
  9.         newPlate:Show()
  10.       end
  11.     end
  12.     RNP:Show()
  13.   end
  14.  
  15.   --OnUpdate func
  16.   RNP.lastUpdate = 0
  17.   RNP.updateInterval = 1.0
  18.   local function OnUpdate(self,elapsed)
  19.     RNP.lastUpdate = RNP.lastUpdate + elapsed
  20.     RepositionAllNamePlates()
  21.     if RNP.lastUpdate > RNP.updateInterval then
  22.       SearchForNamePlates(self)
  23.       RNP.lastUpdate = 0
  24.     end
  25.   end
  26.  
  27.   WorldFrame:HookScript("OnUpdate", OnUpdate)

Basically you move all your visible nameplate elements to a new nameplate object and you hide that nameplate object each frame before applying a setpoint. So basically the object points change while being hidden. The fps gain is incredible.

Elv UI integrated that concept into the new nameplates aswell.

Rainrider 11-12-13 03:05 PM

Quote:

Originally Posted by Oppugno (Post 286893)
[...] As for a nicer solution than what I posted before, why not just set the two TOPLEFT and TOPRIGHT anchors and instead of setting the height of the bar set a BOTTOM anchor with the correct offset?

Already tried that without success. But your previous proposal seems to work out so far.

Quote:

Originally Posted by zork (Post 286899)
[...] Btw...Rainrider have you read http://www.wowinterface.com/forums/s...ad.php?t=46740 ?

Currently the best practice for doing nameplates is doing sth like this:
[...]
Basically you move all your visible nameplate elements to a new nameplate object and you hide that nameplate object each frame before applying a setpoint. So basically the object points change while being hidden. The fps gain is incredible.

Elv UI integrated that concept into the new nameplates aswell.

I read the thread but it didn't make much sense to me as I hadn't noticed any lag. I'll do a molten core run and try to verify your results.

Edit: I have a 4 fps drop. From 107 to 103.


All times are GMT -6. The time now is 10:53 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI