A Chromatic Dragonspawn
Join Date: May 2011
Posts: 162
|
trying to make an XP bar the way i want it
ok i am having issues herethe functions all work fine and all
but what i am trying to do here is
make the XP bar Primary
inside of a frame named XPFrame
now i have a mathmatic formula that sizes that frame so i include it here, yay the formula works, however my darn xp bar dont switch to a Rep bar at max level
also i want a little mouse interaction of on shift right click it switches to Rep bar, also i want to have it auto switch at max level
here is my code, please for god sake some one help me im bout to loose my mind, basically i have a working XP bar and a working Rep Bar
sorry for bombarding you all... maybe i need a more experienced coder to work with me on my project, yes no?
Code:
local fontsize = 12
localfont = "Fonts\\FRIZQT__.TTF"
local resolHeight = GetScreenHeight()
local resolWidth = GetScreenWidth()
local aspectRatio = (resolWidth/resolHeight)
--XP Bar
if UnitLevel("player") < MAX_PLAYER_LEVEL then
local derXpBarbg = CreateFrame("Frame", derXpBarbg, XPFrame)
derXpBarbg:SetFrameLevel(0)
derXpBarbg:SetFrameStrata("low")
derXpBarbg:SetHeight(14)
derXpBarbg:SetPoint("bottom",0,8)
derXpBarbg:SetBackdrop( {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = (-1), right = (-1), top = (-1), bottom = -(1)}
})
derXpBarbg:SetBackdropColor(0.1,0.1,0.1)
derXpBarbg:SetBackdropBorderColor(0.6,0.6,0.6)
local derXpBar = CreateFrame("Frame", derXpBar, XPFrame)
derXpBar:SetFrameLevel(1)
derXpBar:SetFrameStrata("low")
derXpBar:SetHeight(14)
derXpBar:SetPoint("LEFT", derXpBarbg, "LEFT", 1, 0)
derXpBar:SetBackdrop( {
bgFile = "Interface\\Buttons\\WHITE8X8",
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = (-1), right = (-1), top = (-1), bottom = -(1)}
})
derXpBar:RegisterEvent("PLAYER_XP_UPDATE");
derXpBar:RegisterEvent("PLAYER_LEVEL_UP");
derXpBar:RegisterEvent("UPDATE_EXHAUSTION");
derXpBar:RegisterEvent("PLAYER_ENTERING_WORLD")
local derXpBarRested = CreateFrame("Frame", derXpBar, XPFrame)
derXpBarRested:SetFrameLevel(1)
derXpBarRested:SetFrameStrata("low")
derXpBarRested:SetHeight(14)
derXpBarRested:SetPoint("LEFT", derXpBar, "RIGHT", 1, 0)
derXpBarRested:SetBackdrop( {
bgFile = "Interface\\Buttons\\WHITE8X8",
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = (-1), right = (-1), top = (-1), bottom = -(1)}
})
derXpBarRested:SetBackdropColor(0.2,0.2,0.8,0.5) --blue Rested
local newNameRegion = derXpBar:CreateFontString()
newNameRegion:SetPoint("CENTER", derXpBarbg, "CENTER", 0, 0)
newNameRegion:SetFont(localfont, fontsize, "OVERLAY")
local function eventHandler(self, event, ...)
local percent_full = UnitXP("player") / UnitXPMax("player");
derXpBarbg:SetWidth(resolWidth*.34-15)--/2)
if event == "PLAYER_LEVEL_UP" then
derXpBar:SetWidth(resolWidth*.34-15)
if UnitLevel("player") == MAX_PLAYER_LEVEL then
derXpBarbg:SetAlpha(0)
derXpBar:SetAlpha(0)
derXpBarRested:SetAlpha(0)
derXpBar:UnregisterEvent("PLAYER_XP_UPDATE");
derXpBar:UnregisterEvent("PLAYER_LEVEL_UP");
derXpBar:UnregisterEvent("UPDATE_EXHAUSTION");
derXpBar:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
else
derXpBar:SetWidth(percent_full*(resolWidth*.34-15))--/2))
end
--newNameRegion:SetText(string.sub((percent_full*100),0,5).."%") --Show Percentage
newNameRegion:SetText(UnitXP("player").." / "..UnitXPMax("player")) --Show Full Numbers
if GetXPExhaustion() then
derXpBar:SetBackdropColor(0.6,0,0.8,0.5)
derXpBarRested:SetAlpha(1)
if GetXPExhaustion()/UnitXPMax("player") > 0.99 then
derXpBarRested:SetWidth((resolWidth*.34-15) - derXpBar:GetWidth())
else
derXpBarRested:SetWidth((GetXPExhaustion()/UnitXPMax("player"))*(resolWidth*.34-15))--/2))
end
else
derXpBar:SetBackdropColor(0.6,0,0.8,0.5)
derXpBarRested:SetAlpha(0)
end
end
derXpBar:SetScript("OnEvent", eventHandler);
end
--Rep Bar
local myrepbarbg = CreateFrame("Frame", myrepbarbg, RepFrame)
myrepbarbg:SetFrameLevel(1)
myrepbarbg:SetFrameStrata("low")
myrepbarbg:SetHeight(16)
if UnitLevel("player") == MAX_PLAYER_LEVEL then
myrepbarbg:SetPoint("center",0,0)
else
myrepbarbg:SetPoint("center",0,0)
end
if UnitLevel("player") == MAX_PLAYER_LEVEL then
myrepbarbg:SetBackdrop( {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = (-1), right = (-1), top = (-1), bottom = -(1)}
})
myrepbarbg:SetBackdropColor(0.1,0.1,0.1)
myrepbarbg:SetBackdropBorderColor(0.6,0.6,0.6)
myrepbarbg:SetPoint("center",0,20)
end
local derRepBar = CreateFrame("Frame", derRepBar, RepFrame)
derRepBar:SetFrameLevel(1)
derRepBar:SetFrameStrata("low")
derRepBar:SetHeight(18)
derRepBar:SetPoint("LEFT", XPFrame, "LEFT", 10, 20)
derRepBar:SetBackdrop( {
bgFile = "Interface\\Buttons\\WHITE8X8",
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = (-1), right = (-1), top = (-1), bottom = -(1)}
})
derRepBar:RegisterEvent("UPDATE_FACTION");
local newNameRegion = derRepBar:CreateFontString()
newNameRegion:SetPoint("CENTER", myrepbarbg, "CENTER", 0, 0)
newNameRegion:SetFont(localfont, fontsize, "OVERLAY")
local function eventHandler(self, event, ...)
local name, standing, min, max, value = GetWatchedFactionInfo()
if name then
local percent_full = (value-min) / (max-min);
myrepbarbg:SetWidth(resolWidth*.34-15)
derRepBar:SetWidth(percent_full*resolWidth*.34-19)
newNameRegion:SetText(name.." "..(value-min).." / "..(max-min).." "..(getglobal("FACTION_STANDING_LABEL"..standing)))
derRepBar:SetBackdropColor(FACTION_BAR_COLORS[standing].r, FACTION_BAR_COLORS[standing].g, FACTION_BAR_COLORS[standing].b,0.8)
myrepbarbg:Show()
derRepBar:Show()
else
myrepbarbg:Hide()
derRepBar:Hide()
end
end
derRepBar:SetScript("OnEvent", eventHandler);
|