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);
}
}
}
}
}