Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluwne comm #2153

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Communications;
using Robust.Client.UserInterface;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;

namespace Content.Client.SS220.CluwneComms.UI
{
public sealed class CluwneCommunicationsConsoleBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IConfigurationManager _cfg = default!;

[ViewVariables]
private CluwneCommunicationsConsoleMenu? _menu;

public CluwneCommunicationsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();

_menu = this.CreateWindow<CluwneCommunicationsConsoleMenu>();
_menu.OnAnnounce += AnnounceButtonPressed;
}

public void AnnounceButtonPressed(string message)
{
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
var msg = SharedChatSystem.SanitizeAnnouncement(message, maxLength);
SendMessage(new CommunicationsConsoleAnnounceMessage(msg));
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not CommunicationsConsoleInterfaceState commsState)
return;

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:ui220="clr-namespace:Content.Client.SS220.UserInterface"
Title="{Loc 'cluwne-comms-console-menu-title'}"
MinSize="400 225">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="5">
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="5">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<ui220:ExtendedTextEdit Name="CodeInput" HorizontalExpand="True" VerticalExpand="True" Margin="0 0 0 5" MinHeight="100" />
</BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<ui220:ExtendedTextEdit Name="InstructionInput" HorizontalExpand="True" VerticalExpand="True" Margin="0 0 0 5" MinHeight="100" />
<OptionButton Name="AlertLevelButton" StyleClasses="OpenRight" Access="Public" />
<Button Name="CodeButton" Text="{Loc 'cluwne-comms-console-menu-code-button'}" StyleClasses="OpenLeft" Access="Public" />
</BoxContainer>
</BoxContainer>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" Margin="5">
<ui220:ExtendedTextEdit Name="MessageInput" HorizontalExpand="True" VerticalExpand="True" Margin="0 0 0 5" MinHeight="100" />
<Button Name="AnnounceButton" Text="{Loc 'cluwne-comms-console-menu-announcement-button'}" StyleClasses="OpenLeft" Access="Public" />
</BoxContainer>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using System.Globalization;
using Content.Client.UserInterface.Controls;
using Content.Shared.CCVar;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client.SS220.CluwneComms.UI
{
[GenerateTypedNameReferences]
public sealed partial class CluwneCommunicationsConsoleMenu : FancyWindow
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;

public bool CanAnnounce;
public bool CanAllert;
public bool AlertLevelSelectable;
public bool CountdownStarted;
public string CurrentLevel = string.Empty;
public TimeSpan? CountdownEnd;

public event Action? OnEmergencyLevel;
public event Action<string>? OnAlertLevel;
public event Action<string>? OnAnnounce;
public CluwneCommunicationsConsoleMenu()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

// SS220 Text Edit Limits begin
//MessageInput.Placeholder = new Rope.Leaf(_loc.GetString("comms-console-menu-announcement-placeholder"));

//var maxAnnounceLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
//MessageInput.OnTextChanged += (args) =>
MessageInput.Edit.Placeholder = new Rope.Leaf(_loc.GetString("comms-console-menu-announcement-placeholder"));

var maxAnnounceLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
MessageInput.MaxLength = maxAnnounceLength;
MessageInput.Edit.OnTextChanged += (args) =>
// SS220 Text Edit Limits end
{
if (args.Control.TextLength > maxAnnounceLength)
{
AnnounceButton.Disabled = true;
AnnounceButton.ToolTip = Loc.GetString("comms-console-message-too-long");
}
else
{
AnnounceButton.Disabled = !CanAnnounce;
AnnounceButton.ToolTip = null;
}
};

AnnounceButton.OnPressed += _ => OnAnnounce?.Invoke(Rope.Collapse(MessageInput.TextRope));
AnnounceButton.Disabled = !CanAnnounce;

AlertLevelButton.OnItemSelected += args =>
{
var metadata = AlertLevelButton.GetItemMetadata(args.Id);
if (metadata != null && metadata is string cast)
{
OnAlertLevel?.Invoke(cast);
}
};


AlertLevelButton.Disabled = !AlertLevelSelectable;
}

protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
UpdateCountdown();
}

