Skip to content

Commit

Permalink
Коллективный разум (#248)
Browse files Browse the repository at this point in the history
* Коллективный разум

* Колективный разум гуманоидному ксеносу
  • Loading branch information
VigersRay authored Jul 27, 2024
1 parent adb8552 commit bb2e9f6
Show file tree
Hide file tree
Showing 24 changed files with 453 additions and 25 deletions.
32 changes: 32 additions & 0 deletions Content.Client/Chat/CollectiveMindChatUpdateSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Content.Client.Chat.Managers;
using Content.Shared.Sunrise.CollectiveMind;
using Robust.Client.Player;

namespace Content.Client.Chat
{
public sealed class CollectiveMindChatUpdateSystem : EntitySystem
{
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CollectiveMindComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<CollectiveMindComponent, ComponentRemove>(OnRemove);
}

public CollectiveMindComponent? Player => CompOrNull<CollectiveMindComponent>(_playerManager.LocalSession?.AttachedEntity);
public bool IsCollectiveMind => Player != null;

private void OnInit(EntityUid uid, CollectiveMindComponent component, ComponentInit args)
{
_chatManager.UpdatePermissions();
}

private void OnRemove(EntityUid uid, CollectiveMindComponent component, ComponentRemove args)
{
_chatManager.UpdatePermissions();
}
}
}
15 changes: 15 additions & 0 deletions Content.Client/Chat/Managers/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal sealed class ChatManager : IChatManager
[Dependency] private readonly IEntitySystemManager _systems = default!;

private ISawmill _sawmill = default!;
public event Action? PermissionsUpdated; // Sunrise-Edit

public void Initialize()
{
Expand Down Expand Up @@ -67,9 +68,23 @@ public void SendMessage(string text, ChatSelectChannel channel)
_consoleHost.ExecuteCommand($"whisper \"{CommandParsing.Escape(str)}\"");
break;

// Sunrise-Start
case ChatSelectChannel.CollectiveMind:
_consoleHost.ExecuteCommand($"cmsay \"{CommandParsing.Escape(str)}\"");
break;
// Sunrise-End


default:
throw new ArgumentOutOfRangeException(nameof(channel), channel, null);
}
}

// Sunrise-Start
public void UpdatePermissions()
{
PermissionsUpdated?.Invoke();
}
// Sunrise-End
}
}
3 changes: 2 additions & 1 deletion Content.Client/Chat/Managers/IChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace Content.Client.Chat.Managers
public interface IChatManager
{
void Initialize();

event Action PermissionsUpdated; // Sunrise-Edit
public void SendMessage(string text, ChatSelectChannel channel);
public void UpdatePermissions(); // Sunrise-Edit
}
}
71 changes: 57 additions & 14 deletions Content.Client/UserInterface/Systems/Chat/ChatUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
using Content.Client.UserInterface.Screens;
using Content.Client.UserInterface.Systems.Chat.Widgets;
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Shared._Sunrise.CollectiveMind;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Decals;
using Content.Shared.Damage.ForceSay;
using Content.Shared.Decals;
using Content.Shared.Input;
Expand Down Expand Up @@ -57,6 +59,7 @@ public sealed class ChatUIController : UIController

[UISystemDependency] private readonly ExamineSystem? _examine = default;
[UISystemDependency] private readonly GhostSystem? _ghost = default;
[UISystemDependency] private readonly CollectiveMindChatUpdateSystem? _collectiveMind = default!;
[UISystemDependency] private readonly TypingIndicatorSystem? _typingIndicator = default;
[UISystemDependency] private readonly ChatSystem? _chatSys = default;
[UISystemDependency] private readonly TransformSystem? _transform = default;
Expand All @@ -79,7 +82,8 @@ public sealed class ChatUIController : UIController
{SharedChatSystem.EmotesAltPrefix, ChatSelectChannel.Emotes},
{SharedChatSystem.AdminPrefix, ChatSelectChannel.Admin},
{SharedChatSystem.RadioCommonPrefix, ChatSelectChannel.Radio},
{SharedChatSystem.DeadPrefix, ChatSelectChannel.Dead}
{SharedChatSystem.DeadPrefix, ChatSelectChannel.Dead},
{SharedChatSystem.CollectiveMindPrefix, ChatSelectChannel.CollectiveMind} // Sunrise-Edit
};

