Skip to content

Instantly share code, notes, and snippets.

@ChrisLundquist
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisLundquist/10243594 to your computer and use it in GitHub Desktop.
Save ChrisLundquist/10243594 to your computer and use it in GitHub Desktop.
Slightly Improved Experience Bar Fix
-- Must be the first line
SIEB = {}
SIEB.name = "SlightlyImprovedExperienceBar"
SIEB.version = "1.3"
SIEB.throttle = {}
SIEB.defaults = {
minimumAlpha = 0.6,
showPercentageText = true,
showCurrentMaxText = true,
}
local LAM = LibStub:GetLibrary("LibAddonMenu-1.0")
function SIEB.Points()
local exp = 0
local maxExp = 1
if(IsUnitVeteran("player")) then
exp = GetUnitVeteranPoints("player")
maxExp = GetUnitVeteranPointsMax("player")
else
exp = GetUnitXP("player")
maxExp = GetUnitXPMax("player")
end
return exp,maxExp
end
-- Initializer functions that runs once when the game is loading addons
function SIEB.Initialize(eventCode, addOnName)
-- Only initialize our own addon
if (SIEB.name ~= addOnName) then return end
-- Load the saved variables
SIEB.vars = ZO_SavedVars:NewAccountWide("SIEBVars", 1, nil, SIEB.defaults)
-- Create config menu
panelId = LAM:CreateControlPanel(SIEB.name.."Config", "Experience Bar")
LAM:AddHeader(panelId, "SIEB.Heading", "General")
LAM:AddSlider(panelId, "SIEB.AlphaConfig", "Transparency", "Transparency value for the experience bar", 0, 10, 1,
function() return SIEB.vars.minimumAlpha * 10 end,
function(newValue) SIEB.vars.minimumAlpha = newValue / 10.0 end)
LAM:AddCheckbox(panelId, "SIEB.PctConfig", "Percentage Text", "Show current experience as a percent",
function() return SIEB.vars.showPercentageText end,
function(newValue) SIEB.vars.showPercentageText = newValue; SIEB.RefreshLabel() end)
LAM:AddCheckbox(panelId, "SIEB.CurMaxConfig", "Cur/Max Text", "Show current/maximum experience values",
function() return SIEB.vars.showCurrentMaxText end,
function(newValue) SIEB.vars.showCurrentMaxText = newValue; SIEB.RefreshLabel() end)
-- Create labels for the experience bar
local parent = _G["ZO_ExperienceBar"]
local label = WINDOW_MANAGER:CreateControl("SIEB_ExperienceBarLabel", parent, CT_LABEL)
label:SetDimensions(parent:GetWidth(), 20)
label:SetAnchor(CENTER, parent, CENTER, 0, 40)
label:SetFont("ZoFontGame")
label:SetColor(0.9, 0.9, 0.9, 1)
label:SetHorizontalAlignment(1)
label:SetVerticalAlignment(1)
SIEB.experienceLabel = label
SIEB.RefreshLabel()
-- Register for future power updates
EVENT_MANAGER:RegisterForEvent("SIEB", EVENT_EXPERIENCE_UPDATE, SIEB.ExperienceUpdate)
EVENT_MANAGER:RegisterForEvent("SIEB", EVENT_VETERAN_POINTS_UPDATE, SIEB.ExperienceUpdate)
end
-- Register for the init handler (needs to be declaired after the SIEB.Initialize function)
EVENT_MANAGER:RegisterForEvent("SIEB", EVENT_ADD_ON_LOADED, SIEB.Initialize)
-- Create the label string based on user preferences
function SIEB.FormatLabelText(current, max)
local percent = 0
if (max > 0) then
percent = string.format("%.2f", (current/max) * 100)
end
local str = ""
str = str .. current .. " / " .. max
str = str .. " "
str = str .. percent .. "%"
return str
end
-- Callback for the experience update event
function SIEB.ExperienceUpdate(reason, unitTag, currentExp, maxExp)
if (unitTag ~= "player") then return end
SIEB.RefreshLabel()
end
-- Refresh the label values without being triggered
function SIEB.RefreshLabel()
exp, maxExp = SIEB.Points()
SIEB.experienceLabel:SetText(SIEB.FormatLabelText(exp, maxExp))
end
function SIEB.UpdateThrottle(key, frequency)
if key == nil then return end
if SIEB.throttle[key] == nil then SIEB.throttle[key] = {} end
SIEB.throttle[key].frequency = frequency or 250
SIEB.throttle[key].now = GetFrameTimeMilliseconds()
if SIEB.throttle[key].last == nil then SIEB.throttle[key].last = SIEB.throttle[key].now end
SIEB.throttle[key].diff = SIEB.throttle[key].now - SIEB.throttle[key].last
SIEB.throttle[key].eval = SIEB.throttle[key].diff >= SIEB.throttle[key].frequency
if SIEB.throttle[key].eval then SIEB.throttle[key].last = SIEB.throttle[key].now end
return SIEB.throttle[key].eval
end
-- Callback for the gui control from the xml file
function SIEB.Update()
-- Perform this logic at a slow rate
-- if (SIEB.UpdateThrottle("Update") == false) then return end
-- Update was triggered before the saved variables were loaded
if (SIEB.vars == nil) then return end
local expBar = _G["ZO_ExperienceBar"]
local mapIsHidden = _G["ZO_WorldMapContainer"]:IsHidden()
local craftingIsHidden = _G["ZO_CraftingResultsTopLevel"]:IsHidden()
if (mapIsHidden == false or craftingIsHidden == false) then
expBar:SetHidden(true)
else
expBar:SetHidden(false)
expBar:SetAlpha(SIEB.vars.minimumAlpha)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment