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

@@ -20,31 +20,37 @@ public sealed partial class RCDMenu : RadialMenu
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
private readonly SpriteSystem _spriteSystem;
private readonly SharedPopupSystem _popup;
private SharedPopupSystem _popup;
private SpriteSystem _sprites;
public event Action<ProtoId<RCDPrototype>>? SendRCDSystemMessageAction;
private EntityUid _owner;
public RCDMenu(EntityUid owner, RCDMenuBoundUserInterface bui)
public RCDMenu()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
_spriteSystem = _entManager.System<SpriteSystem>();
_popup = _entManager.System<SharedPopupSystem>();
_sprites = _entManager.System<SpriteSystem>();
_owner = owner;
OnChildAdded += AddRCDMenuButtonOnClickActions;
}
public void SetEntity(EntityUid uid)
{
_owner = uid;
Refresh();
}
public void Refresh()
{
// Find the main radial container
var main = FindControl<RadialContainer>("Main");
if (main == null)
return;
// Populate secondary radial containers
if (!_entManager.TryGetComponent<RCDComponent>(owner, out var rcd))
if (!_entManager.TryGetComponent<RCDComponent>(_owner, out var rcd))
return;
foreach (var protoId in rcd.AvailablePrototypes)
@@ -56,14 +62,10 @@ public sealed partial class RCDMenu : RadialMenu
continue;
var parent = FindControl<RadialContainer>(proto.Category);
if (parent == null)
continue;
var tooltip = Loc.GetString(proto.SetName);
if ((proto.Mode == RcdMode.ConstructTile || proto.Mode == RcdMode.ConstructObject) &&
proto.Prototype != null && _protoManager.TryIndex(proto.Prototype, out var entProto))
proto.Prototype != null && _protoManager.TryIndex(proto.Prototype, out var entProto, logError: false))
{
tooltip = Loc.GetString(entProto.Name);
}
@@ -84,7 +86,7 @@ public sealed partial class RCDMenu : RadialMenu
{
VerticalAlignment = VAlignment.Center,
HorizontalAlignment = HAlignment.Center,
Texture = _spriteSystem.Frame0(proto.Sprite),
Texture = _sprites.Frame0(proto.Sprite),
TextureScale = new Vector2(2f, 2f),
};
@@ -112,11 +114,9 @@ public sealed partial class RCDMenu : RadialMenu
// Set up menu actions
foreach (var child in Children)
{
AddRCDMenuButtonOnClickActions(child);
OnChildAdded += AddRCDMenuButtonOnClickActions;
SendRCDSystemMessageAction += bui.SendRCDSystemMessage;
}
}
private static string OopsConcat(string a, string b)
@@ -153,7 +153,7 @@ public sealed partial class RCDMenu : RadialMenu
var name = Loc.GetString(proto.SetName);
if (proto.Prototype != null &&
_protoManager.TryIndex(proto.Prototype, out var entProto))
_protoManager.TryIndex(proto.Prototype, out var entProto, logError: false))
name = entProto.Name;
msg = Loc.GetString("rcd-component-change-build-mode", ("name", name));

View File

@@ -3,6 +3,7 @@ using Content.Shared.RCD.Components;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.RCD;
@@ -24,8 +25,9 @@ public sealed class RCDMenuBoundUserInterface : BoundUserInterface
{
base.Open();
_menu = new(Owner, this);
_menu.OnClose += Close;
_menu = this.CreateWindow<RCDMenu>();
_menu.SetEntity(Owner);
_menu.SendRCDSystemMessageAction += SendRCDSystemMessage;
// Open the menu, centered on the mouse
var vpSize = _displayManager.ScreenSize;
@@ -34,16 +36,8 @@ public sealed class RCDMenuBoundUserInterface : BoundUserInterface
public void SendRCDSystemMessage(ProtoId<RCDPrototype> protoId)
{
// A predicted message cannot be used here as the RCD UI is closed immediately
// A predicted message cannot be used here as the RCD UI is closed immediately
// after this message is sent, which will stop the server from receiving it
SendMessage(new RCDSystemMessage(protoId));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_menu?.Dispose();
}
}