-
Notifications
You must be signed in to change notification settings - Fork 178
Expand file tree
/
Copy pathclient.lua
More file actions
123 lines (105 loc) · 3.29 KB
/
client.lua
File metadata and controls
123 lines (105 loc) · 3.29 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
local sharedItems = exports['qb-core']:GetShared('Items')
local headerShown = false
local sendData = nil
-- Functions
local function sortData(data, skipfirst)
local header = data[1]
local tempData = data
if skipfirst then table.remove(tempData, 1) end
table.sort(tempData, function(a, b) return a.header < b.header end)
if skipfirst then table.insert(tempData, 1, header) end
return tempData
end
local function openMenu(data, sort, skipFirst)
if not data or not next(data) then return end
if sort then data = sortData(data, skipFirst) end
for _, v in pairs(data) do
if v['icon'] then
if sharedItems[tostring(v['icon'])] then
if not string.find(sharedItems[tostring(v['icon'])].image, '//') and not string.find(v['icon'], '//') then
v['icon'] = 'nui://qb-inventory/html/images/' .. sharedItems[tostring(v['icon'])].image
end
end
end
end
SetNuiFocus(true, true)
headerShown = false
sendData = data
SendNUIMessage({
action = 'OPEN_MENU',
data = table.clone(data)
})
end
local function closeMenu()
sendData = nil
headerShown = false
SetNuiFocus(false)
SendNUIMessage({
action = 'CLOSE_MENU'
})
end
local function showHeader(data)
if not data or not next(data) then return end
headerShown = true
sendData = data
SendNUIMessage({
action = 'SHOW_HEADER',
data = table.clone(data)
})
end
-- Events
RegisterNetEvent('qb-menu:client:openMenu', function(data, sort, skipFirst)
openMenu(data, sort, skipFirst)
end)
RegisterNetEvent('qb-menu:client:closeMenu', function()
closeMenu()
end)
-- NUI Callbacks
RegisterNUICallback('clickedButton', function(option, cb)
if headerShown then headerShown = false end
PlaySoundFrontend(-1, 'Highlight_Cancel', 'DLC_HEIST_PLANNING_BOARD_SOUNDS', 1)
SetNuiFocus(false)
if sendData then
local data = sendData[tonumber(option)]
sendData = nil
if data.action ~= nil then
data.action()
cb('ok')
return
end
if data then
if data.params.event then
if data.params.isServer then
TriggerServerEvent(data.params.event, data.params.args)
elseif data.params.isCommand then
ExecuteCommand(data.params.event)
elseif data.params.isQBCommand then
TriggerServerEvent('QBCore:CallCommand', data.params.event, data.params.args)
elseif data.params.isAction then
data.params.event(data.params.args)
else
TriggerEvent(data.params.event, data.params.args)
end
end
end
end
cb('ok')
end)
RegisterNUICallback('closeMenu', function(_, cb)
headerShown = false
sendData = nil
SetNuiFocus(false)
cb('ok')
TriggerEvent('qb-menu:client:menuClosed')
end)
-- Command and Keymapping
RegisterCommand('playerfocus', function()
if headerShown then
SetNuiFocus(true, true)
end
end)
RegisterKeyMapping('playerFocus', 'Give Menu Focus', 'keyboard', 'LMENU')
-- Exports
exports('openMenu', openMenu)
exports('closeMenu', closeMenu)
exports('showHeader', showHeader)