From 88a32d6a6c50fd4da4a79deaa6b8032643937df1 Mon Sep 17 00:00:00 2001 From: Taavi <97351942+Taavi-AU@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:02:14 +0800 Subject: [PATCH 1/6] full context implementation --- [esx_addons]/esx_taxijob/client/main.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/[esx_addons]/esx_taxijob/client/main.lua b/[esx_addons]/esx_taxijob/client/main.lua index 7c363578..afb3b56e 100644 --- a/[esx_addons]/esx_taxijob/client/main.lua +++ b/[esx_addons]/esx_taxijob/client/main.lua @@ -238,15 +238,18 @@ function OpenMobileTaxiActionsMenu() ESX.OpenContext("right", elements, function(menu,element) if element.value == "billing" then - ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'billing', { - title = TranslateCap('invoice_amount') - }, function(data, menu) + local elements2 = { + {unselectable = true, icon = "fas fa-taxi", title = element.title}, + {title = "Amount", input = true, inputType = "number", inputMin = 1, inputMax = 250000, inputPlaceholder = "Amount to bill.."}, + {icon = "fas fa-check-double", title = "Confirm", value = "confirm"} + } - local amount = tonumber(data.value) + ESX.OpenContext("right", elements2, function(menu2,element2) + local amount = tonumber(menu2.eles[2].inputValue) if amount == nil then ESX.ShowNotification(TranslateCap('amount_invalid')) else - menu.close() + ESX.CloseContext() local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() if closestPlayer == -1 or closestDistance > 3.0 then ESX.ShowNotification(TranslateCap('no_players_near')) @@ -256,8 +259,6 @@ function OpenMobileTaxiActionsMenu() ESX.ShowNotification(TranslateCap('billing_sent')) end end - end, function(data, menu) - menu.close() end) elseif element.value == "start_job" then if OnJob then From d5888d3ff09079eec7d589877a66c617b1a30d16 Mon Sep 17 00:00:00 2001 From: Taavi <97351942+Taavi-AU@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:12:03 +0800 Subject: [PATCH 2/6] remove is menu open check --- [esx]/es_extended/client/main.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/[esx]/es_extended/client/main.lua b/[esx]/es_extended/client/main.lua index b613f741..5c35d413 100644 --- a/[esx]/es_extended/client/main.lua +++ b/[esx]/es_extended/client/main.lua @@ -250,9 +250,7 @@ if not Config.OxInventory then ESX.UI.ShowInventoryItemNotification(true, item, count) end - if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then - ESX.ShowInventory() - end + ESX.ShowInventory() end) RegisterNetEvent('esx:removeInventoryItem') @@ -269,9 +267,7 @@ if not Config.OxInventory then ESX.UI.ShowInventoryItemNotification(false, item, count) end - if ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then - ESX.ShowInventory() - end + ESX.ShowInventory() end) RegisterNetEvent('esx:addWeapon') @@ -463,7 +459,7 @@ end if not Config.OxInventory and Config.EnableDefaultInventory then RegisterCommand('showinv', function() - if not ESX.PlayerData.dead and not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then + if not ESX.PlayerData.dead then ESX.ShowInventory() end end) From 25b1660fef3aa3363e9a61ae1aee8ac6510a91d2 Mon Sep 17 00:00:00 2001 From: Taavi <97351942+Taavi-AU@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:12:46 +0800 Subject: [PATCH 3/6] inventory context implementation --- [esx]/es_extended/client/functions.lua | 248 ++++++++++++------------- 1 file changed, 122 insertions(+), 126 deletions(-) diff --git a/[esx]/es_extended/client/functions.lua b/[esx]/es_extended/client/functions.lua index d59e240c..3be7d9c7 100644 --- a/[esx]/es_extended/client/functions.lua +++ b/[esx]/es_extended/client/functions.lua @@ -1088,22 +1088,26 @@ end function ESX.ShowInventory() local playerPed = ESX.PlayerData.ped - local elements, currentWeight = {}, 0 + local elements = { + {unselectable = true, icon = 'fas fa-box', title = 'Player Inventory'} + } + local currentWeight = 0 for i=1, #(ESX.PlayerData.accounts) do if ESX.PlayerData.accounts[i].money > 0 then - local formattedMoney = TranslateCap('locale_currency', ESX.Math.GroupDigits(ESX.PlayerData.accounts[i].money)) + local formattedMoney = _U('locale_currency', ESX.Math.GroupDigits(ESX.PlayerData.accounts[i].money)) local canDrop = ESX.PlayerData.accounts[i].name ~= 'bank' - table.insert(elements, { - label = ('%s: %s'):format(ESX.PlayerData.accounts[i].label, formattedMoney), + elements[#elements+1] = { + icon = 'fas fa-money-bill-wave', + title = ('%s: %s'):format(ESX.PlayerData.accounts[i].label, formattedMoney), count = ESX.PlayerData.accounts[i].money, type = 'item_account', value = ESX.PlayerData.accounts[i].name, usable = false, rare = false, canRemove = canDrop - }) + } end end @@ -1111,15 +1115,16 @@ function ESX.ShowInventory() if v.count > 0 then currentWeight = currentWeight + (v.weight * v.count) - table.insert(elements, { - label = ('%s x%s'):format(v.label, v.count), + elements[#elements+1] = { + icon = 'fas fa-box', + title = ('%s x%s'):format(v.label, v.count), count = v.count, type = 'item_standard', value = v.name, usable = v.usable, rare = v.rare, canRemove = v.canRemove - }) + } end end @@ -1135,8 +1140,9 @@ function ESX.ShowInventory() label = v.label end - table.insert(elements, { - label = label, + elements[#elements+1] = { + icon = 'fas fa-gun', + title = label, count = 1, type = 'item_weapon', value = v.name, @@ -1145,76 +1151,80 @@ function ESX.ShowInventory() ammo = ammo, canGiveAmmo = (v.ammo ~= nil), canRemove = true - }) + } end end - ESX.UI.Menu.CloseAll() + elements[#elements+1] = { + unselectable = true, + icon = "fas fa-weight", + title = "Current Weight: "..currentWeight + } + + ESX.CloseContext() - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'inventory', { - title = TranslateCap('inventory', currentWeight, ESX.PlayerData.maxWeight), - align = 'bottom-right', - elements = elements - }, function(data, menu) - menu.close() + ESX.OpenContext("right", elements, function(menu,element) local player, distance = ESX.Game.GetClosestPlayer() - elements = {} - if data.current.usable then - table.insert(elements, { - label = TranslateCap('use'), + elements2 = {} + + if element.usable then + elements2[#elements2+1] = { + icon = "fas fa-utensils", + title = _U('use'), action = 'use', - type = data.current.type, - value = data.current.value - }) + type = element.type, + value = element.value + } end - if data.current.canRemove then + if element.canRemove then if player ~= -1 and distance <= 3.0 then - table.insert(elements, { - label = TranslateCap('give'), + elements2[#elements2+1] = { + icon = "fas fa-hands", + title = _U('give'), action = 'give', - type = data.current.type, - value = data.current.value - }) + type = element.type, + value = element.value + } end - table.insert(elements, { - label = TranslateCap('remove'), + elements2[#elements2+1] = { + icon = "fas fa-trash", + title = _U('remove'), action = 'remove', - type = data.current.type, - value = data.current.value - }) + type = element.type, + value = element.value + } end - if data.current.type == 'item_weapon' and data.current.canGiveAmmo and data.current.ammo > 0 and player ~= -1 and - distance <= 3.0 then - table.insert(elements, { - label = TranslateCap('giveammo'), + if element.type == 'item_weapon' and element.canGiveAmmo and element.ammo > 0 and player ~= -1 and distance <= 3.0 then + elements2[#elements2+1] = { + icon = "fas fa-gun", + title = _U('giveammo'), action = 'give_ammo', - type = data.current.type, - value = data.current.value - }) + type = element.type, + value = element.value + } end - table.insert(elements, { - label = TranslateCap('return'), + elements2[#elements2+1] = { + icon = "fas fa-arrow-left", + title = _U('return'), action = 'return' - }) + } - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'inventory_item', { - title = data.current.label, - align = 'bottom-right', - elements = elements - }, function(data1, menu1) - local item, type = data1.current.value, data1.current.type + ESX.OpenContext("right", elements2, function(menu2,element2) + local item, type = element2.value, element2.type - if data1.current.action == 'give' then + if element2.action == "give" then local playersNearby = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0) if #playersNearby > 0 then local players = {} - elements = {} + elements3 = { + {unselectable = true, icon = "fas fa-users", title = "Nearby Players"} + } for k, playerNearby in ipairs(playersNearby) do players[GetPlayerServerId(playerNearby)] = true @@ -1222,19 +1232,15 @@ function ESX.ShowInventory() ESX.TriggerServerCallback('esx:getPlayerNames', function(returnedPlayers) for playerId, playerName in pairs(returnedPlayers) do - table.insert(elements, { - label = playerName, + elements3[#elements3+1] = { + icon = "fas fa-user", + title = playerName, playerId = playerId - }) + } end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'give_item_to', { - title = TranslateCap('give_to'), - align = 'bottom-right', - elements = elements - }, function(data2, menu2) - local selectedPlayer, selectedPlayerId = GetPlayerFromServerId(data2.current.playerId), - data2.current.playerId + ESX.OpenContext("right", elements3, function(menu3,element3) + local selectedPlayer, selectedPlayerId = GetPlayerFromServerId(element3.playerId), element3.playerId playersNearby = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0) playersNearby = ESX.Table.Set(playersNearby) @@ -1244,80 +1250,75 @@ function ESX.ShowInventory() if IsPedOnFoot(selectedPlayerPed) and not IsPedFalling(selectedPlayerPed) then if type == 'item_weapon' then TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, type, item, nil) - menu2.close() - menu1.close() + ESX.CloseContext() else - ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), - 'inventory_item_count_give', { - title = TranslateCap('amount') - }, function(data3, menu3) - local quantity = tonumber(data3.value) + local elementsG = { + {unselectable = true, icon = "fas fa-trash", title = element.title}, + {icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to give..", inputMin = 1, inputMax = 1000}, + {icon = "fas fa-check-double", title = "Confirm", val = "confirm"} + } - if quantity and quantity > 0 and data.current.count >= quantity then - TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, type, - item, quantity) - menu3.close() - menu2.close() - menu1.close() - else - ESX.ShowNotification(TranslateCap('amount_invalid')) - end - end, function(data3, menu3) - menu3.close() - end) + ESX.OpenContext("right", elementsG, function(menuG,elementG) + local quantity = tonumber(menuG.eles[2].inputValue) + + if quantity and quantity > 0 and element.count >= quantity then + TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, type, item, quantity) + ESX.CloseContext() + else + ESX.ShowNotification(_U('amount_invalid')) + end + end) end else - ESX.ShowNotification(TranslateCap('in_vehicle')) + ESX.ShowNotification(_U('in_vehicle')) end else - ESX.ShowNotification(TranslateCap('players_nearby')) - menu2.close() + ESX.ShowNotification(_U('players_nearby')) + ESX.CloseContext() end - end, function(data2, menu2) - menu2.close() end) end, players) - else - ESX.ShowNotification(TranslateCap('players_nearby')) end - elseif data1.current.action == 'remove' then + elseif element2.action == "remove" then if IsPedOnFoot(playerPed) and not IsPedFalling(playerPed) then local dict, anim = 'weapons@first_person@aim_rng@generic@projectile@sticky_bomb@', 'plant_floor' ESX.Streaming.RequestAnimDict(dict) if type == 'item_weapon' then - menu1.close() + ESX.CloseContext() TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, 1000, 16, 0.0, false, false, false) RemoveAnimDict(dict) Wait(1000) TriggerServerEvent('esx:removeInventoryItem', type, item) else - ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_remove', { - title = TranslateCap('amount') - }, function(data2, menu2) - local quantity = tonumber(data2.value) + local elementsR = { + {unselectable = true, icon = "fas fa-trash", title = element.title}, + {icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to remove..", inputMin = 1, inputMax = 1000}, + {icon = "fas fa-check-double", title = "Confirm", val = "confirm"} + } - if quantity and quantity > 0 and data.current.count >= quantity then - menu2.close() - menu1.close() + ESX.OpenContext("right", elementsR, function(menuR,elementR) + local quantity = tonumber(menuR.eles[2].inputValue) + + if quantity and quantity > 0 and element.count >= quantity then + ESX.CloseContext() TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, 1000, 16, 0.0, false, false, false) RemoveAnimDict(dict) Wait(1000) TriggerServerEvent('esx:removeInventoryItem', type, item, quantity) else - ESX.ShowNotification(TranslateCap('amount_invalid')) + ESX.ShowNotification(_U('amount_invalid')) end - end, function(data2, menu2) - menu2.close() end) end end - elseif data1.current.action == 'use' then + elseif element2.action == "use" then + ESX.CloseContext() TriggerServerEvent('esx:useItem', item) - elseif data1.current.action == 'return' then - ESX.UI.Menu.CloseAll() + elseif element2.action == "return" then + ESX.CloseContext() ESX.ShowInventory() - elseif data1.current.action == 'give_ammo' then + elseif element2.action == "give_ammo" then local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer() local closestPed = GetPlayerPed(closestPlayer) local pedAmmo = GetAmmoInPedWeapon(playerPed, joaat(item)) @@ -1325,42 +1326,37 @@ function ESX.ShowInventory() if IsPedOnFoot(closestPed) and not IsPedFalling(closestPed) then if closestPlayer ~= -1 and closestDistance < 3.0 then if pedAmmo > 0 then - ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', { - title = TranslateCap('amountammo') - }, function(data2, menu2) - local quantity = tonumber(data2.value) + local elementsGA = { + {unselectable = true, icon = "fas fa-trash", title = element.title}, + {icon = "fas fa-tally", title = "Amount.", input = true, inputType = "number", inputPlaceholder = "Amount to give..", inputMin = 1, inputMax = 1000}, + {icon = "fas fa-check-double", title = "Confirm", val = "confirm"} + } + + ESX.OpenContext("right", elementsGA, function(menuGA,elementGA) + local quantity = tonumber(menuGA.eles[2].inputValue) if quantity and quantity > 0 then if pedAmmo >= quantity then - TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), - 'item_ammo', item, quantity) - menu2.close() - menu1.close() + TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), 'item_ammo', item, quantity) + ESX.CloseContext() else - ESX.ShowNotification(TranslateCap('noammo')) + ESX.ShowNotification(_U('noammo')) end else - ESX.ShowNotification(TranslateCap('amount_invalid')) + ESX.ShowNotification(_U('amount_invalid')) end - end, function(data2, menu2) - menu2.close() end) else - ESX.ShowNotification(TranslateCap('noammo')) + ESX.ShowNotification(_U('noammo')) end else - ESX.ShowNotification(TranslateCap('players_nearby')) + ESX.ShowNotification(_U('players_nearby')) end else - ESX.ShowNotification(TranslateCap('in_vehicle')) + ESX.ShowNotification(_U('in_vehicle')) end end - end, function(data1, menu1) - ESX.UI.Menu.CloseAll() - ESX.ShowInventory() end) - end, function(data, menu) - menu.close() end) end From 04ebf295f607b97a608452164c176de855651dc5 Mon Sep 17 00:00:00 2001 From: Taavi <97351942+Taavi-AU@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:13:46 +0800 Subject: [PATCH 4/6] remove closeall func --- [esx]/esx_multicharacter/client/main.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/[esx]/esx_multicharacter/client/main.lua b/[esx]/esx_multicharacter/client/main.lua index 69365dee..ca6f89ac 100644 --- a/[esx]/esx_multicharacter/client/main.lua +++ b/[esx]/esx_multicharacter/client/main.lua @@ -35,7 +35,6 @@ if ESX.GetConfig().Multichar then RenderScriptCams(true, false, 1, true, true) SetCamCoord(cam, offset.x, offset.y, offset.z) PointCamAtCoord(cam, Config.Spawn.x, Config.Spawn.y, Config.Spawn.z + 1.3) - ESX.UI.Menu.CloseAll() ESX.UI.HUD.SetDisplay(0.0) StartLoop() ShutdownLoadingScreen() From fa8b7d6068d6c713d77f0634def1033ce05d5764 Mon Sep 17 00:00:00 2001 From: Taavi <97351942+Taavi-AU@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:16:40 +0800 Subject: [PATCH 5/6] fix _U to TranslateCap --- [esx]/es_extended/client/functions.lua | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/[esx]/es_extended/client/functions.lua b/[esx]/es_extended/client/functions.lua index 3be7d9c7..77ac0dc5 100644 --- a/[esx]/es_extended/client/functions.lua +++ b/[esx]/es_extended/client/functions.lua @@ -1095,7 +1095,7 @@ function ESX.ShowInventory() for i=1, #(ESX.PlayerData.accounts) do if ESX.PlayerData.accounts[i].money > 0 then - local formattedMoney = _U('locale_currency', ESX.Math.GroupDigits(ESX.PlayerData.accounts[i].money)) + local formattedMoney = TranslateCap('locale_currency', ESX.Math.GroupDigits(ESX.PlayerData.accounts[i].money)) local canDrop = ESX.PlayerData.accounts[i].name ~= 'bank' elements[#elements+1] = { @@ -1171,7 +1171,7 @@ function ESX.ShowInventory() if element.usable then elements2[#elements2+1] = { icon = "fas fa-utensils", - title = _U('use'), + title = TranslateCap('use'), action = 'use', type = element.type, value = element.value @@ -1182,7 +1182,7 @@ function ESX.ShowInventory() if player ~= -1 and distance <= 3.0 then elements2[#elements2+1] = { icon = "fas fa-hands", - title = _U('give'), + title = TranslateCap('give'), action = 'give', type = element.type, value = element.value @@ -1191,7 +1191,7 @@ function ESX.ShowInventory() elements2[#elements2+1] = { icon = "fas fa-trash", - title = _U('remove'), + title = TranslateCap('remove'), action = 'remove', type = element.type, value = element.value @@ -1201,7 +1201,7 @@ function ESX.ShowInventory() if element.type == 'item_weapon' and element.canGiveAmmo and element.ammo > 0 and player ~= -1 and distance <= 3.0 then elements2[#elements2+1] = { icon = "fas fa-gun", - title = _U('giveammo'), + title = TranslateCap('giveammo'), action = 'give_ammo', type = element.type, value = element.value @@ -1210,7 +1210,7 @@ function ESX.ShowInventory() elements2[#elements2+1] = { icon = "fas fa-arrow-left", - title = _U('return'), + title = TranslateCap('return'), action = 'return' } @@ -1265,15 +1265,15 @@ function ESX.ShowInventory() TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, type, item, quantity) ESX.CloseContext() else - ESX.ShowNotification(_U('amount_invalid')) + ESX.ShowNotification(TranslateCap('amount_invalid')) end end) end else - ESX.ShowNotification(_U('in_vehicle')) + ESX.ShowNotification(TranslateCap('in_vehicle')) end else - ESX.ShowNotification(_U('players_nearby')) + ESX.ShowNotification(TranslateCap('players_nearby')) ESX.CloseContext() end end) @@ -1307,7 +1307,7 @@ function ESX.ShowInventory() Wait(1000) TriggerServerEvent('esx:removeInventoryItem', type, item, quantity) else - ESX.ShowNotification(_U('amount_invalid')) + ESX.ShowNotification(TranslateCap('amount_invalid')) end end) end @@ -1340,20 +1340,20 @@ function ESX.ShowInventory() TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), 'item_ammo', item, quantity) ESX.CloseContext() else - ESX.ShowNotification(_U('noammo')) + ESX.ShowNotification(TranslateCap('noammo')) end else - ESX.ShowNotification(_U('amount_invalid')) + ESX.ShowNotification(TranslateCap('amount_invalid')) end end) else - ESX.ShowNotification(_U('noammo')) + ESX.ShowNotification(TranslateCap('noammo')) end else - ESX.ShowNotification(_U('players_nearby')) + ESX.ShowNotification(TranslateCap('players_nearby')) end else - ESX.ShowNotification(_U('in_vehicle')) + ESX.ShowNotification(TranslateCap('in_vehicle')) end end end) From 14b852dee1e7be7960da76ea6248413eca5ae57f Mon Sep 17 00:00:00 2001 From: Taavi <97351942+Taavi-AU@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:26:49 +0800 Subject: [PATCH 6/6] closecontext func --- [esx_addons]/esx_shops/client/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/[esx_addons]/esx_shops/client/main.lua b/[esx_addons]/esx_shops/client/main.lua index 1d12688d..f2077b0f 100644 --- a/[esx_addons]/esx_shops/client/main.lua +++ b/[esx_addons]/esx_shops/client/main.lua @@ -49,7 +49,7 @@ end) AddEventHandler('esx_shops:hasExitedMarker', function(zone) currentAction = nil - ESX.UI.Menu.CloseAll() + ESX.CloseContext() end) -- Create Blips