Quantcast
Splitting a powerbar into segments? - WoWInterface
Thread Tools Display Modes
10-12-16, 08:39 AM   #1
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,739
Splitting a powerbar into segments?

I'm currently looking for ideas on how to split statusbars into segments (graphically only).

My current idea is as follows...

Statusbar before:


Statusbar after:


Code idea for a power bar as an example:
Lua Code:
  1. local function CreateSplit(self,i)
  2.   local split = self:CreateTexture()
  3.   split:SetTexture(abc)
  4.   split:SetSize(6,self:GetHeight())
  5.   local layer, sublayer = self:GetStatusBarTexture():GetDrawLayer()
  6.   split:SetDrawLayer(layer,sublayer+1)
  7.   self.splits[i] = split
  8.   return split
  9. end
  10.  
  11. local function UpdateSplits(self,maxSegments)
  12.   if not self.useSplits then return end
  13.   if self.maxSegments == maxSegments then return end
  14.   self.maxSegments = maxSegments
  15.   if maxSegements < 2 then return end
  16.   if maxSemgents > 8 then maxSegments = 5 end --anything above 8 will be split into 5 parts of 20%.
  17.   if not self.splits then self.splits = {} end
  18.   local p = self:GetWidth()/maxSegments
  19.   for i=1,7 do
  20.     if i>maxSemgents-1 then
  21.       if self.splits[i] and self.splits[i]:IsShown() then
  22.         self.splits[i]:Hide()
  23.       end
  24.     else
  25.       local split = self.splits[i] or CreateSplit(self,i)
  26.       split:SetPoint("CENTER",self,"LEFT",p*i,0)
  27.       if not split:IsShown() then split:Show() end
  28.     end
  29.   end
  30. end
  31.  
  32. local function UpdatePower(self, event, unit, powerType)
  33.   if self.unit ~= unit then return end
  34.   local ppmax = UnitPowerMax(unit, powerType)
  35.   UpdateSplits(self,ppmax)
  36.   ...
  37. end

What do you think about that?
Would you do it differently? Why?
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

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

Last edited by zork : 10-12-16 at 09:01 AM.
  Reply With Quote
10-12-16, 10:30 AM   #2
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,704
Custom texture
  Reply With Quote
10-12-16, 11:56 AM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,991
If I remember right, the StatusBar only changes the size of the texture, stretching it over the entire bar. My honest opinion would be to ditch the StatusBar object, manipulate a texture object manually, and update its TexCoord accordingly. I would honestly like to see the performance impact between these two methods as I have pretty much used the later exclusively. Either way, if you can manipulate the TexCoord of a StatusBar with a custom texture, that would be the preferred way as you could have more options on what the "splits" look like, including creating transparent gaps in the bar.
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-12-16 at 12:00 PM.
  Reply With Quote
10-12-16, 12:14 PM   #4
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Well I suppose you could simply use appropriately low status bar values. That wouldn't give you the separators for free, of course.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
10-12-16, 12:18 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,307
DUF status bars are based on the TexCoord method. Take from that what you will.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 10-12-16 at 12:32 PM.
  Reply With Quote
10-12-16, 01:26 PM   #6
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,739
Thanks. I do not want to put that into the statusbar texture or integrate that in any other texture though. The splits are dynamic. Some bars have 4 other bars have 6 splits. I use them for class bars atm. On top of that the bar is configurable which would result in undesired stretches.

Here is my solution for now:
https://github.com/zorker/rothui/blo...assBar.lua#L35

Works well and is only triggered when needed.
My classbar element is using the full UnitPower (where the last argument is true). Not the segmented one. Underneath the split textures is a longer statusbar.



__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW) | TDMOG

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

Last edited by zork : 10-12-16 at 01:35 PM.
  Reply With Quote
10-13-16, 06:15 AM   #7
ObbleYeah
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Sep 2008
Posts: 210
alternatively, you could use unicode or texture string escape sequences + string.rep
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Splitting a powerbar into segments?

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