Skip to content
This repository was archived by the owner on Apr 7, 2023. It is now read-only.

Chat Visibility Toggle #12

Closed
wants to merge 6 commits into from
Closed
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
30 changes: 30 additions & 0 deletions resources/[system]/chat/cl_chat.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
local chatInputActive = false
local chatInputActivating = false
local chatVisibilityToggle = false

RegisterNetEvent('chatMessage')
RegisterNetEvent('chat:addTemplate')
RegisterNetEvent('chat:addMessage')
RegisterNetEvent('chat:addSuggestion')
RegisterNetEvent('chat:removeSuggestion')
RegisterNetEvent('chat:clear')
RegisterNetEvent('chat:toggleChat')

-- internal events
RegisterNetEvent('__cfx_internal:serverPrint')
Expand Down Expand Up @@ -83,6 +85,34 @@ AddEventHandler('chat:clear', function(name)
})
end)

AddEventHandler('chat:toggleChat',function(newState)
if(newState == true or newState == false)then
chatVisibilityToggle = not newState
else
chatVisibilityToggle = not chatVisibilityToggle
end

local state = (chatVisibilityToggle == true) and "^1disabled" or "^2enabled"

SendNUIMessage({
type = 'ON_TOGGLE_CHAT',
toggle = chatVisibilityToggle
})

SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = {255,255,255},
multiline = true,
args = {"Chat Visibility has been "..state}
}
})
end)

RegisterCommand("togglechat",function()
TriggerEvent('chat:toggleChat')
end)

RegisterNUICallback('chatResult', function(data, cb)
chatInputActive = false
SetNuiFocus(false)
Expand Down
17 changes: 16 additions & 1 deletion resources/[system]/chat/html/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ window.APP = {
style: CONFIG.style,
showInput: false,
showWindow: false,
neverShowWindow: false,
neverShowWindowFlag: false,
suggestions: [],
templates: CONFIG.templates,
message: '',
Expand All @@ -32,7 +34,9 @@ window.APP = {
if (this.showWindowTimer) {
clearTimeout(this.showWindowTimer);
}
this.showWindow = true;
if(this.neverShowWindowFlag == false){
this.showWindow = true;
}
this.resetShowWindowTimer();

const messagesObj = this.$refs.messages;
Expand All @@ -45,6 +49,8 @@ window.APP = {
ON_OPEN() {
this.showInput = true;
this.showWindow = true;
this.neverShowWindow = false

if (this.showWindowTimer) {
clearTimeout(this.showWindowTimer);
}
Expand Down Expand Up @@ -80,6 +86,12 @@ window.APP = {
this.templates[template.id] = template.html;
}
},
ON_TOGGLE_CHAT({ toggle }){
if(toggle == true || toggle == false){
this.neverShowWindow = toggle
this.neverShowWindowFlag = toggle
}
},
warn(msg) {
this.messages.push({
args: [msg],
Expand All @@ -94,6 +106,9 @@ window.APP = {
this.showWindowTimer = setTimeout(() => {
if (!this.showInput) {
this.showWindow = false;
if(this.neverShowWindowFlag){
this.neverShowWindow = true
}
}
}, CONFIG.fadeTimeout);
},
Expand Down
5 changes: 5 additions & 0 deletions resources/[system]/chat/html/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,8 @@ textarea:focus, input:focus {
.suggestion {
margin-bottom: 5px;
}

.forceHidden {
opacity: 0.0 !important;
visibility: none !important;
}
2 changes: 1 addition & 1 deletion resources/[system]/chat/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<!-- App Template -->
<script type="text/x-template" id="app_template">
<div id="app">
<div class="chat-window" :style="this.style" :class="{ 'fadeOut animated': !showWindow }">
<div class="chat-window" :style="this.style" :class="{ 'fadeOut animated': !showWindow, 'forceHidden': neverShowWindow }">
<div class="chat-messages" ref="messages">
<message v-for="msg in messages"
:templates="templates"
Expand Down