Add positioning and coloring units

This commit is contained in:
robin 2021-04-29 12:19:17 +02:00
parent 647adb795a
commit 9449a22a73
2 changed files with 81 additions and 0 deletions

View File

@ -5,6 +5,7 @@
<Script file="broker.lua"/>
<Script file="chat.lua"/>
<Script file="cvars.lua"/>
<Script file="units.lua"/>
<Script file="core.lua"/>
<Script file="litepanels.lua"/>
<Script file="layout.lua"/>

80
units.lua Normal file
View File

@ -0,0 +1,80 @@
local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local events = child['events']
local ClassColorUnits = {
["target"] = {
["name"] = "TargetFrame",
["back"] = "TargetFrame",
["x-offset"] = -104,
["y-offset"] = 60,
["x-offset2"] = 6,
["y-offset2"] = -22,
},
["player"] = {
["name"] = "PlayerFrame",
["back"] = "PlayerFrameBackground",
["x-offset"] = 0,
["y-offset"] = 22,
["x-offset2"] = 0,
["y-offset2"] = 0,
},
["focus"] = {
["name"] = "FocusFrame",
["back"] = "FocusFrame",
["x-offset"] = -104,
["y-offset"] = 60,
["x-offset2"] = 6,
["y-offset2"] = -22,
},
}
local function updateClassColor(unit)
if(unit and UnitExists(unit)) then
local _,class = UnitClass(unit)
if(class and RAID_CLASS_COLORS[class]) then
if(ClassColorUnits[unit]) then
local uf = _G[ClassColorUnits[unit]['name']]
local bg = _G[ClassColorUnits[unit]['back']]
if(not uf['unitClassColorBack']) then
uf['unitClassColorBack'] = uf:CreateTexture(nil, "ARTWORK")
uf['unitClassColorBack']:SetPoint("TOPLEFT", bg, ClassColorUnits[unit]['x-offset2'], ClassColorUnits[unit]['y-offset2'])
uf['unitClassColorBack']:SetPoint("BOTTOMRIGHT", bg, ClassColorUnits[unit]['x-offset'], ClassColorUnits[unit]['y-offset'])
uf['unitClassColorBack']:SetTexture("Interface\\TargetingFrame\\UI-StatusBar")
end
local col = RAID_CLASS_COLORS[class]
if(not UnitIsPlayer(unit)) then
uf['unitClassColorBack']:SetVertexColor(0, 0, 0, 0)
else
uf['unitClassColorBack']:SetVertexColor(col['r'], col['g'], col['b'],1)
end
end
end
end
end
function events:PLAYER_TARGET_CHANGED()
updateClassColor("target")
end
function events:PLAYER_FOCUS_CHANGED()
updateClassColor("focus")
end
local init = {
Setup = function(self, childName, event)
if(PlayerFrame:IsUserPlaced()) then
PlayerFrame:SetMoveable(false)
else
PlayerFrame:SetUserPlaced(true)
PlayerFrame:ClearAllPoints()
PlayerFrame:SetPoint("RIGHT", UIParent, "CENTER", 0, -140)
end
if(not TargetFrame:IsUserPlaced()) then
TargetFrame:SetUserPlaced(true)
TargetFrame:ClearAllPoints()
TargetFrame:SetPoint("TOPLEFT", PlayerFrame, "TOPRIGHT",0,0)
else
TargetFrame:SetMoveable(false)
end
updateClassColor("player")
end
}
addon.RegisterCallback(init, format("Init%s", childName), 'Setup', childName)