-
Notifications
You must be signed in to change notification settings - Fork 0
/
RestedXpTooltip.lua
59 lines (49 loc) · 1.9 KB
/
RestedXpTooltip.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
local feature = ns.Register({
identifier = "RestedXpTooltip",
description = "Adds rested XP in percentage to the XP bar.",
category = "interface",
config = {},
frames = {
expbar = nil,
},
data = {
attached = false,
exhaustion = 0,
currentXP = 0,
nextLevelXP = 0,
},
})
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:RegisterEvent("UPDATE_EXHAUSTION")
frame:RegisterEvent("PLAYER_UPDATE_RESTING")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:RegisterEvent("PLAYER_LEVEL_UP")
frame:RegisterEvent("PLAYER_XP_UPDATE")
frame:SetScript("OnEvent", function()
if not ns.IsEnabled(feature.identifier) then return end
if not feature.frames.exp then
feature.frames.exp = CreateFrame("Frame", "exp", UIParent)
feature.frames.exp:SetFrameStrata("HIGH")
feature.frames.exp.expstring = feature.frames.exp:CreateFontString(nil, "OVERLAY", "NumberFontNormal")
feature.frames.exp.expstring:ClearAllPoints()
feature.frames.exp.expstring:SetPoint("CENTER", MainMenuExpBar, "CENTER", 0, 2)
feature.frames.exp.expstring:SetJustifyH("CENTER")
feature.frames.exp.expstring:SetTextColor(1,1,1)
MainMenuExpBar:SetScript("OnEnter", function(self)
feature.frames.exp.expstring:SetText(string.format("XP %s / %s (%s%%)", feature.data.currentXP, feature.data.nextLevelXP, feature.data.exhaustion))
feature.frames.exp:Show()
end)
MainMenuExpBar:SetScript("OnLeave", function(self)
feature.frames.exp:Hide()
end)
feature.data.attached = true
end
end)
frame:SetScript("OnUpdate", function()
if not ns.IsEnabled(feature.identifier) then return end
local currentXP, nextLevelXP, exhaustion = UnitXP("player"), UnitXPMax("player"), GetXPExhaustion() or 0
feature.data.exhaustion = math.floor(exhaustion / nextLevelXP * 100) or 0
feature.data.currentXP = currentXP
feature.data.nextLevelXP = nextLevelXP
end)