Configuration verb (#2465)

* Implement configuration verbs

* Fix nullable errors
Change getting session from actor to user.PlayerSession()
Fix not having an interaction range

Co-authored-by: Julian Giebel <j.giebel@netrocks.info>
Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
Julian Giebel
2020-11-27 08:45:16 +01:00
committed by GitHub
parent 4a2875dca6
commit 4a56df749b
5 changed files with 137 additions and 17 deletions

View File

@@ -1,11 +1,20 @@
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.Utility;
using Content.Shared.GameObjects.Components;
using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.Console;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System.Collections.Generic;
@@ -77,9 +86,7 @@ namespace Content.Server.GameObjects.Components
if (!await tool.UseTool(eventArgs.User, Owner, 0.2f, ToolQuality.Multitool))
return false;
UpdateUserInterface();
UserInterface.Open(actor.playerSession);
UserInterface.SendMessage(new ValidationUpdateMessage(_validation.ToString()), actor.playerSession);
OpenUserInterface(actor);
return true;
}
@@ -109,11 +116,44 @@ namespace Content.Server.GameObjects.Components
UserInterface?.SetState(new ConfigurationBoundUserInterfaceState(_config));
}
private void OpenUserInterface(IActorComponent actor)
{
UpdateUserInterface();
UserInterface.Open(actor.playerSession);
UserInterface.SendMessage(new ValidationUpdateMessage(_validation.ToString()), actor.playerSession);
}
private static void FillConfiguration<T>(List<string> list, Dictionary<string, T> configuration, T value){
for (var index = 0; index < list.Count; index++)
{
configuration.Add(list[index], value);
}
}
[Verb]
public sealed class ConfigureVerb : Verb<ConfigurationComponent>
{
protected override void GetData(IEntity user, ConfigurationComponent component, VerbData data)
{
var session = user.PlayerSession();
var groupController = IoCManager.Resolve<IConGroupController>();
if (session == null || !groupController.CanAdminMenu(session))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Open Configuration");
data.IconTexture = "/Textures/Interface/VerbIcons/settings.svg.96dpi.png";
}
protected override void Activate(IEntity user, ConfigurationComponent component)
{
if (user.TryGetComponent(out IActorComponent actor))
{
component.OpenUserInterface(actor);
}
}
}
}
}

View File

@@ -2,19 +2,25 @@
using System;
using System.Collections.Generic;
using System.Text;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Server.Utility;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.Console;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
@@ -77,7 +83,7 @@ namespace Content.Server.GameObjects.Components.Disposal
var msg = (UiActionMessage) obj.Message;
if (!PlayerCanUseDisposalTagger(obj.Session.AttachedEntity))
if (!PlayerCanUseDisposalTagger(obj.Session))
return;
//Check for correct message and ignore maleformed strings
@@ -95,22 +101,25 @@ namespace Content.Server.GameObjects.Components.Disposal
/// <summary>
/// Checks whether the player entity is able to use the configuration interface of the pipe tagger.
/// </summary>
/// <param name="playerEntity">The player entity.</param>
/// <param name="IPlayerSession">The player session.</param>
/// <returns>Returns true if the entity can use the configuration interface, and false if it cannot.</returns>
private bool PlayerCanUseDisposalTagger(IEntity playerEntity)
private bool PlayerCanUseDisposalTagger(IPlayerSession session)
{
//Need player entity to check if they are still able to use the configuration interface
if (playerEntity == null)
if (session.AttachedEntity == null)
return false;
if (!Anchored)
return false;
var groupController = IoCManager.Resolve<IConGroupController>();
//Check if player can interact in their current state
if (!ActionBlockerSystem.CanInteract(playerEntity) || !ActionBlockerSystem.CanUse(playerEntity))
if (!groupController.CanAdminMenu(session) && (!ActionBlockerSystem.CanInteract(session.AttachedEntity) || !ActionBlockerSystem.CanUse(session.AttachedEntity)))
return false;
return true;
}
/// <summary>
/// Gets component data to be used to update the user interface client-side.
/// </summary>
@@ -166,8 +175,7 @@ namespace Content.Server.GameObjects.Components.Disposal
var activeHandEntity = hands.GetActiveHand?.Owner;
if (activeHandEntity == null)
{
UpdateUserInterface();
UserInterface?.Open(actor.playerSession);
OpenUserInterface(actor);
}
}
@@ -176,5 +184,37 @@ namespace Content.Server.GameObjects.Components.Disposal
UserInterface?.CloseAll();
base.OnRemove();
}
private void OpenUserInterface(IActorComponent actor)
{
UpdateUserInterface();
UserInterface?.Open(actor.playerSession);
}
[Verb]
public sealed class ConfigureVerb : Verb<DisposalRouterComponent>
{
protected override void GetData(IEntity user, DisposalRouterComponent component, VerbData data)
{
var session = user.PlayerSession();
var groupController = IoCManager.Resolve<IConGroupController>();
if (session == null || !groupController.CanAdminMenu(session))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Open Configuration");
data.IconTexture = "/Textures/Interface/VerbIcons/settings.svg.96dpi.png";
}
protected override void Activate(IEntity user, DisposalRouterComponent component)
{
if (user.TryGetComponent(out IActorComponent? actor))
{
component.OpenUserInterface(actor);
}
}
}
}
}

