using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Containers.ItemSlots;
+using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
using static Content.Shared.Access.Components.AccessOverriderComponent;
{
base.Open();
+ _window = this.CreateWindow<AccessOverriderWindow>();
+ RefreshAccess();
+ _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
+ _window.OnSubmit += SubmitData;
+
+ _window.PrivilegedIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(PrivilegedIdCardSlotId));
+ }
+
+ public override void OnProtoReload(PrototypesReloadedEventArgs args)
+ {
+ base.OnProtoReload(args);
+ if (!args.WasModified<AccessLevelPrototype>())
+ return;
+
+ RefreshAccess();
+
+ if (State != null)
+ _window?.UpdateState(_prototypeManager, (AccessOverriderBoundUserInterfaceState) State);
+ }
+
+ private void RefreshAccess()
+ {
List<ProtoId<AccessLevelPrototype>> accessLevels;
if (EntMan.TryGetComponent<AccessOverriderComponent>(Owner, out var accessOverrider))
accessLevels = accessOverrider.AccessLevels;
accessLevels.Sort();
}
-
else
{
accessLevels = new List<ProtoId<AccessLevelPrototype>>();
_accessOverriderSystem.Log.Error($"No AccessOverrider component found for {EntMan.ToPrettyString(Owner)}!");
}
- _window = new AccessOverriderWindow(this, _prototypeManager, accessLevels)
- {
- Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName
- };
-
- _window.PrivilegedIdButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(PrivilegedIdCardSlotId));
-
- _window.OnClose += Close;
- _window.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _window?.Dispose();
+ _window?.SetAccessLevels(_prototypeManager, accessLevels);
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
var castState = (AccessOverriderBoundUserInterfaceState) state;
- _window?.UpdateState(castState);
+ _window?.UpdateState(_prototypeManager, castState);
}
public void SubmitData(List<ProtoId<AccessLevelPrototype>> newAccessList)
[GenerateTypedNameReferences]
public sealed partial class AccessOverriderWindow : DefaultWindow
{
- [Dependency] private readonly ILogManager _logManager = default!;
- [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
-
- private readonly AccessOverriderBoundUserInterface _owner;
private readonly Dictionary<string, Button> _accessButtons = new();
- public AccessOverriderWindow(AccessOverriderBoundUserInterface owner, IPrototypeManager prototypeManager,
- List<ProtoId<AccessLevelPrototype>> accessLevels)
+ public event Action<List<ProtoId<AccessLevelPrototype>>>? OnSubmit;
+
+ public AccessOverriderWindow()
{
RobustXamlLoader.Load(this);
- IoCManager.InjectDependencies(this);
- var logMill = _logManager.GetSawmill(SharedAccessOverriderSystem.Sawmill);
+ }
- _owner = owner;
+ public void SetAccessLevels(IPrototypeManager protoManager, List<ProtoId<AccessLevelPrototype>> accessLevels)
+ {
+ _accessButtons.Clear();
+ AccessLevelGrid.DisposeAllChildren();
foreach (var access in accessLevels)
{
- if (!prototypeManager.TryIndex(access, out var accessLevel))
+ if (!protoManager.TryIndex(access, out var accessLevel))
{
- logMill.Error($"Unable to find accesslevel for {access}");
continue;
}
AccessLevelGrid.AddChild(newButton);
_accessButtons.Add(accessLevel.ID, newButton);
- newButton.OnPressed += _ => SubmitData();
+ newButton.OnPressed += _ =>
+ {
+ OnSubmit?.Invoke(
+ // Iterate over the buttons dictionary, filter by `Pressed`, only get key from the key/value pair
+ _accessButtons.Where(x => x.Value.Pressed).Select(x => new ProtoId<AccessLevelPrototype>(x.Key)).ToList());
+ };
}
}
- public void UpdateState(AccessOverriderBoundUserInterfaceState state)
+ public void UpdateState(IPrototypeManager protoManager, AccessOverriderBoundUserInterfaceState state)
{
PrivilegedIdLabel.Text = state.PrivilegedIdName;
PrivilegedIdButton.Text = state.IsPrivilegedIdPresent
if (state.MissingPrivilegesList != null && state.MissingPrivilegesList.Any())
{
- List<string> missingPrivileges = new List<string>();
+ var missingPrivileges = new List<string>();
foreach (string tag in state.MissingPrivilegesList)
{
- string privilege = Loc.GetString(_prototypeManager.Index<AccessLevelPrototype>(tag)?.Name ?? "generic-unknown");
+ var privilege = Loc.GetString(protoManager.Index<AccessLevelPrototype>(tag)?.Name ?? "generic-unknown");
missingPrivileges.Add(privilege);
}
}
}
}
-
- private void SubmitData()
- {
- _owner.SubmitData(
-
- // Iterate over the buttons dictionary, filter by `Pressed`, only get key from the key/value pair
- _accessButtons.Where(x => x.Value.Pressed).Select(x => new ProtoId<AccessLevelPrototype>(x.Key)).ToList());
- }
}
}
using Content.Shared.Access.Systems;
using Content.Shared.StatusIcon;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Access.UI
{
base.Open();
- _window?.Dispose();
- _window = new AgentIDCardWindow(this);
- if (State != null)
- UpdateState(State);
+ _window = this.CreateWindow<AgentIDCardWindow>();
- _window.OpenCentered();
-
- _window.OnClose += Close;
_window.OnNameChanged += OnNameChanged;
_window.OnJobChanged += OnJobChanged;
+ _window.OnJobIconChanged += OnJobIconChanged;
}
private void OnNameChanged(string newName)
_window.SetCurrentJob(cast.CurrentJob);
_window.SetAllowedIcons(cast.Icons, cast.CurrentJobIconId);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _window?.Dispose();
- }
}
}
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
private readonly SpriteSystem _spriteSystem;
- private readonly AgentIDCardBoundUserInterface _bui;
private const int JobIconColumnCount = 10;
public event Action<string>? OnNameChanged;
public event Action<string>? OnJobChanged;
- public AgentIDCardWindow(AgentIDCardBoundUserInterface bui)
+ public event Action<ProtoId<StatusIconPrototype>>? OnJobIconChanged;
+
+ public AgentIDCardWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_spriteSystem = _entitySystem.GetEntitySystem<SpriteSystem>();
- _bui = bui;
NameLineEdit.OnTextEntered += e => OnNameChanged?.Invoke(e.Text);
NameLineEdit.OnFocusExit += e => OnNameChanged?.Invoke(e.Text);
};
// Generate buttons textures
- TextureRect jobIconTexture = new TextureRect
+ var jobIconTexture = new TextureRect
{
Texture = _spriteSystem.Frame0(jobIcon.Icon),
TextureScale = new Vector2(2.5f, 2.5f),
};
jobIconButton.AddChild(jobIconTexture);
- jobIconButton.OnPressed += _ => _bui.OnJobIconChanged(jobIconId);
+ jobIconButton.OnPressed += _ => OnJobIconChanged?.Invoke(jobIcon.ID);
IconGrid.AddChild(jobIconButton);
if (jobIconId.Equals(currentJobIconId))
using Content.Shared.Ame.Components;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
namespace Content.Client.Ame.UI
{
{
base.Open();
- _window = new AmeWindow(this);
- _window.OnClose += Close;
- _window.OpenCentered();
+ _window = this.CreateWindow<AmeWindow>();
+ _window.OnAmeButton += ButtonPressed;
}
/// <summary>
{
SendMessage(new UiButtonPressedMessage(button));
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _window?.Dispose();
- }
- }
}
}
+using System.Linq;
using Content.Client.UserInterface;
using Content.Shared.Ame.Components;
using Robust.Client.AutoGenerated;
[GenerateTypedNameReferences]
public sealed partial class AmeWindow : DefaultWindow
{
- public AmeWindow(AmeControllerBoundUserInterface ui)
+ public event Action<UiButton>? OnAmeButton;
+
+ public AmeWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
- EjectButton.OnPressed += _ => ui.ButtonPressed(UiButton.Eject);
- ToggleInjection.OnPressed += _ => ui.ButtonPressed(UiButton.ToggleInjection);
- IncreaseFuelButton.OnPressed += _ => ui.ButtonPressed(UiButton.IncreaseFuel);
- DecreaseFuelButton.OnPressed += _ => ui.ButtonPressed(UiButton.DecreaseFuel);
+ EjectButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.Eject);
+ ToggleInjection.OnPressed += _ => OnAmeButton?.Invoke(UiButton.ToggleInjection);
+ IncreaseFuelButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.IncreaseFuel);
+ DecreaseFuelButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.DecreaseFuel);
}
/// <summary>
var castState = (AmeControllerBoundUserInterfaceState) state;
// Disable all buttons if not powered
- if (Contents.Children != null)
+ if (Contents.Children.Any())
{
ButtonHelpers.SetButtonDisabledRecursive(Contents, !castState.HasPower);
EjectButton.Disabled = false;
CoreCount.Text = $"{castState.CoreCount}";
InjectionAmount.Text = $"{castState.InjectionAmount}";
// format power statistics to pretty numbers
- CurrentPowerSupply.Text = $"{castState.CurrentPowerSupply.ToString("N1")}";
- TargetedPowerSupply.Text = $"{castState.TargetedPowerSupply.ToString("N1")}";
+ CurrentPowerSupply.Text = $"{castState.CurrentPowerSupply:N1}";
+ TargetedPowerSupply.Text = $"{castState.TargetedPowerSupply:N1}";
}
}
}
using Content.Shared.Gravity;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Anomaly.Ui;
{
base.Open();
- _window = new(Owner);
-
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<AnomalyGeneratorWindow>();
+ _window.SetEntity(Owner);
_window.OnGenerateButtonPressed += () =>
{
return;
_window?.UpdateState(msg);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
-
- _window?.Dispose();
- }
-
- public void SetPowerSwitch(bool on)
- {
- SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(on));
- }
}
public Action? OnGenerateButtonPressed;
- public AnomalyGeneratorWindow(EntityUid gen)
+ public AnomalyGeneratorWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
- EntityView.SetEntity(gen);
EntityView.SpriteOffset = false;
GenerateButton.OnPressed += _ => OnGenerateButtonPressed?.Invoke();
}
+ public void SetEntity(EntityUid uid)
+ {
+ EntityView.SetEntity(uid);
+ }
+
public void UpdateState(AnomalyGeneratorUserInterfaceState state)
{
_cooldownEnd = state.CooldownEndTime;
private static readonly Vector2 BlockSize = new(15, 15);
- private readonly BlockGameBoundUserInterface _owner;
-
private readonly PanelContainer _mainPanel;
private readonly BoxContainer _gameRootContainer;
private bool _isPlayer = false;
private bool _gameOver = false;
- public BlockGameMenu(BlockGameBoundUserInterface owner)
+ public event Action<BlockGamePlayerAction>? OnAction;
+
+ public BlockGameMenu()
{
Title = Loc.GetString("blockgame-menu-title");
- _owner = owner;
MinSize = SetSize = new Vector2(410, 490);
};
_newGameButton.OnPressed += (e) =>
{
- _owner.SendAction(BlockGamePlayerAction.NewGame);
+ OnAction?.Invoke(BlockGamePlayerAction.NewGame);
};
pauseMenuContainer.AddChild(_newGameButton);
pauseMenuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) });
Text = Loc.GetString("blockgame-menu-button-scoreboard"),
TextAlign = Label.AlignMode.Center
};
- _scoreBoardButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.ShowHighscores);
+ _scoreBoardButton.OnPressed += (e) =>
+ {
+ OnAction?.Invoke(BlockGamePlayerAction.ShowHighscores);
+ };
pauseMenuContainer.AddChild(_scoreBoardButton);
_unpauseButtonMargin = new Control { MinSize = new Vector2(1, 10), Visible = false };
pauseMenuContainer.AddChild(_unpauseButtonMargin);
};
_unpauseButton.OnPressed += (e) =>
{
- _owner.SendAction(BlockGamePlayerAction.Unpause);
+ OnAction?.Invoke(BlockGamePlayerAction.Unpause);
};
pauseMenuContainer.AddChild(_unpauseButton);
};
_finalNewGameButton.OnPressed += (e) =>
{
- _owner.SendAction(BlockGamePlayerAction.NewGame);
+ OnAction?.Invoke(BlockGamePlayerAction.NewGame);
};
gameOverMenuContainer.AddChild(_finalNewGameButton);
Text = Loc.GetString("blockgame-menu-button-back"),
TextAlign = Label.AlignMode.Center
};
- _highscoreBackButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.Pause);
+ _highscoreBackButton.OnPressed += (e) =>
+ {
+ OnAction?.Invoke(BlockGamePlayerAction.Pause);
+ };
menuContainer.AddChild(_highscoreBackButton);
menuInnerPanel.AddChild(menuContainer);
private void TryPause()
{
- _owner.SendAction(BlockGamePlayerAction.Pause);
+ OnAction?.Invoke(BlockGamePlayerAction.Pause);
}
public void SetStarted()
return;
else if (args.Function == ContentKeyFunctions.ArcadeLeft)
- _owner.SendAction(BlockGamePlayerAction.StartLeft);
+ OnAction?.Invoke(BlockGamePlayerAction.StartLeft);
else if (args.Function == ContentKeyFunctions.ArcadeRight)
- _owner.SendAction(BlockGamePlayerAction.StartRight);
+ OnAction?.Invoke(BlockGamePlayerAction.StartRight);
else if (args.Function == ContentKeyFunctions.ArcadeUp)
- _owner.SendAction(BlockGamePlayerAction.Rotate);
+ OnAction?.Invoke(BlockGamePlayerAction.Rotate);
else if (args.Function == ContentKeyFunctions.Arcade3)
- _owner.SendAction(BlockGamePlayerAction.CounterRotate);
+ OnAction?.Invoke(BlockGamePlayerAction.CounterRotate);
else if (args.Function == ContentKeyFunctions.ArcadeDown)
- _owner.SendAction(BlockGamePlayerAction.SoftdropStart);
+ OnAction?.Invoke(BlockGamePlayerAction.SoftdropStart);
else if (args.Function == ContentKeyFunctions.Arcade2)
- _owner.SendAction(BlockGamePlayerAction.Hold);
+ OnAction?.Invoke(BlockGamePlayerAction.Hold);
else if (args.Function == ContentKeyFunctions.Arcade1)
- _owner.SendAction(BlockGamePlayerAction.Harddrop);
+ OnAction?.Invoke(BlockGamePlayerAction.Harddrop);
}
protected override void KeyBindUp(GUIBoundKeyEventArgs args)
return;
else if (args.Function == ContentKeyFunctions.ArcadeLeft)
- _owner.SendAction(BlockGamePlayerAction.EndLeft);
+ OnAction?.Invoke(BlockGamePlayerAction.EndLeft);
else if (args.Function == ContentKeyFunctions.ArcadeRight)
- _owner.SendAction(BlockGamePlayerAction.EndRight);
+ OnAction?.Invoke(BlockGamePlayerAction.EndRight);
else if (args.Function == ContentKeyFunctions.ArcadeDown)
- _owner.SendAction(BlockGamePlayerAction.SoftdropEnd);
+ OnAction?.Invoke(BlockGamePlayerAction.SoftdropEnd);
}
public void UpdateNextBlock(BlockGameBlock[] blocks)
{
public sealed class SpaceVillainArcadeMenu : DefaultWindow
{
- public SpaceVillainArcadeBoundUserInterface Owner { get; set; }
-
private readonly Label _enemyNameLabel;
private readonly Label _playerInfoLabel;
private readonly Label _enemyInfoLabel;
private readonly Label _enemyActionLabel;
private readonly Button[] _gameButtons = new Button[3]; //used to disable/enable all game buttons
- public SpaceVillainArcadeMenu(SpaceVillainArcadeBoundUserInterface owner)
+
+ public event Action<SharedSpaceVillainArcadeComponent.PlayerAction>? OnPlayerAction;
+
+ public SpaceVillainArcadeMenu()
{
MinSize = SetSize = new Vector2(300, 225);
Title = Loc.GetString("spacevillain-menu-title");
- Owner = owner;
var grid = new GridContainer { Columns = 1 };
grid.AddChild(_enemyActionLabel);
var buttonGrid = new GridContainer { Columns = 3 };
- _gameButtons[0] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Attack)
+ _gameButtons[0] = new Button()
{
Text = Loc.GetString("spacevillain-menu-button-attack")
};
+
+ _gameButtons[0].OnPressed +=
+ _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Attack);
buttonGrid.AddChild(_gameButtons[0]);
- _gameButtons[1] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Heal)
+ _gameButtons[1] = new Button()
{
Text = Loc.GetString("spacevillain-menu-button-heal")
};
+
+ _gameButtons[1].OnPressed +=
+ _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Heal);
buttonGrid.AddChild(_gameButtons[1]);
- _gameButtons[2] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Recharge)
+ _gameButtons[2] = new Button()
{
Text = Loc.GetString("spacevillain-menu-button-recharge")
};
+
+ _gameButtons[2].OnPressed +=
+ _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Recharge);
buttonGrid.AddChild(_gameButtons[2]);
centerContainer = new CenterContainer();
centerContainer.AddChild(buttonGrid);
grid.AddChild(centerContainer);
- var newGame = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.NewGame)
+ var newGame = new Button()
{
Text = Loc.GetString("spacevillain-menu-button-new-game")
};
+
+ newGame.OnPressed += _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.NewGame);
grid.AddChild(newGame);
Contents.AddChild(grid);
_playerActionLabel.Text = message.PlayerActionMessage;
_enemyActionLabel.Text = message.EnemyActionMessage;
}
-
- private sealed class ActionButton : Button
- {
- private readonly SpaceVillainArcadeBoundUserInterface _owner;
- private readonly SharedSpaceVillainArcadeComponent.PlayerAction _playerAction;
-
- public ActionButton(SpaceVillainArcadeBoundUserInterface owner, SharedSpaceVillainArcadeComponent.PlayerAction playerAction)
- {
- _owner = owner;
- _playerAction = playerAction;
- OnPressed += Clicked;
- }
-
- private void Clicked(ButtonEventArgs e)
- {
- _owner.SendAction(_playerAction);
- }
- }
}
}
using Content.Shared.Arcade;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Arcade.UI;
{
base.Open();
- _menu = new BlockGameMenu(this);
- _menu.OnClose += Close;
- _menu.OpenCentered();
+ _menu = this.CreateWindow<BlockGameMenu>();
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables;
using static Content.Shared.Arcade.SharedSpaceVillainArcadeComponent;
{
[ViewVariables] private SpaceVillainArcadeMenu? _menu;
- //public SharedSpaceVillainArcadeComponent SpaceVillainArcade;
-
public SpaceVillainArcadeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
SendAction(PlayerAction.RequestData);
{
base.Open();
- _menu = new SpaceVillainArcadeMenu(this);
-
- _menu.OnClose += Close;
- _menu.OpenCentered();
+ _menu = this.CreateWindow<SpaceVillainArcadeMenu>();
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
if (message is SpaceVillainArcadeDataUpdateMessage msg)
_menu?.UpdateInfo(msg);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- _menu?.Dispose();
- }
}
using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Monitor.Components;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Log;
{
base.Open();
- _window = new AirAlarmWindow(this);
+ _window = this.CreateWindow<AirAlarmWindow>();
+ _window.SetEntity(Owner);
- if (State != null)
- {
- UpdateState(State);
- }
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
_window.AtmosDeviceDataChanged += OnDeviceDataChanged;
_window.AtmosDeviceDataCopied += OnDeviceDataCopied;
_window.AtmosAlarmThresholdChanged += OnThresholdChanged;
private CheckBox _autoMode => AutoModeCheckBox;
- public AirAlarmWindow(BoundUserInterface owner)
+ public AirAlarmWindow()
{
RobustXamlLoader.Load(this);
_sensors.Clear();
ResyncAllRequested!.Invoke();
};
+ }
- EntityView.SetEntity(owner.Owner);
+ public void SetEntity(EntityUid uid)
+ {
+ EntityView.SetEntity(uid);
}
public void UpdateState(AirAlarmUIState state)
using Content.Shared.Atmos.Piping.Binary.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI
{
{
base.Open();
- _window = new GasCanisterWindow();
+ _window = this.CreateWindow<GasCanisterWindow>();
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
_window.ReleaseValveCloseButtonPressed += OnReleaseValveClosePressed;
_window.ReleaseValveOpenButtonPressed += OnReleaseValveOpenPressed;
_window.ReleasePressureSet += OnReleasePressureSet;
using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Localizations;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI
{
var atmosSystem = EntMan.System<AtmosphereSystem>();
- _window = new GasFilterWindow(atmosSystem.Gases);
-
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<GasFilterWindow>();
+ _window.PopulateGasList(atmosSystem.Gases);
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.FilterTransferRateChanged += OnFilterTransferRatePressed;
public event Action<string>? FilterTransferRateChanged;
public event Action? SelectGasPressed;
- public GasFilterWindow(IEnumerable<GasPrototype> gases)
+ public GasFilterWindow()
{
RobustXamlLoader.Load(this);
- PopulateGasList(gases);
ToggleStatusButton.OnPressed += _ => SetFilterStatus(!FilterStatus);
ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke();
SelectGasButton.Disabled = true;
}
- private void PopulateGasList(IEnumerable<GasPrototype> gases)
+ public void PopulateGasList(IEnumerable<GasPrototype> gases)
{
GasList.Add(new ItemList.Item(GasList)
{
Text = Loc.GetString("comp-gas-filter-ui-filter-gas-none")
});
- foreach (GasPrototype gas in gases)
+ foreach (var gas in gases)
{
var gasName = Loc.GetString(gas.Name);
GasList.Add(GetGasItem(gas.ID, gasName, GasList));
using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Localizations;
using JetBrains.Annotations;
-using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI
{
{
base.Open();
- _window = new GasMixerWindow();
-
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<GasMixerWindow>();
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.MixerOutputPressureChanged += OnMixerOutputPressurePressed;
_window.SetOutputPressure(cast.OutputPressure);
_window.SetNodePercentages(cast.NodeOne);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- _window?.Dispose();
- }
}
}
using Content.Shared.Localizations;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI
{
{
base.Open();
- _window = new GasPressurePumpWindow();
-
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<GasPressurePumpWindow>();
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.PumpOutputPressureChanged += OnPumpOutputPressurePressed;
_window.SetPumpStatus(cast.Enabled);
_window.SetOutputPressure(cast.OutputPressure);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- _window?.Dispose();
- }
}
}
using Content.Shared.Atmos.Piping.Unary.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI
{
{
base.Open();
- _window = new GasThermomachineWindow();
-
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<GasThermomachineWindow>();
_window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed();
_window.TemperatureSpinbox.OnValueChanged += _ => OnTemperatureChanged(_window.TemperatureSpinbox.Value);
true => Loc.GetString("comp-gas-thermomachine-ui-title-heater")
};
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- _window?.Dispose();
- }
}
}
using Content.Shared.Localizations;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI
{
{
base.Open();
- _window = new GasVolumePumpWindow();
-
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<GasVolumePumpWindow>();
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.PumpTransferRateChanged += OnPumpTransferRatePressed;
if (_window == null || state is not GasVolumePumpBoundUserInterfaceState cast)
return;
- _window.Title = (cast.PumpLabel);
+ _window.Title = cast.PumpLabel;
_window.SetPumpStatus(cast.Enabled);
_window.SetTransferRate(cast.TransferRate);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- _window?.Dispose();
- }
}
}
using Content.Shared.Atmos.Piping.Portable.Components;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.Atmos.UI;
{
base.Open();
- _window = new SpaceHeaterWindow();
-
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<SpaceHeaterWindow>();
_window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed();
_window.IncreaseTempRange.OnPressed += _ => OnTemperatureRangeChanged(_window.TemperatureChangeDelta);
using Content.Shared.Audio.Jukebox;
using Robust.Client.Audio;
-using Robust.Client.Player;
+using Robust.Client.UserInterface;
using Robust.Shared.Audio.Components;
-using Robust.Shared.Player;
using Robust.Shared.Prototypes;
namespace Content.Client.Audio.Jukebox;
{
base.Open();
- _menu = new JukeboxMenu();
- _menu.OnClose += Close;
- _menu.OpenCentered();
+ _menu = this.CreateWindow<JukeboxMenu>();
_menu.OnPlayPressed += args =>
{
SendMessage(new JukeboxSetTimeMessage(sentTime));
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- if (_menu == null)
- return;
-
- _menu.OnClose -= Close;
- _menu.Dispose();
- _menu = null;
- }
}
using Content.Shared.Bed.Cryostorage;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
namespace Content.Client.Bed.Cryostorage;
{
base.Open();
- _menu = new();
-
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<CryostorageMenu>();
_menu.SlotRemoveButtonPressed += (ent, slot) =>
{
{
SendMessage(new CryostorageRemoveItemBuiMessage(ent, hand, CryostorageRemoveItemBuiMessage.RemovalType.Hand));
};
-
- _menu.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
break;
}
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
- _menu?.Dispose();
- }
}
using Content.Client.Cargo.UI;
using Content.Shared.Cargo.Components;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
namespace Content.Client.Cargo.BUI;
{
base.Open();
- _menu = new();
-
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<CargoBountyMenu>();
_menu.OnLabelButtonPressed += id =>
{
{
SendMessage(new BountySkipMessage(id));
};
-
- _menu.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState message)
_menu?.UpdateEntries(state.Bounties, state.UntilNextSkip);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (!disposing)
- return;
-
- _menu?.Dispose();
- }
}
using Content.Shared.Cargo.BUI;
using Content.Shared.Cargo.Events;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Cargo.BUI;
{
base.Open();
- _menu = new CargoPalletMenu();
+ _menu = this.CreateWindow<CargoPalletMenu>();
_menu.AppraiseRequested += OnAppraisal;
_menu.SellRequested += OnSell;
- _menu.OnClose += Close;
-
- _menu.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (disposing)
- {
- _menu?.Dispose();
- }
}
private void OnAppraisal()
using Content.Shared.Cargo.BUI;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Cargo.BUI;
[UsedImplicitly]
public sealed class CargoShuttleConsoleBoundUserInterface : BoundUserInterface
{
+ [Dependency] private readonly IPrototypeManager _protoManager = default!;
+
[ViewVariables]
private CargoShuttleMenu? _menu;
protected override void Open()
{
base.Open();
- var collection = IoCManager.Instance;
-
- if (collection == null)
- return;
-
- _menu = new CargoShuttleMenu(collection.Resolve<IPrototypeManager>(), collection.Resolve<IEntitySystemManager>().GetEntitySystem<SpriteSystem>());
- _menu.OnClose += Close;
-
- _menu.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (disposing)
- {
- _menu?.Dispose();
- }
+ _menu = this.CreateWindow<CargoShuttleMenu>();
}
protected override void UpdateState(BoundUserInterfaceState state)
if (state is not CargoShuttleConsoleBoundUserInterfaceState cargoState) return;
_menu?.SetAccountName(cargoState.AccountName);
_menu?.SetShuttleName(cargoState.ShuttleName);
- _menu?.SetOrders(cargoState.Orders);
+ _menu?.SetOrders(EntMan.System<SpriteSystem>(), _protoManager, cargoState.Orders);
}
}
[GenerateTypedNameReferences]
public sealed partial class CargoShuttleMenu : FancyWindow
{
- private readonly IPrototypeManager _protoManager;
- private readonly SpriteSystem _spriteSystem;
-
- public CargoShuttleMenu(IPrototypeManager protoManager, SpriteSystem spriteSystem)
+ public CargoShuttleMenu()
{
RobustXamlLoader.Load(this);
- _protoManager = protoManager;
- _spriteSystem = spriteSystem;
Title = Loc.GetString("cargo-shuttle-console-menu-title");
}
ShuttleNameLabel.Text = name;
}
- public void SetOrders(List<CargoOrderData> orders)
+ public void SetOrders(SpriteSystem sprites, IPrototypeManager protoManager, List<CargoOrderData> orders)
{
Orders.DisposeAllChildren();
foreach (var order in orders)
{
- var product = _protoManager.Index<EntityPrototype>(order.ProductId);
+ var product = protoManager.Index<EntityPrototype>(order.ProductId);
var productName = product.Name;
var row = new CargoOrderRow
{
Order = order,
- Icon = { Texture = _spriteSystem.Frame0(product) },
+ Icon = { Texture = sprites.Frame0(product) },
ProductName =
{
Text = Loc.GetString(
using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Chemistry.UI
{
base.Open();
// Setup window layout/elements
- _window = new ChemMasterWindow
- {
- Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
- };
-
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<ChemMasterWindow>();
+ _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
// Setup static button actions.
_window.InputEjectButton.OnPressed += _ => SendMessage(
_window?.UpdateState(castState); // Update window state
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _window?.Dispose();
- }
- }
}
}
using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Chemistry.UI
{
[ViewVariables]
private ReagentDispenserWindow? _window;
- [ViewVariables]
- private ReagentDispenserBoundUserInterfaceState? _lastState;
-
public ReagentDispenserBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
base.Open();
// Setup window layout/elements
- _window = new()
- {
- Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
- HelpGuidebookIds = EntMan.GetComponent<GuideHelpComponent>(Owner).Guides
- };
-
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<ReagentDispenserWindow>();
+ _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
+ _window.HelpGuidebookIds = EntMan.GetComponent<GuideHelpComponent>(Owner).Guides;
// Setup static button actions.
_window.EjectButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(SharedReagentDispenser.OutputSlotName));
base.UpdateState(state);
var castState = (ReagentDispenserBoundUserInterfaceState) state;
- _lastState = castState;
-
_window?.UpdateState(castState); //Update window state
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _window?.Dispose();
- }
- }
}
}
using Content.Shared.FixedPoint;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Chemistry.UI
{
protected override void Open()
{
base.Open();
- _window = new TransferAmountWindow();
+ _window = this.CreateWindow<TransferAmountWindow>();
_window.ApplyButton.OnPressed += _ =>
{
_window.Close();
}
};
- _window.OnClose += Close;
- _window.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- _window?.Dispose();
}
}
}
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Content.Shared.Cloning.CloningConsole;
+using Robust.Client.UserInterface;
namespace Content.Client.CloningConsole.UI
{
protected override void Open()
{
base.Open();
- _window = new CloningConsoleWindow
- {
- Title = Loc.GetString("cloning-console-window-title")
- };
- _window.OnClose += Close;
+
+ _window = this.CreateWindow<CloningConsoleWindow>();
+ _window.Title = Loc.GetString("cloning-console-window-title");
+
_window.CloneButton.OnPressed += _ => SendMessage(new UiButtonPressedMessage(UiButton.Clone));
- _window.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
_window?.Populate((CloningConsoleBoundUserInterfaceState) state);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- if (_window != null)
- {
- _window.OnClose -= Close;
- _window.CloneButton.OnPressed -= _ => SendMessage(new UiButtonPressedMessage(UiButton.Clone));
- }
- _window?.Dispose();
- }
}
}
using Content.Shared.Clothing.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Clothing.UI;
{
base.Open();
- _menu = new ChameleonMenu();
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<ChameleonMenu>();
_menu.OnIdSelected += OnIdSelected;
- _menu.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
SendMessage(new ChameleonPrototypeSelectedMessage(selectedId));
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _menu?.Close();
- _menu = null;
- }
- }
}
using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Communications;
+using Robust.Client.UserInterface;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
{
public sealed class CommunicationsConsoleBoundUserInterface : BoundUserInterface
{
- [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[ViewVariables]
private CommunicationsConsoleMenu? _menu;
- [ViewVariables]
- public bool CanAnnounce { get; private set; }
- [ViewVariables]
- public bool CanBroadcast { get; private set; }
-
- [ViewVariables]
- public bool CanCall { get; private set; }
-
- [ViewVariables]
- public bool CountdownStarted { get; private set; }
-
- [ViewVariables]
- public bool AlertLevelSelectable { get; private set; }
-
- [ViewVariables]
- public string CurrentLevel { get; private set; } = default!;
-
- [ViewVariables]
- private TimeSpan? _expectedCountdownTime;
-
- public int Countdown => _expectedCountdownTime == null ? 0 : Math.Max((int) _expectedCountdownTime.Value.Subtract(_gameTiming.CurTime).TotalSeconds, 0);
-
public CommunicationsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
{
base.Open();
- _menu = new CommunicationsConsoleMenu(this);
- _menu.OnClose += Close;
- _menu.OpenCentered();
+ _menu = this.CreateWindow<CommunicationsConsoleMenu>();
+ _menu.OnAnnounce += AnnounceButtonPressed;
+ _menu.OnBroadcast += BroadcastButtonPressed;
+ _menu.OnAlertLevel += AlertLevelSelected;
+ _menu.OnEmergencyLevel += EmergencyShuttleButtonPressed;
}
public void AlertLevelSelected(string level)
{
- if (AlertLevelSelectable)
+ if (_menu!.AlertLevelSelectable)
{
- CurrentLevel = level;
+ _menu.CurrentLevel = level;
SendMessage(new CommunicationsConsoleSelectAlertLevelMessage(level));
}
}
public void EmergencyShuttleButtonPressed()
{
- if (CountdownStarted)
+ if (_menu!.CountdownStarted)
RecallShuttle();
else
CallShuttle();
if (state is not CommunicationsConsoleInterfaceState commsState)
return;
- CanAnnounce = commsState.CanAnnounce;
- CanBroadcast = commsState.CanBroadcast;
- CanCall = commsState.CanCall;
- _expectedCountdownTime = commsState.ExpectedCountdownEnd;
- CountdownStarted = commsState.CountdownStarted;
- AlertLevelSelectable = commsState.AlertLevels != null && !float.IsNaN(commsState.CurrentAlertDelay) && commsState.CurrentAlertDelay <= 0;
- CurrentLevel = commsState.CurrentAlert;
-
if (_menu != null)
{
+ _menu.CanAnnounce = commsState.CanAnnounce;
+ _menu.CanBroadcast = commsState.CanBroadcast;
+ _menu.CanCall = commsState.CanCall;
+ _menu.CountdownStarted = commsState.CountdownStarted;
+ _menu.AlertLevelSelectable = commsState.AlertLevels != null && !float.IsNaN(commsState.CurrentAlertDelay) && commsState.CurrentAlertDelay <= 0;
+ _menu.CurrentLevel = commsState.CurrentAlert;
+ _menu.CountdownEnd = commsState.ExpectedCountdownEnd;
+
_menu.UpdateCountdown();
- _menu.UpdateAlertLevels(commsState.AlertLevels, CurrentLevel);
- _menu.AlertLevelButton.Disabled = !AlertLevelSelectable;
- _menu.EmergencyShuttleButton.Disabled = !CanCall;
- _menu.AnnounceButton.Disabled = !CanAnnounce;
- _menu.BroadcastButton.Disabled = !CanBroadcast;
+ _menu.UpdateAlertLevels(commsState.AlertLevels, _menu.CurrentLevel);
+ _menu.AlertLevelButton.Disabled = !_menu.AlertLevelSelectable;
+ _menu.EmergencyShuttleButton.Disabled = !_menu.CanCall;
+ _menu.AnnounceButton.Disabled = !_menu.CanAnnounce;
+ _menu.BroadcastButton.Disabled = !_menu.CanBroadcast;
}
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
-
- _menu?.Dispose();
- }
}
}
-using Content.Client.UserInterface.Controls;
-using System.Threading;
+using System.Globalization;
+using Content.Client.UserInterface.Controls;
using Content.Shared.CCVar;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
+using Robust.Shared.Timing;
using Robust.Shared.Utility;
-using Timer = Robust.Shared.Timing.Timer;
namespace Content.Client.Communications.UI
{
[GenerateTypedNameReferences]
public sealed partial class CommunicationsConsoleMenu : FancyWindow
{
- private CommunicationsConsoleBoundUserInterface Owner { get; set; }
- private readonly CancellationTokenSource _timerCancelTokenSource = new();
-
[Dependency] private readonly IConfigurationManager _cfg = default!;
-
- public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
+ [Dependency] private readonly IGameTiming _timing = default!;
+ [Dependency] private readonly ILocalizationManager _loc = default!;
+
+ public bool CanAnnounce;
+ public bool CanBroadcast;
+ public bool CanCall;
+ public bool AlertLevelSelectable;
+ public bool CountdownStarted;
+ public string CurrentLevel = string.Empty;
+ public TimeSpan? CountdownEnd;
+
+ public event Action? OnEmergencyLevel;
+ public event Action<string>? OnAlertLevel;
+ public event Action<string>? OnAnnounce;
+ public event Action<string>? OnBroadcast;
+
+ public CommunicationsConsoleMenu()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
- Owner = owner;
-
- var loc = IoCManager.Resolve<ILocalizationManager>();
- MessageInput.Placeholder = new Rope.Leaf(loc.GetString("comms-console-menu-announcement-placeholder"));
+ MessageInput.Placeholder = new Rope.Leaf(_loc.GetString("comms-console-menu-announcement-placeholder"));
var maxAnnounceLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
MessageInput.OnTextChanged += (args) =>
}
else
{
- AnnounceButton.Disabled = !owner.CanAnnounce;
+ AnnounceButton.Disabled = !CanAnnounce;
AnnounceButton.ToolTip = null;
}
};
- AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(Rope.Collapse(MessageInput.TextRope));
- AnnounceButton.Disabled = !owner.CanAnnounce;
+ AnnounceButton.OnPressed += _ => OnAnnounce?.Invoke(Rope.Collapse(MessageInput.TextRope));
+ AnnounceButton.Disabled = !CanAnnounce;
- BroadcastButton.OnPressed += (_) => Owner.BroadcastButtonPressed(Rope.Collapse(MessageInput.TextRope));
- BroadcastButton.Disabled = !owner.CanBroadcast;
+ BroadcastButton.OnPressed += _ => OnBroadcast?.Invoke(Rope.Collapse(MessageInput.TextRope));
+ BroadcastButton.Disabled = !CanBroadcast;
AlertLevelButton.OnItemSelected += args =>
{
var metadata = AlertLevelButton.GetItemMetadata(args.Id);
if (metadata != null && metadata is string cast)
{
- Owner.AlertLevelSelected(cast);
+ OnAlertLevel?.Invoke(cast);
}
};
- AlertLevelButton.Disabled = !owner.AlertLevelSelectable;
- EmergencyShuttleButton.OnPressed += (_) => Owner.EmergencyShuttleButtonPressed();
- EmergencyShuttleButton.Disabled = !owner.CanCall;
+ AlertLevelButton.Disabled = !AlertLevelSelectable;
+
+ EmergencyShuttleButton.OnPressed += _ => OnEmergencyLevel?.Invoke();
+ EmergencyShuttleButton.Disabled = !CanCall;
+ }
+
+ protected override void FrameUpdate(FrameEventArgs args)
+ {
+ base.FrameUpdate(args);
UpdateCountdown();
- Timer.SpawnRepeating(1000, UpdateCountdown, _timerCancelTokenSource.Token);
}
// The current alert could make levels unselectable, so we need to ensure that the UI reacts properly.
public void UpdateCountdown()
{
- if (!Owner.CountdownStarted)
+ if (!CountdownStarted)
{
- CountdownLabel.SetMessage("");
+ CountdownLabel.SetMessage(string.Empty);
EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-call-shuttle");
return;
}
+ var diff = MathHelper.Max((CountdownEnd - _timing.CurTime) ?? TimeSpan.Zero, TimeSpan.Zero);
+
EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-recall-shuttle");
var infoText = Loc.GetString($"comms-console-menu-time-remaining",
- ("time", Owner.Countdown.ToString()));
+ ("time", diff.TotalSeconds.ToString(CultureInfo.CurrentCulture)));
CountdownLabel.SetMessage(infoText);
}
-
- public override void Close()
- {
- base.Close();
-
- _timerCancelTokenSource.Cancel();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- _timerCancelTokenSource.Cancel();
- }
}
}
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;
namespace Content.Client.Computer
{
base.Open();
- _window = (TWindow) _dynamicTypeFactory.CreateInstance(typeof(TWindow));
+ _window = this.CreateWindow<TWindow>();
_window.SetupComputerWindow(this);
- _window.OnClose += Close;
- _window.OpenCentered();
}
// Alas, this constructor has to be copied to the subclass. :(
_window.UpdateState((TState) state);
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _window?.Dispose();
- }
- }
-
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{
_window?.ReceiveMessage(message);
using System.Text.RegularExpressions;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using static Content.Shared.Configurable.ConfigurationComponent;
namespace Content.Client.Configurable.UI
[ViewVariables]
private ConfigurationMenu? _menu;
- [ViewVariables]
- public Regex? Validation { get; internal set; }
-
public ConfigurationBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
- _menu = new ConfigurationMenu(this);
-
- _menu.OnClose += Close;
- _menu.OpenCentered();
+ _menu = this.CreateWindow<ConfigurationMenu>();
+ _menu.OnConfiguration += SendConfiguration;
}
protected override void UpdateState(BoundUserInterfaceState state)
base.UpdateState(state);
if (state is not ConfigurationBoundUserInterfaceState configurationState)
- {
return;
- }
_menu?.Populate(configurationState);
}
{
base.ReceiveMessage(message);
+ if (_menu == null)
+ return;
+
if (message is ValidationUpdateMessage msg)
{
- Validation = new Regex(msg.ValidationString, RegexOptions.Compiled);
+ _menu.Validation = new Regex(msg.ValidationString, RegexOptions.Compiled);
}
}
{
SendMessage(new ConfigurationUpdatedMessage(config));
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing && _menu != null)
- {
- _menu.OnClose -= Close;
- _menu.Close();
- }
- }
}
}
using System.Collections.Generic;
using System.Numerics;
+using System.Text.RegularExpressions;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
{
public sealed class ConfigurationMenu : DefaultWindow
{
- public ConfigurationBoundUserInterface Owner { get; }
-
private readonly BoxContainer _column;
private readonly BoxContainer _row;
private readonly List<(string name, LineEdit input)> _inputs;
- public ConfigurationMenu(ConfigurationBoundUserInterface owner)
+ [ViewVariables]
+ public Regex? Validation { get; internal set; }
+
+ public event Action<Dictionary<string, string>>? OnConfiguration;
+
+ public ConfigurationMenu()
{
MinSize = SetSize = new Vector2(300, 250);
- Owner = owner;
_inputs = new List<(string name, LineEdit input)>();
Title = Loc.GetString("configuration-menu-device-title");
- BoxContainer baseContainer = new BoxContainer
+ var baseContainer = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
VerticalExpand = true,
private void OnConfirm(ButtonEventArgs args)
{
var config = GenerateDictionary(_inputs, "Text");
-
- Owner.SendConfiguration(config);
+ OnConfiguration?.Invoke(config);
Close();
}
private bool Validate(string value)
{
- return Owner.Validation == null || Owner.Validation.IsMatch(value);
+ return Validation?.IsMatch(value) != false;
}
private Dictionary<string, string> GenerateDictionary(IEnumerable<(string name, LineEdit input)> inputs, string propertyName)
using Content.Shared.Construction.Components;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
namespace Content.Client.Construction.UI
{
{
base.Open();
- _menu = new FlatpackCreatorMenu(Owner);
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<FlatpackCreatorMenu>();
+ _menu.SetEntity(Owner);
_menu.PackButtonPressed += () =>
{
_menu.OpenCentered();
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _menu?.Dispose();
- }
}
}
private readonly FlatpackSystem _flatpack;
private readonly MaterialStorageSystem _materialStorage;
- private readonly EntityUid _owner;
+ private EntityUid _owner;
[ValidatePrototypeId<EntityPrototype>]
public const string NoBoardEffectId = "FlatpackerNoBoardEffect";
public event Action? PackButtonPressed;
- public FlatpackCreatorMenu(EntityUid uid)
+ public FlatpackCreatorMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_flatpack = _entityManager.System<FlatpackSystem>();
_materialStorage = _entityManager.System<MaterialStorageSystem>();
- _owner = uid;
-
PackButton.OnPressed += _ => PackButtonPressed?.Invoke();
- MaterialStorageControl.SetOwner(uid);
InsertLabel.SetMarkup(Loc.GetString("flatpacker-ui-insert-board"));
}
+ public void SetEntity(EntityUid uid)
+ {
+ _owner = uid;
+ MaterialStorageControl.SetOwner(uid);
+ }
+
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
using Content.Shared.Crayon;
using Content.Shared.Decals;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Crayon.UI
{
public sealed class CrayonBoundUserInterface : BoundUserInterface
{
+ [Dependency] private readonly IPrototypeManager _protoManager = default!;
+
[ViewVariables]
private CrayonWindow? _menu;
protected override void Open()
{
base.Open();
- _menu = new CrayonWindow(this);
-
- _menu.OnClose += Close;
- var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
- var crayonDecals = prototypeManager.EnumeratePrototypes<DecalPrototype>().Where(x => x.Tags.Contains("crayon"));
- _menu.Populate(crayonDecals);
+ _menu = this.CreateWindow<CrayonWindow>();
+ _menu.OnColorSelected += SelectColor;
+ _menu.OnSelected += Select;
+ PopulateCrayons();
_menu.OpenCenteredLeft();
}
+ private void PopulateCrayons()
+ {
+ var crayonDecals = _protoManager.EnumeratePrototypes<DecalPrototype>().Where(x => x.Tags.Contains("crayon"));
+ _menu?.Populate(crayonDecals);
+ }
+
+ public override void OnProtoReload(PrototypesReloadedEventArgs args)
+ {
+ base.OnProtoReload(args);
+
+ if (!args.WasModified<DecalPrototype>())
+ return;
+
+ PopulateCrayons();
+ }
+
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
{
SendMessage(new CrayonColorMessage(color));
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _menu?.Close();
- _menu = null;
- }
- }
}
}
[GenerateTypedNameReferences]
public sealed partial class CrayonWindow : DefaultWindow
{
- public CrayonBoundUserInterface Owner { get; }
-
private Dictionary<string, Texture>? _decals;
private string? _selected;
private Color _color;
- public CrayonWindow(CrayonBoundUserInterface owner)
+ public event Action<Color>? OnColorSelected;
+ public event Action<string>? OnSelected;
+
+ public CrayonWindow()
{
RobustXamlLoader.Load(this);
- Owner = owner;
-
Search.OnTextChanged += _ => RefreshList();
ColorSelector.OnColorChanged += SelectColor;
}
{
_color = color;
- Owner.SelectColor(color);
-
+ OnColorSelected?.Invoke(color);
RefreshList();
}
private void RefreshList()
{
// Clear
- Grid.RemoveAllChildren();
- if (_decals == null) return;
+ Grid.DisposeAllChildren();
+ if (_decals == null)
+ return;
var filter = Search.Text;
foreach (var (decal, tex) in _decals)
{
if (obj.Button.Name == null) return;
- Owner.Select(obj.Button.Name);
_selected = obj.Button.Name;
RefreshList();
}
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent;
namespace Content.Client.Disposal.UI
{
base.Open();
- _window = new DisposalRouterWindow();
-
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<DisposalRouterWindow>();
_window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text);
_window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text);
-
}
private void ButtonPressed(UiAction action, string tag)
{
SendMessage(new UiActionMessage(action, tag));
- _window?.Close();
+ Close();
}
protected override void UpdateState(BoundUserInterfaceState state)
_window?.UpdateState(cast);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _window?.Dispose();
- }
- }
-
-
}
-
}
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using static Content.Shared.Disposal.Components.SharedDisposalTaggerComponent;
namespace Content.Client.Disposal.UI
{
base.Open();
- _window = new DisposalTaggerWindow();
-
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<DisposalTaggerWindow>();
_window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text);
_window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text);
-
}
private void ButtonPressed(UiAction action, string tag)
{
+ // TODO: This looks copy-pasted with the other mailing stuff...
SendMessage(new UiActionMessage(action, tag));
- _window?.Close();
+ Close();
}
protected override void UpdateState(BoundUserInterfaceState state)
_window?.UpdateState(cast);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _window?.Dispose();
- }
- }
-
-
}
-
}
using Content.Shared.Access;
using Content.Shared.Doors.Electronics;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Doors.Electronics;
protected override void Open()
{
base.Open();
+ _window = this.CreateWindow<DoorElectronicsConfigurationMenu>();
+ _window.OnAccessChanged += UpdateConfiguration;
+ Reset();
+ }
+
+ public override void OnProtoReload(PrototypesReloadedEventArgs args)
+ {
+ base.OnProtoReload(args);
+
+ if (!args.WasModified<AccessLevelPrototype>())
+ return;
+
+ Reset();
+ }
+
+ private void Reset()
+ {
List<ProtoId<AccessLevelPrototype>> accessLevels = new();
foreach (var accessLevel in _prototypeManager.EnumeratePrototypes<AccessLevelPrototype>())
}
accessLevels.Sort();
-
- _window = new DoorElectronicsConfigurationMenu(this, accessLevels, _prototypeManager);
- _window.OnClose += Close;
- _window.OpenCentered();
+ _window?.Reset(_prototypeManager, accessLevels);
}
protected override void UpdateState(BoundUserInterfaceState state)
_window?.UpdateState(castState);
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
-
- _window?.Dispose();
- }
-
public void UpdateConfiguration(List<ProtoId<AccessLevelPrototype>> newAccessList)
{
SendMessage(new DoorElectronicsUpdateConfigurationMessage(newAccessList));
[GenerateTypedNameReferences]
public sealed partial class DoorElectronicsConfigurationMenu : FancyWindow
{
- private readonly DoorElectronicsBoundUserInterface _owner;
- private AccessLevelControl _buttonsList = new();
+ private readonly AccessLevelControl _buttonsList = new();
- public DoorElectronicsConfigurationMenu(DoorElectronicsBoundUserInterface ui, List<ProtoId<AccessLevelPrototype>> accessLevels, IPrototypeManager prototypeManager)
+ public event Action<List<ProtoId<AccessLevelPrototype>>>? OnAccessChanged;
+
+ public DoorElectronicsConfigurationMenu()
{
RobustXamlLoader.Load(this);
-
- _owner = ui;
-
- _buttonsList.Populate(accessLevels, prototypeManager);
AccessLevelControlContainer.AddChild(_buttonsList);
+ }
+
+ public void Reset(IPrototypeManager protoManager, List<ProtoId<AccessLevelPrototype>> accessLevels)
+ {
+ _buttonsList.Populate(accessLevels, protoManager);
- foreach (var (id, button) in _buttonsList.ButtonsList)
+ foreach (var button in _buttonsList.ButtonsList.Values)
{
- button.OnPressed += _ => _owner.UpdateConfiguration(
- _buttonsList.ButtonsList.Where(x => x.Value.Pressed).Select(x => x.Key).ToList());
+ button.OnPressed += _ => OnAccessChanged?.Invoke(_buttonsList.ButtonsList.Where(x => x.Value.Pressed).Select(x => x.Key).ToList());
}
}
{
base.Open();
- _window = new FaxWindow();
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<FaxWindow>();
_window.FileButtonPressed += OnFileButtonPressed;
_window.CopyButtonPressed += OnCopyButtonPressed;
_window.SendButtonPressed += OnSendButtonPressed;
_window.UpdateState(cast);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (disposing)
- _window?.Dispose();
- }
}
using Robust.Client.GameObjects;
using Robust.Shared.Timing;
using Content.Shared.Forensics;
+using Robust.Client.UserInterface;
namespace Content.Client.Forensics
{
protected override void Open()
{
base.Open();
- _window = new ForensicScannerMenu();
- _window.OnClose += Close;
+ _window = this.CreateWindow<ForensicScannerMenu>();
_window.Print.OnPressed += _ => Print();
_window.Clear.OnPressed += _ => Clear();
- _window.OpenCentered();
}
private void Print()
_printCooldown = cast.PrintCooldown;
+ // TODO: Fix this
if (cast.PrintReadyAt > _gameTiming.CurTime)
Timer.Spawn(cast.PrintReadyAt - _gameTiming.CurTime, () =>
{
_window.UpdateState(cast);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _window?.Dispose();
- }
}
}
using Content.Shared.Gateway;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Gateway.UI;
{
base.Open();
- _window = new GatewayWindow(EntMan.GetNetEntity(Owner));
+ _window = this.CreateWindow<GatewayWindow>();
+ _window.SetEntity(EntMan.GetNetEntity(Owner));
_window.OpenPortal += destination =>
{
SendMessage(new GatewayOpenPortalMessage(destination));
};
- _window.OnClose += Close;
- _window?.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (disposing)
- {
- _window?.Dispose();
- _window = null;
- }
}
protected override void UpdateState(BoundUserInterfaceState state)
public event Action<NetEntity>? OpenPortal;
private List<GatewayDestinationData> _destinations = new();
- public readonly NetEntity Owner;
+ public NetEntity Owner;
private NetEntity? _current;
private TimeSpan _nextReady;
/// </summary>
private bool _isCooldownPending = true;
- public GatewayWindow(NetEntity netEntity)
+ public GatewayWindow()
{
RobustXamlLoader.Load(this);
var dependencies = IoCManager.Instance!;
_timing = dependencies.Resolve<IGameTiming>();
- Owner = netEntity;
NextUnlockBar.ForegroundStyleBoxOverride = new StyleBoxFlat(Color.FromHex("#C74EBD"));
}
+ public void SetEntity(NetEntity entity)
+ {
+
+ }
+
public void UpdateState(GatewayBoundUserInterfaceState state)
{
_destinations = state.Destinations;
using Content.Shared.Gravity;
using JetBrains.Annotations;
-using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Gravity.UI
{
{
base.Open();
- _window = new GravityGeneratorWindow(this);
-
- /*
- _window.Switch.OnPressed += _ =>
- {
- SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(!IsOn));
- };
- */
-
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<GravityGeneratorWindow>();
+ _window.SetEntity(Owner);
}
protected override void UpdateState(BoundUserInterfaceState state)
_window?.UpdateState(castState);
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
-
- _window?.Dispose();
- }
-
public void SetPowerSwitch(bool on)
{
SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(on));
{
private readonly ButtonGroup _buttonGroup = new();
- private readonly GravityGeneratorBoundUserInterface _owner;
+ public event Action<bool>? OnPowerSwitch;
- public GravityGeneratorWindow(GravityGeneratorBoundUserInterface owner)
+ public GravityGeneratorWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
- _owner = owner;
-
OnButton.Group = _buttonGroup;
OffButton.Group = _buttonGroup;
- OnButton.OnPressed += _ => _owner.SetPowerSwitch(true);
- OffButton.OnPressed += _ => _owner.SetPowerSwitch(false);
+ OnButton.OnPressed += _ => OnPowerSwitch?.Invoke(true);
+ OffButton.OnPressed += _ => OnPowerSwitch?.Invoke(false);
+ }
- EntityView.SetEntity(owner.Owner);
+ public void SetEntity(EntityUid uid)
+ {
+ EntityView.SetEntity(uid);
}
public void UpdateState(SharedGravityGeneratorComponent.GeneratorState state)
using Content.Shared.MedicalScanner;
using JetBrains.Annotations;
-using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.HealthAnalyzer.UI
{
protected override void Open()
{
base.Open();
- _window = new HealthAnalyzerWindow
- {
- Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
- };
- _window.OnClose += Close;
- _window.OpenCentered();
+ _window = this.CreateWindow<HealthAnalyzerWindow>();
+
+ _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message)
_window.Populate(cast);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- if (_window != null)
- _window.OnClose -= Close;
-
- _window?.Dispose();
- }
}
}
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
+using Robust.Client.UserInterface;
namespace Content.Client.Humanoid;
{
base.Open();
- _window = new();
- _window.OnClose += Close;
+ _window = this.CreateWindow<HumanoidMarkingModifierWindow>();
_window.OnMarkingAdded += SendMarkingSet;
_window.OnMarkingRemoved += SendMarkingSet;
_window.OnMarkingColorChange += SendMarkingSetNoResend;
{
private readonly InstrumentBoundUserInterface _owner;
- public BandMenu(InstrumentBoundUserInterface owner) : base()
+ public EntityUid? Master;
+
+ public BandMenu(InstrumentBoundUserInterface owner)
{
RobustXamlLoader.Load(this);
{
var uid = entManager.GetEntity(nent);
var item = BandList.AddItem(name, null, true, uid);
- item.Selected = _owner.Instrument?.Master == uid;
+ item.Selected = Master == uid;
}
}
}
}
}
- public void Populate()
+ public void Populate(InstrumentComponent? instrument)
{
ChannelList.Clear();
var item = ChannelList.AddItem(_owner.Loc.GetString("instrument-component-channel-name",
("number", i)), null, true, i);
- item.Selected = !_owner.Instrument?.FilteredChannels[i] ?? false;
+
+ item.Selected = !instrument?.FilteredChannels[i] ?? false;
}
}
}
[ViewVariables] private BandMenu? _bandMenu;
[ViewVariables] private ChannelsMenu? _channelsMenu;
- [ViewVariables] public InstrumentComponent? Instrument { get; private set; }
-
public InstrumentBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
IoCManager.InjectDependencies(this);
protected override void Open()
{
- if (!EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument))
- return;
+ _instrumentMenu = this.CreateWindow<InstrumentMenu>();
+ _instrumentMenu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
- Instrument = instrument;
- _instrumentMenu = new InstrumentMenu(this);
- _instrumentMenu.OnClose += Close;
+ _instrumentMenu.OnOpenBand += OpenBandMenu;
+ _instrumentMenu.OnOpenChannels += OpenChannelsMenu;
+ _instrumentMenu.OnCloseChannels += CloseChannelsMenu;
+ _instrumentMenu.OnCloseBands += CloseBandMenu;
- _instrumentMenu.OpenCentered();
+ _instrumentMenu.SetMIDI(MidiManager.IsAvailable);
+
+ if (EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument))
+ {
+ _instrumentMenu.SetInstrument((Owner, instrument));
+ }
}
protected override void Dispose(bool disposing)
base.Dispose(disposing);
if (!disposing)
return;
- _instrumentMenu?.Dispose();
+
+ if (EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument))
+ {
+ _instrumentMenu?.RemoveInstrument(instrument);
+ }
+
_bandMenu?.Dispose();
_channelsMenu?.Dispose();
}
{
_bandMenu ??= new BandMenu(this);
+ if (EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument))
+ {
+ _bandMenu.Master = instrument.Master;
+ }
+
// Refresh cache...
RefreshBands();
public void OpenChannelsMenu()
{
_channelsMenu ??= new ChannelsMenu(this);
- _channelsMenu.Populate();
+ EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument);
+
+ _channelsMenu.Populate(instrument);
_channelsMenu.OpenCenteredRight();
}
using System.IO;
using System.Numerics;
using System.Threading.Tasks;
+using Content.Client.Interactable;
+using Content.Shared.ActionBlocker;
using Robust.Client.AutoGenerated;
+using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
[GenerateTypedNameReferences]
public sealed partial class InstrumentMenu : DefaultWindow
{
- private readonly InstrumentBoundUserInterface _owner;
+ [Dependency] private readonly IEntityManager _entManager = default!;
+ [Dependency] private readonly IFileDialogManager _dialogs = default!;
+ [Dependency] private readonly IPlayerManager _player = default!;
private bool _isMidiFileDialogueWindowOpen;
- public InstrumentMenu(InstrumentBoundUserInterface owner)
- {
- RobustXamlLoader.Load(this);
-
- _owner = owner;
+ public event Action? OnOpenBand;
+ public event Action? OnOpenChannels;
+ public event Action? OnCloseBands;
+ public event Action? OnCloseChannels;
- if (_owner.Instrument != null)
- {
- _owner.Instrument.OnMidiPlaybackEnded += InstrumentOnMidiPlaybackEnded;
- Title = _owner.Entities.GetComponent<MetaDataComponent>(_owner.Owner).EntityName;
- LoopButton.Disabled = !_owner.Instrument.IsMidiOpen;
- LoopButton.Pressed = _owner.Instrument.LoopMidi;
- ChannelsButton.Disabled = !_owner.Instrument.IsRendererAlive;
- StopButton.Disabled = !_owner.Instrument.IsMidiOpen;
- PlaybackSlider.MouseFilter = _owner.Instrument.IsMidiOpen ? MouseFilterMode.Pass : MouseFilterMode.Ignore;
- }
+ public EntityUid Entity;
- if (!_owner.MidiManager.IsAvailable)
- {
- UnavailableOverlay.Visible = true;
- // We return early as to not give the buttons behavior.
- return;
- }
+ public InstrumentMenu()
+ {
+ RobustXamlLoader.Load(this);
+ IoCManager.InjectDependencies(this);
InputButton.OnToggled += MidiInputButtonOnOnToggled;
BandButton.OnPressed += BandButtonOnPressed;
MinSize = SetSize = new Vector2(400, 150);
}
+ public void SetInstrument(Entity<InstrumentComponent> entity)
+ {
+ Entity = entity;
+ var component = entity.Comp;
+ component.OnMidiPlaybackEnded += InstrumentOnMidiPlaybackEnded;
+ LoopButton.Disabled = !component.IsMidiOpen;
+ LoopButton.Pressed = component.LoopMidi;
+ ChannelsButton.Disabled = !component.IsRendererAlive;
+ StopButton.Disabled = !component.IsMidiOpen;
+ PlaybackSlider.MouseFilter = component.IsMidiOpen ? MouseFilterMode.Pass : MouseFilterMode.Ignore;
+ }
+
+ public void RemoveInstrument(InstrumentComponent component)
+ {
+ component.OnMidiPlaybackEnded -= InstrumentOnMidiPlaybackEnded;
+ }
+
+ public void SetMIDI(bool available)
+ {
+ UnavailableOverlay.Visible = !available;
+ }
+
private void BandButtonOnPressed(ButtonEventArgs obj)
{
if (!PlayCheck())
return;
- _owner.OpenBandMenu();
+ OnOpenBand?.Invoke();
}
private void BandButtonOnToggled(ButtonToggledEventArgs obj)
if (obj.Pressed)
return;
- _owner.Instruments.SetMaster(_owner.Owner, null);
+ if (_entManager.TryGetComponent(Entity, out InstrumentComponent? instrument))
+ {
+ _entManager.System<InstrumentSystem>().SetMaster(Entity, instrument.Master);
+ }
}
private void ChannelsButtonOnPressed(ButtonEventArgs obj)
{
- _owner.OpenChannelsMenu();
+ OnOpenChannels?.Invoke();
}
private void InstrumentOnMidiPlaybackEnded()
public void MidiPlaybackSetButtonsDisabled(bool disabled)
{
- if(disabled)
- _owner.CloseChannelsMenu();
+ if (disabled)
+ {
+ OnCloseChannels?.Invoke();
+ }
LoopButton.Disabled = disabled;
StopButton.Disabled = disabled;
if (_isMidiFileDialogueWindowOpen)
return;
- _owner.CloseBandMenu();
+ OnCloseBands?.Invoke();
var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
// or focus the previously-opened window.
_isMidiFileDialogueWindowOpen = true;
- await using var file = await _owner.FileDialogManager.OpenFile(filters);
+ await using var file = await _dialogs.OpenFile(filters);
_isMidiFileDialogueWindowOpen = false;
await file.CopyToAsync(memStream);
- if (_owner.Instrument is not {} instrument
- || !_owner.Instruments.OpenMidi(_owner.Owner, memStream.GetBuffer().AsSpan(0, (int) memStream.Length), instrument))
+ if (!_entManager.TryGetComponent<InstrumentComponent>(Entity, out var instrument))
+ {
return;
+ }
+
+ if (!_entManager.System<InstrumentSystem>()
+ .OpenMidi(Entity,
+ memStream.GetBuffer().AsSpan(0, (int) memStream.Length),
+ instrument))
+ {
+ return;
+ }
MidiPlaybackSetButtonsDisabled(false);
if (InputButton.Pressed)
private void MidiInputButtonOnOnToggled(ButtonToggledEventArgs obj)
{
- _owner.CloseBandMenu();
+ OnCloseBands?.Invoke();
if (obj.Pressed)
{
return;
MidiStopButtonOnPressed(null);
- if(_owner.Instrument is {} instrument)
- _owner.Instruments.OpenInput(_owner.Owner, instrument);
+
+ if (_entManager.TryGetComponent(Entity, out InstrumentComponent? instrument))
+ _entManager.System<InstrumentSystem>().OpenInput(Entity, instrument);
}
- else if (_owner.Instrument is { } instrument)
+ else
{
- _owner.Instruments.CloseInput(_owner.Owner, false, instrument);
- _owner.CloseChannelsMenu();
+ _entManager.System<InstrumentSystem>().CloseInput(Entity, false);
+ OnCloseChannels?.Invoke();
}
}
private bool PlayCheck()
{
// TODO all of these checks should also be done server-side.
-
- var instrumentEnt = _owner.Owner;
- var instrument = _owner.Instrument;
-
- if (instrument == null)
+ if (!_entManager.TryGetComponent(Entity, out InstrumentComponent? instrument))
return false;
- var localEntity = _owner.PlayerManager.LocalEntity;
+ var localEntity = _player.LocalEntity;
// If we don't have a player or controlled entity, we return.
if (localEntity == null)
return false;
// By default, allow an instrument to play itself and skip all other checks
- if (localEntity == instrumentEnt)
+ if (localEntity == Entity)
return true;
- var container = _owner.Entities.System<SharedContainerSystem>();
+ var container = _entManager.System<SharedContainerSystem>();
// If we're a handheld instrument, we might be in a container. Get it just in case.
- container.TryGetContainingContainer(instrumentEnt, out var conMan);
+ container.TryGetContainingContainer(Entity, out var conMan);
// If the instrument is handheld and we're not holding it, we return.
- if ((instrument.Handheld && (conMan == null || conMan.Owner != localEntity)))
+ if (instrument.Handheld && (conMan == null || conMan.Owner != localEntity))
return false;
- if (!_owner.ActionBlocker.CanInteract(localEntity.Value, instrumentEnt))
+ if (!_entManager.System<ActionBlockerSystem>().CanInteract(localEntity.Value, Entity))
return false;
// We check that we're in range unobstructed just in case.
- return _owner.Interactions.InRangeUnobstructed(localEntity.Value, instrumentEnt);
+ return _entManager.System<InteractionSystem>().InRangeUnobstructed(localEntity.Value, Entity);
}
private void MidiStopButtonOnPressed(ButtonEventArgs? obj)
{
MidiPlaybackSetButtonsDisabled(true);
- if (_owner.Instrument is not {} instrument)
- return;
-
- _owner.Instruments.CloseMidi(_owner.Owner, false, instrument);
- _owner.CloseChannelsMenu();
+ _entManager.System<InstrumentSystem>().CloseMidi(Entity, false);
+ OnCloseChannels?.Invoke();
}
private void MidiLoopButtonOnOnToggled(ButtonToggledEventArgs obj)
{
- if (_owner.Instrument == null)
- return;
+ var instrument = _entManager.System<InstrumentSystem>();
+
+ if (_entManager.TryGetComponent(Entity, out InstrumentComponent? instrumentComp))
+ {
+ instrumentComp.LoopMidi = obj.Pressed;
+ }
- _owner.Instrument.LoopMidi = obj.Pressed;
- _owner.Instruments.UpdateRenderer(_owner.Owner, _owner.Instrument);
+ instrument.UpdateRenderer(Entity);
}
private void PlaybackSliderSeek(Range _)
{
// Do not seek while still grabbing.
- if (PlaybackSlider.Grabbed || _owner.Instrument is not {} instrument)
+ if (PlaybackSlider.Grabbed)
return;
- _owner.Instruments.SetPlayerTick(_owner.Owner, (int)Math.Ceiling(PlaybackSlider.Value), instrument);
+ _entManager.System<InstrumentSystem>().SetPlayerTick(Entity, (int)Math.Ceiling(PlaybackSlider.Value));
}
private void PlaybackSliderKeyUp(GUIBoundKeyEventArgs args)
{
- if (args.Function != EngineKeyFunctions.UIClick || _owner.Instrument is not {} instrument)
+ if (args.Function != EngineKeyFunctions.UIClick)
return;
- _owner.Instruments.SetPlayerTick(_owner.Owner, (int)Math.Ceiling(PlaybackSlider.Value), instrument);
- }
-
- public override void Close()
- {
- base.Close();
- _owner.CloseBandMenu();
- _owner.CloseChannelsMenu();
+ _entManager.System<InstrumentSystem>().SetPlayerTick(Entity, (int)Math.Ceiling(PlaybackSlider.Value));
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
- if (_owner.Instrument == null)
+ if (!_entManager.TryGetComponent(Entity, out InstrumentComponent? instrument))
return;
- var hasMaster = _owner.Instrument.Master != null;
+ var hasMaster = instrument.Master != null;
BandButton.ToggleMode = hasMaster;
BandButton.Pressed = hasMaster;
- BandButton.Disabled = _owner.Instrument.IsMidiOpen || _owner.Instrument.IsInputOpen;
- ChannelsButton.Disabled = !_owner.Instrument.IsRendererAlive;
+ BandButton.Disabled = instrument.IsMidiOpen || instrument.IsInputOpen;
+ ChannelsButton.Disabled = !instrument.IsRendererAlive;
- if (!_owner.Instrument.IsMidiOpen)
+ if (!instrument.IsMidiOpen)
{
PlaybackSlider.MaxValue = 1;
PlaybackSlider.SetValueWithoutEvent(0);
if (PlaybackSlider.Grabbed)
return;
- PlaybackSlider.MaxValue = _owner.Instrument.PlayerTotalTick;
- PlaybackSlider.SetValueWithoutEvent(_owner.Instrument.PlayerTick);
+ PlaybackSlider.MaxValue = instrument.PlayerTotalTick;
+ PlaybackSlider.SetValueWithoutEvent(instrument.PlayerTick);
}
}
}
public const string HiddenPocketEntityId = "StrippingHiddenEntity";
[ViewVariables]
- private readonly StrippingMenu? _strippingMenu;
+ private StrippingMenu? _strippingMenu;
[ViewVariables]
private readonly EntityUid _virtualHiddenEntity;
_examine = EntMan.System<ExamineSystem>();
_inv = EntMan.System<InventorySystem>();
_cuffable = EntMan.System<SharedCuffableSystem>();
-
- // TODO update name when identity changes
- var title = Loc.GetString("strippable-bound-user-interface-stripping-menu-title", ("ownerName", Identity.Name(Owner, EntMan)));
- _strippingMenu = new StrippingMenu(title, this);
- _strippingMenu.OnClose += Close;
-
- // TODO use global entity
- // BUIs are opened and closed while applying comp sates, so spawning entities here is probably not the best idea.
_virtualHiddenEntity = EntMan.SpawnEntity(HiddenPocketEntityId, MapCoordinates.Nullspace);
}
protected override void Open()
{
base.Open();
+
+ _strippingMenu = this.CreateWindow<StrippingMenu>();
+ _strippingMenu.OnDirty += UpdateMenu;
+ _strippingMenu.Title = Loc.GetString("strippable-bound-user-interface-stripping-menu-title", ("ownerName", Identity.Name(Owner, EntMan)));
+
_strippingMenu?.OpenCenteredLeft();
}
protected override void Dispose(bool disposing)
{
- base.Dispose(disposing);
-
- EntMan.DeleteEntity(_virtualHiddenEntity);
-
if (!disposing)
return;
- _strippingMenu?.Dispose();
+ if (_strippingMenu != null)
+ _strippingMenu.OnDirty -= UpdateMenu;
+
+ EntMan.DeleteEntity(_virtualHiddenEntity);
+ base.Dispose(disposing);
}
public void DirtyMenu()
[GenerateTypedNameReferences]
public sealed partial class GrinderMenu : FancyWindow
{
- private readonly IEntityManager _entityManager;
- private readonly IPrototypeManager _prototypeManager;
- private readonly ReagentGrinderBoundUserInterface _owner;
+ [Dependency] private readonly IEntityManager _entityManager = default!;
+ [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly Dictionary<int, EntityUid> _chamberVisualContents = new();
- public GrinderMenu(ReagentGrinderBoundUserInterface owner, IEntityManager entityManager, IPrototypeManager prototypeManager)
+ public event Action? OnToggleAuto;
+ public event Action? OnGrind;
+ public event Action? OnJuice;
+ public event Action? OnEjectAll;
+ public event Action? OnEjectBeaker;
+ public event Action<EntityUid>? OnEjectChamber;
+
+ public GrinderMenu()
{
RobustXamlLoader.Load(this);
- _entityManager = entityManager;
- _prototypeManager = prototypeManager;
- _owner = owner;
- AutoModeButton.OnPressed += owner.ToggleAutoMode;
- GrindButton.OnPressed += owner.StartGrinding;
- JuiceButton.OnPressed += owner.StartJuicing;
- ChamberContentBox.EjectButton.OnPressed += owner.EjectAll;
- BeakerContentBox.EjectButton.OnPressed += owner.EjectBeaker;
+ IoCManager.InjectDependencies(this);
+ AutoModeButton.OnPressed += _ => OnToggleAuto?.Invoke();
+ GrindButton.OnPressed += _ => OnGrind?.Invoke();
+ JuiceButton.OnPressed += _ => OnJuice?.Invoke();
+ ChamberContentBox.EjectButton.OnPressed += _ => OnEjectAll?.Invoke();
+ BeakerContentBox.EjectButton.OnPressed += _ => OnEjectBeaker?.Invoke();
ChamberContentBox.BoxContents.OnItemSelected += OnChamberBoxContentsItemSelected;
BeakerContentBox.BoxContents.SelectMode = ItemList.ItemListSelectMode.None;
}
private void OnChamberBoxContentsItemSelected(ItemList.ItemListSelectedEventArgs args)
{
- _owner.EjectChamberContent(_chamberVisualContents[args.ItemIndex]);
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- _chamberVisualContents.Clear();
- GrindButton.OnPressed -= _owner.StartGrinding;
- JuiceButton.OnPressed -= _owner.StartJuicing;
- ChamberContentBox.EjectButton.OnPressed -= _owner.EjectAll;
- BeakerContentBox.EjectButton.OnPressed -= _owner.EjectBeaker;
- ChamberContentBox.BoxContents.OnItemSelected -= OnChamberBoxContentsItemSelected;
+ OnEjectChamber?.Invoke(_chamberVisualContents[args.ItemIndex]);
}
public void UpdateState(ReagentGrinderInterfaceState state)
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
+using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
[ViewVariables]
private readonly Dictionary<int, ReagentQuantity> _reagents = new();
- [Dependency] private readonly IGameTiming _gameTiming = default!;
-
- public MicrowaveUpdateUserInterfaceState currentState = default!;
-
- private IEntityManager _entManager;
public MicrowaveBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
- _entManager = IoCManager.Resolve<IEntityManager>();
- }
-
- public TimeSpan GetCurrentTime()
- {
- return _gameTiming.CurTime;
}
protected override void Open()
{
base.Open();
- _menu = new MicrowaveMenu(this);
- _menu.OpenCentered();
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<MicrowaveMenu>();
_menu.StartButton.OnPressed += _ => SendPredictedMessage(new MicrowaveStartCookMessage());
_menu.EjectButton.OnPressed += _ => SendPredictedMessage(new MicrowaveEjectMessage());
_menu.IngredientsList.OnItemSelected += args =>
};
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (!disposing)
- {
- return;
- }
-
- _solids.Clear();
- _menu?.Dispose();
- }
-
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
- if (state is not MicrowaveUpdateUserInterfaceState cState)
+ if (state is not MicrowaveUpdateUserInterfaceState cState || _menu == null)
{
return;
}
+ _menu.IsBusy = cState.IsMicrowaveBusy;
+ _menu.CurrentCooktimeEnd = cState.CurrentCookTimeEnd;
- _menu?.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0);
- currentState = cState;
-
+ _menu.ToggleBusyDisableOverlayPanel(cState.IsMicrowaveBusy || cState.ContainedSolids.Length == 0);
// TODO move this to a component state and ensure the net ids.
- RefreshContentsDisplay(_entManager.GetEntityArray(cState.ContainedSolids));
-
- if (_menu == null) return;
+ RefreshContentsDisplay(EntMan.GetEntityArray(cState.ContainedSolids));
//Set the cook time info label
- var cookTime = cState.ActiveButtonIndex == 0
+ var cookTime = cState.ActiveButtonIndex == 0
? Loc.GetString("microwave-menu-instant-button")
: cState.CurrentCookTime.ToString();
[GenerateTypedNameReferences]
public sealed partial class MicrowaveMenu : FancyWindow
{
- public sealed class MicrowaveCookTimeButton : Button
- {
- public uint CookTime;
- }
+ [Dependency] private readonly IGameTiming _timing = default!;
public event Action<BaseButton.ButtonEventArgs, int>? OnCookTimeSelected;
public ButtonGroup CookTimeButtonGroup { get; }
- private readonly MicrowaveBoundUserInterface _owner;
- public MicrowaveMenu(MicrowaveBoundUserInterface owner)
+ public bool IsBusy;
+ public TimeSpan CurrentCooktimeEnd;
+
+ public MicrowaveMenu()
{
RobustXamlLoader.Load(this);
+ IoCManager.InjectDependencies(this);
CookTimeButtonGroup = new ButtonGroup();
InstantCookButton.Group = CookTimeButtonGroup;
- _owner = owner;
InstantCookButton.OnPressed += args =>
{
OnCookTimeSelected?.Invoke(args, 0);
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
- if(!_owner.currentState.IsMicrowaveBusy)
+
+ if (!IsBusy)
return;
- if(_owner.currentState.CurrentCookTimeEnd > _owner.GetCurrentTime())
+ if (CurrentCooktimeEnd > _timing.CurTime)
{
CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label",
- ("time",_owner.currentState.CurrentCookTimeEnd.Subtract(_owner.GetCurrentTime()).Seconds));
+ ("time", CurrentCooktimeEnd.Subtract(_timing.CurTime).Seconds));
}
}
+
+ public sealed class MicrowaveCookTimeButton : Button
+ {
+ public uint CookTime;
+ }
}
}
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Kitchen;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Prototypes;
{
public sealed class ReagentGrinderBoundUserInterface : BoundUserInterface
{
- [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
-
[ViewVariables]
private GrinderMenu? _menu;
{
base.Open();
- _menu = new GrinderMenu(this, EntMan, _prototypeManager);
- _menu.OpenCentered();
- _menu.OnClose += Close;
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- {
- return;
- }
-
- _menu?.Dispose();
+ _menu = this.CreateWindow<GrinderMenu>();
+ _menu.OnToggleAuto += ToggleAutoMode;
+ _menu.OnGrind += StartGrinding;
+ _menu.OnJuice += StartJuicing;
+ _menu.OnEjectAll += EjectAll;
+ _menu.OnEjectBeaker += EjectBeaker;
+ _menu.OnEjectChamber += EjectChamberContent;
}
protected override void UpdateState(BoundUserInterfaceState state)
_menu?.HandleMessage(message);
}
- public void ToggleAutoMode(BaseButton.ButtonEventArgs args)
+ public void ToggleAutoMode()
{
SendMessage(new ReagentGrinderToggleAutoModeMessage());
}
- public void StartGrinding(BaseButton.ButtonEventArgs? _ = null)
+ public void StartGrinding()
{
SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Grind));
}
- public void StartJuicing(BaseButton.ButtonEventArgs? _ = null)
+ public void StartJuicing()
{
SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Juice));
}
- public void EjectAll(BaseButton.ButtonEventArgs? _ = null)
+ public void EjectAll()
{
SendMessage(new ReagentGrinderEjectChamberAllMessage());
}
- public void EjectBeaker(BaseButton.ButtonEventArgs? _ = null)
+ public void EjectBeaker()
{
SendMessage(new ItemSlotButtonPressedEvent(SharedReagentGrinder.BeakerSlotId));
}
using Content.Shared.Labels;
using Content.Shared.Labels.Components;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Labels.UI
{
{
base.Open();
- _window = new HandLabelerWindow();
- if (State != null)
- UpdateState(State);
+ _window = this.CreateWindow<HandLabelerWindow>();
- _window.OpenCentered();
-
- _window.OnClose += Close;
_window.OnLabelChanged += OnLabelChanged;
Reload();
}
_window.SetCurrentLabel(component.AssignedLabel);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- _window?.Dispose();
- }
}
-
}
using Content.Shared.Lathe;
using Content.Shared.Research.Components;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
namespace Content.Client.Lathe.UI
{
{
base.Open();
- _menu = new LatheMenu(this);
- _menu.OnClose += Close;
-
+ _menu = this.CreateWindow<LatheMenu>();
+ _menu.SetEntity(Owner);
+ _menu.OpenCenteredRight();
_menu.OnServerListButtonPressed += _ =>
{
{
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
};
-
- _menu.OpenCenteredRight();
}
protected override void UpdateState(BoundUserInterfaceState state)
break;
}
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
- _menu?.Dispose();
- }
}
}
+using System.Buffers;
using System.Linq;
using System.Text;
using Content.Client.Materials;
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
- private EntityUid _owner;
private readonly SpriteSystem _spriteSystem;
private readonly LatheSystem _lathe;
private readonly MaterialStorageSystem _materialStorage;
public ProtoId<LatheCategoryPrototype>? CurrentCategory;
- public LatheMenu(LatheBoundUserInterface owner)
+ public EntityUid Entity;
+
+ public LatheMenu()
{
- _owner = owner.Owner;
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_lathe = _entityManager.System<LatheSystem>();
_materialStorage = _entityManager.System<MaterialStorageSystem>();
- Title = _entityManager.GetComponent<MetaDataComponent>(owner.Owner).EntityName;
-
SearchBar.OnTextChanged += _ =>
{
PopulateRecipes();
FilterOption.OnItemSelected += OnItemSelected;
ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a);
+ }
- if (_entityManager.TryGetComponent<LatheComponent>(owner.Owner, out var latheComponent))
+ public void SetEntity(EntityUid uid)
+ {
+ Entity = uid;
+
+ if (_entityManager.TryGetComponent<LatheComponent>(Entity, out var latheComponent))
{
if (!latheComponent.DynamicRecipes.Any())
{
}
}
- MaterialsList.SetOwner(owner.Owner);
+ MaterialsList.SetOwner(Entity);
}
/// <summary>
var sortedRecipesToShow = recipesToShow.OrderBy(p => p.Name);
RecipeList.Children.Clear();
+ _entityManager.TryGetComponent(Entity, out LatheComponent? lathe);
+
foreach (var prototype in sortedRecipesToShow)
{
EntityPrototype? recipeProto = null;
- if (_prototypeManager.TryIndex(prototype.Result, out EntityPrototype? entityProto) && entityProto != null)
+ if (_prototypeManager.TryIndex(prototype.Result, out EntityPrototype? entityProto))
recipeProto = entityProto;
- var canProduce = _lathe.CanProduce(_owner, prototype, quantity);
+ var canProduce = _lathe.CanProduce(Entity, prototype, quantity, component: lathe);
var control = new RecipeControl(prototype, () => GenerateTooltipText(prototype), canProduce, recipeProto);
control.OnButtonPressed += s =>
private string GenerateTooltipText(LatheRecipePrototype prototype)
{
StringBuilder sb = new();
+ var multiplier = _entityManager.GetComponent<LatheComponent>(Entity).MaterialUseMultiplier;
foreach (var (id, amount) in prototype.RequiredMaterials)
{
if (!_prototypeManager.TryIndex<MaterialPrototype>(id, out var proto))
continue;
- var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, _entityManager.GetComponent<LatheComponent>(_owner).MaterialUseMultiplier);
+ var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, multiplier);
var sheetVolume = _materialStorage.GetSheetVolume(proto);
var unit = Loc.GetString(proto.Unit);
var sheets = adjustedAmount / (float) sheetVolume;
- var availableAmount = _materialStorage.GetMaterialAmount(_owner, id);
+ var availableAmount = _materialStorage.GetMaterialAmount(Entity, id);
var missingAmount = Math.Max(0, adjustedAmount - availableAmount);
var missingSheets = missingAmount / (float) sheetVolume;
using Content.Shared.MachineLinking;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Shared.Timing;
namespace Content.Client.MachineLinking.UI;
{
base.Open();
- _window = new SignalTimerWindow(this);
-
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<SignalTimerWindow>();
+ _window.OnStartTimer += StartTimer;
_window.OnCurrentTextChanged += OnTextChanged;
_window.OnCurrentDelayMinutesChanged += OnDelayChanged;
_window.OnCurrentDelaySecondsChanged += OnDelayChanged;
}
- public void OnStartTimer()
+ public void StartTimer()
{
SendMessage(new SignalTimerStartMessage());
}
SendMessage(new SignalTimerDelayChangedMessage(_window.GetDelay()));
}
- public TimeSpan GetCurrentTime()
- {
- return _gameTiming.CurTime;
- }
-
/// <summary>
/// Update the UI state based on server-sent info
/// </summary>
_window.SetTimerStarted(cast.TimerStarted);
_window.SetHasAccess(cast.HasAccess);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- _window?.Dispose();
- }
}
[GenerateTypedNameReferences]
public sealed partial class SignalTimerWindow : DefaultWindow
{
+ [Dependency] private readonly IGameTiming _timing = default!;
+
private const int MaxTextLength = 5;
public event Action<string>? OnCurrentTextChanged;
public event Action<string>? OnCurrentDelayMinutesChanged;
public event Action<string>? OnCurrentDelaySecondsChanged;
- private readonly SignalTimerBoundUserInterface _owner;
-
private TimeSpan? _triggerTime;
private bool _timerStarted;
- public SignalTimerWindow(SignalTimerBoundUserInterface owner)
+ public event Action? OnStartTimer;
+
+ public SignalTimerWindow()
{
RobustXamlLoader.Load(this);
-
- _owner = owner;
+ IoCManager.InjectDependencies(this);
CurrentTextEdit.OnTextChanged += e => OnCurrentTextChange(e.Text);
CurrentDelayEditMinutes.OnTextChanged += e => OnCurrentDelayMinutesChange(e.Text);
CurrentDelayEditSeconds.OnTextChanged += e => OnCurrentDelaySecondsChange(e.Text);
- StartTimer.OnPressed += _ => OnStartTimer();
+ StartTimer.OnPressed += _ => StartTimerWeh();
}
- public void OnStartTimer()
+ private void StartTimerWeh()
{
if (!_timerStarted)
{
_timerStarted = true;
- _triggerTime = _owner.GetCurrentTime() + GetDelay();
+ _triggerTime = _timing.CurTime + GetDelay();
}
else
{
SetTimerStarted(false);
}
- _owner.OnStartTimer();
+
+ OnStartTimer?.Invoke();
}
protected override void FrameUpdate(FrameEventArgs args)
if (!_timerStarted || _triggerTime == null)
return;
- if (_owner.GetCurrentTime() < _triggerTime.Value)
+ if (_timing.CurTime < _triggerTime.Value)
{
- StartTimer.Text = TextScreenSystem.TimeToString(_triggerTime.Value - _owner.GetCurrentTime());
+ StartTimer.Text = TextScreenSystem.TimeToString(_triggerTime.Value - _timing.CurTime);
}
else
{
using Content.Shared.Humanoid.Markings;
using Content.Shared.MagicMirror;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.MagicMirror;
{
base.Open();
- _window = new();
+ _window = this.CreateWindow<MagicMirrorWindow>();
_window.OnHairSelected += tuple => SelectHair(MagicMirrorCategory.Hair, tuple.id, tuple.slot);
_window.OnHairColorChanged += args => ChangeColor(MagicMirrorCategory.Hair, args.marking, args.slot);
args => ChangeColor(MagicMirrorCategory.FacialHair, args.marking, args.slot);
_window.OnFacialHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.FacialHair); };
_window.OnFacialHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.FacialHair, args);
-
- _window.OnClose += Close;
- _window.OpenCentered();
}
private void SelectHair(MagicMirrorCategory category, string marking, int slot)
_window.UpdateState(data);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _window?.Dispose();
- }
}
using JetBrains.Annotations;
using Content.Shared.MassMedia.Systems;
using Content.Shared.MassMedia.Components;
+using Robust.Client.UserInterface;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
[UsedImplicitly]
public sealed class NewsWriterBoundUserInterface : BoundUserInterface
{
- [Dependency] private readonly IGameTiming _gameTiming = default!;
-
[ViewVariables]
private NewsWriterMenu? _menu;
protected override void Open()
{
- _menu = new NewsWriterMenu(_gameTiming);
-
- _menu.OpenCentered();
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<NewsWriterMenu>();
_menu.ArticleEditorPanel.PublishButtonPressed += OnPublishButtonPressed;
_menu.DeleteButtonPressed += OnDeleteButtonPressed;
SendMessage(new NewsWriterArticlesRequestMessage());
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _menu?.Close();
- _menu?.Dispose();
- }
-
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
[GenerateTypedNameReferences]
public sealed partial class NewsWriterMenu : FancyWindow
{
- private readonly IGameTiming _gameTiming;
+ [Dependency] private readonly IGameTiming _gameTiming = default!;
private TimeSpan? _nextPublish;
public event Action<int>? DeleteButtonPressed;
- public NewsWriterMenu(IGameTiming gameTiming)
+ public NewsWriterMenu()
{
RobustXamlLoader.Load(this);
+ IoCManager.InjectDependencies(this);
- _gameTiming = gameTiming;
ContentsContainer.RectClipContent = false;
// Customize scrollbar width and margin. This is not possible in xaml
using Content.Shared.Mech.Components;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Mech.Ui;
{
base.Open();
- _menu = new(Owner);
-
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<MechMenu>();
+ _menu.SetEntity(Owner);
_menu.OpenCenteredLeft();
_menu.OnRemoveButtonPressed += uid =>
}
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (!disposing)
- return;
-
- _menu?.Close();
- }
-
public UIFragment? GetEquipmentUi(EntityUid? uid)
{
var component = EntMan.GetComponentOrNull<UIFragmentComponent>(uid);
public event Action<EntityUid>? OnRemoveButtonPressed;
- public MechMenu(EntityUid mech)
+ public MechMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
+ }
- _mech = mech;
-
- MechView.SetEntity(mech);
+ public void SetEntity(EntityUid uid)
+ {
+ MechView.SetEntity(uid);
}
public void UpdateMechStats()
using Content.Shared.Medical.CrewMonitoring;
+using Robust.Client.UserInterface;
namespace Content.Client.Medical.CrewMonitoring;
protected override void Open()
{
EntityUid? gridUid = null;
- string stationName = string.Empty;
+ var stationName = string.Empty;
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
{
}
}
- _menu = new CrewMonitoringWindow(stationName, gridUid);
-
- _menu.OpenCentered();
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<CrewMonitoringWindow>();
+ _menu.Set(stationName, gridUid);
}
protected override void UpdateState(BoundUserInterfaceState state)
break;
}
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _menu?.Dispose();
- }
}
[GenerateTypedNameReferences]
public sealed partial class CrewMonitoringWindow : FancyWindow
{
- private readonly IEntityManager _entManager;
- private readonly IPrototypeManager _prototypeManager;
+ [Dependency] private readonly IEntityManager _entManager = default!;
+ [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly SpriteSystem _spriteSystem;
private NetEntity? _trackedEntity;
private bool _tryToScrollToListFocus;
private Texture? _blipTexture;
- public CrewMonitoringWindow(string stationName, EntityUid? mapUid)
+ public CrewMonitoringWindow()
{
RobustXamlLoader.Load(this);
+ IoCManager.InjectDependencies(this);
- _entManager = IoCManager.Resolve<IEntityManager>();
- _prototypeManager = IoCManager.Resolve<IPrototypeManager>();
_spriteSystem = _entManager.System<SpriteSystem>();
+ NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;
+
+ }
+
+ public void Set(string stationName, EntityUid? mapUid)
+ {
_blipTexture = _spriteSystem.Frame0(new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/NavMap/beveled_circle.png")));
if (_entManager.TryGetComponent<TransformComponent>(mapUid, out var xform))
StationName.AddStyleClass("LabelBig");
StationName.Text = stationName;
-
- NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;
NavMap.ForceNavMapUpdate();
}
using Content.Client.NetworkConfigurator.Systems;
using Content.Shared.DeviceNetwork;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.NetworkConfigurator;
switch (UiKey)
{
case NetworkConfiguratorUiKey.List:
- _listMenu = new NetworkConfiguratorListMenu(this);
- _listMenu.OnClose += Close;
+ _listMenu = this.CreateWindow<NetworkConfiguratorListMenu>();
_listMenu.ClearButton.OnPressed += _ => OnClearButtonPressed();
- _listMenu.OpenCenteredRight();
+ _listMenu.OnRemoveAddress += OnRemoveButtonPressed;
break;
case NetworkConfiguratorUiKey.Configure:
- _configurationMenu = new NetworkConfiguratorConfigurationMenu();
- _configurationMenu.OnClose += Close;
+ _configurationMenu = this.CreateWindow<NetworkConfiguratorConfigurationMenu>();
_configurationMenu.Set.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Set);
_configurationMenu.Add.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Add);
//_configurationMenu.Edit.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Edit);
_configurationMenu.Copy.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Copy);
_configurationMenu.Show.OnPressed += OnShowPressed;
_configurationMenu.Show.Pressed = _netConfig.ConfiguredListIsTracked(Owner);
- _configurationMenu.OpenCentered();
+ _configurationMenu.OnRemoveAddress += OnRemoveButtonPressed;
break;
case NetworkConfiguratorUiKey.Link:
- _linkMenu = new NetworkConfiguratorLinkMenu(this);
- _linkMenu.OnClose += Close;
- _linkMenu.OpenCentered();
+ _linkMenu = this.CreateWindow<NetworkConfiguratorLinkMenu>();
+ _linkMenu.OnLinkDefaults += args =>
+ {
+ SendMessage(new NetworkConfiguratorLinksSaveMessage(args));
+ };
+
+ _linkMenu.OnToggleLink += (left, right) =>
+ {
+ SendMessage(new NetworkConfiguratorToggleLinkMessage(left, right));
+ };
+
+ _linkMenu.OnClearLinks += () =>
+ {
+ SendMessage(new NetworkConfiguratorClearLinksMessage());
+ };
break;
}
}
}
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
-
- _linkMenu?.Dispose();
- _listMenu?.Dispose();
- _configurationMenu?.Dispose();
- }
-
private void OnClearButtonPressed()
{
SendMessage(new NetworkConfiguratorClearDevicesMessage());
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorConfigurationMenu : FancyWindow
{
+ public event Action<string>? OnRemoveAddress;
+
public NetworkConfiguratorConfigurationMenu()
{
RobustXamlLoader.Load(this);
Clear.StyleClasses.Add(StyleBase.ButtonOpenLeft);
Clear.StyleClasses.Add(StyleNano.StyleClassButtonColorRed);
+ DeviceList.OnRemoveAddress += args =>
+ {
+ OnRemoveAddress?.Invoke(args);
+ };
}
public void UpdateState(DeviceListUserInterfaceState state)
{
- DeviceList.UpdateState(null, state.DeviceList);
+ DeviceList.UpdateState(state.DeviceList, false);
Count.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count));
}
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer
{
- public void UpdateState(NetworkConfiguratorBoundUserInterface? ui, HashSet<(string address, string name)> devices)
+ public event Action<string>? OnRemoveAddress;
+
+ public void UpdateState(HashSet<(string address, string name)> devices, bool ui)
{
DeviceList.RemoveAllChildren();
foreach (var device in devices)
{
- DeviceList.AddChild(BuildDeviceListRow(ui, device));
+ DeviceList.AddChild(BuildDeviceListRow(device, ui));
}
}
- private static BoxContainer BuildDeviceListRow(NetworkConfiguratorBoundUserInterface? ui, (string address, string name) savedDevice)
+ private BoxContainer BuildDeviceListRow((string address, string name) savedDevice, bool ui)
{
var row = new BoxContainer()
{
row.AddChild(name);
row.AddChild(address);
- if (ui != null)
+ if (ui)
{
row.AddChild(removeButton);
- removeButton.OnPressed += _ => ui.OnRemoveButtonPressed(savedDevice.address);
+ removeButton.OnPressed += _ => OnRemoveAddress?.Invoke(savedDevice.address);
}
return row;
private readonly LinksRender _links;
-
private readonly List<SourcePortPrototype> _sources = new();
private readonly List<SinkPortPrototype> _sinks = new();
- private readonly NetworkConfiguratorBoundUserInterface _userInterface;
-
private (ButtonPosition position, string id, int index)? _selectedButton;
private List<(string left, string right)>? _defaults;
- public NetworkConfiguratorLinkMenu(NetworkConfiguratorBoundUserInterface userInterface)
+ public event Action? OnClearLinks;
+ public event Action<string, string>? OnToggleLink;
+ public event Action<List<(string left, string right)>>? OnLinkDefaults;
+
+ public NetworkConfiguratorLinkMenu()
{
- _userInterface = userInterface;
RobustXamlLoader.Load(this);
var footerStyleBox = new StyleBoxFlat()
ButtonOk.OnPressed += _ => Close();
ButtonLinkDefault.OnPressed += _ => LinkDefaults();
- ButtonClear.OnPressed += _ => _userInterface.SendMessage(new NetworkConfiguratorClearLinksMessage());
+ ButtonClear.OnPressed += _ => OnClearLinks?.Invoke();
}
public void UpdateState(DeviceLinkUserInterfaceState linkState)
if (_defaults == default)
return;
- _userInterface.SendMessage(new NetworkConfiguratorLinksSaveMessage(_defaults));
+ OnLinkDefaults?.Invoke(_defaults);
}
private Button CreateButton(ButtonPosition position, string name, string description, string id, int index)
var left = _selectedButton.Value.position == ButtonPosition.Left ? _selectedButton.Value.id : id;
var right = _selectedButton.Value.position == ButtonPosition.Left ? id : _selectedButton.Value.id;
- _userInterface.SendMessage(new NetworkConfiguratorToggleLinkMessage(left, right));
+ OnToggleLink?.Invoke(left, right);
args.Button.Pressed = false;
[GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorListMenu : FancyWindow
{
- private readonly NetworkConfiguratorBoundUserInterface _ui;
- public NetworkConfiguratorListMenu(NetworkConfiguratorBoundUserInterface ui)
+ public event Action<string>? OnRemoveAddress;
+
+ public NetworkConfiguratorListMenu()
{
RobustXamlLoader.Load(this);
-
- _ui = ui;
+ DeviceList.OnRemoveAddress += args =>
+ {
+ OnRemoveAddress?.Invoke(args);
+ };
}
public void UpdateState(NetworkConfiguratorUserInterfaceState state)
{
DeviceCountLabel.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count));
- DeviceList.UpdateState(_ui, state.DeviceList);
+ DeviceList.UpdateState(state.DeviceList, true);
}
}
using Content.Shared.Nuke;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Nuke
{
[ViewVariables]
private NukeMenu? _menu;
- public NukeBoundUserInterface([NotNull] EntityUid owner, [NotNull] Enum uiKey) : base(owner, uiKey)
+ public NukeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
- _menu = new NukeMenu();
- _menu.OpenCentered();
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<NukeMenu>();
_menu.OnKeypadButtonPressed += i =>
{
break;
}
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _menu?.Close();
- _menu?.Dispose();
- }
}
}
using Content.Shared.Chat;
using Content.Shared.NukeOps;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
public sealed class WarDeclaratorBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IConfigurationManager _cfg = default!;
- [Dependency] private readonly IGameTiming _gameTiming = default!;
- [Dependency] private readonly ILocalizationManager _localizationManager = default!;
[ViewVariables]
private WarDeclaratorWindow? _window;
{
base.Open();
- _window = new WarDeclaratorWindow(_gameTiming, _localizationManager);
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<WarDeclaratorWindow>();
_window.OnActivated += OnWarDeclaratorActivated;
}
_window?.UpdateState(cast);
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (disposing)
- _window?.Dispose();
- }
-
private void OnWarDeclaratorActivated(string message)
{
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
[GenerateTypedNameReferences]
public sealed partial class WarDeclaratorWindow : FancyWindow
{
- private readonly IGameTiming _gameTiming;
+ [Dependency] private readonly IGameTiming _gameTiming = default!;
+ [Dependency] private readonly ILocalizationManager _localizationManager = default!;
public event Action<string>? OnActivated;
private TimeSpan _shuttleDisabledTime;
private WarConditionStatus _status;
- public WarDeclaratorWindow(IGameTiming gameTiming, ILocalizationManager localizationManager)
+ public WarDeclaratorWindow()
{
RobustXamlLoader.Load(this);
- _gameTiming = gameTiming;
-
WarButton.OnPressed += (_) => OnActivated?.Invoke(Rope.Collapse(MessageEdit.TextRope));
- MessageEdit.Placeholder = new Rope.Leaf(localizationManager.GetString("war-declarator-message-placeholder"));
+ MessageEdit.Placeholder = new Rope.Leaf(_localizationManager.GetString("war-declarator-message-placeholder"));
}
protected override void FrameUpdate(FrameEventArgs args)
if (_menu == null)
CreateMenu();
-
- _menu?.OpenCenteredLeft();
}
private void CreateMenu()
{
- _menu = new PdaMenu();
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<PdaMenu>();
+ _menu.OpenCenteredLeft();
+
_menu.FlashLightToggleButton.OnToggled += _ =>
{
SendMessage(new PdaToggleFlashlightMessage());
_menu?.UpdateState(updateState);
}
-
protected override void AttachCartridgeUI(Control cartridgeUIFragment, string? title)
{
_menu?.ProgramView.AddChild(cartridgeUIFragment);
_menu?.UpdateAvailablePrograms(programs);
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _menu?.Dispose();
- }
-
private PdaBorderColorComponent? GetBorderColorComponent()
{
return EntMan.GetComponentOrNull<PdaBorderColorComponent>(Owner);
using Content.Shared.PDA;
using Content.Shared.PDA.Ringer;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
using Robust.Shared.Timing;
namespace Content.Client.PDA.Ringer
protected override void Open()
{
base.Open();
- _menu = new RingtoneMenu();
+ _menu = this.CreateWindow<RingtoneMenu>();
_menu.OpenToLeft();
- _menu.OnClose += Close;
_menu.TestRingerButton.OnPressed += _ =>
{
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Utility;
using static Content.Shared.Paper.SharedPaperComponent;
{
base.Open();
- _window = new PaperWindow();
- _window.OnClose += Close;
- _window.OnSaved += Input_OnTextEntered;
+ _window = this.CreateWindow<PaperWindow>();
+ _window.OnSaved += InputOnTextEntered;
if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
{
_window.InitVisuals(Owner, visuals);
}
-
- _window.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
_window?.Populate((PaperBoundUserInterfaceState) state);
}
- private void Input_OnTextEntered(string text)
+ private void InputOnTextEntered(string text)
{
SendMessage(new PaperInputTextMessage(text));
_window.Input.CursorPosition = new TextEdit.CursorPos(0, TextEdit.LineBreakBias.Top);
}
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- _window?.Dispose();
- }
}
public sealed partial class PaperWindow : BaseWindow
{
[Dependency] private readonly IInputManager _inputManager = default!;
+ [Dependency] private readonly IResourceCache _resCache = default!;
private static Color DefaultTextColor = new(25, 25, 25);
// Randomize the placement of any stamps based on the entity UID
// so that there's some variety in different papers.
StampDisplay.PlacementSeed = (int)entity;
- var resCache = IoCManager.Resolve<IResourceCache>();
// Initialize the background:
PaperBackground.ModulateSelfOverride = visuals.BackgroundModulate;
- var backgroundImage = visuals.BackgroundImagePath != null? resCache.GetResource<TextureResource>(visuals.BackgroundImagePath) : null;
+ var backgroundImage = visuals.BackgroundImagePath != null? _resCache.GetResource<TextureResource>(visuals.BackgroundImagePath) : null;
if (backgroundImage != null)
{
var backgroundImageMode = visuals.BackgroundImageTile ? StyleBoxTexture.StretchMode.Tile : StyleBoxTexture.StretchMode.Stretch;
PaperContent.ModulateSelfOverride = visuals.ContentImageModulate;
WrittenTextLabel.ModulateSelfOverride = visuals.FontAccentColor;
- var contentImage = visuals.ContentImagePath != null ? resCache.GetResource<TextureResource>(visuals.ContentImagePath) : null;
+ var contentImage = visuals.ContentImagePath != null ? _resCache.GetResource<TextureResource>(visuals.ContentImagePath) : null;
if (contentImage != null)
{
// Setup the paper content texture, but keep a reference to it, as we can't set
using Content.Shared.Singularity.Components;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.ParticleAccelerator.UI
{
{
base.Open();
- _menu = new ParticleAcceleratorControlMenu(this);
- _menu.OnClose += Close;
- _menu.OpenCentered();
+ _menu = this.CreateWindow<ParticleAcceleratorControlMenu>();
+ _menu.OnOverallState += SendEnableMessage;
+ _menu.OnPowerState += SendPowerStateMessage;
+ _menu.OnScanPartsRequested += SendScanPartsMessage;
}
public void SendEnableMessage(bool enable)
{
_menu?.DataUpdate((ParticleAcceleratorUIState) state);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- _menu?.Dispose();
- _menu = null;
- }
}
}
{
public sealed class ParticleAcceleratorControlMenu : BaseWindow
{
- private readonly ShaderInstance _greyScaleShader;
+ [Dependency] private readonly IPrototypeManager _protoManager = default!;
+ [Dependency] private readonly IResourceCache _cache = default!;
- private readonly ParticleAcceleratorBoundUserInterface _owner;
+ private readonly ShaderInstance _greyScaleShader;
private readonly Label _drawLabel;
private readonly FastNoiseLite _drawNoiseGenerator;
private bool _shouldContinueAnimating;
private int _maxStrength = 3;
- public ParticleAcceleratorControlMenu(ParticleAcceleratorBoundUserInterface owner)
+ public event Action<bool>? OnOverallState;
+ public event Action<ParticleAcceleratorPowerState>? OnPowerState;
+ public event Action? OnScanPartsRequested;
+
+ public ParticleAcceleratorControlMenu()
{
+ IoCManager.InjectDependencies(this);
SetSize = new Vector2(400, 320);
- _greyScaleShader = IoCManager.Resolve<IPrototypeManager>().Index<ShaderPrototype>("Greyscale").Instance();
+ _greyScaleShader = _protoManager.Index<ShaderPrototype>("Greyscale").Instance();
- _owner = owner;
_drawNoiseGenerator = new();
_drawNoiseGenerator.SetFractalType(FastNoiseLite.FractalType.FBm);
_drawNoiseGenerator.SetFrequency(0.5f);
- var resourceCache = IoCManager.Resolve<IResourceCache>();
- var font = resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13);
- var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
+ var font = _cache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13);
+ var panelTex = _cache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
MouseFilter = MouseFilterMode.Stop;
Text = Loc.GetString("particle-accelerator-control-menu-off-button"),
StyleClasses = { StyleBase.ButtonOpenRight },
};
- _offButton.OnPressed += args => owner.SendEnableMessage(false);
+
+ _offButton.OnPressed += args => OnOverallState?.Invoke(false);
_onButton = new Button
{
Text = Loc.GetString("particle-accelerator-control-menu-on-button"),
StyleClasses = { StyleBase.ButtonOpenLeft },
};
- _onButton.OnPressed += args => owner.SendEnableMessage(true);
+ _onButton.OnPressed += args => OnOverallState?.Invoke(true);
var closeButton = new TextureButton
{
}
});
- _scanButton.OnPressed += args => _owner.SendScanPartsMessage();
+ _scanButton.OnPressed += args => OnScanPartsRequested?.Invoke();
_alarmControl.AnimationCompleted += s =>
{
PASegmentControl Segment(string name)
{
- return new(this, resourceCache, name);
+ return new(this, _cache, name);
}
UpdateUI(false, false, false, false);
}
_stateSpinBox.SetButtonDisabled(true);
- _owner.SendPowerStateMessage(newState);
+ OnPowerState?.Invoke(newState);
}
protected override DragMode GetDragModeFor(Vector2 relativeMousePos)
using Content.Shared.Pinpointer;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
namespace Content.Client.Pinpointer.UI;
protected override void Open()
{
base.Open();
- _window = new NavMapBeaconWindow(Owner);
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<NavMapBeaconWindow>();
+
+ if (EntMan.TryGetComponent(Owner, out NavMapBeaconComponent? beacon))
+ {
+ _window.SetEntity(Owner, beacon);
+ }
_window.OnApplyButtonPressed += (label, enabled, color) =>
{
SendMessage(new NavMapBeaconConfigureBuiMessage(label, enabled, color));
};
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- _window?.Dispose();
- }
}
[GenerateTypedNameReferences]
public sealed partial class NavMapBeaconWindow : FancyWindow
{
- [Dependency] private readonly IEntityManager _entityManager = default!;
-
private string? _defaultLabel;
private bool _defaultEnabled;
private Color _defaultColor;
public event Action<string?, bool, Color>? OnApplyButtonPressed;
- public NavMapBeaconWindow(EntityUid beaconEntity)
+ public NavMapBeaconWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
- if (!_entityManager.TryGetComponent<NavMapBeaconComponent>(beaconEntity, out var navMap))
- return;
- _defaultLabel = navMap.Text;
- _defaultEnabled = navMap.Enabled;
- _defaultColor = navMap.Color;
- UpdateVisibleButton(navMap.Enabled);
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed);
-
- LabelLineEdit.Text = navMap.Text ?? string.Empty;
LabelLineEdit.OnTextChanged += OnTextChanged;
-
- ColorSelector.Color = navMap.Color;
ColorSelector.OnColorChanged += _ => TryEnableApplyButton();
TryEnableApplyButton();
ApplyButton.OnPressed += OnApplyPressed;
}
+ public void SetEntity(EntityUid uid, NavMapBeaconComponent navMap)
+ {
+ _defaultLabel = navMap.Text;
+ _defaultEnabled = navMap.Enabled;
+ _defaultColor = navMap.Color;
+
+ UpdateVisibleButton(navMap.Enabled);
+ LabelLineEdit.Text = navMap.Text ?? string.Empty;
+ ColorSelector.Color = navMap.Color;
+ }
+
private void UpdateVisibleButton(bool value)
{
VisibleButton.Pressed = value;
-using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Pinpointer.UI;
protected override void Open()
{
base.Open();
- _window?.Close();
EntityUid? gridUid = null;
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
gridUid = xform.GridUid;
}
- _window = new StationMapWindow(gridUid, Owner);
- _window.OpenCentered();
- _window.OnClose += Close;
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- _window?.Dispose();
+ _window = this.CreateWindow<StationMapWindow>();
+ _window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
+ _window.Set(gridUid, Owner);
}
}
[GenerateTypedNameReferences]
public sealed partial class StationMapWindow : FancyWindow
{
- public StationMapWindow(EntityUid? mapUid, EntityUid? trackedEntity)
+ public StationMapWindow()
{
RobustXamlLoader.Load(this);
+ }
+
+ public void Set(EntityUid? mapUid, EntityUid? trackedEntity)
+ {
NavMapScreen.MapUid = mapUid;
if (trackedEntity != null)
NavMapScreen.TrackedCoordinates.Add(new EntityCoordinates(trackedEntity.Value, Vector2.Zero), (true, Color.Cyan));
- if (IoCManager.Resolve<IEntityManager>().TryGetComponent<MetaDataComponent>(mapUid, out var metadata))
- {
- Title = metadata.EntityName;
- }
-
NavMapScreen.ForceNavMapUpdate();
}
}
-using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Pinpointer.UI;
protected override void Open()
{
base.Open();
- _window?.Close();
EntityUid? gridUid = null;
+ // TODO: What this just looks like it's been copy-pasted wholesale from StationMapBoundUserInterface?
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
{
gridUid = xform.GridUid;
}
- _window = new StationMapWindow(gridUid, null);
- _window.OpenCentered();
- _window.OnClose += Close;
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- _window?.Dispose();
+ _window = this.CreateWindow<StationMapWindow>();
+ _window.Set(gridUid, Owner);
}
}
using Content.Shared.APC;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Power.APC
{
{
base.Open();
- _menu = new ApcMenu(this);
- _menu.OnClose += Close;
- _menu.OpenCentered();
+ _menu = this.CreateWindow<ApcMenu>();
+ _menu.OnBreaker += BreakerPressed;
}
protected override void UpdateState(BoundUserInterfaceState state)
{
SendMessage(new ApcToggleMainBreakerMessage());
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _menu?.Dispose();
- }
- }
}
}
[GenerateTypedNameReferences]
public sealed partial class ApcMenu : FancyWindow
{
- public ApcMenu(ApcBoundUserInterface owner)
+ public event Action? OnBreaker;
+
+ public ApcMenu()
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
- EntityView.SetEntity(owner.Owner);
- BreakerButton.OnPressed += _ => owner.BreakerPressed();
+ BreakerButton.OnPressed += _ => OnBreaker?.Invoke();
+ }
+
+ public void SetEntity(EntityUid entity)
+ {
+ EntityView.SetEntity(entity);
}
public void UpdateState(BoundUserInterfaceState state)
[GenerateTypedNameReferences]
public sealed partial class GeneratorWindow : FancyWindow
{
- private readonly EntityUid _entity;
-
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;
- private readonly SharedPowerSwitchableSystem _switchable;
- private readonly FuelGeneratorComponent? _component;
- private PortableGeneratorComponentBuiState? _lastState;
+ private EntityUid _entity;
+
+ public float? MaximumPower;
+
+ public event Action<int>? OnPower;
+ public event Action<bool>? OnState;
+ public event Action? OnSwitchOutput;
+ public event Action? OnEjectFuel;
- public GeneratorWindow(PortableGeneratorBoundUserInterface bui, EntityUid entity)
+ public GeneratorWindow()
{
- _entity = entity;
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
- _entityManager.TryGetComponent(entity, out _component);
- _switchable = _entityManager.System<SharedPowerSwitchableSystem>();
-
- EntityView.SetEntity(entity);
TargetPower.IsValid += IsValid;
TargetPower.ValueChanged += (args) =>
{
- bui.SetTargetPower(args.Value);
+ OnPower?.Invoke(args.Value);
};
- StartButton.OnPressed += _ => bui.Start();
- StopButton.OnPressed += _ => bui.Stop();
- OutputSwitchButton.OnPressed += _ => bui.SwitchOutput();
- FuelEject.OnPressed += _ => bui.EjectFuel();
+ StartButton.OnPressed += _ => OnState?.Invoke(true);
+ StopButton.OnPressed += _ => OnState?.Invoke(false);
+ OutputSwitchButton.OnPressed += _ => OnSwitchOutput?.Invoke();
+ FuelEject.OnPressed += _ => OnEjectFuel?.Invoke();
+ }
+
+ public void SetEntity(EntityUid entity)
+ {
+ _entity = entity;
+ EntityView.SetEntity(entity);
}
private bool IsValid(int arg)
if (arg < 0)
return false;
- if (arg > (_lastState?.MaximumPower / 1000.0f ?? 0))
+ if (arg > (MaximumPower / 1000.0f ?? 0))
return false;
return true;
public void Update(PortableGeneratorComponentBuiState state)
{
- if (_component == null)
+ MaximumPower = state.MaximumPower;
+
+ if (!_entityManager.TryGetComponent(_entity, out FuelGeneratorComponent? component))
return;
- _lastState = state;
if (!TargetPower.LineEditControl.HasKeyboardFocus())
TargetPower.OverrideValue((int)(state.TargetPower / 1000.0f));
- var efficiency = SharedGeneratorSystem.CalcFuelEfficiency(state.TargetPower, state.OptimalPower, _component);
+ var efficiency = SharedGeneratorSystem.CalcFuelEfficiency(state.TargetPower, state.OptimalPower, component);
Efficiency.Text = efficiency.ToString("P1");
- var burnRate = _component.OptimalBurnRate / efficiency;
+ var burnRate = component.OptimalBurnRate / efficiency;
var left = state.RemainingFuel / burnRate;
Eta.Text = Loc.GetString(
}
var canSwitch = _entityManager.TryGetComponent(_entity, out PowerSwitchableComponent? switchable);
+ var switcher = _entityManager.System<SharedPowerSwitchableSystem>();
OutputSwitchLabel.Visible = canSwitch;
OutputSwitchButton.Visible = canSwitch;
if (switchable != null)
{
- var voltage = _switchable.VoltageString(_switchable.GetVoltage(_entity, switchable));
+ var voltage = switcher.VoltageString(switcher.GetVoltage(_entity, switchable));
OutputSwitchLabel.Text = Loc.GetString("portable-generator-ui-current-output", ("voltage", voltage));
- var nextVoltage = _switchable.VoltageString(_switchable.GetNextVoltage(_entity, switchable));
+ var nextVoltage = switcher.VoltageString(switcher.GetNextVoltage(_entity, switchable));
OutputSwitchButton.Text = Loc.GetString("power-switchable-switch-voltage", ("voltage", nextVoltage));
OutputSwitchButton.Disabled = state.On;
}
using Content.Shared.Power.Generator;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Power.Generator;
protected override void Open()
{
base.Open();
- _window = new GeneratorWindow(this, Owner);
+ _window = this.CreateWindow<GeneratorWindow>();
+ _window.SetEntity(Owner);
+ _window.OnState += args =>
+ {
+ if (args)
+ {
+ Start();
+ }
+ else
+ {
+ Stop();
+ }
+ };
+
+ _window.OnPower += SetTargetPower;
+ _window.OnEjectFuel += EjectFuel;
+ _window.OnSwitchOutput += SwitchOutput;
_window.OpenCenteredLeft();
- _window.OnClose += Close;
}
protected override void UpdateState(BoundUserInterfaceState state)
_window?.Update(msg);
}
- protected override void Dispose(bool disposing)
- {
- _window?.Dispose();
- }
-
public void SetTargetPower(int target)
{
SendMessage(new PortableGeneratorSetTargetPowerMessage(target));
using Content.Shared.Power;
+using Robust.Client.UserInterface;
namespace Content.Client.Power;
protected override void Open()
{
- _menu = new PowerMonitoringWindow(this, Owner);
- _menu.OpenCentered();
- _menu.OnClose += Close;
+ _menu = this.CreateWindow<PowerMonitoringWindow>();
+ _menu.SetEntity(Owner);
+ _menu.SendPowerMonitoringConsoleMessageAction += SendPowerMonitoringConsoleMessage;
}
protected override void UpdateState(BoundUserInterfaceState state)
var castState = (PowerMonitoringConsoleBoundInterfaceState) state;
- if (castState == null)
- return;
-
EntMan.TryGetComponent<TransformComponent>(Owner, out var xform);
_menu?.ShowEntites
(castState.TotalSources,
{
SendMessage(new PowerMonitoringConsoleMessage(netEntity, group));
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- _menu?.Dispose();
- }
}
if (windowEntry == null)
return;
- // Update sources and loads
+ // Update sources and loads
UpdateEntrySourcesOrLoads(masterContainer, windowEntry.SourcesContainer, focusSources, _sourceIcon);
UpdateEntrySourcesOrLoads(masterContainer, windowEntry.LoadsContainer, focusLoads, _loadIconPath);
subEntry.Button.OnButtonUp += args => { ButtonAction(subEntry, masterContainer); };
}
- if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(_owner, out var console))
+ if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(Entity, out var console))
return;
// Update all children
AddChild(MainContainer);
- // Grid container to hold the list of sources when selected
+ // Grid container to hold the list of sources when selected
SourcesContainer = new BoxContainer()
{
Orientation = LayoutOrientation.Vertical,
[GenerateTypedNameReferences]
public sealed partial class PowerMonitoringWindow : FancyWindow
{
- private readonly IEntityManager _entManager;
+ [Dependency] private IEntityManager _entManager = default!;
private readonly SpriteSystem _spriteSystem;
- private readonly IGameTiming _gameTiming;
+ [Dependency] private IGameTiming _gameTiming = default!;
private const float BlinkFrequency = 1f;
- private EntityUid? _owner;
private NetEntity? _focusEntity;
public event Action<NetEntity?, PowerMonitoringConsoleGroup>? SendPowerMonitoringConsoleMessageAction;
{ PowerMonitoringConsoleGroup.APC, (new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/NavMap/beveled_triangle.png")), Color.LimeGreen) },
};
- public PowerMonitoringWindow(PowerMonitoringConsoleBoundUserInterface userInterface, EntityUid? owner)
+ public EntityUid Entity;
+
+ public PowerMonitoringWindow()
{
RobustXamlLoader.Load(this);
- _entManager = IoCManager.Resolve<IEntityManager>();
- _gameTiming = IoCManager.Resolve<IGameTiming>();
+ IoCManager.InjectDependencies(this);
_spriteSystem = _entManager.System<SpriteSystem>();
- _owner = owner;
+
+ // Set trackable entity selected action
+ NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;
+
+ // Update nav map
+ NavMap.ForceNavMapUpdate();
+
+ // Set UI tab titles
+ MasterTabContainer.SetTabTitle(0, Loc.GetString("power-monitoring-window-label-sources"));
+ MasterTabContainer.SetTabTitle(1, Loc.GetString("power-monitoring-window-label-smes"));
+ MasterTabContainer.SetTabTitle(2, Loc.GetString("power-monitoring-window-label-substation"));
+ MasterTabContainer.SetTabTitle(3, Loc.GetString("power-monitoring-window-label-apc"));
+
+ // Track when the MasterTabContainer changes its tab
+ MasterTabContainer.OnTabChanged += OnTabChanged;
+
+ // Set UI toggles
+ ShowHVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.HighVoltage);
+ ShowMVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.MediumVoltage);
+ ShowLVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.Apc);
+ }
+
+ public void SetEntity(EntityUid uid)
+ {
+ Entity = uid;
// Pass owner to nav map
- NavMap.Owner = _owner;
+ NavMap.Owner = uid;
// Set nav map grid uid
var stationName = Loc.GetString("power-monitoring-window-unknown-location");
- if (_entManager.TryGetComponent<TransformComponent>(owner, out var xform))
+ if (_entManager.TryGetComponent<TransformComponent>(uid, out var xform))
{
NavMap.MapUid = xform.GridUid;
- // Assign station name
+ // Assign station name
if (_entManager.TryGetComponent<MetaDataComponent>(xform.GridUid, out var stationMetaData))
stationName = stationMetaData.EntityName;
var msg = new FormattedMessage();
- msg.AddMarkup(Loc.GetString("power-monitoring-window-station-name", ("stationName", stationName)));
+ msg.AddMarkupOrThrow(Loc.GetString("power-monitoring-window-station-name", ("stationName", stationName)));
StationName.SetMessage(msg);
}
StationName.SetMessage(stationName);
NavMap.Visible = false;
}
-
- // Set trackable entity selected action
- NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;
-
- // Update nav map
- NavMap.ForceNavMapUpdate();
-
- // Set UI tab titles
- MasterTabContainer.SetTabTitle(0, Loc.GetString("power-monitoring-window-label-sources"));
- MasterTabContainer.SetTabTitle(1, Loc.GetString("power-monitoring-window-label-smes"));
- MasterTabContainer.SetTabTitle(2, Loc.GetString("power-monitoring-window-label-substation"));
- MasterTabContainer.SetTabTitle(3, Loc.GetString("power-monitoring-window-label-apc"));
-
- // Track when the MasterTabContainer changes its tab
- MasterTabContainer.OnTabChanged += OnTabChanged;
-
- // Set UI toggles
- ShowHVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.HighVoltage);
- ShowMVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.MediumVoltage);
- ShowLVCable.OnToggled += _ => OnShowCableToggled(PowerMonitoringConsoleLineGroup.Apc);
-
- // Set power monitoring message action
- SendPowerMonitoringConsoleMessageAction += userInterface.SendPowerMonitoringConsoleMessage;
}
private void OnTabChanged(int tab)
PowerMonitoringConsoleEntry[] focusLoads,
EntityCoordinates? monitorCoords)
{
- if (_owner == null)
- return;
-
- if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(_owner.Value, out var console))
+ if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(Entity, out var console))
return;
// Update power status text
}
// Show monitor location
- var mon = _entManager.GetNetEntity(_owner);
+ var mon = _entManager.GetNetEntity(Entity);
- if (monitorCoords != null && mon != null)
+ if (monitorCoords != null && mon.IsValid())
{
var texture = _spriteSystem.Frame0(new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/NavMap/beveled_circle.png")));
var blip = new NavMapBlip(monitorCoords.Value, texture, Color.Cyan, true, false);
- NavMap.TrackedEntities[mon.Value] = blip;
+ NavMap.TrackedEntities[mon] = blip;
}
// If the entry group doesn't match the current tab, the data is out dated, do not use it
if (netEntity == null)
return;
- if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(_owner, out var console))
+ if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(Entity, out var console))
return;
if (!console.PowerMonitoringDeviceMetaData.TryGetValue(netEntity.Value, out var metaData))
{
AutoScrollToFocus();
- // Warning sign pulse
+ // Warning sign pulse
var lit = _gameTiming.RealTime.TotalSeconds % BlinkFrequency > BlinkFrequency / 2f;
SystemWarningPanel.Modulate = lit ? Color.White : new Color(178, 178, 178);
}
[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)
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);
}
{
VerticalAlignment = VAlignment.Center,
HorizontalAlignment = HAlignment.Center,
- Texture = _spriteSystem.Frame0(proto.Sprite),
+ Texture = _sprites.Frame0(proto.Sprite),
TextureScale = new Vector2(2f, 2f),
};
// Set up menu actions
foreach (var child in Children)
+ {
AddRCDMenuButtonOnClickActions(child);
-
- OnChildAdded += AddRCDMenuButtonOnClickActions;
-
- SendRCDSystemMessageAction += bui.SendRCDSystemMessage;
+ }
}
private static string OopsConcat(string a, string b)
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));
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.Input;
+using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.RCD;
{
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;
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();
- }
}
using Content.Shared.Radio;
using Content.Shared.Radio.Components;
using JetBrains.Annotations;
+using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Radio.Ui;
{
base.Open();
- var comp = EntMan.GetComponent<IntercomComponent>(Owner);
+ _menu = this.CreateWindow<IntercomMenu>();
- _menu = new((Owner, comp));
+ if (EntMan.TryGetComponent(Owner, out IntercomComponent? intercom))
+ {
+ _menu.Update((Owner, intercom));
+ }
_menu.OnMicPressed += enabled =>
{
{
SendMessage(new SelectIntercomChannelMessage(channel));
};
-
- _menu.OnClose += Close;
- _menu.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
- _menu?.Close();
}
public void Update(Entity<IntercomComponent> ent)
private readonly List<string> _channels = new();
- public IntercomMenu(Entity<IntercomComponent> entity)
+ public IntercomMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
MicButton.OnPressed += args => OnMicPressed?.Invoke(args.Button.Pressed);
SpeakerButton.OnPressed += args => OnSpeakerPressed?.Invoke(args.Button.Pressed);
-
- Update(entity);
}
public void Update(Entity<IntercomComponent> entity)
using Content.Shared.Research;
using Content.Shared.Research.Components;
+using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Research.UI
{
{
base.Open();
- _menu = new();
-
- _menu.OnClose += Close;
- _menu.OpenCentered();
+ _menu = this.CreateWindow<DiskConsoleMenu>();
_menu.OnServerButtonPressed += () =>
{
};
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
- _menu?.Close();
- }
-
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
using Content.Shared.Research.Components;
+using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
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)
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();
- }
}
}
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)
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;
var owner = Owner;
- _consoleMenu = new ResearchConsoleMenu(owner);
+ _consoleMenu = this.CreateWindow<ResearchConsoleMenu>();
+ _consoleMenu.SetEntity(owner);
_consoleMenu.OnTechnologyCardPressed += id =>
{
{
SendMessage(new ConsoleServerSelectionMessage());
};
+ }
+
+ public override void OnProtoReload(PrototypesReloadedEventArgs args)
+ {
+ base.OnProtoReload(args);
+
+ if (!args.WasModified<TechnologyPrototype>())
+ return;
- _consoleMenu.OnClose += Close;
+ if (State is not ResearchConsoleBoundInterfaceState rState)
+ return;
- _consoleMenu.OpenCentered();
+ _consoleMenu?.UpdatePanels(rState);
+ _consoleMenu?.UpdateInformationPanel(rState);
}
protected override void UpdateState(BoundUserInterfaceState state)
_consoleMenu?.UpdatePanels(castState);
_consoleMenu?.UpdateInformationPanel(castState);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
- _consoleMenu?.Dispose();
- }
}
[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);
_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 SetEntity(EntityUid entity)
+ {
+ Entity = entity;
}
- public void UpdatePanels(ResearchConsoleBoundInterfaceState state)
+ 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
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);
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);
}
("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;
}
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)
using Content.Shared.Robotics;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Robotics.UI;
{
base.Open();
- _window = new RoboticsConsoleWindow(Owner);
+ _window = this.CreateWindow<RoboticsConsoleWindow>();
+ _window.SetEntity(Owner);
+
_window.OnDisablePressed += address =>
{
SendMessage(new RoboticsConsoleDisableMessage(address));
{
SendMessage(new RoboticsConsoleDestroyMessage(address));
};
- _window.OnClose += Close;
-
- _window.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
if (state is not RoboticsConsoleState cast)
return;
- _window?.UpdateState(cast);
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- _window?.Dispose();
+ _window.UpdateState(cast);
}
}
public Action<string>? OnDisablePressed;
public Action<string>? OnDestroyPressed;
- private Entity<RoboticsConsoleComponent, LockComponent?> _console;
private string? _selected;
private Dictionary<string, CyborgControlData> _cyborgs = new();
- public RoboticsConsoleWindow(EntityUid console)
+ public EntityUid Entity;
+
+ public RoboticsConsoleWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_lock = _entMan.System<LockSystem>();
_sprite = _entMan.System<SpriteSystem>();
- _console = (console, _entMan.GetComponent<RoboticsConsoleComponent>(console), null);
- _entMan.TryGetComponent(_console, out _console.Comp2);
-
Cyborgs.OnItemSelected += args =>
{
if (Cyborgs[args.ItemIndex].Metadata is not string address)
DestroyButton.StyleClasses.Add(StyleBase.ButtonCaution);
}
+ public void SetEntity(EntityUid uid)
+ {
+ Entity = uid;
+ }
+
public void UpdateState(RoboticsConsoleState state)
{
_cyborgs = state.Cyborgs;
PopulateData();
- var locked = _lock.IsLocked((_console, _console.Comp2));
+ var locked = _lock.IsLocked(Entity);
DangerZone.Visible = !locked;
LockedMessage.Visible = locked;
}
// how the turntables
DisableButton.Disabled = !(data.HasBrain && data.CanDisable);
- DestroyButton.Disabled = _timing.CurTime < _console.Comp1.NextDestroy;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
- DestroyButton.Disabled = _timing.CurTime < _console.Comp1.NextDestroy;
+ if (_entMan.TryGetComponent(Entity, out RoboticsConsoleComponent? console))
+ {
+ DestroyButton.Disabled = _timing.CurTime < console.NextDestroy;
+ }
+ else
+ {
+ DestroyButton.Disabled = true;
+ }
}
}
protected override void Open()
{
base.Open();
- _window = new OfferingWindow();
+ _window = this.CreateWindow<OfferingWindow>();
_window.Title = Loc.GetString("salvage-expedition-window-title");
- _window.OnClose += Close;
- _window?.OpenCenteredLeft();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- _window?.Dispose();
- _window = null;
+ _window.OpenCenteredLeft();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.Open();
- if (_window is null)
- {
- _window = new OfferingWindow();
- _window.Title = Loc.GetString("salvage-magnet-window-title");
- _window.OnClose += Close;
- _window.OpenCenteredLeft();
- }
+ _window = this.CreateWindow<OfferingWindow>();
+ _window.Title = Loc.GetString("salvage-magnet-window-title");
+ _window.OpenCenteredLeft();
}
protected override void UpdateState(BoundUserInterfaceState state)
_window.AddOption(option);
}
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- if (disposing)
- {
- _window?.Close();
- _window?.Dispose();
- }
- }
}
using Content.Shared.Shuttles.Events;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Shuttles.BUI;
{
base.Open();
- _window = new IFFConsoleWindow();
- _window.OnClose += Close;
+ _window = this.CreateWindow<IFFConsoleWindow>();
_window.ShowIFF += SendIFFMessage;
_window.ShowVessel += SendVesselMessage;
_window.OpenCenteredLeft();
using Content.Shared.Shuttles.BUIStates;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using RadarConsoleWindow = Content.Client.Shuttles.UI.RadarConsoleWindow;
namespace Content.Client.Shuttles.BUI;
{
base.Open();
- _window = new RadarConsoleWindow();
- _window.OnClose += Close;
- _window.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (disposing)
- {
- _window?.Dispose();
- }
+ _window = this.CreateWindow<RadarConsoleWindow>();
}
protected override void UpdateState(BoundUserInterfaceState state)
using Content.Shared.Shuttles.BUIStates;
using Content.Shared.Shuttles.Events;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
using Robust.Shared.Map;
namespace Content.Client.Shuttles.BUI;
protected override void Open()
{
base.Open();
- _window = new ShuttleConsoleWindow();
- _window.OpenCentered();
- _window.OnClose += Close;
+ _window = this.CreateWindow<ShuttleConsoleWindow>();
_window.RequestFTL += OnFTLRequest;
_window.RequestBeaconFTL += OnFTLBeaconRequest;
using Content.Shared.Silicons.Borgs;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Silicons.Borgs;
{
base.Open();
- var owner = Owner;
-
- _menu = new BorgMenu(owner);
+ _menu = this.CreateWindow<BorgMenu>();
+ _menu.SetEntity(Owner);
_menu.BrainButtonPressed += () =>
{
{
SendMessage(new BorgRemoveModuleBuiMessage(EntMan.GetNetEntity(module)));
};
-
- _menu.OnClose += Close;
-
- _menu.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
return;
_menu?.UpdateState(msg);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
- _menu?.Dispose();
- }
}
VerticalExpand="True">
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True" Margin="15 10 15 15">
<BoxContainer Orientation="Horizontal">
- <ProgressBar Name="ChargeBar" Access="Public" HorizontalExpand="True" MinValue="0" MaxValue="1">
+ <ProgressBar Name="ChargeBar" Access="Public" HorizontalExpand="True" MinValue="0" Value="1" MaxValue="1">
<Label Name="ChargeLabel" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5 0 0 0"/>
</ProgressBar>
<Control MinWidth="5"/>
public Action<string>? NameChanged;
public Action<EntityUid>? RemoveModuleButtonPressed;
- private readonly BorgChassisComponent? _chassis;
- public readonly EntityUid Entity;
public float AccumulatedTime;
private string _lastValidName;
private List<EntityUid> _modules = new();
- public BorgMenu(EntityUid entity)
+ public EntityUid Entity;
+
+ public BorgMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
- Entity = entity;
+ _lastValidName = NameLineEdit.Text;
- if (_entity.TryGetComponent<BorgChassisComponent>(Entity, out var chassis))
- _chassis = chassis;
+ EjectBatteryButton.OnPressed += _ => EjectBatteryButtonPressed?.Invoke();
+ BrainButton.OnPressed += _ => BrainButtonPressed?.Invoke();
+ NameLineEdit.OnTextChanged += OnNameChanged;
+ NameLineEdit.OnTextEntered += OnNameEntered;
+ NameLineEdit.OnFocusExit += OnNameFocusExit;
+
+ UpdateBrainButton();
+ }
+
+ public void SetEntity(EntityUid entity)
+ {
+ Entity = entity;
BorgSprite.SetEntity(entity);
- ChargeBar.MaxValue = 1f;
- ChargeBar.Value = 1f;
if (_entity.TryGetComponent<NameIdentifierComponent>(Entity, out var nameIdentifierComponent))
{
NameIdentifierLabel.Visible = false;
NameLineEdit.Text = _entity.GetComponent<MetaDataComponent>(Entity).EntityName;
}
-
- _lastValidName = NameLineEdit.Text;
-
- EjectBatteryButton.OnPressed += _ => EjectBatteryButtonPressed?.Invoke();
- BrainButton.OnPressed += _ => BrainButtonPressed?.Invoke();
-
- NameLineEdit.OnTextChanged += OnNameChanged;
- NameLineEdit.OnTextEntered += OnNameEntered;
- NameLineEdit.OnFocusExit += OnNameFocusExit;
-
- UpdateBrainButton();
}
protected override void FrameUpdate(FrameEventArgs args)
private void UpdateBrainButton()
{
- if (_chassis?.BrainEntity is { } brain)
+ if (_entity.TryGetComponent(Entity, out BorgChassisComponent? chassis) && chassis.BrainEntity is { } brain)
{
BrainButton.Text = _entity.GetComponent<MetaDataComponent>(brain).EntityName;
BrainView.Visible = true;
private void UpdateModulePanel()
{
- if (_chassis == null)
+ if (!_entity.TryGetComponent(Entity, out BorgChassisComponent? chassis))
return;
ModuleCounter.Text = Loc.GetString("borg-ui-module-counter",
- ("actual", _chassis.ModuleCount),
- ("max", _chassis.MaxModules));
+ ("actual", chassis.ModuleCount),
+ ("max", chassis.MaxModules));
- if (_chassis.ModuleContainer.Count == _modules.Count)
+ if (chassis.ModuleContainer.Count == _modules.Count)
{
var isSame = true;
- foreach (var module in _chassis.ModuleContainer.ContainedEntities)
+ foreach (var module in chassis.ModuleContainer.ContainedEntities)
{
if (_modules.Contains(module))
continue;
ModuleContainer.Children.Clear();
_modules.Clear();
- foreach (var module in _chassis.ModuleContainer.ContainedEntities)
+ foreach (var module in chassis.ModuleContainer.ContainedEntities)
{
var control = new BorgModuleControl(module, _entity);
control.RemoveButtonPressed += () =>
using Content.Shared.Silicons.Laws;
using Content.Shared.Silicons.Laws.Components;
using JetBrains.Annotations;
+using Robust.Client.UserInterface;
namespace Content.Client.Silicons.Laws.Ui;
{
base.Open();
- _menu = new();
-
- _menu.OnClose += Close;
- _menu.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
- _menu?.Close();
+ _menu = this.CreateWindow<SiliconLawMenu>();
}
protected override void UpdateState(BoundUserInterfaceState state)
using Content.Shared.SprayPainter;
using Content.Shared.SprayPainter.Components;
-using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
namespace Content.Client.SprayPainter.UI;
[ViewVariables]
private SprayPainterWindow? _window;
- [ViewVariables]
- private SprayPainterSystem? _painter;
-
public SprayPainterBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
{
base.Open();
- if (!EntMan.TryGetComponent<SprayPainterComponent>(Owner, out var comp))
- return;
-
- _window = new SprayPainterWindow();
+ _window = this.CreateWindow<SprayPainterWindow>();
- _painter = EntMan.System<SprayPainterSystem>();
-
- _window.OnClose += Close;
_window.OnSpritePicked = OnSpritePicked;
_window.OnColorPicked = OnColorPicked;
- _window.Populate(_painter.Entries, comp.Index, comp.PickedColor, comp.ColorPalette);
-
- _window.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- _window?.Dispose();
+ if (EntMan.TryGetComponent(Owner, out SprayPainterComponent? comp))
+ {
+ _window.Populate(EntMan.System<SprayPainterSystem>().Entries, comp.Index, comp.PickedColor, comp.ColorPalette);
+ }
}
private void OnSpritePicked(ItemList.ItemListSelectedEventArgs args)
using Content.Shared.StationRecords;
+using Robust.Client.UserInterface;
namespace Content.Client.StationRecords;
{
base.Open();
- _window = new();
+ _window = this.CreateWindow<GeneralStationRecordConsoleWindow>();
_window.OnKeySelected += key =>
SendMessage(new SelectStationRecord(key));
_window.OnFiltersChanged += (type, filterValue) =>
SendMessage(new SetStationRecordFilter(type, filterValue));
_window.OnDeleted += id => SendMessage(new DeleteStationRecord(id));
- _window.OnClose += Close;
-
- _window.OpenCentered();
}
protected override void UpdateState(BoundUserInterfaceState state)
_window?.UpdateState(cast);
}
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
-
- _window?.Close();
- }
}
using JetBrains.Annotations;
using System.Linq;
using Content.Shared.Store.Components;
+using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.Store.Ui;
protected override void Open()
{
- _menu = new StoreMenu();
+ _menu = this.CreateWindow<StoreMenu>();
if (EntMan.TryGetComponent<StoreComponent>(Owner, out var store))
_menu.Title = Loc.GetString(store.Name);
- _menu.OpenCentered();
- _menu.OnClose += Close;
-
_menu.OnListingButtonPressed += (_, listing) =>
{
SendMessage(new StoreBuyListingMessage(listing));
}
}
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
- _menu?.Close();
- _menu?.Dispose();
- }
-
private void UpdateListingsWithSearchFilter()
{
if (_menu == null)
-using Content.Client.Inventory;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Timing;
public LayoutContainer InventoryContainer = new();
public BoxContainer HandsContainer = new() { Orientation = LayoutOrientation.Horizontal };
public BoxContainer SnareContainer = new();
- private StrippableBoundUserInterface _bui;
public bool Dirty = true;
- public StrippingMenu(string title, StrippableBoundUserInterface bui)
- {
- Title = title;
- _bui = bui;
+ public event Action? OnDirty;
+ public StrippingMenu()
+ {
var box = new BoxContainer() { Orientation = LayoutOrientation.Vertical, Margin = new Thickness(0, 8) };
Contents.AddChild(box);
box.AddChild(SnareContainer);
return;
Dirty = false;
- _bui.UpdateMenu();
+ OnDirty?.Invoke();
}
}
}
using Content.Client.Eye;
using Content.Shared.SurveillanceCamera;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.SurveillanceCamera.UI;
{
base.Open();
- _window = new SurveillanceCameraMonitorWindow();
-
- if (State != null)
- {
- UpdateState(State);
- }
-
- _window.OpenCentered();
+ _window = this.CreateWindow<SurveillanceCameraMonitorWindow>();
_window.CameraSelected += OnCameraSelected;
_window.SubnetOpened += OnSubnetRequest;
_window.CameraRefresh += OnCameraRefresh;
_window.SubnetRefresh += OnSubnetRefresh;
- _window.OnClose += Close;
_window.CameraSwitchTimer += OnCameraSwitchTimer;
_window.CameraDisconnect += OnCameraDisconnect;
}
using Content.Shared.Thief;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Thief;
{
base.Open();
- _window = new ThiefBackpackMenu(this);
- _window.OnClose += Close;
- _window.OpenCentered();
- }
-
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing)
- return;
-
- if (_window != null)
- _window.OnClose -= Close;
-
- _window?.Dispose();
+ _window = this.CreateWindow<ThiefBackpackMenu>();
+ _window.OnApprove += SendApprove;
+ _window.OnSetChange += SendChangeSelected;
}
protected override void UpdateState(BoundUserInterfaceState state)
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
private readonly SpriteSystem _spriteSystem;
- private readonly ThiefBackpackBoundUserInterface _owner;
+ public event Action? OnApprove;
+ public event Action<int>? OnSetChange;
- public ThiefBackpackMenu(ThiefBackpackBoundUserInterface owner)
+ public ThiefBackpackMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_spriteSystem = _sysMan.GetEntitySystem<SpriteSystem>();
- _owner = owner;
-
- ApproveButton.OnButtonDown += (args) =>
+ ApproveButton.OnPressed += args =>
{
- _owner.SendApprove();
+ OnApprove?.Invoke();
};
}
public void UpdateState(ThiefBackpackBoundUserInterfaceState state)
{
- SetsGrid.RemoveAllChildren();
- int count = 0;
- int selectedNumber = 0;
- foreach (var set in state.Sets)
+ SetsGrid.DisposeAllChildren();
+ var selectedNumber = 0;
+ foreach (var (set, info) in state.Sets)
{
- var child = new ThiefBackpackSet(set.Value, _spriteSystem);
+ var child = new ThiefBackpackSet(info, _spriteSystem);
child.SetButton.OnButtonDown += (args) =>
{
- _owner.SendChangeSelected(set.Key);
+ OnSetChange?.Invoke(set);
};
SetsGrid.AddChild(child);
- count++;
-
- if (set.Value.Selected)
+ if (info.Selected)
selectedNumber++;
}
Description.Text = Loc.GetString("thief-backpack-window-description", ("maxCount", state.MaxSelectedSets));
SelectedSets.Text = Loc.GetString("thief-backpack-window-selected", ("selectedCount", selectedNumber), ("maxCount", state.MaxSelectedSets));
- ApproveButton.Disabled = selectedNumber == state.MaxSelectedSets ? false : true;
+ ApproveButton.Disabled = selectedNumber != state.MaxSelectedSets;
}
}
using Content.Shared.Atmos.Components;
using JetBrains.Annotations;
+using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.UserInterface.Systems.Atmos.GasTank
{
{
}
- public void SetOutputPressure(in float value)
+ public void SetOutputPressure(float value)
{
SendMessage(new GasTankSetPressureMessage
{
protected override void Open()
{
base.Open();
- _window = new GasTankWindow(this, EntMan.GetComponent<MetaDataComponent>(Owner).EntityName);
- _window.OnClose += Close;
- _window.OpenCentered();
+ _window = this.CreateWindow<GasTankWindow>();
+ _window.SetTitle(EntMan.GetComponent<MetaDataComponent>(Owner).EntityName);
+ _window.OnOutputPressure += SetOutputPressure;
+ _window.OnToggleInternals += ToggleInternals;
}
protected override void UpdateState(BoundUserInterfaceState state)
public sealed class GasTankWindow
: BaseWindow
{
+ [Dependency] private readonly IResourceCache _cache = default!;
+
private readonly RichTextLabel _lblPressure;
private readonly FloatSpinBox _spbPressure;
private readonly RichTextLabel _lblInternals;
private readonly Button _btnInternals;
+ private readonly Label _topLabel;
+
+ public event Action<float>? OnOutputPressure;
+ public event Action? OnToggleInternals;
- public GasTankWindow(GasTankBoundUserInterface owner, string uidName)
+ public GasTankWindow()
{
+ IoCManager.InjectDependencies(this);
Control contentContainer;
BoxContainer topContainer;
TextureButton btnClose;
- var resourceCache = IoCManager.Resolve<IResourceCache>();
var rootContainer = new LayoutContainer { Name = "GasTankRoot" };
AddChild(rootContainer);
MouseFilter = MouseFilterMode.Stop;
- var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
+ var panelTex = _cache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
var back = new StyleBoxTexture
{
Texture = panelTex,
LayoutContainer.SetAnchorPreset(topContainerWrap, LayoutContainer.LayoutPreset.Wide);
- var font = resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13);
+ var font = _cache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13);
+
+ _topLabel = new Label
+ {
+ FontOverride = font,
+ FontColorOverride = StyleNano.NanoGold,
+ VerticalAlignment = VAlignment.Center,
+ HorizontalExpand = true,
+ HorizontalAlignment = HAlignment.Left,
+ Margin = new Thickness(0, 0, 20, 0),
+ };
var topRow = new BoxContainer
{
Margin = new Thickness(4, 2, 12, 2),
Children =
{
- (new Label
- {
- Text = uidName,
- FontOverride = font,
- FontColorOverride = StyleNano.NanoGold,
- VerticalAlignment = VAlignment.Center,
- HorizontalExpand = true,
- HorizontalAlignment = HAlignment.Left,
- Margin = new Thickness(0, 0, 20, 0),
- }),
+ _topLabel,
(btnClose = new TextureButton
{
StyleClasses = {DefaultWindow.StyleClassWindowCloseButton},
// Handlers
_spbPressure.OnValueChanged += args =>
{
- owner.SetOutputPressure(args.Value);
+ OnOutputPressure?.Invoke(args.Value);
};
_btnInternals.OnPressed += args =>
{
- owner.ToggleInternals();
+ OnToggleInternals?.Invoke();
};
btnClose.OnPressed += _ => Close();
}
+ public void SetTitle(string name)
+ {
+ _topLabel.Text = name;
+ }
+
public void UpdateState(GasTankBoundUserInterfaceState state)
{
_lblPressure.SetMarkup(Loc.GetString("gas-tank-window-tank-pressure-text", ("tankPressure", $"{state.TankPressure:0.##}")));
using Content.Shared.VendingMachines;
using Robust.Client.UserInterface.Controls;
using System.Linq;
+using Robust.Client.UserInterface;
namespace Content.Client.VendingMachines
{
_cachedInventory = vendingMachineSys.GetAllInventory(Owner);
- _menu = new VendingMachineMenu { Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName };
+ _menu = this.CreateWindow<VendingMachineMenu>();
+ _menu.OpenCenteredLeft();
+ _menu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName;
- _menu.OnClose += Close;
_menu.OnItemSelected += OnItemSelected;
_menu.OnSearchChanged += OnSearchChanged;
_menu.Populate(_cachedInventory, out _cachedFilteredIndex);
-
- _menu.OpenCenteredLeft();
}
protected override void UpdateState(BoundUserInterfaceState state)
using Content.Shared.VoiceMask;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
using Robust.Shared.Prototypes;
namespace Content.Client.VoiceMask;
public sealed class VoiceMaskBoundUserInterface : BoundUserInterface
{
- [Dependency] private readonly IPrototypeManager _proto = default!;
+ [Dependency] private readonly IPrototypeManager _protomanager = default!;
[ViewVariables]
private VoiceMaskNameChangeWindow? _window;
{
base.Open();
- _window = new(_proto);
+ _window = this.CreateWindow<VoiceMaskNameChangeWindow>();
+ _window.ReloadVerbs(_protomanager);
- _window.OpenCentered();
_window.OnNameChange += OnNameSelected;
_window.OnVerbChange += verb => SendMessage(new VoiceMaskChangeVerbMessage(verb));
- _window.OnClose += Close;
}
private void OnNameSelected(string name)
private string? _verb;
- public VoiceMaskNameChangeWindow(IPrototypeManager proto)
+ public VoiceMaskNameChangeWindow()
{
RobustXamlLoader.Load(this);
SpeechVerbSelector.SelectId(args.Id);
};
- ReloadVerbs(proto);
-
AddVerbs();
}
- private void ReloadVerbs(IPrototypeManager proto)
+ public void ReloadVerbs(IPrototypeManager proto)
{
foreach (var verb in proto.EnumeratePrototypes<SpeechVerbPrototype>())
{
using Robust.Client.GameObjects;
using Content.Shared.Speech.Components;
+using Robust.Client.UserInterface;
namespace Content.Client.Weapons.Melee.UI;
{
base.Open();
- _window = new MeleeSpeechWindow();
- if (State != null)
- UpdateState(State);
-
- _window.OpenCentered();
-
- _window.OnClose += Close;
+ _window = this.CreateWindow<MeleeSpeechWindow>();
_window.OnBattlecryEntered += OnBattlecryChanged;
}
-
private void OnBattlecryChanged(string newBattlecry)
{
SendMessage(new MeleeSpeechBattlecryChangedMessage(newBattlecry));
using Content.Shared.Wires;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Wires.UI
{
protected override void Open()
{
base.Open();
-
- _menu = new WiresMenu(this);
- _menu.OnClose += Close;
- _menu.OpenCenteredLeft();
+ _menu = this.CreateWindow<WiresMenu>();
+ _menu.OnAction += PerformAction;
}
protected override void UpdateState(BoundUserInterfaceState state)
-using System;
using System.Numerics;
using Content.Client.Examine;
using Content.Client.Resources;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Animations;
using Robust.Shared.Input;
-using Robust.Shared.IoC;
-using Robust.Shared.Localization;
-using Robust.Shared.Maths;
-using Robust.Shared.Random;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Wires.UI
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
- public WiresBoundUserInterface Owner { get; }
-
private readonly Control _wiresHBox;
private readonly Control _topContainer;
private readonly Control _statusContainer;
public TextureButton CloseButton { get; set; }
- public WiresMenu(WiresBoundUserInterface owner)
+ public event Action<int, WiresAction>? OnAction;
+
+ public WiresMenu()
{
IoCManager.InjectDependencies(this);
- Owner = owner;
var rootContainer = new LayoutContainer {Name = "WireRoot"};
AddChild(rootContainer);
control.WireClicked += () =>
{
- Owner.PerformAction(wire.Id, wire.IsCut ? WiresAction.Mend : WiresAction.Cut);
+ OnAction?.Invoke(wire.Id, wire.IsCut ? WiresAction.Mend : WiresAction.Cut);
};
control.ContactsClicked += () =>
{
- Owner.PerformAction(wire.Id, WiresAction.Pulse);
+ OnAction?.Invoke(wire.Id, WiresAction.Pulse);
};
}
using Content.Shared.Xenoarchaeology.Equipment;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
+using Robust.Client.UserInterface;
namespace Content.Client.Xenoarchaeology.Ui;
{
base.Open();
- _consoleMenu = new AnalysisConsoleMenu();
-
- _consoleMenu.OnClose += Close;
- _consoleMenu.OpenCentered();
+ _consoleMenu = this.CreateWindow<AnalysisConsoleMenu>();
_consoleMenu.OnServerSelectionButtonPressed += () =>
{