Language:
Lua     Change language:
Pastebin: 106724
Author: airtonix
Subject: oUF_Healcomm - vertical bars
Created: 2009-01-21 14:12:32
Download and save
Toggle line numbers
1--============================================================================== 
2-- 
3-- oUF_HealComm 
4-- 
5-- Uses data from LibHealComm-3.0 to add incoming heal estimate bars onto units  
6-- health bars. 
7-- 
8-- * currently won't update the frame if max HP is unknown (ie, restricted to  
9--   players/pets in your group that are in range), hides the bar for these 
10-- * can define frame.ignoreHealComm in layout to not have the bars appear on  
11--   that frame 
12-- 
13--============================================================================= 
14oUF.debug=false 
15local oufDebug = function(msg) 
16    if(oUF.debug) then print("|cff00FF10"..msg.."|r") end 
17end 
18if not oUF then return end 
19 
20--set texture and color here 
21local color = { 
22    r = 0
23    g = 1
24    b = 0
25    a = .25
26} 
27 
28local oUF_HealComm = {} 
29 
30local healcomm = LibStub("LibHealComm-3.0"
31 
32local playerName = UnitName("player"
33local playerIsCasting = false 
34local playerHeals = 0 
35local playerTarget = "" 
36 
37--update a specific bar 
38local updateHealCommBar = function(frame, unit) 
39    local curHP = UnitHealth(unit) 
40    local maxHP = UnitHealthMax(unit) 
41    local percHP = curHP / maxHP 
42 
43    local incHeals = select(2, healcomm:UnitIncomingHealGet(unit, GetTime())) or 0 
44 
45    --add player's own heals if casting on this unit 
46    if playerIsCasting then 
47        for i = 1, select("#", playerTarget) do 
48            local target = select(i, playerTarget) 
49            if target == unit then 
50                incHeals = incHeals + playerHeals 
51            end 
52        end 
53    end 
54 
55    --hide if unknown max hp or no heals inc 
56    if maxHP == 100 or incHeals == 0 then 
57        frame.HealCommBar:Hide() 
58        return 
59    else 
60        frame.HealCommBar:Show() 
61    end 
62 
63    percInc = incHeals / maxHP 
64    h = frame.Health:GetHeight() 
65    w = frame.Health:GetWidth() 
66    orient = frame.Health:GetOrientation() 
67    oufDebug("orient: "..orient, "h: "..h, "w: "..w, "percInc: "..percInc) 
68 
69    frame.HealCommBar:ClearAllPoints() 
70    frame.HealCommBar:SetFrameStrata("TOOLTIP"
71    if(orient=="VERTICAL")then 
72        frame.HealCommBar:SetHeight(percInc * h) 
73        frame.HealCommBar:SetWidth(w) 
74        frame.HealCommBar:SetPoint("BOTTOM", frame.Health, "BOTTOM", 0, h * percHP) 
75    else 
76        frame.HealCommBar:SetWidth(percInc * w) 
77        frame.HealCommBar:SetHeight(h) 
78        frame.HealCommBar:SetPoint("LEFT", frame.Health, "LEFT", w * percHP,0
79    end 
80end 
81 
82--used by library callbacks, arguments should be list of units to update 
83local updateHealCommBars = function(...) 
84    for i = 1, select("#", ...) do 
85        local unit = select(i, ...) 
86 
87        --search current oUF frames for this unit 
88        for frame in pairs(oUF.units) do 
89            local name, server = UnitName(frame) 
90            if server then name = strjoin("-",name,server) end 
91            if name == unit and not oUF.units[frame].ignoreHealComm then 
92                updateHealCommBar(oUF.units[frame],unit) 
93            end 
94        end 
95    end 
96end 
97 
98local function hook(frame) 
99    if frame.ignoreHealComm then return end 
100 
101    --create heal bar here and set initial values 
102    if(frame.Health:GetOrientation() =="VERTICAL")then 
103        local hcb = CreateFrame"StatusBar" 
104        hcb:SetWidth(frame.Health:GetWidth()) -- same height as health bar 
105        hcb:SetHeight(4) --no initial width 
106        hcb:SetStatusBarTexture(frame.Health:GetStatusBarTexture():GetTexture()) 
107        hcb:SetStatusBarColor(color.r, color.g, color.b, color.a) 
108        hcb:SetParent(frame) 
109        hcb:SetPoint("BOTTOMLEFT", frame.Health, "TOPLEFT",0,0) --attach to immediate right of health bar to start 
110    --    hcb:SetFrameLevel 
111        hcb:Hide() --hide it for now 
112        frame.HealCommBar = hcb 
113    else 
114        local hcb = CreateFrame"StatusBar" 
115        hcb:SetHeight(frame.Health:GetHeight()) -- same height as health bar 
116        hcb:SetWidth(4) --no initial width 
117        hcb:SetStatusBarTexture(frame.Health:GetStatusBarTexture():GetTexture()) 
118        hcb:SetStatusBarColor(color.r, color.g, color.b, color.a) 
119        hcb:SetParent(frame) 
120        hcb:SetPoint("LEFT", frame.Health, "RIGHT",0,0) --attach to immediate right of health bar to start 
121    --    hcb:SetFrameLevel 
122        hcb:Hide() --hide it for now 
123        frame.HealCommBar = hcb 
124    end 
125    local o = frame.PostUpdateHealth 
126    frame.PostUpdateHealth = function(...) 
127        if o then o(...) end 
128        local name, server = UnitName(frame.unit) 
129        if server then name = strjoin("-",name,server) end 
130        updateHealCommBar(frame, name) --update the bar when unit's health is updated 
131    end 
132end 
133 
134--hook into all existing frames 
135for i, frame in ipairs(oUF.objects) do hook(frame) end 
136 
137--hook into new frames as they're created 
138oUF:RegisterInitCallback(hook) 
139 
140--set up LibHealComm callbacks 
141function oUF_HealComm:HealComm_DirectHealStart(event, healerName, healSize, endTime, ...) 
142    if healerName == playerName then 
143        playerIsCasting = true 
144        playerTarget = ... 
145        playerHeals = healSize 
146    end 
147    updateHealCommBars(...) 
148end 
149 
150function oUF_HealComm:HealComm_DirectHealUpdate(event, healerName, healSize, endTime, ...) 
151    updateHealCommBars(...) 
152end 
153 
154function oUF_HealComm:HealComm_DirectHealStop(event, healerName, healSize, succeeded, ...) 
155    if healerName == playerName then 
156        playerIsCasting = false 
157    end 
158    updateHealCommBars(...) 
159end 
160 
161function oUF_HealComm:HealComm_HealModifierUpdate(event, unit, targetName, healModifier) 
162    updateHealCommBars(unit) 
163end 
164 
165healcomm.RegisterCallback(oUF_HealComm, "HealComm_DirectHealStart"
166healcomm.RegisterCallback(oUF_HealComm, "HealComm_DirectHealUpdate"
167healcomm.RegisterCallback(oUF_HealComm, "HealComm_DirectHealStop"
168healcomm.RegisterCallback(oUF_HealComm, "HealComm_HealModifierUpdate"
Download and save
Toggle line numbers
Thread:
[106724] oUF_Healcomm - vertical bars by airtonix at 2009-01-21 14:12:32
Tip: Click the line numbers to toggle highliting on that line.

Paste followup:

Language:
Author:
Subject:


    Tabstop:     bigger biggest
Note: You can prefix a line with "@@@" to highlight it.