Revert "Added button and manager for in game bug reports (Part 1)" (#39872)

Revert "Added button and manager for in game bug reports (Part 1) (#35350)"

This reverts commit a8d6dbc324.
This commit is contained in:
Fildrance
2025-08-28 11:46:24 +03:00
committed by GitHub
parent 420fb5cebf
commit 60ea135fd3
37 changed files with 3 additions and 1831 deletions

View File

@@ -1,113 +0,0 @@
using Content.Client.Gameplay;
using Content.Client.Resources;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.BugReport.Windows;
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.Shared.BugReport;
using Content.Shared.CCVar;
using JetBrains.Annotations;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Configuration;
using Robust.Shared.Network;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.BugReport;
[UsedImplicitly]
public sealed class BugReportUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>
{
[Dependency] private readonly IClientNetManager _net = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IResourceCache _resource = default!;
// This is the link to the hotbar button
private MenuButton? BugReportButton => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>()?.ReportBugButton;
// Don't clear this window. It needs to be saved so the input doesn't get erased when it's closed!
private BugReportWindow _bugReportWindow = default!;
private ResPath Bug = new("/Textures/Interface/bug.svg.192dpi.png");
private ResPath Splat = new("/Textures/Interface/splat.svg.192dpi.png");
public void OnStateEntered(GameplayState state)
{
SetupWindow();
}
public void OnStateExited(GameplayState state)
{
CleanupWindow();
}
public void LoadButton()
{
if (BugReportButton != null)
BugReportButton.OnPressed += ButtonToggleWindow;
}
public void UnloadButton()
{
if (BugReportButton != null)
BugReportButton.OnPressed -= ButtonToggleWindow;
}
private void SetupWindow()
{
if (BugReportButton == null)
return;
_bugReportWindow = UIManager.CreateWindow<BugReportWindow>();
// This is to make sure the hotbar button gets checked and unchecked when the window is opened / closed.
_bugReportWindow.OnClose += () =>
{
BugReportButton.Pressed = false;
BugReportButton.Icon = _resource.GetTexture(Bug);
};
_bugReportWindow.OnOpen += () =>
{
BugReportButton.Pressed = true;
BugReportButton.Icon = _resource.GetTexture(Splat);
};
_bugReportWindow.OnBugReportSubmitted += OnBugReportSubmitted;
_cfg.OnValueChanged(CCVars.EnablePlayerBugReports, UpdateButtonVisibility, true);
}
private void CleanupWindow()
{
_bugReportWindow.CleanupCCvars();
_cfg.UnsubValueChanged(CCVars.EnablePlayerBugReports, UpdateButtonVisibility);
}
private void ToggleWindow()
{
if (_bugReportWindow.IsOpen)
_bugReportWindow.Close();
else
_bugReportWindow.OpenCentered();
}
private void OnBugReportSubmitted(PlayerBugReportInformation report)
{
var message = new BugReportMessage { ReportInformation = report };
_net.ClientSendMessage(message);
_bugReportWindow.Close();
}
private void ButtonToggleWindow(BaseButton.ButtonEventArgs obj)
{
ToggleWindow();
}
private void UpdateButtonVisibility(bool val)
{
if (BugReportButton == null)
return;
BugReportButton.Visible = val;
}
}

View File

@@ -1,31 +0,0 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc bug-report-window-name}"
MinSize="600 400">
<BoxContainer Orientation="Vertical" Margin="10 0 20 0">
<RichTextLabel Name="DisabledLabel" HorizontalAlignment="Center" Visible="False" ReservesSpace="False" />
<BoxContainer Orientation="Vertical" Name="BugReportContainer">
<RichTextLabel Name="BugReportExplanation" HorizontalAlignment="Center" Margin="0 0 0 10" Text="{Loc bug-report-window-explanation}" />
<!-- Title -->
<BoxContainer VerticalAlignment="Center">
<LineEdit Name="BugReportTitle" PlaceHolder="{Loc bug-report-window-title-place-holder}" HorizontalExpand="True" />
<Label Name="TitleCharacterCounter" StyleClasses="LabelSmall" Margin="10 0 0 0" VerticalAlignment="Center" />
</BoxContainer>
<!-- Description -->
<TextEdit Name="BugReportDescription" MaxHeight="300" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" MinHeight="200" Margin="0 10 0 0" >
<Label Name="PlaceholderCenter" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Loc bug-report-window-description-place-holder}" StyleClasses="PlaceholderText" />
</TextEdit>
<!-- Footer -->
<BoxContainer HorizontalAlignment="Center" Orientation="Horizontal" >
<Label Name="DescriptionCharacterCounter" StyleClasses="LabelSmall"/>
</BoxContainer>
<!-- Submit button and disclaimer -->
<controls:ConfirmButton Name="SubmitButton" ConfirmationText="{Loc bug-report-window-submit-button-confirm-text}" Text="{Loc bug-report-window-submit-button-text}" Margin="0 5 0 0" />
<Label HorizontalAlignment="Center" Text="{Loc bug-report-window-submit-button-disclaimer}" StyleClasses="LabelSmall" />
</BoxContainer>
</BoxContainer>
</DefaultWindow>

