mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-24 21:10:49 +00:00
prediction: optimize code
This commit is contained in:
+15
-2
@@ -107,14 +107,27 @@ function pfUI.uf:CreateUnitFrame(unit, id, config, tick)
|
|||||||
f.hp.bar.texture:SetAllPoints(f.hp.bar)
|
f.hp.bar.texture:SetAllPoints(f.hp.bar)
|
||||||
end
|
end
|
||||||
|
|
||||||
f.incHeal = CreateFrame("StatusBar", nil, f)
|
f.incHeal = CreateFrame("StatusBar", nil, f.hp.bar)
|
||||||
|
f.incHeal:SetHeight(f.config.height)
|
||||||
|
f.incHeal:SetWidth(f.config.width)
|
||||||
f.incHeal:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar")
|
f.incHeal:SetStatusBarTexture("Interface\\AddOns\\pfUI\\img\\bar")
|
||||||
f.incHeal:SetFrameStrata("MEDIUM")
|
|
||||||
f.incHeal:SetMinMaxValues(0, 1)
|
f.incHeal:SetMinMaxValues(0, 1)
|
||||||
f.incHeal:SetValue(1)
|
f.incHeal:SetValue(1)
|
||||||
f.incHeal:SetStatusBarColor(0, 1, 0, 0.5)
|
f.incHeal:SetStatusBarColor(0, 1, 0, 0.5)
|
||||||
f.incHeal:Hide()
|
f.incHeal:Hide()
|
||||||
|
|
||||||
|
if pfUI_config.unitframes.custombg == "0" then
|
||||||
|
f.incHeal:SetFrameLevel(2)
|
||||||
|
else
|
||||||
|
f.incHeal:SetFrameLevel(3)
|
||||||
|
end
|
||||||
|
|
||||||
|
if f.config.verticalbar == "0" then
|
||||||
|
f.incHeal:SetPoint("TOPLEFT", f.hp.bar, "TOPLEFT", 0, 0)
|
||||||
|
else
|
||||||
|
f.incHeal:SetPoint("BOTTOM", f.hp.bar, "BOTTOM", 0, 0)
|
||||||
|
end
|
||||||
|
|
||||||
f.ressIcon = CreateFrame("Frame", nil, f.hp.bar)
|
f.ressIcon = CreateFrame("Frame", nil, f.hp.bar)
|
||||||
f.ressIcon:SetFrameLevel(16)
|
f.ressIcon:SetFrameLevel(16)
|
||||||
f.ressIcon:SetWidth(32)
|
f.ressIcon:SetWidth(32)
|
||||||
|
|||||||
+91
-105
@@ -1,45 +1,57 @@
|
|||||||
pfUI:RegisterModule("prediction", function ()
|
pfUI:RegisterModule("prediction", function ()
|
||||||
local heals = {}
|
local heals = {}
|
||||||
local ress = {}
|
local ress = {}
|
||||||
|
local events = {}
|
||||||
|
|
||||||
pfUI.prediction = CreateFrame("Frame")
|
pfUI.prediction = CreateFrame("Frame")
|
||||||
pfUI.prediction:RegisterEvent("COMBAT_TEXT_UPDATE")
|
|
||||||
pfUI.prediction:RegisterEvent("UNIT_COMBAT")
|
|
||||||
pfUI.prediction:RegisterEvent("UNIT_HEALTH")
|
pfUI.prediction:RegisterEvent("UNIT_HEALTH")
|
||||||
pfUI.prediction:RegisterEvent("CHAT_MSG_ADDON")
|
pfUI.prediction:RegisterEvent("CHAT_MSG_ADDON")
|
||||||
pfUI.prediction:RegisterEvent("PLAYER_TARGET_CHANGED")
|
pfUI.prediction:RegisterEvent("PLAYER_TARGET_CHANGED")
|
||||||
pfUI.prediction:RegisterEvent("SPELLCAST_STOP")
|
|
||||||
|
|
||||||
pfUI.prediction:SetScript("OnEvent", function()
|
pfUI.prediction:SetScript("OnEvent", function()
|
||||||
if event == "CHAT_MSG_ADDON" and arg1 == "HealComm" then
|
if event == "CHAT_MSG_ADDON" and arg1 == "HealComm" then
|
||||||
local channel = arg3
|
local channel = arg3
|
||||||
local sender = arg4
|
local sender = arg4
|
||||||
|
|
||||||
if arg2 == "Healstop" then
|
if arg2 == "Healstop" or arg2 == "GrpHealstop" then
|
||||||
pfUI.prediction:HealStop(sender)
|
for ttarget, t in pairs(heals) do
|
||||||
return
|
for tsender in pairs(heals[ttarget]) do
|
||||||
elseif arg2 == "GrpHealstop" then
|
if sender == tsender then
|
||||||
pfUI.prediction:HealStop(sender)
|
heals[ttarget][tsender] = nil
|
||||||
|
pfUI.prediction:TriggerUpdate(ttarget)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
return
|
return
|
||||||
elseif arg2 == "Resurrection/stop/" then
|
elseif arg2 == "Resurrection/stop/" then
|
||||||
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
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, _, evtype, target, amount, duration = string.find(arg2, '(Heal)/(%a+)/(%d+)/(%d+)/')
|
local _, _, evtype, target, amount, duration = string.find(arg2, '(Heal)/(%a+)/(%d+)/(%d+)/')
|
||||||
if evtype then
|
if evtype then
|
||||||
|
local timeout = duration/1000 + GetTime()
|
||||||
heals[target] = heals[target] or {}
|
heals[target] = heals[target] or {}
|
||||||
heals[target][sender] = { amount, duration + GetTime() }
|
heals[target][sender] = { amount, timeout }
|
||||||
pfUI.prediction:TriggerUpdate(target)
|
pfUI.prediction:TriggerUpdate(target)
|
||||||
|
pfUI.prediction:AddEvent(timeout, target)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local _, _, evtype, amount, duration, targets = string.find(arg2, '(GrpHeal)/(%d+)/(%d+)/(.+)/')
|
local _, _, evtype, amount, duration, targets = string.find(arg2, '(GrpHeal)/(%d+)/(%d+)/(.+)/')
|
||||||
if evtype then
|
if evtype then
|
||||||
for _, target in pairs({strsplit("/", targets)}) do
|
for _, target in pairs({strsplit("/", targets)}) do
|
||||||
|
local timeout = duration/1000 + GetTime()
|
||||||
heals[target] = heals[target] or {}
|
heals[target] = heals[target] or {}
|
||||||
heals[target][sender] = { amount, duration + GetTime() }
|
heals[target][sender] = { amount, timeout }
|
||||||
pfUI.prediction:TriggerUpdate(target)
|
pfUI.prediction:TriggerUpdate(target)
|
||||||
|
pfUI.prediction:AddEvent(timeout, target)
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -51,10 +63,6 @@ pfUI:RegisterModule("prediction", function ()
|
|||||||
pfUI.prediction:TriggerUpdate(target)
|
pfUI.prediction:TriggerUpdate(target)
|
||||||
return
|
return
|
||||||
end
|
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
|
elseif event == "UNIT_HEALTH" then
|
||||||
local name = UnitName(arg1)
|
local name = UnitName(arg1)
|
||||||
if ress[name] and not UnitIsDeadOrGhost(arg1) then
|
if ress[name] and not UnitIsDeadOrGhost(arg1) then
|
||||||
@@ -65,38 +73,25 @@ pfUI:RegisterModule("prediction", function ()
|
|||||||
if heals[name] then
|
if heals[name] then
|
||||||
pfUI.prediction:TriggerUpdate(name)
|
pfUI.prediction:TriggerUpdate(name)
|
||||||
end
|
end
|
||||||
elseif event == "SPELLCAST_STOP" then
|
|
||||||
pfUI.prediction:HealStop(UnitName("player"))
|
|
||||||
elseif event == "PLAYER_TARGET_CHANGED" then
|
elseif event == "PLAYER_TARGET_CHANGED" then
|
||||||
if pfUI.uf and pfUI.uf.target then
|
pfUI.prediction:TriggerUpdate(UnitName("target"))
|
||||||
pfUI.prediction:DrawPrediction("target", pfUI.uf.target)
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
pfUI.prediction:SetScript("OnUpdate", function()
|
||||||
|
for timestamp, targets in pairs(events) do
|
||||||
|
if GetTime() >= timestamp then
|
||||||
|
for id, target in pairs(targets) do
|
||||||
|
pfUI.prediction:TriggerUpdate(target)
|
||||||
|
end
|
||||||
|
events[timestamp] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
pfUI.prediction.scanner = CreateFrame('GameTooltip', "pfPredictionScanner", UIParent, "GameTooltipTemplate")
|
function pfUI.prediction:AddEvent(time, target)
|
||||||
pfUI.prediction.scanner:SetOwner(WorldFrame, "ANCHOR_NONE")
|
events[time] = events[time] or {}
|
||||||
|
table.insert(events[time], target)
|
||||||
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
|
end
|
||||||
|
|
||||||
function pfUI.prediction:GetHeal(target)
|
function pfUI.prediction:GetHeal(target)
|
||||||
@@ -105,21 +100,17 @@ pfUI:RegisterModule("prediction", function ()
|
|||||||
return sumheal
|
return sumheal
|
||||||
else
|
else
|
||||||
for sender, amount in pairs(heals[target]) do
|
for sender, amount in pairs(heals[target]) do
|
||||||
sumheal = sumheal + amount[1]
|
if amount[2] <= GetTime() then
|
||||||
end
|
heals[target][sender] = nil
|
||||||
end
|
if table.getn(heals[target]) == 0 then
|
||||||
return sumheal
|
heals[target] = nil
|
||||||
end
|
end
|
||||||
|
else
|
||||||
function pfUI.prediction:RessStop(sender)
|
sumheal = sumheal + amount[1]
|
||||||
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
|
||||||
end
|
end
|
||||||
|
return sumheal
|
||||||
end
|
end
|
||||||
|
|
||||||
function pfUI.prediction:GetRess(target)
|
function pfUI.prediction:GetRess(target)
|
||||||
@@ -136,68 +127,63 @@ pfUI:RegisterModule("prediction", function ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function pfUI.prediction:TriggerUpdate(target)
|
function pfUI.prediction:TriggerUpdate(target)
|
||||||
for id, frame in _G.pfUI.uf.frames do
|
if not target or not heals[target] then return end
|
||||||
if frame:IsVisible() and UnitName(frame.label .. frame.id) == target then
|
local heal = pfUI.prediction:GetHeal(target)
|
||||||
pfUI.prediction:DrawPrediction(frame.label .. frame.id, frame)
|
local ress = pfUI.prediction:GetRess(target)
|
||||||
end
|
|
||||||
|
if pfUI.uf then
|
||||||
|
pfUI.prediction:UpdateUnitFrames(target, heal, ress)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function pfUI.prediction:DrawPrediction(unit, frame)
|
function pfUI.prediction:UpdateUnitFrames(name, heal, ress)
|
||||||
OVERHEALPERCENT = OVERHEALPERCENT or 20
|
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
|
for id, frame in _G.pfUI.uf.frames do
|
||||||
frame.ressIcon:Show()
|
if frame:IsVisible() then
|
||||||
return
|
local unit = frame.label .. frame.id
|
||||||
else
|
local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
|
||||||
frame.ressIcon:Hide()
|
|
||||||
end
|
|
||||||
|
|
||||||
local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
|
if UnitName(unit) == name then
|
||||||
if( healed > 0 and (health < maxHealth or OVERHEALPERCENT > 0 )) then
|
if ress and UnitIsDeadOrGhost(unit) then
|
||||||
frame.incHeal:Show()
|
frame.ressIcon:Show()
|
||||||
frame.incHeal:SetFrameStrata("BACKGROUND")
|
elseif heal and heal > 0 and (health < maxHealth or OVERHEALPERCENT > 0 ) then
|
||||||
frame.incHeal:ClearAllPoints()
|
local width = frame.config.width
|
||||||
|
local height = frame.config.height
|
||||||
|
|
||||||
local width = frame.hp.bar:GetWidth() / frame.hp.bar:GetEffectiveScale()
|
if frame.config.verticalbar == "0" then
|
||||||
local height = frame.hp.bar:GetHeight() / frame.hp.bar:GetEffectiveScale()
|
local healthWidth = width * (health / maxHealth)
|
||||||
|
local incWidth = width * heal / maxHealth
|
||||||
|
if healthWidth + incWidth > width * (1+(OVERHEALPERCENT/100)) then
|
||||||
|
incWidth = width * (1+OVERHEALPERCENT/100) - healthWidth
|
||||||
|
end
|
||||||
|
|
||||||
if frame.config.verticalbar == "0" then
|
if frame.config.invert_healthbar == "1" then
|
||||||
local healthWidth = width * (health / maxHealth)
|
frame.incHeal:SetWidth(incWidth)
|
||||||
local incWidth = width * healed / maxHealth
|
else
|
||||||
if healthWidth + incWidth > width * (1+(OVERHEALPERCENT/100)) then
|
frame.incHeal:SetWidth(incWidth + healthWidth)
|
||||||
incWidth = width * (1+OVERHEALPERCENT/100) - healthWidth
|
end
|
||||||
end
|
else
|
||||||
|
local healthHeight = height * (health / maxHealth)
|
||||||
|
local incHeight = height * heal / maxHealth
|
||||||
|
if healthHeight + incHeight > height * (1+(OVERHEALPERCENT/100)) then
|
||||||
|
incHeight = height * (1+OVERHEALPERCENT/100) - healthHeight
|
||||||
|
end
|
||||||
|
|
||||||
frame.incHeal:SetPoint("TOPLEFT", frame.hp.bar, "TOPLEFT", 0, 0)
|
if frame.config.invert_healthbar == "1" then
|
||||||
frame.incHeal:SetHeight(height)
|
frame.incHeal:SetHeight(incHeight)
|
||||||
frame.incHeal:SetWidth(incWidth + healthWidth)
|
else
|
||||||
|
frame.incHeal:SetHeight(incHeight + healthHeight)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if frame.config.invert_healthbar == "1" then
|
frame.incHeal:Show()
|
||||||
frame.incHeal:SetWidth(incWidth)
|
else
|
||||||
frame.incHeal:SetFrameStrata("HIGH")
|
frame.incHeal:Hide()
|
||||||
end
|
frame.ressIcon:Hide()
|
||||||
else
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
else
|
|
||||||
frame.incHeal:Hide()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user