Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/sunrise_public/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
VigersRay committed Jan 22, 2025
2 parents 2bc550c + d44fffa commit a3a4e47
Show file tree
Hide file tree
Showing 106 changed files with 252,436 additions and 57,069 deletions.
1 change: 1 addition & 0 deletions Content.Client/Options/UI/Tabs/ExtraTab.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<!-- Graphics -->
<Label Text="{Loc 'ui-options-sunrise-general-graphics'}" StyleClasses="LabelKeyText"/>
<CheckBox Name="ChatIconsEnableCheckBox" Text="{Loc 'ui-options-chat-icons-enable'}" />

</BoxContainer>
</ScrollContainer>
Expand Down
2 changes: 2 additions & 0 deletions Content.Client/Options/UI/Tabs/ExtraTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public ExtraTab()
Control.AddOptionCheckBox(SunriseCCVars.DamageOverlaySelf, DamageOverlaySelfCheckBox);
Control.AddOptionCheckBox(SunriseCCVars.DamageOverlayStructures, DamageOverlayStructuresCheckBox);

Control.AddOptionCheckBox(SunriseCCVars.ChatIconsEnable, ChatIconsEnableCheckBox);

Control.Initialize();
}

Expand Down
20 changes: 18 additions & 2 deletions Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Robust.Shared.Input;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using System.Linq;
using static Robust.Client.UserInterface.Controls.LineEdit;

namespace Content.Client.UserInterface.Systems.Chat.Widgets;
Expand Down Expand Up @@ -81,7 +82,7 @@ private void OnChannelSelect(ChatSelectChannel channel)

public void Repopulate()
{
Contents.Clear();
ClearChatContents(); // Sunrise

foreach (var message in _controller.History)
{
Expand All @@ -91,7 +92,7 @@ public void Repopulate()

private void OnChannelFilter(ChatChannel channel, bool active)
{
Contents.Clear();
ClearChatContents(); // Sunrise

foreach (var message in _controller.History)
{
Expand All @@ -104,6 +105,21 @@ private void OnChannelFilter(ChatChannel channel, bool active)
}
}

// Sunrise start
private void ClearChatContents()
{
Contents.Clear();

foreach (var child in Contents.Children.ToArray())
{
if (child.Name != "_v_scroll")
{
Contents.RemoveChild(child);
}
}
}
// Sunrise end

public void AddLine(string message, Color color)
{
var formatted = new FormattedMessage(3);
Expand Down
31 changes: 31 additions & 0 deletions Content.Client/_Sunrise/ChatIcons/RadioIconsSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Content.Client.UserInterface.Systems.Chat;
using Content.Shared._Sunrise.SunriseCCVars;
using Robust.Client.UserInterface;
using Robust.Shared.Configuration;

namespace Content.Client._Sunrise.ChatIcons;

public sealed class ChatIconsSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IUserInterfaceManager _uiMan = default!;

public override void Initialize()
{
base.Initialize();

_cfg.OnValueChanged(SunriseCCVars.ChatIconsEnable, OnRadioIconsChanged, true);
}

public override void Shutdown()
{
base.Shutdown();

_cfg.UnsubValueChanged(SunriseCCVars.ChatIconsEnable, OnRadioIconsChanged);
}

private void OnRadioIconsChanged(bool enable)
{
_uiMan.GetUIController<ChatUIController>().Repopulate();
}
}
100 changes: 100 additions & 0 deletions Content.Client/_Sunrise/UserInterface/RichText/RadioIconTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Content.Shared._Sunrise.SunriseCCVars;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.RichText;
using Robust.Shared.Configuration;
using Robust.Shared.Utility;

namespace Content.Client._Sunrise.UserInterface.RichText;

public sealed class RadioIconTag : IMarkupTag
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IResourceCache _cache = default!;

public string Name => "radicon";

/// <inheritdoc/>
public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? control)
{
if (_cfg.GetCVar(SunriseCCVars.ChatIconsEnable))
{
if (!node.Attributes.TryGetValue("path", out var rawPath))
{
control = null;
return false;
}

if (!node.Attributes.TryGetValue("scale", out var scale) || !scale.TryGetLong(out var scaleValue))
{
scaleValue = 1;
}

control = DrawIcon(rawPath.ToString(), scaleValue.Value);
}
else
{
if (!node.Attributes.TryGetValue("text", out var text))
{
control = null;
return false;
}

if (!node.Attributes.TryGetValue("color", out var color))
{
control = null;
return false;
}

control = DrawText(text.ToString(), color.ToString());
}

return true;
}

private Control DrawIcon(string path, long scaleValue)
{
var texture = new TextureRect();

path = ClearString(path);

texture.TexturePath = path;
texture.TextureScale = new Vector2(scaleValue, scaleValue);

return texture;
}

private Control DrawText(string text, string color)
{
var label = new Label();

color = ClearString(color);
text = ClearString(text);

label.Text = text;
label.FontColorOverride = Color.FromHex(color);
label.FontOverride = new VectorFont(_cache.GetResource<FontResource>("/Fonts/NotoSans/NotoSans-Bold.ttf"), 13);

return label;
}

/// <summary>
/// Очищает строку от мусора, который приходит вместе с ней
/// </summary>
/// <remarks>
/// Почему мне приходят строки в говне
/// </remarks>
private static string ClearString(string str)
{
str = str.Replace("=", "");
str = str.Replace(" ", "");
str = str.Replace("\"", "");

return str;
}

}
42 changes: 42 additions & 0 deletions Content.Client/_Sunrise/UserInterface/RichText/TextureTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.RichText;

