From c711b1a7ea9d9cef2ba53a9eb4ddcfb5405126b2 Mon Sep 17 00:00:00 2001 From: Aleksi Blinnikka Date: Sun, 28 Jan 2018 15:53:00 +0200 Subject: [PATCH 1/1] Add action bar addon, just exp bar for now --- OmaAB/ActionBars.lua | 77 ++++++++++++++++++++++++++++++++++++++++++++ OmaAB/OmaAB.toc | 7 ++++ 2 files changed, 84 insertions(+) create mode 100644 OmaAB/ActionBars.lua create mode 100644 OmaAB/OmaAB.toc diff --git a/OmaAB/ActionBars.lua b/OmaAB/ActionBars.lua new file mode 100644 index 0000000..f61b9c7 --- /dev/null +++ b/OmaAB/ActionBars.lua @@ -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 index 0000000..0af84fa --- /dev/null +++ b/OmaAB/OmaAB.toc @@ -0,0 +1,7 @@ +## Interface: 70300 +## Title: Oma Action Bar +## Version: 1.0 +## Author: schyrio +## Notes: My action bars + +ActionBars.lua -- 2.39.5