-
Notifications
You must be signed in to change notification settings - Fork 0
/
Progress.lua
273 lines (230 loc) · 9.17 KB
/
Progress.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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
--[[--------------------------------------------------------------------
Progress
Basic experience and reputation plugin for DataBroker displays.
Copyright (c) 2008-2017 Phanx <addons@phanx.net>. All rights reserved.
https://github.com/Phanx/Progress
https://mods.curse.com/addons/wow/progress
https://www.wowinterface.com/downloads/info11032-Progress.html
----------------------------------------------------------------------]]
local _, ns = ...
------------------------------------------------------------------------
local L = setmetatable(ns.L or {}, { __index = function(t, k)
if k == nil then return "" end
local v = tostring(k)
t[k] = v
return v
end })
for k, v in pairs(L) do -- clean up missing translations
if v == "" then
L[k] = k
end
end
L["Level"] = LEVEL
L["Faction"] = FACTION
L["Standing"] = STANDING
L["Reputation"] = REPUTATION
------------------------------------------------------------------------
local defaults = {
forceRep = false, -- Show reputation in the tooltip even if below max level
friendlyNumbers = true, -- Add digit grouping to large numbers
longText = false, -- Show current level or watched faction on plugin text [NYI]
shortFactions = true, -- Abbreviate name shown with longText [NYI]
}
------------------------------------------------------------------------
local STANDING_COLOR = {
"|cffcc2222", -- Hated
"|cffff0000", -- Hostile
"|cffee6622", -- Unfriendly
"|cffffff00", -- Neutral
"|cff00ff00", -- Friendly
"|cff00ff88", -- Honored
"|cff00ffcc", -- Revered
"|cff00ffff", -- Exalted
}
local STANDING_LABEL_MALE = {
FACTION_STANDING_LABEL1,
FACTION_STANDING_LABEL2,
FACTION_STANDING_LABEL3,
FACTION_STANDING_LABEL4,
FACTION_STANDING_LABEL5,
FACTION_STANDING_LABEL6,
FACTION_STANDING_LABEL7,
FACTION_STANDING_LABEL8,
}
local STANDING_LABEL_FEMALE = {
FACTION_STANDING_LABEL1_FEMALE,
FACTION_STANDING_LABEL2_FEMALE,
FACTION_STANDING_LABEL3_FEMALE,
FACTION_STANDING_LABEL4_FEMALE,
FACTION_STANDING_LABEL5_FEMALE,
FACTION_STANDING_LABEL6_FEMALE,
FACTION_STANDING_LABEL7_FEMALE,
FACTION_STANDING_LABEL8_FEMALE,
}
------------------------------------------------------------------------
local XP_PER_LEVEL = {
400, 900, 1400, 2100, 2800, 3800, 5000, 6400, 8100, 8800, -- 10
9800, 11500, 14000, 16300, 18800, 20800, 22500, 24000, 25700, 27300, -- 20
29100, 30900, 32500, 34400, 36500, 38200, 40100, 41800, 44800, 47600, -- 30
50900, 53500, 56400, 59100, 62000, 65100, 67800, 70800, 73700, 95700, -- 40
99500, 103300, 107000, 110800, 114700, 118500, 122400, 126300, 130200, 134300, -- 50
138300, 142400, 146500, 150500, 154700, 158900, 163200, 167300, 171700, 254000, -- 60
275000, 301000, 328000, 359000, 367000, 374000, 381000, 388000, 395000, 405000, -- 70
415000, 422000, 427000, 432000, 438000, 445000, 455000, 462000, 474000, 482000, -- 80
487000, 492000, 497000, 506000, 517000, 545000, 550000, 556000, 562000, 596000, -- 90
603000, 608000, 614000, 621000, 627000, 632000, 639000, 645000, 651000, 657000, -- 100
663000, 669000, 675000, 681000, 687000, 693000, 699000, 705000, 711000, 717000, -- 110
}
------------------------------------------------------------------------
local MAX_PLAYER_LEVEL = MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()]
for i = #XP_PER_LEVEL + 1, MAX_PLAYER_LEVEL do
-- workaround for new expansions without data yet
XP_PER_LEVEL[i] = XP_PER_LEVEL[i - 1]
end
local XP_TO_MAX_LEVEL = 0
for i = 1, MAX_PLAYER_LEVEL - 1 do
XP_TO_MAX_LEVEL = XP_TO_MAX_LEVEL + XP_PER_LEVEL[i]
end
local xpToCurrentLevel = 0
local shortFactions = {}
------------------------------------------------------------------------
local Progress = CreateFrame("Frame")
Progress:SetScript("OnEvent", function(self, event, ...) return self[event] and self[event](self, ...) end)
Progress:RegisterEvent("ADDON_LOADED")
------------------------------------------------------------------------
local function Debug(lvl, str, ...)
if lvl > 0 then return end
if ... then
str = str:format(...)
end
DEFAULT_CHAT_FRAME:AddMessage("|cffff7f7fProgress:|r " .. str)
end
------------------------------------------------------------------------
function Progress:ADDON_LOADED(addon)
if addon ~= "Progress" then return end
if not ProgressDB then
ProgressDB = defaults
self.db = ProgressDB
else
self.db = ProgressDB
for k, v in pairs(defaults) do
if type(self.db[k]) ~= type(defaults[k]) then
self.db[k] = v
end
end
end
self:UnregisterEvent("ADDON_LOADED")
self.ADDON_LOADED = nil
if IsLoggedIn() then
self:PLAYER_LOGIN()
else
self:RegisterEvent("PLAYER_LOGIN")
end
end
function Progress:PLAYER_LOGIN()
self.obj = LibStub("LibDataBroker-1.1"):NewDataObject("Progress", {
type = "data source",
icon = "Interface\\Icons\\INV_Misc_PocketWatch_02",
label = L["Progress"],
text = UNKNOWN,
OnClick = function() ToggleCharacter("ReputationFrame") end,
OnTooltipShow = function(tooltip) return Progress:UpdateTooltip(tooltip) end,
})
self:PLAYER_LEVEL_UP()
if UnitLevel("player") < MAX_PLAYER_LEVEL then
self:RegisterEvent("PLAYER_XP_UPDATE")
self:RegisterEvent("UPDATE_EXHAUSTION")
else
self:RegisterEvent("UPDATE_FACTION")
self:RegisterEvent("PLAYER_LEVEL_UP")
hooksecurefunc("SetWatchedFactionIndex", function() return self:UpdateText() end)
end
self:UpdateText()
self.UPDATE_FACTION = self.UpdateText
self.UPDATE_EXHAUSTION = self.UpdateText
self.PLAYER_XP_UPDATE = self.UpdateText
self:RegisterEvent("PLAYER_LOGOUT")
self:UnregisterEvent("PLAYER_LOGIN")
self.PLAYER_LOGIN = nil
end
function Progress:PLAYER_LOGOUT()
for k, v in pairs(self.db) do
if defaults[k] == v then
self.db[k] = nil
end
end
end
function Progress:PLAYER_LEVEL_UP(newLevel)
local level = newLevel or UnitLevel("player")
if level == MAX_PLAYER_LEVEL then
xpToCurrentLevel = XP_TO_MAX_LEVEL
self:RegisterEvent("UPDATE_FACTION")
self:UnregisterEvent("PLAYER_LEVEL_UP")
self:UnregisterEvent("PLAYER_XP_UPDATE")
self:UnregisterEvent("UPDATE_EXHAUSTION")
hooksecurefunc("SetWatchedFactionIndex", function() self:UpdateText() end)
else
xpToCurrentLevel = 0
if level > 1 then
for i = 1, level - 1 do
xpToCurrentLevel = xpToCurrentLevel + XP_PER_LEVEL[i]
end
end
end
end
------------------------------------------------------------------------
function Progress:GetWatchedFactionInfo()
local name, standing, min, max, cur = GetWatchedFactionInfo()
if name and min and max and max > 0 and max > min then
return name, standing, 0, max - min, cur - min
end
end
function Progress:UpdateText()
Debug(2, "UpdateText")
if UnitLevel("player") < MAX_PLAYER_LEVEL then
local cur, max = UnitXP("player"), UnitXPMax("player")
self.obj.text = format("%s (%d%%)", FormatLargeNumber(max - cur), floor(cur / max * 100 + 0.5))
return
end
local name, standing, min, max, cur = self:GetWatchedFactionInfo()
if name then
self.obj.text = format("%s%s (%d%%)|r", STANDING_COLOR[standing], FormatLargeNumber(max - cur), floor(cur / max * 100 + 0.5))
return
end
self.obj.text = L["Progress"]
end
function Progress:UpdateTooltip(tooltip)
tooltip:AddLine(L["Progress"], 1, 1, 1)
local myLevel = UnitLevel("player")
if myLevel < MAX_PLAYER_LEVEL then
tooltip:AddLine(" ")
tooltip:AddDoubleLine(L["Level"], myLevel, nil, nil, nil, 1, 1, 1)
if myLevel < MAX_PLAYER_LEVEL then
local cur, max, rest = UnitXP("player"), UnitXPMax("player"), GetXPExhaustion()
local total = xpToCurrentLevel + cur
tooltip:AddDoubleLine(L["Current XP"], format("%s / %s (%d%%)", FormatLargeNumber(cur), FormatLargeNumber(max), floor(cur / max * 100 + 0.5)), nil, nil, nil, 1, 1, 1)
if rest then
tooltip:AddDoubleLine(L["Rested XP"], format("%s (%s%%)", FormatLargeNumber(rest), floor(rest / max * 100 + 0.5)), nil, nil, nil, 1, 1, 1)
end
tooltip:AddDoubleLine(L["XP To Next Level"], FormatLargeNumber(max - cur), nil, nil, nil, 1, 1, 1)
tooltip:AddLine(" ")
tooltip:AddDoubleLine(format(L["XP To Level %d"], MAX_PLAYER_LEVEL), FormatLargeNumber(XP_TO_MAX_LEVEL - total), nil, nil, nil, 1, 1, 1)
tooltip:AddDoubleLine(" ", format("%d%%", floor(total / XP_TO_MAX_LEVEL * 100 + 0.5)), nil, nil, nil, 1, 1, 1)
end
end
if myLevel == MAX_PLAYER_LEVEL or self.db.forceRep then
local name, standing, min, max, cur = self:GetWatchedFactionInfo()
if name then
tooltip:AddLine(" ")
tooltip:AddDoubleLine(L["Faction"], name, nil, nil, nil, 1, 1, 1)
tooltip:AddDoubleLine(L["Standing"], format("%s%s|r", STANDING_COLOR[standing], UnitSex("player") == 3 and STANDING_LABEL_FEMALE[standing] or STANDING_LABEL_MALE[standing]))
tooltip:AddDoubleLine(L["Reputation"], format("%s / %s (%d%%)", FormatLargeNumber(cur), FormatLargeNumber(max), floor(cur / max * 100 + 0.5)), nil, nil, nil, 1, 1, 1)
if standing < 8 then
tooltip:AddDoubleLine(L["To Next Standing"], FormatLargeNumber(max - cur), nil, nil, nil, 1, 1, 1)
end
end
end
tooltip:AddLine(" ")
tooltip:AddLine(L["Click to toggle the reputation panel."])
tooltip:Show()
end