Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback popup command #2663

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Content.Server/_DV/FeedbackPopup/FeedbackPopupCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Linq;
using Content.Server.Administration;
using Content.Shared._DV.FeedbackOverwatch;
using Content.Shared.Administration;
using Robust.Shared.Console;
using Robust.Shared.Prototypes;

namespace Content.Server._DV.FeedbackPopup;

[AdminCommand(AdminFlags.Server)]
public sealed class FeedbackPopupCommand : LocalizedEntityCommands
{
[Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedFeedbackOverwatchSystem _feedback = default!;

public override string Command => Loc.GetString("feedbackpopup-command-name");

public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 2)
{
shell.WriteError(Loc.GetString("feedbackpopup-command-error-wrong-arguments"));
return;
}

if (!int.TryParse(args[0], out var entityUidInt))
{
shell.WriteError(Loc.GetString("feedbackpopup-command-error-invalid-uid"));
return;
}

var netEnt = new NetEntity(entityUidInt);

if (!EntityManager.TryGetEntity(netEnt, out var target))
{
shell.WriteLine(Loc.GetString("feedbackpopup-command-error-entity-not-found"));
return;
}

if (!_proto.HasIndex<FeedbackPopupPrototype>(args[1]))
{
shell.WriteError(Loc.GetString("feedbackpopup-command-error-invalid-proto"));
return;
}

if (!_feedback.SendPopup(target, args[1]))
{
shell.WriteError(Loc.GetString("feedbackpopup-command-error-popup-send-fail"));
return;
}

shell.WriteLine(Loc.GetString("feedbackpopup-command-success"));
}

public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
{
if (args.Length == 1)
{
return CompletionResult.FromHint(Loc.GetString("feedbackpopup-command-hint-playerUid"));
}

if (args.Length == 2)
{
return CompletionResult.FromHintOptions(_feedback.FeedbackPopupProtoIds, Loc.GetString("feedbackpopup-command-hint-protoId"));
}
return CompletionResult.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,71 @@ namespace Content.Shared._DV.FeedbackOverwatch;
public sealed partial class SharedFeedbackOverwatchSystem : EntitySystem
{
[Dependency] private readonly SharedMindSystem _mind = default!;
[Dependency] private readonly IPrototypeManager _proto = default!;

public List<string> FeedbackPopupProtoIds { get; } = new();

public override void Initialize()
{
InitializeEvents();
SubscribeLocalEvent<PrototypesReloadedEventArgs>(OnPrototypesReloaded);

LoadPrototypes();
}

private void OnPrototypesReloaded(PrototypesReloadedEventArgs args)
{
if (!args.WasModified<FeedbackPopupPrototype>())
return;

LoadPrototypes();
}

/// <summary>
/// Load all the prototype IDs into FeedbackPopupProtoIds.
/// </summary>
private void LoadPrototypes()
{
FeedbackPopupProtoIds.Clear();
var protos = _proto.EnumeratePrototypes<FeedbackPopupPrototype>();
foreach (var proto in protos)
FeedbackPopupProtoIds.Add(proto.ID);
FeedbackPopupProtoIds.Sort();
}

/// <summary>
/// Send a popup to the given client controlling the given UID.
/// </summary>
/// <param name="uid">UID of the entity the player is controlling.</param>
/// <param name="popupPrototype">Popup to send them.</param>
public void SendPopup(EntityUid? uid, ProtoId<FeedbackPopupPrototype> popupPrototype)
/// <returns>Returns true if the popup message was sent to the client successfully.</returns>
public bool SendPopup(EntityUid? uid, ProtoId<FeedbackPopupPrototype> popupPrototype)
{
if (uid == null)
return;
return false;

if (!_mind.TryGetMind(uid.Value, out var mindUid, out _))
return;
return false;

SendPopupMind(mindUid, popupPrototype);
return SendPopupMind(mindUid, popupPrototype);
}

/// <summary>
/// Send a popup to the given client controlling the given mind.
/// </summary>
/// <param name="uid">UID of the players mind.</param>
/// <param name="popupPrototype">Popup to send them.</param>
public void SendPopupMind(EntityUid? uid, ProtoId<FeedbackPopupPrototype> popupPrototype)
/// <returns>Returns true if the popup message was sent to the client successfully.</returns>
public bool SendPopupMind(EntityUid? uid, ProtoId<FeedbackPopupPrototype> popupPrototype)
{
if (uid == null)
return;
return false;

if (!_mind.TryGetSession(uid, out var session))
return;
return false;

var msg = new FeedbackPopupMessage(popupPrototype);
RaiseNetworkEvent(msg, session);
return true;
}
}
15 changes: 15 additions & 0 deletions Resources/Locale/en-US/_DV/feedbackpopup/feedbackpopup.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,18 @@ feedbackpopup-discord-format-header = ```[Round number: {$roundNumber}, Player n
feedbackpopup-discord-format-info = Feedback name: **{$feedbackName}**
feedbackpopup-discord-format-spacer = ---- Feedback start ----
feedbackpopup-discord-format-feedbackbody = {$feedback}

# Command strings
feedbackpopup-command-name = givefeedbackpopup
cmd-givefeedbackpopup-desc = Gives the targeted player a feedback popup.
cmd-givefeedbackpopup-help = Usage: givefeedbackpopup <playerUid> <prototypeId>

feedbackpopup-command-error-wrong-arguments = Wrong number of arguments.
feedbackpopup-command-error-invalid-uid = Invalid entity uid.
feedbackpopup-command-error-entity-not-found = Couldn't find entity.
feedbackpopup-command-error-invalid-proto = Invalid feedback popup prototype.
feedbackpopup-command-error-popup-send-fail = Couldn't send popup. There probably isn't a mind attached to the given entity.
feedbackpopup-command-success = Sent popup!

feedbackpopup-command-hint-playerUid = <playerUid>
feedbackpopup-command-hint-protoId = <prototypeId>
Loading