-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.lua
More file actions
312 lines (244 loc) · 9.23 KB
/
shared.lua
File metadata and controls
312 lines (244 loc) · 9.23 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
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
local Log = IMP_STATS_Logger('IMP_STAS_SHARED')
local addon = {}
function addon.FormatNumber(number)
if number > 1e9 then
return string.format('%.1f B', number / 1e9)
elseif number > 1e6 then
return string.format('%.1f M', number / 1e6)
elseif number > 1e3 then
return string.format('%.1f K', number / 1e3)
else
return string.format('%d', number)
end
end
local RACE_ICONS = {
[1] = 'esoui/art/charactercreate/charactercreate_bretonicon_up.dds',
[2] = 'esoui/art/charactercreate/charactercreate_redguardicon_up.dds',
[3] = 'esoui/art/charactercreate/charactercreate_orcicon_up.dds',
[4] = 'esoui/art/charactercreate/charactercreate_dunmericon_up.dds',
[5] = 'esoui/art/charactercreate/charactercreate_nordicon_up.dds',
[6] = 'esoui/art/charactercreate/charactercreate_argonianicon_up.dds',
[7] = 'esoui/art/charactercreate/charactercreate_altmericon_up.dds',
[8] = 'esoui/art/charactercreate/charactercreate_bosmericon_up.dds',
[9] = 'esoui/art/charactercreate/charactercreate_khajiiticon_up.dds',
[10] = 'esoui/art/charactercreate/charactercreate_imperialicon_up.dds',
}
function addon.GetRaceIcon(raceId)
return RACE_ICONS[raceId]
end
function addon.PossibleNan(value)
return value == value and value or 0
end
local function HSV2RGB(h, s, v)
local k1 = v*(1-s)
local k2 = v - k1
local r = math.min (math.max (3*math.abs (((h )/180)%2-1)-1, 0), 1)
local g = math.min (math.max (3*math.abs (((h -120)/180)%2-1)-1, 0), 1)
local b = math.min (math.max (3*math.abs (((h +120)/180)%2-1)-1, 0), 1)
return k1 + k2 * r, k1 + k2 * g, k1 + k2 * b
end
function addon.Blend(A, B, value)
local Ah, As, Av = ConvertRGBToHSV(unpack(A))
local Bh, Bs, Bv = ConvertRGBToHSV(unpack(B))
Ah = Ah % 360
Bh = Bh % 360
local Ch = Ah + (Bh - Ah) * value
-- local Cs = As + (Bs - As) * value
-- local Cv = Av + (Bv - Av) * value
local r, g, b = HSV2RGB(Ch, 1, 1)
return r, g, b
--[[
local Ar, Ag, Ab = unpack(A)
local Aa = 1
local Br, Bg, Bb = unpack(B)
local Ba = 1
local w, a, w1, w2
w = value * 2 - 1
a = Aa - Ba
w1 = ((w * a == -1 and w or (w + a)/(1 + w * a)) + 1) / 2
w2 = 1 - w1
return
w1 * Ar + w2 * Br,
w1 * Ag + w2 * Bg,
w1 * Ab + w2 * Bb
]]
end
function addon.TableLength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function addon.Get(self, task, filters, tbl)
local function PassFilters(data)
for _, filter in ipairs(filters) do
if not filter(data) then return end
end
return true
end
local function Filter(index, data)
if PassFilters(data) then table.insert(tbl, index) end
end
return task:For(ipairs(self:GetDataRows(task))):Do(Filter)
end
local function InitializeFilter(contorl, entriesData, setFiltersCallback)
local comboBox = ZO_ComboBox_ObjectFromContainer(contorl)
comboBox:SetSortsItems(false)
comboBox:SetFont('ZoFontWinT1')
comboBox:SetSpacing(4)
local function OnFilterChanged(comboBox, entryText, entry)
local newFilters = {}
for i, itemData in ipairs(comboBox.m_selectedItemData) do
table.insert(newFilters, itemData.filterType)
end
setFiltersCallback(newFilters)
end
for i, entry in ipairs(entriesData) do
local item = comboBox:CreateItemEntry(entry.text, OnFilterChanged)
item.filterType = entry.type
comboBox:AddItem(item)
end
return comboBox
end
addon.InitializeFilter = InitializeFilter
local CHARACTER_SELECTION_TYPE_ALL = 1
local CHARACTER_SELECTION_TYPE_CURRENT = 2
local CHARACTER_SELECTION_TYPE_NONE = 3
local CHARACTER_SELECTION_TYPE_CUSTOM = 4
local CHARACTER_SELECTION_MESSAGE = {
[CHARACTER_SELECTION_TYPE_ALL] = 'Deselect All',
[CHARACTER_SELECTION_TYPE_CURRENT] = 'Select All',
[CHARACTER_SELECTION_TYPE_NONE] = 'Select Current',
[CHARACTER_SELECTION_TYPE_CUSTOM] = 'Select All',
}
local function GetTextIf(selectionType)
return CHARACTER_SELECTION_MESSAGE[selectionType]
end
function addon.InitializePlayerCharactersFilter(self, filterControl, charactersList)
local filter
local numCharacters = GetNumCharacters()
local entriesData = {}
local characters = charactersList -- self.filters.selectedCharacters
local function GetSelectionType()
local numCharactersSelected = filter:GetNumSelectedEntries()
-- Log('Characters selected: %d', numCharactersSelected)
if numCharactersSelected == numCharacters then
return CHARACTER_SELECTION_TYPE_ALL
end
if numCharactersSelected == 1 and characters[GetCurrentCharacterId()] then
return CHARACTER_SELECTION_TYPE_CURRENT
end
if numCharactersSelected == 0 then
return CHARACTER_SELECTION_TYPE_NONE
end
return CHARACTER_SELECTION_TYPE_CUSTOM
end
for i = 1, numCharacters do
local name, _, _, classId, _, _, characterId, _ = GetCharacterInfo(i)
local classIcon = zo_iconFormatInheritColor(ZO_GetClassIcon(classId), 24, 24)
local formattedName = zo_strformat('<<1>> <<2>>', classIcon, name)
entriesData[i] = {
text = formattedName,
type = characterId,
}
end
local function callback(newFilters)
for characterId, _ in pairs(characters) do
characters[characterId] = false
end
for _, characterId in ipairs(newFilters) do
characters[characterId] = true
end
self:Update()
local selectButton = GetControl(filterControl, 'SelectButton')
if selectButton then
selectButton:SetText(GetTextIf(GetSelectionType()))
end
end
filter = InitializeFilter(filterControl, entriesData, callback)
filter:SetNoSelectionText('|cFF0000Select Character|r')
filter:SetMultiSelectionTextFormatter('<<1[$d Character/$d Characters]>> Selected')
for i, item in ipairs(filter.m_sortedItems) do
-- Log('%d - %s', i, item.name)
if characters[item.filterType] then
filter:SelectItem(item, true)
-- Log('[B] Selecting %s', item.text)
end
end
local function SelectCharacter(characterId)
for i, item in ipairs(filter.m_sortedItems) do
if item.filterType == characterId then
filter:SelectItem(item, true)
return
end
end
end
local function SelectUnselect(button)
local selectionType = GetSelectionType()
filter:ClearAllSelections() -- seems it reverse selection if SelectItem called on selected item
if selectionType == CHARACTER_SELECTION_TYPE_ALL then
-- filter:ClearAllSelections()
for i, item in ipairs(filter.m_sortedItems) do
characters[item.filterType] = false
end
elseif selectionType == CHARACTER_SELECTION_TYPE_CURRENT or selectionType == CHARACTER_SELECTION_TYPE_CUSTOM then
-- filter:ClearAllSelections()
for i, item in ipairs(filter.m_sortedItems) do
characters[item.filterType] = true
filter:SelectItem(item, true)
end
elseif selectionType == CHARACTER_SELECTION_TYPE_NONE then
local currentCharacterId = GetCurrentCharacterId()
characters[currentCharacterId] = true
SelectCharacter(currentCharacterId)
end
selectionType = GetSelectionType() -- TODO: optimize?
-- Log('Selection type: %d, text to set: %s', selectionType, GetTextIf(selectionType))
button:SetText(GetTextIf(selectionType))
self:Update()
end
local selectButton = GetControl(filterControl, 'SelectButton')
if selectButton then
selectButton:SetHandler('OnMouseDown', SelectUnselect)
selectButton:SetText(GetTextIf(GetSelectionType()))
end
end
function addon.SetGaugeKDAMeter(kdaMeterControl, value)
local r, g, b = IMP_STATS_SHARED.Blend({1, 0, 0}, {0, 1, 0}, value)
GetControl(kdaMeterControl, 'Bar'):StartFixedCooldown(value, CD_TYPE_RADIAL, CD_TIME_TYPE_TIME_REMAINING, false) -- TODO
GetControl(kdaMeterControl, 'Bar'):SetFillColor(r, g, b)
GetControl(kdaMeterControl, 'Winrate'):SetText(('%.0f%%'):format(value * 100))
GetControl(kdaMeterControl, 'Winrate'):SetColor(r, g, b)
end
function addon.SecondsToTime(seconds)
local minutes = math.floor(seconds / 60) % 60
local hours = math.floor(seconds / 60 / 60)
local remainingSeconds = seconds % 60
if hours == 0 then
return string.format('%d:%02d', minutes, remainingSeconds)
else
return string.format('%d:%02d:%02d', hours, minutes, remainingSeconds)
end
end
function addon.class(base)
local cls = {}
if type(base) == 'table' then
for k, v in pairs(base) do
cls[k] = v
end
cls.base = base
end
cls.__index = cls
setmetatable(cls, {
__call = function(self, ...)
local obj = setmetatable({}, cls)
if self.__init__ then
self.__init__(obj, ...)
elseif base ~= nil and base.__init__ ~= nil then
base.__init__(obj, ...)
end
return obj
end
})
return cls
end
IMP_STATS_SHARED = addon