c711b1a - Add action bar addon, just exp bar for now
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sun, 28 Jan 2018 13:53:00 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sun, 28 Jan 2018 13:53:00 +0000
OmaAB/ActionBars.lua [new file with mode: 0644]
OmaAB/OmaAB.toc [new file with mode: 0644]

diff --git a/OmaAB/ActionBars.lua b/OmaAB/ActionBars.lua
new file mode 100644 (file)
index 0000000..f61b9c7
--- /dev/null
@@ -0,0 +1,77 @@
+-- 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);
diff --git a/OmaAB/OmaAB.toc b/OmaAB/OmaAB.toc
new file mode 100644 (file)
index 0000000..0af84fa
--- /dev/null
@@ -0,0 +1,7 @@
+## Interface: 70300
+## Title: Oma Action Bar
+## Version: 1.0
+## Author: schyrio
+## Notes: My action bars
+
+ActionBars.lua