mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
Merge branch 'v3'
This commit is contained in:
@@ -10,3 +10,10 @@ function RegisterCommand(commandName, callback, restricted)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterNUICallback('getConfig', function(_, cb)
|
||||
cb({
|
||||
primaryColor = GetConvar('ox:primaryColor', 'blue'),
|
||||
primaryShade = GetConvarInt('ox:primaryShade', 8)
|
||||
})
|
||||
end)
|
||||
@@ -10,6 +10,8 @@ end
|
||||
---@field header string;
|
||||
---@field content string;
|
||||
---@field centered? boolean?;
|
||||
---@field size? 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
||||
---@field overflow? boolean?;
|
||||
---@field cancel? boolean?;
|
||||
---@field labels? {cancel?: string, confirm?: string}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local input
|
||||
|
||||
---@class InputDialogRowProps
|
||||
---@field type 'input' | 'number' | 'checkbox' | 'select' | 'slider'
|
||||
---@field type 'input' | 'number' | 'checkbox' | 'select' | 'slider' | 'multi-select' | 'date' | 'date-range' | 'time' | 'textarea'
|
||||
---@field label string
|
||||
---@field options? { value: string, label: string, default?: string }[]
|
||||
---@field password? boolean
|
||||
@@ -14,12 +14,20 @@ local input
|
||||
---@field min? number
|
||||
---@field max? number
|
||||
---@field step? number
|
||||
---@field autosize? boolean
|
||||
---@field required? boolean
|
||||
---@field format? string
|
||||
---@field clearable? string
|
||||
---@field description? string
|
||||
|
||||
---@class InputDialogOptionsProps
|
||||
---@field allowCancel? boolean
|
||||
|
||||
---@param heading string
|
||||
---@param rows string[] | InputDialogRowProps[]
|
||||
---@param options InputDialogOptionsProps[]
|
||||
---@return string[] | number[] | boolean[] | nil
|
||||
function lib.inputDialog(heading, rows)
|
||||
function lib.inputDialog(heading, rows, options)
|
||||
if input then return end
|
||||
input = promise.new()
|
||||
|
||||
@@ -35,7 +43,8 @@ function lib.inputDialog(heading, rows)
|
||||
action = 'openDialog',
|
||||
data = {
|
||||
heading = heading,
|
||||
rows = rows
|
||||
rows = rows,
|
||||
options = options
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
---@alias NotificationPosition 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left'
|
||||
---@alias NotificationPosition 'top' | 'top-right' | 'top-left' | 'bottom' | 'bottom-right' | 'bottom-left' | 'center-right' | 'center-left'
|
||||
---@alias NotificationType 'inform' | 'error' | 'success'
|
||||
|
||||
---@class NotifyProps
|
||||
@@ -15,7 +15,7 @@
|
||||
---@param data NotifyProps
|
||||
function lib.notify(data)
|
||||
SendNUIMessage({
|
||||
action = 'customNotify',
|
||||
action = 'notify',
|
||||
data = data
|
||||
})
|
||||
end
|
||||
@@ -30,10 +30,10 @@ end
|
||||
|
||||
---@param data DefaultNotifyProps
|
||||
function lib.defaultNotify(data)
|
||||
SendNUIMessage({
|
||||
action = 'notify',
|
||||
data = data
|
||||
})
|
||||
-- Backwards compat for v3
|
||||
data.type = data.status
|
||||
if data.type == 'info' or data.type == 'warning' then data.type = 'inform' end
|
||||
return lib.notify(data)
|
||||
end
|
||||
|
||||
RegisterNetEvent('ox_lib:notify', lib.notify)
|
||||
|
||||
@@ -198,8 +198,6 @@ end
|
||||
function lib.cancelProgress()
|
||||
if not progress then
|
||||
error('No progress bar is active')
|
||||
elseif not progress.canCancel then
|
||||
error('Progress bar cannot be cancelled')
|
||||
end
|
||||
|
||||
progress = false
|
||||
|
||||
173
resource/interface/client/radial.lua
Normal file
173
resource/interface/client/radial.lua
Normal file
@@ -0,0 +1,173 @@
|
||||
local isOpen = false
|
||||
local menus = {}
|
||||
local menuItems = {}
|
||||
local currentRadial = nil
|
||||
|
||||
---@class RadialMenuItem
|
||||
---@field id string
|
||||
---@field icon string
|
||||
---@field label string
|
||||
---@field menu? string
|
||||
---@field onSelect? function
|
||||
|
||||
---@class RadialMenuProps
|
||||
---@field id string
|
||||
---@field items RadialMenuItem[]
|
||||
|
||||
---Registers a radial sub menu with predefined options.
|
||||
---@param radial RadialMenuProps
|
||||
function lib.registerRadial(radial)
|
||||
menus[radial.id] = radial
|
||||
end
|
||||
|
||||
---Open a registered radial submenu with the given id.
|
||||
---@param id string
|
||||
local function showRadial(id)
|
||||
local radial = menus[id]
|
||||
|
||||
if not radial then return error('No radial menu with such id found.') end
|
||||
|
||||
currentRadial = radial
|
||||
|
||||
SendNUIMessage({
|
||||
action = 'openRadialMenu',
|
||||
data = {
|
||||
items = radial.items,
|
||||
sub = true
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
function lib.hideRadial()
|
||||
if not isOpen then return end
|
||||
|
||||
SendNUIMessage({
|
||||
action = 'openRadialMenu',
|
||||
data = false
|
||||
})
|
||||
|
||||
SetNuiFocus(false, false)
|
||||
|
||||
isOpen = false
|
||||
currentRadial = nil
|
||||
end
|
||||
|
||||
---Registers an item or array of items in the global radial menu.
|
||||
---@param items RadialMenuItem | RadialMenuItem[]
|
||||
function lib.addRadialItem(items)
|
||||
local menuSize = #menuItems
|
||||
local invokingResource = GetInvokingResource()
|
||||
|
||||
if table.type(items) == 'array' then
|
||||
for i = 1, #items do
|
||||
local item = items[i]
|
||||
item.resource = invokingResource
|
||||
menuSize += 1
|
||||
menuItems[menuSize] = item
|
||||
end
|
||||
else
|
||||
items.resource = invokingResource
|
||||
menuItems[menuSize + 1] = items
|
||||
end
|
||||
|
||||
if isOpen then
|
||||
SendNUIMessage({
|
||||
action = 'refreshItems',
|
||||
data = menuItems
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
---Removes an item from the global radial menu with the given id.
|
||||
---@param id string
|
||||
function lib.removeRadialItem(id)
|
||||
for i = 1, #menuItems do
|
||||
local item = menuItems[i]
|
||||
if item.id == id then
|
||||
table.remove(menuItems, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
if isOpen then
|
||||
SendNUIMessage({
|
||||
action = 'refreshItems',
|
||||
data = menuItems
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
RegisterNUICallback('radialClick', function(index, cb)
|
||||
cb(1)
|
||||
local item = not currentRadial and menuItems[index + 1] or currentRadial.items[index + 1]
|
||||
|
||||
if item.onSelect then item.onSelect() end
|
||||
if item.menu then return showRadial(item.menu) end
|
||||
|
||||
lib.hideRadial()
|
||||
end)
|
||||
|
||||
RegisterNUICallback('radialBack', function(_, cb)
|
||||
cb(1)
|
||||
if currentRadial.menu then
|
||||
return showRadial(currentRadial.menu)
|
||||
end
|
||||
|
||||
currentRadial = nil
|
||||
|
||||
SendNUIMessage({
|
||||
action = 'openRadialMenu',
|
||||
data = {
|
||||
items = menuItems
|
||||
}
|
||||
})
|
||||
end)
|
||||
|
||||
RegisterNUICallback('radialClose', function(_, cb)
|
||||
cb(1)
|
||||
|
||||
if not isOpen then return end
|
||||
|
||||
SetNuiFocus(false, false)
|
||||
|
||||
isOpen = false
|
||||
currentRadial = nil
|
||||
end)
|
||||
|
||||
lib.addKeybind({
|
||||
name = 'ox_lib-radial',
|
||||
description = 'Open radial menu',
|
||||
defaultKey = 'z',
|
||||
onPressed = function()
|
||||
if isOpen or #menuItems == 0 or IsNuiFocused() or IsPauseMenuActive() then return end
|
||||
|
||||
isOpen = true
|
||||
|
||||
SendNUIMessage({
|
||||
action = 'openRadialMenu',
|
||||
data = {
|
||||
items = menuItems
|
||||
}
|
||||
})
|
||||
SetNuiFocus(true, true)
|
||||
SetNuiFocusKeepInput(true)
|
||||
SetCursorLocation(0.5, 0.5)
|
||||
|
||||
while isOpen do
|
||||
DisablePlayerFiring(cache.playerId, true)
|
||||
DisableControlAction(0, 1, true)
|
||||
DisableControlAction(0, 2, true)
|
||||
Wait(0)
|
||||
end
|
||||
end,
|
||||
onReleased = lib.hideRadial,
|
||||
})
|
||||
|
||||
AddEventHandler('onClientResourceStop', function(resource)
|
||||
for i = #menuItems, 1, -1 do
|
||||
local item = menuItems[i]
|
||||
|
||||
if item.resource == resource then
|
||||
table.remove(menuItems, i)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -4,15 +4,19 @@ local skillcheck
|
||||
---@alias SkillCheckDifficulity 'easy' | 'medium' | 'hard' | { areaSize: number, speedMultiplier: number }
|
||||
|
||||
---@param difficulty SkillCheckDifficulity | SkillCheckDifficulity[]
|
||||
---@param inputs string[]
|
||||
---@return boolean?
|
||||
function lib.skillCheck(difficulty)
|
||||
function lib.skillCheck(difficulty, inputs)
|
||||
if skillcheck then return end
|
||||
skillcheck = promise:new()
|
||||
|
||||
SetNuiFocus(true, false)
|
||||
SendNUIMessage({
|
||||
action = 'startSkillCheck',
|
||||
data = difficulty
|
||||
data = {
|
||||
difficulty = difficulty,
|
||||
inputs = inputs
|
||||
}
|
||||
})
|
||||
|
||||
return Citizen.Await(skillcheck)
|
||||
|
||||
Reference in New Issue
Block a user