Improve on disposal routing code (#1795)

Co-authored-by: Julian Giebel <j.giebel@netrocks.info>
This commit is contained in:
Julian Giebel
2020-08-19 20:43:56 +02:00
committed by GitHub
parent 20ab566f8c
commit 7771f58460
8 changed files with 23 additions and 31 deletions

View File

@@ -23,15 +23,13 @@ namespace Content.Client.GameObjects.Components.Disposal
{
base.Open();
_window = new DisposalRouterWindow
{
Title = Loc.GetString("Disposal Router"),
};
_window = new DisposalRouterWindow();
_window.OpenCentered();
_window.OnClose += Close;
_window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text);
_window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text);
}

View File

@@ -1,7 +1,4 @@
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Content.Shared.GameObjects.Components.Disposal;
using Robust.Client.Graphics.Drawing;
using Content.Shared.GameObjects.Components.Disposal;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
@@ -21,11 +18,9 @@ namespace Content.Client.GameObjects.Components.Disposal
protected override Vector2? CustomSize => (400, 80);
private Regex _tagRegex;
public DisposalRouterWindow()
{
_tagRegex = new Regex("^[a-zA-Z0-9, ]*$", RegexOptions.Compiled);
Title = Loc.GetString("Disposal Router");
Contents.AddChild(new VBoxContainer
{
@@ -38,7 +33,7 @@ namespace Content.Client.GameObjects.Components.Disposal
Children =
{
(TagInput = new LineEdit {SizeFlagsHorizontal = SizeFlags.Expand, CustomMinimumSize = (320, 0),
ToolTip = Loc.GetString("A comma separated list of tags"), IsValid = tags => _tagRegex.IsMatch(tags)}),
ToolTip = Loc.GetString("A comma separated list of tags"), IsValid = tags => TagRegex.IsMatch(tags)}),
new Control {CustomMinimumSize = (10, 0)},
(Confirm = new Button {Text = Loc.GetString("Confirm")})
}

View File

@@ -23,15 +23,13 @@ namespace Content.Client.GameObjects.Components.Disposal
{
base.Open();
_window = new DisposalTaggerWindow
{
Title = Loc.GetString("Disposal Tagger"),
};
_window = new DisposalTaggerWindow();
_window.OpenCentered();
_window.OnClose += Close;
_window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text);
_window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text);
}

View File

@@ -1,7 +1,4 @@
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Content.Shared.GameObjects.Components.Disposal;
using Robust.Client.Graphics.Drawing;
using Content.Shared.GameObjects.Components.Disposal;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
@@ -21,11 +18,9 @@ namespace Content.Client.GameObjects.Components.Disposal
protected override Vector2? CustomSize => (400, 80);
private Regex _tagRegex;
public DisposalTaggerWindow()
{
_tagRegex = new Regex("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled);
Title = Loc.GetString("Disposal Tagger");
Contents.AddChild(new VBoxContainer
{
@@ -38,7 +33,7 @@ namespace Content.Client.GameObjects.Components.Disposal
Children =
{
(TagInput = new LineEdit {SizeFlagsHorizontal = SizeFlags.Expand, CustomMinimumSize = (320, 0),
IsValid = tag => _tagRegex.IsMatch(tag)}),
IsValid = tag => TagRegex.IsMatch(tag)}),
new Control {CustomMinimumSize = (10, 0)},
(Confirm = new Button {Text = Loc.GetString("Confirm")})
}

View File

@@ -78,17 +78,17 @@ namespace Content.Server.GameObjects.Components.Disposal
if (!PlayerCanUseDisposalTagger(obj.Session.AttachedEntity))
return;
if (msg.Action == UiAction.Ok)
//Check for correct message and ignore maleformed strings
if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tags))
{
_tags.Clear();
foreach (var tag in msg.Tags.Split(',', StringSplitOptions.RemoveEmptyEntries))
{
_tags.Add(tag.Trim());
}
}
ClickSound();
}
}
}
/// <summary>
/// Checks whether the player entity is able to use the configuration interface of the pipe tagger.

View File

@@ -68,13 +68,13 @@ namespace Content.Server.GameObjects.Components.Disposal
if (!PlayerCanUseDisposalTagger(obj.Session.AttachedEntity))
return;
if (msg.Action == UiAction.Ok)
//Check for correct message and ignore maleformed strings
if (msg.Action == UiAction.Ok && TagRegex.IsMatch(msg.Tag))
{
_tag = msg.Tag;
}
ClickSound();
}
}
/// <summary>
/// Checks whether the player entity is able to use the configuration interface of the pipe tagger.

View File

@@ -2,6 +2,7 @@
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Serialization;
using System;
using System.Text.RegularExpressions;
namespace Content.Shared.GameObjects.Components.Disposal
{
@@ -9,6 +10,8 @@ namespace Content.Shared.GameObjects.Components.Disposal
{
public override string Name => "DisposalRouter";
public static readonly Regex TagRegex = new Regex("^[a-zA-Z0-9, ]*$", RegexOptions.Compiled);
[Serializable, NetSerializable]
public class DisposalRouterUserInterfaceState : BoundUserInterfaceState
{

View File

@@ -3,6 +3,7 @@ using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.UserInterface;
using Robust.Shared.Serialization;
using System;
using System.Text.RegularExpressions;
namespace Content.Shared.GameObjects.Components.Disposal
{
@@ -10,6 +11,8 @@ namespace Content.Shared.GameObjects.Components.Disposal
{
public override string Name => "DisposalTagger";
public static readonly Regex TagRegex = new Regex("^[a-zA-Z0-9 ]*$", RegexOptions.Compiled);
[Serializable, NetSerializable]
public class DisposalTaggerUserInterfaceState : BoundUserInterfaceState
{
@@ -33,7 +36,7 @@ namespace Content.Shared.GameObjects.Components.Disposal
if (Action == UiAction.Ok)
{
Tag = tag;
Tag = tag.Substring(0, Math.Min(tag.Length, 30));
}
}
}