diff --git a/api/unitframes.lua b/api/unitframes.lua index 46dca25f..71085f88 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -107,6 +107,24 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick) f.hp.bar.texture:SetAllPoints(f.hp.bar) end + f.incHeal = CreateFrame("StatusBar", nil, f) + f.incHeal:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar") + f.incHeal:SetFrameStrata("MEDIUM") + f.incHeal:SetMinMaxValues(0, 1) + f.incHeal:SetValue(1) + f.incHeal:SetStatusBarColor(0, 1, 0, 0.5) + f.incHeal:Hide() + + f.ressIcon = CreateFrame("Frame", nil, f.hp.bar) + f.ressIcon:SetFrameLevel(16) + f.ressIcon:SetWidth(32) + f.ressIcon:SetHeight(32) + f.ressIcon:SetPoint("CENTER", f, "CENTER", 0, 4) + f.ressIcon.texture = f.ressIcon:CreateTexture(nil,"BACKGROUND") + f.ressIcon.texture:SetTexture("Interface\\AddOns\\pfUI\\img\\ress") + f.ressIcon.texture:SetAllPoints(f.ressIcon) + f.ressIcon:Hide() + f.power = CreateFrame("Frame",nil, f) f.power:SetPoint(f.config.panchor, f.hp, relative_point, 0, -2*default_border - f.config.pspace) f.power:SetWidth((f.config.pwidth ~= "-1" and f.config.pwidth or f.config.width)) diff --git a/modules/prediction.lua b/modules/prediction.lua new file mode 100644 index 00000000..ae878047 --- /dev/null +++ b/modules/prediction.lua @@ -0,0 +1,198 @@ +pfUI:RegisterModule("prediction", function () + local heals = {} + local ress = {} + + pfUI.prediction = CreateFrame("Frame") + pfUI.prediction:RegisterEvent("COMBAT_TEXT_UPDATE") + pfUI.prediction:RegisterEvent("UNIT_COMBAT") + pfUI.prediction:RegisterEvent("UNIT_HEALTH") + pfUI.prediction:RegisterEvent("CHAT_MSG_ADDON") + pfUI.prediction:RegisterEvent("PLAYER_TARGET_CHANGED") + pfUI.prediction:RegisterEvent("SPELLCAST_STOP") + + pfUI.prediction:SetScript("OnEvent", function() + if event == "CHAT_MSG_ADDON" and arg1 == "HealComm" then + local channel = arg3 + local sender = arg4 + + if arg2 == "Healstop" then + pfUI.prediction:HealStop(sender) + return + elseif arg2 == "GrpHealstop" then + pfUI.prediction:HealStop(sender) + return + elseif arg2 == "Resurrection/stop/" then + pfUI.prediction:RessStop(sender) + return + end + + local _, _, evtype, target, amount, duration = string.find(arg2, '(Heal)/(%a+)/(%d+)/(%d+)/') + if evtype then + heals[target] = heals[target] or {} + heals[target][sender] = { amount, duration + GetTime() } + pfUI.prediction:TriggerUpdate(target) + return + end + + local _, _, evtype, amount, duration, targets = string.find(arg2, '(GrpHeal)/(%d+)/(%d+)/(.+)/') + if evtype then + for _, target in pairs({strsplit("/", targets)}) do + heals[target] = heals[target] or {} + heals[target][sender] = { amount, duration + GetTime() } + pfUI.prediction:TriggerUpdate(target) + end + return + end + + local _, _, evtype, target = string.find(arg2, '(Resurrection)/(%a+)/(start)/') + if evtype then + ress[target] = ress[target] or {} + ress[target][sender] = true + pfUI.prediction:TriggerUpdate(target) + return + end + elseif event == "COMBAT_TEXT_UPDATE" and arg1 == "HEAL" then + pfUI.prediction:HealStop(arg2) + elseif event == "UNIT_COMBAT" and arg2 == "HEAL" then + pfUI.prediction:CleanHeals() + elseif event == "UNIT_HEALTH" then + if ress[UnitName(arg1)] and not UnitIsDeadOrGhost(arg1) then + ress[UnitName(arg1)] = nil + pfUI.prediction:TriggerUpdate(UnitName(arg1)) + end + elseif event == "SPELLCAST_STOP" then + pfUI.prediction:HealStop(UnitName("player")) + elseif event == "PLAYER_TARGET_CHANGED" then + if pfUI.uf and pfUI.uf.target then + pfUI.prediction:DrawPrediction("target", pfUI.uf.target) + end + end + end) + + pfUI.prediction.scanner = CreateFrame('GameTooltip', "pfPredictionScanner", UIParent, "GameTooltipTemplate") + pfUI.prediction.scanner:SetOwner(WorldFrame, "ANCHOR_NONE") + + function pfUI.prediction:CleanHeals() + for ttarget, t in pairs(heals) do + for tsender in pairs(heals[ttarget]) do + if heals[ttarget][tsender][2] >= GetTime() then + heals[ttarget][tsender] = nil + pfUI.prediction:TriggerUpdate(ttarget) + end + end + end + end + + function pfUI.prediction:HealStop(sender) + for ttarget, t in pairs(heals) do + for tsender in pairs(heals[ttarget]) do + if sender == tsender then + heals[ttarget][tsender] = nil + pfUI.prediction:TriggerUpdate(ttarget) + end + end + end + end + + function pfUI.prediction:GetHeal(target) + local sumheal = 0 + if not heals[target] then + return sumheal + else + for sender, amount in pairs(heals[target]) do + sumheal = sumheal + amount[1] + end + end + return sumheal + end + + function pfUI.prediction:RessStop(sender) + for ttarget, t in pairs(ress) do + for tsender in pairs(ress[ttarget]) do + if sender == tsender then + ress[ttarget][tsender] = nil + pfUI.prediction:TriggerUpdate(ttarget) + end + end + end + end + + function pfUI.prediction:GetRess(target) + if not ress[target] then + return nil + else + for sender, val in pairs(ress[target]) do + if val == true then + return val + end + end + end + return nil + end + + function pfUI.prediction:TriggerUpdate(target) + for id, frame in _G.pfUI.uf.frames do + if frame:IsVisible() and UnitName(frame.label .. frame.id) == target then + pfUI.prediction:DrawPrediction(frame.label .. frame.id, frame) + end + end + end + + function pfUI.prediction:DrawPrediction(unit, frame) + OVERHEALPERCENT = OVERHEALPERCENT or 20 + if not frame then return end + local healed = pfUI.prediction:GetHeal(UnitName(unit)) + local ressed = pfUI.prediction:GetRess(UnitName(unit)) + + if ressed and UnitIsDeadOrGhost(unit) then + frame.ressIcon:Show() + return + else + frame.ressIcon:Hide() + end + + local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit) + if( healed > 0 and (health < maxHealth or OVERHEALPERCENT > 0 )) then + frame.incHeal:Show() + frame.incHeal:SetFrameStrata("BACKGROUND") + frame.incHeal:ClearAllPoints() + + local width = frame.hp.bar:GetWidth() / frame.hp.bar:GetEffectiveScale() + local height = frame.hp.bar:GetHeight() / frame.hp.bar:GetEffectiveScale() + + if frame.config.verticalbar == "0" then + local healthWidth = width * (health / maxHealth) + local incWidth = width * healed / maxHealth + if healthWidth + incWidth > width * (1+(OVERHEALPERCENT/100)) then + incWidth = width * (1+OVERHEALPERCENT/100) - healthWidth + end + + frame.incHeal:SetPoint("TOPLEFT", frame.hp.bar, "TOPLEFT", 0, 0) + frame.incHeal:SetHeight(height) + frame.incHeal:SetWidth(incWidth + healthWidth) + + if frame.config.invert_healthbar == "1" then + frame.incHeal:SetWidth(incWidth) + frame.incHeal:SetFrameStrata("HIGH") + end + else + local healthHeight = height * (health / maxHealth) + local incHeight = height * healed / maxHealth + if healthHeight + incHeight > height * (1+(OVERHEALPERCENT/100)) then + incHeight = height * (1+OVERHEALPERCENT/100) - healthHeight + end + + frame.incHeal:SetPoint("BOTTOM", frame.hp.bar, "BOTTOM", 0, 0) + frame.incHeal:SetWidth(width) + frame.incHeal:SetHeight(incHeight + healthHeight) + + if frame.config.invert_healthbar == "1" then + frame.incHeal:SetHeight(incHeight) + frame.incHeal:SetFrameStrata("HIGH") + end + end + else + frame.incHeal:Hide() + end + end +end) diff --git a/modules/thirdparty.lua b/modules/thirdparty.lua index 0988cf67..1461fb1d 100644 --- a/modules/thirdparty.lua +++ b/modules/thirdparty.lua @@ -423,221 +423,6 @@ pfUI:RegisterModule("thirdparty", function () end) end) - AddIntegration("HealComm", function() - if C.thirdparty.healcomm.enable == "0" then return end - - if AceLibrary and AceLibrary:HasInstance("HealComm-1.0") then - pfUI.healComm = {} - - local HealComm = AceLibrary("HealComm-1.0") - local AceEvent = AceLibrary("AceEvent-2.0") - - function pfUI.healComm.createIncHeal(unit) - if pfUI.uf.player and unit == "player" then - if not pfUI.uf.player.hp then return end - - if pfUI.uf.player and not pfUI.uf.player.incHeal then - pfUI.uf.player.incHeal = CreateFrame("StatusBar", "PlayerFrameIncHealBar", pfUI.uf.player) - pfUI.uf.player.incHeal:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar") - pfUI.uf.player.incHeal:SetFrameStrata("MEDIUM") - pfUI.uf.player.incHeal:SetMinMaxValues(0, 1) - pfUI.uf.player.incHeal:SetValue(1) - pfUI.uf.player.incHeal:SetStatusBarColor(0, 1, 0, 0.5) - pfUI.uf.player.incHeal:Hide() - end - return pfUI.uf.player - end - - if pfUI.uf.target and unit == "target" then - if not pfUI.uf.target.hp then return end - - if not pfUI.uf.target.incHeal then - pfUI.uf.target.incHeal = CreateFrame("StatusBar", "PlayerFrameIncHealBar", pfUI.uf.target) - pfUI.uf.target.incHeal:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar") - pfUI.uf.target.incHeal:SetFrameStrata("MEDIUM") - pfUI.uf.target.incHeal:SetMinMaxValues(0, 1) - pfUI.uf.target.incHeal:SetValue(1) - pfUI.uf.target.incHeal:SetStatusBarColor(0, 1, 0, 0.5) - pfUI.uf.target.incHeal:Hide() - end - return pfUI.uf.target - end - - if pfUI.uf.group and strsub(unit,0,5) == "party" then - local id = tonumber(strsub(unit,6)) - if pfUI.uf.group[id] then - if not pfUI.uf.group[id].hp then return end - - if not pfUI.uf.group[id].incHeal then - pfUI.uf.group[id].incHeal = CreateFrame("StatusBar", "PlayerFrameIncHealBar", pfUI.uf.group[id]) - pfUI.uf.group[id].incHeal:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar") - pfUI.uf.group[id].incHeal:SetFrameStrata("MEDIUM") - pfUI.uf.group[id].incHeal:SetMinMaxValues(0, 1) - pfUI.uf.group[id].incHeal:SetValue(1) - pfUI.uf.group[id].incHeal:SetStatusBarColor(0, 1, 0, 0.5) - pfUI.uf.group[id].incHeal:Hide() - end - return pfUI.uf.group[id] - end - end - - if pfUI.uf.raid and strsub(unit,0,4) == "raid" then - local rid = tonumber(strsub(unit,5)) - local id = nil - - for i=1,40 do - if not pfUI.uf.raid then break end - if pfUI.uf.raid[i] and pfUI.uf.raid[i].id == rid then id = i end - end - - if id == nil then return end - if pfUI.uf.raid[id] then - if not pfUI.uf.raid[id].hp then return end - - if not pfUI.uf.raid[id].incHeal then - pfUI.uf.raid[id].incHeal = CreateFrame("StatusBar", "PlayerFrameIncHealBar", pfUI.uf.raid[id]) - pfUI.uf.raid[id].incHeal:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar") - pfUI.uf.raid[id].incHeal:SetFrameStrata("MEDIUM") - pfUI.uf.raid[id].incHeal:SetMinMaxValues(0, 1) - pfUI.uf.raid[id].incHeal:SetValue(1) - pfUI.uf.raid[id].incHeal:SetStatusBarColor(0, 1, 0, 0.5) - pfUI.uf.raid[id].incHeal:Hide() - end - return pfUI.uf.raid[id] - end - end - - return nil - end - - function pfUI.healComm.onEvent(unitname) - if UnitName("target") == unitname then - pfUI.healComm.onHeal("target") - end - - if UnitName("player") == unitname then - pfUI.healComm.onHeal("player") - end - - if UnitInRaid("player") then - for i=1,40 do - if UnitName("raid" .. i) == unitname then - pfUI.healComm.onHeal("raid" .. i) - end - end - end - - for i=1,4 do - if UnitName("party" .. i) == unitname then - pfUI.healComm.onHeal("party" .. i) - end - end - end - - function pfUI.healComm.onEventHealthChange(unit) - pfUI.healComm.onHeal(unit) - end - - function pfUI.healComm.TargetChanged() - pfUI.healComm.onHeal("target") - end - - function pfUI.healComm.onHeal(unit) - OVERHEALPERCENT = OVERHEALPERCENT or 20 - - local frame = pfUI.healComm.createIncHeal(unit) - if not frame then return end - - local healed = HealComm:getHeal(UnitName(unit)) - - local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit) - - if( healed > 0 and (health < maxHealth or OVERHEALPERCENT > 0 )) and frame:IsVisible() then - frame.incHeal:Show() - frame.incHeal:SetFrameStrata("BACKGROUND") - frame.incHeal:ClearAllPoints() - - local width = frame.hp.bar:GetWidth() / frame.hp.bar:GetEffectiveScale() - local height = frame.hp.bar:GetHeight() / frame.hp.bar:GetEffectiveScale() - - if frame.config.verticalbar == "0" then - local healthWidth = width * (health / maxHealth) - local incWidth = width * healed / maxHealth - if healthWidth + incWidth > width * (1+(OVERHEALPERCENT/100)) then - incWidth = width * (1+OVERHEALPERCENT/100) - healthWidth - end - - frame.incHeal:SetPoint("TOPLEFT", frame.hp.bar, "TOPLEFT", 0, 0) - frame.incHeal:SetHeight(height) - frame.incHeal:SetWidth(incWidth + healthWidth) - - if frame.config.invert_healthbar == "1" then - frame.incHeal:SetWidth(incWidth) - frame.incHeal:SetFrameStrata("HIGH") - end - else - local healthHeight = height * (health / maxHealth) - local incHeight = height * healed / maxHealth - if healthHeight + incHeight > height * (1+(OVERHEALPERCENT/100)) then - incHeight = height * (1+OVERHEALPERCENT/100) - healthHeight - end - - frame.incHeal:SetPoint("BOTTOM", frame.hp.bar, "BOTTOM", 0, 0) - frame.incHeal:SetWidth(width) - frame.incHeal:SetHeight(incHeight + healthHeight) - - if frame.config.invert_healthbar == "1" then - frame.incHeal:SetHeight(incHeight) - frame.incHeal:SetFrameStrata("HIGH") - end - end - else - frame.incHeal:Hide() - end - end - - function pfUI.healComm.onEventRes(unitname) - for _, f in pairs(pfUI.uf.frames) do - if f.label and f.id and UnitName(f.label .. f.id) == unitname then - - if not f.ressIcon then - f.ressIcon = CreateFrame("Frame", nil, f.hp.bar) - f.ressIcon:SetFrameLevel(1) - f.ressIcon.base = f - f.ressIcon:RegisterEvent("PLAYER_TARGET_CHANGED") - f.ressIcon:SetScript("OnEvent", function() - if HealComm:UnitisResurrecting(UnitName(this.base.label .. this.base.id)) then - this:Show() - else - this:Hide() - end - end) - - f.ressIcon:SetWidth(32) - f.ressIcon:SetHeight(32) - f.ressIcon:SetPoint("CENTER", f, "CENTER", 0, 4) - f.ressIcon.texture = f.ressIcon:CreateTexture(nil,"BACKGROUND") - f.ressIcon.texture:SetTexture("Interface\\AddOns\\pfUI\\img\\ress") - f.ressIcon.texture:SetAllPoints(f.ressIcon) - end - - if HealComm:UnitisResurrecting(unitname) then - f.ressIcon:Show() - else - f.ressIcon:Hide() - end - - end - end - end - - AceEvent:RegisterEvent("HealComm_Healupdate", pfUI.healComm.onEvent) - AceEvent:RegisterEvent("HealComm_Ressupdate", pfUI.healComm.onEventRes) - AceEvent:RegisterEvent("UNIT_HEALTH", pfUI.healComm.onEventHealthChange) - AceEvent:RegisterEvent("PLAYER_TARGET_CHANGED", pfUI.healComm.TargetChanged) - end - end) - AddIntegration("SortBags", function() if C.thirdparty.sortbags.enable == "0" then return end diff --git a/pfUI.toc b/pfUI.toc index 72a398df..1b854315 100644 --- a/pfUI.toc +++ b/pfUI.toc @@ -51,6 +51,7 @@ modules\chat.lua modules\addons.lua modules\minimap.lua modules\panel.lua +modules\prediction.lua modules\player.lua modules\focus.lua modules\target.lua