Quantcast
powercolor and druidform - WoWInterface
Thread Tools Display Modes
03-18-14, 12:22 PM   #1
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
powercolor and druidform

Can i use "power.colorPower = true" on a texture other than the powerbar that updates based on the druidform.

this is what I have now, it works as long as I'm in the same stance as when I reloaded.
but as soon I change form the color will not change (from yellow to red and so on)

Lua Code:
  1. local powerType, powerToken = UnitPowerType("player")
  2. local powerColor = PowerBarColor[powerToken]
  3.        
  4. local EventFrame = CreateFrame("Frame")
  5. EventFrame:RegisterEvent("UNIT_" .. powerToken)

and I use this to set the color
Lua Code:
  1. rt2:SetVertexColor(powerColor.r, powerColor.g, powerColor.b)

So I was wondering if there is another code I could use that will update when I changes form

*edit: also I get a errormessage when I log in, and it is gone after a /reload

Last edited by saxitoxin : 03-18-14 at 12:40 PM.
  Reply With Quote
03-18-14, 02:05 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Please post your entire code. The snippets you posted without context are not enough to see what you are actually doing, let alone tell you why it isn't working, or what you should do instead.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
03-18-14, 03:04 PM   #3
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
This is the entire code for the powerframe of the playerframe

Lua Code:
  1. -- power
  2.     local power = CreateFrame("StatusBar", nil, scp)
  3.     power:SetStatusBarTexture(folder.."power_ring")
  4.     power:SetPoint("TOP", bgFrame)
  5.     power:SetPoint("LEFT")
  6.     power:SetPoint("RIGHT")
  7.     power:SetScript("OnValueChanged", updatePower)
  8.    
  9.     if powerScroll == true then
  10.         power:SetHeight(1)
  11.         local powerType, powerToken = UnitPowerType("player")
  12.         local powerColor = PowerBarColor[powerToken]
  13.        
  14.         local EventFrame = CreateFrame("Frame")
  15.         EventFrame:RegisterEvent("UNIT_" .. powerToken)
  16.        
  17.         local powerdummy = power:CreateTexture(nil,"BACKGROUND",nil,-8)
  18.         powerdummy:SetTexture(folder.."power_ring")
  19.         powerdummy:SetVertexColor(powerColor.r, powerColor.g, powerColor.b)
  20.         powerdummy:SetSize(size*1.42,size*1.42)
  21.         powerdummy:SetPoint("CENTER", bgFrame)
  22.         power.texture = powerdummy
  23.        
  24.     else
  25.         power:SetHeight(size)
  26.     end
  27.    
  28.         -- Options
  29.     power.frequentUpdates = true
  30.     power.colorPower = true
  31.    
  32.     -- Register it with oUF
  33.     self.Power = power

Everything works except for the coloring of the powerdummy when I change druid form
  Reply With Quote
