Make ghost timer a cvar (#8817)

Co-authored-by: Just-a-Unity-Dev <rnmangunay@addu.edu.ph>
Co-authored-by: Just-a-Unity-Dev <just-a-unity-dev@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
eclips_e
2022-06-16 17:56:09 +08:00
committed by GitHub
parent c757841150
commit df9f9aee53
3 changed files with 31 additions and 6 deletions

View File

@@ -1,26 +1,38 @@
using System;
using Content.Shared.Ghost.Roles;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Content.Shared.CCVar;
using Robust.Shared.Configuration;
namespace Content.Client.Ghost.Roles.UI namespace Content.Client.Ghost.Roles.UI
{ {
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class GhostRoleRulesWindow : DefaultWindow public sealed partial class GhostRoleRulesWindow : DefaultWindow
{ {
private float _timer = 5.0f; [Dependency] private readonly IConfigurationManager _cfg = IoCManager.Resolve<IConfigurationManager>();
private float _timer;
public GhostRoleRulesWindow(string rules, Action<BaseButton.ButtonEventArgs> requestAction) public GhostRoleRulesWindow(string rules, Action<BaseButton.ButtonEventArgs> requestAction)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
TopBanner.SetMessage(FormattedMessage.FromMarkupPermissive(rules + "\n" + Loc.GetString("ghost-roles-window-rules-footer"))); var ghostRoleTime = _cfg.GetCVar(CCVars.GhostRoleTime);
_timer = ghostRoleTime;
if (ghostRoleTime > 0f)
{
RequestButton.Text = Loc.GetString("ghost-roles-window-request-role-button-timer", ("time", $"{_timer:0.0}"));
TopBanner.SetMessage(FormattedMessage.FromMarkupPermissive(rules + "\n" + Loc.GetString("ghost-roles-window-rules-footer", ("time", ghostRoleTime))));
RequestButton.Disabled = true;
}
RequestButton.OnPressed += requestAction; RequestButton.OnPressed += requestAction;
} }
protected override void FrameUpdate(FrameEventArgs args) protected override void FrameUpdate(FrameEventArgs args)
{ {
base.FrameUpdate(args); base.FrameUpdate(args);
@@ -28,10 +40,12 @@ namespace Content.Client.Ghost.Roles.UI
if (_timer > 0.0) if (_timer > 0.0)
{ {
_timer -= args.DeltaSeconds; _timer -= args.DeltaSeconds;
RequestButton.Text = Loc.GetString("ghost-roles-window-request-role-button-timer", ("time", $"{_timer:0.0}"));
} }
else else
{ {
RequestButton.Disabled = false; RequestButton.Disabled = false;
RequestButton.Text = Loc.GetString("ghost-roles-window-request-role-button");
} }
} }
} }

View File

@@ -991,5 +991,15 @@ namespace Content.Shared.CCVar
/// </summary> /// </summary>
public static readonly CVarDef<float> UpdateRestartDelay = public static readonly CVarDef<float> UpdateRestartDelay =
CVarDef.Create("update.restart_delay", 20f, CVar.SERVERONLY); CVarDef.Create("update.restart_delay", 20f, CVar.SERVERONLY);
/*
* Ghost
*/
/// <summary>
/// The time you must spend reading the rules, before the "Request" button is enabled
/// </summary>
public static readonly CVarDef<float> GhostRoleTime =
CVarDef.Create("ghost.role_time", 3f, CVar.REPLICATED);
} }
} }

View File

@@ -7,7 +7,8 @@ ghost-target-window-current-button = Warp: {$name}
ghost-roles-window-title = Ghost Roles ghost-roles-window-title = Ghost Roles
ghost-roles-window-request-role-button = Request ghost-roles-window-request-role-button = Request
ghost-roles-window-request-role-button-timer = Request ({$time}s)
ghost-roles-window-follow-role-button = Follow ghost-roles-window-follow-role-button = Follow
ghost-roles-window-no-roles-available-label = There are currently no available ghost roles. ghost-roles-window-no-roles-available-label = There are currently no available ghost roles.
ghost-roles-window-rules-footer = The button will enable after 5 seconds (this delay is to make sure you read the rules). ghost-roles-window-rules-footer = The button will enable after {$time} seconds (this delay is to make sure you read the rules).