forked from ImBaphomettt/RageUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuController.lua
339 lines (306 loc) · 11.8 KB
/
MenuController.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
---
--- @author Dylan MALANDAIN, Kalyptus
--- @version 1.0.0
--- created at [24/05/2021 10:02]
---
RageUI.LastControl = false
local ControlActions = {
'Left',
'Right',
'Select',
'Click',
}
---GoUp
---@param Options number
---@return nil
---@public
function RageUI.GoUp(Options)
local CurrentMenu = RageUI.CurrentMenu;
if CurrentMenu ~= nil then
Options = CurrentMenu.Options
if CurrentMenu() then
if (Options ~= 0) then
if Options > CurrentMenu.Pagination.Total then
if CurrentMenu.Index <= CurrentMenu.Pagination.Minimum then
if CurrentMenu.Index == 1 then
CurrentMenu.Pagination.Minimum = Options - (CurrentMenu.Pagination.Total - 1)
CurrentMenu.Pagination.Maximum = Options
CurrentMenu.Index = Options
else
CurrentMenu.Pagination.Minimum = (CurrentMenu.Pagination.Minimum - 1)
CurrentMenu.Pagination.Maximum = (CurrentMenu.Pagination.Maximum - 1)
CurrentMenu.Index = CurrentMenu.Index - 1
end
else
CurrentMenu.Index = CurrentMenu.Index - 1
end
else
if CurrentMenu.Index == 1 then
CurrentMenu.Pagination.Minimum = Options - (CurrentMenu.Pagination.Total - 1)
CurrentMenu.Pagination.Maximum = Options
CurrentMenu.Index = Options
else
CurrentMenu.Index = CurrentMenu.Index - 1
end
end
Audio.PlaySound(RageUI.Settings.Audio.UpDown.audioName, RageUI.Settings.Audio.UpDown.audioRef)
RageUI.LastControl = true
if (CurrentMenu.onIndexChange ~= nil) then
CurrentMenu.onIndexChange(CurrentMenu.Index)
end
else
Audio.PlaySound(RageUI.Settings.Audio.Error.audioName, RageUI.Settings.Audio.Error.audioRef)
end
end
end
end
---GoDown
---@param Options number
---@return nil
---@public
function RageUI.GoDown(Options)
local CurrentMenu = RageUI.CurrentMenu;
if CurrentMenu ~= nil then
Options = CurrentMenu.Options
if CurrentMenu() then
if (Options ~= 0) then
if Options > CurrentMenu.Pagination.Total then
if CurrentMenu.Index >= CurrentMenu.Pagination.Maximum then
if CurrentMenu.Index == Options then
CurrentMenu.Pagination.Minimum = 1
CurrentMenu.Pagination.Maximum = CurrentMenu.Pagination.Total
CurrentMenu.Index = 1
else
CurrentMenu.Pagination.Maximum = (CurrentMenu.Pagination.Maximum + 1)
CurrentMenu.Pagination.Minimum = CurrentMenu.Pagination.Maximum - (CurrentMenu.Pagination.Total - 1)
CurrentMenu.Index = CurrentMenu.Index + 1
end
else
CurrentMenu.Index = CurrentMenu.Index + 1
end
else
if CurrentMenu.Index == Options then
CurrentMenu.Pagination.Minimum = 1
CurrentMenu.Pagination.Maximum = CurrentMenu.Pagination.Total
CurrentMenu.Index = 1
else
CurrentMenu.Index = CurrentMenu.Index + 1
end
end
Audio.PlaySound(RageUI.Settings.Audio.UpDown.audioName, RageUI.Settings.Audio.UpDown.audioRef)
RageUI.LastControl = false
if (CurrentMenu.onIndexChange ~= nil) then
CurrentMenu.onIndexChange(CurrentMenu.Index)
end
else
Audio.PlaySound(RageUI.Settings.Audio.Error.audioName, RageUI.Settings.Audio.Error.audioRef)
end
end
end
end
function RageUI.GoActionControl(Controls, Action)
if Controls[Action or 'Left'].Enabled then
for Index = 1, #Controls[Action or 'Left'].Keys do
if not Controls[Action or 'Left'].Pressed then
if IsDisabledControlJustPressed(Controls[Action or 'Left'].Keys[Index][1], Controls[Action or 'Left'].Keys[Index][2]) then
Controls[Action or 'Left'].Pressed = true
Citizen.CreateThread(function()
Controls[Action or 'Left'].Active = true
Citizen.Wait(0.01)
Controls[Action or 'Left'].Active = false
Citizen.Wait(175)
while Controls[Action or 'Left'].Enabled and IsDisabledControlPressed(Controls[Action or 'Left'].Keys[Index][1], Controls[Action or 'Left'].Keys[Index][2]) do
Controls[Action or 'Left'].Active = true
Citizen.Wait(1)
Controls[Action or 'Left'].Active = false
Citizen.Wait(124)
end
Controls[Action or 'Left'].Pressed = false
if (Action ~= ControlActions[5]) then
Citizen.Wait(10)
end
end)
break
end
end
end
end
end
function RageUI.GoActionControlSlider(Controls, Action)
if Controls[Action].Enabled then
for Index = 1, #Controls[Action].Keys do
if not Controls[Action].Pressed then
if IsDisabledControlJustPressed(Controls[Action].Keys[Index][1], Controls[Action].Keys[Index][2]) then
Controls[Action].Pressed = true
Citizen.CreateThread(function()
Controls[Action].Active = true
Citizen.Wait(1)
Controls[Action].Active = false
while Controls[Action].Enabled and IsDisabledControlPressed(Controls[Action].Keys[Index][1], Controls[Action].Keys[Index][2]) do
Controls[Action].Active = true
Citizen.Wait(1)
Controls[Action].Active = false
end
Controls[Action].Pressed = false
end)
break
end
end
end
end
end
---Controls
---@return nil
---@public
function RageUI.Controls()
local CurrentMenu = RageUI.CurrentMenu;
if CurrentMenu ~= nil then
if CurrentMenu() then
if CurrentMenu.Open then
local Controls = CurrentMenu.Controls;
local Options = CurrentMenu.Options
RageUI.Options = CurrentMenu.Options
if CurrentMenu.EnableMouse then
DisableAllControlActions(2)
end
if not IsInputDisabled(2) then
for Index = 1, #Controls.Enabled.Controller do
EnableControlAction(Controls.Enabled.Controller[Index][1], Controls.Enabled.Controller[Index][2], true)
end
else
for Index = 1, #Controls.Enabled.Keyboard do
EnableControlAction(Controls.Enabled.Keyboard[Index][1], Controls.Enabled.Keyboard[Index][2], true)
end
end
if Controls.Up.Enabled then
for Index = 1, #Controls.Up.Keys do
if not Controls.Up.Pressed then
if IsDisabledControlJustPressed(Controls.Up.Keys[Index][1], Controls.Up.Keys[Index][2]) then
Controls.Up.Pressed = true
Citizen.CreateThread(function()
RageUI.GoUp(Options)
Citizen.Wait(175)
while Controls.Up.Enabled and IsDisabledControlPressed(Controls.Up.Keys[Index][1], Controls.Up.Keys[Index][2]) do
RageUI.GoUp(Options)
Citizen.Wait(50)
end
Controls.Up.Pressed = false
end)
break
end
end
end
end
if Controls.Down.Enabled then
for Index = 1, #Controls.Down.Keys do
if not Controls.Down.Pressed then
if IsDisabledControlJustPressed(Controls.Down.Keys[Index][1], Controls.Down.Keys[Index][2]) then
Controls.Down.Pressed = true
Citizen.CreateThread(function()
RageUI.GoDown(Options)
Citizen.Wait(175)
while Controls.Down.Enabled and IsDisabledControlPressed(Controls.Down.Keys[Index][1], Controls.Down.Keys[Index][2]) do
RageUI.GoDown(Options)
Citizen.Wait(50)
end
Controls.Down.Pressed = false
end)
break
end
end
end
end
for i = 1, #ControlActions do
RageUI.GoActionControl(Controls, ControlActions[i])
end
RageUI.GoActionControlSlider(Controls, 'SliderLeft')
RageUI.GoActionControlSlider(Controls, 'SliderRight')
if Controls.Back.Enabled then
for Index = 1, #Controls.Back.Keys do
if not Controls.Back.Pressed then
if IsDisabledControlJustPressed(Controls.Back.Keys[Index][1], Controls.Back.Keys[Index][2]) then
Controls.Back.Pressed = true
Citizen.CreateThread(function()
Citizen.Wait(175)
Controls.Down.Pressed = false
end)
break
end
end
end
end
end
end
end
end
---Navigation
---@return nil
---@public
function RageUI.Navigation()
local CurrentMenu = RageUI.CurrentMenu;
if CurrentMenu ~= nil then
if CurrentMenu() and (CurrentMenu.Display.Navigation) then
if CurrentMenu.EnableMouse then
SetMouseCursorActiveThisFrame()
end
if RageUI.Options > CurrentMenu.Pagination.Total then
local UpHovered = false
local DownHovered = false
if not CurrentMenu.SafeZoneSize then
CurrentMenu.SafeZoneSize = { X = 0, Y = 0 }
if CurrentMenu.Safezone then
CurrentMenu.SafeZoneSize = RageUI.GetSafeZoneBounds()
SetScriptGfxAlign(76, 84)
SetScriptGfxAlignParams(0, 0, 0, 0)
end
end
if CurrentMenu.EnableMouse then
UpHovered = Graphics.IsMouseInBounds(CurrentMenu.X + CurrentMenu.SafeZoneSize.X, CurrentMenu.Y + CurrentMenu.SafeZoneSize.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Rectangle.Width + CurrentMenu.WidthOffset, RageUI.Settings.Items.Navigation.Rectangle.Height)
DownHovered = Graphics.IsMouseInBounds(CurrentMenu.X + CurrentMenu.SafeZoneSize.X, CurrentMenu.Y + RageUI.Settings.Items.Navigation.Rectangle.Height + CurrentMenu.SafeZoneSize.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Rectangle.Width + CurrentMenu.WidthOffset, RageUI.Settings.Items.Navigation.Rectangle.Height)
if CurrentMenu.Controls.Click.Active then
if UpHovered then
RageUI.GoUp(RageUI.Options)
elseif DownHovered then
RageUI.GoDown(RageUI.Options)
end
end
if UpHovered then
Graphics.Rectangle(CurrentMenu.X, CurrentMenu.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Rectangle.Width + CurrentMenu.WidthOffset, RageUI.Settings.Items.Navigation.Rectangle.Height, 30, 30, 30, 255)
else
Graphics.Rectangle(CurrentMenu.X, CurrentMenu.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Rectangle.Width + CurrentMenu.WidthOffset, RageUI.Settings.Items.Navigation.Rectangle.Height, 0, 0, 0, 200)
end
if DownHovered then
Graphics.Rectangle(CurrentMenu.X, CurrentMenu.Y + RageUI.Settings.Items.Navigation.Rectangle.Height + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Rectangle.Width + CurrentMenu.WidthOffset, RageUI.Settings.Items.Navigation.Rectangle.Height, 30, 30, 30, 255)
else
Graphics.Rectangle(CurrentMenu.X, CurrentMenu.Y + RageUI.Settings.Items.Navigation.Rectangle.Height + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Rectangle.Width + CurrentMenu.WidthOffset, RageUI.Settings.Items.Navigation.Rectangle.Height, 0, 0, 0, 200)
end
else
Graphics.Rectangle(CurrentMenu.X, CurrentMenu.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Rectangle.Width + CurrentMenu.WidthOffset, RageUI.Settings.Items.Navigation.Rectangle.Height, 0, 0, 0, 200)
Graphics.Rectangle(CurrentMenu.X, CurrentMenu.Y + RageUI.Settings.Items.Navigation.Rectangle.Height + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Rectangle.Width + CurrentMenu.WidthOffset, RageUI.Settings.Items.Navigation.Rectangle.Height, 0, 0, 0, 200)
end
Graphics.Sprite(RageUI.Settings.Items.Navigation.Arrows.Dictionary, RageUI.Settings.Items.Navigation.Arrows.Texture, CurrentMenu.X + RageUI.Settings.Items.Navigation.Arrows.X + (CurrentMenu.WidthOffset / 2), CurrentMenu.Y + RageUI.Settings.Items.Navigation.Arrows.Y + CurrentMenu.SubtitleHeight + RageUI.ItemOffset, RageUI.Settings.Items.Navigation.Arrows.Width, RageUI.Settings.Items.Navigation.Arrows.Height)
RageUI.ItemOffset = RageUI.ItemOffset + (RageUI.Settings.Items.Navigation.Rectangle.Height * 2)
end
end
end
end
---GoBack
---@return nil
---@public
function RageUI.GoBack()
local CurrentMenu = RageUI.CurrentMenu
if CurrentMenu ~= nil then
Audio.PlaySound(RageUI.Settings.Audio.Back.audioName, RageUI.Settings.Audio.Back.audioRef)
if CurrentMenu.Parent ~= nil then
if CurrentMenu.Parent() then
RageUI.NextMenu = CurrentMenu.Parent
else
RageUI.NextMenu = nil
RageUI.Visible(CurrentMenu, false)
end
else
RageUI.NextMenu = nil
RageUI.Visible(CurrentMenu, false)
end
end
end