View Single Post
08-07-17, 08:57 AM   #4
Joker119
A Flamescale Wyrmkin
 
Joker119's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 113
I've been trying to implement this and I've had great success making the addon determine when there is an extra "half shard" ontop of the shards held (IE a shard is being made but not completed yet)

However, I'm hitting a wall when it comes to implementing it into a usable form.

What I WANT it to do, when a shard is full, the shard icon will be purple, if it is being created, it will be green. However the closest I can get is full shards are purple, and when a shard is being created, it turns all the empty slots green, instead of just the next shard slot.

Here's my code;
Lua Code:
  1. if select(2, UnitClass("player")) ~= "WARLOCK" then return end
  2.  
  3. local parent, ns = ...
  4. local oUF = ns.oUF or oUF
  5.  
  6.  
  7.  
  8. local SPELL_POWER_SOUL_SHARDS     = SPELL_POWER_SOUL_SHARDS
  9.  
  10.  
  11. local Update = function(self, event, unit, powerType)
  12.   local bar = self.SoulShardPowerBar
  13.   local mod = UnitPowerDisplayMod(7)
  14.   local cur_unmod = UnitPower("player", 7, true)
  15.   local max_unmod = UnitPowerMax("player", 7, true)
  16.   local cur = UnitPower("player", 7)
  17.   local max = UnitPowerMax("player", 7)
  18.   --adjust the width of the soulshard power frame
  19.   local w = 64*(max+1)
  20.   bar:SetWidth(w)
  21.   for i = 1, bar.maxOrbs do
  22.     local orb = self.SoulShards[i]
  23.     if i > max then
  24.        if orb:IsShown() then orb:Hide() end
  25.     else
  26.       if not orb:IsShown() then orb:Show() end
  27.     end
  28.   end
  29.     for i = 1, bar.maxOrbs do
  30.         local orb = self.SoulShards[i]
  31.         local orb2 = self.SoulShards[i+1]
  32.         local full = cur/max
  33.         if(i <= cur) then
  34.             if full == 1 then
  35.                 orb.fill:SetVertexColor(1,0,0)
  36.                 orb.glow:SetVertexColor(1,0,0)
  37.             else
  38.                 orb.fill:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  39.                 orb.glow:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  40.             end
  41.             orb.fill:Show()
  42.             orb.glow:Show()
  43.             orb.highlight:Show()
  44.         else
  45.             orb.fill:Hide()
  46.             orb.glow:Hide()
  47.             orb.highlight:Hide()
  48.         end
  49.         if(i > cur) then
  50.             local orb = self.SoulShards[i]
  51.             if cur_unmod/mod > cur then
  52.                 orb.fill:SetVertexColor(0,1,0)
  53.                 orb.glow:SetVertexColor(0,1,0)
  54.                 orb.fill:Show()
  55.                 orb.glow:Show()
  56.                 orb.highlight:Show()
  57.             end
  58.         end
  59.     end
  60. end
  61.  
  62. local Visibility = function(self, event, unit)
  63.   local element = self.SoulShards
  64.   local bar = self.SoulShardPowerBar
  65.   if UnitHasVehicleUI("player")
  66.     or ((HasVehicleActionBar() and UnitVehicleSkin("player") and UnitVehicleSkin("player") ~= "")
  67.     or (HasOverrideActionBar() and GetOverrideBarSkin() and GetOverrideBarSkin() ~= ""))
  68.   then
  69.     bar:Hide()
  70.   elseif(select(2, UnitClass("player")) == "WARLOCK") then
  71.     bar:Show()
  72.     element.ForceUpdate(element)
  73.   else
  74.     bar:Hide()
  75.   end
  76. end
  77.  
  78. local Path = function(self, ...)
  79.   return (self.SoulShards.Override or Update) (self, ...)
  80. end
  81.  
  82. local ForceUpdate = function(element)
  83.   return Path(element.__owner, "ForceUpdate", element.__owner.unit, "SOUL_SHARDS")
  84. end
  85.  
  86. local function Enable(self, unit)
  87.   local element = self.SoulShards
  88.   if(element and unit == "player") then
  89.     element.__owner = self
  90.     element.ForceUpdate = ForceUpdate
  91.  
  92.     self:RegisterEvent("UNIT_POWER_FREQUENT", Path)
  93.     self:RegisterEvent("UNIT_DISPLAYPOWER", Path)
  94.     self:RegisterEvent("PLAYER_TALENT_UPDATE", Visibility, true)
  95.     self:RegisterEvent("SPELLS_CHANGED", Visibility, true)
  96.     self:RegisterEvent("UPDATE_OVERRIDE_ACTIONBAR", Visibility, true)
  97.     self:RegisterEvent("UNIT_ENTERED_VEHICLE", Visibility)
  98.     self:RegisterEvent("UNIT_EXITED_VEHICLE", Visibility)
  99.  
  100.     local helper = CreateFrame("Frame") --this is needed...adding player_login to the visivility events does not do anything
  101.     helper:RegisterEvent("PLAYER_LOGIN")
  102.     helper:SetScript("OnEvent", function() Visibility(self) end)
  103.  
  104.     return true
  105.   end
  106. end
  107.  
  108. local function Disable(self)
  109.   local element = self.SoulShards
  110.   if(element) then
  111.     self:UnregisterEvent("UNIT_POWER_FREQUENT", Path)
  112.     self:UnregisterEvent("UNIT_DISPLAYPOWER", Path)
  113.     self:UnregisterEvent("PLAYER_TALENT_UPDATE", Visibility)
  114.     self:UnregisterEvent("SPELLS_CHANGED", Visibility)
  115.     self:UnregisterEvent("UPDATE_OVERRIDE_ACTIONBAR", Visibility)
  116.     self:UnregisterEvent("UNIT_ENTERED_VEHICLE", Visibility)
  117.     self:UnregisterEvent("UNIT_EXITED_VEHICLE", Visibility)
  118.   end
  119. end
  120.  
  121. oUF:AddElement("SoulShards", Path, Enable, Disable)

The important part is
Lua Code:
  1. for i = 1, bar.maxOrbs do
  2.         local orb = self.SoulShards[i]
  3.         local orb2 = self.SoulShards[i+1]
  4.         local full = cur/max
  5.         if(i <= cur) then
  6.             if full == 1 then
  7.                 orb.fill:SetVertexColor(1,0,0)
  8.                 orb.glow:SetVertexColor(1,0,0)
  9.             else
  10.                 orb.fill:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  11.                 orb.glow:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  12.             end
  13.             orb.fill:Show()
  14.             orb.glow:Show()
  15.             orb.highlight:Show()
  16.         else
  17.             orb.fill:Hide()
  18.             orb.glow:Hide()
  19.             orb.highlight:Hide()
  20.         end
  21.         if(i > cur) then
  22.             if cur_unmod/mod > cur then
  23.                 orb.fill:SetVertexColor(0,1,0)
  24.                 orb.glow:SetVertexColor(0,1,0)
  25.                 orb.fill:Show()
  26.                 orb.glow:Show()
  27.                 orb.highlight:Show()
  28.             end
  29.         end
  30.     end
  31. end

I don't know how to make the second if function ( if(i > cur) then ) select the NEXT shard icon only.

The local "orb2" was an attempt at having it select the next shard when it fills the previous, however when I change the second if condition's "orb.fill" with "orb2.fill" it gives me an error saying it's a nil value.
It's been awhile since i've done coding and I just can't figure this one out.
Probably doesn't help I haven't slept in 26hrs ><
__________________
My Addons | "If someone says something is impossible, they lack either imagination, or determination."
  Reply With Quote