forked from Ostoic/RaidBrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.lua
318 lines (256 loc) · 7.96 KB
/
gui.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
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
313
314
315
316
317
318
---@diagnostic disable: undefined-field
RaidBrowser.gui = {}
local search_button = LFRQueueFrameFindGroupButton
local join_button = LFRBrowseFrameInviteButton
local name_column = LFRBrowseFrameColumnHeader1
local gs_list_column = LFRBrowseFrameColumnHeader2
local raid_list_column = LFRBrowseFrameColumnHeader3
local sort_column
local sort_ascending = false
---Order by ascending or descending based on module variable sort_ascending.
---@param a any
---@param b any
---@return boolean
---@nodiscard
local function compare(a, b)
if sort_ascending then
return a > b
else
return a < b
end
end
---@param a table
---@param b table
---@return boolean
---@nodiscard
local sort_function = function(a, b)
if sort_column == "name" then
return compare(a.sender, b.sender)
elseif sort_column == "gs" then
return compare(a.gs, b.gs)
elseif sort_column == "raid" then
return compare(a.raid_info.name, b.raid_info.name)
else
return compare(a.time, b.time)
end
end
---@param column string
local function set_sort(column)
if sort_column == column then
sort_ascending = not sort_ascending
else
sort_column = column
end
if RaidBrowser.gui then
RaidBrowser.gui.update_list()
end
end
---@return table
---@nodiscard
local function get_sorted_messages()
local keys = {}
for _, info in pairs(RaidBrowser.lfm_messages) do
table.insert(keys, info)
end
table.sort(keys, sort_function)
return keys
end
name_column:SetScript('OnClick', function() set_sort('name') end)
gs_list_column:SetText('GS')
gs_list_column:SetScript('OnClick', function() set_sort('gs') end)
raid_list_column:SetText('Raid')
raid_list_column:SetScript('OnClick', function() set_sort('raid') end)
local function on_join()
local raid_message = RaidBrowser.lfm_messages[LFRBrowseFrame.selectedName]
if not raid_message then return end
local raid_name = raid_message.raid_info.name;
local message = RaidBrowser.stats.build_join_message(raid_name);
--print(LFRBrowseFrame.selectedName.." -> "..message)
SendChatMessage(message, 'WHISPER', nil, LFRBrowseFrame.selectedName);
end
join_button:SetText('Join')
join_button:SetScript('OnClick', on_join)
---@param value integer
---@return string
---@nodiscard
local function format_count(value)
if value == 1 then
return ' ';
end
return 's ';
end
---@param seconds string
---@return string
---@nodiscard
local function format_seconds(seconds)
local num_seconds = tonumber(seconds)
if num_seconds <= 0 then
return "00 seconds";
end
local days_text = '';
local hours_text = '';
local minutes_text = '';
if num_seconds >= 86400 then
local days = math.floor(num_seconds / 86400);
days_text = days .. ' day' .. format_count(days);
num_seconds = num_seconds % 86400;
end
if num_seconds >= 3600 then
local hours = math.floor(num_seconds / 3600);
hours_text = hours .. ' hr' .. format_count(hours);
num_seconds = num_seconds % 3600;
end
if num_seconds >= 60 then
local minutes = math.floor(num_seconds / 60);
minutes_text = minutes .. ' min' .. format_count(minutes);
end
return days_text .. hours_text .. minutes_text;
end
-- Hide unused dropdown menu
LFRBrowseFrameRaidDropDown:Hide()
search_button:SetText('Find Raid')
search_button:SetScript('OnClick', function() end)
local function clear_highlights()
for i = 1, NUM_LFR_LIST_BUTTONS do
_G["LFRBrowseFrameListButton" .. i]:UnlockHighlight();
end
end
-- Assignment operator for LFR buttons
---@param button Button
---@param host_name string
---@param lfm_info any
---@param index integer
local function assign_lfr_button(button, host_name, lfm_info, index)
local offset = FauxScrollFrame_GetOffset(LFRBrowseFrameListScrollFrame);
button.index = index;
index = index - offset;
button.lfm_info = lfm_info;
button.raid_info = lfm_info.raid_info;
-- Update selected LFR raid host name
button.unitName = host_name;
-- Update button text with raid host name , GS, Raid, and role information
button.name:SetText(host_name);
button.level:SetText(button.lfm_info.gs); -- Previously level, now GS
-- Raid name
button.class:SetText(button.raid_info.name);
button.raid_locked, button.raid_reset_time = RaidBrowser.stats.raid_lock_info(button.raid_info);
button.type = "party";
button.partyIcon:Show();
button.tankIcon:Hide();
button.healerIcon:Hide();
button.damageIcon:Hide();
-- Get all the roles from the lfm info table
for _, role in pairs(button.lfm_info.roles) do
if role == 'tank' then
button.tankIcon:Show()
end
if role == 'healer' then
button.healerIcon:Show();
end
if role == 'melee_dps' or role == 'ranged_dps' or role == 'dps' then
button.damageIcon:Show();
end
end
button:Enable();
button.name:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
button.level:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
-- If the raid is saved, then color the raid text in the list as red
if button.raid_locked then
button.class:SetTextColor(1, 0, 0);
else
button.class:SetTextColor(0, 1, 1);
end
-- Set up the corresponding textures for the roles columns
button.tankIcon:SetTexture("Interface\\LFGFrame\\LFGRole");
button.healerIcon:SetTexture("Interface\\LFGFrame\\LFGRole");
button.damageIcon:SetTexture("Interface\\LFGFrame\\LFGRole");
button.partyIcon:SetTexture("Interface\\LFGFrame\\LFGRole");
button:SetScript('OnEnter',
function(lfr_button)
GameTooltip:SetOwner(lfr_button, 'ANCHOR_RIGHT');
local seconds = time() - lfr_button.lfm_info.time;
local last_sent = string.format('Last sent: %d seconds ago', seconds);
GameTooltip:AddLine(lfr_button.lfm_info.message, 1, 1, 1, true);
GameTooltip:AddLine(last_sent);
if lfr_button.raid_locked then
GameTooltip:AddLine('\nYou are |cffff0000saved|cffffd100 for ' .. lfr_button.raid_info.name);
GameTooltip:AddLine('Lockout expires in ' .. format_seconds(lfr_button.raid_reset_time));
else
GameTooltip:AddLine('\nYou are |cff00ffffnot saved|cffffd100 for ' .. lfr_button.raid_info.name);
end
GameTooltip:Show();
end
)
button:SetScript('OnLeave',
function(_)
GameTooltip:Hide();
end
)
end
---@param button Button
---@param index integer
local function insert_lfm_button(button, index)
local count = 1;
local sortedMessages = get_sorted_messages()
for _, lfm_info in pairs(sortedMessages) do
if count == index then
assign_lfr_button(button, lfm_info.sender, lfm_info, index);
break;
end
count = count + 1;
end
end
local function update_buttons()
LFRBrowseFrameSendMessageButton:Enable();
LFRBrowseFrameInviteButton:Enable();
end
local function clear_list()
for i = 1, NUM_LFR_LIST_BUTTONS do
local button = _G["LFRBrowseFrameListButton" .. i];
button:Hide();
button:UnlockHighlight();
end
end
---@param t table
---@return integer
local function table_length(t)
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end
function RaidBrowser.gui.update_list()
LFRBrowseFrameRefreshButton.timeUntilNextRefresh = LFR_BROWSE_AUTO_REFRESH_TIME;
local numResults = table_length(RaidBrowser.lfm_messages)
FauxScrollFrame_Update(LFRBrowseFrameListScrollFrame, numResults, NUM_LFR_LIST_BUTTONS, 16);
local offset = FauxScrollFrame_GetOffset(LFRBrowseFrameListScrollFrame);
clear_list();
-- Update button information
for i = 1, NUM_LFR_LIST_BUTTONS do
local button = _G["LFRBrowseFrameListButton" .. i];
if (i <= numResults) then
insert_lfm_button(button, i + offset);
button:Show();
else
button:Hide();
end
end
clear_highlights();
-- Update button highlights
for i = 1, NUM_LFR_LIST_BUTTONS do
local button = _G["LFRBrowseFrameListButton" .. i];
if (LFRBrowseFrame.selectedName == button.unitName) then
button:LockHighlight();
else
button:UnlockHighlight();
end
update_buttons();
end
end
-- Setup LFR browser hooks
LFRBrowse_UpdateButtonStates = update_buttons
LFRBrowseFrameList_Update = RaidBrowser.gui.update_list
LFRBrowseFrameListButton_SetData = insert_lfm_button
-- Set the "Browse" tab to be active.
LFRFrame_SetActiveTab(2)
LFRParentFrameTab1:Hide();
LFRParentFrameTab2:Hide();