Hey!
I’m newbie in programming but I want to recreate good old GypsyMod Unit_Frames.
I’m asking for a help if anyone here knows something about WoW addons dev.
I can’t get whats wrong in code, but it looks this way:
https:// i.imgur .com/LwyP1wk.png
Full addon:
https:// www.dropbox. com/s/vsy6j3gse3jwu2s/Gypsy.rar?dl=0
.lua file:
--[[
Gypsy_PlayerFrame.lua
GypsyVersion++2004.11.13++
]]
– ** PLAYER FRAME FUNCTIONS ** –
function Gypsy_PlayerFrameOnLoad(self)
– Health and mana registrations
self:RegisterEvent(“UNIT_HEALTH”);
self:RegisterEvent(“UNIT_MAXHEALTH”);
self:RegisterEvent(“UNIT_POWER”);
– If a druid shapeshifts, the bar changes from rage/mana/energy/etc
self:RegisterEvent(“UNIT_DISPLAYPOWER”);
– Experience registrations
self:RegisterEvent(“PLAYER_XP_UPDATE”);
self:RegisterEvent(“UPDATE_EXHAUSTION”);
self:RegisterEvent(“PLAYER_LEVEL_UP”);
– Register for variable loading to run our configuration registrations
self:RegisterEvent(“PLAYER_ENTERING_WORLD”);
self:RegisterEvent(“VARIABLES_LOADED”);
– Combat events for coloring the player name
self:RegisterEvent(“PLAYER_ENTER_COMBAT”);
self:RegisterEvent(“PLAYER_LEAVE_COMBAT”);
– Vehicle
self:RegisterEvent(“UNIT_ENTERED_VEHICLE”);
self:RegisterEvent(“UNIT_EXITED_VEHICLE”);
Gypsy_ShowPlayerHealth();
Gypsy_ShowPlayerPower();
Gypsy_UpdateTypeMana();
end
function Gypsy_PlayerFrameOnEvent(self, event)
– Added unit_health and unit_mana (ish) event handlers. Anytime either of these values change, we need to update.
if ( event == “UNIT_HEALTH” or event == “UNIT_MAXHEALTH”) then
Gypsy_ShowPlayerHealth();
return;
end
– Also keep in mind, “mana” is really mana, energy, focus, or rage, so we need to watch all of those.
if ( event == “UNIT_POWER”) then
Gypsy_ShowPlayerPower();
return;
end
– Color the player name text red when entering combat
if ( event == “PLAYER_ENTER_COMBAT” or event == “PLAYER_LEAVE_COMBAT”) then
Gypsy_UpdateAttackState(self:GetParent());
return;
end
– Added unit exp handles to update the player displayed experience numbers.
if ( event == “PLAYER_XP_UPDATE” or event == “UPDATE_EXHAUSTION” or event == “PLAYER_LEVEL_UP”) then
Gypsy_ShowPlayerExp();
return;
end
– if the player power change (druid shapeshifts, …)
if ( event == “UNIT_DISPLAYPOWER”) then
Gypsy_UpdateTypeMana();
return;
end
if ( event == ‘UNIT_ENTERED_VEHICLE’ or event == ‘UNIT_EXITED_VEHICLE’) then
Gypsy_ShowPlayerHealth();
Gypsy_ShowPlayerPower();
Gypsy_UpdateTypeMana();
Gypsy_XPBarSlashHanlder(Gypsy_XPBar.show);
return;
end
-- When variables load, run our options setup
if ( event == "VARIABLES_LOADED") then
if not Gypsy_XPBar then
Gypsy_XPBar = { };
Gypsy_XPBar.show = 1;
end
-- Register slash commands
SlashCmdList["GYPSY_XPBAR"] = Gypsy_XPBarSlashHanlder ;
SLASH_GYPSY_XPBAR1 = "/unitbarxpbar";
SLASH_GYPSY_XPBAR2 = "/ubxpbar";
return;
end
if ( event == "PLAYER_ENTERING_WORLD" ) then
-- We need to do an initial display of all our values when the player first logs in.
Gypsy_ShowPlayerHealth();
Gypsy_ShowPlayerPower();
Gypsy_UpdateTypeMana();
Gypsy_ShowPlayerExp();
Gypsy_XPBarSlashHanlder(Gypsy_XPBar.show);
return;
end
end
– ** LOCAL FUNCTIONS ** –
– Update player name depending on attack state
local function Gypsy_UpdateAttackState(self)
if (self.inCombat and self.OnHateList or self.inCombat) then
PlayerName:SetTextColor(1, 0, 0);
else
PlayerName:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
end
end
– ** TEXT DISPLAY FUNCTIONS ** –
local function Gypsy_ShowPlayerHealth()
local cur, max, text, r, g, b = Gypsy.getCurMaxColor(“player”);
local value = ceil((cur / max)*100+100);
Gypsy_PlayerHealthText:SetText(text);
Gypsy_PlayerHealthPercent:SetText(value.."%");
Gypsy_PlayerHealthText:SetTextColor(r, g, b);
Gypsy_PlayerHealthPercent:SetTextColor(r, g, b);
end
local function Gypsy_ShowPlayerPower()
if (not UnitInVehicle(“player”)) then
Gypsy_PlayerManaText:SetText(UnitPower(“player”)…" / “…UnitPowerMax(“player”));
else
Gypsy_PlayerManaText:SetText(UnitPower(“vehicle”)…” / "…UnitPowerMax(“vehicle”));
end
end
local function Gypsy_UpdateTypeMana()
local powerType, powerTypeString;
if (not UnitInVehicle(“player”)) then
powerType, powerTypeString = UnitPowerType(“player”);
else
powerType, powerTypeString = UnitPowerType(“vehicle”);
end
local r = 0.0;
local g = 0.55;
local b = 1.0;
if ( powerType ~= 0) then
local info = PowerBarColor[powerType];
if ( not info ) then
– couldn’t find a power token entry…default to indexing by power type or just mana if we don’t have that either
info = PowerBarColor[“ENERGY”];
end
r = info.r;
g = info.g;
b = info.b;
end
Gypsy_PlayerManaText:SetTextColor(r, g, b);
end
local function Gypsy_ShowPlayerExp()
local currXP = UnitXP(“player”);
local nextXP = UnitXPMax(“player”);
local restXP = GetXPExhaustion();
local percent = ceil((currXP/nextXP) * 100)…"%";
if(restXP == nil) then
Gypsy_ExpAmount:SetText(percent);
Gypsy_PlayerFrameExpBar:SetStatusBarColor(1, 0, 0.4);
else
local str = format("(%s)", (tonumber(restXP) / 2));
Gypsy_ExpAmount:SetText(percent..str);
Gypsy_PlayerFrameExpBar:SetStatusBarColor(0, 0.6, 1);
end
end
– ** SLASH HANDLER FUNCTIONS ** –
local function Gypsy_XPBarSlashHanlder(msg)
msg = string.lower(msg);
if (msg == “yes” or msg == “1” or msg == “true” or msg == “show”) then
Gypsy_XPBar.show = 1;
Gypsy_ExpAmount:Show();
Gypsy_PlayerFrameExpBar:Show();
Gypsy_PlayerFrameBottom:Show();
PlayerFrameFlash:SetTexture(“Interface\AddOns\Gypsy\Art\Gypsy_PlayerFlashXp.tga”);
PlayerFrameFlash:SetTexCoord( 1, 0, 0, 1 );
elseif (msg == “no” or msg == “0” or msg == “false” or msg == “hide”) then
Gypsy_XPBar.show = 0;
Gypsy_ExpAmount:Hide();
Gypsy_PlayerFrameExpBar:Hide();
Gypsy_PlayerFrameBottom:Hide();
PlayerFrameFlash:SetTexture(“Interface\AddOns\Gypsy\Art\Gypsy_PlayerFlash.tga”);
PlayerFrameFlash:SetTexCoord( 1, 0, 0, 1 );
else
DEFAULT_CHAT_FRAME:AddMessage(“Valid parameters for: /unitxpbar /ubxpbar”, 1, 0.89, 0.01);
DEFAULT_CHAT_FRAME:AddMessage(" yes, true, show or 1 - Show Xp bar", 1, 1, 1);
DEFAULT_CHAT_FRAME:AddMessage(" no, false, hide or 0 - Hide Xp bar", 1, 1, 1);
end
end
– ** EXPERIENCE BAR FUNCTIONS ** –
function Gypsy_PlayerFrameExpBarOnLoad (self)
– Experience bar registrations
self:RegisterEvent(“PLAYER_XP_UPDATE”);
self:RegisterEvent(“PLAYER_LEVEL_UP”);
self:RegisterEvent(“PLAYER_ENTERING_WORLD”);
-- Can not be any higher, should not be lower
self:SetFrameLevel(0);
Gypsy_ShowPlayerExp();
end
function Gypsy_PlayerFrameExpBarOnEvent(self, event)
– Setup our experience bar when the player logs in, when experience changes, or when the player levels up
if (event == “PLAYER_XP_UPDATE” or event == “PLAYER_LEVEL_UP” or event == “PLAYER_ENTERING_WORLD”) then
local currXP = UnitXP(“player”);
local nextXP = UnitXPMax(“player”);
self:SetMinMaxValues(min(0, currXP), nextXP);
self:SetValue(currXP);
return;
end
end
.xml file:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">
<!-- Script file with text display functions and functions to move player frame and right click menu -->
<Script file="Gypsy_PlayerFrame.lua"/>
<!-- Frame displays hp, mana, and exp text, and graphic overlays, and runs needed scripting -->
<Frame name="$parentGypsy" parent="PlayerFrame">
<Scripts>
<OnLoad>Gypsy_PlayerFrameOnLoad(self);</OnLoad>
<OnEvent>Gypsy_PlayerFrameOnEvent(self, event);</OnEvent>
</Scripts>
<Layers>
<Layer level="BACKGROUND">
<!-- Dark shading for right side graphic, under health and mana -->
<Texture name="Gypsy_PlayerFrameRightBackground">
<Size>
<AbsDimension x="100" y="42"/>
</Size>
<Anchors>
<Anchor point="LEFT" relativeTo="PlayerFrame" relativePoint="RIGHT">
<Offset>
<AbsDimension x="-7" y="8"/>
</Offset>
</Anchor>
</Anchors>
<Color r="0" g="0" b="0" a="0.5"/>
</Texture>
</Layer>
</Layers>
<Frames>
<Frame setAllPoints="true">
<Frames>
<Frame setAllPoints="true">
<Layers>
<Layer level="OVERLAY">
<!-- Overlay graphic to frame health, hp percentage, and mana text -->
<Texture name="Gypsy_PlayerFrameRight" file="Interface\AddOns\Gypsy\Art\Gypsy_PlayerFrameRight.tga">
<Size>
<AbsDimension x="128" y="128"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT" relativeTo="PlayerFrame" relativePoint="TOPLEFT">
<Offset>
<AbsDimension x="220" y="-19"/>
</Offset>
</Anchor>
</Anchors>
</Texture>
<Texture name="Gypsy_PlayerFrameBottom" file="Interface\AddOns\Gypsy\Art\Gypsy_PlayerFrameBottom.tga">
<Size>
<AbsDimension x="256" y="128"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT" relativeTo="PlayerFrame" relativePoint="TOPLEFT">
<Offset>
<AbsDimension x="77" y="-60"/>
</Offset>
</Anchor>
</Anchors>
</Texture>
<!-- Player health text, 1234 / 1234 -->
<FontString name="Gypsy_PlayerHealthText" inherits="GameFontNormalSmall" text="Loading...">
<Size>
<AbsDimension x="100" y="10" />
</Size>
<Anchors>
<Anchor point="LEFT" relativeTo="PlayerFrame" relativePoint="TOPLEFT">
<Offset>
<AbsDimension x="228" y="-47"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
<!-- Player health percentage, 100% -->
<FontString name="Gypsy_PlayerHealthPercent" inherits="GameFontNormalSmall" text="Loading...">
<Size>
<AbsDimension x="107" y="10" />
</Size>
<Anchors>
<Anchor point="LEFT" relativeTo="PlayerFrame" relativePoint="TOPLEFT">
<Offset>
<AbsDimension x="228" y="-32"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
<!-- Player mana text, 1234 / 1234 -->
<FontString name="Gypsy_PlayerManaText" inherits="GameFontNormalSmall" text="Loading...">
<Size>
<AbsDimension x="100" y="10" />
</Size>
<Anchors>
<Anchor point="LEFT" relativeTo="PlayerFrame" relativePoint="TOPLEFT">
<Offset>
<AbsDimension x="235" y="-58"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
<!-- Player experience, CurrentXP / MaxXP (+RestedXPBonus) -->
<FontString name="Gypsy_ExpAmount" inherits="GameFontNormalSmall" text="Loading...">
<Size>
<AbsDimension x="150" y="10" />
</Size>
<Anchors>
<Anchor point="CENTER" relativeTo="Gypsy_PlayerFrameBottom" relativePoint="CENTER">
<Offset>
<AbsDimension x="0" y="53"/>
</Offset>
</Anchor>
</Anchors>
<Color r="1" g="1" b="0"/>
</FontString>
</Layer>
</Layers>
</Frame>
<StatusBar name="Gypsy_PlayerFrameExpBar" inherits="TextStatusBar">
<Size>
<AbsDimension x="250" y="12"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT" relativeTo="Gypsy_PlayerFrameBottom" relativePoint="TOPLEFT">
<Offset>
<AbsDimension x="0" y="-5"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>Gypsy_PlayerFrameExpBarOnLoad(self);</OnLoad>
<OnEvent>Gypsy_PlayerFrameExpBarOnEvent(self, event);</OnEvent>
</Scripts>
<BarTexture file="Interface\TargetingFrame\UI-StatusBar"/>
<BarColor r="0.5" g="0.5" b="0"/>
<Frames>
<Frame name="Gypsy_PlayerFrameExpBarBackground">
<Layers>
<Layer level="BACKGROUND">
<!-- Dark shading for the bottom graphic, under experince -->
<Texture name="Gypsy_PlayerFrameLowerBackground1">
<Size>
<AbsDimension x="257" y="12"/>
</Size>
<Anchors>
<Anchor point="BOTTOM" relativeTo="PlayerFrame">
<Offset>
<AbsDimension x="84" y="23"/>
</Offset>
</Anchor>
</Anchors>
<Color r="0" g="0" b="0" a="0.5"/>
</Texture>
<Texture name="Gypsy_PlayerFrameLowerBackground2">
<Size>
<AbsDimension x="10" y="6"/>
</Size>
<Anchors>
<Anchor point="BOTTOM" relativeTo="PlayerFrame">
<Offset>
<AbsDimension x="-28" y="22"/>
</Offset>
</Anchor>
</Anchors>
<Color r="0" g="0" b="0" a="0.5"/>
</Texture>
</Layer>
</Layers>
</Frame>
</Frames>
</StatusBar>
</Frames>
</Frame>
</Frames>
</Frame>
/cheer!