Skip to content

Instantly share code, notes, and snippets.

@ChrisLundquist
Created April 12, 2014 03:11
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/10516872 to your computer and use it in GitHub Desktop.
Save ChrisLundquist/10516872 to your computer and use it in GitHub Desktop.
-- Must be the first line
LARB = {}
-- Transparency value limit for the fading out of the experience bar. Value is the
-- minimum allowed, and should be a float number between 0 and 1. A value
-- of 0 would mimic the default behavior to hide the frame entirely.
LARB.minimumAlpha = 0.6
-- Boolean values to control the display of the text string that goes over the experience
-- bar. Values must be either 'true' or 'false'. If both are configured, the current/max
-- values will come first followed by the percentage.
LARB.showPercentageText = true
LARB.showCurrentMaxText = true
--
-- DON'T EDIT BELOW THIS LINE!
--
LARB.name = "LlauronAllianceRankBar"
LARB.version = "1.0"
LARB.throttle = {}
function LARB.Points()
local rankPoints = GetUnitAvARankPoints("player")
local maxRankPoints = GetNumPointsNeededForAvARank("player")
return rankPoints,maxRankPoints
end
-- Initializer functions that runs once when the game is loading addons
function LARB.Initialize(eventCode, addOnName)
-- Only initialize our own addon
if (LARB.name ~= addOnName) then return end
local parent = _G["GetAvARankProgress"]()
local label = WINDOW_MANAGER:CreateControl("LARB_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)
label:SetMirrorAlongX(1)
local rankPoints, maxRankPoints = LARB.Points()
LARB.experienceLabel = label
LARB.RefreshLabel()
EVENT_MANAGER:RegisterForEvent("LARB", EVENT_RANK_POINT_UPDATE, LARB.RankUpdate)
EVENT_MANAGER:RegisterForEvent("LARB", EVENT_ADD_ON_LOADED, LARB.Initialize)
end
function LARB.RefreshLabel()
local rankPoints, maxRankPoints = LARB.Points()
LARB.experienceLabel:SetText(LARB.FormatLabelText(rankPoints, maxRankPoints))
end
-- Create the label string based on user preferences
function LARB.FormatLabelText(current, max)
local percent = 0
if (max > 0) then
percent = string.format("%.2f", (current/max) * 100)
end
local str = ""
if (LARB.showCurrentMaxText) then
str = str .. current .. " / " .. max
end
if (LARB.showPercentageText) then
if (LARB.showCurrentMaxText) then
str = str .. " "
end
str = str .. percent .. "%"
end
return str
end
function LARB.RankUpdate(reason, unitTag, currentExp, maxExp)
if (unitTag ~= "player") then return end
LARB.experienceLabel:SetText(LARB.FormatLabelText(currentExp, maxExp))
end
-- Callback for the gui control from the xml file
function LARB.Update()
local expBar = _G["ZO_ExperienceBar"]
local mapIsHidden = _G["ZO_WorldMapContainer"]:IsHidden()
local craftingIsHidden = _G["ZO_CraftingResultsTopLevel"]:IsHidden()
if (mapIsHidden or craftingIsHidden) then
-- Player is playing, show the bar
expBar:SetHidden(false)
expBar:SetAlpha(LARB.minimumAlpha)
else
-- Otherwise, player is crafting or something, hide bar
expBar:SetHidden(true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment