-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclient.lua
248 lines (213 loc) · 6.28 KB
/
client.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
local Settings = {
HelpPosition = 'top-left',
HelpAudio = true,
NotificationStyle = 'clean', -- clean or transparent
NotificationPosition = 'top-right',
NotificationAudio = true,
Volume = 1
}
local Notification_Types = {
['info'] = true,
['warning'] = true,
['error'] = true,
['success'] = true,
}
local Promise = nil
local Locale = {
['accept'] = 'Accept',
['decline'] = 'Decline',
['submit'] = 'Submit'
}
RegisterNUICallback('initialize', function(data, cb)
cb({
locale=Locale
})
end)
RegisterNUICallback('hideFrame', function(data, cb)
SetNuiFocus(false, false)
if Promise then
Promise:resolve(nil)
Promise = nil
end
cb(1)
end)
-- Notification
function SendAlert(title, message, type, duration, position)
type = type or 'info'
if not Notification_Types[type] then
type = 'info'
end
SendNUIMessage({
action='sendAlert',
data={
title=title,
message=message,
type=type,
play=Settings.NotificationAudio,
volume=Settings.Volume,
style=Settings.NotificationStyle,
position=position or Settings.NotificationPosition,
duration=duration
}
})
end
RegisterNetEvent('hud:SendAlert')
AddEventHandler('hud:SendAlert', SendAlert)
exports('SendAlert', SendAlert)
-- Help Text
RegisterNetEvent('hud:displayHelp')
AddEventHandler('hud:displayHelp', displayHelp)
RegisterNetEvent('hud:closeHelp')
AddEventHandler('hud:closeHelp', closeHelp)
function displayHelp(text, position)
SendNUIMessage({
action="displayHelp",
data={
text=text,
play=Settings.HelpAudio,
volume=Settings.Volume,
position=position or Settings.HelpPosition
}
})
end
function closeHelp()
SendNUIMessage({
action="closeHelp",
data={}
})
end
exports('displayHelp', displayHelp)
exports('closeHelp', closeHelp)
-- Settings stuff
RegisterNUICallback('saveSettings', function(data, cb)
Settings = data
cb(1)
end)
RegisterCommand('hudsettings', function()
SendNUIMessage({
action='settings',
data=true
})
SetNuiFocus(true, true)
end)
-- Modal Stuff
RegisterNUICallback('acceptModal', function(data, cb)
Promise:resolve(true)
Promise = nil
cb(1)
end)
RegisterNUICallback('declineModal', function(data, cb)
Promise:resolve(false)
Promise = nil
cb(1)
end)
exports('openModal', function(title, text, acceptCb, declineCb)
SendNUIMessage({
action="openModal",
data={
title=title,
text=text,
}
})
SetNuiFocus(true, true)
Promise = promise.new()
local accepted = Citizen.Await(Promise)
if accepted then
acceptCb()
else
declineCb()
end
end)
exports('closeModal', function()
SendNUIMessage({
action="closeModal",
data={}
})
end)
-- Input Keyboard
RegisterNUICallback('submitKeyboard', function(data, cb)
Promise:resolve(data)
Promise = nil
cb(1)
end)
-- Taken from nh-keyboard https://github.com/nerohiro/nh-keyboard/blob/4167ed31c363738db72c51e124273256781899a3/client.lua#L29
-- Credits to Nerohiro
UnpackInput = function(kb, i)
if not kb then return end
local index = i or 1
if index <= #kb then
return kb[index], UnpackInput(kb, index + 1)
end
end
exports('keyboard', function(title, rows)
SendNUIMessage({
action="openInputKeyboard",
data= {
title=title,
rows=rows
}
})
SetNuiFocus(true, true)
Promise = promise.new()
local results = Citizen.Await(Promise)
return results and true or false, UnpackInput(results)
end)
exports('keybind', function(data)
data.position = data.position or 'center-right'
SendNUIMessage({
action="keybind",
data= data
})
end)
exports('closeKeybind', function()
SendNUIMessage({
action='closeKeybind',
})
end)
RegisterCommand('testnotify', function()
-- Default notification position is on top right
exports['bcs_hud']:SendAlert('Title Here', 'Message of notification here!', 'success', 3000)
Wait(1000)
exports['bcs_hud']:SendAlert('Title Here', 'Message of notification here!', 'error', 3000, 'bottom-right')
Wait(1000)
exports['bcs_hud']:SendAlert('Title Here', 'Message of notification here!', 'warning', 3000, 'bottom-left')
Wait(1000)
exports['bcs_hud']:SendAlert('Title Here', 'Message of notification here!', 'info', 3000, 'top-center')
end)
RegisterCommand('testhelp', function()
-- default position is on top-left
exports['bcs_hud']:displayHelp('Press ~E~ to open something')
Wait(1500)
exports['bcs_hud']:closeHelp()
exports['bcs_hud']:displayHelp('Press ~E~ to open something', 'center-right')
Wait(1500)
exports['bcs_hud']:closeHelp()
exports['bcs_hud']:displayHelp('Press ~E~ to open something', 'top-right')
Wait(1500)
exports['bcs_hud']:closeHelp()
exports['bcs_hud']:displayHelp('Press ~E~ to open something', 'bottom-right')
Wait(1500)
exports['bcs_hud']:closeHelp()
exports['bcs_hud']:displayHelp('Press ~E~ to open something', 'top-center')
Wait(1500)
exports['bcs_hud']:closeHelp()
exports['bcs_hud']:displayHelp('Press ~E~ to open something', 'bottom-right')
Wait(1500)
exports['bcs_hud']:closeHelp()
end)
RegisterCommand('testkeyboard', function()
local result, row1, row2, row3, row4 = exports['bcs_hud']:keyboard('The title here', {
{title='Text Input'},
{title='Number input', type='number'},
{title='Text input with placeholder', placeholder='Place your holder here'},
{title='Other variation of input', type='password'}
})
print(result, row1, row2, row3, row4)
end)
RegisterCommand('testdialog', function()
exports['bcs_hud']:openModal('Confirmation Title','Are you sure you want to confirm this?', function()
print('accepted')
end, function()
print('declined!')
end)
end)