WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Totem-module with statusbars (https://www.wowinterface.com/forums/showthread.php?t=40405)

Mischback 06-05-11 04:49 AM

Totem-module with statusbars
 
1 Attachment(s)
The Totem-module of oUF handles totems by default with an icon a cooldown spiral.

For a current project I wanted the remaining duration to be displayed as statusbars, as it has been done with oUF_boring_totembar.

Here's my solution, thought I share it:

In your layout-file (in the section of the player-frame, for my layout), build a totem-layout (I stripped down mine a lot, this is poc-quality):

lua Code:
  1. if ( class == 'SHAMAN' ) then
  2.         local t = CreateFrame('Frame', nil, self)
  3.  
  4.         t[4] = CreateFrame('StatusBar', nil, t)
  5.         t[4]:SetSize(width, height)
  6.         t[4]:SetPoint('RIGHT', self, 'TOPRIGHT', -spacing, 0)
  7.         t[4]:SetStatusBarTexture(tex)
  8.         t[4]:SetStatusBarColor(unpack(self.colors.totems[AIR_TOTEM_SLOT]))
  9.         t[3] = CreateFrame('StatusBar', nil, t)
  10.         t[3]:SetSize(width, height)
  11.         t[3]:SetPoint('TOPRIGHT', t[4], 'TOPLEFT', -spacing, 0)
  12.         t[3]:SetStatusBarTexture(tex)
  13.         t[3]:SetStatusBarColor(unpack(self.colors.totems[WATER_TOTEM_SLOT]))
  14.         t[2] = CreateFrame('StatusBar', nil, t)
  15.         t[2]:SetSize(width, height)
  16.         t[2]:SetPoint('TOPRIGHT', t[3], 'TOPLEFT', -spacing, 0)
  17.         t[2]:SetStatusBarTexture(tex)
  18.         t[2]:SetStatusBarColor(unpack(self.colors.totems[EARTH_TOTEM_SLOT]))
  19.         t[1] = CreateFrame('StatusBar', nil, t)
  20.         t[1]:SetSize(width, height)
  21.         t[1]:SetPoint('TOPRIGHT', t[2], 'TOPLEFT', -spacing, 0)
  22.         t[1]:SetStatusBarTexture(tex)
  23.         t[1]:SetStatusBarColor(unpack(self.colors.totems[FIRE_TOTEM_SLOT]))
  24.  
  25.         self.Totems = t
  26.         self.Totems.Override = core.TotemOverride
  27.     end

As you can see, I override the default-Update-function, so here it is:

lua Code:
  1. core.TotemOverride = function(self, event, slot)
  2.     local totems = self.Totems
  3.  
  4.     local totem = totems[slot]
  5.     local haveTotem, name, start, duration, icon = GetTotemInfo(slot)
  6.     if(duration > 0) then
  7.         totem:SetMinMaxValues(0, duration)
  8.         totem.start = start
  9.         totem.duration = duration
  10.         totem.TimeSinceLastUpdate = 0
  11.         totem:SetScript('OnUpdate', function(self, elapsed)
  12.             self.TimeSinceLastUpdate = self.TimeSinceLastUpdate +  elapsed
  13.             if ( self.TimeSinceLastUpdate > 0.5 ) then
  14.                 self.TimeSinceLastUpdate = 0
  15.                 self:SetValue(self.start+self.duration-GetTime())
  16.             end
  17.         end)
  18.         totem:Show()
  19.     else
  20.         totem:Hide()
  21.     end
  22. end

You may of course throttle the update as you want it to be.

Rainrider 06-05-11 01:07 PM

@Mischback
FIRE_TOTEM_SLOT and so on translate to the corresponding totem id, so you could use a for loop for creating the totems. Here is what I use in my layout in case someone is interested.

This is what I do:

lua Code:
  1. local AddTotems = function(self, width, height)
  2.     local numTotems = MAX_TOTEMS
  3.  
  4.     self.Totems = CreateFrame("Frame", "oUF_Rain_Totems", self.Overlay)
  5.     self.Totems:SetHeight(height)
  6.     self.Totems:SetPoint("BOTTOMLEFT", self.Overlay, 0, 1)
  7.     self.Totems:SetPoint("BOTTOMRIGHT", self.Overlay, 0, 1)
  8.    
  9.     for i = 1, numTotems do
  10.         self.Totems[i] = CreateFrame("StatusBar", "oUF_Rain_Totem"..i, self.Totems)
  11.         self.Totems[i]:SetStatusBarTexture(ns.media.TEXTURE)
  12.         self.Totems[i]:SetMinMaxValues(0, 1)
  13.        
  14.         if (playerClass == "SHAMAN") then
  15.             self.Totems[i]:SetSize((215 - numTotems - 1) / numTotems, height)
  16.             self.Totems[i]:SetPoint("BOTTOMLEFT", self.Totems, (i - 1) * (214 / numTotems) + 1, 0)
  17.             self.Totems[i]:SetStatusBarColor(unpack(ns.colors.totems[i]))
  18.         elseif (playerClass == "DRUID") then -- Druid's mushrooms
  19.             self.Totems[i]:SetSize(width, height)
  20.             self.Totems[i]:SetStatusBarColor(unpack(ns.colors.class[playerClass]))
  21.                 if (i == 1) then
  22.                     self.Totems[i]:SetPoint("BOTTOM", self.Overlay, "TOP", 0, 0)
  23.                 elseif (i == 2) then
  24.                     self.Totems[i]:SetPoint("RIGHT", self.Totems[1], "LEFT", -1, 0)
  25.                 else
  26.                     self.Totems[i]:SetPoint("LEFT", self.Totems[1], "RIGHT", 1, 0)
  27.                 end
  28.         elseif (playerClass) == "DEATHKNIGHT" then -- Death knight's ghoul
  29.             self.Totems[i]:SetSize(width, height)
  30.             self.Totems[i]:SetStatusBarColor(unpack(ns.colors.class[playerClass]))
  31.             self.Totems[i]:SetPoint("BOTTOM", self.Overlay, "TOP", 0, 0)
  32.         end
  33.        
  34.         self.Totems[i]:SetBackdrop(ns.media.BACKDROP)
  35.         self.Totems[i]:SetBackdropColor(0, 0, 0)
  36.        
  37.         self.Totems[i].Destroy = CreateFrame("Button", nil, self.Totems[i])
  38.         self.Totems[i].Destroy:SetAllPoints()
  39.         self.Totems[i].Destroy:RegisterForClicks("RightButtonUp")
  40.         self.Totems[i].Destroy:SetScript("OnClick", function()
  41.             if (IsShiftKeyDown()) then
  42.                 DestroyTotem(i)
  43.             end
  44.         end)
  45.        
  46.         self.Totems[i].Destroy:EnableMouse()
  47.         self.Totems[i].Destroy:SetScript("OnEnter", function(self)
  48.             GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT")
  49.             local totem = self:GetParent()
  50.             GameTooltip:SetTotem(totem:GetID())
  51.             GameTooltip:AddLine("|cffff0000"..GLYPH_SLOT_REMOVE_TOOLTIP.."|r") -- <Shift Right Click to Remove>
  52.             GameTooltip:Show()
  53.         end)
  54.         self.Totems[i].Destroy:SetScript("OnLeave", function()
  55.             GameTooltip:Hide()
  56.         end)
  57.     end
  58.    
  59.     self.Totems.PostUpdate = ns.PostUpdateTotems
  60. end
  61. ns.AddTotems = AddTotems

and the postupdate function:
lua Code:
  1. local PostUpdateTotems = function(Totems, slot, haveTotem, name, start, duration, icon)
  2.     local delay = 0.5
  3.     local total = 0
  4.    
  5.     if (duration > 0) then
  6.         local current = GetTime() - start
  7.         if (current > 0) then
  8.             Totems[slot]:SetValue(1 - (current / duration))
  9.             Totems[slot]:SetScript("OnUpdate", function(self, elapsed)
  10.                 total = total + elapsed
  11.                 if (total >= delay) then
  12.                     total = 0
  13.                     self:SetValue(1 - ((GetTime() - start) / duration))
  14.                 end
  15.             end)
  16.         end
  17.     end
  18. end
  19. ns.PostUpdateTotems = PostUpdateTotems

Probably using Override instead of PostUpdate makes more sense, I'll take a look at it later.


All times are GMT -6. The time now is 11:54 AM.

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