Quantcast
Need help with Nameplate Castbar - WoWInterface
Thread Tools Display Modes
12-18-15, 05:57 AM   #1
Basso
A Fallenroot Satyr
 
Basso's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 22
Need help with Nameplate Castbar

I'm working on a little nameplate addon but i got two problems left i can't solve at the moment.

Code:
spellIcon:ClearAllPoints(); 
	spellIcon:SetWidth(CASTBAR_HEIGHT * (BAR_BORDER + 1)); 
	spellIcon:SetHeight(CASTBAR_HEIGHT * (BAR_BORDER + 1)); 
	spellIcon:SetPoint("BOTTOMRIGHT", castBar, "BOTTOMLEFT", -4, 0);
	
	
	local SpellIconOverlay = castBar:CreateTexture(nil, "MEDIUM", nil, -2); 
	SpellIconOverlay:SetTexture("Interface\\AddOns\\Test\\SpellIcon"); 
	SpellIconOverlay:SetVertexColor(0, 0, 0); 
	SpellIconOverlay:SetWidth((CASTBAR_HEIGHT * (BAR_BORDER + 1)) + 1); 
	SpellIconOverlay:SetHeight((CASTBAR_HEIGHT * (BAR_BORDER + 1)) + 1); 
	SpellIconOverlay:SetPoint("CENTER", castBar.spellIcon, "CENTER", 0, 0);
This is the positioning of the Castbar Spell Icon and this works so far, my Problem is the overlay always
stays behind the actual spell icon, and if i try to us :SetFrameLevel("LOW") on the Spellicon i get bombed
with this error:
Code:
Message: ...e\AddOns\Test\Test.lua:173: attempt to call method 'SetFrameLevel' (a nil value)
My idea was that maybe the spell icon stuff is further splitted in a table but i can't find a list of it.


the second Problem is the spell name, i want to shorten it if its gets longer then a specific amount
of letters, i have a function for that which i use on the name of the unit that works fine, but i can't use
it on the CastbarText, at the moment it seems to me that it is the same problem as above.

same attempt like on the name:
Code:
castBar.spellName = utf8sub(castBar.spellName:GetText(), 27, false);
the error:
Code:
Message: ...e\AddOns\Test\Test.lua:18: attempt to index local 'string' (a nil value)
Anyone knows a solution?
Or simply has a list of the content of these Tables i seem to dumb to find ?

Thanks,
Basso
  Reply With Quote
12-18-15, 09:24 AM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
We need to see your code.
  Reply With Quote
12-18-15, 09:59 AM   #3
Basso
A Fallenroot Satyr
 
Basso's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 22
Originally Posted by Resike View Post
We need to see your code.
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.
  Reply With Quote
12-18-15, 10:09 AM   #4
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Your first error is because you try to call SetFrameLevel on a texture and it's only works on frames.

The second error could be caused because some spells have no names or you call it too early.
  Reply With Quote
12-18-15, 12:59 PM   #5
Basso
A Fallenroot Satyr
 
Basso's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 22
Originally Posted by Resike View Post
Your first error is because you try to call SetFrameLevel on a texture and it's only works on frames.

The second error could be caused because some spells have no names or you call it too early.
i could sort out the second error now, the shortening works fine now.
thanks for your hint.

but im at my wits end with the fucking border
but without it it looks somewhat stupid, i love clean black borders
green one for better visibility as attachment.

is there any simple way to put my border overlay over the spellIcon im overlooking ?
creating a frame over it is to much of code and workarounds for that, because i also
need to show and hide it dynamically.
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_121815_195722.png
Views:	85
Size:	21.5 KB
ID:	8673  

Last edited by Basso : 12-18-15 at 01:02 PM.
  Reply With Quote
12-18-15, 01:16 PM   #6
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Basso View Post
i could sort out the second error now, the shortening works fine now.
thanks for your hint.

but im at my wits end with the fucking border
but without it it looks somewhat stupid, i love clean black borders
green one for better visibility as attachment.

is there any simple way to put my border overlay over the spellIcon im overlooking ?
creating a frame over it is to much of code and workarounds for that, because i also
need to show and hide it dynamically.
I could suggest you to use one of these icon packs:

http://www.wowinterface.com/downloads/info19844

That would be the easiest way.
  Reply With Quote
12-18-15, 02:38 PM   #7
Basso
A Fallenroot Satyr
 
Basso's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 22
Originally Posted by Resike View Post
I could suggest you to use one of these icon packs:

http://www.wowinterface.com/downloads/info19844

That would be the easiest way.
That works for me thanks^^
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need help with Nameplate Castbar

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off