--- /dev/null
+-- ActionBars.lua
+local _;
+local min = math.min;
+local CreateFrame = CreateFrame;
+local UnitXP, UnitXPMax, GetXPExhaustion = UnitXP, UnitXPMax, GetXPExhaustion;
+local ExhaustionToolTipText = ExhaustionToolTipText;
+local GameTooltip = nil;
+
+local width = 300;
+
+local ActionBars = CreateFrame("Frame", "OmaActionBars");
+
+local function expBar(parent)
+ local frame = CreateFrame("Frame", "OmaExpBar", parent);
+ frame:SetPoint("BOTTOM");
+ frame:SetWidth(width);
+ frame:SetHeight(10);
+ frame.base = frame:CreateTexture(nil, "BACKGROUND");
+ frame.base:SetAllPoints();
+ frame.base:SetColorTexture(0, 0, 0, 0.5);
+ frame.bar = frame:CreateTexture(nil, "BORDER");
+ frame.bar:SetPoint("TOPLEFT", frame.base, "TOPLEFT");
+ frame.bar:SetPoint("BOTTOMLEFT", frame.base, "BOTTOMLEFT");
+ frame.bar:SetColorTexture(1, 1, 1);
+ frame.rest = frame:CreateTexture(nil, "BORDER");
+ frame.rest:SetPoint("TOPLEFT", frame.bar, "TOPRIGHT");
+ frame.rest:SetPoint("BOTTOMLEFT", frame.bar, "BOTTOMRIGHT");
+ frame.rest:SetColorTexture(0, 0.3, 1, 0.7);
+ frame.text = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlight");
+ frame.text:SetPoint("BOTTOM");
+ frame.text:Hide();
+
+ local function updateXP()
+ local xp, xpmax = UnitXP("player"), UnitXPMax("player");
+ local rested = GetXPExhaustion();
+ local current, restw = xp/xpmax*width, rested/xpmax*width;
+ local space = width - current;
+ frame.bar:SetWidth(current);
+ if rested then
+ frame.rest:SetWidth(min(space, restw));
+ frame.rest:Show();
+ frame.text:SetFormattedText("%d / %d (+%d)", xp, xpmax, rested/2);
+ frame.bar:SetVertexColor(0, 0.5, 1, 0.9);
+ else
+ frame.rest:Hide();
+ frame.text:SetFormattedText("%d / %d", xp, xpmax);
+ frame.bar:SetVertexColor(0.6, 0.2, 1, 0.9);
+ end
+ end
+ updateXP();
+
+ frame:SetScript("OnEvent", function(self, event)
+ if event == "PLAYER_XP_UPDATE" or event == "PLAYER_LEVEL_UP" then
+ updateXP();
+ end
+ end);
+ frame:RegisterEvent("PLAYER_XP_UPDATE");
+ frame:RegisterEvent("PLAYER_LEVEL_UP");
+ -- 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);
+end
+
+local function initialize()
+ -- let other addons hook this to anchor tooltip elsewhere
+ GameTooltip = _G["GameTooltip"];
+ if UnitLevel("player") < 110 and not IsXPUserDisabled() then
+ expBar(UIParent);
+ end
+end
+
+ActionBars:RegisterEvent("PLAYER_LOGIN");
+ActionBars:SetScript("OnEvent", function(self, event)
+ if event == "PLAYER_LOGIN" then
+ initialize();
+ end
+end);