View File

@@ -1,181 +0,0 @@
using System.Diagnostics.CodeAnalysis;
using Content.Client.Players.PlayTimeTracking;
using Content.Shared.BugReport;
using Content.Shared.CCVar;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.UserInterface.Systems.BugReport.Windows;
[GenerateTypedNameReferences]
public sealed partial class BugReportWindow : DefaultWindow
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
// TODO: Use SharedPlaytimeManager when its refactored out of job requirements
[Dependency] private readonly JobRequirementsManager _job = default!;
// This action gets invoked when the user submits a bug report.
public event Action<PlayerBugReportInformation>? OnBugReportSubmitted;
private DateTime _lastIsEnabledUpdated;
private readonly TimeSpan _isEnabledUpdateInterval = TimeSpan.FromSeconds(1);
// These are NOT always up to date. If someone disconnects and reconnects, the values will be reset.
// The only other way of getting updated values would be a message from client -> server then from server -> client.
// I don't think that is worth the added complexity.
private DateTime _lastBugReportSubmittedTime = DateTime.MinValue;
private int _amountOfBugReportsSubmitted;
private readonly ConfigurationMultiSubscriptionBuilder _configSub;
#region ccvar
private bool _enablePlayerBugReports;
private int _minimumPlaytimeBugReports;
private int _minimumTimeBetweenBugReports;
private int _maximumBugReportsPerRound;
private int _maximumBugReportTitleLength;
private int _minimumBugReportTitleLength;
private int _maximumBugReportDescriptionLength;
private int _minimumBugReportDescriptionLength;
#endregion
public BugReportWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_configSub = _cfg.SubscribeMultiple()
.OnValueChanged(CCVars.EnablePlayerBugReports, x => _enablePlayerBugReports = x, true)
.OnValueChanged(CCVars.MinimumPlaytimeInMinutesToEnableBugReports, x => _minimumPlaytimeBugReports = x, true)
.OnValueChanged(CCVars.MinimumSecondsBetweenBugReports, x => _minimumTimeBetweenBugReports = x, true)
.OnValueChanged(CCVars.MaximumBugReportsPerRound, x => _maximumBugReportsPerRound = x, true)
.OnValueChanged(CCVars.MaximumBugReportTitleLength, x => _maximumBugReportTitleLength = x, true)
.OnValueChanged(CCVars.MinimumBugReportTitleLength, x => _minimumBugReportTitleLength = x, true)
.OnValueChanged(CCVars.MaximumBugReportDescriptionLength, x => _maximumBugReportDescriptionLength = x, true)
.OnValueChanged(CCVars.MinimumBugReportDescriptionLength, x => _minimumBugReportDescriptionLength = x, true);
// Hook up the events
SubmitButton.OnPressed += _ => OnSubmitButtonPressed();
BugReportTitle.OnTextChanged += _ => HandleInputChange();
BugReportDescription.OnTextChanged += _ => HandleInputChange();
OnOpen += UpdateEnabled;
HandleInputChange();
UpdateEnabled();
}
private void OnSubmitButtonPressed()
{
var report = new PlayerBugReportInformation
{
BugReportTitle = BugReportTitle.Text,
BugReportDescription = Rope.Collapse(BugReportDescription.TextRope),
};
OnBugReportSubmitted?.Invoke(report);
_lastBugReportSubmittedTime = DateTime.UtcNow;
_amountOfBugReportsSubmitted++;
BugReportTitle.Text = string.Empty;
BugReportDescription.TextRope = Rope.Leaf.Empty;
HandleInputChange();
UpdateEnabled();
}
/// <summary>
/// Deals with the user changing their input. Ensures that things that depend on what the user has inputted get updated
/// (E.g. the amount of characters they have typed)
/// </summary>
private void HandleInputChange()
{
var titleLen = BugReportTitle.Text.Length;
var descriptionLen = BugReportDescription.TextLength;
var invalidTitleLen = titleLen < _minimumBugReportTitleLength || titleLen > _maximumBugReportTitleLength;
var invalidDescriptionLen = descriptionLen < _minimumBugReportDescriptionLength || descriptionLen > _maximumBugReportDescriptionLength;
TitleCharacterCounter.Text = Loc.GetString("bug-report-window-submit-char-split", ("typed", titleLen), ("total", _maximumBugReportTitleLength));
TitleCharacterCounter.FontColorOverride = invalidTitleLen ? Color.Red : Color.Green;
DescriptionCharacterCounter.Text = Loc.GetString("bug-report-window-submit-char-split", ("typed", descriptionLen), ("total", _maximumBugReportDescriptionLength));
DescriptionCharacterCounter.FontColorOverride = invalidDescriptionLen ? Color.Red : Color.Green;
SubmitButton.Disabled = invalidTitleLen || invalidDescriptionLen;
PlaceholderCenter.Visible = descriptionLen == 0;
}
/// <summary>
/// Checks if the bug report window should be enabled for this client.
/// </summary>
private bool IsEnabled([NotNullWhen(false)] out string? errorMessage)
{
errorMessage = null;
if (!_enablePlayerBugReports)
{
errorMessage = Loc.GetString("bug-report-window-disabled-not-enabled");
return false;
}
if (TimeSpan.FromMinutes(_minimumPlaytimeBugReports) > _job.FetchOverallPlaytime())
{
errorMessage = Loc.GetString("bug-report-window-disabled-playtime");
return false;
}
if (_amountOfBugReportsSubmitted >= _maximumBugReportsPerRound)
{
errorMessage = Loc.GetString("bug-report-window-disabled-submissions", ("num", _maximumBugReportsPerRound));
return false;
}
var timeSinceLastReport = DateTime.UtcNow - _lastBugReportSubmittedTime;
var timeBetweenBugReports = TimeSpan.FromSeconds(_minimumTimeBetweenBugReports);
if (timeSinceLastReport <= timeBetweenBugReports)
{
var time = timeBetweenBugReports - timeSinceLastReport;
errorMessage = Loc.GetString("bug-report-window-disabled-cooldown", ("time", time.ToString(@"d\.hh\:mm\:ss")));
return false;
}
return true;
}
// Update the state of the window to display either the bug report window or an error explaining why you can't submit a report.
private void UpdateEnabled()
{
var isEnabled = IsEnabled(out var errorMessage);
DisabledLabel.Text = errorMessage;
DisabledLabel.Visible = !isEnabled;
BugReportContainer.Visible = isEnabled;
_lastIsEnabledUpdated = DateTime.UtcNow;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!Visible) // Don't bother updating if no one can see the window anyway.
return;
if(DateTime.UtcNow - _lastIsEnabledUpdated > _isEnabledUpdateInterval)
UpdateEnabled();
}
public void CleanupCCvars()
{
_configSub.Dispose();
}
}

