-
Notifications
You must be signed in to change notification settings - Fork 2
/
Scoreboard.lua
208 lines (180 loc) · 6.54 KB
/
Scoreboard.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
local addonName, addon = ...
local L = addon.L
local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
local ldbi = LibStub:GetLibrary('LibDBIcon-1.0')
local function showConfig()
InterfaceOptionsFrame_OpenToCategory(addonName)
InterfaceOptionsFrame_OpenToCategory(addonName)
end
local function normal(text)
if not text then return "" end
return NORMAL_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE;
end
local function highlight(text)
if not text then return "" end
return HIGHLIGHT_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE;
end
local function muted(text)
if not text then return "" end
return DISABLED_FONT_COLOR_CODE..text..FONT_COLOR_CODE_CLOSE;
end
-- Init & config panel
do
local eventFrame = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer)
eventFrame:SetScript("OnEvent", function(self, event, loadedAddon)
if loadedAddon ~= addonName then return end
self:UnregisterEvent("ADDON_LOADED")
if type(ScoreboardSettings) ~= "table" then ScoreboardSettings = {currencies={},minimap={hide=false}} end
local sv = ScoreboardSettings
if type(sv.currencies) ~= "table" then sv.currencies = {} end
if type(sv.minimap) ~= "table" then sv.minimap = {hide=false} end
if type(sv.showHKs) ~= "boolean" then sv.showHKs = true end
if type(sv.showIcons) ~= "boolean" then sv.showIcons = true end
if type(sv.showLabels) ~= "boolean" then sv.showLabels = true end
if type(sv.showLimits) ~= "boolean" then sv.showLimits = true end
if type(sv.showHeaders) ~= "boolean" then sv.showHeaders = true end
if type(sv.useShortLabels) ~= "boolean" then sv.useShortLabels = false end
addon.db = sv
ldbi:Register(addonName, addon.dataobj, addon.db.minimap)
self:SetScript("OnEvent", nil)
end)
eventFrame:RegisterEvent("ADDON_LOADED")
addon.frame = eventFrame
end
-- data text
do
local f = CreateFrame("frame")
local text = "..loading.."
local tooltip = ""
local dataobj = ldb:NewDataObject("Scoreboard", {
type = "data source",
icon = "Interface\\ICONS\\achievement_pvp_a_14",
text = text,
OnEnter = function(frame)
GameTooltip:SetOwner(frame, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", frame, "BOTTOMLEFT")
GameTooltip:ClearLines()
addon:updateTooltip(frame)
GameTooltip:Show()
end,
OnLeave = function()
GameTooltip:Hide()
end,
OnClick = function(self, button)
if button == "RightButton" then
showConfig()
else
ToggleCharacter("TokenFrame");
end
end,
})
addon.dataobj = dataobj
-- Remove any non-word characters that cause issues saving in other locales
local function getIconKey(icon) return gsub(icon, "[^%w]", "") end
local function fmtIcon(icon)
local text
if not icon then icon = [[Interface\Icons\Temp]] end
text = " |T"..icon..":16:16:0:0:64:64:4:60:4:60|t ";
return text;
end
local function fmtLabel(text)
if not text then return "" end
if not addon.db.showLabels then return "" end
text = normal(text);
if addon.db.useShortLabels then
return normal(gsub(text, "[^%u]", ""))..": ";
end
return normal(text)..": ";
end
local function updateText()
local text = "";
local size = C_CurrencyInfo.GetCurrencyListSize();
local function renderItem(name, count, icon, mx)
local t = ""
if (addon.db.showIcons) then t = t..fmtIcon(icon) end
t = t..fmtLabel(name)..highlight(count);
if (addon.db.showLimits and mx and mx > 0) then t = t.."/"..mx end
return t
end
for i=1, size do
local c = C_CurrencyInfo.GetCurrencyListInfo(i)
if (not c.isHeader) then
if (addon:getCurrency(c.iconFileID) and not c.isTypeUnused) then
text = text..renderItem(c.name, c.quantity, c.iconFileID, c.maxQuantity)
if (i ~= size) then text = text.." " end
end
end
end
if (addon.db.showHKs) then
local faction, _ = UnitFactionGroup("player")
local count, _ = GetPVPLifetimeStats()
local icon = [[Interface\ICONS\achievement_pvp_p_01]]
if (faction == "Alliance") then
icon = [[Interface\ICONS\achievement_pvp_a_01]]
elseif (faction == "Horde") then
icon = [[Interface\ICONS\achievement_pvp_h_01]]
end
text = text..renderItem(L["Honor Kills"], count, icon, 0)
end
dataobj.text = text;
end
function addon:updateTooltip()
local size = C_CurrencyInfo.GetCurrencyListSize()
local function renderItem(name, count, icon, max)
local t = ""
t = t..fmtIcon(icon)..normal(name)..highlight(count)
if (mx and mx > 0) then t = t.."/"..mx end
return t
end
GameTooltip:AddLine(L["Scoreboard"].."\n")
GameTooltip:AddLine(muted(L["usageDescription"]))
for i=1, size do
local c = C_CurrencyInfo.GetCurrencyListInfo(i)
if c.isHeader then
if c.isHeaderExpanded and addon.db.showHeaders and c.name ~= "Unused" then
GameTooltip:AddLine(highlight(c.name).."\n")
end
else
if not c.isUnused then
-- @todo stylize the count when nearing limit?
local ltext = fmtIcon(c.iconFileID)..c.name
local rtext = highlight(c.quantity)
if addon.db.showLimits and c.maxQuantity and c.maxQuantity > 0 then
rtext = rtext.." / "..highlight(c.maxQuantity)
end
GameTooltip:AddDoubleLine(ltext, rtext)
end
end
end
if (addon.db.showHKs) then
GameTooltip:AddLine(highlight(L["PvP Stats"]).."\n")
local hks, dks = GetPVPLifetimeStats()
local pct = string.format(" (%.f%%)", math.max(0, UnitHonor("player")) / math.max(1, UnitHonorMax("player")) * 100)
GameTooltip:AddDoubleLine(L["Honorable Kills"], highlight(hks))
GameTooltip:AddDoubleLine(L["Dishonorable Kills"], highlight(dks))
GameTooltip:AddDoubleLine(L["Honor Level"], highlight(UnitHonorLevel("player"))..muted(pct))
elseif (size == 0) then
GameTooltip:AddLine(muted(L["No currencies can be displayed."]))
end
end
function addon:setDB(key, value)
addon.db[key] = value
updateText()
end
function addon:setCurrency(icon, value)
local ik = getIconKey(icon)
addon.db.currencies[ik] = value
updateText()
end
function addon:getCurrency(icon)
local ik = getIconKey(icon)
return addon.db.currencies[ik] == true
end
f:RegisterEvent("PLAYER_ENTERING_WORLD");
f:RegisterEvent("CURRENCY_DISPLAY_UPDATE");
f:SetScript("OnEvent", function(self, event)
if(event == "CURRENCY_DISPLAY_UPDATE" or event == "PLAYER_ENTERING_WORLD") then
updateText()
end
end)
end