mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 16:06:02 +01:00
fix(client/addKeybind): get control button when indexing currentKey
Changing the key binding for a command invalidates the previous result from GetControlInstructionalButton. Use an index metamethod for backwards compatibility and add the getCurrentKey method.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
---@class CKeybind : KeybindProps
|
---@class CKeybind : KeybindProps
|
||||||
---@field currentKey string
|
---@field currentKey string
|
||||||
|
---@field getCurrentKey fun(): string
|
||||||
|
|
||||||
local keybinds = {}
|
local keybinds = {}
|
||||||
|
|
||||||
@@ -18,6 +19,28 @@ local function disableKeybind(self, toggle)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local IsPauseMenuActive = IsPauseMenuActive
|
local IsPauseMenuActive = IsPauseMenuActive
|
||||||
|
local GetControlInstructionalButton = GetControlInstructionalButton
|
||||||
|
local joaat = joaat
|
||||||
|
|
||||||
|
local keybind_mt = {
|
||||||
|
disabled = false,
|
||||||
|
}
|
||||||
|
|
||||||
|
function keybind_mt:__index(index)
|
||||||
|
local value = keybind_mt[index]
|
||||||
|
|
||||||
|
if value then
|
||||||
|
return value
|
||||||
|
end
|
||||||
|
|
||||||
|
if index == 'currentKey' then
|
||||||
|
return self:getCurrentKey()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function keybind_mt:getCurrentKey()
|
||||||
|
return GetControlInstructionalButton(0, joaat('+' .. self.name) | 0x80000000, true):sub(3)
|
||||||
|
end
|
||||||
|
|
||||||
---@param data KeybindProps
|
---@param data KeybindProps
|
||||||
---@return CKeybind
|
---@return CKeybind
|
||||||
@@ -41,10 +64,9 @@ function lib.addKeybind(data)
|
|||||||
TriggerEvent('chat:removeSuggestion', ('/-%s'):format(data.name))
|
TriggerEvent('chat:removeSuggestion', ('/-%s'):format(data.name))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
data.currentKey = GetControlInstructionalButton(0, joaat('+' .. data.name) | 0x80000000, true):sub(3)
|
data.disabled = data.disabled
|
||||||
data.disabled = data.disabled or false
|
|
||||||
data.disable = disableKeybind
|
data.disable = disableKeybind
|
||||||
keybinds[data.name] = data
|
keybinds[data.name] = setmetatable(data, keybind_mt)
|
||||||
---@cast data -KeybindProps
|
---@cast data -KeybindProps
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user