Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
beck-thompson committed Dec 29, 2024
1 parent 0fa9e0a commit cad37bb
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Content.Client/DeltaV/FeedbackPopup/FeedbackPopupSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Shared.DeltaV.FeedbackOverwatch;
using Robust.Shared.Configuration;

namespace Content.Client.DeltaV.FeedbackPopup;

/// <summary>
/// This handles getting feedback popup messages from the server and making a popup in the client.
/// Currently, this system can only support one window at a time.
/// </summary>
public sealed class FeedbackPopupSystem : EntitySystem
{
private FeedbackPopupWindow? _window;

public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<FeedbackPopupMessage>(OnFeedbackPopup);
}

private void OnFeedbackPopup(FeedbackPopupMessage msg)
{
// If a window is already open, close it
_window?.Close();

_window = new FeedbackPopupWindow(msg.FeedbackPrototype);
_window.OpenCentered();
_window.OnClose += () => _window = null;
}
}
11 changes: 11 additions & 0 deletions Content.Client/DeltaV/FeedbackPopup/FeedbackPopupWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'feedbackpopup-window-name'}"
MinSize="300 250"
SetSize="600 250">
<BoxContainer Orientation="Vertical" Margin="10 0 10 0">
<RichTextLabel HorizontalAlignment="Center" Name="TitleLabel" Margin="0 0 0 20"></RichTextLabel>
<BoxContainer Name="SectionContainer" Orientation="Vertical"></BoxContainer>
<BoxContainer Name="FeedbackLocationContainer" Orientation="Vertical" Margin="0 10 0 0"></BoxContainer>
</BoxContainer>
</controls:FancyWindow>
78 changes: 78 additions & 0 deletions Content.Client/DeltaV/FeedbackPopup/FeedbackPopupWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.DeltaV.FeedbackOverwatch;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;

namespace Content.Client.DeltaV.FeedbackPopup;

[GenerateTypedNameReferences]
public sealed partial class FeedbackPopupWindow : FancyWindow
{
[Dependency] private readonly IPrototypeManager _proto = default!;
private readonly IUriOpener _uri;

private readonly FeedbackPopupPrototype _feedbackpopup;
public FeedbackPopupWindow(ProtoId<FeedbackPopupPrototype> popupProto)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_uri = IoCManager.Resolve<IUriOpener>();

_feedbackpopup = _proto.Index(popupProto);
PopulateWindow();
}

private void PopulateWindow()
{
// Title
TitleLabel.Text = _feedbackpopup.Title;

// Description
foreach (var section in _feedbackpopup.Description)
CreateSection(section);

// Feedback location
if (_feedbackpopup.FeedbackLocation != null)
{
var label = new RichTextLabel
{
Text = _feedbackpopup.FeedbackLocation,
Margin = new Thickness(0,0,0,10),
HorizontalAlignment = HAlignment.Center,
};

FeedbackLocationContainer.AddChild(label);
}

// Discord link button
if (_feedbackpopup.DiscordLink != null && _feedbackpopup.DiscordLink.StartsWith("https://discord.com/"))
{
var button = new Button
{
Text = Loc.GetString("feedbackpopup-discord-button-name"),
};
button.OnPressed += OnButtonPressed;
FeedbackLocationContainer.AddChild(button);
}
}

private void CreateSection(string text)
{
var label = new RichTextLabel
{
Text = text,
Margin = new Thickness(0,0,0,10),
};
SectionContainer.AddChild(label);
}

private void OnButtonPressed(BaseButton.ButtonEventArgs args)
{
if (_feedbackpopup.DiscordLink != null)
_uri.OpenUri(_feedbackpopup.DiscordLink);
}
}

18 changes: 18 additions & 0 deletions Content.Shared/DeltaV/FeedbackOverwatch/FeedbackOverwatchEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;

namespace Content.Shared.DeltaV.FeedbackOverwatch;

/// <summary>
/// When clients recieve this message a popup will appear on their screen with the contents from the given prototype.
/// </summary>
[Serializable, NetSerializable]
public sealed class FeedbackPopupMessage : EntityEventArgs
{
public ProtoId<FeedbackPopupPrototype> FeedbackPrototype;

public FeedbackPopupMessage(ProtoId<FeedbackPopupPrototype> feedbackPrototype)
{
FeedbackPrototype = feedbackPrototype;
}
};
42 changes: 42 additions & 0 deletions Content.Shared/DeltaV/FeedbackOverwatch/FeedbackPopupPrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Robust.Shared.Prototypes;

namespace Content.Shared.DeltaV.FeedbackOverwatch;

/// <summary>
/// Prototype that describes the contents of a feedback popup.
/// </summary>
[Prototype]
public sealed partial class FeedbackPopupPrototype : IPrototype
{
/// <inheritdoc/>
[IdDataField]
public string ID { get; } = default!;

/// <summary>
/// Title of the popup. This supports rich text so you can use colors and stuff.
/// </summary>
[DataField(required: true)]
public string Title = "";

/// <summary>
/// List of "paragraphs" that are placed in the middle of the popup. Put the any relavent information about
/// what to give feedback on here!
/// </summary>
[DataField(required: true)]
public List<string> Description = new();

/// <summary>
/// Describe where you want to put the feedback here.
/// </summary>
[DataField]
public string? FeedbackLocation;

/// <summary>
/// Link to the discord channel that will be linked when the button is clicked.
/// </summary>
/// <remarks>
/// Must start with "https://discord.com/".
/// </remarks>
[DataField]
public string? DiscordLink;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Content.Shared.DeltaV.FeedbackOverwatch;

public sealed partial class SharedFeedbackOverwatchSystem
{
public override void Initialize()
{
// Subscribe to events that would be good for popups here.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Content.Shared.Mind;
using Robust.Shared.Prototypes;

namespace Content.Shared.DeltaV.FeedbackOverwatch;

public sealed partial class SharedFeedbackOverwatchSystem : EntitySystem
{
[Dependency] private readonly SharedMindSystem _mind = default!;

/// <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)
{
if (uid == null)
return;

if (!_mind.TryGetMind(uid.Value, out var mindUid, out _))
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)
{
if (uid == null)
return;

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

var msg = new FeedbackPopupMessage(popupPrototype);
RaiseNetworkEvent(msg, session);
}
}
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/deltav/feedbackpopup/feedbackpopup.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feedbackpopup-window-name = Feedback popup
feedbackpopup-discord-button-name = Click here to go to discord channel
11 changes: 11 additions & 0 deletions Resources/Prototypes/DeltaV/FeedbackPopup/feedbackpopups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Example
- type: feedbackPopup
id: ExampleFeedbackPopup
title: "[color=red]FEEDBACK[/color] on new popup system."
description:
- "This is a new system to get feedback on features. It will give popups!"
- "It also supports multiple sections if it looks better."
feedbackLocation: "Please go to the [color=red]#general[/color] channel to give your feedback!"
discordLink: "https://discord.com/channels/968983104247185448/968983104662409244"

# Popups

0 comments on commit cad37bb

Please sign in to comment.