-- ActionBars.lua
local _;
local min = math.min;
-local CreateFrame = CreateFrame;
+local CreateFrame, IsResting = CreateFrame, IsResting;
local UnitXP, UnitXPMax, GetXPExhaustion = UnitXP, UnitXPMax, GetXPExhaustion;
+local CTimerAfter = C_Timer.After;
local ExhaustionToolTipText = ExhaustionToolTipText;
local GameTooltip = nil;
local width = 300;
+local running = false;
local ActionBars = CreateFrame("Frame", "OmaActionBars");
local function updateXP()
local xp, xpmax = UnitXP("player"), UnitXPMax("player");
local rested = GetXPExhaustion();
- local current, restw = xp/xpmax*width, rested/xpmax*width;
+ local current = xp/xpmax*width;
local space = width - current;
frame.bar:SetWidth(current);
if rested then
+ local restw = rested/xpmax*width;
frame.rest:SetWidth(min(space, restw));
frame.rest:Show();
frame.text:SetFormattedText("%d / %d (+%d)", xp, xpmax, rested/2);
frame.bar:SetVertexColor(0.6, 0.2, 1, 0.9);
end
end
+ local function updater()
+ updateXP();
+ if running then CTimerAfter(10, updater) end
+ end
updateXP();
frame:SetScript("OnEvent", function(self, event)
if event == "PLAYER_XP_UPDATE" or event == "PLAYER_LEVEL_UP" then
updateXP();
+ elseif event == "PLAYER_UPDATE_RESTING" then
+ if IsResting() then
+ running = true;
+ CTimerAfter(6, updater);
+ else
+ running = false;
+ end
end
end);
frame:RegisterEvent("PLAYER_XP_UPDATE");
frame:RegisterEvent("PLAYER_LEVEL_UP");
+ frame:RegisterEvent("PLAYER_UPDATE_RESTING");
-- from FrameXML/MainMenuBar.lua
frame:SetScript("OnEnter", function(frame) frame.text:Show(); ExhaustionToolTipText(); end);
frame:SetScript("OnLeave", function(frame) frame.text:Hide(); GameTooltip:Hide(); end);