Quantcast Creating oUF Harmony indicator - WoWInterface
Thread Tools Display Modes
10-20-12, 09:07 AM   #1
lerb
A Frostmaul Preserver
 
lerb's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 259
Creating oUF Harmony indicator

Hey guys

I'm in need of some help creating indicators for Harmony in my oUF layout. Nothing fancy, just 4-5 frames above my unitframe with a !beautycase border and the same texture as my statusbars, that shows and hides depending on how much Chi I have.

Now, I've tried making this work all day, but I just can't get my head around how oUF works. I'm good at modifying existing layouts (oUF_Simple in this case), and I've tried looking at other peoples codes for their harmony but still, my brain hurts.

I don't know if I'm asking too much but I'd really appreciate the help.

Here's the core.lua of my layout, it's essentially oUF_Simple with a few tweaks:

Lua Code:
  1. -- // oUF_Lerb, an oUF layout
  2.   -- // Based on oUF_Simple2 by zork - 2011
  3.  
  4.   -----------------------------
  5.   -- INIT
  6.   -----------------------------
  7.  
  8.   --get the addon namespace
  9.   local addon, ns = ...
  10.   --get the config values
  11.   local cfg = ns.cfg
  12.   local dragFrameList = ns.dragFrameList
  13.   --holder for some lib functions
  14.   local lib = CreateFrame("Frame")
  15.   ns.lib = lib
  16.  
  17.   -----------------------------
  18.   -- FUNCTIONS
  19.   -----------------------------
  20.  
  21.   --backdrop table
  22.   local backdrop_tab = {
  23.     bgFile = cfg.backdrop_texture,
  24.     edgeFile = cfg.backdrop_edge_texture,
  25.     tile = false,
  26.     tileSize = 0,
  27.     edgeSize = 5,
  28.     insets = {
  29.       left = 5,
  30.       right = 5,
  31.       top = 5,
  32.       bottom = 5,
  33.     },
  34.   }
  35.  
  36.   --backdrop func
  37.   lib.gen_backdrop = function(f)
  38.     f:SetBackdrop(backdrop_tab);
  39.     f:SetBackdropColor(0,0,0)
  40.     f:SetBackdropBorderColor(0,0,0)
  41.   end
  42.  
  43.   --fontstring func
  44.   lib.gen_fontstring = function(f, name, size, outline)
  45.     local fs = f:CreateFontString(nil, "OVERLAY")
  46.     fs:SetFont(name, size, outline)
  47.     fs:SetShadowColor(0,0,0,0.5)
  48.     fs:SetShadowOffset(0,-0)
  49.     return fs
  50.   end
  51.  
  52.   local dropdown = CreateFrame("Frame", addon.."DropDown", UIParent, "UIDropDownMenuTemplate")
  53.  
  54.   UIDropDownMenu_Initialize(dropdown, function(self)
  55.     local unit = self:GetParent().unit
  56.     if not unit then return end
  57.     local menu, name, id
  58.     if UnitIsUnit(unit, "player") then
  59.       menu = "SELF"
  60.     elseif UnitIsUnit(unit, "vehicle") then
  61.       menu = "VEHICLE"
  62.     elseif UnitIsUnit(unit, "pet") then
  63.       menu = "PET"
  64.     elseif UnitIsPlayer(unit) then
  65.       id = UnitInRaid(unit)
  66.       if id then
  67.         menu = "RAID_PLAYER"
  68.         name = GetRaidRosterInfo(id)
  69.       elseif UnitInParty(unit) then
  70.         menu = "PARTY"
  71.       else
  72.         menu = "PLAYER"
  73.       end
  74.     else
  75.       menu = "TARGET"
  76.       name = RAID_TARGET_ICON
  77.     end
  78.     if menu then
  79.       UnitPopup_ShowMenu(self, menu, unit, name, id)
  80.     end
  81.   end, "MENU")
  82.  
  83.   lib.menu = function(self)
  84.     dropdown:SetParent(self)
  85.     ToggleDropDownMenu(1, nil, dropdown, "cursor", 0, 0)
  86.   end
  87.  
  88.   --remove focus from menu list
  89.   do
  90.     for k,v in pairs(UnitPopupMenus) do
  91.       for x,y in pairs(UnitPopupMenus[k]) do
  92.         if y == "SET_FOCUS" then
  93.           table.remove(UnitPopupMenus[k],x)
  94.         elseif y == "CLEAR_FOCUS" then
  95.           table.remove(UnitPopupMenus[k],x)
  96.         end
  97.       end
  98.     end
  99.   end
  100.  
  101.   --update health func
  102.   lib.updateHealth = function(bar, unit, min, max)
  103.     --color the hp bar in red if the unit has aggro
  104.     --if not the preset color does not get overwritten
  105.     if unit and UnitThreatSituation(unit) == 3 then
  106.           bar:SetStatusBarColor(1,0,0)
  107.       bar.bg:SetVertexColor(1*bar.bg.multiplier,0,0)
  108.     end
  109.   end
  110.  
  111.   --check threat
  112.   lib.checkThreat = function(f,event,unit)
  113.     --force an update on the health frame
  114.     f.Health:ForceUpdate()
  115.   end
  116.  
  117.   --gen healthbar func
  118.   lib.gen_hpbar = function(f)
  119.     --statusbar
  120.     local s = CreateFrame("StatusBar", nil, f)
  121.     s:SetStatusBarTexture(cfg.statusbar_texture)
  122.     s:SetHeight(26)
  123.     s:SetWidth(f.width)
  124.     s:SetPoint("TOP",f,"TOP")
  125.     --helper
  126.     local h = CreateFrame("Frame", nil, s)
  127.     h:SetFrameLevel(0)
  128.     h:SetPoint("TOPLEFT",-5,5)
  129.     h:SetPoint("BOTTOMRIGHT",5,-5)
  130.     lib.gen_backdrop(h)
  131.     --bg
  132.     local b = s:CreateTexture(nil, "BACKGROUND")
  133.     b:SetTexture(cfg.statusbar_texture)
  134.     b:SetAllPoints(s)
  135.     --border
  136.     CreateBorder(s, 12, 1, 1, 1, 4, 3, 4, 3, 4, 3, 4, 3) -- !beautycase s=frame, 12=bordersize, 1,1,1=color(rgb), rest=spacing
  137.  
  138.     --debuff highlight
  139.     local dbh = s:CreateTexture(nil, "OVERLAY")
  140.     dbh:SetAllPoints(f)
  141.     dbh:SetTexture(cfg.debuff_highlight_texture)
  142.     dbh:SetBlendMode("ADD")
  143.     dbh:SetVertexColor(0,0,0,0)
  144.  
  145.     f.DebuffHighlightAlpha = 1
  146.     f.DebuffHighlightFilter = true
  147.  
  148.     f.DebuffHighlight = dbh
  149.     f.Health = s
  150.     f.Health.bg = b
  151.  
  152.     f.Health.PostUpdate = lib.updateHealth
  153.     f:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", lib.checkThreat)
  154.  
  155.   end
  156.  
  157.   --gen hp strings func
  158.   lib.gen_hpstrings = function(f)
  159.  
  160.     local name, hpval
  161.  
  162.     --health/name text strings
  163.     if not f.hidename then
  164.       name = lib.gen_fontstring(f.Health, cfg.font, 16, "THINOUTLINE")
  165.       name:SetPoint("LEFT", f.Health, "LEFT", 2, 0)
  166.       name:SetJustifyH("LEFT")
  167.     end
  168.  
  169.     hpval = lib.gen_fontstring(f.Health, cfg.font, 16, "THINOUTLINE")
  170.     hpval:SetPoint("RIGHT", f.Health, "RIGHT", -2, 0)
  171.  
  172.     if f.hidename then
  173.       hpval:SetJustifyH("CENTER")
  174.       hpval:SetPoint("LEFT", f.Health, "LEFT", 2, 0)
  175.     else
  176.       --this will make the name go "..." when its to long
  177.       name:SetPoint("RIGHT", hpval, "LEFT", -5, 0)
  178.       hpval:SetJustifyH("RIGHT")
  179.       if f.nametag then
  180.         f:Tag(name, f.nametag)
  181.       else
  182.         f:Tag(name, "[name]")
  183.       end
  184.     end
  185.  
  186.     if f.hptag then
  187.       f:Tag(hpval, f.hptag)
  188.     else
  189.       f:Tag(hpval, "[simple:hpdefault]")
  190.     end
  191.  
  192.   end
  193.  
  194.   --gen powerbar func
  195.   lib.gen_ppbar = function(f)
  196.     --statusbar
  197.     local s = CreateFrame("StatusBar", nil, f)
  198.     s:SetStatusBarTexture(cfg.statusbar_texture)
  199.       if f.mystyle == "tot" then
  200.         s:Hide()
  201.       end
  202.     s:SetHeight(20)
  203.     s:SetWidth(f.width)
  204.     s:SetPoint("BOTTOM",f,"BOTTOM")
  205.     --helper
  206.     local h = CreateFrame("Frame", nil, s)
  207.     h:SetFrameLevel(0)
  208.     h:SetPoint("TOPLEFT",-5,5)
  209.     h:SetPoint("BOTTOMRIGHT",5,-5)
  210.     lib.gen_backdrop(h)
  211.     --bg
  212.     local b = s:CreateTexture(nil, "BACKGROUND")
  213.     b:SetTexture(cfg.statusbar_texture)
  214.     b:SetAllPoints(s)
  215.     f.Power = s
  216.     f.Power.bg = b
  217.     --border
  218.     CreateBorder(s, 12, 1, 1, 1, 4, 3, 4, 3, 4, 3, 4, 3) -- !beautycase s=frame, 12=bordersize, 1,1,1=color(rgb), rest=spacing
  219.   end
  220.  
  221.   --moveme func
  222.   lib.moveme = function(f)
  223.     f:SetMovable(true)
  224.     f:SetUserPlaced(true)
  225.     f:EnableMouse(true)
  226.     f:RegisterForDrag("LeftButton","RightButton")
  227.     --f:SetScript("OnDragStart", function(self) if IsAltKeyDown() and IsShiftKeyDown() then self:StartMoving() end end)
  228.     f:SetScript("OnDragStart", function(self) self:StartMoving() end)
  229.     f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
  230.   end
  231.  
  232.   --gen castbar
  233.   lib.gen_castbar = function(f)
  234.  
  235.     local s = CreateFrame("StatusBar", "oUF_SimpleCastbar"..f.mystyle:sub(1,1):upper()..f.mystyle:sub(2), f)
  236.     s:SetHeight(26)
  237.     s:SetWidth(f.width)
  238.     if f.mystyle == "player" then
  239.       s:SetPoint("TOPLEFT",f,"BOTTOMLEFT",0,-8)
  240.     elseif f.mystyle == "target" then
  241.       s:SetPoint("TOPRIGHT",f,"BOTTOMRIGHT",0,-8)
  242.     else
  243.       s:SetPoint("TOP",f,"BOTTOM",0,-8)
  244.     end
  245.    
  246.     s:SetStatusBarTexture(cfg.statusbar_texture)
  247.     s:SetStatusBarColor(1,0.8,0,1)
  248.     --helper
  249.     local h = CreateFrame("Frame", nil, s)
  250.     h:SetFrameLevel(0)
  251.     h:SetPoint("TOPLEFT",-5,5)
  252.     h:SetPoint("BOTTOMRIGHT",5,-5)
  253.     lib.gen_backdrop(h)
  254.     --helper2
  255.     local h2 = CreateFrame("Frame", nil, s)
  256.     h2:SetFrameLevel(0)
  257.     h2:SetPoint("TOPLEFT",-1,1)
  258.     h2:SetPoint("BOTTOMRIGHT",1,-1)
  259.     lib.gen_backdrop(h2)
  260.  
  261.     local b = s:CreateTexture(nil, "BACKGROUND")
  262.     b:SetTexture(cfg.statusbar_texture)
  263.     b:SetAllPoints(s)
  264.     b:SetVertexColor(1*0.3,0.8*0.3,0,0.7)
  265.  
  266.     --spellname
  267.     local txt = lib.gen_fontstring(s, cfg.font, 14, "THINOUTLINE")
  268.     txt:SetPoint("LEFT", 2, 1)
  269.     txt:SetJustifyH("LEFT")
  270.    
  271.     --time
  272.     local t = lib.gen_fontstring(s, cfg.font, 14, "THINOUTLINE")
  273.     t:SetPoint("RIGHT", -2, 1)
  274.     txt:SetPoint("RIGHT", t, "LEFT", -5, 0)
  275.  
  276.     if f.mystyle == "player" then
  277.       --latency only for player unit
  278.       local z = s:CreateTexture(nil,"OVERLAY")
  279.       z:SetTexture(cfg.statusbar_texture)
  280.       z:SetVertexColor(1,0,0,0.6)
  281.       z:SetPoint("TOPRIGHT",0,-2)
  282.       z:SetPoint("BOTTOMRIGHT",0,2)
  283.       s.SafeZone = z
  284.     end
  285.    
  286.     --border
  287.     CreateBorder(s, 12, 1, 1, 1, 4, 3, 4, 3, 4, 3, 4, 3)
  288.    
  289.     f.Castbar = s
  290.     f.Castbar.Text = txt
  291.     f.Castbar.Time = t
  292.     f.Castbar.Icon = i
  293.   end
  294.  
  295.   lib.gen_portrait = function(f)
  296.     if cfg.hideportraits then return end
  297.     local p = CreateFrame("PlayerModel", nil, f)
  298.     p:SetWidth(f.height)
  299.     p:SetHeight(f.height)
  300.     if f.mystyle == "target" then
  301.       p:SetPoint("TOPLEFT", f, "TOPRIGHT", 10, 0)
  302.     elseif f.mystyle == "focus" then
  303.       p:Hide()
  304.     else
  305.       p:SetPoint("TOPRIGHT", f, "TOPLEFT", -10, 0)
  306.     end
  307.  
  308.     --helper
  309.     local h = CreateFrame("Frame", nil, p)
  310.     h:SetFrameLevel(0)
  311.     h:SetPoint("TOPLEFT",-5,5)
  312.     h:SetPoint("BOTTOMRIGHT",5,-5)
  313.     lib.gen_backdrop(h)
  314.    
  315.     --border
  316.     CreateBorder(p, 12, 1, 1, 1, 3)
  317.  
  318.     f.Portrait = p
  319.   end
  320.  
  321.   lib.PostCreateIcon = function(self, button)
  322.     button.cd:SetReverse()
  323.     button.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  324.     button.icon:SetDrawLayer("BACKGROUND")
  325.     --count
  326.     button.count:ClearAllPoints()
  327.     button.count:SetJustifyH("RIGHT")
  328.     button.count:SetPoint("TOPRIGHT", 2, 2)
  329.     button.count:SetTextColor(0.7,0.7,0.7)
  330.     --helper
  331.     local h = CreateFrame("Frame", nil, button)
  332.     h:SetFrameLevel(0)
  333.     h:SetPoint("TOPLEFT",-4,4)
  334.     h:SetPoint("BOTTOMRIGHT",4,-4)
  335.     lib.gen_backdrop(h)
  336.     --border
  337.     CreateBorder(h,12,1,1,1)
  338.   end
  339.  
  340.   lib.createBuffs = function(f)
  341.     b = CreateFrame("Frame", nil, f)
  342.     b.size = 18
  343.     if f.mystyle == "target" then
  344.       b.num = 40
  345.     elseif f.mystyle == "player" then
  346.       b.num = 10
  347.       b.onlyShowPlayer = true
  348.     else
  349.       b.num = 5
  350.     end
  351.     b.spacing = 10
  352.     b.onlyShowPlayer = false
  353.     b:SetHeight((b.size+b.spacing)*4)
  354.     b:SetWidth(f.width)
  355.     b:SetPoint("BOTTOMLEFT", f, "TOPLEFT", 0, 9)
  356.     b.initialAnchor = "BOTTOMLEFT"
  357.     b["growth-x"] = "RIGHT"
  358.     b["growth-y"] = "UP"
  359.     b.PostCreateIcon = lib.PostCreateIcon
  360.     f.Buffs = b
  361.   end
  362.  
  363.   lib.createDebuffs = function(f)
  364.     b = CreateFrame("Frame", nil, f)
  365.     b.size = 18
  366.     if f.mystyle == "target" then
  367.       b.num = 40
  368.     elseif f.mystyle == "player" then
  369.       b.num = 10
  370.     elseif f.mystyle == "tot" then
  371.       b:Hide()
  372.     else
  373.       b.num = 5
  374.     end
  375.     b.spacing = 10
  376.     b.onlyShowPlayer = false
  377.     b:SetHeight((b.size+b.spacing)*4)
  378.     b:SetWidth(f.width)
  379.       if f.mystyle == "focus" then
  380.         b:SetPoint("BOTTOMLEFT", f.Health, "TOPLEFT", 0, 9)
  381.         b:SetPoint("TOPLEFT", f.Power, "BOTTOMLEFT", 0, -9)
  382.         b.initialAnchor = "BOTTOMLEFT"
  383.         b["growth-x"] = "RIGHT"
  384.         b["growth-y"] = "UP"
  385.       else
  386.         b:SetPoint("TOPLEFT", f.Power, "BOTTOMLEFT", 0, -9)
  387.         b.initialAnchor = "TOPLEFT"
  388.         b["growth-x"] = "RIGHT"
  389.         b["growth-y"] = "DOWN"
  390.       end
  391.     b.PostCreateIcon = lib.PostCreateIcon
  392.     f.Debuffs = b
  393.   end
