2024-04-17 21:12:20 +10:00
|
|
|
-- Some users have locale set from ox_lib v2
|
|
|
|
|
if GetResourceKvpInt('reset_locale') ~= 1 then
|
|
|
|
|
DeleteResourceKvp('locale')
|
|
|
|
|
SetResourceKvpInt('reset_locale', 1)
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-01 19:19:59 +11:00
|
|
|
local settings = {
|
2024-04-17 21:12:20 +10:00
|
|
|
default_locale = GetConvar('ox:locale', 'en'),
|
2024-04-12 09:45:49 +10:00
|
|
|
notification_position = GetResourceKvpString('notification_position') or 'top-right',
|
2024-04-03 14:58:35 +11:00
|
|
|
notification_audio = GetResourceKvpInt('notification_audio') == 1
|
2024-04-01 19:19:59 +11:00
|
|
|
}
|
|
|
|
|
|
2024-04-17 21:12:20 +10:00
|
|
|
settings.locale = GetResourceKvpString('locale') or settings.default_locale
|
|
|
|
|
|
2024-04-12 09:45:49 +10:00
|
|
|
local function set(key, value)
|
|
|
|
|
if settings[key] == value then return false end
|
|
|
|
|
|
|
|
|
|
settings[key] = value
|
|
|
|
|
local valueType = type(value)
|
|
|
|
|
|
|
|
|
|
if valueType == 'nil' then
|
|
|
|
|
DeleteResourceKvp(key)
|
|
|
|
|
elseif valueType == 'string' then
|
|
|
|
|
SetResourceKvp(key, value)
|
|
|
|
|
elseif valueType == 'table' then
|
|
|
|
|
SetResourceKvp(key, json.encode(value))
|
|
|
|
|
elseif valueType == 'number' then
|
|
|
|
|
SetResourceKvpInt(key, value)
|
|
|
|
|
elseif valueType == 'boolean' then
|
|
|
|
|
SetResourceKvpInt(key, value and 1 or 0)
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
2024-04-01 19:19:59 +11:00
|
|
|
RegisterCommand('ox_lib', function()
|
|
|
|
|
local input = lib.inputDialog('Settings', {
|
|
|
|
|
{
|
|
|
|
|
type = 'select',
|
|
|
|
|
label = locale('ui.settings.locale'),
|
|
|
|
|
searchable = true,
|
|
|
|
|
description = locale('ui.settings.locale_description', settings.locale),
|
|
|
|
|
options = GlobalState['ox_lib:locales'],
|
2024-04-12 09:45:49 +10:00
|
|
|
default = settings.locale,
|
|
|
|
|
required = true,
|
2024-04-01 19:19:59 +11:00
|
|
|
icon = 'book',
|
2024-04-03 14:58:35 +11:00
|
|
|
},
|
2024-04-12 09:45:49 +10:00
|
|
|
{
|
|
|
|
|
type = 'select',
|
|
|
|
|
label = locale('ui.settings.notification_position'),
|
|
|
|
|
options = {
|
|
|
|
|
{ label = locale('ui.position.top-right'), value = 'top-right' },
|
|
|
|
|
{ label = locale('ui.position.top'), value = 'top' },
|
|
|
|
|
{ label = locale('ui.position.top-left'), value = 'top-left' },
|
|
|
|
|
{ label = locale('ui.position.center-right'), value = 'center-right' },
|
|
|
|
|
{ label = locale('ui.position.center-left'), value = 'center-left' },
|
|
|
|
|
{ label = locale('ui.position.bottom-right'), value = 'bottom-right' },
|
|
|
|
|
{ label = locale('ui.position.bottom'), value = 'bottom' },
|
|
|
|
|
{ label = locale('ui.position.bottom-left'), value = 'bottom-left' },
|
|
|
|
|
},
|
|
|
|
|
default = settings.notification_position,
|
|
|
|
|
required = true,
|
|
|
|
|
icon = 'message',
|
|
|
|
|
},
|
2024-04-03 14:58:35 +11:00
|
|
|
{
|
|
|
|
|
type = 'checkbox',
|
|
|
|
|
label = locale('ui.settings.notification_audio'),
|
|
|
|
|
checked = settings.notification_audio,
|
2024-04-01 19:19:59 +11:00
|
|
|
}
|
2024-04-12 09:45:49 +10:00
|
|
|
}) --[[@as table?]]
|
2024-04-01 19:19:59 +11:00
|
|
|
|
|
|
|
|
if not input then return end
|
|
|
|
|
|
2024-04-12 09:45:49 +10:00
|
|
|
---@type string, string, boolean
|
|
|
|
|
local locale, notification_position, notification_audio = table.unpack(input)
|
2024-04-03 14:58:35 +11:00
|
|
|
|
2024-04-12 09:45:49 +10:00
|
|
|
if set('locale', locale) then lib.setLocale(locale) end
|
|
|
|
|
|
|
|
|
|
set('notification_position', notification_position)
|
|
|
|
|
set('notification_audio', notification_audio)
|
2024-04-01 19:19:59 +11:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
return settings
|