From 2dc8f07ccf739cec8161a3b366084603ac78e265 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 22 Mar 2019 22:41:21 +0000 Subject: [PATCH] Added Chat Popups --- config/file_loader.lua | 2 ++ locale/en/addons.cfg | 3 ++ .../en/{commands-local.cfg => commands.cfg} | 0 modules/addons/addons.cfg | 3 ++ modules/addons/chat-popups.lua | 30 +++++++++++++++++++ .../{commands-local.cfg => commands.cfg} | 0 old/modules/{ => DONE}/ChatPopup/control.lua | 0 old/modules/{ => DONE}/ChatPopup/softmod.json | 0 8 files changed, 38 insertions(+) create mode 100644 locale/en/addons.cfg rename locale/en/{commands-local.cfg => commands.cfg} (100%) create mode 100644 modules/addons/addons.cfg create mode 100644 modules/addons/chat-popups.lua rename modules/commands/{commands-local.cfg => commands.cfg} (100%) rename old/modules/{ => DONE}/ChatPopup/control.lua (100%) rename old/modules/{ => DONE}/ChatPopup/softmod.json (100%) diff --git a/config/file_loader.lua b/config/file_loader.lua index 56005d6a..8eb1c26a 100644 --- a/config/file_loader.lua +++ b/config/file_loader.lua @@ -14,6 +14,8 @@ return { 'modules.commands.cheat-mode', 'modules.commands.interface', 'modules.commands.help', + -- QoL Addons + 'modules.addons.chat-popups', -- Config Files 'config.command_auth_admin', -- commands tags with admin_only are blocked for non admins 'config.permission_groups', -- loads some predefined permission groups diff --git a/locale/en/addons.cfg b/locale/en/addons.cfg new file mode 100644 index 00000000..409e71a0 --- /dev/null +++ b/locale/en/addons.cfg @@ -0,0 +1,3 @@ +[chat-popup] +message=__1__: __2__ +ping=You have been mentioned in chat by __1__. \ No newline at end of file diff --git a/locale/en/commands-local.cfg b/locale/en/commands.cfg similarity index 100% rename from locale/en/commands-local.cfg rename to locale/en/commands.cfg diff --git a/modules/addons/addons.cfg b/modules/addons/addons.cfg new file mode 100644 index 00000000..409e71a0 --- /dev/null +++ b/modules/addons/addons.cfg @@ -0,0 +1,3 @@ +[chat-popup] +message=__1__: __2__ +ping=You have been mentioned in chat by __1__. \ No newline at end of file diff --git a/modules/addons/chat-popups.lua b/modules/addons/chat-popups.lua new file mode 100644 index 00000000..3a0592d3 --- /dev/null +++ b/modules/addons/chat-popups.lua @@ -0,0 +1,30 @@ +--- Creates flying text entities when a player sends a message in chat +-- also displays a ping above users who are named in the message +local Game = require 'utils.game' +local Event = require 'utils.event' + +local send_text = Game.print_player_floating_text -- (player_index, text, color) + +Event.add(defines.events.on_console_chat,function(event) + local player = Game.get_player_by_index(event.player_index) + + -- Some basic sanity checks + if not player then return end + if not event.message then return end + + -- Sends the message as text above them + send_text(player.index,{'chat-popup.message',player.name,event.message},player.chat_color) + + -- Makes lower and removes white space from the message + local search_string = event.message:lower():gsub("%s+", "") + + -- Loops over online players to see if they name is included + for _,mentioned_player in pairs(game.connected_players) do + if mentioned_player.index ~= player.index then + if search_string:match(mentioned_player.name:lower()) then + send_text(mentioned_player.index,{'chat-popup.ping',player.name},player.chat_color) + end + end + end + +end) \ No newline at end of file diff --git a/modules/commands/commands-local.cfg b/modules/commands/commands.cfg similarity index 100% rename from modules/commands/commands-local.cfg rename to modules/commands/commands.cfg diff --git a/old/modules/ChatPopup/control.lua b/old/modules/DONE/ChatPopup/control.lua similarity index 100% rename from old/modules/ChatPopup/control.lua rename to old/modules/DONE/ChatPopup/control.lua diff --git a/old/modules/ChatPopup/softmod.json b/old/modules/DONE/ChatPopup/softmod.json similarity index 100% rename from old/modules/ChatPopup/softmod.json rename to old/modules/DONE/ChatPopup/softmod.json