View Single Post
10-02-12, 09:29 AM   #22
Paopao001
A Fallenroot Satyr
 
Paopao001's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2011
Posts: 20
Hello.
I would like to change the width of each class icon when the max number of the resource changes.

Lua Code:
  1. local ClassIconsPostUpdate = function(element, cur, max, maxchange)
  2.     for i = 1, 5 do
  3.         if cur == max then
  4.             element[i]:SetStatusBarColor(unpack(classicon_colors[cur]))
  5.         else
  6.             element[i]:SetStatusBarColor(unpack(classicon_colors[i]))
  7.         end
  8.         if maxchange then
  9.             element[i]:SetWidth((oUF_MlightDB.width+3)/max-3)
  10.         end    
  11.     end
  12. end
Lua Code:
  1. local _, class = UnitClass("player")
  2.        
  3.         -- Runes, Shards, HolyPower and so on --
  4.         if multicheck(class, "DEATHKNIGHT", "WARLOCK", "PALADIN", "MONK", "SHAMAN", "PRIEST", "MAGE", "ROGUE", "DRUID") then
  5.             local count
  6.             if class == "DEATHKNIGHT" then
  7.                 count = 6
  8.             elseif class == "WARLOCK" then
  9.                 count = 4
  10.             elseif class == "PALADIN" or class == "PRIEST" or class == "MONK" then
  11.                 count = 5
  12.             elseif class == "SHAMAN" then
  13.                 count = 4
  14.             elseif class == "MAGE" then
  15.                 count = 6
  16.             elseif class == "ROGUE" or class == "DRUID" then
  17.                 count = 5 -- combopoints
  18.             end
  19.  
  20.             local bars = CreateFrame("Frame", nil, self)
  21.             bars:SetPoint("BOTTOMLEFT", self, "TOPLEFT", 0, 3)
  22.             bars:SetSize(oUF_MlightDB.width, 10)
  23.  
  24.             for i = 1, count do
  25.                 bars[i] = createStatusbar(bars, texture, nil, oUF_MlightDB.height*-(oUF_MlightDB.hpheight-1), (oUF_MlightDB.width+2)/count-3, 1, 1, 1, 1)
  26.  
  27.                 if i == 1 then
  28.                     bars[i]:SetPoint("BOTTOMLEFT", bars, "BOTTOMLEFT")
  29.                 else
  30.                     bars[i]:SetPoint("LEFT", bars[i-1], "RIGHT", 3, 0)
  31.                 end
  32.  
  33.                 bars[i].bd = createBackdrop(bars[i], bars[i], 1)
  34.             end
  35.  
  36.             if class == "DEATHKNIGHT" then
  37.                 self.Runes = bars
  38.             elseif class == "WARLOCK" then
  39.                 self.WarlockSpecBars = bars
  40.             elseif class == "PALADIN" or class == "PRIEST" or class == "MONK" then
  41.                 self.ClassIcons = bars
  42.                 self.ClassIcons.UpdateTexture = function() end
  43.                 self.ClassIcons.PostUpdate = ClassIconsPostUpdate
  44.             elseif class == "SHAMAN" then
  45.                 self.TotemBar = bars
  46.             elseif class == "MAGE" then
  47.                 self.ArcaneCharge = bars
  48.             elseif class == "ROGUE" or class == "DRUID" then
  49.                 self.CPoints = bars
  50.                 self.CPoints.PostUpdate = CpointsPostUpdate
  51.             end
  52.         end

When the max number of power changes, it works properly. But there's a problem when log-in.
If the player is shadow priest. The width of each element is 1/5 of the width of player frame.
I would like it to be 1/3. A paladin under lvl 85 ,a warlock with 3 soul shards and a monk with 4 chis got the same problem.
The solution I found is to change element.__max to 5 in oUF\elements\classicons.lua(because I can't find a right place to make it in my layout).
This means: when I create the frames/textures for the element, I set the width of each icon suppose the player got 5 class icons. When PLAYER_TALENT_UPDATE fires, oUF update the element and oldMax ~= max is true in element:PostUpdate(cur, max, oldMax ~= max). So the layout can change the width of each icon when log-in.

Haste, I really appreciate if you could set element.__max to 5 in oUF\elements\classicons.lua or make it easier to change element.__max in layout.
__________________

I hope you could understand my broken English.
If I offended you it was unwitting.
  Reply With Quote