Remove some BUI boilerplate (#28399)

* Remove some BUI boilerplate

- The disposals overrides got removed due to the helper method handling it.
- Replace window creation with CreateWindow helper.
- Fixed some stinky code which would cause exceptions.

* More

* moar

* weh

* done

* More BUIs

* More updates

* weh

* moar

* look who it is

* weh

* merge

* weh

* fixes
This commit is contained in:
metalgearsloth
2024-07-20 15:40:16 +10:00
committed by GitHub
parent 4aba9ec131
commit cbf329a82d
137 changed files with 1094 additions and 1753 deletions

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)