public void UpdateCountdown()
{
/*
if (!CountdownStarted)
{
CountdownLabel.SetMessage(string.Empty);
return;
}

var diff = MathHelper.Max((CountdownEnd - _timing.CurTime) ?? TimeSpan.Zero, TimeSpan.Zero);

var infoText = Loc.GetString($"comms-console-menu-time-remaining",
("time", diff.ToString(@"hh\:mm\:ss", CultureInfo.CurrentCulture)));
CountdownLabel.SetMessage(infoText);
*/
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using Content.Server.UserInterface;
using Content.Shared.Communications;
using Robust.Shared.Audio;

namespace Content.Server.SS220.CluwneCommunications
{
[RegisterComponent]
public sealed partial class CluwneCommunicationsConsoleComponent : SharedCluwneCommunicationsConsoleComponent
{
public float UIUpdateAccumulator = 0f;

/// <summary>
/// Remaining cooldown between making announcements.
/// </summary>
[ViewVariables]
[DataField]
public float AnnouncementCooldownRemaining;

/// <summary>
/// Fluent ID for the announcement title
/// If a Fluent ID isn't found, just uses the raw string
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField(required: true)]
public LocId Title = "comms-console-announcement-title-station";

/// <summary>
/// Announcement color
/// </summary>
[ViewVariables]
[DataField]
public Color Color = Color.Gold;

/// <summary>
/// Time in seconds between announcement delays on a per-console basis
/// </summary>
[ViewVariables]
[DataField]
public int Delay = 90;

/// <summary>
/// Time in seconds of announcement cooldown when a new console is created on a per-console basis
/// </summary>
[ViewVariables]
[DataField]
public int InitialDelay = 30;

/// <summary>
/// Announce on all grids (for nukies)
/// </summary>
[DataField]
public bool Global = false;

/// <summary>
/// Announce sound file path
/// </summary>
[DataField]
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Announcements/announce.ogg");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Robust.Shared.Audio;
using Robust.Shared.Serialization;

namespace Content.Shared.SS220.CluwneCommunications;

[RegisterComponent]
public sealed partial class CluwneCommunicationsConsoleComponent : Component
{
[ViewVariables]
[DataField]
public bool CanAnnounce;

[ViewVariables]
[DataField]
public bool CanAlert;

public string AlertLevel = "Unknown";

/// <summary>
/// Remaining cooldown between making announcements.
/// </summary>
[ViewVariables]
[DataField]
public TimeSpan? AnnouncementCooldownRemaining;

[ViewVariables]
[DataField]
public TimeSpan? AlertCooldownRemaining;

/// <summary>
/// Time in seconds of announcement cooldown when a new console is created on a per-console basis
/// </summary>
[ViewVariables]
[DataField]
public TimeSpan Delay = TimeSpan.FromMinutes(5);

/// <summary>
/// Fluent ID for the announcement title
/// If a Fluent ID isn't found, just uses the raw string
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField(required: true)]
public LocId Title = "cluwne-comms-console-announcement-title-station";

/// <summary>
/// Announcement color
/// </summary>
[ViewVariables]
[DataField]
public Color Color = Color.Gold;

/// <summary>
/// Announce on all grids (for nukies)
/// </summary>
[DataField]
public bool Global = false;

/// <summary>
/// Announce sound file path
/// </summary>
[DataField]
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/SS220/Announcements/cluwne_comm_announce.ogg");
}
[Serializable, NetSerializable]
public sealed class CluwneCommunicationsConsoleInterfaceState(bool canAnnounce, string currentAlert) : BoundUserInterfaceState
{
public readonly bool CanAnnounce = canAnnounce;
public string CurrentAlert = currentAlert;
}

[Serializable, NetSerializable]
public sealed class CluwneCommunicationsConsoleAnnounceMessage(string message) : BoundUserInterfaceMessage
{
public readonly string Message = message;
}


[Serializable, NetSerializable]
public enum CluwneCommunicationsConsoleUiKey : byte
{
Key
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Content.Shared.Communications;
using Robust.Shared.Timing;
using Robust.Shared.GameObjects;
using static Content.Shared.Access.Components.AccessOverriderComponent;
using System.ComponentModel;

namespace Content.Shared.SS220.CluwneCommunications
{
public sealed class SharedCluwneCommunicationssConsoleSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;

public override void Initialize()
{
SubscribeLocalEvent<CluwneCommunicationsConsoleComponent, MapInitEvent>(OnMapInit);
}
public void OnMapInit(Entity<CluwneCommunicationsConsoleComponent> ent, ref MapInitEvent args)
{
ent.Comp.AnnouncementCooldownRemaining = _timing.CurTime + ent.Comp.Delay;
ent.Comp.AlertCooldownRemaining = _timing.CurTime + ent.Comp.Delay;
ent.Comp.CanAnnounce = false;
ent.Comp.CanAlert = false;
}

public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<CluwneCommunicationsConsoleComponent>();
while (query.MoveNext(out var uid, out var comp))
{
if (!comp.CanAnnounce && _timing.CurTime >= comp.AnnouncementCooldownRemaining)
{
comp.CanAnnounce = true;
UpdateUI(uid, comp);
}

if (!comp.CanAlert && _timing.CurTime >= comp.AlertCooldownRemaining)
{
comp.CanAlert = true;
UpdateUI(uid, comp);
}
}
}

private void UpdateUI(EntityUid ent, CluwneCommunicationsConsoleComponent comp)
{
CluwneCommunicationsConsoleInterfaceState newState = new CluwneCommunicationsConsoleInterfaceState(
comp.CanAnnounce,
PrivilegedIdIsAuthorized(uid, component),
currentAccess,
possibleAccess,
missingAccess,
privilegedIdName,
targetLabel,
targetLabelColor);

_uiSystem.SetUiState(ent, CommunicationsConsoleUiKey.Key, newState);
}
}
}
4 changes: 4 additions & 0 deletions Resources/Audio/SS220/Announcements/attributions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- files: ["cluwne_comm_announce.ogg"]
license: "CC0-1.0"
copyright: "Downloaded from free library, modified by SkaldetSkaeg"
source: "https://sound-pack.net/imitaciya-loshadinogo-rzhaniya-na-trube-2-zvuk-mp3"
Binary file not shown.
Loading
Loading