|
05-28-14, 07:49 PM | #1 |
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); |
|
05-28-14, 09:40 PM | #2 |
You can save yourself a lot of work by using StatusBar objects instead of manually calculating and setting the width of plain Frame objects. Your code was really messy and I didn't feel like going over it line by line, so I just adapted the code from my already-working XP/rep bar to behave the way you described (auto switch to rep at max level or on shift-right-click) and use the same flat texture as your code.
Code:
local XP_COLOR = { r = 0.6, g = 0, b = 0.5 } local REST_COLOR = { r = 0.2, g = 0.2, b = 0.8 } ------------------------------------------------------------------------ -- Object creation local f = CreateFrame("Frame", "derXPBar", UIParent) f:SetPoint("BOTTOM", 0, 8) f:SetHeight(14) f:SetWidth(UIParent:GetWidth() * 0.75) f:SetBackdrop({ bgFile = "Interface\\BUTTONS\\WHITE8X8", edgeFile = "Interface\\BUTTONS\\WHITE8X8", edgeSize = 1, insets = { left = 1, right = 1, top = 1, bottom = 1 } }) f:SetBackdropColor(0.1, 0.1, 0.1) f:SetBackdropBorderColor(0.6, 0.6, 0.6) local restBar = CreateFrame("StatusBar", nil, f) restBar:SetPoint("BOTTOMLEFT", 1, 1) restBar:SetPoint("TOPRIGHT", -1, -1) restBar:SetStatusBarTexture("Interface\\BUTTONS\\WHITE8X8") restBar:SetStatusBarColor(REST_COLOR.r, REST_COLOR.g, REST_COLOR.b, 0.5) local bar = CreateFrame("StatusBar", nil, restBar) bar:SetAllPoints(true) bar:SetStatusBarTexture("Interface\\BUTTONS\\WHITE8X8") local text = bar:CreateFontString(nil, "OVERLAY", "GameFontNormal") text:SetPoint("CENTER") ------------------------------------------------------------------------ -- Display logic local mode = "XP" function f:Update(event, arg1) if event == "PET_BATTLE_OPENING_START" or C_PetBattles.IsInBattle() then return f:Hide() end local level = event == "PLAYER_LEVEL_UP" and arg1 or UnitLevel("player") if level == MAX_PLAYER_LEVEL or mode == "REP" then local name, standing, min, max, rep = GetWatchedFactionInfo() if name then text:SetFormattedText("%s: %d / %d %s", name, max - rep, max - min, UnitSex("player") == 3 and _G["FACTION_STANDING_LABEL"..standing.."_FEMALE"] or _G["FACTION_STANDING_LABEL"..standing]) bar:SetMinMaxValues(min, max) bar:SetValue(cur) local color = FACTION_BAR_COLORS[standing] bar:SetStatusBarColor(color.r, color.g, color.b) restBar:SetMinMaxValues(0, 1) restBar:SetValue(0) return end end local xp, max, rest = UnitXP("player"), UnitXPMax("player"), GetXPExhaustion() text:SetFormattedText("Level %d XP: %d / %d", level, xp, max) bar:SetMinMaxValues(0, max) bar:SetValue(xp) if rest then bar:SetStatusBarColor(REST_COLOR.r, REST_COLOR.g, REST_COLOR.b) restBar:SetMinMaxValues(0, max) restBar:SetValue( (xp + rest > max) and max or (xp + rest) ) else bar:SetStatusBarColor(XP_COLOR.r, XP_COLOR.g, XP_COLOR.b) restBar:SetMinMaxValues(0, 1) restBar:SetValue(0) end end ------------------------------------------------------------------------ -- Update on events f:RegisterEvent("PET_BATTLE_OPENING_START") f:RegisterEvent("PET_BATTLE_CLOSE") f:RegisterEvent("PLAYER_ENTERING_WORLD") f:RegisterEvent("PLAYER_LEVEL_UP") f:RegisterEvent("PLAYER_XP_UPDATE") f:RegisterEvent("UPDATE_EXHAUSTION") f:RegisterEvent("UPDATE_FACTION") f:SetScript("OnEvent", f.Update) hooksecurefunc("SetWatchedFactionIndex", f.Update) ------------------------------------------------------------------------ -- Toggle mode on click f:EnableMouse(true) f:SetScript("OnMouseUp", function(self, button) if button == "RightButton" and IsShiftKeyDown() then mode = mode == "XP" and "REP" or "XP" end self:Update() end)
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
05-29-14, 03:14 AM | #3 | ||
Phannx, your a God i only had to tweek that just a little bit... i.e. Code:
local f = CreateFrame("Frame", "derXPBar", XPFrame) f:SetPoint("CENTER", 0, 0) f:SetHeight(14) f:SetWidth(UIParent:GetWidth() * 0.33) i was wondering though, how could i add in a texture like all those cool bars out there, i dont really like the flat to much.. i like the aluminum texture a lot and when i use my other addon UI-tat, thats my primary texture Librarys convolute things a lot because i dont understand their workings |
|||
05-29-14, 04:12 AM | #4 |
I just use a backdrop myself, my XP bar overall is probably my favorite part of my UI of all things too. Likely because it's one of the first parts I made.
|
|
05-29-14, 04:25 AM | #5 |
error
im getting a consistant error right now, i see where its happening but cant understand why,
in the code you altered for me here is the error as provided by bug sack/grabber Code:
7x Deranjata-0.0.2.1a\Modules\XPbar.lua:198: Usage: <unnamed>:SetValue(value) <in C code> Deranjata-0.0.2.1a\Modules\XPbar.lua:198: in function "Update" Deranjata-0.0.2.1a\Modules\XPbar.lua:249: in function <Deranjata\Modules\XPbar.lua:245> Locals: self = derXPBar { 0 = <userdata> Update = <function> defined @Interface\AddOns\Deranjata\Modules\XPbar.lua:186 } event = nil arg1 = nil level = 6 name = "Silvermoon City" standing = 5 min = 3000 max = 9000 rep = 7102 f = derXPBar { 0 = <userdata> Update = <function> defined @Interface\AddOns\Deranjata\Modules\XPbar.lua:186 } mode = "REP" text = <unnamed> { 0 = <userdata> } bar = <unnamed> { 0 = <userdata> } restBar = <unnamed> { 0 = <userdata> } REST_COLOR = <table> { b = 0.8 g = 0.2 r = 0.2 } XP_COLOR = <table> { b = 0.5 g = 0 r = 0.6 } |
|
05-29-14, 05:36 AM | #6 |
Can you post your current XPbar.lua? preferrably on a site like pastebin using the lua syntax highlighting.
|
|
05-29-14, 05:50 AM | #7 | ||
Please stop encasing every line of your post in a color tag... makes reading through code and quoting really annoying.
Code:
restBar:SetStatusBarTexture("Interface\\BUTTONS\\WHITE8X8") Code:
restBar:SetStatusBarTexture("Interface\\AddOns\\MyXPAddon\\MyTextureFile")
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|||
WoWInterface » Developer Discussions » Lua/XML Help » trying to make an XP bar the way i want it |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|