mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-06-09 12:06:35 +02:00
Merge pull request #3602 from KloopRE/ahelp
отображение префиксов ролей администратора и антагониста в UI Ahelp
This commit is contained in:
@@ -25,6 +25,7 @@ using Robust.Shared.Network;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Server.Corvax.Administration; // Corvax-Administration
|
||||
|
||||
namespace Content.Server.Administration.Systems
|
||||
{
|
||||
@@ -678,6 +679,11 @@ namespace Content.Server.Administration.Systems
|
||||
|
||||
bwoinkText = $"{(message.AdminOnly ? Loc.GetString("bwoink-message-admin-only") : !message.PlaySound ? Loc.GetString("bwoink-message-silent") : "")} {bwoinkText}: {escapedText}";
|
||||
|
||||
// Corvax-Start-Administration
|
||||
var transformEv = new TransformBwoinkTextEvent(bwoinkText, senderSession);
|
||||
RaiseLocalEvent(ref transformEv);
|
||||
bwoinkText = transformEv.Text;
|
||||
// Corvax-End-Administration
|
||||
// If it's not an admin / admin chooses to keep the sound and message is not an admin only message, then play it.
|
||||
var playSound = (!senderAHelpAdmin || message.PlaySound) && !message.AdminOnly;
|
||||
var msg = new BwoinkTextMessage(message.UserId, senderSession.UserId, bwoinkText, playSound: playSound, adminOnly: message.AdminOnly);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Corvax.Administration;
|
||||
|
||||
public sealed partial class BwoinkMetadataSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private IAdminManager _adminManager = default!;
|
||||
[Dependency] private IServerPreferencesManager _preferencesManager = default!;
|
||||
[Dependency] private SharedMindSystem _mind = default!;
|
||||
[Dependency] private SharedRoleSystem _role = default!;
|
||||
|
||||
private static readonly Regex AdminColorRegex = new(@"\[color=(red|purple)\]", RegexOptions.Compiled);
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<TransformBwoinkTextEvent>(OnTransformBwoinkText);
|
||||
}
|
||||
|
||||
private void OnTransformBwoinkText(ref TransformBwoinkTextEvent ev)
|
||||
{
|
||||
var adminData = _adminManager.GetAdminData(ev.SenderSession);
|
||||
|
||||
if (adminData is not null)
|
||||
{
|
||||
if (_adminManager.HasAdminFlag(ev.SenderSession, AdminFlags.NameColor))
|
||||
{
|
||||
var prefs = _preferencesManager.GetPreferencesOrNull(ev.SenderSession.UserId);
|
||||
if (prefs != null)
|
||||
{
|
||||
var hex = prefs.AdminOOCColor.ToHex();
|
||||
ev.Text = AdminColorRegex.Replace(ev.Text, $"[color={hex}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var prefix = GetAntagPrefix(ev.SenderSession);
|
||||
if (prefix != null)
|
||||
ev.Text = InsertPrefix(ev.Text, ev.SenderSession.Name, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
private string? GetAntagPrefix(ICommonSession session)
|
||||
{
|
||||
var mindId = _mind.GetMind(session.UserId);
|
||||
if (mindId is not { } mind)
|
||||
return null;
|
||||
|
||||
var roles = _role.MindGetAllRoleInfo(mind);
|
||||
var antagRoles = roles.Where(r => r.Antagonist).ToList();
|
||||
|
||||
if (antagRoles.Count == 0)
|
||||
return null;
|
||||
|
||||
var color = AntagPrototype.GroupColor.ToHex();
|
||||
var names = string.Join(", ", antagRoles.Select(r => Loc.GetString(r.Name)));
|
||||
return $"[color={color}]\\[{names}\\][/color]";
|
||||
}
|
||||
|
||||
private static string InsertPrefix(string text, string playerName, string prefix)
|
||||
{
|
||||
var index = text.IndexOf(playerName, StringComparison.Ordinal);
|
||||
if (index < 0)
|
||||
return text;
|
||||
|
||||
// Вставляем префикс перед первым вхождением имени игрока: [текст до имени] + [префикс] + " " + [имя] + [текст после имени]
|
||||
return text[..index] + prefix + " " + playerName + text[(index + playerName.Length)..];
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public struct TransformBwoinkTextEvent
|
||||
{
|
||||
public string Text;
|
||||
public ICommonSession SenderSession;
|
||||
|
||||
public TransformBwoinkTextEvent(string text, ICommonSession senderSession)
|
||||
{
|
||||
Text = text;
|
||||
SenderSession = senderSession;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user