public static readonly Dictionary<ChatSelectChannel, char> ChannelPrefixes = new()
Expand All @@ -92,7 +96,8 @@ public sealed class ChatUIController : UIController
{ChatSelectChannel.Emotes, SharedChatSystem.EmotesPrefix},
{ChatSelectChannel.Admin, SharedChatSystem.AdminPrefix},
{ChatSelectChannel.Radio, SharedChatSystem.RadioCommonPrefix},
{ChatSelectChannel.Dead, SharedChatSystem.DeadPrefix}
{ChatSelectChannel.Dead, SharedChatSystem.DeadPrefix},
{ChatSelectChannel.CollectiveMind, SharedChatSystem.CollectiveMindPrefix} // Sunrise-Edit
};

/// <summary>
Expand Down Expand Up @@ -173,6 +178,7 @@ public override void Initialize()
_sawmill = Logger.GetSawmill("chat");
_sawmill.Level = LogLevel.Info;
_admin.AdminStatusUpdated += UpdateChannelPermissions;
_manager.PermissionsUpdated += UpdateChannelPermissions; // Sunrise-Edit
_player.LocalPlayerAttached += OnAttachedChanged;
_player.LocalPlayerDetached += OnAttachedChanged;
_state.OnStateChanged += StateChanged;
Expand Down Expand Up @@ -222,6 +228,11 @@ public override void Initialize()
_input.SetInputCommand(ContentKeyFunctions.CycleChatChannelBackward,
InputCmdHandler.FromDelegate(_ => CycleChatChannel(false)));

// Sunrise-Start
_input.SetInputCommand(ContentKeyFunctions.FocusCollectiveMindChat,
InputCmdHandler.FromDelegate(_ => FocusChannel(ChatSelectChannel.CollectiveMind)));
// Sunrise-End

var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
gameplayStateLoad.OnScreenLoad += OnScreenLoad;
gameplayStateLoad.OnScreenUnload += OnScreenUnload;
Expand Down Expand Up @@ -552,7 +563,16 @@ private void UpdateChannelPermissions()
FilterableChannels |= ChatChannel.AdminAlert;
FilterableChannels |= ChatChannel.AdminChat;
CanSendChannels |= ChatSelectChannel.Admin;
FilterableChannels |= ChatChannel.CollectiveMind; // Sunrise-Edit
}

// Sunrise-Start
if (_collectiveMind != null && _collectiveMind.IsCollectiveMind)
{
FilterableChannels |= ChatChannel.CollectiveMind;
CanSendChannels |= ChatSelectChannel.CollectiveMind;
}
// Sunrise-End

SelectableChannels = CanSendChannels;

Expand Down Expand Up @@ -683,21 +703,39 @@ private bool TryGetRadioChannel(string text, out RadioChannelPrototype? radioCha
&& _chatSys.TryProccessRadioMessage(uid, text, out _, out radioChannel, quiet: true);
}

// Sunrise-Start
private bool TryGetCollectiveMind(string text, out CollectiveMindPrototype? collectiveMind)
{
collectiveMind = null;
return _player.LocalEntity is { Valid: true } uid
&& _chatSys != null
&& _chatSys.TryProccessCollectiveMindMessage(uid, text, out _, out collectiveMind, quiet: true);
}

public void UpdateSelectedChannel(ChatBox box)
{
var (prefixChannel, _, radioChannel) = SplitInputContents(box.ChatInput.Input.Text.ToLower());
var (prefixChannel, _, radioChannel, collectiveMind) = SplitInputContents(box.ChatInput.Input.Text.ToLower());

if (prefixChannel == ChatSelectChannel.None)
box.ChatInput.ChannelSelector.UpdateChannelSelectButton(box.SelectedChannel, null);
else
box.ChatInput.ChannelSelector.UpdateChannelSelectButton(prefixChannel, radioChannel);
switch (prefixChannel)
{
case ChatSelectChannel.None:
box.ChatInput.ChannelSelector.UpdateChannelSelectButton(box.SelectedChannel, null, null);
break;
case ChatSelectChannel.CollectiveMind:
box.ChatInput.ChannelSelector.UpdateChannelSelectButton(prefixChannel, null, collectiveMind);
break;
default:
box.ChatInput.ChannelSelector.UpdateChannelSelectButton(prefixChannel, radioChannel, null);
break;
}
}
// Sunrise-End

