Thread Tools Display Modes
11-11-13, 02:33 PM   #1
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
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.
  Reply With Quote
11-11-13, 05:51 PM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Couldn't test it ingame only take a look at the code, but couldn't castbar:ClearAllPoints() cause this?
  Reply With Quote
11-12-13, 12:54 AM   #3
Oppugno
A Fallenroot Satyr
Join Date: Sep 2012
Posts: 22
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
  Reply With Quote
11-12-13, 02:46 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
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.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
11-12-13, 05:27 AM   #5
Oppugno
A Fallenroot Satyr
Join Date: Sep 2012
Posts: 22
@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?
  Reply With Quote
11-12-13, 05:47 AM   #6
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
@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.
  Reply With Quote
11-12-13, 08:01 AM   #7
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
@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.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 11-12-13 at 08:25 AM.
  Reply With Quote
11-12-13, 03:05 PM   #8
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Originally Posted by Oppugno View Post
[...] 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.

Originally Posted by zork View Post
[...] 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.

Last edited by Rainrider : 11-12-13 at 04:07 PM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Castbar size on nameplates

Thread Tools
Display Modes

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