-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.lua
More file actions
483 lines (379 loc) · 12.6 KB
/
objects.lua
File metadata and controls
483 lines (379 loc) · 12.6 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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
ui.objects = {}
function ui.objects.createImage(id, path, x, y, style)
local self = {}
self.x = x
self.y = y
self.path = path
self.image = image(path, x, y, 2, id)
self.playerId = id
self.id = ui.user.getObjectId(id, "images")
self.style = style or {}
function self.setPath(path)
if not path then return end
freeimage(self.image)
self.image = image(path, self.x, self.y, 2, id)
self.path = path
self.update()
end
function self.setPos(x, y)
if not x or not y then return end
imagepos(self.image, x, y, imageparam(self.image, "rot"))
self.x = x
self.y = y
end
function self.setStyle(style)
if not style then return end
self.style = style
self.update()
end
function self.update()
self.width = imageparam(self.image, "width")
self.height = imageparam(self.image, "height")
local styleProperties = ui.style.getProperties(self.style)
imagescale(self.image, styleProperties.xScale or 1, styleProperties.yScale or 1)
imagealpha(self.image, styleProperties.alpha or 1)
if styleProperties.color then
imagecolor(self.image, styleProperties.color[1] or 255, styleProperties.color[2] or 255, styleProperties.color[3] or 255)
end
end
function self.remove()
freeimage(self.image)
ui.user.list[id].objects["images"][self.id] = nil
end
self.update()
ui.user.list[id].objects["images"][self.id] = self
return self
end
function ui.objects.createText(id, text, x, y, align, vAlign, style)
local self = {}
self.x = x
self.y = y
self.text = text
self.playerId = id
self.id = ui.user.getObjectId(id, "texts")
if self.id > 200 then
ui.funcs.error("Text couldn't be created, it reached to the limit (> 200).")
return
end
self.style = style or {}
self.align = align or 0
self.vAlign = vAlign or 0
function self.setText(text)
if not text then return end
self.text = text
self.update()
end
function self.setPos(x, y)
if not x or not y then return end
self.x = x
self.y = y
self.update()
end
function self.setAlign(align)
if not align then return end
self.align = align
self.update()
end
function self.setVAlign(vAlign)
if not vAlign then return end
self.vAlign = vAlign
self.update()
end
function self.setStyle(style)
if not style then return end
self.style = style
self.update()
end
function self.removeBackground()
if self.background then
self.background.remove()
end
end
function self.update()
self.width, self.height = textwidth(self.text, textSize), textSize
local styleProperties = ui.style.getProperties(self.style)
local textSize = styleProperties.textSize or 13
if ui.config.textwidthLibrary then
if styleProperties.background and not styleProperties.background.avoidDuplicate then
local padding = (styleProperties.background.padding or 0) * 2
local x, y = self.x, self.y
if self.align == 0 then
x = x + width / 2
elseif self.align == 2 then
x = x - width / 2
end
if self.vAlign == 0 then
y = y + height / 2
elseif self.vAlign == 2 then
y = y - height / 2
end
self.width, self.height = width + padding, height + padding
if self.background then
self.background.setStyle({
xScale = width,
yScale = height,
color = styleProperties.background.color,
alpha = styleProperties.background.alpha
})
else
self.background = ui.objects.createImage(id, ui.funcs.get1x1Image(), x, y, {
xScale = width,
yScale = height,
color = styleProperties.background.color,
alpha = styleProperties.background.alpha
})
end
if self.background then
self.background.setPos(x, y)
end
else
self.removeBackground()
end
end
parse('hudtxt2 '..id..' '..(self.id - 1)..' "\169'..(styleProperties.textColor or "255255255")..self.text..'" '..self.x..' '..self.y..' '..self.align..' '..self.vAlign..' '..textSize)
end
function self.remove()
parse('hudtxt2 '..id..' '..self.id - 1)
ui.user.list[id].objects["texts"][self.id] = nil
end
self.update()
ui.user.list[id].objects["texts"][self.id] = self
return self
end
function ui.objects.createButton(id, text, x, y, width, height, style)
local self = {}
self.x = x
self.y = y
self.width = width
self.height = height
self.text = text
self.textObject = ui.objects.createText(id, text, x, y, 1, 1, style)
self.playerId = id
self.id = ui.user.getObjectId(id, "buttons")
self.style = style or {}
function self.setPos(x, y)
if not x or not y then return end
self.x = x
self.y = y
self.update()
end
function self.setText(text)
if not text then return end
self.text = text
self.update()
end
function self.setSize(width, height)
self.width = width or self.width
self.height = height or self.height
self.update()
end
function self.setStyle(style)
if not style then return end
self.style = style
self.update()
end
function self.removeBackground()
if self.background then
self.background.remove()
end
end
function self.update()
if self.width == true then
self.autosize = true
self.padding = self.height
end
local styleProperties = ui.style.getProperties(self.style)
if self.autosize and ui.config.textwidthLibrary then
local textSize = styleProperties.textSize or 13
local padding = (self.padding or 0) * 2
self.width, self.height = textwidth(self.text, textSize) + padding, textSize + padding
end
if styleProperties.background then
if self.background then
self.background.setStyle({
xScale = self.width,
yScale = self.height,
color = styleProperties.background.color,
alpha = styleProperties.background.alpha
})
else
self.background = ui.objects.createImage(id, ui.funcs.get1x1Image(), self.x, self.y, {
xScale = self.width,
yScale = self.height,
color = styleProperties.background.color,
alpha = styleProperties.background.alpha
})
end
if self.background then
self.background.setPos(x, y)
end
-- Avoiding two different backgrounds from each object
styleProperties.background.avoidDuplicate = true
else
self.removeBackground()
end
self.textObject.setText(self.text)
self.textObject.setPos(self.x, self.y)
self.textObject.setStyle(self.style)
end
function self.remove()
self.removeBackground()
self.textObject.remove()
ui.user.list[id].objects["buttons"][self.id] = nil
end
self.update()
ui.user.list[id].objects["buttons"][self.id] = self
return self
end
function ui.objects.createImageButton(id, path, x, y, width, height, style)
local self = {}
self.x = x
self.y = y
self.path = path
self.width = width
self.height = height
self.imageObject = ui.objects.createImage(id, path, x, y, style)
self.playerId = id
self.id = ui.user.getObjectId(id, "imageButtons")
self.style = style or {}
function self.setPos(x, y)
if not x or not y then return end
self.imageObject.setPos(x, y)
if self.background then
self.background.setPos(x, y)
end
self.x = x
self.y = y
end
function self.setPath(path)
if not path then return end
self.path = path
self.update(true)
end
function self.setSize(width, height)
self.width = width or self.width
self.height = height or self.height
self.update()
end
function self.setStyle(style)
if not style then return end
self.style = style
self.update()
end
function self.removeBackground()
if self.background then
self.background.remove()
end
end
function self.update(updatePath)
local styleProperties = ui.style.getProperties(self.style)
if styleProperties.background then
if self.background then
self.background.setStyle({
xScale = self.width,
yScale = self.height,
color = styleProperties.background.color,
alpha = styleProperties.background.alpha
})
else
self.background = ui.objects.createImage(id, ui.funcs.get1x1Image(), self.x, self.y, {
xScale = self.width,
yScale = self.height,
color = styleProperties.background.color,
alpha = styleProperties.background.alpha
})
end
self.background.setPos(self.x, self.y)
else
self.removeBackground()
end
if updatePath then
self.imageObject.setPath(self.path)
end
self.imageObject.setStyle(self.style)
end
function self.remove()
self.removeBackground()
self.imageObject.remove()
ui.user.list[id].objects["imageButtons"][self.id] = nil
end
self.update()
ui.user.list[id].objects["imageButtons"][self.id] = self
return self
end
function ui.objects.createWindow(id, path, x, y, style, interact, width, height)
local self = {}
self.x = x
self.y = y
self.path = path
self.playerId = id
self.id = ui.user.getObjectId(id, "windows")
self.objects = {}
self.style = style or {}
self.interact = interact or false
self.width = width or false
self.height = height or false
if path == "invisible" then
self.imageObject = false
elseif type(path) == "table" then
self.imageObject = ui.objects.createImage(id, ui.funcs.get1x1Image(), x, y, {
color = {unpack(path[1])},
alpha = path[2],
xScale = width,
yScale = height
})
else
self.imageObject = ui.objects.createImage(id, path, x, y)
end
function self.addObject(...)
for i = 1, #arg do
table.insert(self.objects, arg[i])
end
self.update()
end
function self.removeObject(remove, ...)
for k, v in pairs(self.objects) do
for i = 1, #arg do
if v == arg[i] then
if remove then v.remove() end
self.objects[k] = nil
end
end
end
end
function self.setPos(x, y)
if not x or not y then return end
self.x = x
self.y = y
self.update()
end
function self.setStyle(style)
if not style then return end
self.style = style
self.update()
end
function self.update()
if self.imageObject then
self.imageObject.setPos(self.x, self.y)
end
if self.interact then
for k, v in pairs(self.objects) do
v.setStyle(self.style)
local newX = (v.x / player(id, "screenw")) * self.width
local newY = (v.y / player(id, "screenh")) * self.height
v.setPos(self.x - (self.width / 2) + newX, self.y - (self.height / 2) + newY)
end
end
end
function self.remove()
if self.imageObject then
self.imageObject.remove()
end
for k, v in pairs(self.objects) do
v.remove()
end
ui.user.list[id].objects["windows"][self.id] = nil
end
ui.user.list[id].objects["windows"][self.id] = self
return self
end