Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!refactor(keybinds): support default key #127

Merged
merged 9 commits into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions imports/addKeybind/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---@class CKeybind
---@field name string
---@field description string
---@field defaultKey? string
---@field keybind string
---@field disabled? boolean
---@field disable? fun(self: CKeybind, toggle: boolean)
---@field onPressed? fun(self: CKeybind)
---@field onReleased? fun(self: CKeybind)

local keybinds = {}

local function disableKeybind(self, toggle)
keybinds[self.name].disabled = toggle
end

local IsPauseMenuActive = IsPauseMenuActive

---@param data CKeybind
---@return CKeybind
function lib.addKeybind(data)
data.defaultKey = data.defaultKey or ''
data.keybind = GetControlInstructionalButton(0, joaat('+' .. data.name) | 0x80000000, true):sub(3)
data.disabled = data.disabled or false
data.disable = disableKeybind

RegisterCommand('+' .. data.name, function()
if not data.onPressed or data.disabled or IsPauseMenuActive() then return end
data:onPressed()
end)

RegisterCommand('-' .. data.name, function()
if not data.onReleased or data.disabled or IsPauseMenuActive() then return end
data:onReleased()
end)

RegisterKeyMapping('+' .. data.name, data.description, 'keyboard', data.keybind)

SetTimeout(500, function()
TriggerEvent('chat:removeSuggestion', ('/+%s'):format(data.name))
TriggerEvent('chat:removeSuggestion', ('/-%s'):format(data.name))
end)

keybinds[data.name] = data
return data
end

return lib.addKeybind
53 changes: 0 additions & 53 deletions imports/keybinds/client.lua

This file was deleted.

2 changes: 1 addition & 1 deletion resource/interface/client/textui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
---@field style? string;

---@param text string
---@param options TextUIOptions
---@param options? TextUIOptions
function lib.showTextUI(text, options)
if not options then options = {} end
options.text = text
Expand Down