mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
feat(client/keybinds): added isPressed state for keybinds (#643)
This commit is contained in:
@@ -14,8 +14,10 @@ if cache.game == 'redm' then return end
|
|||||||
---@class CKeybind : KeybindProps
|
---@class CKeybind : KeybindProps
|
||||||
---@field currentKey string
|
---@field currentKey string
|
||||||
---@field disabled boolean
|
---@field disabled boolean
|
||||||
|
---@field isPressed boolean
|
||||||
---@field hash number
|
---@field hash number
|
||||||
---@field getCurrentKey fun(): string
|
---@field getCurrentKey fun(): string
|
||||||
|
---@field isControlPressed fun(): boolean
|
||||||
|
|
||||||
local keybinds = {}
|
local keybinds = {}
|
||||||
|
|
||||||
@@ -24,6 +26,7 @@ local GetControlInstructionalButton = GetControlInstructionalButton
|
|||||||
|
|
||||||
local keybind_mt = {
|
local keybind_mt = {
|
||||||
disabled = false,
|
disabled = false,
|
||||||
|
isPressed = false,
|
||||||
defaultKey = '',
|
defaultKey = '',
|
||||||
defaultMapper = 'keyboard',
|
defaultMapper = 'keyboard',
|
||||||
}
|
}
|
||||||
@@ -36,6 +39,10 @@ function keybind_mt:getCurrentKey()
|
|||||||
return GetControlInstructionalButton(0, self.hash, true):sub(3)
|
return GetControlInstructionalButton(0, self.hash, true):sub(3)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function keybind_mt:isControlPressed()
|
||||||
|
return self.isPressed
|
||||||
|
end
|
||||||
|
|
||||||
function keybind_mt:disable(toggle)
|
function keybind_mt:disable(toggle)
|
||||||
self.disabled = toggle
|
self.disabled = toggle
|
||||||
end
|
end
|
||||||
@@ -48,13 +55,15 @@ function lib.addKeybind(data)
|
|||||||
keybinds[data.name] = setmetatable(data, keybind_mt)
|
keybinds[data.name] = setmetatable(data, keybind_mt)
|
||||||
|
|
||||||
RegisterCommand('+' .. data.name, function()
|
RegisterCommand('+' .. data.name, function()
|
||||||
if not data.onPressed or data.disabled or IsPauseMenuActive() then return end
|
if data.disabled or IsPauseMenuActive() then return end
|
||||||
data:onPressed()
|
data.isPressed = true
|
||||||
|
if data.onPressed then data:onPressed() end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterCommand('-' .. data.name, function()
|
RegisterCommand('-' .. data.name, function()
|
||||||
if not data.onReleased or data.disabled or IsPauseMenuActive() then return end
|
if data.disabled or IsPauseMenuActive() then return end
|
||||||
data:onReleased()
|
data.isPressed = false
|
||||||
|
if data.onReleased then data:onReleased() end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterKeyMapping('+' .. data.name, data.description, data.defaultMapper, data.defaultKey)
|
RegisterKeyMapping('+' .. data.name, data.description, data.defaultMapper, data.defaultKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user