Skip to content

Commit

Permalink
add the no EORG popup (#2070)
Browse files Browse the repository at this point in the history
ONE MORE PR TODAY
  • Loading branch information
MilonPL authored Oct 28, 2024
1 parent 5ad7cbf commit 29c66f3
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Content.Client/DeltaV/RoundEnd/NoEorgPopup.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'no-eorg-popup-title'}"
MinSize="520 450"
MaxSize="520 450">
<BoxContainer Orientation="Vertical" Margin="20">
<Label Name="TitleLabel"
StyleClasses="LabelBig"
HorizontalAlignment="Center"
Margin="0 0 0 5" />
<PanelContainer StyleClasses="BackgroundDark" Margin="0 0 0 10">
<BoxContainer Orientation="Vertical" Margin="10">
<RichTextLabel Name="MessageLabel" HorizontalAlignment="Center" />
<Control MinSize="0 5" />
<RichTextLabel Name="RuleLabel" HorizontalAlignment="Center" />
<RichTextLabel Name="RuleTextLabel" HorizontalAlignment="Center" Margin="0 5 0 0" />
</BoxContainer>
</PanelContainer>
<BoxContainer Orientation="Vertical" VerticalAlignment="Bottom" Margin="0 10 0 0">
<CheckBox Name="SkipCheckBox"
Text="{Loc 'no-eorg-popup-skip-checkbox'}"
HorizontalAlignment="Center"
Margin="0 0 0 10" />
<Button Name="NoEorgCloseButton"
HorizontalAlignment="Center"
MinWidth="150" />
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>
91 changes: 91 additions & 0 deletions Content.Client/DeltaV/RoundEnd/NoEorgPopup.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.DeltaV.CCVars;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

namespace Content.Client.DeltaV.RoundEnd;

[GenerateTypedNameReferences]
public sealed partial class NoEorgPopup : FancyWindow
{
[Dependency] private readonly IConfigurationManager _cfg = default!;

private float _remainingTime;
private bool _initialSkipState;

public NoEorgPopup()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

InitializeUI();
InitializeEvents();
ResetTimer();
}

private void InitializeUI()
{
TitleLabel.Text = Loc.GetString("no-eorg-popup-label");
MessageLabel.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("no-eorg-popup-message")));
RuleLabel.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("no-eorg-popup-rule")));
RuleTextLabel.SetMessage(FormattedMessage.FromMarkupOrThrow(Loc.GetString("no-eorg-popup-rule-text")));

_initialSkipState =
_cfg.GetCVar(DCCVars.SkipRoundEndNoEorgPopup); // Store the initial CVar value to compare against
SkipCheckBox.Pressed = _initialSkipState;
NoEorgCloseButton.Disabled = true;

UpdateCloseButtonText();
}

private void InitializeEvents()
{
OnClose += SaveSkipState; // Only change the CVar once the close button is pressed
NoEorgCloseButton.OnPressed += OnClosePressed;
}

private void ResetTimer()
{
_remainingTime = _cfg.GetCVar(DCCVars.RoundEndNoEorgPopupTime); // Set how long to show the popup for
UpdateCloseButtonText();
}

private void SaveSkipState()
{
if (SkipCheckBox.Pressed == _initialSkipState)
return;

_cfg.SetCVar(DCCVars.SkipRoundEndNoEorgPopup, SkipCheckBox.Pressed);
_cfg.SaveToFile();
}

private void OnClosePressed(BaseButton.ButtonEventArgs args)
{
Close();
}

private void UpdateCloseButtonText()
{
var isWaiting = _remainingTime > 0f;
NoEorgCloseButton.Text = isWaiting
? Loc.GetString("no-eorg-popup-close-button-wait", ("time", (int)MathF.Ceiling(_remainingTime)))
: Loc.GetString("no-eorg-popup-close-button");
NoEorgCloseButton.Disabled = isWaiting;
}

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

if (!NoEorgCloseButton.Disabled)
return;

_remainingTime = MathF.Max(0f, _remainingTime - args.DeltaSeconds);
UpdateCloseButtonText();
}
}

36 changes: 36 additions & 0 deletions Content.Client/DeltaV/RoundEnd/NoEorgPopupSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Content.Shared.GameTicking;
using Content.Shared.DeltaV.CCVars;
using Robust.Shared.Configuration;

namespace Content.Client.DeltaV.RoundEnd;

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

private NoEorgPopup? _window;

public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RoundEndMessageEvent>(OnRoundEnd);
}

private void OnRoundEnd(RoundEndMessageEvent ev)
{
if (_cfg.GetCVar(DCCVars.SkipRoundEndNoEorgPopup) || _cfg.GetCVar(DCCVars.RoundEndNoEorgPopup) == false)
return;

OpenNoEorgPopup();
}

private void OpenNoEorgPopup()
{
if (_window != null)
return;

_window = new NoEorgPopup();
_window.OpenCentered();
_window.OnClose += () => _window = null;
}
}
18 changes: 18 additions & 0 deletions Content.Shared/DeltaV/CCVars/DCCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ public sealed class DCCVars
public static readonly CVarDef<bool> RoundEndPacifist =
CVarDef.Create("game.round_end_pacifist", false, CVar.SERVERONLY);

/// <summary>
/// Whether the no EORG popup is enabled.
/// </summary>
public static readonly CVarDef<bool> RoundEndNoEorgPopup =
CVarDef.Create("game.round_end_eorg_popup_enabled", true, CVar.SERVER | CVar.REPLICATED);

/// <summary>
/// Skip the no EORG popup.
/// </summary>
public static readonly CVarDef<bool> SkipRoundEndNoEorgPopup =
CVarDef.Create("game.skip_round_end_eorg_popup", false, CVar.CLIENTONLY | CVar.ARCHIVE);

/// <summary>
/// How long to display the EORG popup for.
/// </summary>
public static readonly CVarDef<float> RoundEndNoEorgPopupTime =
CVarDef.Create("game.round_end_eorg_popup_time", 5f, CVar.SERVER | CVar.REPLICATED);

/// <summary>
/// Disables all vision filters for species like Vulpkanin or Harpies. There are good reasons someone might want to disable these.
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Resources/Locale/en-US/deltav/roundend/no-eorg-popup.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
no-eorg-popup-title = Delta-V
no-eorg-popup-label = Welcome to the End of Round!
no-eorg-popup-message = [bold]End-of-round grief (EORG)[/bold] is not allowed at Delta-V. Please stay in character until the lobby screen appears to maintain an immersive environment for everyone. Thank you for respecting the community rules!
no-eorg-popup-rule = [bold][color=#a4885c]Rule B4: Significant end-of-round grief (EORG) is not allowed.[/color][/bold]
no-eorg-popup-rule-text = This includes attacking, destroying, polluting, and severely injuring without reason both at and on the way to Central Command. Remember that you are playing a character throughout the round.
no-eorg-popup-close-button = Sounds good!
no-eorg-popup-close-button-wait = The close button will be enabled after {$time} seconds.
no-eorg-popup-skip-checkbox = Don't show this again.

0 comments on commit 29c66f3

Please sign in to comment.