View File

@@ -1,6 +1,5 @@
using Content.Client.UserInterface.Systems.Actions;
using Content.Client.UserInterface.Systems.Admin;
using Content.Client.UserInterface.Systems.BugReport;
using Content.Client.UserInterface.Systems.Bwoink;
using Content.Client.UserInterface.Systems.Character;
using Content.Client.UserInterface.Systems.Crafting;
@@ -25,7 +24,6 @@ public sealed class GameTopMenuBarUIController : UIController
[Dependency] private readonly SandboxUIController _sandbox = default!;
[Dependency] private readonly GuidebookUIController _guidebook = default!;
[Dependency] private readonly EmotesUIController _emotes = default!;
[Dependency] private readonly BugReportUIController _bug = default!;
private GameTopMenuBar? GameTopMenuBar => UIManager.GetActiveUIWidgetOrNull<GameTopMenuBar>();
@@ -49,7 +47,6 @@ public sealed class GameTopMenuBarUIController : UIController
_action.UnloadButton();
_sandbox.UnloadButton();
_emotes.UnloadButton();
_bug.UnloadButton();
}
public void LoadButtons()
@@ -63,6 +60,5 @@ public sealed class GameTopMenuBarUIController : UIController
_action.LoadButton();
_sandbox.LoadButton();
_emotes.LoadButton();
_bug.LoadButton();
}
}

View File

@@ -93,15 +93,6 @@
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
/>
<ui:MenuButton
Name="ReportBugButton"
Access="Internal"
Icon="{xe:Tex '/Textures/Interface/bug.svg.192dpi.png'}"
ToolTip="{Loc 'game-hud-open-bug-report-window-button-tooltip'}"
MinSize="42 64"
HorizontalExpand="True"
AppendStyleClass="{x:Static style:StyleBase.ButtonSquare}"
/>
<ui:MenuButton
Name="AHelpButton"
Access="Internal"