__________________
  Reply With Quote
10-21-12, 12:06 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Harmony/chi icons/orbs/whatevers are handled by oUF as part of the ClassIcons element, which is set up exactly like combo points, and should already be included in oUF_Simple (which, by the way, is about the least simple oUF layout code I've ever seen, but that's neither here nor there). If it's not, just copy your combo points element, change the element name to "ClassIcons", and change where it's positioned. Make sure it has 5 icons/orbs/whatevers, or oUF will throw a fit, since some classes have 5 icons and oUF expects the element to be functional for all classes; the extra icons will be hidden.
__________________
Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
  Reply With Quote
10-21-12, 05:18 AM   #3
lerb
A Frostmaul Preserver
 
lerb's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 259
Thank you Phanx I searched the forums before I posted and saw some similar responses, but I couldn't wrap my head around this anyhow. I don't know if it's because of oUF_Simple or my poor Lua knowledge, but probably a mix of the two

Anyhow, it's working! I'll post this here so people searching in the future might get something out of it. And, please, correct me if what I'm stating is wrong. It's based only on my poor Lua knowledge

oUF_Simple, like a lot of other layouts, has a core.lua that handles all the functions for the unitframes. These functions create castbars, healthbars and all that. Then we have the style.lua that "activates" all these for the different units aswell as some other options such as each units individual height and width, for example.

