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

feat(resources/chat): Add toggleChat for RedM and extra parameter to set chat state #2152

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
53 changes: 25 additions & 28 deletions ext/system-resources/resources/chat/cl_chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ RegisterNUICallback('loaded', function(data, cb)
refreshThemes()

chatLoaded = true
addSuggestion('/toggleChat', 'set Chat state from whenactive hidden or always visible', {
addSuggestion('/toggleChat', 'set Chat state', {
{ name = "state", help = "whenactive hidden visible" },
})
cb('ok')
Expand All @@ -227,34 +227,30 @@ local CHAT_HIDE_STATES = {
local kvpEntry = GetResourceKvpString('hideState')
local chatHideState = kvpEntry and tonumber(kvpEntry) or CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
local isFirstHide = true

if not isRDR then
Copy link
Author

@outsider31000 outsider31000 May 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is redundante since we are already checking for if RegisterKeyMapping exists, so best to remove it.
This allows to one day if it is implemented to RedM to work with no modifications needed in the future.

if RegisterKeyMapping then
RegisterKeyMapping('toggleChat', 'Toggle chat', 'keyboard', 'l')
end
if RegisterKeyMapping then
RegisterKeyMapping('toggleChat', 'Toggle chat', 'keyboard', 'l')
end

RegisterCommand('toggleChat', function(source, args, rawCommand)
if not args[1] then
if chatHideState == CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE then
chatHideState = CHAT_HIDE_STATES.ALWAYS_SHOW
elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_SHOW then
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_HIDE then
chatHideState = CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
end
SetResourceKvp('hideState', tostring(chatHideState))
else
if args[1] == "visible" then
chatHideState = CHAT_HIDE_STATES.ALWAYS_SHOW
elseif args[1] == "hidden" then
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
elseif args[1] == "whenactive" then
chatHideState = CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
end
end

isFirstHide = false
if not args[1] then
if chatHideState == CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE then
chatHideState = CHAT_HIDE_STATES.ALWAYS_SHOW
elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_SHOW then
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_HIDE then
chatHideState = CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
end
else
if args[1] == "visible" then
chatHideState = CHAT_HIDE_STATES.ALWAYS_SHOW
elseif args[1] == "hidden" then
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
elseif args[1] == "whenactive" then
chatHideState = CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
end
end
SetResourceKvp('hideState', tostring(chatHideState))
isFirstHide = false
end, false)

Citizen.CreateThread(function()
Expand All @@ -263,12 +259,13 @@ Citizen.CreateThread(function()

local lastChatHideState = -1
local origChatHideState = -1
local input = isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245

while true do
Wait(0)

if not chatInputActive then
if IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) --[[ INPUT_MP_TEXT_CHAT_ALL ]] then
if IsControlPressed(0, input) then
chatInputActive = true
chatInputActivating = true

Expand All @@ -279,7 +276,7 @@ Citizen.CreateThread(function()
end

if chatInputActivating then
if not IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) then
if not IsControlPressed(0, input) then
SetNuiFocus(true)

chatInputActivating = false
Expand Down
Loading