Hi Briskman3000,
Thank you for your suggestion and example code
Here's my edited version of
Experience.lua:
Lua Code:
local LSM = LibStub("LibSharedMedia-3.0");
local font = LSM:Fetch("font", "MeatEdition");
local E, L = unpack(select(2, ...));
local Experience = E:NewModule("Experience", "AceEvent-3.0");
Experience.Frame = CreateFrame("Frame", nil, UIParent);
Experience.Frame:SetMovable(true);
Experience.Frame:EnableMouse(true);
Experience.Frame:RegisterForDrag("LeftButton");
Experience.Frame:SetScript("OnDragStart", Experience.Frame.StartMoving);
Experience.Frame:SetScript("OnDragStop", Experience.Frame.StopMovingOrSizing);
Experience.Frame:SetSize(280, 50);
Experience.Frame:SetTemplate(true); -- custom function
local r, g, b = Experience.Frame.template:GetBackdropColor();
Experience.Frame.template:SetBackdropColor(r, g, b, 0.7);
local _, class = UnitClass("player");
local color = RAID_CLASS_COLORS[class];
Frame.NameText = Experience.Frame:CreateFontString(nil, "OVERLAY");
Frame.NameText:SetFont(font, 16, "OUTLINE");
Frame.NameText:SetPoint("TOP", 0, -5);
Frame.NameText:SetTextColor(color.r, color.g, color.b);
Frame.NameText:SetText("");
Frame.ExpText = Experience.Frame:CreateFontString(nil, "OVERLAY");
Frame.ExpText:SetFont(font, 14, "OUTLINE");
Frame.ExpText:SetPoint("BOTTOM", 0, 5);
Frame.ExpText:SetTextColor(1, 1, 1);
Frame.ExpText:SetFormattedText("Level: %d, Exp: %d / %d (%.2f%%)", 0, 0, 0, 0);
local function CommaValue(value)
local left, num, right = string.match(value, '^([^%d]*%d)(%d*)(.-)$');
return left .. (num:reverse():gsub('(%d%d%d)', '%1,'):reverse()) .. right;
end
function Experience:UpdateText()
local level = UnitLevel("player");
local curXP, maxXP = UnitXP("player"), UnitXPMax("player");
local perXP = curXP / maxXP * 100;
self.Frame.NameText:SetText(UnitName("player"));
self.Frame.ExpText:SetFormattedText("|cffeda900Level:|r %d, |cffeda900Exp:|r %s / %s (%.2f%%)", level, CommaValue(curXP), CommaValue(maxXP), perXP);
end
function Experience:PLAYER_LOGIN()
local point, relativeFrame, relativePoint, ofsx, ofsy;
if E.db.pos then
point, relativeFrame, relativePoint, ofsx, ofsy = unpack(E.db.pos);
else
point, relativeFrame, relativePoint, ofsx, ofsy = "CENTER", "UIParent", "CENTER", 0, 200;
end
self.Frame:SetPoint(point, relativeFrame, relativePoint, ofsx, ofsy);
self:UpdateText();
end
function Experience:PLAYER_XP_UPDATE()
self:UpdateText();
end
function Experience:PLAYER_LOGOUT()
local point, relativeFrame, relativePoint, ofsx, ofsy = self.Frame:GetPoint();
if relativeFrame == UIParent then
relativeFrame = "UIParent";
end
E.db.pos = {
point,
relativeFrame,
relativePoint,
ofsx,
ofsy,
}
end
Experience:RegisterEvent("PLAYER_LOGIN");
Experience:RegisterEvent("PLAYER_XP_UPDATE");
Experience:RegisterEvent("PLAYER_LOGOUT");
I tried to get rid of ADDON_LOADED function, but once I remove that function, it won't be able to access db as it recognize db as 'nil'
EDIT: Got rid of ADDON_LOADED function and immigrated stuffs into PLAYER_LOGIN function due to db issue.