-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXP_Text.lua
More file actions
87 lines (72 loc) · 2.15 KB
/
XP_Text.lua
File metadata and controls
87 lines (72 loc) · 2.15 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--
-- time of day string display
-- some code ganked from the system UI XP Bar, also
-- borrowed basic structure from tyroney's Game_Clock, which
-- borrowed code from thanto_
--
require "string"
require "math"
require "table"
local math = math;
--CONSTANTS
local FRAME = Component.GetFrame("Main")
local XP_TEXT = Component.GetWidget("XP_Text")
-- TWEAKUI INFO
require "lib/lib_TweakUI"
TWEAKUI = {}
TWEAKUI.FRAMENAME = "Main"
TWEAKUI.FORMAT = "<Xpct><Ypct><WIDTH><HEIGHT>"
TWEAKUI.DEFAULTS = {
_VERSION = 1,
Xpct = {key="left:", value="5", link="; "},
Ypct = {key="bottom:", value="100%%-30", link="; "},
WIDTH = {key="width:", value=120, link="; "},
HEIGHT = {key="height:", value=20, link="; "},
SCALE = 1,
ENABLED = "true",
}
TweakUI.AddOption({id="ENABLED", label="Show XP Text", button="checkbox", reply="self"})
TweakUI.AddOption({id="SCALE", label="Scale", button="slider", min=0.5, max=2.0, inc=0.01, format="%0.0f", convert="percent", unit="%", reply="tweakui", disable={id="ENABLED",is="=",to="false"}})
--VARIABLES
local g_enabled = true
local g_HUDShow = true
local g_XPinfo = {};
--EVENTS
function OnComponentLoad()
end
function OnShow(args)
g_HUDShow = args.show
FRAME:ParamTo("alpha", tonumber(g_HUDShow), args.dur);
end
function OnMessage(args)
if args.type == "ENABLED" then
g_enabled = (args.data == true or args.data == "true")
FRAME:Show(g_enabled and not Player.IsSpectating())
if g_enabled then
UpdateXP();
end
end
end
function OnExperienceChanged()
UpdateXP();
end
function OnBattleframeChanged()
UpdateXP();
end
function OnLevelChanged()
UpdateXP();
end
function UpdateXP()
log("UpdateXP called!")
g_XPinfo = Player.GetClassProgression();
if g_XPinfo.total_level_xp > 0 then
g_XPinfo.percent = g_XPinfo.player_level_xp / g_XPinfo.total_level_xp;
g_XPinfo.remaining = g_XPinfo.total_level_xp - g_XPinfo.player_level_xp;
local xp_string = string.format("%d / %d [%d to next level]", g_XPinfo.player_level_xp, g_XPinfo.total_level_xp, g_XPinfo.remaining);
log(xp_string);
XP_TEXT:SetText(xp_string);
else
g_XPinfo.percent = 0
g_XPinfo.remaining = 0
end
end