Skip to content

Commit

Permalink
feat: finished nui handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ardelan869 committed Sep 26, 2024
1 parent 9140bd6 commit 2b29aa1
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion client/main.lua
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
-- TODO: Handle NUI, etc
RESOURCE_NAME = 'ragemenu';
LAST_RESOURCE = nil;

exports('SendNUIMessage', function(message)
local resource = GetInvokingResource();

if not resource then
return;
end

LAST_RESOURCE = resource;

SendNUIMessage(message);
end);

exports('SetNuiFocus', SetNuiFocus);
exports('SetNuiFocusKeepInput', SetNuiFocusKeepInput);

for _, callback in next, {
'OnSelect',
'OnChange',
'OnCheck',
'OnClick',
'Exit'
} do
RegisterNUICallback(callback, function(req, resp)
if not req.menu.resource then
return resp('OK');
end

local import <const> = exports[req.menu.resource];

if not import then
return resp('OK');
end

if callback == 'Exit' then
LAST_RESOURCE = nil;
end

import:Emit(callback, req);

resp('OK');
end);
end

AddEventHandler('onResourceStop', function(resource)
if LAST_RESOURCE == resource then
SendNUIMessage({ action = 'SetItems' });
end
end);

0 comments on commit 2b29aa1

Please sign in to comment.