Thread Tools Display Modes
Prev Previous Post   Next Post Next
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,740
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)

"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
 

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


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