First, we need a function that handles the frame for Harmony using oUFs element ClassIcons.

This is what I added to my core.lua:

Lua Code:
  1. lib.gen_ClassIcons = function(f)
  2.  
  3.     local ci = CreateFrame("Frame", nil, f)
  4.     ci:SetPoint('CENTER', f.Health, 'TOP', 0, 1)
  5.     ci:SetSize(200, 16)
  6.         for i = 1, 5 do
  7.             ci[i] = CreateFrame("StatusBar", f:GetName().."_ClassBar"..i, f)
  8.             ci[i]:SetSize(36, 16)
  9.             ci[i]:SetStatusBarTexture(cfg.statusbar_texture)
  10.             ci[i]:SetFrameLevel(11)
  11.             ci[i].SetVertexColor = ci[i].SetStatusBarColor
  12.             CreateBorder(ci[i],12,1,1,1,2) -- !beautycase border
  13.             local h = CreateFrame("Frame", nil, ci[i])
  14.             h:SetFrameLevel(10)
  15.             h:SetPoint("TOPLEFT",-4,3)
  16.             h:SetPoint("BOTTOMRIGHT",4,-3)
  17.             lib.gen_backdrop(h)
  18.             if (i == 1) then
  19.                 ci[i]:SetPoint('BOTTOMLEFT', f, 'TOPLEFT', -2, 7)
  20.             else
  21.                 ci[i]:SetPoint('TOPLEFT', ci[i-1], "TOPRIGHT", 6, 0)
  22.             end
  23.            
  24.         end
  25.     f.ClassIcons = ci
  26.   end

