Files
tbd-station-14/Content.Client/Changelog/ChangelogWindow.xaml.cs
LordCarve a3ddba6f42 Cleanup - Use RemoveAllChildren() over DisposeAllChildren() (#39848)
* Content - change the (should-be-obsolete) DisposeAllChildren into the more robust RemoveAllChildren.

* Remove duplicate calls.

---------

Co-authored-by: ElectroJr <leonsfriedrich@gmail.com>
2025-09-23 15:40:48 +12:00

127 lines
3.8 KiB
C#

using System.Linq;
using Content.Client.Administration.Managers;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.EscapeMenu;
using Content.Shared.Administration;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Console;
namespace Content.Client.Changelog
{
[GenerateTypedNameReferences]
public sealed partial class ChangelogWindow : FancyWindow
{
[Dependency] private readonly IClientAdminManager _adminManager = default!;
[Dependency] private readonly ChangelogManager _changelog = default!;
public ChangelogWindow()
{
RobustXamlLoader.Load(this);
WindowTitle.AddStyleClass(StyleBase.StyleClassLabelHeading);
Stylesheet = IoCManager.Resolve<IStylesheetManager>().SheetSpace;
}
protected override void Opened()
{
base.Opened();
_changelog.SaveNewReadId();
PopulateChangelog();
}
protected override void EnteredTree()
{
base.EnteredTree();
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
}
protected override void ExitedTree()
{
base.ExitedTree();
_adminManager.AdminStatusUpdated -= OnAdminStatusUpdated;
}
private void OnAdminStatusUpdated()
{
TabsUpdated();
}
private async void PopulateChangelog()
{
// Changelog is not kept in memory so load it again.
var changelogs = await _changelog.LoadChangelog();
Tabs.RemoveAllChildren();
var i = 0;
foreach (var changelog in changelogs)
{
var tab = new ChangelogTab { AdminOnly = changelog.AdminOnly };
tab.PopulateChangelog(changelog);
Tabs.AddChild(tab);
Tabs.SetTabTitle(i++, Loc.GetString($"changelog-tab-title-{changelog.Name}"));
}
VersionLabel.Text = _changelog.GetClientVersion();
TabsUpdated();
}
private void TabsUpdated()
{
var tabs = Tabs.Children.OfType<ChangelogTab>().ToArray();
var isAdmin = _adminManager.IsAdmin(true);
var visibleTabs = 0;
int? firstVisible = null;
for (var i = 0; i < tabs.Length; i++)
{
var tab = tabs[i];
if (!tab.AdminOnly || isAdmin)
{
Tabs.SetTabVisible(i, true);
visibleTabs++;
firstVisible ??= i;
}
else
{
Tabs.SetTabVisible(i, false);
}
}
Tabs.TabsVisible = visibleTabs > 1;
// Current tab became invisible, select the first one that is visible
if (!Tabs.GetTabVisible(Tabs.CurrentTab) && firstVisible != null)
{
Tabs.CurrentTab = firstVisible.Value;
}
// We are only displaying one tab, hide its header
if (!Tabs.TabsVisible && firstVisible != null)
{
Tabs.SetTabVisible(firstVisible.Value, false);
}
}
}
[UsedImplicitly, AnyCommand]
public sealed class ChangelogCommand : LocalizedCommands
{
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
public override string Command => "changelog";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
_uiManager.GetUIController<ChangelogUIController>().OpenWindow();
}
}
}