diff --git a/resources/[system]/chat/cl_chat.lua b/resources/[system]/chat/cl_chat.lua index 25ce6be..8848f3e 100644 --- a/resources/[system]/chat/cl_chat.lua +++ b/resources/[system]/chat/cl_chat.lua @@ -13,15 +13,16 @@ RegisterNetEvent('_chat:messageEntered') --deprecated, use chat:addMessage AddEventHandler('chatMessage', function(author, color, text) - if author == "" then - author = false + local args = { text } + if author ~= "" then + table.insert(args, 1, author) end SendNUIMessage({ type = 'ON_MESSAGE', message = { color = color, multiline = true, - args = { author, text } + args = args } }) end) diff --git a/resources/[system]/chat/html/App.js b/resources/[system]/chat/html/App.js index e0552ae..ff9d89b 100644 --- a/resources/[system]/chat/html/App.js +++ b/resources/[system]/chat/html/App.js @@ -19,7 +19,7 @@ window.APP = { window.removeEventListener('message', this.listener); }, mounted() { - $.post('http://chat/loaded', JSON.stringify({})); + post('http://chat/loaded', JSON.stringify({})); this.listener = window.addEventListener('message', (event) => { const item = event.data || event.detail; //'detail' is for debuging via browsers if (this[item.type]) { @@ -135,11 +135,10 @@ window.APP = { this.resize(); } else { if(this.message !== '') { - $.post('http://chat/chatResult', JSON.stringify({ + post('http://chat/chatResult', JSON.stringify({ message: this.message, })); this.oldMessages.unshift(this.message); - this.message = ''; this.oldMessagesIndex = -1; this.hideInput(); } else { @@ -149,8 +148,9 @@ window.APP = { }, hideInput(canceled = false) { if (canceled) { - $.post('http://chat/chatResult', JSON.stringify({ canceled })); + post('http://chat/chatResult', JSON.stringify({ canceled })); } + this.message = ''; this.showInput = false; clearInterval(this.focusTimer); this.resetShowWindowTimer(); diff --git a/resources/[system]/chat/html/Message.js b/resources/[system]/chat/html/Message.js index a83e65e..52c0a4a 100644 --- a/resources/[system]/chat/html/Message.js +++ b/resources/[system]/chat/html/Message.js @@ -6,6 +6,13 @@ Vue.component('message', { computed: { textEscaped() { let s = this.template ? this.template : this.templates[this.templateId]; + + //This hack is required to preserve backwards compatability + if (this.templateId == CONFIG.defaultTemplateId + && this.args.length == 1) { + s = this.templates[CONFIG.defaultAltTemplateId] //Swap out default template :/ + } + s = s.replace(/{(\d+)}/g, (match, number) => { const argEscaped = this.args[number] != undefined ? this.escape(this.args[number]) : match if (number == 0 && this.color) { @@ -19,10 +26,23 @@ Vue.component('message', { }, methods: { colorizeOld(str) { - return `${str}` + return `${str}` }, colorize(str) { - const s = "" + (str.replace(/\^([0-9]+)/g, (str, color) => ``)) + ""; + let s = "" + (str.replace(/\^([0-9]+)/g, (str, color) => ``)) + ""; + + const styleDict = { + '*': 'font-weight: bold;', + '_': 'text-decoration: underline;', + '~': 'text-decoration: line-through;', + '=': 'text-decoration: underline line-through;', + 'r': 'text-decoration: none;font-weight: normal;', + }; + + const styleRegex = /\^(\_|\*|\=|\~|\/|r)(.*?)(?=$|\^r|<\/em>)/; + while (s.match(styleRegex)) { //Any better solution would be appreciated :P + s = s.replace(styleRegex, (str, style, inner) => `${inner}`) + } return s.replace(/]*><\/span[^>]*>/g, ''); }, escape(unsafe) { diff --git a/resources/[system]/chat/html/config.default.js b/resources/[system]/chat/html/config.default.js index a517381..7e57105 100644 --- a/resources/[system]/chat/html/config.default.js +++ b/resources/[system]/chat/html/config.default.js @@ -1,9 +1,11 @@ // DO NOT EDIT THIS FILE // Copy it to `config.js` and edit it window.CONFIG = { - defaultTemplateId: 'default', //This template will be used for normal chat messages + defaultTemplateId: 'default', //This is the default template for 2 args1 + defaultAltTemplateId: 'defaultAlt', //This one for 1 arg templates: { //You can add static templates here 'default': '{0}: {1}', + 'defaultAlt': '{0}', 'example:important': '

^2{0}

' }, fadeTimeout: 7000, diff --git a/resources/[system]/chat/html/index.css b/resources/[system]/chat/html/index.css index 3357e56..dedb895 100644 --- a/resources/[system]/chat/html/index.css +++ b/resources/[system]/chat/html/index.css @@ -18,6 +18,10 @@ flex-grow: 0; } +em { + font-style: normal; +} + #app { font-family: 'Lato', Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; diff --git a/resources/[system]/chat/html/index.html b/resources/[system]/chat/html/index.html index de5ced8..64ee96e 100644 --- a/resources/[system]/chat/html/index.html +++ b/resources/[system]/chat/html/index.html @@ -8,9 +8,6 @@ - - - @@ -91,6 +88,13 @@