1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-04 00:15:45 +02:00
ComfyFactorio/modules/global_chat_toggle.lua
Gerkiz 3cb39ad94a Changes
Adds a new gui button at top that allows players to toggle all the top buttons
Minor changes to fish defender
Minor changes to Mtn v3
2023-11-17 00:17:00 +01:00

91 lines
2.4 KiB
Lua

local Gui = require 'utils.gui'
local function toggle(player)
if not player.gui.top.global_chat_toggle then
return
end
local button = player.gui.top.global_chat_toggle
if button.caption == 'Global Chat' then
button.caption = 'Team Chat'
button.tooltip = 'Chat messages are only sent to your team.'
button.style.font_color = {r = 0.77, g = 0.77, b = 0.0}
return
end
button.caption = 'Global Chat'
button.tooltip = 'Chat messages are sent to everyone.'
button.style.font_color = {r = 0.0, g = 0.77, b = 0.0}
end
local function create_gui_button(player)
if player.gui.top.global_chat_toggle then
return
end
local b =
player.gui.top.add(
{
type = 'sprite-button',
name = 'global_chat_toggle',
caption = '',
style = Gui.button_style
}
)
b.style.font = 'heading-2'
b.style.minimal_width = 100
b.style.minimal_height = 38
b.style.maximal_height = 38
b.style.padding = 1
b.style.margin = 0
toggle(player)
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
create_gui_button(player)
end
local function on_gui_click(event)
if not event then
return
end
if not event.element then
return
end
if not event.element.valid then
return
end
local player = game.players[event.element.player_index]
if event.element.name ~= 'global_chat_toggle' then
return
end
toggle(player)
end
local function on_console_chat(event)
if not event.message then
return
end
if not event.player_index then
return
end
local player = game.players[event.player_index]
if not player.gui.top.global_chat_toggle then
return
end
local button = player.gui.top.global_chat_toggle
if button.caption ~= 'Global Chat' then
return
end
for _, force in pairs(game.forces) do
if force.name ~= player.force.name then
force.print(player.name .. ' ' .. player.tag .. ': ' .. event.message, player.chat_color)
end
end
end
local Event = require 'utils.event'
Event.add(defines.events.on_console_chat, on_console_chat)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_gui_click, on_gui_click)