public (ChatSelectChannel chatChannel, string text, RadioChannelPrototype? radioChannel) SplitInputContents(string text)
public (ChatSelectChannel chatChannel, string text, RadioChannelPrototype? radioChannel, CollectiveMindPrototype? collectiveMind) SplitInputContents(string text)
{
text = text.Trim();
if (text.Length == 0)
return (ChatSelectChannel.None, text, null);
return (ChatSelectChannel.None, text, null, null); // Sunrise-Edit

// We only cut off prefix only if it is not a radio or local channel, which both map to the same /say command
// because ????????
Expand All @@ -709,20 +747,25 @@ public void UpdateSelectedChannel(ChatBox box)
chatChannel = PrefixToChannel.GetValueOrDefault(text[0]);

if ((CanSendChannels & chatChannel) == 0)
return (ChatSelectChannel.None, text, null);
return (ChatSelectChannel.None, text, null, null); // Sunrise-Edit

if (chatChannel == ChatSelectChannel.Radio)
return (chatChannel, text, radioChannel);
return (chatChannel, text, radioChannel, null); // Sunrise-Edit

// Sunrise-Start
if (TryGetCollectiveMind(text, out var collectiveMind) && chatChannel == ChatSelectChannel.CollectiveMind)
return (chatChannel, text, radioChannel, collectiveMind);
// Sunrise-End

if (chatChannel == ChatSelectChannel.Local)
{
if (_ghost?.IsGhost != true)
return (chatChannel, text, null);
return (chatChannel, text, null, null); // Sunrise-Edit
else
chatChannel = ChatSelectChannel.Dead;
}

return (chatChannel, text[1..].TrimStart(), null);
return (chatChannel, text[1..].TrimStart(), null, null); // Sunrise-Edit
}

public void SendMessage(ChatBox box, ChatSelectChannel channel)
Expand All @@ -737,7 +780,7 @@ public void SendMessage(ChatBox box, ChatSelectChannel channel)
if (string.IsNullOrWhiteSpace(text))
return;

(var prefixChannel, text, var _) = SplitInputContents(text);
(var prefixChannel, text, var _, var _) = SplitInputContents(text); // Sunrise-Edit

// Check if message is longer than the character limit
if (text.Length > MaxMessageLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public sealed partial class ChannelFilterPopup : Popup
ChatChannel.Admin,
ChatChannel.AdminAlert,
ChatChannel.AdminChat,
ChatChannel.Server
ChatChannel.Server,
ChatChannel.CollectiveMind // Sunrise-Edit
};

private readonly Dictionary<ChatChannel, ChannelFilterCheckbox> _filterStates = new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using Content.Shared._Sunrise.CollectiveMind;
using Content.Shared.Chat;

namespace Content.Client.UserInterface.Systems.Chat.Controls;
Expand Down Expand Up @@ -68,9 +69,24 @@ public Color ChannelSelectColor(ChatSelectChannel channel)
};
}

public void UpdateChannelSelectButton(ChatSelectChannel channel, Shared.Radio.RadioChannelPrototype? radio)
// Sunrise-Start
public void UpdateChannelSelectButton(ChatSelectChannel channel, Shared.Radio.RadioChannelPrototype? radio, CollectiveMindPrototype? collectiveMind)
{
Text = radio != null ? Loc.GetString(radio.Name) : ChannelSelectorName(channel);
Modulate = radio?.Color ?? ChannelSelectColor(channel);
if (radio != null)
{
Text = Loc.GetString(radio.Name);
Modulate = radio?.Color ?? ChannelSelectColor(channel);
}
else if (collectiveMind != null)
{
Text = Loc.GetString(collectiveMind.Name);
Modulate = collectiveMind.Color;
}
else
{
Text = ChannelSelectorName(channel);
Modulate = ChannelSelectColor(channel);
}
}
// Sunrise-End
}
42 changes: 42 additions & 0 deletions Content.Server/Chat/Commands/CollectiveMindCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Content.Server.Chat.Systems;
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.Enums;

namespace Content.Server.Chat.Commands
{
[AnyCommand]
internal sealed class CollectiveMindCommand : IConsoleCommand
{
public string Command => "cmsay";
public string Description => "Send chat messages to the collective mind.";
public string Help => "cmsay <text>";

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (shell.Player is not { } player)
{
shell.WriteError("This command cannot be run from the server.");
return;
}

if (player.Status != SessionStatus.InGame)
return;

if (player.AttachedEntity is not {} playerEntity)
{
shell.WriteError("You don't have an entity!");
return;
}

if (args.Length < 1)
return;

var message = string.Join(" ", args).Trim();
if (string.IsNullOrEmpty(message))
return;

EntitySystem.Get<ChatSystem>().TrySendInGameICMessage(playerEntity, message, InGameICChatType.CollectiveMind, ChatTransmitRange.Normal);
}
}
}
Loading

0 comments on commit bb2e9f6

Please sign in to comment.