Here's what the player unit looked like in style.lua before adding ClassIcons:

Lua Code:
  1. --the player style
  2.   local function CreatePlayerStyle(self)
  3.     --style specific stuff
  4.     self.width = 200
  5.     self.height = 54
  6.     self.mystyle = "player"
  7.     init(self)
  8.     self.Health:SetStatusBarColor(.35,.35,.35)
  9.     self.Health.bg:SetVertexColor(.15,.15,.15)
  10.     self.Power.colorClass = true
  11.     self.Power.bg.multiplier = 0.2
  12.     self.Power.Smooth = true
  13.     self.Power.frequentUpdates = true
  14.     lib.gen_castbar(self)
  15.     lib.gen_portrait(self)
  16.   end

Simply add "lib.gen_ClassIcons(self)" which will attach ClassIcons to this unitframe:

Lua Code:
  1. --the player style
  2.   local function CreatePlayerStyle(self)
  3.     --style specific stuff
  4.     self.width = 200
  5.     self.height = 54
  6.     self.mystyle = "player"
  7.     init(self)
  8.     self.Health:SetStatusBarColor(.35,.35,.35)
  9.     self.Health.bg:SetVertexColor(.15,.15,.15)
  10.     self.Power.colorClass = true
  11.     self.Power.bg.multiplier = 0.2
  12.     self.Power.Smooth = true
  13.     self.Power.frequentUpdates = true
  14.     lib.gen_ClassIcons(self)
  15.     lib.gen_castbar(self)
  16.     lib.gen_portrait(self)
  17.   end

I hope this makes sense and that it's somewhat well executed. I'm still learning, so any inputs are welcome Thank you again Phanx.
__________________
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Creating oUF Harmony indicator

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