using Robust.Shared.Utility;

namespace Content.Client._Sunrise.UserInterface.RichText;

public sealed class TextureTag : IMarkupTag
{
public string Name => "tex";

/// <inheritdoc/>
public bool TryGetControl(MarkupNode node, [NotNullWhen(true)] out Control? control)
{
if (!node.Attributes.TryGetValue("path", out var rawPath))
{
control = null;
return false;
}

if (!node.Attributes.TryGetValue("scale", out var scale) || !scale.TryGetLong(out var scaleValue))
{
scaleValue = 1;
}

var texture = new TextureRect();

var path = rawPath.ToString();
path = path.Replace("=", "");
path = path.Replace(" ", "");
path = path.Replace("\"", "");

texture.TexturePath = path;
texture.TextureScale = new Vector2(scaleValue.Value, scaleValue.Value);

control = texture;
return true;
}
}
29 changes: 3 additions & 26 deletions Content.Server/Administration/Managers/BanManager.Notification.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Content.Server.Database;

namespace Content.Server.Administration.Managers;

Expand Down Expand Up @@ -30,36 +28,15 @@ public sealed partial class BanManager
private TimeSpan _banNotificationRateLimitStart;
private int _banNotificationRateLimitCount;

private void OnDatabaseNotification(DatabaseNotification notification)
private bool OnDatabaseNotificationEarlyFilter()
{
if (notification.Channel != BanNotificationChannel)
return;

if (notification.Payload == null)
{
_sawmill.Error("Got ban notification with null payload!");
return;
}

BanNotificationData data;
try
{
data = JsonSerializer.Deserialize<BanNotificationData>(notification.Payload)
?? throw new JsonException("Content is null");
}
catch (JsonException e)
{
_sawmill.Error($"Got invalid JSON in ban notification: {e}");
return;
}

if (!CheckBanRateLimit())
{
_sawmill.Verbose("Not processing ban notification due to rate limit");
return;
return false;
}

_taskManager.RunOnMainThread(() => ProcessBanNotification(data));
return true;
}

private async void ProcessBanNotification(BanNotificationData data)
Expand Down
7 changes: 6 additions & 1 deletion Content.Server/Administration/Managers/BanManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ public void Initialize()
{
_netManager.RegisterNetMessage<MsgRoleBans>();

_db.SubscribeToNotifications(OnDatabaseNotification);
_db.SubscribeToJsonNotification<BanNotificationData>(
_taskManager,
_sawmill,
BanNotificationChannel,
ProcessBanNotification,
OnDatabaseNotificationEarlyFilter);

_userDbData.AddOnLoadPlayer(CachePlayerData);
_userDbData.AddOnPlayerDisconnect(ClearPlayerData);
Expand Down
Loading

0 comments on commit a3a4e47

Please sign in to comment.