unitframes: replace 'this' by 'unit'

This commit is contained in:
shagu
2017-06-02 18:01:50 +02:00
parent 99c436a2c4
commit f6629dc47b
+102 -102
View File
@@ -461,7 +461,7 @@ end
function pfUI.uf:RefreshUnit(unit, component) function pfUI.uf:RefreshUnit(unit, component)
local component = component or "" local component = component or ""
-- break early on misconfigured UF's -- break early on misconfigured UF's
if not this.label then return end if not unit.label then return end
local default_border = pfUI_config.appearance.border.default local default_border = pfUI_config.appearance.border.default
if pfUI_config.appearance.border.groupframes ~= "-1" then if pfUI_config.appearance.border.groupframes ~= "-1" then
@@ -470,181 +470,181 @@ function pfUI.uf:RefreshUnit(unit, component)
local C = pfUI_config local C = pfUI_config
if UnitName(this.label .. this.id) or (pfUI.gitter and pfUI.gitter:IsShown()) then if UnitName(unit.label .. unit.id) or (pfUI.gitter and pfUI.gitter:IsShown()) then
this:Show() else this:Hide() unit:Show() else unit:Hide()
end end
if not this.cache then unit.cache = {} end if not unit.cache then unit.cache = {} end
if not unit.id then unit.id = "" end if not unit.id then unit.id = "" end
-- Raid Icon -- Raid Icon
if this.raidIcon and ( component == "all" or component == "raidIcon" ) then if unit.raidIcon and ( component == "all" or component == "raidIcon" ) then
local raidIcon = GetRaidTargetIndex(this.label .. this.id) local raidIcon = GetRaidTargetIndex(unit.label .. unit.id)
if raidIcon and UnitName(this.label .. this.id) then if raidIcon and UnitName(unit.label .. unit.id) then
SetRaidTargetIconTexture(this.raidIcon.texture, raidIcon) SetRaidTargetIconTexture(unit.raidIcon.texture, raidIcon)
this.raidIcon:Show() unit.raidIcon:Show()
else else
this.raidIcon:Hide() unit.raidIcon:Hide()
end end
end end
-- Leader Icon -- Leader Icon
if this.leaderIcon and ( component == "all" or component == "leaderIcon" ) then if unit.leaderIcon and ( component == "all" or component == "leaderIcon" ) then
if GetNumPartyMembers() == 0 and GetNumRaidMembers() == 0 then if GetNumPartyMembers() == 0 and GetNumRaidMembers() == 0 then
this.leaderIcon:Hide() unit.leaderIcon:Hide()
elseif UnitIsPartyLeader(this.label .. this.id) then elseif UnitIsPartyLeader(unit.label .. unit.id) then
this.leaderIcon:Show() unit.leaderIcon:Show()
else else
this.leaderIcon:Hide() unit.leaderIcon:Hide()
end end
end end
-- Loot Icon -- Loot Icon
if this.lootIcon and ( component == "all" or component == "lootIcon" ) then if unit.lootIcon and ( component == "all" or component == "lootIcon" ) then
local _, lootmaster = GetLootMethod() local _, lootmaster = GetLootMethod()
if GetNumPartyMembers() == 0 and GetNumRaidMembers() == 0 then if GetNumPartyMembers() == 0 and GetNumRaidMembers() == 0 then
this.lootIcon:Hide() unit.lootIcon:Hide()
elseif lootmaster and ( elseif lootmaster and (
( this.label == "party" and tonumber(this.id) == lootmaster ) or ( unit.label == "party" and tonumber(unit.id) == lootmaster ) or
( this.label == "player" and lootmaster == 0 ) )then ( unit.label == "player" and lootmaster == 0 ) )then
this.lootIcon:Show() unit.lootIcon:Show()
else else
this.lootIcon:Hide() unit.lootIcon:Hide()
end end
end end
-- Buffs -- Buffs
if this.buffs and ( component == "all" or component == "aura" ) then if unit.buffs and ( component == "all" or component == "aura" ) then
for i=1, 16 do for i=1, 16 do
local texture, stacks local texture, stacks
if this.label == "player" then if unit.label == "player" then
stacks = GetPlayerBuffApplications(GetPlayerBuff(i-1,"HELPFUL")) stacks = GetPlayerBuffApplications(GetPlayerBuff(i-1,"HELPFUL"))
texture = GetPlayerBuffTexture(GetPlayerBuff(i-1,"HELPFUL")) texture = GetPlayerBuffTexture(GetPlayerBuff(i-1,"HELPFUL"))
else else
texture, stacks = UnitBuff(this.label .. this.id ,i) texture, stacks = UnitBuff(unit.label .. unit.id ,i)
end end
pfUI.api.CreateBackdrop(this.buffs[i], default_border) pfUI.api.CreateBackdrop(unit.buffs[i], default_border)
this.buffs[i]:SetNormalTexture(texture) unit.buffs[i]:SetNormalTexture(texture)
for i,v in ipairs({this.buffs[i]:GetRegions()}) do for i,v in ipairs({unit.buffs[i]:GetRegions()}) do
if v.SetTexCoord then v:SetTexCoord(.08, .92, .08, .92) end if v.SetTexCoord then v:SetTexCoord(.08, .92, .08, .92) end
end end
if texture then if texture then
this.buffs[i]:Show() unit.buffs[i]:Show()
if stacks > 1 then if stacks > 1 then
this.buffs[i].stacks:SetText(stacks) unit.buffs[i].stacks:SetText(stacks)
else else
this.buffs[i].stacks:SetText("") unit.buffs[i].stacks:SetText("")
end end
else else
this.buffs[i]:Hide() unit.buffs[i]:Hide()
end end
end end
end end
-- Debuffs -- Debuffs
if this.debuffs and ( component == "all" or component == "aura" ) then if unit.debuffs and ( component == "all" or component == "aura" ) then
for i=1, 16 do for i=1, 16 do
local row = 0 local row = 0
local top = 0 local top = 0
if i > 8 then row = 1 end if i > 8 then row = 1 end
if this.config.buffs == this.config.debuffs then if unit.config.buffs == unit.config.debuffs then
if this.buffs[1]:IsShown() then top = top + 1 end if unit.buffs[1]:IsShown() then top = top + 1 end
if this.buffs[9]:IsShown() then top = top + 1 end if unit.buffs[9]:IsShown() then top = top + 1 end
end end
local invert, af, as local invert, af, as
if this.config.debuffs == "top" then if unit.config.debuffs == "top" then
invert = 1 invert = 1
af = "BOTTOMLEFT" af = "BOTTOMLEFT"
as = "TOPLEFT" as = "TOPLEFT"
elseif this.config.debuffs == "bottom" then elseif unit.config.debuffs == "bottom" then
invert = -1 invert = -1
af = "TOPLEFT" af = "TOPLEFT"
as = "BOTTOMLEFT" as = "BOTTOMLEFT"
end end
this.debuffs[i]:SetPoint(af, this, as, unit.debuffs[i]:SetPoint(af, unit, as,
(i-1-8*row)*((2*default_border) + C.unitframes.debuff_size + 1), (i-1-8*row)*((2*default_border) + C.unitframes.debuff_size + 1),
invert * (top)*((2*default_border) + C.unitframes.buff_size + 1) + invert * (top)*((2*default_border) + C.unitframes.buff_size + 1) +
invert * (row)*((2*default_border) + C.unitframes.debuff_size + 1) + invert*(2*default_border + 1)) invert * (row)*((2*default_border) + C.unitframes.debuff_size + 1) + invert*(2*default_border + 1))
local texture, stacks, dtype local texture, stacks, dtype
if this.label == "player" then if unit.label == "player" then
texture = GetPlayerBuffTexture(GetPlayerBuff(i-1, "HARMFUL")) texture = GetPlayerBuffTexture(GetPlayerBuff(i-1, "HARMFUL"))
stacks = GetPlayerBuffApplications(GetPlayerBuff(i-1, "HARMFUL")) stacks = GetPlayerBuffApplications(GetPlayerBuff(i-1, "HARMFUL"))
dtype = GetPlayerBuffDispelType(GetPlayerBuff(i-1, "HARMFUL")) dtype = GetPlayerBuffDispelType(GetPlayerBuff(i-1, "HARMFUL"))
else else
texture, stacks, dtype = UnitDebuff(this.label .. this.id ,i) texture, stacks, dtype = UnitDebuff(unit.label .. unit.id ,i)
end end
pfUI.api.CreateBackdrop(this.debuffs[i], default_border) pfUI.api.CreateBackdrop(unit.debuffs[i], default_border)
this.debuffs[i]:SetNormalTexture(texture) unit.debuffs[i]:SetNormalTexture(texture)
for i,v in ipairs({this.debuffs[i]:GetRegions()}) do for i,v in ipairs({unit.debuffs[i]:GetRegions()}) do
if v.SetTexCoord then v:SetTexCoord(.08, .92, .08, .92) end if v.SetTexCoord then v:SetTexCoord(.08, .92, .08, .92) end
end end
if dtype == "Magic" then if dtype == "Magic" then
this.debuffs[i].backdrop:SetBackdropBorderColor(0,1,1,1) unit.debuffs[i].backdrop:SetBackdropBorderColor(0,1,1,1)
elseif dtype == "Poison" then elseif dtype == "Poison" then
this.debuffs[i].backdrop:SetBackdropBorderColor(0,1,0,1) unit.debuffs[i].backdrop:SetBackdropBorderColor(0,1,0,1)
elseif dtype == "Curse" then elseif dtype == "Curse" then
this.debuffs[i].backdrop:SetBackdropBorderColor(1,0,1,1) unit.debuffs[i].backdrop:SetBackdropBorderColor(1,0,1,1)
elseif dtype == "Disease" then elseif dtype == "Disease" then
this.debuffs[i].backdrop:SetBackdropBorderColor(1,1,0,1) unit.debuffs[i].backdrop:SetBackdropBorderColor(1,1,0,1)
else else
this.debuffs[i].backdrop:SetBackdropBorderColor(1,0,0,1) unit.debuffs[i].backdrop:SetBackdropBorderColor(1,0,0,1)
end end
if texture then if texture then
this.debuffs[i]:Show() unit.debuffs[i]:Show()
if stacks > 1 then if stacks > 1 then
this.debuffs[i].stacks:SetText(stacks) unit.debuffs[i].stacks:SetText(stacks)
else else
this.debuffs[i].stacks:SetText("") unit.debuffs[i].stacks:SetText("")
end end
else else
this.debuffs[i]:Hide() unit.debuffs[i]:Hide()
end end
end end
end end
-- portrait -- portrait
if this.portrait and ( component == "all" or component == "portrait" ) then if unit.portrait and ( component == "all" or component == "portrait" ) then
if not UnitIsVisible(this.label .. this.id) or not UnitIsConnected(this.label .. this.id) then if not UnitIsVisible(unit.label .. unit.id) or not UnitIsConnected(unit.label .. unit.id) then
if this.config.portrait == "bar" then if unit.config.portrait == "bar" then
this.portrait.tex:Hide() unit.portrait.tex:Hide()
this.portrait.model:Hide() unit.portrait.model:Hide()
elseif pfUI_config.unitframes.portraittexture == "1" then elseif pfUI_config.unitframes.portraittexture == "1" then
this.portrait.tex:Show() unit.portrait.tex:Show()
this.portrait.model:Hide() unit.portrait.model:Hide()
SetPortraitTexture(this.portrait.tex, this.label .. this.id) SetPortraitTexture(unit.portrait.tex, unit.label .. unit.id)
else else
this.portrait.tex:Hide() unit.portrait.tex:Hide()
this.portrait.model:Show() unit.portrait.model:Show()
this.portrait.model:SetModelScale(4.25) unit.portrait.model:SetModelScale(4.25)
this.portrait.model:SetPosition(0, 0, -1) unit.portrait.model:SetPosition(0, 0, -1)
this.portrait.model:SetModel("Interface\\Buttons\\talktomequestionmark.mdx") unit.portrait.model:SetModel("Interface\\Buttons\\talktomequestionmark.mdx")
end end
else else
if this.config.portrait == "bar" then if unit.config.portrait == "bar" then
this.portrait:SetAlpha(pfUI_config.unitframes.portraitalpha) unit.portrait:SetAlpha(pfUI_config.unitframes.portraitalpha)
end end
this.portrait.tex:Hide() unit.portrait.tex:Hide()
this.portrait.model:Show() unit.portrait.model:Show()
if this.tick then if unit.tick then
this.portrait.model.next:SetUnit(this.label .. this.id) unit.portrait.model.next:SetUnit(unit.label .. unit.id)
if this.portrait.model.lastUnit ~= UnitName(this.label .. this.id) or this.portrait.model:GetModel() ~= this.portrait.model.next:GetModel() then if unit.portrait.model.lastUnit ~= UnitName(unit.label .. unit.id) or unit.portrait.model:GetModel() ~= unit.portrait.model.next:GetModel() then
this.portrait.model:SetUnit(this.label .. this.id) unit.portrait.model:SetUnit(unit.label .. unit.id)
this.portrait.model.lastUnit = UnitName(this.label .. this.id) unit.portrait.model.lastUnit = UnitName(unit.label .. unit.id)
this.portrait.model:SetCamera(0) unit.portrait.model:SetCamera(0)
end end
else else
this.portrait.model:SetUnit(this.label .. this.id) unit.portrait.model:SetUnit(unit.label .. unit.id)
this.portrait.model:SetCamera(0) unit.portrait.model:SetCamera(0)
end end
end end
@@ -656,8 +656,8 @@ function pfUI.uf:RefreshUnit(unit, component)
unit.cache.power = UnitMana(unit.label .. unit.id) unit.cache.power = UnitMana(unit.label .. unit.id)
unit.cache.powermax = UnitManaMax(unit.label .. unit.id) unit.cache.powermax = UnitManaMax(unit.label .. unit.id)
if this.label == "target" and MobHealth3 then if unit.label == "target" and MobHealth3 then
unit.cache.hp, unit.cache.hpmax = MobHealth3:GetUnitHealth(this.label) unit.cache.hp, unit.cache.hpmax = MobHealth3:GetUnitHealth(unit.label)
end end
unit.hp.bar:SetMinMaxValues(0, unit.cache.hpmax) unit.hp.bar:SetMinMaxValues(0, unit.cache.hpmax)
@@ -716,8 +716,8 @@ function pfUI.uf:RefreshUnit(unit, component)
pfUI.uf:SetupDebuffFilter() pfUI.uf:SetupDebuffFilter()
if table.getn(pfUI.uf.debuffs) > 0 and if table.getn(pfUI.uf.debuffs) > 0 and
((pfUI_config.unitframes.group.raid_debuffs == "1" and this.label == "party") or ((pfUI_config.unitframes.group.raid_debuffs == "1" and unit.label == "party") or
this.label == "raid") unit.label == "raid")
then then
local infected = false local infected = false
for i=1,32 do for i=1,32 do
@@ -787,8 +787,8 @@ function pfUI.uf:RefreshUnit(unit, component)
pfUI.uf:SetupBuffFilter() pfUI.uf:SetupBuffFilter()
if table.getn(pfUI.uf.buffs) > 0 and if table.getn(pfUI.uf.buffs) > 0 and
((pfUI_config.unitframes.group.raid_buffs == "1" and this.label == "party") or ((pfUI_config.unitframes.group.raid_buffs == "1" and unit.label == "party") or
this.label == "raid") unit.label == "raid")
then then
local active = {} local active = {}
@@ -806,14 +806,14 @@ function pfUI.uf:RefreshUnit(unit, component)
-- add icons for every found buff -- add icons for every found buff
for pos, icon in pairs(active) do for pos, icon in pairs(active) do
pfUI.uf:AddIcon(this, pos, icon) pfUI.uf:AddIcon(unit, pos, icon)
end end
end end
end end
-- hide unued icon slots -- hide unued icon slots
for pos=table.getn(active)+1, 6 do for pos=table.getn(active)+1, 6 do
pfUI.uf:HideIcon(this, pos) pfUI.uf:HideIcon(unit, pos)
end end
end end
end end
@@ -1137,48 +1137,48 @@ function pfUI.uf:GetStatusValue(unit, pos)
elseif elite == "rare" then elseif elite == "rare" then
level = level .. "R" level = level .. "R"
end end
level = this:GetColor("level") .. level level = unit:GetColor("level") .. level
name = this:GetColor("unit") .. name name = unit:GetColor("unit") .. name
return level .. " " .. name return level .. " " .. name
elseif config == "name" then elseif config == "name" then
return this:GetColor("unit") .. UnitName(unitstr) return unit:GetColor("unit") .. UnitName(unitstr)
elseif config == "level" then elseif config == "level" then
return this:GetColor("level") .. UnitLevel(unitstr) return unit:GetColor("level") .. UnitLevel(unitstr)
elseif config == "class" then elseif config == "class" then
return this:GetColor("class") .. UnitClass(unitstr) return unit:GetColor("class") .. UnitClass(unitstr)
-- health -- health
elseif config == "health" then elseif config == "health" then
return this:GetColor("health") .. UnitHealth(unitstr) return unit:GetColor("health") .. UnitHealth(unitstr)
elseif config == "healthmax" then elseif config == "healthmax" then
return this:GetColor("health") .. UnitHealthMax(unitstr) return unit:GetColor("health") .. UnitHealthMax(unitstr)
elseif config == "healthperc" then elseif config == "healthperc" then
return this:GetColor("health") .. ceil(UnitHealth(unitstr) / UnitHealthMax(unitstr) * 100) return unit:GetColor("health") .. ceil(UnitHealth(unitstr) / UnitHealthMax(unitstr) * 100)
elseif config == "healthmiss" then elseif config == "healthmiss" then
return this:GetColor("health") .. ceil(UnitHealth(unitstr) - UnitHealthMax(unitstr)) return unit:GetColor("health") .. ceil(UnitHealth(unitstr) - UnitHealthMax(unitstr))
elseif config == "healthdyn" then elseif config == "healthdyn" then
if UnitHealth(unitstr) ~= UnitHealthMax(unitstr) then if UnitHealth(unitstr) ~= UnitHealthMax(unitstr) then
return this:GetColor("health") .. UnitHealth(unitstr) .. " - " .. ceil(UnitHealth(unitstr) / UnitHealthMax(unitstr) * 100) .. "%" return unit:GetColor("health") .. UnitHealth(unitstr) .. " - " .. ceil(UnitHealth(unitstr) / UnitHealthMax(unitstr) * 100) .. "%"
else else
return this:GetColor("health") .. UnitHealth(unitstr) return unit:GetColor("health") .. UnitHealth(unitstr)
end end
-- mana/power/focus -- mana/power/focus
elseif config == "power" then elseif config == "power" then
return this:GetColor("power") .. UnitMana(unitstr) return unit:GetColor("power") .. UnitMana(unitstr)
elseif config == "powermax" then elseif config == "powermax" then
return this:GetColor("power") .. UnitManaMax(unitstr) return unit:GetColor("power") .. UnitManaMax(unitstr)
elseif config == "powerperc" then elseif config == "powerperc" then
return this:GetColor("power") .. ceil(UnitMana(unitstr) / UnitManaMax(unitstr) * 100) return unit:GetColor("power") .. ceil(UnitMana(unitstr) / UnitManaMax(unitstr) * 100)
elseif config == "powermiss" then elseif config == "powermiss" then
return this:GetColor("power") .. ceil(UnitMana(unitstr) - UnitManaMax(unitstr)) return unit:GetColor("power") .. ceil(UnitMana(unitstr) - UnitManaMax(unitstr))
elseif config == "powerdyn" then elseif config == "powerdyn" then
if UnitMana(unitstr) ~= UnitManaMax(unitstr) then if UnitMana(unitstr) ~= UnitManaMax(unitstr) then
return this:GetColor("power") .. UnitMana(unitstr) .. " - " .. ceil(UnitMana(unitstr) / UnitManaMax(unitstr) * 100) .. "%" return unit:GetColor("power") .. UnitMana(unitstr) .. " - " .. ceil(UnitMana(unitstr) / UnitManaMax(unitstr) * 100) .. "%"
else else
return this:GetColor("power") .. UnitMana(unitstr) return unit:GetColor("power") .. UnitMana(unitstr)
end end
else else
return "" return ""