Skip to content

Commit

Permalink
Add gui paused event/api.
Browse files Browse the repository at this point in the history
  • Loading branch information
Imagic committed Aug 11, 2017
1 parent d4fde5c commit 91511dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -171,6 +171,8 @@ AddEventHandler("vRP:playerJoinGroup", function(user_id, group, gtype) end)
-- gtype can be nil
AddEventHandler("vRP:playerLeaveGroup", function(user_id, group, gtype) end)

-- (client) called when the menu pause state change
AddEventHandler("vRP:pauseChange", function(paused) end)
```

### API
Expand Down Expand Up @@ -799,6 +801,8 @@ vRP.addStaticMenuChoices(name, choices)

-- TUNNEL CLIENT API

-- return menu paused state
vRP.isPaused()

-- progress bar

Expand Down
23 changes: 22 additions & 1 deletion vrp/client/gui.lua
@@ -1,3 +1,9 @@

-- pause
AddEventHandler("vRP:pauseChange", function(paused)
SendNUIMessage({act="pause_change", paused=paused})
end)

-- MENU

function tvRP.openMenuData(menudata)
Expand Down Expand Up @@ -125,7 +131,13 @@ function tvRP.removeDiv(name)
SendNUIMessage({act="remove_div", name = name})
end

-- CONTROLS
-- CONTROLS/GUI

local paused = false

function tvRP.isPaused()
return paused
end

-- gui controls (from cellphone)
Citizen.CreateThread(function()
Expand All @@ -146,6 +158,15 @@ Citizen.CreateThread(function()
if IsControlJustPressed(table.unpack(cfg.controls.request.yes)) then SendNUIMessage({act="event",event="F5"}) end
if IsControlJustPressed(table.unpack(cfg.controls.request.no)) then SendNUIMessage({act="event",event="F6"}) end

-- pause events
local pause_menu = IsPauseMenuActive()
if pause_menu and not paused then
paused = true
TriggerEvent("vRP:pauseChange", paused)
elseif not pause_menu and paused then
paused = false
TriggerEvent("vRP:pauseChange", paused)
end
end
end)

6 changes: 6 additions & 0 deletions vrp/gui/main.js
Expand Up @@ -43,6 +43,12 @@ window.addEventListener("load",function(){
if(data.act == "cfg"){
cfg = data.cfg
}
else if(data.act == "pause_change"){
if(data.paused)
$(document.body).hide();
else
$(document.body).show();
}
else if(data.act == "open_menu"){ //OPEN DYNAMIC MENU
current_menu.close();
dynamic_menu.open(data.menudata.name,data.menudata.choices);
Expand Down

0 comments on commit 91511dd

Please sign in to comment.