Add a wait time for the rules popup (#5823)
* Create new rules popup * Implement accept and quit buttons * Add rules accept timer Forces the player to read the rules by making them wait. Speed reading the rules took me just under 45 seconds which means it'll take longer than that if someone's reading this for the first time. * Fix info rules header * Change _rulesPopup to local variable
This commit is contained in:
@@ -6,7 +6,6 @@ using Content.Client.Info;
|
||||
using Content.Client.Resources;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.Targeting;
|
||||
using Content.Shared;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.HUD;
|
||||
using Content.Shared.Input;
|
||||
@@ -304,8 +303,6 @@ namespace Content.Client.HUD
|
||||
|
||||
_rulesAndInfoWindow = new RulesAndInfoWindow();
|
||||
|
||||
IoCManager.Resolve<RulesManager>().OpenRulesAndInfoWindow += OpenRulesAndInfoWindow;
|
||||
|
||||
_rulesAndInfoWindow.OnClose += () => _buttonInfo.Pressed = false;
|
||||
|
||||
_inputManager.SetInputCommand(ContentKeyFunctions.OpenInfo,
|
||||
@@ -431,12 +428,6 @@ namespace Content.Client.HUD
|
||||
LC.SetGrowVertical(VoteContainer, LC.GrowDirection.End);
|
||||
}
|
||||
|
||||
private void OpenRulesAndInfoWindow()
|
||||
{
|
||||
_rulesAndInfoWindow.OpenCentered();
|
||||
_buttonInfo.Pressed = true;
|
||||
}
|
||||
|
||||
private void ButtonInfoOnOnToggled()
|
||||
{
|
||||
_buttonInfo.StyleClasses.Remove(TopButton.StyleClassRedTopButton);
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace Content.Client.Info
|
||||
|
||||
private void PopulateRules(Info rulesList)
|
||||
{
|
||||
AddSection(rulesList, Loc.GetString("ui-info-header-rules"), "Rules.txt", true);
|
||||
AddSection(rulesList, Loc.GetString("ui-rules-header"), "Rules.txt", true);
|
||||
}
|
||||
|
||||
private void PopulateTutorial(Info tutorialList)
|
||||
|
||||
6
Content.Client/Info/RulesControl.xaml
Normal file
6
Content.Client/Info/RulesControl.xaml
Normal file
@@ -0,0 +1,6 @@
|
||||
<BoxContainer xmlns="https://spacestation14.io"
|
||||
Name="InfoContainer"
|
||||
Orientation="Vertical"
|
||||
Margin="2 2 0 0"
|
||||
SeparationOverride="10"
|
||||
Access="Public"/>
|
||||
23
Content.Client/Info/RulesControl.xaml.cs
Normal file
23
Content.Client/Info/RulesControl.xaml.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
namespace Content.Client.Info;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class RulesControl : BoxContainer
|
||||
{
|
||||
[Dependency] private readonly IResourceCache _resourceManager = default!;
|
||||
|
||||
public RulesControl()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
AddChild(new InfoSection(Loc.GetString("ui-rules-header"),
|
||||
_resourceManager.ContentFileReadAllText($"/Server Info/Rules.txt"), true));
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Content.Client.Lobby;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.State;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -16,9 +17,9 @@ public sealed class RulesManager
|
||||
{
|
||||
[Dependency] private readonly IResourceManager _resource = default!;
|
||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
||||
[Dependency] private readonly IStateManager _stateManager = default!;
|
||||
|
||||
public event Action? OpenRulesAndInfoWindow;
|
||||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -39,8 +40,10 @@ public sealed class RulesManager
|
||||
else
|
||||
SaveLastReadTime();
|
||||
|
||||
if (showRules)
|
||||
OpenRulesAndInfoWindow?.Invoke();
|
||||
if (!showRules)
|
||||
return;
|
||||
|
||||
ShowRules(_configManager.GetCVar(CCVars.RulesWaitTime));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,4 +55,25 @@ public sealed class RulesManager
|
||||
|
||||
sw.Write(DateTime.UtcNow.ToUniversalTime());
|
||||
}
|
||||
|
||||
private void ShowRules(float time)
|
||||
{
|
||||
var rulesPopup = new RulesPopup
|
||||
{
|
||||
Timer = time
|
||||
};
|
||||
rulesPopup.OnQuitPressed += OnQuitPressed;
|
||||
rulesPopup.OnAcceptPressed += OnAcceptPressed;
|
||||
_userInterfaceManager.RootControl.AddChild(rulesPopup);
|
||||
}
|
||||
|
||||
private void OnQuitPressed()
|
||||
{
|
||||
_consoleHost.ExecuteCommand("quit");
|
||||
}
|
||||
|
||||
private void OnAcceptPressed()
|
||||
{
|
||||
SaveLastReadTime();
|
||||
}
|
||||
}
|
||||
|
||||
24
Content.Client/Info/RulesPopup.xaml
Normal file
24
Content.Client/Info/RulesPopup.xaml
Normal file
@@ -0,0 +1,24 @@
|
||||
<Control xmlns="https://spacestation14.io"
|
||||
xmlns:parallax="clr-namespace:Content.Client.Parallax"
|
||||
xmlns:info="clr-namespace:Content.Client.Info"
|
||||
VerticalExpand="True" HorizontalExpand="True"
|
||||
MouseFilter="Stop">
|
||||
<parallax:ParallaxControl />
|
||||
<Control VerticalExpand="True"
|
||||
MaxWidth="650">
|
||||
<PanelContainer StyleClasses="windowPanel" />
|
||||
<ScrollContainer HScrollEnabled="False">
|
||||
<BoxContainer Orientation="Vertical" SeparationOverride="10">
|
||||
<info:RulesControl />
|
||||
<Label Name="WaitLabel" />
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Button Name="AcceptButton"
|
||||
Text="{Loc 'ui-rules-accept'}"
|
||||
Disabled="True" />
|
||||
<Button Name="QuitButton"
|
||||
Text="{Loc 'ui-escape-quit'}" />
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
</Control>
|
||||
</Control>
|
||||
69
Content.Client/Info/RulesPopup.xaml.cs
Normal file
69
Content.Client/Info/RulesPopup.xaml.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.Info;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class RulesPopup : Control
|
||||
{
|
||||
private float _timer;
|
||||
|
||||
public float Timer
|
||||
{
|
||||
get => _timer;
|
||||
set
|
||||
{
|
||||
WaitLabel.Text = Loc.GetString("ui-rules-wait", ("time", MathF.Floor(value)));
|
||||
_timer = value;
|
||||
}
|
||||
}
|
||||
|
||||
public event Action? OnQuitPressed;
|
||||
public event Action? OnAcceptPressed;
|
||||
|
||||
public RulesPopup()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
AcceptButton.OnPressed += OnAcceptButtonPressed;
|
||||
QuitButton.OnPressed += OnQuitButtonPressed;
|
||||
}
|
||||
|
||||
private void OnQuitButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
OnQuitPressed?.Invoke();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
private void OnAcceptButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
Parent?.RemoveChild(this);
|
||||
OnAcceptPressed?.Invoke();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
if (!AcceptButton.Disabled)
|
||||
return;
|
||||
|
||||
if (Timer > 0.0)
|
||||
{
|
||||
if (Timer - args.DeltaSeconds < 0)
|
||||
Timer = 0;
|
||||
else
|
||||
Timer -= args.DeltaSeconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
AcceptButton.Disabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -603,5 +603,15 @@ namespace Content.Shared.CCVar
|
||||
/// </summary>
|
||||
public static readonly CVarDef<string>
|
||||
SalvageForced = CVarDef.Create("salvage.forced", "", CVar.SERVERONLY);
|
||||
|
||||
/*
|
||||
* Rules
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Time that players have to wait before rules can be accepted.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<float> RulesWaitTime =
|
||||
CVarDef.Create("rules.time", 45f, CVar.SERVER | CVar.REPLICATED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,6 @@ ui-info-title = Information
|
||||
ui-info-tab-rules = Server Rules
|
||||
ui-info-tab-tutorial = Tutorial
|
||||
|
||||
## Rules tab
|
||||
|
||||
ui-info-header-rules = SS14 Official Server Rules
|
||||
|
||||
## Tutorial tab
|
||||
ui-info-text-controls = You can review and rebind SS14s controls in the
|
||||
|
||||
|
||||
5
Resources/Locale/en-US/info/rules.ftl
Normal file
5
Resources/Locale/en-US/info/rules.ftl
Normal file
@@ -0,0 +1,5 @@
|
||||
# Rules
|
||||
|
||||
ui-rules-header = SS14 Official Server Rules
|
||||
ui-rules-accept = I have read and agree to follow the rules
|
||||
ui-rules-wait = The accept button will be enabled after {$time} seconds.
|
||||
Reference in New Issue
Block a user