Code:
-- Nephilist Nameplates v1.0
-- by lieandswell / Neph <Nephthys @ Hyjal-US>
local function NephilistTest(input)
if ( input ) then
DEFAULT_CHAT_FRAME:AddMessage(input);
else
DEFAULT_CHAT_FRAME:AddMessage("Test");
end
end
-- Local copies of global variables and often-used functions
local _G = _G;
local WorldFrame = WorldFrame;
local string = string;
local function utf8sub(string, i, dots)
local bytes = string:len()
if bytes <= i then
return string
else
local len, pos = 0, 1
while pos <= bytes do
len = len + 1
local c = string:byte(pos)
if c > 0 and c <= 127 then
pos = pos + 1
elseif c >= 194 and c <= 223 then
pos = pos + 2
elseif c >= 224 and c <= 239 then
pos = pos + 3
elseif c >= 240 and c <= 244 then
pos = pos + 4
end
if len == i then break end
end
if len == i and pos <= bytes then
return string:sub(1, pos - 1)..'*'
else
return string
end
end
end
-- AddOn variables
local newNamePlates = {};
local FONT = 'Interface\\AddOns\\NephilistNameplates\\ROADWAY.ttf'
local NAMEPLATE_SCALE = 1;
local FONT_SIZE = 14;
local NONTARGET_ALPHA = 0.5;
local BAR_BORDER = 2;
local HEALTHBAR_WIDTH = 130; -- Default nameplate width is ~130
local HEALTHBAR_HEIGHT = 4;
local HEALTHBAR_SIZE = {HEALTHBAR_WIDTH, HEALTHBAR_HEIGHT};
local CASTBAR_WIDTH = HEALTHBAR_WIDTH -15;
local CASTBAR_HEIGHT = HEALTHBAR_HEIGHT;
local CASTBAR_SIZE = {CASTBAR_WIDTH, CASTBAR_HEIGHT};
local RED = {0.7, 0.1, 0.1, 1};
local YELLOW = {0.7, 0.7, 0.1, 1};
local GREEN = {0.1, 0.6, 0.1, 1};
local BLUE = {0.1, 0.2, 0.7, 1};
local LVLC = {0, 0, 0};
local trash = CreateFrame("Frame");
trash:Hide();
local function ProcessOldNamePlate(namePlate)
namePlate.nameFrame = namePlate.NameContainer;
namePlate.name = namePlate.NameContainer.NameText;
namePlate.barFrame = namePlate.ArtContainer;
namePlate.border = namePlate.ArtContainer.Border;
namePlate.oldHighlight = namePlate.ArtContainer.Highlight;
namePlate.level = namePlate.ArtContainer.LevelText;
namePlate.raidIcon = namePlate.ArtContainer.RaidTargetIcon;
namePlate.eliteDragon = namePlate.ArtContainer.EliteIcon;
namePlate.threatTexture = namePlate.ArtContainer.AggroWarningTexture;
namePlate.bossIcon = namePlate.ArtContainer.HighLevelIcon;
namePlate.healthBar = namePlate.ArtContainer.HealthBar;
namePlate.healthBar.barTexture = namePlate.healthBar:GetRegions();
namePlate.castBar = namePlate.ArtContainer.CastBar;
namePlate.castBar.barTexture = namePlate.castBar:GetRegions();
namePlate.castBar.border = namePlate.ArtContainer.CastBarBorder;
namePlate.castBar.spellIcon = namePlate.ArtContainer.CastBarSpellIcon;
namePlate.castBar.shield = namePlate.ArtContainer.CastBarFrameShield;
namePlate.castBar.spellName = namePlate.ArtContainer.CastBarText;
namePlate.castBar.nameShadow = namePlate.ArtContainer.CastBarTextBG;
-- Reuse some elements of old nameplate
namePlate.healthBar:SetParent(namePlate.newPlate);
namePlate.castBar:SetParent(namePlate.newPlate);
namePlate.raidIcon:SetParent(namePlate.healthBar);
-- namePlate.highlight:SetParent(namePlate.newPlate);
-- Nameplates are secure and Hide() will taint, so...
-- Reparent text frames we don't need/want so they don't get shown
namePlate.nameFrame:SetParent(trash);
namePlate.level:SetParent(trash);
-- Hide unused textures with SetTexture(nil)
namePlate.border:SetTexture(nil);
namePlate.oldHighlight:SetTexture(nil);
namePlate.threatTexture:SetTexture(nil);
namePlate.castBar.border:SetTexture(nil);
namePlate.castBar.nameShadow:SetTexture(nil);
end
local function MakeNewHealthBar(namePlate)
local healthBar = namePlate.healthBar;
healthBar:SetStatusBarTexture("Interface\\AddOns\\NephilistNamePlates\\NephilistBarClean");
-- HealthBar Size and position set in NamePlate_OnShow()
local healthBarBackground = healthBar:CreateTexture(nil, "ARTWORK", nil, -5);
healthBarBackground:SetTexture("Interface\\AddOns\\NephilistNamePlates\\NephilistBarClean");
healthBarBackground:SetVertexColor(unpack(LVLC));
healthBarBackground:SetWidth(HEALTHBAR_WIDTH + 2 * BAR_BORDER);
healthBarBackground:SetHeight(HEALTHBAR_HEIGHT + 2 * BAR_BORDER);
healthBarBackground:SetPoint("CENTER");
local newName = healthBar:CreateFontString(nil, "LOW", "GameFontNormal");
newName:SetFont(FONT, FONT_SIZE,'THINOUTLINE');
newName:SetPoint("BOTTOMLEFT", healthBar, "BOTTOMLEFT", 0, 0);
namePlate.newName = newName;
local LVL = healthBar:CreateFontString(nil, "LOW", "GameFontNormal");
LVL:SetFont(FONT, FONT_SIZE-4,'THINOUTLINE');
LVL:SetPoint("TOPRIGHT", healthBarBackground, "BOTTOMRIGHT", 0, -2);
namePlate.LVL = LVL;
local raidIcon = namePlate.raidIcon;
raidIcon:SetHeight(6 * HEALTHBAR_HEIGHT);
raidIcon:SetWidth(6 * HEALTHBAR_HEIGHT);
raidIcon:ClearAllPoints();
raidIcon:SetPoint("BOTTOM", healthBar, "TOP", 0, 24);
local highlight = healthBar:CreateTexture(nil, "ARTWORK", nil, -6);
highlight:SetTexture("Interface\\AddOns\\NephilistNamePlates\\NephilistBarClean");
highlight:SetVertexColor(1, 1, 1);
highlight:SetWidth(HEALTHBAR_WIDTH + 3 * BAR_BORDER);
highlight:SetHeight(HEALTHBAR_HEIGHT + 3 * BAR_BORDER);
-- highlight:ClearAllPoints();
highlight:SetPoint("CENTER");
namePlate.highlight = highlight;
end
local function MakeNewCastBar(nameplate)
local castBar = nameplate.castBar
local spellIcon = nameplate.castBar.spellIcon
castBar:SetStatusBarTexture("Interface\\AddOns\\NephilistNamePlates\\NephilistBarClean");
castBar.point = {"BOTTOMRIGHT", nameplate.healthBar, "TOPRIGHT", 0, 15};
castBar.size = CASTBAR_SIZE;
-- castBar.size and castBar.point used to set size and position in CastBar_OnShow()
local castBarBackground = castBar:CreateTexture(nil, "ARTWORK", nil, -2);
castBarBackground:SetTexture("Interface\\AddOns\\NephilistNamePlates\\NephilistBarClean");
castBarBackground:SetVertexColor(0, 0, 0);
castBarBackground:SetWidth(CASTBAR_WIDTH + 2 * BAR_BORDER);
castBarBackground:SetHeight(CASTBAR_HEIGHT + 2 * BAR_BORDER);
castBarBackground:SetPoint("CENTER");
spellIcon:ClearAllPoints();
--spellIcon:SetFrameLevel("LOW");
spellIcon:SetWidth(CASTBAR_HEIGHT * (BAR_BORDER + 1));
spellIcon:SetHeight(CASTBAR_HEIGHT * (BAR_BORDER + 1));
spellIcon:SetPoint("BOTTOMRIGHT", castBar, "BOTTOMLEFT", -4, 0);
local SpellIconBackground = castBar:CreateTexture(nil, "MEDIUM", nil, -2);
SpellIconBackground:SetTexture("Interface\\AddOns\\NephilistNamePlates\\SpellIcon");
SpellIconBackground:SetVertexColor(0, 0, 0);
SpellIconBackground:SetWidth((CASTBAR_HEIGHT * (BAR_BORDER + 1)) + 1);
SpellIconBackground:SetHeight((CASTBAR_HEIGHT * (BAR_BORDER + 1)) + 1);
SpellIconBackground:SetPoint("CENTER", castBar.spellIcon, "CENTER", 0, 0);
castBar.spellName:SetFont(FONT, FONT_SIZE,'THINOUTLINE');
castBar.spellName:ClearAllPoints();
castBar.spellName:SetPoint("BOTTOMLEFT");
--castBar.spellName = utf8sub(castBar.spellName:GetText(), 27, false);
castBar.shield:SetDrawLayer("OVERLAY", -6);
castBar.shield:SetTexture("Interface\\HELPFRAME\\HelpIcon-AccountSecurity");
castBar.shield:SetDesaturated(true);
-- Shield size and position set in CastBar_OnShow()
end
local function NamePlate_OnShow(namePlate)
local healthBar = namePlate.healthBar;
healthBar:SetWidth(HEALTHBAR_WIDTH);
healthBar:SetHeight(HEALTHBAR_HEIGHT);
healthBar:ClearAllPoints();
healthBar:SetPoint("CENTER", namePlate.barFrame, "CENTER", 0, 0);
-- Mute colors
local red, green, blue, alpha = healthBar.barTexture:GetVertexColor();
--[[
if ( red > 0.99 ) and ( green < 0.01 ) and ( blue < 0.01 ) then -- Red
healthBar.barTexture:SetVertexColor(0.7, 0.1, 0.1, 1);
elseif ( red > 0.99 ) and ( green > 0.99 ) and ( blue < 0.01 ) then -- Yellow
healthBar.barTexture:SetVertexColor(0.7, 0.7, 0.1, 1);
elseif ( red < 0.01 ) and ( green > 0.99 ) and ( blue < 0.01 ) then -- Green
healthBar.barTexture:SetVertexColor(0.1, 0.6, 0.1, 1);
elseif ( red < 0.01 ) and ( green < 0.01 ) and ( blue > 0.99 ) then -- Blue
healthBar.barTexture:SetVertexColor(0.1, 0.2, 0.7, 1);
end
--]]
if ( red > 0.99 ) and ( green < 0.01 ) and ( blue < 0.01 ) then -- Red
healthBar.barTexture:SetVertexColor(unpack(RED));
elseif ( red > 0.99 ) and ( green > 0.99 ) and ( blue < 0.01 ) then -- Yellow
healthBar.barTexture:SetVertexColor(unpack(YELLOW));
elseif ( red < 0.01 ) and ( green > 0.99 ) and ( blue < 0.01 ) then -- Green
healthBar.barTexture:SetVertexColor(unpack(GREEN));
elseif ( red < 0.01 ) and ( green < 0.01 ) and ( blue > 0.99 ) then -- Blue
healthBar.barTexture:SetVertexColor(unpack(BLUE));
end
local name = utf8sub(namePlate.name:GetText(), 27, false) or "Unknown";
namePlate.newName:SetText(name);
namePlate.newName:SetTextColor(0.8, 0.8, 0.8);
local level, elite = tonumber(namePlate.level:GetText()), namePlate.eliteDragon:IsShown()
if namePlate.bossIcon:IsShown() then
namePlate.LVL:SetText("Boss")
elseif elite then
namePlate.LVL:SetText(level..(elite and "+" or ""))
else
namePlate.LVL:SetText(level);
end
namePlate.LVL:SetTextColor(0.8, 0.8, 0.8);
namePlate.eliteDragon:SetTexture(nil);
namePlate.bossIcon:SetTexture(nil);
local scale = namePlate.barFrame:GetScale();
if (scale > 0.9) then
namePlate.newPlate:SetScale(NAMEPLATE_SCALE);
else
namePlate.newPlate:SetScale(0.7 * NAMEPLATE_SCALE);
end
namePlate.newPlate:Show();
end
local function NamePlate_OnHide(namePlate)
namePlate.newPlate:Hide();
end
local function CastBar_OnShow(castBar)
castBar:SetSize(unpack(castBar.size));
castBar:ClearAllPoints();
castBar:SetPoint(unpack(castBar.point));
if ( castBar.shield:IsShown() ) then
castBar.shield:ClearAllPoints();
castBar.shield:SetPoint("CENTER", castBar.spellIcon, "CENTER", 0, 0);
castBar.shield:SetWidth(2.4 * CASTBAR_HEIGHT);
castBar.shield:SetHeight(2.4 * CASTBAR_HEIGHT);
castBar.shield:SetVertexColor(0.8, 0.8, 0.8, 1);
castBar:SetStatusBarColor(0.35, 0.35, 0.35);
else
castBar:SetStatusBarColor(0.77, 0.77, 0.77);
end
end
-- Instead of anchoring new nameplate directly to Blizzard nameplate, track nameplate position
-- with SetPoint(). Attaching frames to default nameplates will kill your framerate.
local function PositionNamePlate(namePlate)
local positionFrame = CreateFrame("Frame", nil, namePlate.newPlate);
positionFrame:SetPoint("BOTTOMLEFT", WorldFrame);
positionFrame:SetPoint("TOPRIGHT", namePlate, "CENTER");
positionFrame:SetScript("OnSizeChanged", function(self, x, y)
if ( namePlate:IsShown() ) then
namePlate.newPlate:Hide(); -- Supposedly increases framerate. Not convinced.
namePlate.newPlate:SetPoint("TOP", WorldFrame, "BOTTOMLEFT", x, y);
namePlate.newPlate:Show();
end
end)
end
local function MakeNewNamePlate(namePlate)
namePlate.newPlate = CreateFrame("Frame", nil, WorldFrame);
newNamePlates[namePlate] = namePlate.newPlate;
ProcessOldNamePlate(namePlate);
MakeNewHealthBar(namePlate);
MakeNewCastBar(namePlate);
NamePlate_OnShow(namePlate);
if ( not namePlate:IsShown() ) then namePlate.newPlate:Hide(); end
CastBar_OnShow(namePlate.castBar);
namePlate:HookScript("OnShow", NamePlate_OnShow);
namePlate:HookScript("OnHide", NamePlate_OnHide);
namePlate.castBar:HookScript("OnShow", CastBar_OnShow);
namePlate.castBar:HookScript("OnValueChanged", CastBar_OnShow);
-- Sometimes the castBar isn't getting redrawn. Why not? Something to do with channeled spells.
PositionNamePlate(namePlate);
end
local numChildren = -1;
WorldFrame:HookScript("OnUpdate", function(self, elapsed)
-- Detect new nameplates and process any we haven't already
local currentChildren = select("#", WorldFrame:GetChildren());
if ( numChildren ~= currentChildren ) then
for i = 1, currentChildren do
local namePlate = select(i, WorldFrame:GetChildren());
local name = namePlate:GetName();
if ( name and string.match(name, "^NamePlate%d+$") and not newNamePlates[namePlate] ) then
MakeNewNamePlate(namePlate);
end
end
numChildren = currentChildren;
end
for namePlate, newPlate in next, newNamePlates do
if ( namePlate:IsShown() ) then
-- Fade out unselected nameplates
if ( namePlate:GetAlpha() > 0.99 ) then
newPlate:SetAlpha(1);
else
newPlate:SetAlpha(NONTARGET_ALPHA);
end
-- Show/hide highlight
if ( namePlate.oldHighlight:IsShown() ) then
namePlate.highlight:Show();
else
namePlate.highlight:Hide();
end
end
end
end)
that the whole code of the nameplate addon im modifying for personal use.