Reapply "Remove some BUI boilerplate" (#30214) (#30219)

* Reapply "Remove some BUI boilerplate" (#30214)

This reverts commit cb0ba66be3.

* Fix gas tank

* Fix PA

* Fix microwave

* Comms console underwrap

* Fix rcd

* log wehs
This commit is contained in:
metalgearsloth
2024-07-21 14:48:13 +10:00
committed by GitHub
parent 87e52e50b4
commit edb05e36bb
137 changed files with 1102 additions and 1757 deletions

View File

@@ -1,5 +1,7 @@
using Content.Shared.Research;
using Content.Shared.Research.Components;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Research.UI
{
@@ -16,10 +18,7 @@ namespace Content.Client.Research.UI
{
base.Open();
_menu = new();
_menu.OnClose += Close;
_menu.OpenCentered();
_menu = this.CreateWindow<DiskConsoleMenu>();
_menu.OnServerButtonPressed += () =>
{
@@ -31,14 +30,6 @@ namespace Content.Client.Research.UI
};
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Close();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

View File

@@ -1,4 +1,6 @@
using Content.Shared.Research.Components;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Research.UI
{
@@ -15,10 +17,9 @@ namespace Content.Client.Research.UI
protected override void Open()
{
base.Open();
_menu = new ResearchClientServerSelectionMenu(this);
_menu.OnClose += Close;
_menu.OpenCentered();
_menu = this.CreateWindow<ResearchClientServerSelectionMenu>();
_menu.OnServerSelected += SelectServer;
_menu.OnServerDeselected += DeselectServer;
}
public void SelectServer(int serverId)
@@ -37,12 +38,5 @@ namespace Content.Client.Research.UI
if (state is not ResearchClientBoundInterfaceState rState) return;
_menu?.Populate(rState.ServerCount, rState.ServerNames, rState.ServerIds, rState.SelectedServerId);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_menu?.Dispose();
}
}
}

View File

@@ -13,27 +13,26 @@ namespace Content.Client.Research.UI
private int[] _serverIds = Array.Empty<int>();
private int _selectedServerId = -1;
private ResearchClientBoundUserInterface Owner { get; }
public event Action<int>? OnServerSelected;
public event Action? OnServerDeselected;
public ResearchClientServerSelectionMenu(ResearchClientBoundUserInterface owner)
public ResearchClientServerSelectionMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
Owner = owner;
Servers.OnItemSelected += OnItemSelected;
Servers.OnItemDeselected += OnItemDeselected;
}
public void OnItemSelected(ItemList.ItemListSelectedEventArgs itemListSelectedEventArgs)
{
Owner.SelectServer(_serverIds[itemListSelectedEventArgs.ItemIndex]);
OnServerSelected?.Invoke(_serverIds[itemListSelectedEventArgs.ItemIndex]);
}
public void OnItemDeselected(ItemList.ItemListDeselectedEventArgs itemListDeselectedEventArgs)
{
Owner.DeselectServer();
OnServerDeselected?.Invoke();
}
public void Populate(int serverCount, string[] serverNames, int[] serverIds, int selectedServerId)

View File

@@ -1,5 +1,8 @@
using Content.Shared.Research.Components;
using Content.Shared.Research.Prototypes;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Research.UI;
@@ -19,7 +22,8 @@ public sealed class ResearchConsoleBoundUserInterface : BoundUserInterface
var owner = Owner;
_consoleMenu = new ResearchConsoleMenu(owner);
_consoleMenu = this.CreateWindow<ResearchConsoleMenu>();
_consoleMenu.SetEntity(owner);
_consoleMenu.OnTechnologyCardPressed += id =>
{
@@ -30,10 +34,20 @@ public sealed class ResearchConsoleBoundUserInterface : BoundUserInterface
{
SendMessage(new ConsoleServerSelectionMessage());
};
}
_consoleMenu.OnClose += Close;
public override void OnProtoReload(PrototypesReloadedEventArgs args)
{
base.OnProtoReload(args);
_consoleMenu.OpenCentered();
if (!args.WasModified<TechnologyPrototype>())
return;
if (State is not ResearchConsoleBoundInterfaceState rState)
return;
_consoleMenu?.UpdatePanels(rState);
_consoleMenu?.UpdateInformationPanel(rState);
}
protected override void UpdateState(BoundUserInterfaceState state)
@@ -45,12 +59,4 @@ public sealed class ResearchConsoleBoundUserInterface : BoundUserInterface
_consoleMenu?.UpdatePanels(castState);
_consoleMenu?.UpdateInformationPanel(castState);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_consoleMenu?.Dispose();
}
}

