mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-12-12 06:14:09 +01:00
chat: wip rework as chat2
This commit is contained in:
@@ -2,7 +2,6 @@ local isRDR = not TerraingridActivate and true or false
|
||||
|
||||
local chatInputActive = false
|
||||
local chatInputActivating = false
|
||||
local chatHidden = true
|
||||
local chatLoaded = false
|
||||
|
||||
RegisterNetEvent('chatMessage')
|
||||
@@ -10,6 +9,8 @@ RegisterNetEvent('chat:addTemplate')
|
||||
RegisterNetEvent('chat:addMessage')
|
||||
RegisterNetEvent('chat:addSuggestion')
|
||||
RegisterNetEvent('chat:addSuggestions')
|
||||
RegisterNetEvent('chat:addMode')
|
||||
RegisterNetEvent('chat:removeMode')
|
||||
RegisterNetEvent('chat:removeSuggestion')
|
||||
RegisterNetEvent('chat:clear')
|
||||
|
||||
@@ -47,14 +48,25 @@ AddEventHandler('__cfx_internal:serverPrint', function(msg)
|
||||
})
|
||||
end)
|
||||
|
||||
AddEventHandler('chat:addMessage', function(message)
|
||||
-- addMessage
|
||||
local addMessage = function(message)
|
||||
if type(message) == 'string' then
|
||||
message = {
|
||||
args = { message }
|
||||
}
|
||||
end
|
||||
|
||||
SendNUIMessage({
|
||||
type = 'ON_MESSAGE',
|
||||
message = message
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
AddEventHandler('chat:addSuggestion', function(name, help, params)
|
||||
exports('addMessage', addMessage)
|
||||
AddEventHandler('chat:addMessage', addMessage)
|
||||
|
||||
-- addSuggestion
|
||||
local addSuggestion = function(name, help, params)
|
||||
SendNUIMessage({
|
||||
type = 'ON_SUGGESTION_ADD',
|
||||
suggestion = {
|
||||
@@ -63,7 +75,10 @@ AddEventHandler('chat:addSuggestion', function(name, help, params)
|
||||
params = params or nil
|
||||
}
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
exports('addSuggestion', addSuggestion)
|
||||
AddEventHandler('chat:addSuggestion', addSuggestion)
|
||||
|
||||
AddEventHandler('chat:addSuggestions', function(suggestions)
|
||||
for _, suggestion in ipairs(suggestions) do
|
||||
@@ -81,6 +96,20 @@ AddEventHandler('chat:removeSuggestion', function(name)
|
||||
})
|
||||
end)
|
||||
|
||||
AddEventHandler('chat:addMode', function(mode)
|
||||
SendNUIMessage({
|
||||
type = 'ON_MODE_ADD',
|
||||
mode = mode
|
||||
})
|
||||
end)
|
||||
|
||||
AddEventHandler('chat:removeMode', function(name)
|
||||
SendNUIMessage({
|
||||
type = 'ON_MODE_REMOVE',
|
||||
name = name
|
||||
})
|
||||
end)
|
||||
|
||||
AddEventHandler('chat:addTemplate', function(id, html)
|
||||
SendNUIMessage({
|
||||
type = 'ON_TEMPLATE_ADD',
|
||||
@@ -110,7 +139,7 @@ RegisterNUICallback('chatResult', function(data, cb)
|
||||
if data.message:sub(1, 1) == '/' then
|
||||
ExecuteCommand(data.message:sub(2))
|
||||
else
|
||||
TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message)
|
||||
TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message, data.mode)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -124,7 +153,7 @@ local function refreshCommands()
|
||||
local suggestions = {}
|
||||
|
||||
for _, command in ipairs(registeredCommands) do
|
||||
if IsAceAllowed(('command.%s'):format(command.name)) then
|
||||
if IsAceAllowed(('command.%s'):format(command.name)) and command.name ~= 'toggleChat' then
|
||||
table.insert(suggestions, {
|
||||
name = '/' .. command.name,
|
||||
help = ''
|
||||
@@ -178,7 +207,7 @@ AddEventHandler('onClientResourceStop', function(resName)
|
||||
end)
|
||||
|
||||
RegisterNUICallback('loaded', function(data, cb)
|
||||
TriggerServerEvent('chat:init');
|
||||
TriggerServerEvent('chat:init')
|
||||
|
||||
refreshCommands()
|
||||
refreshThemes()
|
||||
@@ -188,10 +217,41 @@ RegisterNUICallback('loaded', function(data, cb)
|
||||
cb('ok')
|
||||
end)
|
||||
|
||||
local CHAT_HIDE_STATES = {
|
||||
SHOW_WHEN_ACTIVE = 0,
|
||||
ALWAYS_SHOW = 1,
|
||||
ALWAYS_HIDE = 2
|
||||
}
|
||||
|
||||
local kvpEntry = GetResourceKvpString('hideState')
|
||||
local chatHideState = kvpEntry and tonumber(kvpEntry) or CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
|
||||
local isFirstHide = true
|
||||
|
||||
if not isRDR then
|
||||
RegisterKeyMapping('toggleChat', 'Toggle chat', 'keyboard', 'l')
|
||||
|
||||
RegisterCommand('toggleChat', function()
|
||||
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
|
||||
|
||||
isFirstHide = false
|
||||
|
||||
SetResourceKvp('hideState', tostring(chatHideState))
|
||||
end, false)
|
||||
end
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
SetTextChatEnabled(false)
|
||||
SetNuiFocus(false)
|
||||
|
||||
local lastChatHideState = -1
|
||||
local origChatHideState = -1
|
||||
|
||||
while true do
|
||||
Wait(0)
|
||||
|
||||
@@ -215,19 +275,26 @@ Citizen.CreateThread(function()
|
||||
end
|
||||
|
||||
if chatLoaded then
|
||||
local shouldBeHidden = false
|
||||
local forceHide = IsScreenFadedOut() or IsPauseMenuActive()
|
||||
|
||||
if IsScreenFadedOut() or IsPauseMenuActive() then
|
||||
shouldBeHidden = true
|
||||
if forceHide then
|
||||
origChatHideState = chatHideState
|
||||
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
|
||||
elseif origChatHideState ~= -1 then
|
||||
chatHideState = origChatHideState
|
||||
origChatHideState = -1
|
||||
end
|
||||
|
||||
if (shouldBeHidden and not chatHidden) or (not shouldBeHidden and chatHidden) then
|
||||
chatHidden = shouldBeHidden
|
||||
if chatHideState ~= lastChatHideState then
|
||||
lastChatHideState = chatHideState
|
||||
|
||||
SendNUIMessage({
|
||||
type = 'ON_SCREEN_STATE_CHANGE',
|
||||
shouldHide = shouldBeHidden
|
||||
hideState = chatHideState,
|
||||
fromUserInteraction = not forceHide and not isFirstHide
|
||||
})
|
||||
|
||||
isFirstHide = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user