2022-04-18 23:30:58 +10:00
|
|
|
local input
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@class InputDialogRowProps
|
|
|
|
|
---@field type 'input' | 'number' | 'checkbox' | 'select' | 'slider'
|
|
|
|
|
---@field label string
|
|
|
|
|
---@field options? { value: string, label: string, default?: string }[]
|
|
|
|
|
---@field password? boolean
|
|
|
|
|
---@field icon? string
|
|
|
|
|
---@field iconColor? string
|
|
|
|
|
---@field placeholder? string
|
|
|
|
|
---@field default? string | number
|
|
|
|
|
---@field checked? boolean
|
|
|
|
|
---@field min? number
|
|
|
|
|
---@field max? number
|
|
|
|
|
---@field step? number
|
2022-04-11 15:26:10 +02:00
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@param heading string
|
|
|
|
|
---@param rows string[] | InputDialogRowProps[]
|
|
|
|
|
---@return string[] | number[] | boolean[] | nil
|
|
|
|
|
function lib.inputDialog(heading, rows)
|
|
|
|
|
if input then return end
|
|
|
|
|
input = promise.new()
|
2022-05-02 13:51:01 +02:00
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
-- Backwards compat with string tables
|
|
|
|
|
for i = 1, #rows do
|
|
|
|
|
if type(rows[i]) == 'string' then
|
|
|
|
|
rows[i] = { type = 'input', label = rows[i] --[[@as string]] }
|
|
|
|
|
end
|
|
|
|
|
end
|
2022-05-02 13:51:01 +02:00
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
SetNuiFocus(true, true)
|
|
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'openDialog',
|
|
|
|
|
data = {
|
|
|
|
|
heading = heading,
|
|
|
|
|
rows = rows
|
|
|
|
|
}
|
|
|
|
|
})
|
2022-04-18 23:30:58 +10:00
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
return Citizen.Await(input)
|
2022-04-11 15:26:10 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
RegisterNUICallback('inputData', function(data, cb)
|
2022-09-18 09:06:32 +10:00
|
|
|
cb(1)
|
|
|
|
|
SetNuiFocus(false, false)
|
|
|
|
|
local promise = input
|
|
|
|
|
input = nil
|
|
|
|
|
promise:resolve(data)
|
|
|
|
|
end)
|