View File

@@ -25,14 +25,13 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
[Dependency] private readonly IEntityManager _entity = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly IPlayerManager _player = default!;
private readonly TechnologyDatabaseComponent? _technologyDatabase;
private readonly ResearchSystem _research;
private readonly SpriteSystem _sprite;
private readonly AccessReaderSystem _accessReader;
public readonly EntityUid Entity;
public EntityUid Entity;
public ResearchConsoleMenu(EntityUid entity)
public ResearchConsoleMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
@@ -40,21 +39,23 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
_research = _entity.System<ResearchSystem>();
_sprite = _entity.System<SpriteSystem>();
_accessReader = _entity.System<AccessReaderSystem>();
Entity = entity;
ServerButton.OnPressed += _ => OnServerButtonPressed?.Invoke();
_entity.TryGetComponent(entity, out _technologyDatabase);
}
public void UpdatePanels(ResearchConsoleBoundInterfaceState state)
public void SetEntity(EntityUid entity)
{
Entity = entity;
}
public void UpdatePanels(ResearchConsoleBoundInterfaceState state)
{
TechnologyCardsContainer.Children.Clear();
var availableTech = _research.GetAvailableTechnologies(Entity);
SyncTechnologyList(AvailableCardsContainer, availableTech);
if (_technologyDatabase == null)
if (!_entity.TryGetComponent(Entity, out TechnologyDatabaseComponent? database))
return;
// i can't figure out the spacing so here you go
@@ -66,7 +67,7 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
var hasAccess = _player.LocalEntity is not { } local ||
!_entity.TryGetComponent<AccessReaderComponent>(Entity, out var access) ||
_accessReader.IsAllowed(local, Entity, access);
foreach (var techId in _technologyDatabase.CurrentTechnologyCards)
foreach (var techId in database.CurrentTechnologyCards)
{
var tech = _prototype.Index<TechnologyPrototype>(techId);
var cardControl = new TechnologyCardControl(tech, _prototype, _sprite, _research.GetTechnologyDescription(tech, includeTier: false), state.Points, hasAccess);
@@ -74,7 +75,7 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
TechnologyCardsContainer.AddChild(cardControl);
}
var unlockedTech = _technologyDatabase.UnlockedTechnologies.Select(x => _prototype.Index<TechnologyPrototype>(x));
var unlockedTech = database.UnlockedTechnologies.Select(x => _prototype.Index<TechnologyPrototype>(x));
SyncTechnologyList(UnlockedCardsContainer, unlockedTech);
}
@@ -85,14 +86,14 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
("points", state.Points)));
ResearchAmountLabel.SetMessage(amountMsg);
if (_technologyDatabase == null)
if (!_entity.TryGetComponent(Entity, out TechnologyDatabaseComponent? database))
return;
var disciplineText = Loc.GetString("research-discipline-none");
var disciplineColor = Color.Gray;
if (_technologyDatabase.MainDiscipline != null)
if (database.MainDiscipline != null)
{
var discipline = _prototype.Index<TechDisciplinePrototype>(_technologyDatabase.MainDiscipline);
var discipline = _prototype.Index<TechDisciplinePrototype>(database.MainDiscipline);
disciplineText = Loc.GetString(discipline.Name);
disciplineColor = discipline.Color;
}
@@ -103,10 +104,10 @@ public sealed partial class ResearchConsoleMenu : FancyWindow
MainDisciplineLabel.SetMessage(msg);
TierDisplayContainer.Children.Clear();
foreach (var disciplineId in _technologyDatabase.SupportedDisciplines)
foreach (var disciplineId in database.SupportedDisciplines)
{
var discipline = _prototype.Index<TechDisciplinePrototype>(disciplineId);
var tier = _research.GetHighestDisciplineTier(_technologyDatabase, discipline);
var tier = _research.GetHighestDisciplineTier(database, discipline);
// don't show tiers with no available tech
if (tier == 0)