Skip to content

Commit ec41738

Browse files
committed
Refactor chat popup
1 parent 0830830 commit ec41738

File tree

10 files changed

+61
-54
lines changed

10 files changed

+61
-54
lines changed

exp_legacy/module/config/_file_loader.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ return {
77
"expcore.player_data", -- must be loaded first to register event handlers
88

99
--- Addons
10-
"modules.addons.chat-popups",
1110
"modules.addons.damage-popups",
1211
"modules.addons.death-logger",
1312
"modules.addons.spawn-area",

exp_legacy/module/locale/en/addons.cfg

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[chat-popup]
2-
message=__1__: __2__
3-
ping=You have been mentioned in chat by __1__.
4-
51
[damage-popup]
62
player-health=__1__
73
player-damage=__1__

exp_legacy/module/locale/zh-CN/addons.cfg

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[chat-popup]
2-
message=__1__: __2__
3-
ping=__1__ 在信息中提到了你。
4-
51
[damage-popup]
62
player-health=__1__
73
player-damage=__1__

exp_legacy/module/locale/zh-TW/addons.cfg

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[chat-popup]
2-
message=__1__: __2__
3-
ping=__1__ 在信息中提到了你。
4-
51
[damage-popup]
62
player-health=__1__
73
player-damage=__1__

exp_legacy/module/modules/addons/chat-popups.lua

Lines changed: 0 additions & 41 deletions
This file was deleted.

exp_scenario/module/control.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ require("modules/exp_scenario/commands/waterfill")
4545
--- Control
4646
add(require("modules/exp_scenario/control/afk_kick"))
4747
add(require("modules/exp_scenario/control/bonus"))
48+
add(require("modules/exp_scenario/control/chat_popup"))
4849
add(require("modules/exp_scenario/control/custom_start"))
4950
add(require("modules/exp_scenario/control/research"))
5051

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--[[-- Control - Chat Popup
2+
Creates flying text entities when a player sends a message in chat
3+
]]
4+
5+
local FlyingText = require("modules/exp_util/flying_text")
6+
local config = require("modules.exp_legacy.config.popup_messages")
7+
8+
local lower = string.lower
9+
local find = string.find
10+
11+
--- Create a chat bubble when a player types a message
12+
--- @param event EventData.on_console_chat
13+
local function on_console_chat(event)
14+
if not event.player_index then return end
15+
local player = assert(game.get_player(event.player_index))
16+
local name = player.name
17+
18+
-- Sends the message as text above them
19+
if config.show_player_messages then
20+
FlyingText.create_as_player{
21+
target_player = player,
22+
text = { "exp_chat-popup.flying-text-message", name, event.message },
23+
}
24+
end
25+
26+
if not config.show_player_mentions then return end
27+
28+
-- Loops over online players to see if they name is included
29+
local search_string = lower(event.message)
30+
for _, mentioned_player in ipairs(game.connected_players) do
31+
if mentioned_player.index ~= player.index then
32+
if find(search_string, lower(mentioned_player.name), 1, true) then
33+
FlyingText.create_as_player{
34+
target_player = mentioned_player,
35+
text = { "exp_chat-popup.flying-text-ping", name },
36+
}
37+
end
38+
end
39+
end
40+
end
41+
42+
local e = defines.events
43+
44+
return {
45+
events = {
46+
[e.on_console_chat] = on_console_chat,
47+
}
48+
}

exp_scenario/module/locale/en.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,7 @@ caption-set-location=Set
375375
type-player=Player
376376
type-static=Static
377377
type-loop=Loop
378+
379+
[exp_chat-popup]
380+
flying-text-message=__1__: __2__
381+
flying-text-ping=You have been mentioned in chat by __1__.

exp_scenario/module/locale/zh-CN.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,7 @@ caption-set-location=設
375375
type-player=用戶
376376
type-static=靜態
377377
type-loop=循環
378+
379+
[exp_chat-popup]
380+
flying-text-message=__1__: __2__
381+
flying-text-ping=__1__ 在信息中提到了你。

exp_scenario/module/locale/zh-TW.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,7 @@ caption-set-location=設
375375
type-player=用戶
376376
type-static=靜態
377377
type-loop=循環
378+
379+
[exp_chat-popup]
380+
flying-text-message=__1__: __2__
381+
flying-text-ping=__1__ 在信息中提到了你。

0 commit comments

Comments
 (0)