mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-12 00:20:01 +00:00
libunitscan: unify all unit scanners
This commit is contained in:
+34
-97
@@ -3,10 +3,6 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
local font_size = C.nameplates.use_unitfonts == "1" and C.global.font_unit_size or C.global.font_size
|
||||
|
||||
pfUI.nameplates = CreateFrame("Frame", nil, UIParent)
|
||||
pfUI.nameplates.players = pfUI_playerDB
|
||||
pfUI.nameplates.mobs = {}
|
||||
pfUI.nameplates.targets = {}
|
||||
pfUI.nameplates.scanqueue = {}
|
||||
|
||||
-- catch all nameplates
|
||||
pfUI.nameplates.scanner = CreateFrame("Frame", "pfNameplateScanner", UIParent)
|
||||
@@ -33,41 +29,6 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- [[ scan missing names ]]
|
||||
for index, name in pairs(pfUI.nameplates.scanqueue) do
|
||||
-- remove entry if already scanned
|
||||
if pfUI.nameplates.targets[name] == "OK" then
|
||||
table.remove(pfUI.nameplates.scanqueue, index)
|
||||
else
|
||||
if UnitName("mouseover") == name then
|
||||
if UnitIsPlayer("mouseover") then
|
||||
local _, class = UnitClass("mouseover")
|
||||
pfUI.nameplates.players[name] = {}
|
||||
pfUI.nameplates.players[name]["class"] = class
|
||||
elseif UnitClassification("mouseover") then
|
||||
local elite = UnitClassification("mouseover")
|
||||
pfUI.nameplates.mobs[name] = elite
|
||||
end
|
||||
pfUI.nameplates.targets[name] = "OK"
|
||||
|
||||
elseif not UnitName("target") then
|
||||
TargetByName(name, true)
|
||||
|
||||
if UnitIsPlayer("target") then
|
||||
local _, class = UnitClass("target")
|
||||
pfUI.nameplates.players[name] = {}
|
||||
pfUI.nameplates.players[name]["class"] = class
|
||||
elseif UnitClassification("target") then
|
||||
local elite = UnitClassification("target")
|
||||
pfUI.nameplates.mobs[name] = elite
|
||||
end
|
||||
pfUI.nameplates.targets[name] = "OK"
|
||||
|
||||
ClearTarget()
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local plate_width = C.nameplates.width + 50
|
||||
@@ -82,7 +43,6 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
this.nameplate.parent = this
|
||||
this.healthbar = this:GetChildren()
|
||||
this.healthbar:SetScript("OnEnter", function() return nil end)
|
||||
|
||||
for i, frame in pairs({this:GetRegions()}) do
|
||||
if NAMEPLATE_OBJECTORDER[i] == "_" then
|
||||
frame.Show = function() return end
|
||||
@@ -351,14 +311,12 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
end
|
||||
|
||||
if C.nameplates.players == "1" then
|
||||
if pfUI.nameplates.targets[this.name:GetText()] == "OK" then
|
||||
if not pfUI.nameplates.players[this.name:GetText()] then this:Hide() end
|
||||
end
|
||||
local _, _, _, uplayer = GetUnitData(this.name:GetText(), true)
|
||||
if uplayer then this:Hide() end
|
||||
end
|
||||
|
||||
this.needNameUpdate = true
|
||||
this.needClassColorUpdate = true
|
||||
this.needLevelColorUpdate = true
|
||||
this.needBasicColorUpdate = true
|
||||
this.needEliteUpdate = true
|
||||
|
||||
this.setup = true
|
||||
@@ -371,24 +329,21 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
local healthbar = this.healthbar
|
||||
local border, glow, name, level, levelicon , raidicon, combopoints = this.border, this.glow, this.name, this.level, this.levelicon , this.raidicon, this.combopoints
|
||||
local unitname = name:GetText()
|
||||
local uclass, ulevel, uelite, uplayer = GetUnitData(unitname, true)
|
||||
|
||||
-- add scan entry if not existing
|
||||
if this.needNameUpdate and unitname ~= UNKNOWN then
|
||||
if not pfUI.nameplates.targets[unitname] then
|
||||
table.insert(pfUI.nameplates.scanqueue, unitname)
|
||||
end
|
||||
this.needNameUpdate = nil
|
||||
if unitname == UNKNOWN then
|
||||
this.needClassColorUpdate = true
|
||||
this.needBasicColorUpdate = true
|
||||
this.needEliteUpdate = true
|
||||
end
|
||||
|
||||
-- hide non-player frames
|
||||
if C.nameplates.players == "1" and not this.needNameUpdate then
|
||||
if pfUI.nameplates.targets[unitname] == "OK" then
|
||||
if not pfUI.nameplates.players[unitname] then this:Hide() end
|
||||
end
|
||||
if C.nameplates.players == "1" then
|
||||
if uplayer then this:Hide() end
|
||||
end
|
||||
|
||||
-- hide critters
|
||||
if C.nameplates.critters == "1" and not this.needNameUpdate then
|
||||
if C.nameplates.critters == "1" then
|
||||
local red, green, blue, _ = healthbar:GetStatusBarColor()
|
||||
local name_val = unitname
|
||||
for i, critter_val in pairs(L["critters"]) do
|
||||
@@ -399,7 +354,7 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
end
|
||||
|
||||
-- hide totems
|
||||
if C.nameplates.totems == "1" and not this.needNameUpdate then
|
||||
if C.nameplates.totems == "1" then
|
||||
for totem in pairs(L["totems"]) do
|
||||
if string.find(unitname, totem) then
|
||||
this:Hide()
|
||||
@@ -414,13 +369,13 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
end
|
||||
|
||||
-- level elite indicator
|
||||
if this.needEliteUpdate and pfUI.nameplates.mobs[unitname] then
|
||||
if this.needEliteUpdate and uelite then
|
||||
if level:GetText() ~= nil then
|
||||
if pfUI.nameplates.mobs[unitname] == "elite" then
|
||||
if uelite == "elite" then
|
||||
level:SetText(level:GetText() .. "+")
|
||||
elseif pfUI.nameplates.mobs[unitname] == "rareelite" then
|
||||
elseif uelite == "rareelite" then
|
||||
level:SetText(level:GetText() .. "R+")
|
||||
elseif pfUI.nameplates.mobs[unitname] == "rare" then
|
||||
elseif uelite == "rare" then
|
||||
level:SetText(level:GetText() .. "R")
|
||||
end
|
||||
end
|
||||
@@ -428,72 +383,54 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
end
|
||||
|
||||
-- level colors
|
||||
if this.needLevelColorUpdate then
|
||||
if this.needBasicColorUpdate then
|
||||
local red, green, blue, _ = level:GetTextColor()
|
||||
if red > 0.99 and green == 0 and blue == 0 then
|
||||
level:SetTextColor(1,0.4,0.2,0.85)
|
||||
elseif red > 0.99 and green > 0.81 and green < 0.82 and blue == 0 then
|
||||
level:SetTextColor(1,1,1,0.85)
|
||||
end
|
||||
this.needLevelColorUpdate = nil
|
||||
end
|
||||
|
||||
-- healtbar: update colors
|
||||
local red, green, blue, _ = healthbar:GetStatusBarColor()
|
||||
if red ~= healthbar.wantR or green ~= healthbar.wantG or blue ~= healthbar.wantB then
|
||||
-- set reaction color
|
||||
-- healthbar: update colors
|
||||
local red, green, blue, _ = healthbar:GetStatusBarColor()
|
||||
-- reaction: 0 enemy ; 1 neutral ; 2 player ; 3 npc
|
||||
if red > 0.9 and green < 0.2 and blue < 0.2 then
|
||||
healthbar.reaction = 0
|
||||
healthbar:SetStatusBarColor(.9,.2,.3,0.8)
|
||||
healthbar.r, healthbar.g, healthbar.b, healthbar.a = .9, .2, .3, .8
|
||||
elseif red > 0.9 and green > 0.9 and blue < 0.2 then
|
||||
healthbar.reaction = 1
|
||||
healthbar:SetStatusBarColor(1,1,.3,0.8)
|
||||
healthbar.r, healthbar.g, healthbar.b, healthbar.a = 1, 1, .3, .8
|
||||
elseif ( blue > 0.9 and red == 0 and green == 0 ) then
|
||||
healthbar.reaction = 2
|
||||
healthbar:SetStatusBarColor(0.2,0.6,1,0.8)
|
||||
healthbar.r, healthbar.g, healthbar.b, healthbar.a = .2, .6, 1, .8
|
||||
elseif red == 0 and green > 0.99 and blue == 0 then
|
||||
healthbar.reaction = 3
|
||||
healthbar:SetStatusBarColor(0.6,1,0,0.8)
|
||||
healthbar.r, healthbar.g, healthbar.b, healthbar.a = .6, 1, 0, .8
|
||||
end
|
||||
|
||||
healthbar.wantR, healthbar.wantG, healthbar.wantB = healthbar:GetStatusBarColor()
|
||||
this.needClassColorUpdate = true
|
||||
this.needBasicColorUpdate = nil
|
||||
end
|
||||
|
||||
-- add class colors
|
||||
if this.needClassColorUpdate and pfUI.nameplates.targets[unitname] == "OK" then
|
||||
-- show class names?
|
||||
if this.needClassColorUpdate and uplayer and uclass then
|
||||
if healthbar.reaction == 0 then
|
||||
if C.nameplates["enemyclassc"] == "1"
|
||||
and pfUI.nameplates.players[unitname]
|
||||
and pfUI.nameplates.players[unitname]["class"]
|
||||
and RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]]
|
||||
then
|
||||
healthbar:SetStatusBarColor(
|
||||
RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].r,
|
||||
RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].g,
|
||||
RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].b,
|
||||
0.9)
|
||||
if C.nameplates["enemyclassc"] == "1" and RAID_CLASS_COLORS[uclass] then
|
||||
local color = RAID_CLASS_COLORS[uclass]
|
||||
healthbar.r, healthbar.g, healthbar.b, healthbar.a = color.r, color.g, color.b, .9
|
||||
end
|
||||
elseif healthbar.reaction == 2 then
|
||||
if C.nameplates["friendclassc"] == "1"
|
||||
and pfUI.nameplates.players[unitname]
|
||||
and pfUI.nameplates.players[unitname]["class"]
|
||||
and RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]]
|
||||
then
|
||||
healthbar:SetStatusBarColor(
|
||||
RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].r,
|
||||
RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].g,
|
||||
RAID_CLASS_COLORS[pfUI.nameplates.players[unitname]["class"]].b,
|
||||
0.9)
|
||||
if C.nameplates["friendclassc"] == "1" and RAID_CLASS_COLORS[uclass] then
|
||||
local color = RAID_CLASS_COLORS[uclass]
|
||||
healthbar.r, healthbar.g, healthbar.b, healthbar.a = color.r, color.g, color.b, .9
|
||||
end
|
||||
end
|
||||
|
||||
healthbar.wantR, healthbar.wantG, healthbar.wantB = healthbar:GetStatusBarColor()
|
||||
this.needClassColorUpdate = nil
|
||||
end
|
||||
|
||||
-- color changes are done within the C-API, we need to overwrite on each paint
|
||||
healthbar:SetStatusBarColor(healthbar.r, healthbar.g, healthbar.b, healthbar.a)
|
||||
|
||||
-- name color
|
||||
local red, green, blue, _ = name:GetTextColor()
|
||||
if red > 0.99 and green == 0 and blue == 0 then
|
||||
|
||||
Reference in New Issue
Block a user