2022-04-18 23:30:58 +10:00
|
|
|
local input
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@class InputDialogRowProps
|
2023-02-17 11:28:53 +01:00
|
|
|
---@field type 'input' | 'number' | 'checkbox' | 'select' | 'slider' | 'multi-select' | 'date' | 'date-range' | 'time' | 'textarea'
|
2022-09-18 09:06:32 +10:00
|
|
|
---@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
|
2022-10-27 03:17:53 -04:00
|
|
|
---@field disabled? boolean
|
2022-09-18 09:06:32 +10:00
|
|
|
---@field checked? boolean
|
|
|
|
|
---@field min? number
|
|
|
|
|
---@field max? number
|
|
|
|
|
---@field step? number
|
2023-02-17 11:28:53 +01:00
|
|
|
---@field autosize? boolean
|
|
|
|
|
---@field required? boolean
|
|
|
|
|
---@field format? string
|
|
|
|
|
---@field clearable? string
|
2022-10-27 13:45:27 +02:00
|
|
|
---@field description? string
|
2022-04-11 15:26:10 +02:00
|
|
|
|
2023-01-11 20:54:29 +01:00
|
|
|
---@class InputDialogOptionsProps
|
|
|
|
|
---@field allowCancel? boolean
|
|
|
|
|
|
2022-09-18 09:06:32 +10:00
|
|
|
---@param heading string
|
|
|
|
|
---@param rows string[] | InputDialogRowProps[]
|
2023-02-25 18:20:14 +11:00
|
|
|
---@param options InputDialogOptionsProps[]?
|
2022-09-18 09:06:32 +10:00
|
|
|
---@return string[] | number[] | boolean[] | nil
|
2023-01-11 20:54:29 +01:00
|
|
|
function lib.inputDialog(heading, rows, options)
|
2022-09-18 09:06:32 +10:00
|
|
|
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,
|
2023-01-11 20:54:29 +01:00
|
|
|
rows = rows,
|
|
|
|
|
options = options
|
2022-09-18 09:06:32 +10:00
|
|
|
}
|
|
|
|
|
})
|
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
|
|
|
|
|
|
2022-09-29 11:39:30 +02:00
|
|
|
function lib.closeInputDialog()
|
|
|
|
|
if not input then return end
|
|
|
|
|
input:resolve(nil)
|
|
|
|
|
input = nil
|
|
|
|
|
SetNuiFocus(false, false)
|
|
|
|
|
SendNUIMessage({
|
|
|
|
|
action = 'closeInputDialog'
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
|
2022-04-11 15:26:10 +02:00
|
|
|
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)
|
2022-10-27 13:45:27 +02:00
|
|
|
end)
|