View File

@@ -1,20 +1,26 @@
#nullable enable
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.Interfaces.GameObjects.Components.Items;
using Content.Server.Utility;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Server.Console;
using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.ViewVariables;
using System;
using static Content.Shared.GameObjects.Components.Disposal.SharedDisposalTaggerComponent;
namespace Content.Server.GameObjects.Components.Disposal
@@ -63,7 +69,7 @@ namespace Content.Server.GameObjects.Components.Disposal
{
var msg = (UiActionMessage) obj.Message;
if (!PlayerCanUseDisposalTagger(obj.Session.AttachedEntity))
if (!PlayerCanUseDisposalTagger(obj.Session))
return;
//Check for correct message and ignore maleformed strings
@@ -77,17 +83,19 @@ namespace Content.Server.GameObjects.Components.Disposal
/// <summary>
/// Checks whether the player entity is able to use the configuration interface of the pipe tagger.
/// </summary>
/// <param name="playerEntity">The player entity.</param>
/// <param name="IPlayerSession">The player entity.</param>
/// <returns>Returns true if the entity can use the configuration interface, and false if it cannot.</returns>
private bool PlayerCanUseDisposalTagger(IEntity? playerEntity)
private bool PlayerCanUseDisposalTagger(IPlayerSession session)
{
//Need player entity to check if they are still able to use the configuration interface
if (playerEntity == null)
if (session.AttachedEntity == null)
return false;
if (!Anchored)
return false;
var groupController = IoCManager.Resolve<IConGroupController>();
//Check if player can interact in their current state
if (!ActionBlockerSystem.CanInteract(playerEntity) || !ActionBlockerSystem.CanUse(playerEntity))
if (!groupController.CanAdminMenu(session) && (!ActionBlockerSystem.CanInteract(session.AttachedEntity) || !ActionBlockerSystem.CanUse(session.AttachedEntity)))
return false;
return true;
@@ -133,8 +141,7 @@ namespace Content.Server.GameObjects.Components.Disposal
var activeHandEntity = hands.GetActiveHand?.Owner;
if (activeHandEntity == null)
{
UpdateUserInterface();
UserInterface?.Open(actor.playerSession);
OpenUserInterface(actor);
}
}
@@ -143,5 +150,37 @@ namespace Content.Server.GameObjects.Components.Disposal
base.OnRemove();
UserInterface?.CloseAll();
}
[Verb]
public sealed class ConfigureVerb : Verb<DisposalTaggerComponent>
{
protected override void GetData(IEntity user, DisposalTaggerComponent component, VerbData data)
{
var groupController = IoCManager.Resolve<IConGroupController>();
if (!user.TryGetComponent(out IActorComponent? actor) || !groupController.CanAdminMenu(actor.playerSession))
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = Loc.GetString("Open Configuration");
data.IconTexture = "/Textures/Interface/VerbIcons/settings.svg.96dpi.png";
}
protected override void Activate(IEntity user, DisposalTaggerComponent component)
{
if (user.TryGetComponent(out IActorComponent? actor))
{
component.OpenUserInterface(actor);
}
}
}
private void OpenUserInterface(IActorComponent actor)
{
UpdateUserInterface();
UserInterface?.Open(actor.playerSession);
}
}
}

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-settings"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>

After

Width:  |  Height:  |  Size: 1004 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B