forked from Epix-Incorporated/Adonis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.luau
More file actions
356 lines (299 loc) · 8.96 KB
/
List.luau
File metadata and controls
356 lines (299 loc) · 8.96 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
client, service = nil, nil
return function(data, env)
if env then
setfenv(1, env)
end
local Name = data.Name
local Title = data.Title
local TitleButtons = data.TitleButtons or {}
local Icon = data.Icon
local Tabs = data.Tabs
local Tab = data.Table or data.Tab
local Update = data.Update
local UpdateArg = data.UpdateArg
local UpdateArgs = data.UpdateArgs
local AutoUpdate = data.AutoUpdate
local LoadTime = data.LoadTime
local gIndex = data.gIndex
local gTable = data.gTable
local Dots = data.Dots
local Size = data.Size
local Sanitize = data.Sanitize
local Stacking = data.Stacking
local PagesEnabled = (data.PagesEnabled ~= nil and data.PagesEnabled) or (data.PagesEnabled == nil and true)
local PageSize = data.PageSize or 100
local PageNumber = data.PageNumber or 1
local PageCounter = PageNumber or 1
local RichText = data.RichTextSupported or data.RichTextAllowed or data.RichText
local TextSelectable = data.TextSelectable
local TimeOptions = data.TimeOptions
local getListTab, getPage
local doSearch, genList
local window, scroller, search
local lastPageButton, nextPageButton, pageCounterLabel;
local currentListTab
local pageDebounce
local genDebounce = false
function getPage(tab, pageNum)
if not PagesEnabled then
return tab
end
local pageNum = pageNum or 1
local startPos = (pageNum-1) * PageSize
local endPos = pageNum *PageSize
local pageList = {}
for i = startPos, endPos do
if tab[i] ~= nil then
table.insert(pageList, tab[i])
end
end
return pageList
end
function getListTab(Tab)
local newTab = {}
for i, v in ipairs(Tab) do
if type(v) == "table" then
newTab[i] = {
Text = v.Text;
Desc = v.Desc;
Color = v.Color;
Time = v.Time;
Filter = v.Filter;
Duplicates = v.Duplicates;
OnClick = v.OnClick;
}
elseif type(v) == "string" then
newTab[i] = {
Text = v;
Desc = v;
}
end
end
if Stacking then
local oldNewTab = newTab
newTab = {}
local lastTab
for _, ent in ipairs(oldNewTab) do
ent.Text = service.EscapeControlCharacters(service.Trim(ent.Text))
ent.Desc = service.EscapeControlCharacters(service.Trim(ent.Desc))
if not lastTab then
lastTab = ent
table.insert(newTab, ent)
else
if lastTab.Text == ent.Text and lastTab.Desc == ent.Desc then
lastTab.Duplicates = (lastTab.Duplicates and lastTab.Duplicates+1) or 2
else
lastTab = ent
table.insert(newTab, ent)
end
end
end
end
for _, v in ipairs(newTab) do
v.Text = (data.Sanitize and service.SanitizeString(v.Text)) or v.Text
if v.Duplicates then
v.Text = `(x{v.Duplicates}) {v.Text}`
end
if v.Time then
v.Text = `[{type(v.Time) == "number" and service.FormatTime(v.Time, TimeOptions) or v.Time}] {v.Text}`
end
end
return newTab
end
function doSearch(tab, text)
local found = {}
text = string.lower(tostring(text)):gsub("%%", "%%%%"):gsub("%[", "%%["):gsub("%]", "%%]")
for _, v in ipairs(tab) do
if text == "" or (type(v) == "string" and string.find(string.lower(v),text)) or (type(v) == "table" and ((v.Text and string.find(string.lower(tostring(v.Text)), text)) or (v.Filter and string.find(string.lower(v.Filter),text)))) then
table.insert(found, v)
end
end
return found
end
function genList(Tab)
local gotList = Tab
if not genDebounce then
genDebounce = true
if search.Text ~= "" then
PageCounter = 1
gotList = getListTab(doSearch(Tab, search.Text))
else
PageCounter = PageNumber
search.Text = ""
search.PlaceholderText = "Search (" .. (#Tab == 1 and "1 Item" or #Tab .. " Items") .. ")";
gotList = getListTab(Tab)
end
if PagesEnabled and #gotList > PageSize then
scroller.Size = UDim2.new(1, -10, 1, -60)
nextPageButton.Visible = true
pageCounterLabel.Visible = true
if currentListTab then
local maxPages = math.ceil(#currentListTab/PageSize)
pageCounterLabel.Text = `Page: {PageCounter}/{maxPages}`
else
pageCounterLabel.Text = `Page: {PageCounter}`
end
if PageCounter > 1 then
lastPageButton.Visible = true
else
lastPageButton.Visible = false
end
else
scroller.Size = UDim2.new(1, -10, 1, -30)
nextPageButton.Visible = false
lastPageButton.Visible = false
pageCounterLabel.Visible = false
end
scroller:ClearAllChildren()
currentListTab = gotList
scroller:GenerateList(getPage(gotList, PageCounter), {
RichTextAllowed = RichText;
TextSelectable = TextSelectable;
})
genDebounce = false
end
end
window = client.UI.Make("Window", {
Name = data.Name or "List";
Title = Title;
Icon = Icon;
Size = Size or {300, 250};
MinSize = {200, 120};
OnRefresh = Update and function()
Tab = client.Remote.Get("UpdateList", Update, unpack(UpdateArgs or {UpdateArg}))
if Tab then
currentListTab = Tab
genList(Tab)
end
end;
RichTextSupport = data.RichTextSupport or data.SupportRichText or false;
})
scroller = window:Add("ScrollingFrame", {
List = {};
ScrollBarThickness = 2;
BackgroundTransparency = 1;
Position = UDim2.new(0, 5, 0, 30);
Size = UDim2.new(1,-10,1,-30); -- UDim2.new(1,-10,1,-60); when paging
--LabelProps = {
-- TextXAlignment = "Left";
--}
})
pageCounterLabel = window:Add("TextLabel", {
Size = UDim2.new(0, 60, 0, 20);
Position = UDim2.new(0.5, -30, 1, -25);
Text = "Page: 1";
BackgroundTransparency = 1;
TextTransparency = 0.5;
TextWrapped = false;
ClipsDescendants = false;
TextXAlignment = "Center";
})
nextPageButton = window:Add("TextButton", {
Size = UDim2.new(0, 50, 0, 20);
Position = UDim2.new(1, -60, 1, -25);
Text = ">";
Visible = false;
Debounce = true;
OnClick = function()
if not pageDebounce then
pageDebounce = true
local origLTrans = nextPageButton.BackgroundTransparency
lastPageButton.BackgroundTransparency = origLTrans + 0.35
local origNTrans = nextPageButton.BackgroundTransparency
nextPageButton.BackgroundTransparency = origNTrans + 0.35
lastPageButton.TextTransparency = 0.8
nextPageButton.TextTransparency = 0.8
if currentListTab then
local maxPages = math.ceil(#currentListTab/PageSize);
PageCounter = math.clamp(PageCounter+1, 1, maxPages);
pageCounterLabel.Text = `Page: {PageCounter}/{maxPages}`
if PageCounter > 1 then
lastPageButton.Visible = true
end
if PageCounter == maxPages then
nextPageButton.Visible = false
end
scroller:ClearAllChildren()
scroller.CanvasPosition = Vector2.new(0, 0)
scroller:GenerateList(getPage(currentListTab, PageCounter), {
RichTextAllowed = RichText;
TextSelectable = TextSelectable;
})
end
lastPageButton.BackgroundTransparency = origLTrans
nextPageButton.BackgroundTransparency = origNTrans
lastPageButton.TextTransparency = 0
nextPageButton.TextTransparency = 0
pageDebounce = false
end
end
})
lastPageButton = window:Add("TextButton", {
Size = UDim2.new(0, 50, 0, 20);
Position = UDim2.new(0, 10, 1, -25);
Text = "<";
Visible = false;
Debounce = true;
OnClick = function()
if not pageDebounce then
pageDebounce = true
local origLTrans = nextPageButton.BackgroundTransparency
lastPageButton.BackgroundTransparency = origLTrans + 0.2
local origNTrans = nextPageButton.BackgroundTransparency
nextPageButton.BackgroundTransparency = origNTrans + 0.2
lastPageButton.TextTransparency = 0.8
nextPageButton.TextTransparency = 0.8
if currentListTab then
local maxPages = math.ceil(#currentListTab/PageSize)
PageCounter = math.clamp(PageCounter-1, 1, maxPages)
pageCounterLabel.Text = `Page: {PageCounter}/{maxPages}`
if PageCounter == 1 then
lastPageButton.Visible = false
end
if PageCounter == maxPages then
nextPageButton.Visible = false
else
nextPageButton.Visible = true
end
scroller:ClearAllChildren()
scroller.CanvasPosition = Vector2.new(0, 0)
scroller:GenerateList(getPage(currentListTab, PageCounter), {
RichTextAllowed = RichText;
TextSelectable = TextSelectable;
})
end
lastPageButton.BackgroundTransparency = origLTrans
nextPageButton.BackgroundTransparency = origNTrans
lastPageButton.TextTransparency = 0
nextPageButton.TextTransparency = 0
pageDebounce = false
end
end
})
for i, v in ipairs(TitleButtons) do
window:AddTitleButton(v)
end
search = window:Add("TextBox", {
Size = UDim2.new(1, -10, 0, 20);
Position = UDim2.new(0, 5, 0, 5);
BackgroundTransparency = 0.5;
BorderSizePixel = 0;
Text = "";
PlaceholderText = "Search";
TextStrokeTransparency = 1;
})
search:GetPropertyChangedSignal("Text"):Connect(function()
currentListTab = Tab
genList(Tab)
end)
--window:SetPosition(UDim2.new(0.25, 0, 0.5, -window.AbsoluteSize.Y/2))
gTable = window.gTable
window:Ready()
currentListTab = Tab
genList(Tab)
if Update and AutoUpdate then
while gTable.Active and task.wait(AutoUpdate) do
window:Refresh()
end
end
end