03-18-14, 06:33 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
That's still very much out of context. What's in your "updatePower" function? Why are you replacing the bar's OnValueChanged script instead of using oUF's native "PostUpdate" or "Override" methods? Why are you creating your own event handling frame instead of just telling oUF which event(s) to update your element(s) on? (Also, you're never actually setting an event handling script on that frame so you may as well not be creating it in the first place, and "UNIT_powerToken" is never going to give you a valid event, as the UNIT_MANA and similar events were consolidated into UNIT_POWER several expansions ago.) What is the purpose of effectively hiding the power bar and replacing it with the "powerdummy" texture if the mystery variable "powerScroll" is set? What are you expecting this whole thing to look like and/or do?

Nobody here is psychic, and we're all far too lazy to hack into your computer just to get a look at your addon. Just post your entire file or addon.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
03-19-14, 03:00 PM   #5
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
sorry about the vague descriptions

This is the all of the written code (way not finished yet)

This is what it looks like: album
Please don't look at the mess at the bottom, that is just the prototype for how I want it to look later
Credit for lots of the textures and some of the code go to Zork

when it comes to your questions, I did not have the knowlege that those code existed, and I have no idea how to use them, I only started learning this two months ago.


Lua Code:
  1. --addonName and namespace
  2. local addon, ns = ...
  3.  
  4.  --reference config and core
  5.   local player = ns.player
  6.   --local cfg = ns.cfg
  7.  
  8. ---------------------------------------------
  9. -- FUNCTIONS
  10. ---------------------------------------------
  11.  
  12. local cc = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[(select(2, UnitClass("player")))]
  13. local size = 250 -- the size of the entire thing
  14. local hpsize = size*0.75 -- the size of the hp orb
  15. local unpack = unpack
  16. oUF.colors.power["MANA"] = {0.4, 0.6, 1} -- changes the mana color lighter
  17. local hpcolor = {0,1,0.2,0.9} -- color of the hp orb
  18. local floor, abs, sin, pi = floor, math.abs, math.sin, math.pi
  19. local treD = true -- true = 3D portrait & false = 2D portrait
  20. local powerScroll = true -- true = rotating powerframe & false = static
  21. local castScroll = true -- true = rotating castframe & false = static
  22. local showGalaxy = false -- true = show a rotating galaxy inside the hp orb & false = hide the galaxy
  23. local showModel = true -- true = show a model over the hp orb & false = hide the model
  24. local modelnr = 38512 -- the modelnr. see the model.txt file for more models
  25. local folder = "Interface\\AddOns\\"..addon.."\\media\\"
  26. local FONT = folder.."clear_font.ttf"
  27.  
  28. local updateHealth = function(hp,value)
  29.     local min, max = hp:GetMinMaxValues()
  30.     local per = 0
  31.     if max > 0 then per = value/max*100 end
  32.     local offset = hpsize-per*hpsize/100
  33.     hp.scrollFrame:SetPoint("TOP",0,-offset)
  34.     hp.scrollFrame:SetVerticalScroll(offset)
  35.     --adjust the orb spark in width/height matching the current scrollframe state
  36.     if not hp.spark then return end
  37.     local multiplier = floor(sin(per/100*pi)*1000)/1000
  38.     if multiplier <= 0.25 then
  39.         hp.spark:Hide()
  40.     else
  41.         hp.spark:SetWidth(256*hpsize/256*multiplier)
  42.         hp.spark:SetHeight(32*hpsize/256*multiplier)
  43.         hp.spark:SetPoint("TOP", hp.scrollFrame, 0, 16*hpsize/256*multiplier)
  44.         hp.spark:Show()
  45.     end
  46. end
  47.  
  48. local updatePower = function(power,value)
  49.     if powerScroll == true then
  50.         local min, max = power:GetMinMaxValues()
  51.         local per = 0
  52.         if max > 0 then per = value/max end
  53.         local rot = math.rad(per*180-180)
  54.         power.texture:SetRotation(rot)
  55.  local updateStatusBarColor = function(power, r, g, b)
  56.     power.texture:SetVertexColor(r,g,b)
  57.         end
  58.     else
  59.     end
  60. end
  61.  
  62.  
  63. local updateCast = function(cb,value)
  64.     if castScroll == true then
  65.         local min, max = cb:GetMinMaxValues()
  66.         local per = 0
  67.         if max > 0 then per = value/max end
  68.         local rot = math.rad(per*180)
  69.         cb.texture:SetRotation(-rot)
  70.     else
  71.     end
  72. end
  73.  
  74. local function CreateOrbTemplate(self)
  75.     self:SetSize(size, size)
  76.    
  77.     --menu, tooltip
  78.     self:RegisterForClicks("AnyDown")
  79.     self:HookScript("OnEnter", UnitFrame_OnEnter)
  80.     self:HookScript("OnLeave", UnitFrame_OnLeave)
  81.    
  82.     -- all bg
  83.     local f = CreateFrame("Frame","bgFrame",self)
  84.     f:SetPoint ("CENTER")
  85.     f:SetWidth(size)
  86.     f:SetHeight(size)
  87.     f.t1 = self:CreateTexture(nil,"BACKGROUND",nil,-7)
  88.     f.t2 = self:CreateTexture(nil,"BACKGROUND",nil,-8)
  89.     --texture
  90.     f.t1:SetTexture( "Interface\\AddOns\\oUF_Diablo\\media\\orb_innershadow")
  91.     f.t2:SetTexture("Interface\\AddOns\\oUF_Diablo\\media\\orb_filling19")
  92.     --colors
  93.     --  f.t1:SetVertexColor(cc.r,cc.g,cc.b,0.5)
  94.     f.t1:SetGradientAlpha("VERTICAL", cc.r,cc.g,cc.b,1, 0.1,0.1,0.1,1)
  95.     f.t2:SetGradientAlpha("VERTICAL", 0.1,0.1,0.1,1, cc.r,cc.g,cc.b,1)
  96.     --setpoint
  97.     f.t1:SetAllPoints(f)
  98.     f.t2:SetAllPoints(f)
  99.  
  100.     --[[Center Spark
  101.     local split = CreateFrame("Frame",nil,bgFrame)
  102.     split:SetFrameLevel(4)
  103.     split:SetPoint("CENTER", bgFrame, 0, 0)
  104.     split:SetWidth(size)
  105.     split:SetHeight(size*0.15)
  106.     split.t = bgFrame:CreateTexture(nil,"BACKGROUND",nil,-8)
  107.     split.t:SetTexture("Interface\\AddOns\\oUF_Diablo\\media\\orb_spark")
  108.     --split.t:SetVertexColor(cc.r,cc.g,cc.b)
  109.     split.t:SetGradientAlpha("VERTICAL", 0.1,0.1,0.1,1, cc.r,cc.g,cc.b,1)
  110.     --split.t:SetVertexColor(0.8, 0.8, 0.8)
  111.     split.t:SetAllPoints(split)
  112.     --]]
  113.     --frame
  114.     local p = CreateFrame("Frame",nil,bgFrame)
  115.     p:SetFrameLevel(10)
  116.     p:SetWidth(size*2)
  117.     p:SetHeight(size*2)
  118.     p:SetPoint("CENTER", bgFrame)
  119.     p.t = p:CreateTexture("BACKGROUND",nil,-4)
  120.     --texture
  121.     p.t:SetTexture( folder.."playerbar.tga" )
  122.     --setpoint
  123.     p.t:SetAllPoints(p)
  124.    
  125.     --statusorb location
  126.     local so = CreateFrame("Frame", nil, bgFrame)
  127.     so:SetPoint("CENTER", size*0.5025, -size*0.04)
  128.     --portrait location
  129.     local po = CreateFrame("Frame",nil,bgFrame)
  130.     po:SetPoint("CENTER", -size*0.315, size*0.5352)
  131.    
  132.     --hpframe
  133.     local hpFrame = CreateFrame("Frame",nil,bgFrame)
  134.     hpFrame:SetFrameLevel(6)
  135.     hpFrame:SetWidth(hpsize)
  136.     hpFrame:SetHeight(hpsize)
  137.     hpFrame:SetPoint("LEFT", size/(hpsize*0.22), 0)
  138.    
  139.     --healthframe
  140.     --scrollframe
  141.     local sfh = CreateFrame("ScrollFrame","$parentScrollFrame",hpFrame)
  142.     sfh:SetSize(hpFrame:GetSize())
  143.     sfh:SetPoint("CENTER")
  144.    
  145.     local sch = CreateFrame("Frame","$parentScrollChild",sfh)
  146.     sch:SetSize(hpFrame:GetSize())
  147.     sfh:SetScrollChild(sch)
  148.    
  149.     local x = math.random(1, 21)
  150.    
  151.     --health
  152.     local hp = CreateFrame("StatusBar", nil, hpFrame)
  153.     hp:SetSize(hpFrame:GetSize())
  154.     hp:SetPoint("CENTER", hpFrame)
  155.     hp:SetOrientation("VERTICAL")
  156.     hp:SetStatusBarTexture(folder.."health_orb_2")
  157.     hp:SetStatusBarColor(unpack(hpcolor))
  158.     hp.scrollFrame = sfh
  159.     hp:SetScript("OnValueChanged", updateHealth)
  160.    
  161.     -- Add a background
  162.     local hpbg = hpFrame:CreateTexture(nil,"BACKGROUND",nil,1)
  163.     hpbgo = hpFrame:CreateTexture(nil,"BACKGROUND",nil,3)
  164.     hpbg:SetSize(hpFrame:GetSize())
  165.     hpbg:SetAllPoints(hpFrame)
  166.     hpbg:SetTexture(folder.."orb_filling15")
  167.     hpbgo:SetTexture(folder.."orb_bg.tga")
  168.     hpbg:SetVertexColor(0.3,0.3,0.3)
  169.    
  170.     -- Register it with oUF
  171.     self.Health = hp
  172.     self.Health.frequentUpdates = true
  173.    
  174.     local overlay = CreateFrame("Frame","$parentOverlay",sfh)
  175.     overlay:SetAllPoints(hpFrame)
  176.    
  177.     local gloss = overlay:CreateTexture(nil,"OVERLAY",nil,2)
  178.     gloss:SetAllPoints()
  179.     gloss:SetTexture(folder.."orb_gloss")
  180.    
  181.     --powerframe
  182.     --scrollframe
  183.     local sfp = CreateFrame("ScrollFrame",nil,bgFrame)
  184.     sfp:SetSize(size,size/2*1.1)
  185.     sfp:SetPoint("BOTTOMLEFT", bgFrame, 0, 0)
  186.    
  187.     local scp = CreateFrame("Frame")
  188.     scp:SetFrameLevel(2)
  189.     sfp:SetScrollChild(scp)
  190.     scp:SetSize(f:GetSize())
  191.    
  192.     -- power
  193.     local power = CreateFrame("StatusBar", nil, scp)
  194.     power:SetStatusBarTexture(folder.."powerbar")
  195.     power:SetPoint("TOP", bgFrame)
  196.     power:SetPoint("LEFT")
  197.     power:SetPoint("RIGHT")
  198.     power:SetScript("OnValueChanged", updatePower)
  199.    
  200.     if powerScroll == true then
  201.         power:SetHeight(1)
  202.         local powerType, powerToken = UnitPowerType("player")
  203.         local powerColor = PowerBarColor[powerToken]
  204.        
  205.         local EventFrame = CreateFrame("Frame")
  206.         EventFrame:RegisterEvent("UNIT_" .. powerToken)
  207.        
  208.         local powerdummy = power:CreateTexture(nil,"BACKGROUND",nil,-8)
  209.         powerdummy:SetTexture(folder.."powerbar")
  210.         powerdummy:SetVertexColor(powerColor.r, powerColor.g, powerColor.b)
  211.         powerdummy:SetSize(size*1.42,size*1.42)
  212.         powerdummy:SetPoint("CENTER", bgFrame)
  213.         power.texture = powerdummy
  214.        
  215.     else
  216.         power:SetHeight(size)
  217.     end
  218.    
  219.         -- Options
  220.     power.frequentUpdates = true
  221.     power.colorPower = true
  222.    
  223.     -- Register it with oUF
  224.     self.Power = power
  225.    
  226.     --castbar
  227.     --[scrollframe
  228.     local sfc = CreateFrame("ScrollFrame",nil,bgFrame)
  229.     sfc:SetSize(size,size/2)
  230.     sfc:SetPoint("TOPLEFT", bgFrame, 0, 0)
  231.    
  232.     local scc = CreateFrame("Frame")
  233.     scc:SetFrameLevel(2)
  234.     sfc:SetScrollChild(scc)
  235.     scc:SetSize(f:GetSize())
  236.    
  237.     -- Position and size
  238.     local cb = CreateFrame("StatusBar", nil, scc)
  239.     cb:SetStatusBarTexture(folder.."orb_filling19")
  240.     cb:SetStatusBarColor(0.2,0.2,0.2)
  241.     cb:SetPoint("BOTTOM", bgFrame)
  242.     cb:SetPoint("LEFT")
  243.     cb:SetPoint("RIGHT")
  244.     cb:SetScript("OnValueChanged", updateCast)
  245.    
  246.     if castScroll == true then
  247.         cb:SetHeight(1)
  248.         local cbdummy = cb:CreateTexture(nil,"BACKGROUND",nil,7)
  249.         cbdummy:SetTexture(folder.."power_ring")
  250.         cbdummy:SetVertexColor(0.2,0.2,0.2)
  251.         cbdummy:SetSize(size*1.42,size*1.42)
  252.         cbdummy:SetPoint("CENTER", bgFrame)
  253.         cb.texture = cbdummy   
  254.     else
  255.         cb:SetHeight(size)
  256.     end
  257.    
  258.     -- Add spell icon
  259.     local si = CreateFrame("Frame", nil, cb)
  260.     si:SetFrameLevel(50)
  261.     si:SetPoint("CENTER", po)
  262.     local Icon = si:CreateTexture(nil, "OVERLAY", nil, 7)
  263.     Icon:SetSize(size*0.4, size*0.4)
  264.     Icon:SetPoint("CENTER", po)
  265.    
  266.         -- Add a timer
  267.     local Time = cb:CreateFontString(nil, "OVERLAY", nil, 7)
  268.     Time:SetPoint("CENTER", so)
  269.     Time:SetFont(FONT, size*0.08, "THINOUTLINE")
  270.    
  271.     -- Register it with oUF
  272.     self.Castbar = cb
  273.     self.Castbar.Time = Time
  274.     self.Castbar.Text = Text
  275.     self.Castbar.Icon = Icon   
  276.    
  277.     ---------------------------------------------
  278.     -- All the prettier things
  279.     ---------------------------------------------
  280.    
  281.     --portrait
  282.     po:SetFrameLevel(12)
  283.     po:SetSize(size*0.4, size*0.4)
  284.     local pot = po:CreateTexture("BACKGROUND",nil,6)
  285.     pot:SetTexture(folder.."orb_gloss")
  286.     pot:SetAllPoints(po)
  287.    
  288.     if treD == true then    --3D
  289.         local p = CreateFrame("PlayerModel", nil, po)  
  290.         p:SetFrameLevel(11)
  291.         p:SetPoint("CENTER")
  292.         p:SetSize(size/4, size/4)
  293.         -- Register it with oUF
  294.         self.Portrait = p
  295.     else    --2D
  296.         local p = CreateFrame("Frame", nil, po)
  297.         p:SetFrameLevel(11)
  298.         local pt = p:CreateTexture("BACKGROUND",nil,7)
  299.         pt:SetSize(size*0.35, size*0.35)
  300.         pt:SetPoint("CENTER", po)
  301.         -- Register it with oUF
  302.         self.Portrait = pt
  303.     end
  304.    
  305.     -- hp spark
  306.     local hpspark = overlay:CreateTexture(nil,"BACKGROUND",nil,1)
  307.     hpspark:SetTexture("Interface\\AddOns\\DiscoKugel2\\media\\orb_split")
  308.     hpspark:SetVertexColor(unpack(hpcolor))
  309.     local adjust = hpsize/256
  310.     hpspark:SetWidth(256*adjust)
  311.     hpspark:SetHeight(32*adjust)
  312.     hpspark:SetPoint("TOP", sfh, 0, -16*adjust)
  313.     hpspark:SetBlendMode("ADD")
  314.     hp.spark_adjust = adjust
  315.     hp.spark = hpspark
  316.     hp.spark:Hide()
  317.        
  318.     -- galaxy  
  319.     if showGalaxy == true then
  320.     for i=1,3 do
  321.         local galaxy = sch:CreateTexture(nil, "BACKGROUND", nil, sublevel)
  322.         galaxy:SetSize(hpFrame:GetSize())
  323.         galaxy:SetPoint("CENTER")
  324.         galaxy:SetTexture(folder.."galaxy"..i)
  325.         galaxy:SetVertexColor(0.1,0.8,0.3,0.5)
  326.         --galaxy:SetVertexColor(unpack(hpcolor))
  327.         galaxy:SetAlpha(0.8)
  328.         galaxy:SetBlendMode("ADD")
  329.         local ag = galaxy:CreateAnimationGroup()
  330.         local anim = ag:CreateAnimation("Rotation")
  331.         anim:SetDegrees(360)
  332.         anim:SetDuration(i*30)
  333.         ag:Play()
  334.         ag:SetLooping("REPEAT")
  335.     end
  336.     else
  337.     end
  338.    
  339.     --model
  340.     if showModel == true then
  341.     local model = CreateFrame("PlayerModel",nil,sch)
  342.     model:SetSize(hpFrame:GetSize())
  343.     model:SetPoint("CENTER")
  344.     model:ClearFog()
  345.     model:ClearModel()
  346.     model:SetDisplayInfo(modelnr)
  347.     model:SetPortraitZoom(0)
  348.     model:SetCamDistanceScale(0.9)
  349.     model:SetPosition(0,0,0.1)
  350.     model:SetRotation(0)
  351.     --model:SetBackdrop(backdrop)
  352.     model:SetAlpha(1)
  353.     else
  354.     end
  355.    
  356.     --Status Orb
  357.     so:SetFrameLevel(11)
  358.     so:SetSize(size*0.2925, size*0.2925)
  359.     so.t = so:CreateTexture(nil,"BACKGROUND",nil,-8)
  360.     so.t2 = so:CreateTexture(nil,"BACKGROUND",nil,6)
  361.     --texture
  362.     --so.t:SetTexture(folder.."status_orb.tga")
  363.     so.t2:SetTexture(folder.."orb_gloss.tga")
  364.     --setpoint
  365.     so.t:SetAllPoints(so)
  366.     so.t2:SetAllPoints(so)
  367.  
  368.     local icosize = size*0.2
  369.    
  370.     -- Position and size
  371.     local rest = so:CreateTexture(nil, "BACKGROUND",nil,5)
  372.     rest:SetTexture(folder.."status_orb.tga")
  373.     rest:SetVertexColor(0.4, 0.4, 1.0)
  374.     rest:SetSize(so:GetSize())
  375.     rest:SetPoint("CENTER", so)
  376.    
  377.     -- Register it with oUF
  378.     self.Resting = rest
  379.    
  380.     -- Position and size
  381.     local combat = po:CreateTexture(nil, "BACKGROUND",nil,5)
  382.     combat:SetTexture(folder.."status_orb.tga")
  383.     combat:SetVertexColor(1.0, 0.4, 0.4)
  384.     combat:SetSize(so:GetSize())
  385.     combat:SetPoint("CENTER", so)
  386.    
  387.     -- Register it with oUF
  388.     self.Combat = combat
  389.    
  390.     -- Position and size
  391.     local PvP = so:CreateTexture(nil, "OVERLAY",nil,5)
  392.     PvP:SetSize(icosize, icosize)
  393.     PvP:SetPoint("CENTER", po)
  394.    
  395.     -- Register it with oUF
  396.     self.PvP = PvP
  397.    
  398.     -- Position and size
  399.     local RaidIcon = so:CreateTexture(nil, "OVERLAY",nil,7)
  400.     RaidIcon:SetSize(icosize, icosize)
  401.     RaidIcon:SetPoint("CENTER", po, "TOP")
  402.    
  403.     -- Register it with oUF
  404.     self.RaidIcon = RaidIcon
  405.    
  406.     ---------------------------------------------
  407.     -- CLASS BARS
  408.     ---------------------------------------------
  409.  
  410.     ---------------------------------------------
  411.     -- TAGS
  412.     ---------------------------------------------
  413.    
  414.     --fontstring func
  415.     function NewFontString(parent,family,size,outline,layer)
  416.         local fs = parent:CreateFontString(nil, layer or "OVERLAY")
  417.         fs:SetFont(family,size,outline)
  418.         fs:SetShadowOffset(0, -2)
  419.         fs:SetShadowColor(0,0,0,1)
  420.         return fs
  421.     end
  422.    
  423.     --unit curhp tag
  424.     oUF.Tags.Methods["sxui:curhp"] = function(unit)
  425.         local curhp = oUF.Tags.Methods["curhp"](unit)
  426.         return "|cffffffff"..curhp.."|r"
  427.     end
  428.     oUF.Tags.Events["sxui:curhp"] = "UNIT_HEALTH"
  429.    
  430.     --unit hpp tag
  431.     oUF.Tags.Methods["sxui:health"] = function(unit)
  432.         local perhp = oUF.Tags.Methods["perhp"](unit)
  433.         return "|cffffffff"..perhp.."|r"
  434.     end
  435.     oUF.Tags.Events["sxui:health"] = "UNIT_HEALTH_FREQUENT UNIT_MAXHEALTH"
  436.    
  437.     --unit power tag
  438.     oUF.Tags.Methods["unit:power"] = function(unit)
  439.         local perpp = oUF.Tags.Methods["perpp"](unit)
  440.         return "|cffffffff"..perpp.."|r"
  441.     end
  442.     oUF.Tags.Events["unit:power"] = "UNIT_DISPLAYPOWER UNIT_POWER_FREQUENT UNIT_MAXPOWER"
  443.    
  444.    
  445.     --strings
  446.     local hpval = NewFontString(overlay, FONT, size*0.08, "THINOUTLINE")
  447.     hpval:SetPoint("TOP", overlay, "CENTER", 0, 0 )
  448.     self:Tag(hpval, "[sxui:health]%")
  449.    
  450.     local curhp = NewFontString(overlay, FONT, size*0.1, "THINOUTLINE")
  451.     curhp:SetPoint("LEFT",-5,0)
  452.     curhp:SetPoint("RIGHT",5,0)
  453.     curhp:SetPoint("BOTTOM", overlay, "CENTER", 0, 3)
  454.     self:Tag(curhp, "[sxui:curhp]")
  455.    
  456.     local ppval = NewFontString(power, FONT, size*0.08, "THINOUTLINE")
  457.     ppval:SetPoint("LEFT", sfp, "CENTER", size*0.19, size*0.06 )
  458.     self:Tag(ppval, "[unit:power]%")
  459.    
  460.    
  461.     -- All is ending after this
  462. end
  463.  
  464. ---------------------------------------------
  465. -- SPAWNING THE PLAYER
  466. ---------------------------------------------
  467. oUF:RegisterStyle("OrbTemplate", CreateOrbTemplate)
  468. oUF:SetActiveStyle("OrbTemplate")
  469. local playerFrame = oUF:Spawn("player", addon.."Player")
  470. playerFrame:SetPoint("TOPLEFT", size/3, -size/2)

Sorry for only giving only a bit of code at the time
  Reply With Quote
03-19-14, 06:59 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
To answer your original question, if you want your custom texture to follow the original bar's color (which oUF automatically sets) just grab the color from the bar in your update function:

Code:
local r, g, b = power:GetStatusBarColor()
power.texture:SetVertexColor(r, g, b)
As for the other stuff, rather than hooking bar updates, just tell oUF to call your function after running its own update:
Code:
hp.PostUpdate = updateHealth
instead of:
Code:
hp:SetScript("OnValueChanged", updateHealth)
The other advantage of doing this properly is that your function gets the current value, max value, and (for power) power tyep passed in as arguments, so you don't have to call the same functions oUF already called to get the same values.

The only place you need to hook a script is for the castbar, since oUF doesn't provide any OnUpdate callback. Since OnUpdate is fairly expensive, I'd suggest not hooking it at all if the "castScroll" setting isn't enabled, rather than checking for that setting in the function itself.

-----

I'm still not quite sure what you're intending to do by setting the height of the power bar to 0 when you create the rotating texture, though. If you want to hide the original bar, just do that, eg. "power:Hide()". However, it looks like you're just duplicating the texture so you can rotate it. If that's the case, you don't need to create a whole new texture; just the texture object that's already on the statusbar:

Code:
power.texture = power:GetStatusBarTexture()
You can manipulate it just like any other texture object, eg. with SetPoint, SetScale, SetRotation, SetTexture, etc. The statusbar-specific methods are just wrappers around these functions, eg. SetValue just sizes and positions the texture relative to the bar, appropriate for the provided value.

You may also need to "remove" the regular statusbar methods so oUF isn't messing with the texture when it updates the element:

Code:
local doNothing = function() end
power.SetMinMaxValues = doNothing
power.SetValue = doNothing
-----

I'd also recommend putting all of your config variables into a table, to avoid having tons and tons of local variables, and so that later you could move them to their own file, or add in-game options and save changed between sessions, if you wanted. This would also improve code readability, because when you saw a config variable in the code, instead of just "size" you'd see "config.size" and you'd immediately know that variable was set at the top of the file in the configuration section.

There's no need to explicitly check "if <boolean value> == true then" -- you can just do "if <boolean value> then". It's cleaner and (theoretically) more efficient.

Avoid calling functions unless you have to. For example, in once place you were doing "floor(x / 1000) * 1000" to "round" a value to the first 2 decimal points, but you were only using the value as a multiplier for other values, so there's no need to make it "pretty" -- just use it as-is.

Similarly, there's no need to declare a variable if you're only going to use the value once. Instead of "local x = y - 42" and then "SomeFunction(x)" just do "SomeFunction(y - 42)".

Finally, while a variable name like "sch" or "po" may be short and (depending on taste) pretty, are you really going to remember what it is if you haven't looked at your code for a week? a month? a year? When other programmers look at your code, will they be able to figure out what the variable is without having to go find where it's defined? Space is unlimited, so use descriptive variable names like "scrollChild" or "portraitHolder" are better choices.

Also, if you have two similar objects referred to as "hpbg" and "hpbgo" don't mix them together -- calling "hpbg:SetSize" followed by "hpbg:SetTexture" followed by "hpbgo:SetTexture" followed by "hbbg:SetVertedColor" is just confusing. Keep your code organized in logical blocks.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
03-26-14, 11:49 AM   #7
saxitoxin
A Wyrmkin Dreamwalker
 
saxitoxin's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 59
Use Reincarnation... sorry

Thanks for the help Phanx. I made a in config file back when I made the folder, I just had some problems understanding it back then so I made the settings like this in the prototype.

Originally Posted by Phanx View Post
To answer your original question, if you want your custom texture to follow the original bar's color (which oUF automatically sets) just grab the color from the bar in your update function:

Code:
local r, g, b = power:GetStatusBarColor()
power.texture:SetVertexColor(r, g, b)
Thanks this is what I was looking for
as for the hp.PostUpdate = updateHealth I could not make it work, I tried several times with diffrent coding, but whit no luck. So I use the old code until I figure out how to use the PostUpdate and it works

----------

Originally Posted by Phanx View Post
I'm still not quite sure what you're intending to do by setting the height of the power bar to 0 when you create the rotating texture, though. If you want to hide the original bar, just do that, eg. "power:Hide()". However, it looks like you're just duplicating the texture so you can rotate it. If that's the case, you don't need to create a whole new texture; just the texture object that's already on the statusbar:

Code:
power.texture = power:GetStatusBarTexture()
You can manipulate it just like any other texture object, eg. with SetPoint, SetScale, SetRotation, SetTexture, etc. The statusbar-specific methods are just wrappers around these functions, eg. SetValue just sizes and positions the texture relative to the bar, appropriate for the provided value.

You may also need to "remove" the regular statusbar methods so oUF isn't messing with the texture when it updates the element:

Code:
local doNothing = function() end
power.SetMinMaxValues = doNothing
power.SetValue = doNothing
If I hide the statusbar the dummybar also become hidden, same goes for setting alpha to 0
Because of this I think the doNothing code vil do nothing with the dummyframe, so I did not try it.

----------

Also Thanks for all the input on the rest of the code, I did most of the rest that you suggested except the "floor(x / 1000) * 1000" since it broke the function of the hp spark.

If I sound rude that is because I don't have any good English knowledge.

And again thanks for the help
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » powercolor and druidform

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