Revert "Remove some BUI boilerplate" (#30214)

Revert "Remove some BUI boilerplate (#28399)"

This reverts commit cbf329a82d.
This commit is contained in:
Nemanja
2024-07-20 20:42:27 -04:00
committed by GitHub
parent 6d664c9157
commit cb0ba66be3
137 changed files with 1755 additions and 1096 deletions

View File

@@ -2,7 +2,6 @@ using Content.Shared.Access;
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.Access.Systems; using Content.Shared.Access.Systems;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using static Content.Shared.Access.Components.AccessOverriderComponent; using static Content.Shared.Access.Components.AccessOverriderComponent;
@@ -24,28 +23,6 @@ namespace Content.Client.Access.UI
{ {
base.Open(); 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; List<ProtoId<AccessLevelPrototype>> accessLevels;
if (EntMan.TryGetComponent<AccessOverriderComponent>(Owner, out var accessOverrider)) if (EntMan.TryGetComponent<AccessOverriderComponent>(Owner, out var accessOverrider))
@@ -53,20 +30,38 @@ namespace Content.Client.Access.UI
accessLevels = accessOverrider.AccessLevels; accessLevels = accessOverrider.AccessLevels;
accessLevels.Sort(); accessLevels.Sort();
} }
else else
{ {
accessLevels = new List<ProtoId<AccessLevelPrototype>>(); accessLevels = new List<ProtoId<AccessLevelPrototype>>();
_accessOverriderSystem.Log.Error($"No AccessOverrider component found for {EntMan.ToPrettyString(Owner)}!"); _accessOverriderSystem.Log.Error($"No AccessOverrider component found for {EntMan.ToPrettyString(Owner)}!");
} }
_window?.SetAccessLevels(_prototypeManager, accessLevels); _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();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
{ {
base.UpdateState(state); base.UpdateState(state);
var castState = (AccessOverriderBoundUserInterfaceState) state; var castState = (AccessOverriderBoundUserInterfaceState) state;
_window?.UpdateState(_prototypeManager, castState); _window?.UpdateState(castState);
} }
public void SubmitData(List<ProtoId<AccessLevelPrototype>> newAccessList) public void SubmitData(List<ProtoId<AccessLevelPrototype>> newAccessList)

View File

@@ -13,24 +13,26 @@ namespace Content.Client.Access.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class AccessOverriderWindow : DefaultWindow 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(); private readonly Dictionary<string, Button> _accessButtons = new();
public event Action<List<ProtoId<AccessLevelPrototype>>>? OnSubmit; public AccessOverriderWindow(AccessOverriderBoundUserInterface owner, IPrototypeManager prototypeManager,
List<ProtoId<AccessLevelPrototype>> accessLevels)
public AccessOverriderWindow()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
} IoCManager.InjectDependencies(this);
var logMill = _logManager.GetSawmill(SharedAccessOverriderSystem.Sawmill);
public void SetAccessLevels(IPrototypeManager protoManager, List<ProtoId<AccessLevelPrototype>> accessLevels) _owner = owner;
{
_accessButtons.Clear();
AccessLevelGrid.DisposeAllChildren();
foreach (var access in accessLevels) foreach (var access in accessLevels)
{ {
if (!protoManager.TryIndex(access, out var accessLevel)) if (!prototypeManager.TryIndex(access, out var accessLevel))
{ {
logMill.Error($"Unable to find accesslevel for {access}");
continue; continue;
} }
@@ -42,16 +44,11 @@ namespace Content.Client.Access.UI
AccessLevelGrid.AddChild(newButton); AccessLevelGrid.AddChild(newButton);
_accessButtons.Add(accessLevel.ID, newButton); _accessButtons.Add(accessLevel.ID, newButton);
newButton.OnPressed += _ => newButton.OnPressed += _ => SubmitData();
{
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(IPrototypeManager protoManager, AccessOverriderBoundUserInterfaceState state) public void UpdateState(AccessOverriderBoundUserInterfaceState state)
{ {
PrivilegedIdLabel.Text = state.PrivilegedIdName; PrivilegedIdLabel.Text = state.PrivilegedIdName;
PrivilegedIdButton.Text = state.IsPrivilegedIdPresent PrivilegedIdButton.Text = state.IsPrivilegedIdPresent
@@ -69,11 +66,11 @@ namespace Content.Client.Access.UI
if (state.MissingPrivilegesList != null && state.MissingPrivilegesList.Any()) if (state.MissingPrivilegesList != null && state.MissingPrivilegesList.Any())
{ {
var missingPrivileges = new List<string>(); List<string> missingPrivileges = new List<string>();
foreach (string tag in state.MissingPrivilegesList) foreach (string tag in state.MissingPrivilegesList)
{ {
var privilege = Loc.GetString(protoManager.Index<AccessLevelPrototype>(tag)?.Name ?? "generic-unknown"); string privilege = Loc.GetString(_prototypeManager.Index<AccessLevelPrototype>(tag)?.Name ?? "generic-unknown");
missingPrivileges.Add(privilege); missingPrivileges.Add(privilege);
} }
@@ -93,5 +90,13 @@ namespace Content.Client.Access.UI
} }
} }
} }
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());
}
} }
} }

View File

@@ -1,7 +1,6 @@
using Content.Shared.Access.Systems; using Content.Shared.Access.Systems;
using Content.Shared.StatusIcon; using Content.Shared.StatusIcon;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Client.Access.UI namespace Content.Client.Access.UI
@@ -21,11 +20,16 @@ namespace Content.Client.Access.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<AgentIDCardWindow>(); _window?.Dispose();
_window = new AgentIDCardWindow(this);
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.OnNameChanged += OnNameChanged; _window.OnNameChanged += OnNameChanged;
_window.OnJobChanged += OnJobChanged; _window.OnJobChanged += OnJobChanged;
_window.OnJobIconChanged += OnJobIconChanged;
} }
private void OnNameChanged(string newName) private void OnNameChanged(string newName)
@@ -57,5 +61,14 @@ namespace Content.Client.Access.UI
_window.SetCurrentJob(cast.CurrentJob); _window.SetCurrentJob(cast.CurrentJob);
_window.SetAllowedIcons(cast.Icons, cast.CurrentJobIconId); _window.SetAllowedIcons(cast.Icons, cast.CurrentJobIconId);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_window?.Dispose();
}
} }
} }

View File

@@ -17,19 +17,19 @@ namespace Content.Client.Access.UI
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IEntitySystemManager _entitySystem = default!; [Dependency] private readonly IEntitySystemManager _entitySystem = default!;
private readonly SpriteSystem _spriteSystem; private readonly SpriteSystem _spriteSystem;
private readonly AgentIDCardBoundUserInterface _bui;
private const int JobIconColumnCount = 10; private const int JobIconColumnCount = 10;
public event Action<string>? OnNameChanged; public event Action<string>? OnNameChanged;
public event Action<string>? OnJobChanged; public event Action<string>? OnJobChanged;
public event Action<ProtoId<StatusIconPrototype>>? OnJobIconChanged; public AgentIDCardWindow(AgentIDCardBoundUserInterface bui)
public AgentIDCardWindow()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
_spriteSystem = _entitySystem.GetEntitySystem<SpriteSystem>(); _spriteSystem = _entitySystem.GetEntitySystem<SpriteSystem>();
_bui = bui;
NameLineEdit.OnTextEntered += e => OnNameChanged?.Invoke(e.Text); NameLineEdit.OnTextEntered += e => OnNameChanged?.Invoke(e.Text);
NameLineEdit.OnFocusExit += e => OnNameChanged?.Invoke(e.Text); NameLineEdit.OnFocusExit += e => OnNameChanged?.Invoke(e.Text);
@@ -67,7 +67,7 @@ namespace Content.Client.Access.UI
}; };
// Generate buttons textures // Generate buttons textures
var jobIconTexture = new TextureRect TextureRect jobIconTexture = new TextureRect
{ {
Texture = _spriteSystem.Frame0(jobIcon.Icon), Texture = _spriteSystem.Frame0(jobIcon.Icon),
TextureScale = new Vector2(2.5f, 2.5f), TextureScale = new Vector2(2.5f, 2.5f),
@@ -75,7 +75,7 @@ namespace Content.Client.Access.UI
}; };
jobIconButton.AddChild(jobIconTexture); jobIconButton.AddChild(jobIconTexture);
jobIconButton.OnPressed += _ => OnJobIconChanged?.Invoke(jobIcon.ID); jobIconButton.OnPressed += _ => _bui.OnJobIconChanged(jobIconId);
IconGrid.AddChild(jobIconButton); IconGrid.AddChild(jobIconButton);
if (jobIconId.Equals(currentJobIconId)) if (jobIconId.Equals(currentJobIconId))

View File

@@ -1,6 +1,5 @@
using Content.Shared.Ame.Components; using Content.Shared.Ame.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Ame.UI namespace Content.Client.Ame.UI
{ {
@@ -17,8 +16,9 @@ namespace Content.Client.Ame.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<AmeWindow>(); _window = new AmeWindow(this);
_window.OnAmeButton += ButtonPressed; _window.OnClose += Close;
_window.OpenCentered();
} }
/// <summary> /// <summary>
@@ -40,5 +40,15 @@ namespace Content.Client.Ame.UI
{ {
SendMessage(new UiButtonPressedMessage(button)); SendMessage(new UiButtonPressedMessage(button));
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
}
}
} }
} }

View File

@@ -1,4 +1,3 @@
using System.Linq;
using Content.Client.UserInterface; using Content.Client.UserInterface;
using Content.Shared.Ame.Components; using Content.Shared.Ame.Components;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
@@ -10,17 +9,15 @@ namespace Content.Client.Ame.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class AmeWindow : DefaultWindow public sealed partial class AmeWindow : DefaultWindow
{ {
public event Action<UiButton>? OnAmeButton; public AmeWindow(AmeControllerBoundUserInterface ui)
public AmeWindow()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
EjectButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.Eject); EjectButton.OnPressed += _ => ui.ButtonPressed(UiButton.Eject);
ToggleInjection.OnPressed += _ => OnAmeButton?.Invoke(UiButton.ToggleInjection); ToggleInjection.OnPressed += _ => ui.ButtonPressed(UiButton.ToggleInjection);
IncreaseFuelButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.IncreaseFuel); IncreaseFuelButton.OnPressed += _ => ui.ButtonPressed(UiButton.IncreaseFuel);
DecreaseFuelButton.OnPressed += _ => OnAmeButton?.Invoke(UiButton.DecreaseFuel); DecreaseFuelButton.OnPressed += _ => ui.ButtonPressed(UiButton.DecreaseFuel);
} }
/// <summary> /// <summary>
@@ -32,7 +29,7 @@ namespace Content.Client.Ame.UI
var castState = (AmeControllerBoundUserInterfaceState) state; var castState = (AmeControllerBoundUserInterfaceState) state;
// Disable all buttons if not powered // Disable all buttons if not powered
if (Contents.Children.Any()) if (Contents.Children != null)
{ {
ButtonHelpers.SetButtonDisabledRecursive(Contents, !castState.HasPower); ButtonHelpers.SetButtonDisabledRecursive(Contents, !castState.HasPower);
EjectButton.Disabled = false; EjectButton.Disabled = false;
@@ -68,8 +65,8 @@ namespace Content.Client.Ame.UI
CoreCount.Text = $"{castState.CoreCount}"; CoreCount.Text = $"{castState.CoreCount}";
InjectionAmount.Text = $"{castState.InjectionAmount}"; InjectionAmount.Text = $"{castState.InjectionAmount}";
// format power statistics to pretty numbers // format power statistics to pretty numbers
CurrentPowerSupply.Text = $"{castState.CurrentPowerSupply:N1}"; CurrentPowerSupply.Text = $"{castState.CurrentPowerSupply.ToString("N1")}";
TargetedPowerSupply.Text = $"{castState.TargetedPowerSupply:N1}"; TargetedPowerSupply.Text = $"{castState.TargetedPowerSupply.ToString("N1")}";
} }
} }
} }

View File

@@ -2,7 +2,6 @@ using Content.Shared.Anomaly;
using Content.Shared.Gravity; using Content.Shared.Gravity;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Anomaly.Ui; namespace Content.Client.Anomaly.Ui;
@@ -19,8 +18,10 @@ public sealed class AnomalyGeneratorBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<AnomalyGeneratorWindow>(); _window = new(Owner);
_window.SetEntity(Owner);
_window.OpenCentered();
_window.OnClose += Close;
_window.OnGenerateButtonPressed += () => _window.OnGenerateButtonPressed += () =>
{ {
@@ -36,5 +37,18 @@ public sealed class AnomalyGeneratorBoundUserInterface : BoundUserInterface
return; return;
_window?.UpdateState(msg); _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));
}
} }

View File

@@ -18,21 +18,17 @@ public sealed partial class AnomalyGeneratorWindow : FancyWindow
public Action? OnGenerateButtonPressed; public Action? OnGenerateButtonPressed;
public AnomalyGeneratorWindow() public AnomalyGeneratorWindow(EntityUid gen)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
EntityView.SetEntity(gen);
EntityView.SpriteOffset = false; EntityView.SpriteOffset = false;
GenerateButton.OnPressed += _ => OnGenerateButtonPressed?.Invoke(); GenerateButton.OnPressed += _ => OnGenerateButtonPressed?.Invoke();
} }
public void SetEntity(EntityUid uid)
{
EntityView.SetEntity(uid);
}
public void UpdateState(AnomalyGeneratorUserInterfaceState state) public void UpdateState(AnomalyGeneratorUserInterfaceState state)
{ {
_cooldownEnd = state.CooldownEndTime; _cooldownEnd = state.CooldownEndTime;

View File

@@ -28,6 +28,8 @@ namespace Content.Client.Arcade
private static readonly Vector2 BlockSize = new(15, 15); private static readonly Vector2 BlockSize = new(15, 15);
private readonly BlockGameBoundUserInterface _owner;
private readonly PanelContainer _mainPanel; private readonly PanelContainer _mainPanel;
private readonly BoxContainer _gameRootContainer; private readonly BoxContainer _gameRootContainer;
@@ -56,11 +58,10 @@ namespace Content.Client.Arcade
private bool _isPlayer = false; private bool _isPlayer = false;
private bool _gameOver = false; private bool _gameOver = false;
public event Action<BlockGamePlayerAction>? OnAction; public BlockGameMenu(BlockGameBoundUserInterface owner)
public BlockGameMenu()
{ {
Title = Loc.GetString("blockgame-menu-title"); Title = Loc.GetString("blockgame-menu-title");
_owner = owner;
MinSize = SetSize = new Vector2(410, 490); MinSize = SetSize = new Vector2(410, 490);
@@ -175,7 +176,7 @@ namespace Content.Client.Arcade
}; };
_newGameButton.OnPressed += (e) => _newGameButton.OnPressed += (e) =>
{ {
OnAction?.Invoke(BlockGamePlayerAction.NewGame); _owner.SendAction(BlockGamePlayerAction.NewGame);
}; };
pauseMenuContainer.AddChild(_newGameButton); pauseMenuContainer.AddChild(_newGameButton);
pauseMenuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) }); pauseMenuContainer.AddChild(new Control { MinSize = new Vector2(1, 10) });
@@ -185,10 +186,7 @@ namespace Content.Client.Arcade
Text = Loc.GetString("blockgame-menu-button-scoreboard"), Text = Loc.GetString("blockgame-menu-button-scoreboard"),
TextAlign = Label.AlignMode.Center TextAlign = Label.AlignMode.Center
}; };
_scoreBoardButton.OnPressed += (e) => _scoreBoardButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.ShowHighscores);
{
OnAction?.Invoke(BlockGamePlayerAction.ShowHighscores);
};
pauseMenuContainer.AddChild(_scoreBoardButton); pauseMenuContainer.AddChild(_scoreBoardButton);
_unpauseButtonMargin = new Control { MinSize = new Vector2(1, 10), Visible = false }; _unpauseButtonMargin = new Control { MinSize = new Vector2(1, 10), Visible = false };
pauseMenuContainer.AddChild(_unpauseButtonMargin); pauseMenuContainer.AddChild(_unpauseButtonMargin);
@@ -201,7 +199,7 @@ namespace Content.Client.Arcade
}; };
_unpauseButton.OnPressed += (e) => _unpauseButton.OnPressed += (e) =>
{ {
OnAction?.Invoke(BlockGamePlayerAction.Unpause); _owner.SendAction(BlockGamePlayerAction.Unpause);
}; };
pauseMenuContainer.AddChild(_unpauseButton); pauseMenuContainer.AddChild(_unpauseButton);
@@ -259,7 +257,7 @@ namespace Content.Client.Arcade
}; };
_finalNewGameButton.OnPressed += (e) => _finalNewGameButton.OnPressed += (e) =>
{ {
OnAction?.Invoke(BlockGamePlayerAction.NewGame); _owner.SendAction(BlockGamePlayerAction.NewGame);
}; };
gameOverMenuContainer.AddChild(_finalNewGameButton); gameOverMenuContainer.AddChild(_finalNewGameButton);
@@ -329,10 +327,7 @@ namespace Content.Client.Arcade
Text = Loc.GetString("blockgame-menu-button-back"), Text = Loc.GetString("blockgame-menu-button-back"),
TextAlign = Label.AlignMode.Center TextAlign = Label.AlignMode.Center
}; };
_highscoreBackButton.OnPressed += (e) => _highscoreBackButton.OnPressed += (e) => _owner.SendAction(BlockGamePlayerAction.Pause);
{
OnAction?.Invoke(BlockGamePlayerAction.Pause);
};
menuContainer.AddChild(_highscoreBackButton); menuContainer.AddChild(_highscoreBackButton);
menuInnerPanel.AddChild(menuContainer); menuInnerPanel.AddChild(menuContainer);
@@ -478,7 +473,7 @@ namespace Content.Client.Arcade
private void TryPause() private void TryPause()
{ {
OnAction?.Invoke(BlockGamePlayerAction.Pause); _owner.SendAction(BlockGamePlayerAction.Pause);
} }
public void SetStarted() public void SetStarted()
@@ -581,19 +576,19 @@ namespace Content.Client.Arcade
return; return;
else if (args.Function == ContentKeyFunctions.ArcadeLeft) else if (args.Function == ContentKeyFunctions.ArcadeLeft)
OnAction?.Invoke(BlockGamePlayerAction.StartLeft); _owner.SendAction(BlockGamePlayerAction.StartLeft);
else if (args.Function == ContentKeyFunctions.ArcadeRight) else if (args.Function == ContentKeyFunctions.ArcadeRight)
OnAction?.Invoke(BlockGamePlayerAction.StartRight); _owner.SendAction(BlockGamePlayerAction.StartRight);
else if (args.Function == ContentKeyFunctions.ArcadeUp) else if (args.Function == ContentKeyFunctions.ArcadeUp)
OnAction?.Invoke(BlockGamePlayerAction.Rotate); _owner.SendAction(BlockGamePlayerAction.Rotate);
else if (args.Function == ContentKeyFunctions.Arcade3) else if (args.Function == ContentKeyFunctions.Arcade3)
OnAction?.Invoke(BlockGamePlayerAction.CounterRotate); _owner.SendAction(BlockGamePlayerAction.CounterRotate);
else if (args.Function == ContentKeyFunctions.ArcadeDown) else if (args.Function == ContentKeyFunctions.ArcadeDown)
OnAction?.Invoke(BlockGamePlayerAction.SoftdropStart); _owner.SendAction(BlockGamePlayerAction.SoftdropStart);
else if (args.Function == ContentKeyFunctions.Arcade2) else if (args.Function == ContentKeyFunctions.Arcade2)
OnAction?.Invoke(BlockGamePlayerAction.Hold); _owner.SendAction(BlockGamePlayerAction.Hold);
else if (args.Function == ContentKeyFunctions.Arcade1) else if (args.Function == ContentKeyFunctions.Arcade1)
OnAction?.Invoke(BlockGamePlayerAction.Harddrop); _owner.SendAction(BlockGamePlayerAction.Harddrop);
} }
protected override void KeyBindUp(GUIBoundKeyEventArgs args) protected override void KeyBindUp(GUIBoundKeyEventArgs args)
@@ -604,11 +599,11 @@ namespace Content.Client.Arcade
return; return;
else if (args.Function == ContentKeyFunctions.ArcadeLeft) else if (args.Function == ContentKeyFunctions.ArcadeLeft)
OnAction?.Invoke(BlockGamePlayerAction.EndLeft); _owner.SendAction(BlockGamePlayerAction.EndLeft);
else if (args.Function == ContentKeyFunctions.ArcadeRight) else if (args.Function == ContentKeyFunctions.ArcadeRight)
OnAction?.Invoke(BlockGamePlayerAction.EndRight); _owner.SendAction(BlockGamePlayerAction.EndRight);
else if (args.Function == ContentKeyFunctions.ArcadeDown) else if (args.Function == ContentKeyFunctions.ArcadeDown)
OnAction?.Invoke(BlockGamePlayerAction.SoftdropEnd); _owner.SendAction(BlockGamePlayerAction.SoftdropEnd);
} }
public void UpdateNextBlock(BlockGameBlock[] blocks) public void UpdateNextBlock(BlockGameBlock[] blocks)

View File

@@ -8,6 +8,8 @@ namespace Content.Client.Arcade
{ {
public sealed class SpaceVillainArcadeMenu : DefaultWindow public sealed class SpaceVillainArcadeMenu : DefaultWindow
{ {
public SpaceVillainArcadeBoundUserInterface Owner { get; set; }
private readonly Label _enemyNameLabel; private readonly Label _enemyNameLabel;
private readonly Label _playerInfoLabel; private readonly Label _playerInfoLabel;
private readonly Label _enemyInfoLabel; private readonly Label _enemyInfoLabel;
@@ -15,13 +17,11 @@ namespace Content.Client.Arcade
private readonly Label _enemyActionLabel; private readonly Label _enemyActionLabel;
private readonly Button[] _gameButtons = new Button[3]; //used to disable/enable all game buttons 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); MinSize = SetSize = new Vector2(300, 225);
Title = Loc.GetString("spacevillain-menu-title"); Title = Loc.GetString("spacevillain-menu-title");
Owner = owner;
var grid = new GridContainer { Columns = 1 }; var grid = new GridContainer { Columns = 1 };
@@ -47,43 +47,32 @@ namespace Content.Client.Arcade
grid.AddChild(_enemyActionLabel); grid.AddChild(_enemyActionLabel);
var buttonGrid = new GridContainer { Columns = 3 }; var buttonGrid = new GridContainer { Columns = 3 };
_gameButtons[0] = new Button() _gameButtons[0] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Attack)
{ {
Text = Loc.GetString("spacevillain-menu-button-attack") Text = Loc.GetString("spacevillain-menu-button-attack")
}; };
_gameButtons[0].OnPressed +=
_ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Attack);
buttonGrid.AddChild(_gameButtons[0]); buttonGrid.AddChild(_gameButtons[0]);
_gameButtons[1] = new Button() _gameButtons[1] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Heal)
{ {
Text = Loc.GetString("spacevillain-menu-button-heal") Text = Loc.GetString("spacevillain-menu-button-heal")
}; };
_gameButtons[1].OnPressed +=
_ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Heal);
buttonGrid.AddChild(_gameButtons[1]); buttonGrid.AddChild(_gameButtons[1]);
_gameButtons[2] = new Button() _gameButtons[2] = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.Recharge)
{ {
Text = Loc.GetString("spacevillain-menu-button-recharge") Text = Loc.GetString("spacevillain-menu-button-recharge")
}; };
_gameButtons[2].OnPressed +=
_ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.Recharge);
buttonGrid.AddChild(_gameButtons[2]); buttonGrid.AddChild(_gameButtons[2]);
centerContainer = new CenterContainer(); centerContainer = new CenterContainer();
centerContainer.AddChild(buttonGrid); centerContainer.AddChild(buttonGrid);
grid.AddChild(centerContainer); grid.AddChild(centerContainer);
var newGame = new Button() var newGame = new ActionButton(Owner, SharedSpaceVillainArcadeComponent.PlayerAction.NewGame)
{ {
Text = Loc.GetString("spacevillain-menu-button-new-game") Text = Loc.GetString("spacevillain-menu-button-new-game")
}; };
newGame.OnPressed += _ => OnPlayerAction?.Invoke(SharedSpaceVillainArcadeComponent.PlayerAction.NewGame);
grid.AddChild(newGame); grid.AddChild(newGame);
Contents.AddChild(grid); Contents.AddChild(grid);
@@ -110,5 +99,23 @@ namespace Content.Client.Arcade
_playerActionLabel.Text = message.PlayerActionMessage; _playerActionLabel.Text = message.PlayerActionMessage;
_enemyActionLabel.Text = message.EnemyActionMessage; _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);
}
}
} }
} }

View File

@@ -1,6 +1,5 @@
using Content.Shared.Arcade; using Content.Shared.Arcade;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Arcade.UI; namespace Content.Client.Arcade.UI;
@@ -16,7 +15,9 @@ public sealed class BlockGameBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<BlockGameMenu>(); _menu = new BlockGameMenu(this);
_menu.OnClose += Close;
_menu.OpenCentered();
} }
protected override void ReceiveMessage(BoundUserInterfaceMessage message) protected override void ReceiveMessage(BoundUserInterfaceMessage message)

View File

@@ -1,5 +1,4 @@
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using static Content.Shared.Arcade.SharedSpaceVillainArcadeComponent; using static Content.Shared.Arcade.SharedSpaceVillainArcadeComponent;
@@ -10,6 +9,8 @@ public sealed class SpaceVillainArcadeBoundUserInterface : BoundUserInterface
{ {
[ViewVariables] private SpaceVillainArcadeMenu? _menu; [ViewVariables] private SpaceVillainArcadeMenu? _menu;
//public SharedSpaceVillainArcadeComponent SpaceVillainArcade;
public SpaceVillainArcadeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) public SpaceVillainArcadeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{ {
SendAction(PlayerAction.RequestData); SendAction(PlayerAction.RequestData);
@@ -24,7 +25,10 @@ public sealed class SpaceVillainArcadeBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<SpaceVillainArcadeMenu>(); _menu = new SpaceVillainArcadeMenu(this);
_menu.OnClose += Close;
_menu.OpenCentered();
} }
protected override void ReceiveMessage(BoundUserInterfaceMessage message) protected override void ReceiveMessage(BoundUserInterfaceMessage message)
@@ -32,4 +36,12 @@ public sealed class SpaceVillainArcadeBoundUserInterface : BoundUserInterface
if (message is SpaceVillainArcadeDataUpdateMessage msg) if (message is SpaceVillainArcadeDataUpdateMessage msg)
_menu?.UpdateInfo(msg); _menu?.UpdateInfo(msg);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
_menu?.Dispose();
}
} }

View File

@@ -2,7 +2,6 @@ using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor; using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Monitor.Components; using Content.Shared.Atmos.Monitor.Components;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Log; using Robust.Shared.Log;
@@ -21,9 +20,16 @@ public sealed class AirAlarmBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<AirAlarmWindow>(); _window = new AirAlarmWindow(this);
_window.SetEntity(Owner);
if (State != null)
{
UpdateState(State);
}
_window.OpenCentered();
_window.OnClose += Close;
_window.AtmosDeviceDataChanged += OnDeviceDataChanged; _window.AtmosDeviceDataChanged += OnDeviceDataChanged;
_window.AtmosDeviceDataCopied += OnDeviceDataCopied; _window.AtmosDeviceDataCopied += OnDeviceDataCopied;
_window.AtmosAlarmThresholdChanged += OnThresholdChanged; _window.AtmosAlarmThresholdChanged += OnThresholdChanged;

View File

@@ -47,7 +47,7 @@ public sealed partial class AirAlarmWindow : FancyWindow
private CheckBox _autoMode => AutoModeCheckBox; private CheckBox _autoMode => AutoModeCheckBox;
public AirAlarmWindow() public AirAlarmWindow(BoundUserInterface owner)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
@@ -95,11 +95,8 @@ public sealed partial class AirAlarmWindow : FancyWindow
_sensors.Clear(); _sensors.Clear();
ResyncAllRequested!.Invoke(); ResyncAllRequested!.Invoke();
}; };
}
public void SetEntity(EntityUid uid) EntityView.SetEntity(owner.Owner);
{
EntityView.SetEntity(uid);
} }
public void UpdateState(AirAlarmUIState state) public void UpdateState(AirAlarmUIState state)

View File

@@ -1,7 +1,6 @@
using Content.Shared.Atmos.Piping.Binary.Components; using Content.Shared.Atmos.Piping.Binary.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI namespace Content.Client.Atmos.UI
{ {
@@ -22,8 +21,14 @@ namespace Content.Client.Atmos.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<GasCanisterWindow>(); _window = new GasCanisterWindow();
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ReleaseValveCloseButtonPressed += OnReleaseValveClosePressed; _window.ReleaseValveCloseButtonPressed += OnReleaseValveClosePressed;
_window.ReleaseValveOpenButtonPressed += OnReleaseValveOpenPressed; _window.ReleaseValveOpenButtonPressed += OnReleaseValveOpenPressed;
_window.ReleasePressureSet += OnReleasePressureSet; _window.ReleasePressureSet += OnReleasePressureSet;

View File

@@ -3,7 +3,6 @@ using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Trinary.Components; using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Localizations; using Content.Shared.Localizations;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI namespace Content.Client.Atmos.UI
{ {
@@ -29,8 +28,14 @@ namespace Content.Client.Atmos.UI
var atmosSystem = EntMan.System<AtmosphereSystem>(); var atmosSystem = EntMan.System<AtmosphereSystem>();
_window = this.CreateWindow<GasFilterWindow>(); _window = new GasFilterWindow(atmosSystem.Gases);
_window.PopulateGasList(atmosSystem.Gases);
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.FilterTransferRateChanged += OnFilterTransferRatePressed; _window.FilterTransferRateChanged += OnFilterTransferRatePressed;

View File

@@ -26,9 +26,10 @@ namespace Content.Client.Atmos.UI
public event Action<string>? FilterTransferRateChanged; public event Action<string>? FilterTransferRateChanged;
public event Action? SelectGasPressed; public event Action? SelectGasPressed;
public GasFilterWindow() public GasFilterWindow(IEnumerable<GasPrototype> gases)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
PopulateGasList(gases);
ToggleStatusButton.OnPressed += _ => SetFilterStatus(!FilterStatus); ToggleStatusButton.OnPressed += _ => SetFilterStatus(!FilterStatus);
ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke(); ToggleStatusButton.OnPressed += _ => ToggleStatusButtonPressed?.Invoke();
@@ -72,7 +73,7 @@ namespace Content.Client.Atmos.UI
SelectGasButton.Disabled = true; SelectGasButton.Disabled = true;
} }
public void PopulateGasList(IEnumerable<GasPrototype> gases) private void PopulateGasList(IEnumerable<GasPrototype> gases)
{ {
GasList.Add(new ItemList.Item(GasList) GasList.Add(new ItemList.Item(GasList)
{ {
@@ -80,7 +81,7 @@ namespace Content.Client.Atmos.UI
Text = Loc.GetString("comp-gas-filter-ui-filter-gas-none") Text = Loc.GetString("comp-gas-filter-ui-filter-gas-none")
}); });
foreach (var gas in gases) foreach (GasPrototype gas in gases)
{ {
var gasName = Loc.GetString(gas.Name); var gasName = Loc.GetString(gas.Name);
GasList.Add(GetGasItem(gas.ID, gasName, GasList)); GasList.Add(GetGasItem(gas.ID, gasName, GasList));

View File

@@ -2,7 +2,7 @@ using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Trinary.Components; using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Localizations; using Content.Shared.Localizations;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface; using Robust.Client.GameObjects;
namespace Content.Client.Atmos.UI namespace Content.Client.Atmos.UI
{ {
@@ -26,7 +26,14 @@ namespace Content.Client.Atmos.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<GasMixerWindow>(); _window = new GasMixerWindow();
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.MixerOutputPressureChanged += OnMixerOutputPressurePressed; _window.MixerOutputPressureChanged += OnMixerOutputPressurePressed;
@@ -76,5 +83,12 @@ namespace Content.Client.Atmos.UI
_window.SetOutputPressure(cast.OutputPressure); _window.SetOutputPressure(cast.OutputPressure);
_window.SetNodePercentages(cast.NodeOne); _window.SetNodePercentages(cast.NodeOne);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
} }
} }

View File

@@ -3,7 +3,6 @@ using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Localizations; using Content.Shared.Localizations;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI namespace Content.Client.Atmos.UI
{ {
@@ -27,7 +26,14 @@ namespace Content.Client.Atmos.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<GasPressurePumpWindow>(); _window = new GasPressurePumpWindow();
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.PumpOutputPressureChanged += OnPumpOutputPressurePressed; _window.PumpOutputPressureChanged += OnPumpOutputPressurePressed;
@@ -61,5 +67,12 @@ namespace Content.Client.Atmos.UI
_window.SetPumpStatus(cast.Enabled); _window.SetPumpStatus(cast.Enabled);
_window.SetOutputPressure(cast.OutputPressure); _window.SetOutputPressure(cast.OutputPressure);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
} }
} }

View File

@@ -2,7 +2,6 @@
using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.Atmos.Piping.Unary.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI namespace Content.Client.Atmos.UI
{ {
@@ -32,7 +31,14 @@ namespace Content.Client.Atmos.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<GasThermomachineWindow>(); _window = new GasThermomachineWindow();
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed(); _window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed();
_window.TemperatureSpinbox.OnValueChanged += _ => OnTemperatureChanged(_window.TemperatureSpinbox.Value); _window.TemperatureSpinbox.OnValueChanged += _ => OnTemperatureChanged(_window.TemperatureSpinbox.Value);
@@ -85,5 +91,12 @@ namespace Content.Client.Atmos.UI
true => Loc.GetString("comp-gas-thermomachine-ui-title-heater") true => Loc.GetString("comp-gas-thermomachine-ui-title-heater")
}; };
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
} }
} }

View File

@@ -3,7 +3,6 @@ using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Localizations; using Content.Shared.Localizations;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Atmos.UI namespace Content.Client.Atmos.UI
{ {
@@ -27,7 +26,14 @@ namespace Content.Client.Atmos.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<GasVolumePumpWindow>(); _window = new GasVolumePumpWindow();
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed; _window.ToggleStatusButtonPressed += OnToggleStatusButtonPressed;
_window.PumpTransferRateChanged += OnPumpTransferRatePressed; _window.PumpTransferRateChanged += OnPumpTransferRatePressed;
@@ -58,9 +64,16 @@ namespace Content.Client.Atmos.UI
if (_window == null || state is not GasVolumePumpBoundUserInterfaceState cast) if (_window == null || state is not GasVolumePumpBoundUserInterfaceState cast)
return; return;
_window.Title = cast.PumpLabel; _window.Title = (cast.PumpLabel);
_window.SetPumpStatus(cast.Enabled); _window.SetPumpStatus(cast.Enabled);
_window.SetTransferRate(cast.TransferRate); _window.SetTransferRate(cast.TransferRate);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
} }
} }

View File

@@ -1,6 +1,5 @@
using Content.Shared.Atmos.Piping.Portable.Components; using Content.Shared.Atmos.Piping.Portable.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
namespace Content.Client.Atmos.UI; namespace Content.Client.Atmos.UI;
@@ -22,7 +21,14 @@ public sealed class SpaceHeaterBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<SpaceHeaterWindow>(); _window = new SpaceHeaterWindow();
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed(); _window.ToggleStatusButton.OnPressed += _ => OnToggleStatusButtonPressed();
_window.IncreaseTempRange.OnPressed += _ => OnTemperatureRangeChanged(_window.TemperatureChangeDelta); _window.IncreaseTempRange.OnPressed += _ => OnTemperatureRangeChanged(_window.TemperatureChangeDelta);

View File

@@ -1,7 +1,8 @@
using Content.Shared.Audio.Jukebox; using Content.Shared.Audio.Jukebox;
using Robust.Client.Audio; using Robust.Client.Audio;
using Robust.Client.UserInterface; using Robust.Client.Player;
using Robust.Shared.Audio.Components; using Robust.Shared.Audio.Components;
using Robust.Shared.Player;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Client.Audio.Jukebox; namespace Content.Client.Audio.Jukebox;
@@ -22,7 +23,9 @@ public sealed class JukeboxBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<JukeboxMenu>(); _menu = new JukeboxMenu();
_menu.OnClose += Close;
_menu.OpenCentered();
_menu.OnPlayPressed += args => _menu.OnPlayPressed += args =>
{ {
@@ -97,5 +100,19 @@ public sealed class JukeboxBoundUserInterface : BoundUserInterface
SendMessage(new JukeboxSetTimeMessage(sentTime)); 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;
}
} }

View File

@@ -1,6 +1,5 @@
using Content.Shared.Bed.Cryostorage; using Content.Shared.Bed.Cryostorage;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Bed.Cryostorage; namespace Content.Client.Bed.Cryostorage;
@@ -18,7 +17,9 @@ public sealed class CryostorageBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<CryostorageMenu>(); _menu = new();
_menu.OnClose += Close;
_menu.SlotRemoveButtonPressed += (ent, slot) => _menu.SlotRemoveButtonPressed += (ent, slot) =>
{ {
@@ -29,6 +30,8 @@ public sealed class CryostorageBoundUserInterface : BoundUserInterface
{ {
SendMessage(new CryostorageRemoveItemBuiMessage(ent, hand, CryostorageRemoveItemBuiMessage.RemovalType.Hand)); SendMessage(new CryostorageRemoveItemBuiMessage(ent, hand, CryostorageRemoveItemBuiMessage.RemovalType.Hand));
}; };
_menu.OpenCentered();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -42,4 +45,12 @@ public sealed class CryostorageBoundUserInterface : BoundUserInterface
break; break;
} }
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
} }

View File

@@ -1,7 +1,6 @@
using Content.Client.Cargo.UI; using Content.Client.Cargo.UI;
using Content.Shared.Cargo.Components; using Content.Shared.Cargo.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Cargo.BUI; namespace Content.Client.Cargo.BUI;
@@ -19,7 +18,9 @@ public sealed class CargoBountyConsoleBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<CargoBountyMenu>(); _menu = new();
_menu.OnClose += Close;
_menu.OnLabelButtonPressed += id => _menu.OnLabelButtonPressed += id =>
{ {
@@ -30,6 +31,8 @@ public sealed class CargoBountyConsoleBoundUserInterface : BoundUserInterface
{ {
SendMessage(new BountySkipMessage(id)); SendMessage(new BountySkipMessage(id));
}; };
_menu.OpenCentered();
} }
protected override void UpdateState(BoundUserInterfaceState message) protected override void UpdateState(BoundUserInterfaceState message)
@@ -41,4 +44,14 @@ public sealed class CargoBountyConsoleBoundUserInterface : BoundUserInterface
_menu?.UpdateEntries(state.Bounties, state.UntilNextSkip); _menu?.UpdateEntries(state.Bounties, state.UntilNextSkip);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
} }

View File

@@ -2,7 +2,6 @@ using Content.Client.Cargo.UI;
using Content.Shared.Cargo.BUI; using Content.Shared.Cargo.BUI;
using Content.Shared.Cargo.Events; using Content.Shared.Cargo.Events;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Cargo.BUI; namespace Content.Client.Cargo.BUI;
@@ -19,9 +18,21 @@ public sealed class CargoPalletConsoleBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<CargoPalletMenu>(); _menu = new CargoPalletMenu();
_menu.AppraiseRequested += OnAppraisal; _menu.AppraiseRequested += OnAppraisal;
_menu.SellRequested += OnSell; _menu.SellRequested += OnSell;
_menu.OnClose += Close;
_menu.OpenCentered();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Dispose();
}
} }
private void OnAppraisal() private void OnAppraisal()

View File

@@ -2,7 +2,6 @@ using Content.Client.Cargo.UI;
using Content.Shared.Cargo.BUI; using Content.Shared.Cargo.BUI;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Client.Cargo.BUI; namespace Content.Client.Cargo.BUI;
@@ -10,8 +9,6 @@ namespace Content.Client.Cargo.BUI;
[UsedImplicitly] [UsedImplicitly]
public sealed class CargoShuttleConsoleBoundUserInterface : BoundUserInterface public sealed class CargoShuttleConsoleBoundUserInterface : BoundUserInterface
{ {
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[ViewVariables] [ViewVariables]
private CargoShuttleMenu? _menu; private CargoShuttleMenu? _menu;
@@ -22,7 +19,24 @@ public sealed class CargoShuttleConsoleBoundUserInterface : BoundUserInterface
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<CargoShuttleMenu>(); 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();
}
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -31,6 +45,6 @@ public sealed class CargoShuttleConsoleBoundUserInterface : BoundUserInterface
if (state is not CargoShuttleConsoleBoundUserInterfaceState cargoState) return; if (state is not CargoShuttleConsoleBoundUserInterfaceState cargoState) return;
_menu?.SetAccountName(cargoState.AccountName); _menu?.SetAccountName(cargoState.AccountName);
_menu?.SetShuttleName(cargoState.ShuttleName); _menu?.SetShuttleName(cargoState.ShuttleName);
_menu?.SetOrders(EntMan.System<SpriteSystem>(), _protoManager, cargoState.Orders); _menu?.SetOrders(cargoState.Orders);
} }
} }

View File

@@ -12,9 +12,14 @@ namespace Content.Client.Cargo.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class CargoShuttleMenu : FancyWindow public sealed partial class CargoShuttleMenu : FancyWindow
{ {
public CargoShuttleMenu() private readonly IPrototypeManager _protoManager;
private readonly SpriteSystem _spriteSystem;
public CargoShuttleMenu(IPrototypeManager protoManager, SpriteSystem spriteSystem)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
_protoManager = protoManager;
_spriteSystem = spriteSystem;
Title = Loc.GetString("cargo-shuttle-console-menu-title"); Title = Loc.GetString("cargo-shuttle-console-menu-title");
} }
@@ -28,19 +33,19 @@ namespace Content.Client.Cargo.UI
ShuttleNameLabel.Text = name; ShuttleNameLabel.Text = name;
} }
public void SetOrders(SpriteSystem sprites, IPrototypeManager protoManager, List<CargoOrderData> orders) public void SetOrders(List<CargoOrderData> orders)
{ {
Orders.DisposeAllChildren(); Orders.DisposeAllChildren();
foreach (var order in orders) foreach (var order in orders)
{ {
var product = protoManager.Index<EntityPrototype>(order.ProductId); var product = _protoManager.Index<EntityPrototype>(order.ProductId);
var productName = product.Name; var productName = product.Name;
var row = new CargoOrderRow var row = new CargoOrderRow
{ {
Order = order, Order = order,
Icon = { Texture = sprites.Frame0(product) }, Icon = { Texture = _spriteSystem.Frame0(product) },
ProductName = ProductName =
{ {
Text = Loc.GetString( Text = Loc.GetString(

View File

@@ -2,7 +2,6 @@ using Content.Shared.Chemistry;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Chemistry.UI namespace Content.Client.Chemistry.UI
{ {
@@ -28,8 +27,13 @@ namespace Content.Client.Chemistry.UI
base.Open(); base.Open();
// Setup window layout/elements // Setup window layout/elements
_window = this.CreateWindow<ChemMasterWindow>(); _window = new ChemMasterWindow
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName; {
Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
};
_window.OpenCentered();
_window.OnClose += Close;
// Setup static button actions. // Setup static button actions.
_window.InputEjectButton.OnPressed += _ => SendMessage( _window.InputEjectButton.OnPressed += _ => SendMessage(
@@ -71,5 +75,15 @@ namespace Content.Client.Chemistry.UI
_window?.UpdateState(castState); // Update window state _window?.UpdateState(castState); // Update window state
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
}
}
} }
} }

View File

@@ -3,7 +3,6 @@ using Content.Shared.Chemistry;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Chemistry.UI namespace Content.Client.Chemistry.UI
{ {
@@ -16,6 +15,9 @@ namespace Content.Client.Chemistry.UI
[ViewVariables] [ViewVariables]
private ReagentDispenserWindow? _window; private ReagentDispenserWindow? _window;
[ViewVariables]
private ReagentDispenserBoundUserInterfaceState? _lastState;
public ReagentDispenserBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) public ReagentDispenserBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{ {
} }
@@ -30,9 +32,14 @@ namespace Content.Client.Chemistry.UI
base.Open(); base.Open();
// Setup window layout/elements // Setup window layout/elements
_window = this.CreateWindow<ReagentDispenserWindow>(); _window = new()
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName; {
_window.HelpGuidebookIds = EntMan.GetComponent<GuideHelpComponent>(Owner).Guides; Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
HelpGuidebookIds = EntMan.GetComponent<GuideHelpComponent>(Owner).Guides
};
_window.OpenCentered();
_window.OnClose += Close;
// Setup static button actions. // Setup static button actions.
_window.EjectButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(SharedReagentDispenser.OutputSlotName)); _window.EjectButton.OnPressed += _ => SendMessage(new ItemSlotButtonPressedEvent(SharedReagentDispenser.OutputSlotName));
@@ -56,7 +63,19 @@ namespace Content.Client.Chemistry.UI
base.UpdateState(state); base.UpdateState(state);
var castState = (ReagentDispenserBoundUserInterfaceState) state; var castState = (ReagentDispenserBoundUserInterfaceState) state;
_lastState = castState;
_window?.UpdateState(castState); //Update window state _window?.UpdateState(castState); //Update window state
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
}
}
} }
} }

View File

@@ -2,7 +2,6 @@ using Content.Shared.Chemistry;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Chemistry.UI namespace Content.Client.Chemistry.UI
{ {
@@ -19,7 +18,7 @@ namespace Content.Client.Chemistry.UI
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window = this.CreateWindow<TransferAmountWindow>(); _window = new TransferAmountWindow();
_window.ApplyButton.OnPressed += _ => _window.ApplyButton.OnPressed += _ =>
{ {
@@ -29,6 +28,15 @@ namespace Content.Client.Chemistry.UI
_window.Close(); _window.Close();
} }
}; };
_window.OnClose += Close;
_window.OpenCentered();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
} }
} }
} }

View File

@@ -1,7 +1,6 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Content.Shared.Cloning.CloningConsole; using Content.Shared.Cloning.CloningConsole;
using Robust.Client.UserInterface;
namespace Content.Client.CloningConsole.UI namespace Content.Client.CloningConsole.UI
{ {
@@ -18,11 +17,13 @@ namespace Content.Client.CloningConsole.UI
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window = new CloningConsoleWindow
_window = this.CreateWindow<CloningConsoleWindow>(); {
_window.Title = Loc.GetString("cloning-console-window-title"); Title = Loc.GetString("cloning-console-window-title")
};
_window.OnClose += Close;
_window.CloneButton.OnPressed += _ => SendMessage(new UiButtonPressedMessage(UiButton.Clone)); _window.CloneButton.OnPressed += _ => SendMessage(new UiButtonPressedMessage(UiButton.Clone));
_window.OpenCentered();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -31,5 +32,19 @@ namespace Content.Client.CloningConsole.UI
_window?.Populate((CloningConsoleBoundUserInterfaceState) 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();
}
} }
} }

View File

@@ -2,7 +2,6 @@
using Content.Shared.Clothing.Components; using Content.Shared.Clothing.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Clothing.UI; namespace Content.Client.Clothing.UI;
@@ -23,8 +22,10 @@ public sealed class ChameleonBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<ChameleonMenu>(); _menu = new ChameleonMenu();
_menu.OnClose += Close;
_menu.OnIdSelected += OnIdSelected; _menu.OnIdSelected += OnIdSelected;
_menu.OpenCentered();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -41,4 +42,15 @@ public sealed class ChameleonBoundUserInterface : BoundUserInterface
{ {
SendMessage(new ChameleonPrototypeSelectedMessage(selectedId)); SendMessage(new ChameleonPrototypeSelectedMessage(selectedId));
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Close();
_menu = null;
}
}
} }

View File

@@ -1,7 +1,6 @@
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.Chat; using Content.Shared.Chat;
using Content.Shared.Communications; using Content.Shared.Communications;
using Robust.Client.UserInterface;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -9,11 +8,34 @@ namespace Content.Client.Communications.UI
{ {
public sealed class CommunicationsConsoleBoundUserInterface : BoundUserInterface public sealed class CommunicationsConsoleBoundUserInterface : BoundUserInterface
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IConfigurationManager _cfg = default!;
[ViewVariables] [ViewVariables]
private CommunicationsConsoleMenu? _menu; 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) public CommunicationsConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{ {
} }
@@ -22,25 +44,23 @@ namespace Content.Client.Communications.UI
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<CommunicationsConsoleMenu>(); _menu = new CommunicationsConsoleMenu(this);
_menu.OnAnnounce += AnnounceButtonPressed; _menu.OnClose += Close;
_menu.OnBroadcast += BroadcastButtonPressed; _menu.OpenCentered();
_menu.OnAlertLevel += AlertLevelSelected;
_menu.OnEmergencyLevel += EmergencyShuttleButtonPressed;
} }
public void AlertLevelSelected(string level) public void AlertLevelSelected(string level)
{ {
if (_menu!.AlertLevelSelectable) if (AlertLevelSelectable)
{ {
_menu.CurrentLevel = level; CurrentLevel = level;
SendMessage(new CommunicationsConsoleSelectAlertLevelMessage(level)); SendMessage(new CommunicationsConsoleSelectAlertLevelMessage(level));
} }
} }
public void EmergencyShuttleButtonPressed() public void EmergencyShuttleButtonPressed()
{ {
if (_menu!.CountdownStarted) if (CountdownStarted)
RecallShuttle(); RecallShuttle();
else else
CallShuttle(); CallShuttle();
@@ -75,23 +95,31 @@ namespace Content.Client.Communications.UI
if (state is not CommunicationsConsoleInterfaceState commsState) if (state is not CommunicationsConsoleInterfaceState commsState)
return; 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) 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.UpdateCountdown();
_menu.UpdateAlertLevels(commsState.AlertLevels, _menu.CurrentLevel); _menu.UpdateAlertLevels(commsState.AlertLevels, CurrentLevel);
_menu.AlertLevelButton.Disabled = !_menu.AlertLevelSelectable; _menu.AlertLevelButton.Disabled = !AlertLevelSelectable;
_menu.EmergencyShuttleButton.Disabled = !_menu.CanCall; _menu.EmergencyShuttleButton.Disabled = !CanCall;
_menu.AnnounceButton.Disabled = !_menu.CanAnnounce; _menu.AnnounceButton.Disabled = !CanAnnounce;
_menu.BroadcastButton.Disabled = !_menu.CanBroadcast; _menu.BroadcastButton.Disabled = !CanBroadcast;
} }
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_menu?.Dispose();
} }
} }
} }

View File

@@ -1,40 +1,31 @@
using System.Globalization; using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Controls; using System.Threading;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Timer = Robust.Shared.Timing.Timer;
namespace Content.Client.Communications.UI namespace Content.Client.Communications.UI
{ {
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class CommunicationsConsoleMenu : FancyWindow public sealed partial class CommunicationsConsoleMenu : FancyWindow
{ {
private CommunicationsConsoleBoundUserInterface Owner { get; set; }
private readonly CancellationTokenSource _timerCancelTokenSource = new();
[Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;
public bool CanAnnounce; public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
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); IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
MessageInput.Placeholder = new Rope.Leaf(_loc.GetString("comms-console-menu-announcement-placeholder")); Owner = owner;
var loc = IoCManager.Resolve<ILocalizationManager>();
MessageInput.Placeholder = new Rope.Leaf(loc.GetString("comms-console-menu-announcement-placeholder"));
var maxAnnounceLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength); var maxAnnounceLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
MessageInput.OnTextChanged += (args) => MessageInput.OnTextChanged += (args) =>
@@ -46,38 +37,33 @@ namespace Content.Client.Communications.UI
} }
else else
{ {
AnnounceButton.Disabled = !CanAnnounce; AnnounceButton.Disabled = !owner.CanAnnounce;
AnnounceButton.ToolTip = null; AnnounceButton.ToolTip = null;
} }
}; };
AnnounceButton.OnPressed += _ => OnAnnounce?.Invoke(Rope.Collapse(MessageInput.TextRope)); AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(Rope.Collapse(MessageInput.TextRope));
AnnounceButton.Disabled = !CanAnnounce; AnnounceButton.Disabled = !owner.CanAnnounce;
BroadcastButton.OnPressed += _ => OnBroadcast?.Invoke(Rope.Collapse(MessageInput.TextRope)); BroadcastButton.OnPressed += (_) => Owner.BroadcastButtonPressed(Rope.Collapse(MessageInput.TextRope));
BroadcastButton.Disabled = !CanBroadcast; BroadcastButton.Disabled = !owner.CanBroadcast;
AlertLevelButton.OnItemSelected += args => AlertLevelButton.OnItemSelected += args =>
{ {
var metadata = AlertLevelButton.GetItemMetadata(args.Id); var metadata = AlertLevelButton.GetItemMetadata(args.Id);
if (metadata != null && metadata is string cast) if (metadata != null && metadata is string cast)
{ {
OnAlertLevel?.Invoke(cast); Owner.AlertLevelSelected(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(); UpdateCountdown();
Timer.SpawnRepeating(1000, UpdateCountdown, _timerCancelTokenSource.Token);
} }
// The current alert could make levels unselectable, so we need to ensure that the UI reacts properly. // The current alert could make levels unselectable, so we need to ensure that the UI reacts properly.
@@ -119,19 +105,32 @@ namespace Content.Client.Communications.UI
public void UpdateCountdown() public void UpdateCountdown()
{ {
if (!CountdownStarted) if (!Owner.CountdownStarted)
{ {
CountdownLabel.SetMessage(string.Empty); CountdownLabel.SetMessage("");
EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-call-shuttle"); EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-call-shuttle");
return; return;
} }
var diff = (CountdownEnd - _timing.CurTime) ?? TimeSpan.Zero;
EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-recall-shuttle"); EmergencyShuttleButton.Text = Loc.GetString("comms-console-menu-recall-shuttle");
var infoText = Loc.GetString($"comms-console-menu-time-remaining", var infoText = Loc.GetString($"comms-console-menu-time-remaining",
("time", diff.TotalSeconds.ToString(CultureInfo.CurrentCulture))); ("time", Owner.Countdown.ToString()));
CountdownLabel.SetMessage(infoText); CountdownLabel.SetMessage(infoText);
} }
public override void Close()
{
base.Close();
_timerCancelTokenSource.Cancel();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
_timerCancelTokenSource.Cancel();
}
} }
} }

View File

@@ -1,5 +1,4 @@
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
namespace Content.Client.Computer namespace Content.Client.Computer
@@ -20,8 +19,10 @@ namespace Content.Client.Computer
{ {
base.Open(); base.Open();
_window = this.CreateWindow<TWindow>(); _window = (TWindow) _dynamicTypeFactory.CreateInstance(typeof(TWindow));
_window.SetupComputerWindow(this); _window.SetupComputerWindow(this);
_window.OnClose += Close;
_window.OpenCentered();
} }
// Alas, this constructor has to be copied to the subclass. :( // Alas, this constructor has to be copied to the subclass. :(
@@ -41,6 +42,16 @@ namespace Content.Client.Computer
_window.UpdateState((TState) state); _window.UpdateState((TState) state);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
}
}
protected override void ReceiveMessage(BoundUserInterfaceMessage message) protected override void ReceiveMessage(BoundUserInterfaceMessage message)
{ {
_window?.ReceiveMessage(message); _window?.ReceiveMessage(message);

View File

@@ -1,6 +1,5 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using static Content.Shared.Configurable.ConfigurationComponent; using static Content.Shared.Configurable.ConfigurationComponent;
namespace Content.Client.Configurable.UI namespace Content.Client.Configurable.UI
@@ -10,6 +9,9 @@ namespace Content.Client.Configurable.UI
[ViewVariables] [ViewVariables]
private ConfigurationMenu? _menu; private ConfigurationMenu? _menu;
[ViewVariables]
public Regex? Validation { get; internal set; }
public ConfigurationBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) public ConfigurationBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{ {
} }
@@ -17,8 +19,10 @@ namespace Content.Client.Configurable.UI
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<ConfigurationMenu>(); _menu = new ConfigurationMenu(this);
_menu.OnConfiguration += SendConfiguration;
_menu.OnClose += Close;
_menu.OpenCentered();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -26,7 +30,9 @@ namespace Content.Client.Configurable.UI
base.UpdateState(state); base.UpdateState(state);
if (state is not ConfigurationBoundUserInterfaceState configurationState) if (state is not ConfigurationBoundUserInterfaceState configurationState)
{
return; return;
}
_menu?.Populate(configurationState); _menu?.Populate(configurationState);
} }
@@ -35,12 +41,9 @@ namespace Content.Client.Configurable.UI
{ {
base.ReceiveMessage(message); base.ReceiveMessage(message);
if (_menu == null)
return;
if (message is ValidationUpdateMessage msg) if (message is ValidationUpdateMessage msg)
{ {
_menu.Validation = new Regex(msg.ValidationString, RegexOptions.Compiled); Validation = new Regex(msg.ValidationString, RegexOptions.Compiled);
} }
} }
@@ -48,5 +51,16 @@ namespace Content.Client.Configurable.UI
{ {
SendMessage(new ConfigurationUpdatedMessage(config)); SendMessage(new ConfigurationUpdatedMessage(config));
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing && _menu != null)
{
_menu.OnClose -= Close;
_menu.Close();
}
}
} }
} }

View File

@@ -1,6 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using System.Text.RegularExpressions;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
@@ -14,25 +13,23 @@ namespace Content.Client.Configurable.UI
{ {
public sealed class ConfigurationMenu : DefaultWindow public sealed class ConfigurationMenu : DefaultWindow
{ {
public ConfigurationBoundUserInterface Owner { get; }
private readonly BoxContainer _column; private readonly BoxContainer _column;
private readonly BoxContainer _row; private readonly BoxContainer _row;
private readonly List<(string name, LineEdit input)> _inputs; private readonly List<(string name, LineEdit input)> _inputs;
[ViewVariables] public ConfigurationMenu(ConfigurationBoundUserInterface owner)
public Regex? Validation { get; internal set; }
public event Action<Dictionary<string, string>>? OnConfiguration;
public ConfigurationMenu()
{ {
MinSize = SetSize = new Vector2(300, 250); MinSize = SetSize = new Vector2(300, 250);
Owner = owner;
_inputs = new List<(string name, LineEdit input)>(); _inputs = new List<(string name, LineEdit input)>();
Title = Loc.GetString("configuration-menu-device-title"); Title = Loc.GetString("configuration-menu-device-title");
var baseContainer = new BoxContainer BoxContainer baseContainer = new BoxContainer
{ {
Orientation = LayoutOrientation.Vertical, Orientation = LayoutOrientation.Vertical,
VerticalExpand = true, VerticalExpand = true,
@@ -119,13 +116,14 @@ namespace Content.Client.Configurable.UI
private void OnConfirm(ButtonEventArgs args) private void OnConfirm(ButtonEventArgs args)
{ {
var config = GenerateDictionary(_inputs, "Text"); var config = GenerateDictionary(_inputs, "Text");
OnConfiguration?.Invoke(config);
Owner.SendConfiguration(config);
Close(); Close();
} }
private bool Validate(string value) private bool Validate(string value)
{ {
return Validation?.IsMatch(value) != false; return Owner.Validation == null || Owner.Validation.IsMatch(value);
} }
private Dictionary<string, string> GenerateDictionary(IEnumerable<(string name, LineEdit input)> inputs, string propertyName) private Dictionary<string, string> GenerateDictionary(IEnumerable<(string name, LineEdit input)> inputs, string propertyName)

View File

@@ -1,6 +1,5 @@
using Content.Shared.Construction.Components; using Content.Shared.Construction.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Construction.UI namespace Content.Client.Construction.UI
{ {
@@ -18,8 +17,8 @@ namespace Content.Client.Construction.UI
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<FlatpackCreatorMenu>(); _menu = new FlatpackCreatorMenu(Owner);
_menu.SetEntity(Owner); _menu.OnClose += Close;
_menu.PackButtonPressed += () => _menu.PackButtonPressed += () =>
{ {
@@ -28,5 +27,14 @@ namespace Content.Client.Construction.UI
_menu.OpenCentered(); _menu.OpenCentered();
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
} }
} }

View File

@@ -24,7 +24,7 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
private readonly FlatpackSystem _flatpack; private readonly FlatpackSystem _flatpack;
private readonly MaterialStorageSystem _materialStorage; private readonly MaterialStorageSystem _materialStorage;
private EntityUid _owner; private readonly EntityUid _owner;
[ValidatePrototypeId<EntityPrototype>] [ValidatePrototypeId<EntityPrototype>]
public const string NoBoardEffectId = "FlatpackerNoBoardEffect"; public const string NoBoardEffectId = "FlatpackerNoBoardEffect";
@@ -33,7 +33,7 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
public event Action? PackButtonPressed; public event Action? PackButtonPressed;
public FlatpackCreatorMenu() public FlatpackCreatorMenu(EntityUid uid)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
@@ -42,15 +42,12 @@ public sealed partial class FlatpackCreatorMenu : FancyWindow
_flatpack = _entityManager.System<FlatpackSystem>(); _flatpack = _entityManager.System<FlatpackSystem>();
_materialStorage = _entityManager.System<MaterialStorageSystem>(); _materialStorage = _entityManager.System<MaterialStorageSystem>();
_owner = uid;
PackButton.OnPressed += _ => PackButtonPressed?.Invoke(); PackButton.OnPressed += _ => PackButtonPressed?.Invoke();
InsertLabel.SetMarkup(Loc.GetString("flatpacker-ui-insert-board"));
}
public void SetEntity(EntityUid uid)
{
_owner = uid;
MaterialStorageControl.SetOwner(uid); MaterialStorageControl.SetOwner(uid);
InsertLabel.SetMarkup(Loc.GetString("flatpacker-ui-insert-board"));
} }
protected override void FrameUpdate(FrameEventArgs args) protected override void FrameUpdate(FrameEventArgs args)

View File

@@ -2,15 +2,12 @@
using Content.Shared.Crayon; using Content.Shared.Crayon;
using Content.Shared.Decals; using Content.Shared.Decals;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Client.Crayon.UI namespace Content.Client.Crayon.UI
{ {
public sealed class CrayonBoundUserInterface : BoundUserInterface public sealed class CrayonBoundUserInterface : BoundUserInterface
{ {
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[ViewVariables] [ViewVariables]
private CrayonWindow? _menu; private CrayonWindow? _menu;
@@ -21,29 +18,15 @@ namespace Content.Client.Crayon.UI
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<CrayonWindow>(); _menu = new CrayonWindow(this);
_menu.OnColorSelected += SelectColor;
_menu.OnSelected += Select; _menu.OnClose += Close;
PopulateCrayons(); var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var crayonDecals = prototypeManager.EnumeratePrototypes<DecalPrototype>().Where(x => x.Tags.Contains("crayon"));
_menu.Populate(crayonDecals);
_menu.OpenCenteredLeft(); _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) protected override void UpdateState(BoundUserInterfaceState state)
{ {
base.UpdateState(state); base.UpdateState(state);
@@ -60,5 +43,16 @@ namespace Content.Client.Crayon.UI
{ {
SendMessage(new CrayonColorMessage(color)); SendMessage(new CrayonColorMessage(color));
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Close();
_menu = null;
}
}
} }
} }

View File

@@ -18,17 +18,18 @@ namespace Content.Client.Crayon.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class CrayonWindow : DefaultWindow public sealed partial class CrayonWindow : DefaultWindow
{ {
public CrayonBoundUserInterface Owner { get; }
private Dictionary<string, Texture>? _decals; private Dictionary<string, Texture>? _decals;
private string? _selected; private string? _selected;
private Color _color; private Color _color;
public event Action<Color>? OnColorSelected; public CrayonWindow(CrayonBoundUserInterface owner)
public event Action<string>? OnSelected;
public CrayonWindow()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
Owner = owner;
Search.OnTextChanged += _ => RefreshList(); Search.OnTextChanged += _ => RefreshList();
ColorSelector.OnColorChanged += SelectColor; ColorSelector.OnColorChanged += SelectColor;
} }
@@ -37,16 +38,16 @@ namespace Content.Client.Crayon.UI
{ {
_color = color; _color = color;
OnColorSelected?.Invoke(color); Owner.SelectColor(color);
RefreshList(); RefreshList();
} }
private void RefreshList() private void RefreshList()
{ {
// Clear // Clear
Grid.DisposeAllChildren(); Grid.RemoveAllChildren();
if (_decals == null) if (_decals == null) return;
return;
var filter = Search.Text; var filter = Search.Text;
foreach (var (decal, tex) in _decals) foreach (var (decal, tex) in _decals)
@@ -88,6 +89,7 @@ namespace Content.Client.Crayon.UI
{ {
if (obj.Button.Name == null) return; if (obj.Button.Name == null) return;
Owner.Select(obj.Button.Name);
_selected = obj.Button.Name; _selected = obj.Button.Name;
RefreshList(); RefreshList();
} }

View File

@@ -1,6 +1,5 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent; using static Content.Shared.Disposal.Components.SharedDisposalRouterComponent;
namespace Content.Client.Disposal.UI namespace Content.Client.Disposal.UI
@@ -22,16 +21,20 @@ namespace Content.Client.Disposal.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<DisposalRouterWindow>(); _window = new DisposalRouterWindow();
_window.OpenCentered();
_window.OnClose += Close;
_window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text); _window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text);
_window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text); _window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text);
} }
private void ButtonPressed(UiAction action, string tag) private void ButtonPressed(UiAction action, string tag)
{ {
SendMessage(new UiActionMessage(action, tag)); SendMessage(new UiActionMessage(action, tag));
Close(); _window?.Close();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -45,5 +48,18 @@ namespace Content.Client.Disposal.UI
_window?.UpdateState(cast); _window?.UpdateState(cast);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
} }
} }
}
}

View File

@@ -1,6 +1,5 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using static Content.Shared.Disposal.Components.SharedDisposalTaggerComponent; using static Content.Shared.Disposal.Components.SharedDisposalTaggerComponent;
namespace Content.Client.Disposal.UI namespace Content.Client.Disposal.UI
@@ -22,17 +21,20 @@ namespace Content.Client.Disposal.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<DisposalTaggerWindow>(); _window = new DisposalTaggerWindow();
_window.OpenCentered();
_window.OnClose += Close;
_window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text); _window.Confirm.OnPressed += _ => ButtonPressed(UiAction.Ok, _window.TagInput.Text);
_window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text); _window.TagInput.OnTextEntered += args => ButtonPressed(UiAction.Ok, args.Text);
} }
private void ButtonPressed(UiAction action, string tag) private void ButtonPressed(UiAction action, string tag)
{ {
// TODO: This looks copy-pasted with the other mailing stuff...
SendMessage(new UiActionMessage(action, tag)); SendMessage(new UiActionMessage(action, tag));
Close(); _window?.Close();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -46,5 +48,18 @@ namespace Content.Client.Disposal.UI
_window?.UpdateState(cast); _window?.UpdateState(cast);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_window?.Dispose();
} }
} }
}
}

View File

@@ -1,7 +1,6 @@
using Content.Shared.Access; using Content.Shared.Access;
using Content.Shared.Doors.Electronics; using Content.Shared.Doors.Electronics;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Client.Doors.Electronics; namespace Content.Client.Doors.Electronics;
@@ -19,23 +18,6 @@ public sealed class DoorElectronicsBoundUserInterface : BoundUserInterface
protected override void Open() protected override void Open()
{ {
base.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(); List<ProtoId<AccessLevelPrototype>> accessLevels = new();
foreach (var accessLevel in _prototypeManager.EnumeratePrototypes<AccessLevelPrototype>()) foreach (var accessLevel in _prototypeManager.EnumeratePrototypes<AccessLevelPrototype>())
@@ -47,7 +29,10 @@ public sealed class DoorElectronicsBoundUserInterface : BoundUserInterface
} }
accessLevels.Sort(); accessLevels.Sort();
_window?.Reset(_prototypeManager, accessLevels);
_window = new DoorElectronicsConfigurationMenu(this, accessLevels, _prototypeManager);
_window.OnClose += Close;
_window.OpenCentered();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -59,6 +44,14 @@ public sealed class DoorElectronicsBoundUserInterface : BoundUserInterface
_window?.UpdateState(castState); _window?.UpdateState(castState);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
public void UpdateConfiguration(List<ProtoId<AccessLevelPrototype>> newAccessList) public void UpdateConfiguration(List<ProtoId<AccessLevelPrototype>> newAccessList)
{ {
SendMessage(new DoorElectronicsUpdateConfigurationMessage(newAccessList)); SendMessage(new DoorElectronicsUpdateConfigurationMessage(newAccessList));

View File

@@ -15,23 +15,22 @@ namespace Content.Client.Doors.Electronics;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class DoorElectronicsConfigurationMenu : FancyWindow public sealed partial class DoorElectronicsConfigurationMenu : FancyWindow
{ {
private readonly AccessLevelControl _buttonsList = new(); private readonly DoorElectronicsBoundUserInterface _owner;
private AccessLevelControl _buttonsList = new();
public event Action<List<ProtoId<AccessLevelPrototype>>>? OnAccessChanged; public DoorElectronicsConfigurationMenu(DoorElectronicsBoundUserInterface ui, List<ProtoId<AccessLevelPrototype>> accessLevels, IPrototypeManager prototypeManager)
public DoorElectronicsConfigurationMenu()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
_owner = ui;
_buttonsList.Populate(accessLevels, prototypeManager);
AccessLevelControlContainer.AddChild(_buttonsList); AccessLevelControlContainer.AddChild(_buttonsList);
}
public void Reset(IPrototypeManager protoManager, List<ProtoId<AccessLevelPrototype>> accessLevels) foreach (var (id, button) in _buttonsList.ButtonsList)
{ {
_buttonsList.Populate(accessLevels, protoManager); button.OnPressed += _ => _owner.UpdateConfiguration(
_buttonsList.ButtonsList.Where(x => x.Value.Pressed).Select(x => x.Key).ToList());
foreach (var button in _buttonsList.ButtonsList.Values)
{
button.OnPressed += _ => OnAccessChanged?.Invoke(_buttonsList.ButtonsList.Where(x => x.Value.Pressed).Select(x => x.Key).ToList());
} }
} }

View File

@@ -25,7 +25,10 @@ public sealed class FaxBoundUi : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<FaxWindow>(); _window = new FaxWindow();
_window.OpenCentered();
_window.OnClose += Close;
_window.FileButtonPressed += OnFileButtonPressed; _window.FileButtonPressed += OnFileButtonPressed;
_window.CopyButtonPressed += OnCopyButtonPressed; _window.CopyButtonPressed += OnCopyButtonPressed;
_window.SendButtonPressed += OnSendButtonPressed; _window.SendButtonPressed += OnSendButtonPressed;
@@ -101,4 +104,11 @@ public sealed class FaxBoundUi : BoundUserInterface
_window.UpdateState(cast); _window.UpdateState(cast);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
_window?.Dispose();
}
} }

View File

@@ -1,7 +1,6 @@
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Content.Shared.Forensics; using Content.Shared.Forensics;
using Robust.Client.UserInterface;
namespace Content.Client.Forensics namespace Content.Client.Forensics
{ {
@@ -22,9 +21,11 @@ namespace Content.Client.Forensics
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window = this.CreateWindow<ForensicScannerMenu>(); _window = new ForensicScannerMenu();
_window.OnClose += Close;
_window.Print.OnPressed += _ => Print(); _window.Print.OnPressed += _ => Print();
_window.Clear.OnPressed += _ => Clear(); _window.Clear.OnPressed += _ => Clear();
_window.OpenCentered();
} }
private void Print() private void Print()
@@ -61,7 +62,6 @@ namespace Content.Client.Forensics
_printCooldown = cast.PrintCooldown; _printCooldown = cast.PrintCooldown;
// TODO: Fix this
if (cast.PrintReadyAt > _gameTiming.CurTime) if (cast.PrintReadyAt > _gameTiming.CurTime)
Timer.Spawn(cast.PrintReadyAt - _gameTiming.CurTime, () => Timer.Spawn(cast.PrintReadyAt - _gameTiming.CurTime, () =>
{ {
@@ -71,5 +71,14 @@ namespace Content.Client.Forensics
_window.UpdateState(cast); _window.UpdateState(cast);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_window?.Dispose();
}
} }
} }

View File

@@ -1,7 +1,6 @@
using Content.Shared.Gateway; using Content.Shared.Gateway;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Gateway.UI; namespace Content.Client.Gateway.UI;
@@ -18,13 +17,24 @@ public sealed class GatewayBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<GatewayWindow>(); _window = new GatewayWindow(EntMan.GetNetEntity(Owner));
_window.SetEntity(EntMan.GetNetEntity(Owner));
_window.OpenPortal += destination => _window.OpenPortal += destination =>
{ {
SendMessage(new GatewayOpenPortalMessage(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) protected override void UpdateState(BoundUserInterfaceState state)

View File

@@ -22,7 +22,7 @@ public sealed partial class GatewayWindow : FancyWindow,
public event Action<NetEntity>? OpenPortal; public event Action<NetEntity>? OpenPortal;
private List<GatewayDestinationData> _destinations = new(); private List<GatewayDestinationData> _destinations = new();
public NetEntity Owner; public readonly NetEntity Owner;
private NetEntity? _current; private NetEntity? _current;
private TimeSpan _nextReady; private TimeSpan _nextReady;
@@ -46,20 +46,16 @@ public sealed partial class GatewayWindow : FancyWindow,
/// </summary> /// </summary>
private bool _isCooldownPending = true; private bool _isCooldownPending = true;
public GatewayWindow() public GatewayWindow(NetEntity netEntity)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
var dependencies = IoCManager.Instance!; var dependencies = IoCManager.Instance!;
_timing = dependencies.Resolve<IGameTiming>(); _timing = dependencies.Resolve<IGameTiming>();
Owner = netEntity;
NextUnlockBar.ForegroundStyleBoxOverride = new StyleBoxFlat(Color.FromHex("#C74EBD")); NextUnlockBar.ForegroundStyleBoxOverride = new StyleBoxFlat(Color.FromHex("#C74EBD"));
} }
public void SetEntity(NetEntity entity)
{
}
public void UpdateState(GatewayBoundUserInterfaceState state) public void UpdateState(GatewayBoundUserInterfaceState state)
{ {
_destinations = state.Destinations; _destinations = state.Destinations;

View File

@@ -1,6 +1,6 @@
using Content.Shared.Gravity; using Content.Shared.Gravity;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface; using Robust.Client.GameObjects;
namespace Content.Client.Gravity.UI namespace Content.Client.Gravity.UI
{ {
@@ -18,8 +18,17 @@ namespace Content.Client.Gravity.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<GravityGeneratorWindow>(); _window = new GravityGeneratorWindow(this);
_window.SetEntity(Owner);
/*
_window.Switch.OnPressed += _ =>
{
SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(!IsOn));
};
*/
_window.OpenCentered();
_window.OnClose += Close;
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -30,6 +39,14 @@ namespace Content.Client.Gravity.UI
_window?.UpdateState(castState); _window?.UpdateState(castState);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
public void SetPowerSwitch(bool on) public void SetPowerSwitch(bool on)
{ {
SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(on)); SendMessage(new SharedGravityGeneratorComponent.SwitchGeneratorMessage(on));

View File

@@ -12,23 +12,22 @@ namespace Content.Client.Gravity.UI
{ {
private readonly ButtonGroup _buttonGroup = new(); private readonly ButtonGroup _buttonGroup = new();
public event Action<bool>? OnPowerSwitch; private readonly GravityGeneratorBoundUserInterface _owner;
public GravityGeneratorWindow() public GravityGeneratorWindow(GravityGeneratorBoundUserInterface owner)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
_owner = owner;
OnButton.Group = _buttonGroup; OnButton.Group = _buttonGroup;
OffButton.Group = _buttonGroup; OffButton.Group = _buttonGroup;
OnButton.OnPressed += _ => OnPowerSwitch?.Invoke(true); OnButton.OnPressed += _ => _owner.SetPowerSwitch(true);
OffButton.OnPressed += _ => OnPowerSwitch?.Invoke(false); OffButton.OnPressed += _ => _owner.SetPowerSwitch(false);
}
public void SetEntity(EntityUid uid) EntityView.SetEntity(owner.Owner);
{
EntityView.SetEntity(uid);
} }
public void UpdateState(SharedGravityGeneratorComponent.GeneratorState state) public void UpdateState(SharedGravityGeneratorComponent.GeneratorState state)

View File

@@ -1,6 +1,6 @@
using Content.Shared.MedicalScanner; using Content.Shared.MedicalScanner;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface; using Robust.Client.GameObjects;
namespace Content.Client.HealthAnalyzer.UI namespace Content.Client.HealthAnalyzer.UI
{ {
@@ -17,9 +17,12 @@ namespace Content.Client.HealthAnalyzer.UI
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window = this.CreateWindow<HealthAnalyzerWindow>(); _window = new HealthAnalyzerWindow
{
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName; Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName,
};
_window.OnClose += Close;
_window.OpenCentered();
} }
protected override void ReceiveMessage(BoundUserInterfaceMessage message) protected override void ReceiveMessage(BoundUserInterfaceMessage message)
@@ -32,5 +35,17 @@ namespace Content.Client.HealthAnalyzer.UI
_window.Populate(cast); _window.Populate(cast);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
if (_window != null)
_window.OnClose -= Close;
_window?.Dispose();
}
} }
} }

View File

@@ -1,6 +1,5 @@
using Content.Shared.Humanoid; using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings; using Content.Shared.Humanoid.Markings;
using Robust.Client.UserInterface;
namespace Content.Client.Humanoid; namespace Content.Client.Humanoid;
@@ -21,7 +20,8 @@ public sealed class HumanoidMarkingModifierBoundUserInterface : BoundUserInterfa
{ {
base.Open(); base.Open();
_window = this.CreateWindow<HumanoidMarkingModifierWindow>(); _window = new();
_window.OnClose += Close;
_window.OnMarkingAdded += SendMarkingSet; _window.OnMarkingAdded += SendMarkingSet;
_window.OnMarkingRemoved += SendMarkingSet; _window.OnMarkingRemoved += SendMarkingSet;
_window.OnMarkingColorChange += SendMarkingSetNoResend; _window.OnMarkingColorChange += SendMarkingSetNoResend;

View File

@@ -11,9 +11,7 @@ public sealed partial class BandMenu : DefaultWindow
{ {
private readonly InstrumentBoundUserInterface _owner; private readonly InstrumentBoundUserInterface _owner;
public EntityUid? Master; public BandMenu(InstrumentBoundUserInterface owner) : base()
public BandMenu(InstrumentBoundUserInterface owner)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
@@ -42,7 +40,7 @@ public sealed partial class BandMenu : DefaultWindow
{ {
var uid = entManager.GetEntity(nent); var uid = entManager.GetEntity(nent);
var item = BandList.AddItem(name, null, true, uid); var item = BandList.AddItem(name, null, true, uid);
item.Selected = Master == uid; item.Selected = _owner.Instrument?.Master == uid;
} }
} }
} }

View File

@@ -51,7 +51,7 @@ public sealed partial class ChannelsMenu : DefaultWindow
} }
} }
public void Populate(InstrumentComponent? instrument) public void Populate()
{ {
ChannelList.Clear(); ChannelList.Clear();
@@ -60,8 +60,7 @@ public sealed partial class ChannelsMenu : DefaultWindow
var item = ChannelList.AddItem(_owner.Loc.GetString("instrument-component-channel-name", var item = ChannelList.AddItem(_owner.Loc.GetString("instrument-component-channel-name",
("number", i)), null, true, i); ("number", i)), null, true, i);
item.Selected = !_owner.Instrument?.FilteredChannels[i] ?? false;
item.Selected = !instrument?.FilteredChannels[i] ?? false;
} }
} }
} }

View File

@@ -24,6 +24,8 @@ namespace Content.Client.Instruments.UI
[ViewVariables] private BandMenu? _bandMenu; [ViewVariables] private BandMenu? _bandMenu;
[ViewVariables] private ChannelsMenu? _channelsMenu; [ViewVariables] private ChannelsMenu? _channelsMenu;
[ViewVariables] public InstrumentComponent? Instrument { get; private set; }
public InstrumentBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) public InstrumentBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{ {
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
@@ -41,20 +43,14 @@ namespace Content.Client.Instruments.UI
protected override void Open() protected override void Open()
{ {
_instrumentMenu = this.CreateWindow<InstrumentMenu>(); if (!EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument))
_instrumentMenu.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName; return;
_instrumentMenu.OnOpenBand += OpenBandMenu; Instrument = instrument;
_instrumentMenu.OnOpenChannels += OpenChannelsMenu; _instrumentMenu = new InstrumentMenu(this);
_instrumentMenu.OnCloseChannels += CloseChannelsMenu; _instrumentMenu.OnClose += Close;
_instrumentMenu.OnCloseBands += CloseBandMenu;
_instrumentMenu.SetMIDI(MidiManager.IsAvailable); _instrumentMenu.OpenCentered();
if (EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument))
{
_instrumentMenu.SetInstrument((Owner, instrument));
}
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
@@ -62,12 +58,7 @@ namespace Content.Client.Instruments.UI
base.Dispose(disposing); base.Dispose(disposing);
if (!disposing) if (!disposing)
return; return;
_instrumentMenu?.Dispose();
if (EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument))
{
_instrumentMenu?.RemoveInstrument(instrument);
}
_bandMenu?.Dispose(); _bandMenu?.Dispose();
_channelsMenu?.Dispose(); _channelsMenu?.Dispose();
} }
@@ -81,11 +72,6 @@ namespace Content.Client.Instruments.UI
{ {
_bandMenu ??= new BandMenu(this); _bandMenu ??= new BandMenu(this);
if (EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument))
{
_bandMenu.Master = instrument.Master;
}
// Refresh cache... // Refresh cache...
RefreshBands(); RefreshBands();
@@ -101,9 +87,7 @@ namespace Content.Client.Instruments.UI
public void OpenChannelsMenu() public void OpenChannelsMenu()
{ {
_channelsMenu ??= new ChannelsMenu(this); _channelsMenu ??= new ChannelsMenu(this);
EntMan.TryGetComponent(Owner, out InstrumentComponent? instrument); _channelsMenu.Populate();
_channelsMenu.Populate(instrument);
_channelsMenu.OpenCenteredRight(); _channelsMenu.OpenCenteredRight();
} }

View File

@@ -1,10 +1,7 @@
using System.IO; using System.IO;
using System.Numerics; using System.Numerics;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Client.Interactable;
using Content.Shared.ActionBlocker;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Player;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
@@ -19,23 +16,33 @@ namespace Content.Client.Instruments.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class InstrumentMenu : DefaultWindow public sealed partial class InstrumentMenu : DefaultWindow
{ {
[Dependency] private readonly IEntityManager _entManager = default!; private readonly InstrumentBoundUserInterface _owner;
[Dependency] private readonly IFileDialogManager _dialogs = default!;
[Dependency] private readonly IPlayerManager _player = default!;
private bool _isMidiFileDialogueWindowOpen; private bool _isMidiFileDialogueWindowOpen;
public event Action? OnOpenBand; public InstrumentMenu(InstrumentBoundUserInterface owner)
public event Action? OnOpenChannels;
public event Action? OnCloseBands;
public event Action? OnCloseChannels;
public EntityUid Entity;
public InstrumentMenu()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_owner = owner;
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;
}
if (!_owner.MidiManager.IsAvailable)
{
UnavailableOverlay.Visible = true;
// We return early as to not give the buttons behavior.
return;
}
InputButton.OnToggled += MidiInputButtonOnOnToggled; InputButton.OnToggled += MidiInputButtonOnOnToggled;
BandButton.OnPressed += BandButtonOnPressed; BandButton.OnPressed += BandButtonOnPressed;
@@ -50,34 +57,12 @@ namespace Content.Client.Instruments.UI
MinSize = SetSize = new Vector2(400, 150); 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) private void BandButtonOnPressed(ButtonEventArgs obj)
{ {
if (!PlayCheck()) if (!PlayCheck())
return; return;
OnOpenBand?.Invoke(); _owner.OpenBandMenu();
} }
private void BandButtonOnToggled(ButtonToggledEventArgs obj) private void BandButtonOnToggled(ButtonToggledEventArgs obj)
@@ -85,15 +70,12 @@ namespace Content.Client.Instruments.UI
if (obj.Pressed) if (obj.Pressed)
return; return;
if (_entManager.TryGetComponent(Entity, out InstrumentComponent? instrument)) _owner.Instruments.SetMaster(_owner.Owner, null);
{
_entManager.System<InstrumentSystem>().SetMaster(Entity, instrument.Master);
}
} }
private void ChannelsButtonOnPressed(ButtonEventArgs obj) private void ChannelsButtonOnPressed(ButtonEventArgs obj)
{ {
OnOpenChannels?.Invoke(); _owner.OpenChannelsMenu();
} }
private void InstrumentOnMidiPlaybackEnded() private void InstrumentOnMidiPlaybackEnded()
@@ -104,9 +86,7 @@ namespace Content.Client.Instruments.UI
public void MidiPlaybackSetButtonsDisabled(bool disabled) public void MidiPlaybackSetButtonsDisabled(bool disabled)
{ {
if(disabled) if(disabled)
{ _owner.CloseChannelsMenu();
OnCloseChannels?.Invoke();
}
LoopButton.Disabled = disabled; LoopButton.Disabled = disabled;
StopButton.Disabled = disabled; StopButton.Disabled = disabled;
@@ -120,7 +100,7 @@ namespace Content.Client.Instruments.UI
if (_isMidiFileDialogueWindowOpen) if (_isMidiFileDialogueWindowOpen)
return; return;
OnCloseBands?.Invoke(); _owner.CloseBandMenu();
var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi")); var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
@@ -128,7 +108,7 @@ namespace Content.Client.Instruments.UI
// or focus the previously-opened window. // or focus the previously-opened window.
_isMidiFileDialogueWindowOpen = true; _isMidiFileDialogueWindowOpen = true;
await using var file = await _dialogs.OpenFile(filters); await using var file = await _owner.FileDialogManager.OpenFile(filters);
_isMidiFileDialogueWindowOpen = false; _isMidiFileDialogueWindowOpen = false;
@@ -149,18 +129,9 @@ namespace Content.Client.Instruments.UI
await file.CopyToAsync(memStream); await file.CopyToAsync(memStream);
if (!_entManager.TryGetComponent<InstrumentComponent>(Entity, out var instrument)) if (_owner.Instrument is not {} instrument
{ || !_owner.Instruments.OpenMidi(_owner.Owner, memStream.GetBuffer().AsSpan(0, (int) memStream.Length), instrument))
return; return;
}
if (!_entManager.System<InstrumentSystem>()
.OpenMidi(Entity,
memStream.GetBuffer().AsSpan(0, (int) memStream.Length),
instrument))
{
return;
}
MidiPlaybackSetButtonsDisabled(false); MidiPlaybackSetButtonsDisabled(false);
if (InputButton.Pressed) if (InputButton.Pressed)
@@ -169,7 +140,7 @@ namespace Content.Client.Instruments.UI
private void MidiInputButtonOnOnToggled(ButtonToggledEventArgs obj) private void MidiInputButtonOnOnToggled(ButtonToggledEventArgs obj)
{ {
OnCloseBands?.Invoke(); _owner.CloseBandMenu();
if (obj.Pressed) if (obj.Pressed)
{ {
@@ -177,99 +148,109 @@ namespace Content.Client.Instruments.UI
return; return;
MidiStopButtonOnPressed(null); MidiStopButtonOnPressed(null);
if(_owner.Instrument is {} instrument)
if (_entManager.TryGetComponent(Entity, out InstrumentComponent? instrument)) _owner.Instruments.OpenInput(_owner.Owner, instrument);
_entManager.System<InstrumentSystem>().OpenInput(Entity, instrument);
} }
else else if (_owner.Instrument is { } instrument)
{ {
_entManager.System<InstrumentSystem>().CloseInput(Entity, false); _owner.Instruments.CloseInput(_owner.Owner, false, instrument);
OnCloseChannels?.Invoke(); _owner.CloseChannelsMenu();
} }
} }
private bool PlayCheck() private bool PlayCheck()
{ {
// TODO all of these checks should also be done server-side. // TODO all of these checks should also be done server-side.
if (!_entManager.TryGetComponent(Entity, out InstrumentComponent? instrument))
var instrumentEnt = _owner.Owner;
var instrument = _owner.Instrument;
if (instrument == null)
return false; return false;
var localEntity = _player.LocalEntity; var localEntity = _owner.PlayerManager.LocalEntity;
// If we don't have a player or controlled entity, we return. // If we don't have a player or controlled entity, we return.
if (localEntity == null) if (localEntity == null)
return false; return false;
// By default, allow an instrument to play itself and skip all other checks // By default, allow an instrument to play itself and skip all other checks
if (localEntity == Entity) if (localEntity == instrumentEnt)
return true; return true;
var container = _entManager.System<SharedContainerSystem>(); var container = _owner.Entities.System<SharedContainerSystem>();
// If we're a handheld instrument, we might be in a container. Get it just in case. // If we're a handheld instrument, we might be in a container. Get it just in case.
container.TryGetContainingContainer(Entity, out var conMan); container.TryGetContainingContainer(instrumentEnt, out var conMan);
// If the instrument is handheld and we're not holding it, we return. // 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; return false;
if (!_entManager.System<ActionBlockerSystem>().CanInteract(localEntity.Value, Entity)) if (!_owner.ActionBlocker.CanInteract(localEntity.Value, instrumentEnt))
return false; return false;
// We check that we're in range unobstructed just in case. // We check that we're in range unobstructed just in case.
return _entManager.System<InteractionSystem>().InRangeUnobstructed(localEntity.Value, Entity); return _owner.Interactions.InRangeUnobstructed(localEntity.Value, instrumentEnt);
} }
private void MidiStopButtonOnPressed(ButtonEventArgs? obj) private void MidiStopButtonOnPressed(ButtonEventArgs? obj)
{ {
MidiPlaybackSetButtonsDisabled(true); MidiPlaybackSetButtonsDisabled(true);
_entManager.System<InstrumentSystem>().CloseMidi(Entity, false); if (_owner.Instrument is not {} instrument)
OnCloseChannels?.Invoke(); return;
_owner.Instruments.CloseMidi(_owner.Owner, false, instrument);
_owner.CloseChannelsMenu();
} }
private void MidiLoopButtonOnOnToggled(ButtonToggledEventArgs obj) private void MidiLoopButtonOnOnToggled(ButtonToggledEventArgs obj)
{ {
var instrument = _entManager.System<InstrumentSystem>(); if (_owner.Instrument == null)
return;
if (_entManager.TryGetComponent(Entity, out InstrumentComponent? instrumentComp)) _owner.Instrument.LoopMidi = obj.Pressed;
{ _owner.Instruments.UpdateRenderer(_owner.Owner, _owner.Instrument);
instrumentComp.LoopMidi = obj.Pressed;
}
instrument.UpdateRenderer(Entity);
} }
private void PlaybackSliderSeek(Range _) private void PlaybackSliderSeek(Range _)
{ {
// Do not seek while still grabbing. // Do not seek while still grabbing.
if (PlaybackSlider.Grabbed) if (PlaybackSlider.Grabbed || _owner.Instrument is not {} instrument)
return; return;
_entManager.System<InstrumentSystem>().SetPlayerTick(Entity, (int)Math.Ceiling(PlaybackSlider.Value)); _owner.Instruments.SetPlayerTick(_owner.Owner, (int)Math.Ceiling(PlaybackSlider.Value), instrument);
} }
private void PlaybackSliderKeyUp(GUIBoundKeyEventArgs args) private void PlaybackSliderKeyUp(GUIBoundKeyEventArgs args)
{ {
if (args.Function != EngineKeyFunctions.UIClick) if (args.Function != EngineKeyFunctions.UIClick || _owner.Instrument is not {} instrument)
return; return;
_entManager.System<InstrumentSystem>().SetPlayerTick(Entity, (int)Math.Ceiling(PlaybackSlider.Value)); _owner.Instruments.SetPlayerTick(_owner.Owner, (int)Math.Ceiling(PlaybackSlider.Value), instrument);
}
public override void Close()
{
base.Close();
_owner.CloseBandMenu();
_owner.CloseChannelsMenu();
} }
protected override void FrameUpdate(FrameEventArgs args) protected override void FrameUpdate(FrameEventArgs args)
{ {
base.FrameUpdate(args); base.FrameUpdate(args);
if (!_entManager.TryGetComponent(Entity, out InstrumentComponent? instrument)) if (_owner.Instrument == null)
return; return;
var hasMaster = instrument.Master != null; var hasMaster = _owner.Instrument.Master != null;
BandButton.ToggleMode = hasMaster; BandButton.ToggleMode = hasMaster;
BandButton.Pressed = hasMaster; BandButton.Pressed = hasMaster;
BandButton.Disabled = instrument.IsMidiOpen || instrument.IsInputOpen; BandButton.Disabled = _owner.Instrument.IsMidiOpen || _owner.Instrument.IsInputOpen;
ChannelsButton.Disabled = !instrument.IsRendererAlive; ChannelsButton.Disabled = !_owner.Instrument.IsRendererAlive;
if (!instrument.IsMidiOpen) if (!_owner.Instrument.IsMidiOpen)
{ {
PlaybackSlider.MaxValue = 1; PlaybackSlider.MaxValue = 1;
PlaybackSlider.SetValueWithoutEvent(0); PlaybackSlider.SetValueWithoutEvent(0);
@@ -279,8 +260,8 @@ namespace Content.Client.Instruments.UI
if (PlaybackSlider.Grabbed) if (PlaybackSlider.Grabbed)
return; return;
PlaybackSlider.MaxValue = instrument.PlayerTotalTick; PlaybackSlider.MaxValue = _owner.Instrument.PlayerTotalTick;
PlaybackSlider.SetValueWithoutEvent(instrument.PlayerTick); PlaybackSlider.SetValueWithoutEvent(_owner.Instrument.PlayerTick);
} }
} }
} }

View File

@@ -41,7 +41,7 @@ namespace Content.Client.Inventory
public const string HiddenPocketEntityId = "StrippingHiddenEntity"; public const string HiddenPocketEntityId = "StrippingHiddenEntity";
[ViewVariables] [ViewVariables]
private StrippingMenu? _strippingMenu; private readonly StrippingMenu? _strippingMenu;
[ViewVariables] [ViewVariables]
private readonly EntityUid _virtualHiddenEntity; private readonly EntityUid _virtualHiddenEntity;
@@ -51,30 +51,33 @@ namespace Content.Client.Inventory
_examine = EntMan.System<ExamineSystem>(); _examine = EntMan.System<ExamineSystem>();
_inv = EntMan.System<InventorySystem>(); _inv = EntMan.System<InventorySystem>();
_cuffable = EntMan.System<SharedCuffableSystem>(); _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); _virtualHiddenEntity = EntMan.SpawnEntity(HiddenPocketEntityId, MapCoordinates.Nullspace);
} }
protected override void Open() protected override void Open()
{ {
base.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(); _strippingMenu?.OpenCenteredLeft();
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
base.Dispose(disposing);
EntMan.DeleteEntity(_virtualHiddenEntity);
if (!disposing) if (!disposing)
return; return;
if (_strippingMenu != null) _strippingMenu?.Dispose();
_strippingMenu.OnDirty -= UpdateMenu;
EntMan.DeleteEntity(_virtualHiddenEntity);
base.Dispose(disposing);
} }
public void DirtyMenu() public void DirtyMenu()

View File

@@ -12,34 +12,42 @@ namespace Content.Client.Kitchen.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class GrinderMenu : FancyWindow public sealed partial class GrinderMenu : FancyWindow
{ {
[Dependency] private readonly IEntityManager _entityManager = default!; private readonly IEntityManager _entityManager;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; private readonly IPrototypeManager _prototypeManager;
private readonly ReagentGrinderBoundUserInterface _owner;
private readonly Dictionary<int, EntityUid> _chamberVisualContents = new(); private readonly Dictionary<int, EntityUid> _chamberVisualContents = new();
public event Action? OnToggleAuto; public GrinderMenu(ReagentGrinderBoundUserInterface owner, IEntityManager entityManager, IPrototypeManager prototypeManager)
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); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); _entityManager = entityManager;
AutoModeButton.OnPressed += _ => OnToggleAuto?.Invoke(); _prototypeManager = prototypeManager;
GrindButton.OnPressed += _ => OnGrind?.Invoke(); _owner = owner;
JuiceButton.OnPressed += _ => OnJuice?.Invoke(); AutoModeButton.OnPressed += owner.ToggleAutoMode;
ChamberContentBox.EjectButton.OnPressed += _ => OnEjectAll?.Invoke(); GrindButton.OnPressed += owner.StartGrinding;
BeakerContentBox.EjectButton.OnPressed += _ => OnEjectBeaker?.Invoke(); JuiceButton.OnPressed += owner.StartJuicing;
ChamberContentBox.EjectButton.OnPressed += owner.EjectAll;
BeakerContentBox.EjectButton.OnPressed += owner.EjectBeaker;
ChamberContentBox.BoxContents.OnItemSelected += OnChamberBoxContentsItemSelected; ChamberContentBox.BoxContents.OnItemSelected += OnChamberBoxContentsItemSelected;
BeakerContentBox.BoxContents.SelectMode = ItemList.ItemListSelectMode.None; BeakerContentBox.BoxContents.SelectMode = ItemList.ItemListSelectMode.None;
} }
private void OnChamberBoxContentsItemSelected(ItemList.ItemListSelectedEventArgs args) private void OnChamberBoxContentsItemSelected(ItemList.ItemListSelectedEventArgs args)
{ {
OnEjectChamber?.Invoke(_chamberVisualContents[args.ItemIndex]); _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;
} }
public void UpdateState(ReagentGrinderInterfaceState state) public void UpdateState(ReagentGrinderInterfaceState state)

View File

@@ -3,7 +3,6 @@ using Content.Shared.Kitchen.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -20,15 +19,28 @@ namespace Content.Client.Kitchen.UI
[ViewVariables] [ViewVariables]
private readonly Dictionary<int, ReagentQuantity> _reagents = new(); 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) public MicrowaveBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{ {
_entManager = IoCManager.Resolve<IEntityManager>();
}
public TimeSpan GetCurrentTime()
{
return _gameTiming.CurTime;
} }
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<MicrowaveMenu>(); _menu = new MicrowaveMenu(this);
_menu.OpenCentered();
_menu.OnClose += Close;
_menu.StartButton.OnPressed += _ => SendPredictedMessage(new MicrowaveStartCookMessage()); _menu.StartButton.OnPressed += _ => SendPredictedMessage(new MicrowaveStartCookMessage());
_menu.EjectButton.OnPressed += _ => SendPredictedMessage(new MicrowaveEjectMessage()); _menu.EjectButton.OnPressed += _ => SendPredictedMessage(new MicrowaveEjectMessage());
_menu.IngredientsList.OnItemSelected += args => _menu.IngredientsList.OnItemSelected += args =>
@@ -62,20 +74,35 @@ namespace Content.Client.Kitchen.UI
}; };
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void Dispose(bool disposing)
{ {
base.UpdateState(state); base.Dispose(disposing);
if (state is not MicrowaveUpdateUserInterfaceState cState || _menu == null)
if (!disposing)
{ {
return; return;
} }
_menu.IsBusy = cState.IsMicrowaveBusy; _solids.Clear();
_menu.CurrentCooktimeEnd = cState.CurrentCookTimeEnd; _menu?.Dispose();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not MicrowaveUpdateUserInterfaceState cState)
{
return;
}
_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. // TODO move this to a component state and ensure the net ids.
RefreshContentsDisplay(EntMan.GetEntityArray(cState.ContainedSolids)); RefreshContentsDisplay(_entManager.GetEntityArray(cState.ContainedSolids));
if (_menu == null) return;
//Set the cook time info label //Set the cook time info label
var cookTime = cState.ActiveButtonIndex == 0 var cookTime = cState.ActiveButtonIndex == 0

View File

@@ -9,20 +9,22 @@ namespace Content.Client.Kitchen.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class MicrowaveMenu : FancyWindow public sealed partial class MicrowaveMenu : FancyWindow
{ {
[Dependency] private readonly IGameTiming _timing = default!; public sealed class MicrowaveCookTimeButton : Button
{
public uint CookTime;
}
public event Action<BaseButton.ButtonEventArgs, int>? OnCookTimeSelected; public event Action<BaseButton.ButtonEventArgs, int>? OnCookTimeSelected;
public ButtonGroup CookTimeButtonGroup { get; } public ButtonGroup CookTimeButtonGroup { get; }
private readonly MicrowaveBoundUserInterface _owner;
public bool IsBusy; public MicrowaveMenu(MicrowaveBoundUserInterface owner)
public TimeSpan CurrentCooktimeEnd;
public MicrowaveMenu()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
CookTimeButtonGroup = new ButtonGroup(); CookTimeButtonGroup = new ButtonGroup();
InstantCookButton.Group = CookTimeButtonGroup; InstantCookButton.Group = CookTimeButtonGroup;
_owner = owner;
InstantCookButton.OnPressed += args => InstantCookButton.OnPressed += args =>
{ {
OnCookTimeSelected?.Invoke(args, 0); OnCookTimeSelected?.Invoke(args, 0);
@@ -63,20 +65,14 @@ namespace Content.Client.Kitchen.UI
protected override void FrameUpdate(FrameEventArgs args) protected override void FrameUpdate(FrameEventArgs args)
{ {
base.FrameUpdate(args); base.FrameUpdate(args);
if(!_owner.currentState.IsMicrowaveBusy)
if (!IsBusy)
return; return;
if (CurrentCooktimeEnd > _timing.CurTime) if(_owner.currentState.CurrentCookTimeEnd > _owner.GetCurrentTime())
{ {
CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label", CookTimeInfoLabel.Text = Loc.GetString("microwave-bound-user-interface-cook-time-label",
("time", CurrentCooktimeEnd.Subtract(_timing.CurTime).Seconds)); ("time",_owner.currentState.CurrentCookTimeEnd.Subtract(_owner.GetCurrentTime()).Seconds));
} }
}
public sealed class MicrowaveCookTimeButton : Button
{
public uint CookTime;
} }
} }
} }

View File

@@ -1,7 +1,6 @@
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.Kitchen; using Content.Shared.Kitchen;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
@@ -9,6 +8,8 @@ namespace Content.Client.Kitchen.UI
{ {
public sealed class ReagentGrinderBoundUserInterface : BoundUserInterface public sealed class ReagentGrinderBoundUserInterface : BoundUserInterface
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[ViewVariables] [ViewVariables]
private GrinderMenu? _menu; private GrinderMenu? _menu;
@@ -20,13 +21,20 @@ namespace Content.Client.Kitchen.UI
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<GrinderMenu>(); _menu = new GrinderMenu(this, EntMan, _prototypeManager);
_menu.OnToggleAuto += ToggleAutoMode; _menu.OpenCentered();
_menu.OnGrind += StartGrinding; _menu.OnClose += Close;
_menu.OnJuice += StartJuicing; }
_menu.OnEjectAll += EjectAll;
_menu.OnEjectBeaker += EjectBeaker; protected override void Dispose(bool disposing)
_menu.OnEjectChamber += EjectChamberContent; {
base.Dispose(disposing);
if (!disposing)
{
return;
}
_menu?.Dispose();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -44,27 +52,27 @@ namespace Content.Client.Kitchen.UI
_menu?.HandleMessage(message); _menu?.HandleMessage(message);
} }
public void ToggleAutoMode() public void ToggleAutoMode(BaseButton.ButtonEventArgs args)
{ {
SendMessage(new ReagentGrinderToggleAutoModeMessage()); SendMessage(new ReagentGrinderToggleAutoModeMessage());
} }
public void StartGrinding() public void StartGrinding(BaseButton.ButtonEventArgs? _ = null)
{ {
SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Grind)); SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Grind));
} }
public void StartJuicing() public void StartJuicing(BaseButton.ButtonEventArgs? _ = null)
{ {
SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Juice)); SendMessage(new ReagentGrinderStartMessage(GrinderProgram.Juice));
} }
public void EjectAll() public void EjectAll(BaseButton.ButtonEventArgs? _ = null)
{ {
SendMessage(new ReagentGrinderEjectChamberAllMessage()); SendMessage(new ReagentGrinderEjectChamberAllMessage());
} }
public void EjectBeaker() public void EjectBeaker(BaseButton.ButtonEventArgs? _ = null)
{ {
SendMessage(new ItemSlotButtonPressedEvent(SharedReagentGrinder.BeakerSlotId)); SendMessage(new ItemSlotButtonPressedEvent(SharedReagentGrinder.BeakerSlotId));
} }

View File

@@ -1,7 +1,6 @@
using Content.Shared.Labels; using Content.Shared.Labels;
using Content.Shared.Labels.Components; using Content.Shared.Labels.Components;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Labels.UI namespace Content.Client.Labels.UI
{ {
@@ -24,8 +23,13 @@ namespace Content.Client.Labels.UI
{ {
base.Open(); base.Open();
_window = this.CreateWindow<HandLabelerWindow>(); _window = new HandLabelerWindow();
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.OnLabelChanged += OnLabelChanged; _window.OnLabelChanged += OnLabelChanged;
Reload(); Reload();
} }
@@ -47,5 +51,13 @@ namespace Content.Client.Labels.UI
_window.SetCurrentLabel(component.AssignedLabel); _window.SetCurrentLabel(component.AssignedLabel);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
} }
} }
}

View File

@@ -1,7 +1,6 @@
using Content.Shared.Lathe; using Content.Shared.Lathe;
using Content.Shared.Research.Components; using Content.Shared.Research.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Lathe.UI namespace Content.Client.Lathe.UI
{ {
@@ -18,9 +17,9 @@ namespace Content.Client.Lathe.UI
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<LatheMenu>(); _menu = new LatheMenu(this);
_menu.SetEntity(Owner); _menu.OnClose += Close;
_menu.OpenCenteredRight();
_menu.OnServerListButtonPressed += _ => _menu.OnServerListButtonPressed += _ =>
{ {
@@ -31,6 +30,8 @@ namespace Content.Client.Lathe.UI
{ {
SendMessage(new LatheQueueRecipeMessage(recipe, amount)); SendMessage(new LatheQueueRecipeMessage(recipe, amount));
}; };
_menu.OpenCenteredRight();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -49,5 +50,13 @@ namespace Content.Client.Lathe.UI
break; break;
} }
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
} }
} }

View File

@@ -1,4 +1,3 @@
using System.Buffers;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Content.Client.Materials; using Content.Client.Materials;
@@ -23,6 +22,7 @@ public sealed partial class LatheMenu : DefaultWindow
[Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private EntityUid _owner;
private readonly SpriteSystem _spriteSystem; private readonly SpriteSystem _spriteSystem;
private readonly LatheSystem _lathe; private readonly LatheSystem _lathe;
private readonly MaterialStorageSystem _materialStorage; private readonly MaterialStorageSystem _materialStorage;
@@ -36,10 +36,9 @@ public sealed partial class LatheMenu : DefaultWindow
public ProtoId<LatheCategoryPrototype>? CurrentCategory; public ProtoId<LatheCategoryPrototype>? CurrentCategory;
public EntityUid Entity; public LatheMenu(LatheBoundUserInterface owner)
public LatheMenu()
{ {
_owner = owner.Owner;
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
@@ -47,6 +46,8 @@ public sealed partial class LatheMenu : DefaultWindow
_lathe = _entityManager.System<LatheSystem>(); _lathe = _entityManager.System<LatheSystem>();
_materialStorage = _entityManager.System<MaterialStorageSystem>(); _materialStorage = _entityManager.System<MaterialStorageSystem>();
Title = _entityManager.GetComponent<MetaDataComponent>(owner.Owner).EntityName;
SearchBar.OnTextChanged += _ => SearchBar.OnTextChanged += _ =>
{ {
PopulateRecipes(); PopulateRecipes();
@@ -59,13 +60,8 @@ public sealed partial class LatheMenu : DefaultWindow
FilterOption.OnItemSelected += OnItemSelected; FilterOption.OnItemSelected += OnItemSelected;
ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a); ServerListButton.OnPressed += a => OnServerListButtonPressed?.Invoke(a);
}
public void SetEntity(EntityUid uid) if (_entityManager.TryGetComponent<LatheComponent>(owner.Owner, out var latheComponent))
{
Entity = uid;
if (_entityManager.TryGetComponent<LatheComponent>(Entity, out var latheComponent))
{ {
if (!latheComponent.DynamicRecipes.Any()) if (!latheComponent.DynamicRecipes.Any())
{ {
@@ -73,7 +69,7 @@ public sealed partial class LatheMenu : DefaultWindow
} }
} }
MaterialsList.SetOwner(Entity); MaterialsList.SetOwner(owner.Owner);
} }
/// <summary> /// <summary>
@@ -106,15 +102,13 @@ public sealed partial class LatheMenu : DefaultWindow
var sortedRecipesToShow = recipesToShow.OrderBy(p => p.Name); var sortedRecipesToShow = recipesToShow.OrderBy(p => p.Name);
RecipeList.Children.Clear(); RecipeList.Children.Clear();
_entityManager.TryGetComponent(Entity, out LatheComponent? lathe);
foreach (var prototype in sortedRecipesToShow) foreach (var prototype in sortedRecipesToShow)
{ {
EntityPrototype? recipeProto = null; EntityPrototype? recipeProto = null;
if (_prototypeManager.TryIndex(prototype.Result, out EntityPrototype? entityProto)) if (_prototypeManager.TryIndex(prototype.Result, out EntityPrototype? entityProto) && entityProto != null)
recipeProto = entityProto; recipeProto = entityProto;
var canProduce = _lathe.CanProduce(Entity, prototype, quantity, component: lathe); var canProduce = _lathe.CanProduce(_owner, prototype, quantity);
var control = new RecipeControl(prototype, () => GenerateTooltipText(prototype), canProduce, recipeProto); var control = new RecipeControl(prototype, () => GenerateTooltipText(prototype), canProduce, recipeProto);
control.OnButtonPressed += s => control.OnButtonPressed += s =>
@@ -130,20 +124,19 @@ public sealed partial class LatheMenu : DefaultWindow
private string GenerateTooltipText(LatheRecipePrototype prototype) private string GenerateTooltipText(LatheRecipePrototype prototype)
{ {
StringBuilder sb = new(); StringBuilder sb = new();
var multiplier = _entityManager.GetComponent<LatheComponent>(Entity).MaterialUseMultiplier;
foreach (var (id, amount) in prototype.RequiredMaterials) foreach (var (id, amount) in prototype.RequiredMaterials)
{ {
if (!_prototypeManager.TryIndex<MaterialPrototype>(id, out var proto)) if (!_prototypeManager.TryIndex<MaterialPrototype>(id, out var proto))
continue; continue;
var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, multiplier); var adjustedAmount = SharedLatheSystem.AdjustMaterial(amount, prototype.ApplyMaterialDiscount, _entityManager.GetComponent<LatheComponent>(_owner).MaterialUseMultiplier);
var sheetVolume = _materialStorage.GetSheetVolume(proto); var sheetVolume = _materialStorage.GetSheetVolume(proto);
var unit = Loc.GetString(proto.Unit); var unit = Loc.GetString(proto.Unit);
var sheets = adjustedAmount / (float) sheetVolume; var sheets = adjustedAmount / (float) sheetVolume;
var availableAmount = _materialStorage.GetMaterialAmount(Entity, id); var availableAmount = _materialStorage.GetMaterialAmount(_owner, id);
var missingAmount = Math.Max(0, adjustedAmount - availableAmount); var missingAmount = Math.Max(0, adjustedAmount - availableAmount);
var missingSheets = missingAmount / (float) sheetVolume; var missingSheets = missingAmount / (float) sheetVolume;

View File

@@ -1,6 +1,5 @@
using Content.Shared.MachineLinking; using Content.Shared.MachineLinking;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Shared.Timing; using Robust.Shared.Timing;
namespace Content.Client.MachineLinking.UI; namespace Content.Client.MachineLinking.UI;
@@ -20,14 +19,19 @@ public sealed class SignalTimerBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<SignalTimerWindow>(); _window = new SignalTimerWindow(this);
_window.OnStartTimer += StartTimer;
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.OnCurrentTextChanged += OnTextChanged; _window.OnCurrentTextChanged += OnTextChanged;
_window.OnCurrentDelayMinutesChanged += OnDelayChanged; _window.OnCurrentDelayMinutesChanged += OnDelayChanged;
_window.OnCurrentDelaySecondsChanged += OnDelayChanged; _window.OnCurrentDelaySecondsChanged += OnDelayChanged;
} }
public void StartTimer() public void OnStartTimer()
{ {
SendMessage(new SignalTimerStartMessage()); SendMessage(new SignalTimerStartMessage());
} }
@@ -44,6 +48,11 @@ public sealed class SignalTimerBoundUserInterface : BoundUserInterface
SendMessage(new SignalTimerDelayChangedMessage(_window.GetDelay())); SendMessage(new SignalTimerDelayChangedMessage(_window.GetDelay()));
} }
public TimeSpan GetCurrentTime()
{
return _gameTiming.CurTime;
}
/// <summary> /// <summary>
/// Update the UI state based on server-sent info /// Update the UI state based on server-sent info
/// </summary> /// </summary>
@@ -63,4 +72,11 @@ public sealed class SignalTimerBoundUserInterface : BoundUserInterface
_window.SetTimerStarted(cast.TimerStarted); _window.SetTimerStarted(cast.TimerStarted);
_window.SetHasAccess(cast.HasAccess); _window.SetHasAccess(cast.HasAccess);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
} }

View File

@@ -9,44 +9,42 @@ namespace Content.Client.MachineLinking.UI;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class SignalTimerWindow : DefaultWindow public sealed partial class SignalTimerWindow : DefaultWindow
{ {
[Dependency] private readonly IGameTiming _timing = default!;
private const int MaxTextLength = 5; private const int MaxTextLength = 5;
public event Action<string>? OnCurrentTextChanged; public event Action<string>? OnCurrentTextChanged;
public event Action<string>? OnCurrentDelayMinutesChanged; public event Action<string>? OnCurrentDelayMinutesChanged;
public event Action<string>? OnCurrentDelaySecondsChanged; public event Action<string>? OnCurrentDelaySecondsChanged;
private readonly SignalTimerBoundUserInterface _owner;
private TimeSpan? _triggerTime; private TimeSpan? _triggerTime;
private bool _timerStarted; private bool _timerStarted;
public event Action? OnStartTimer; public SignalTimerWindow(SignalTimerBoundUserInterface owner)
public SignalTimerWindow()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_owner = owner;
CurrentTextEdit.OnTextChanged += e => OnCurrentTextChange(e.Text); CurrentTextEdit.OnTextChanged += e => OnCurrentTextChange(e.Text);
CurrentDelayEditMinutes.OnTextChanged += e => OnCurrentDelayMinutesChange(e.Text); CurrentDelayEditMinutes.OnTextChanged += e => OnCurrentDelayMinutesChange(e.Text);
CurrentDelayEditSeconds.OnTextChanged += e => OnCurrentDelaySecondsChange(e.Text); CurrentDelayEditSeconds.OnTextChanged += e => OnCurrentDelaySecondsChange(e.Text);
StartTimer.OnPressed += _ => StartTimerWeh(); StartTimer.OnPressed += _ => OnStartTimer();
} }
private void StartTimerWeh() public void OnStartTimer()
{ {
if (!_timerStarted) if (!_timerStarted)
{ {
_timerStarted = true; _timerStarted = true;
_triggerTime = _timing.CurTime + GetDelay(); _triggerTime = _owner.GetCurrentTime() + GetDelay();
} }
else else
{ {
SetTimerStarted(false); SetTimerStarted(false);
} }
_owner.OnStartTimer();
OnStartTimer?.Invoke();
} }
protected override void FrameUpdate(FrameEventArgs args) protected override void FrameUpdate(FrameEventArgs args)
@@ -56,9 +54,9 @@ public sealed partial class SignalTimerWindow : DefaultWindow
if (!_timerStarted || _triggerTime == null) if (!_timerStarted || _triggerTime == null)
return; return;
if (_timing.CurTime < _triggerTime.Value) if (_owner.GetCurrentTime() < _triggerTime.Value)
{ {
StartTimer.Text = TextScreenSystem.TimeToString(_triggerTime.Value - _timing.CurTime); StartTimer.Text = TextScreenSystem.TimeToString(_triggerTime.Value - _owner.GetCurrentTime());
} }
else else
{ {

View File

@@ -1,7 +1,6 @@
using Content.Shared.Humanoid.Markings; using Content.Shared.Humanoid.Markings;
using Content.Shared.MagicMirror; using Content.Shared.MagicMirror;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.MagicMirror; namespace Content.Client.MagicMirror;
@@ -18,7 +17,7 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<MagicMirrorWindow>(); _window = new();
_window.OnHairSelected += tuple => SelectHair(MagicMirrorCategory.Hair, tuple.id, tuple.slot); _window.OnHairSelected += tuple => SelectHair(MagicMirrorCategory.Hair, tuple.id, tuple.slot);
_window.OnHairColorChanged += args => ChangeColor(MagicMirrorCategory.Hair, args.marking, args.slot); _window.OnHairColorChanged += args => ChangeColor(MagicMirrorCategory.Hair, args.marking, args.slot);
@@ -30,6 +29,9 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface
args => ChangeColor(MagicMirrorCategory.FacialHair, args.marking, args.slot); args => ChangeColor(MagicMirrorCategory.FacialHair, args.marking, args.slot);
_window.OnFacialHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.FacialHair); }; _window.OnFacialHairSlotAdded += delegate () { AddSlot(MagicMirrorCategory.FacialHair); };
_window.OnFacialHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.FacialHair, args); _window.OnFacialHairSlotRemoved += args => RemoveSlot(MagicMirrorCategory.FacialHair, args);
_window.OnClose += Close;
_window.OpenCentered();
} }
private void SelectHair(MagicMirrorCategory category, string marking, int slot) private void SelectHair(MagicMirrorCategory category, string marking, int slot)
@@ -63,5 +65,14 @@ public sealed class MagicMirrorBoundUserInterface : BoundUserInterface
_window.UpdateState(data); _window.UpdateState(data);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_window?.Dispose();
}
} }

View File

@@ -1,7 +1,6 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Content.Shared.MassMedia.Systems; using Content.Shared.MassMedia.Systems;
using Content.Shared.MassMedia.Components; using Content.Shared.MassMedia.Components;
using Robust.Client.UserInterface;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -10,6 +9,8 @@ namespace Content.Client.MassMedia.Ui;
[UsedImplicitly] [UsedImplicitly]
public sealed class NewsWriterBoundUserInterface : BoundUserInterface public sealed class NewsWriterBoundUserInterface : BoundUserInterface
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!;
[ViewVariables] [ViewVariables]
private NewsWriterMenu? _menu; private NewsWriterMenu? _menu;
@@ -20,7 +21,10 @@ public sealed class NewsWriterBoundUserInterface : BoundUserInterface
protected override void Open() protected override void Open()
{ {
_menu = this.CreateWindow<NewsWriterMenu>(); _menu = new NewsWriterMenu(_gameTiming);
_menu.OpenCentered();
_menu.OnClose += Close;
_menu.ArticleEditorPanel.PublishButtonPressed += OnPublishButtonPressed; _menu.ArticleEditorPanel.PublishButtonPressed += OnPublishButtonPressed;
_menu.DeleteButtonPressed += OnDeleteButtonPressed; _menu.DeleteButtonPressed += OnDeleteButtonPressed;
@@ -28,6 +32,16 @@ public sealed class NewsWriterBoundUserInterface : BoundUserInterface
SendMessage(new NewsWriterArticlesRequestMessage()); 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) protected override void UpdateState(BoundUserInterfaceState state)
{ {
base.UpdateState(state); base.UpdateState(state);

View File

@@ -10,17 +10,17 @@ namespace Content.Client.MassMedia.Ui;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class NewsWriterMenu : FancyWindow public sealed partial class NewsWriterMenu : FancyWindow
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!; private readonly IGameTiming _gameTiming;
private TimeSpan? _nextPublish; private TimeSpan? _nextPublish;
public event Action<int>? DeleteButtonPressed; public event Action<int>? DeleteButtonPressed;
public NewsWriterMenu() public NewsWriterMenu(IGameTiming gameTiming)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_gameTiming = gameTiming;
ContentsContainer.RectClipContent = false; ContentsContainer.RectClipContent = false;
// Customize scrollbar width and margin. This is not possible in xaml // Customize scrollbar width and margin. This is not possible in xaml

View File

@@ -3,7 +3,6 @@ using Content.Shared.Mech;
using Content.Shared.Mech.Components; using Content.Shared.Mech.Components;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Mech.Ui; namespace Content.Client.Mech.Ui;
@@ -21,8 +20,9 @@ public sealed class MechBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<MechMenu>(); _menu = new(Owner);
_menu.SetEntity(Owner);
_menu.OnClose += Close;
_menu.OpenCenteredLeft(); _menu.OpenCenteredLeft();
_menu.OnRemoveButtonPressed += uid => _menu.OnRemoveButtonPressed += uid =>
@@ -60,6 +60,16 @@ public sealed class MechBoundUserInterface : BoundUserInterface
} }
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Close();
}
public UIFragment? GetEquipmentUi(EntityUid? uid) public UIFragment? GetEquipmentUi(EntityUid? uid)
{ {
var component = EntMan.GetComponentOrNull<UIFragmentComponent>(uid); var component = EntMan.GetComponentOrNull<UIFragmentComponent>(uid);

View File

@@ -16,15 +16,14 @@ public sealed partial class MechMenu : FancyWindow
public event Action<EntityUid>? OnRemoveButtonPressed; public event Action<EntityUid>? OnRemoveButtonPressed;
public MechMenu() public MechMenu(EntityUid mech)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
}
public void SetEntity(EntityUid uid) _mech = mech;
{
MechView.SetEntity(uid); MechView.SetEntity(mech);
} }
public void UpdateMechStats() public void UpdateMechStats()

View File

@@ -1,5 +1,4 @@
using Content.Shared.Medical.CrewMonitoring; using Content.Shared.Medical.CrewMonitoring;
using Robust.Client.UserInterface;
namespace Content.Client.Medical.CrewMonitoring; namespace Content.Client.Medical.CrewMonitoring;
@@ -15,7 +14,7 @@ public sealed class CrewMonitoringBoundUserInterface : BoundUserInterface
protected override void Open() protected override void Open()
{ {
EntityUid? gridUid = null; EntityUid? gridUid = null;
var stationName = string.Empty; string stationName = string.Empty;
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform)) if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
{ {
@@ -27,8 +26,10 @@ public sealed class CrewMonitoringBoundUserInterface : BoundUserInterface
} }
} }
_menu = this.CreateWindow<CrewMonitoringWindow>(); _menu = new CrewMonitoringWindow(stationName, gridUid);
_menu.Set(stationName, gridUid);
_menu.OpenCentered();
_menu.OnClose += Close;
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -43,4 +44,13 @@ public sealed class CrewMonitoringBoundUserInterface : BoundUserInterface
break; break;
} }
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
} }

View File

@@ -23,27 +23,22 @@ namespace Content.Client.Medical.CrewMonitoring;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class CrewMonitoringWindow : FancyWindow public sealed partial class CrewMonitoringWindow : FancyWindow
{ {
[Dependency] private readonly IEntityManager _entManager = default!; private readonly IEntityManager _entManager;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; private readonly IPrototypeManager _prototypeManager;
private readonly SpriteSystem _spriteSystem; private readonly SpriteSystem _spriteSystem;
private NetEntity? _trackedEntity; private NetEntity? _trackedEntity;
private bool _tryToScrollToListFocus; private bool _tryToScrollToListFocus;
private Texture? _blipTexture; private Texture? _blipTexture;
public CrewMonitoringWindow() public CrewMonitoringWindow(string stationName, EntityUid? mapUid)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_entManager = IoCManager.Resolve<IEntityManager>();
_prototypeManager = IoCManager.Resolve<IPrototypeManager>();
_spriteSystem = _entManager.System<SpriteSystem>(); _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"))); _blipTexture = _spriteSystem.Frame0(new SpriteSpecifier.Texture(new ResPath("/Textures/Interface/NavMap/beveled_circle.png")));
if (_entManager.TryGetComponent<TransformComponent>(mapUid, out var xform)) if (_entManager.TryGetComponent<TransformComponent>(mapUid, out var xform))
@@ -54,6 +49,8 @@ public sealed partial class CrewMonitoringWindow : FancyWindow
StationName.AddStyleClass("LabelBig"); StationName.AddStyleClass("LabelBig");
StationName.Text = stationName; StationName.Text = stationName;
NavMap.TrackedEntitySelectedAction += SetTrackedEntityFromNavMap;
NavMap.ForceNavMapUpdate(); NavMap.ForceNavMapUpdate();
} }

View File

@@ -1,7 +1,6 @@
using Content.Client.NetworkConfigurator.Systems; using Content.Client.NetworkConfigurator.Systems;
using Content.Shared.DeviceNetwork; using Content.Shared.DeviceNetwork;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
namespace Content.Client.NetworkConfigurator; namespace Content.Client.NetworkConfigurator;
@@ -36,12 +35,14 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
switch (UiKey) switch (UiKey)
{ {
case NetworkConfiguratorUiKey.List: case NetworkConfiguratorUiKey.List:
_listMenu = this.CreateWindow<NetworkConfiguratorListMenu>(); _listMenu = new NetworkConfiguratorListMenu(this);
_listMenu.OnClose += Close;
_listMenu.ClearButton.OnPressed += _ => OnClearButtonPressed(); _listMenu.ClearButton.OnPressed += _ => OnClearButtonPressed();
_listMenu.OnRemoveAddress += OnRemoveButtonPressed; _listMenu.OpenCenteredRight();
break; break;
case NetworkConfiguratorUiKey.Configure: case NetworkConfiguratorUiKey.Configure:
_configurationMenu = this.CreateWindow<NetworkConfiguratorConfigurationMenu>(); _configurationMenu = new NetworkConfiguratorConfigurationMenu();
_configurationMenu.OnClose += Close;
_configurationMenu.Set.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Set); _configurationMenu.Set.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Set);
_configurationMenu.Add.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Add); _configurationMenu.Add.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Add);
//_configurationMenu.Edit.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Edit); //_configurationMenu.Edit.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Edit);
@@ -49,24 +50,12 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
_configurationMenu.Copy.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Copy); _configurationMenu.Copy.OnPressed += _ => OnConfigButtonPressed(NetworkConfiguratorButtonKey.Copy);
_configurationMenu.Show.OnPressed += OnShowPressed; _configurationMenu.Show.OnPressed += OnShowPressed;
_configurationMenu.Show.Pressed = _netConfig.ConfiguredListIsTracked(Owner); _configurationMenu.Show.Pressed = _netConfig.ConfiguredListIsTracked(Owner);
_configurationMenu.OnRemoveAddress += OnRemoveButtonPressed; _configurationMenu.OpenCentered();
break; break;
case NetworkConfiguratorUiKey.Link: case NetworkConfiguratorUiKey.Link:
_linkMenu = this.CreateWindow<NetworkConfiguratorLinkMenu>(); _linkMenu = new NetworkConfiguratorLinkMenu(this);
_linkMenu.OnLinkDefaults += args => _linkMenu.OnClose += Close;
{ _linkMenu.OpenCentered();
SendMessage(new NetworkConfiguratorLinksSaveMessage(args));
};
_linkMenu.OnToggleLink += (left, right) =>
{
SendMessage(new NetworkConfiguratorToggleLinkMessage(left, right));
};
_linkMenu.OnClearLinks += () =>
{
SendMessage(new NetworkConfiguratorClearLinksMessage());
};
break; break;
} }
} }
@@ -94,6 +83,16 @@ public sealed class NetworkConfiguratorBoundUserInterface : BoundUserInterface
} }
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_linkMenu?.Dispose();
_listMenu?.Dispose();
_configurationMenu?.Dispose();
}
private void OnClearButtonPressed() private void OnClearButtonPressed()
{ {
SendMessage(new NetworkConfiguratorClearDevicesMessage()); SendMessage(new NetworkConfiguratorClearDevicesMessage());

View File

@@ -9,23 +9,17 @@ namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorConfigurationMenu : FancyWindow public sealed partial class NetworkConfiguratorConfigurationMenu : FancyWindow
{ {
public event Action<string>? OnRemoveAddress;
public NetworkConfiguratorConfigurationMenu() public NetworkConfiguratorConfigurationMenu()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
Clear.StyleClasses.Add(StyleBase.ButtonOpenLeft); Clear.StyleClasses.Add(StyleBase.ButtonOpenLeft);
Clear.StyleClasses.Add(StyleNano.StyleClassButtonColorRed); Clear.StyleClasses.Add(StyleNano.StyleClassButtonColorRed);
DeviceList.OnRemoveAddress += args =>
{
OnRemoveAddress?.Invoke(args);
};
} }
public void UpdateState(DeviceListUserInterfaceState state) public void UpdateState(DeviceListUserInterfaceState state)
{ {
DeviceList.UpdateState(state.DeviceList, false); DeviceList.UpdateState(null, state.DeviceList);
Count.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count)); Count.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count));
} }

View File

@@ -7,19 +7,17 @@ namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer
{ {
public event Action<string>? OnRemoveAddress; public void UpdateState(NetworkConfiguratorBoundUserInterface? ui, HashSet<(string address, string name)> devices)
public void UpdateState(HashSet<(string address, string name)> devices, bool ui)
{ {
DeviceList.RemoveAllChildren(); DeviceList.RemoveAllChildren();
foreach (var device in devices) foreach (var device in devices)
{ {
DeviceList.AddChild(BuildDeviceListRow(device, ui)); DeviceList.AddChild(BuildDeviceListRow(ui, device));
} }
} }
private BoxContainer BuildDeviceListRow((string address, string name) savedDevice, bool ui) private static BoxContainer BuildDeviceListRow(NetworkConfiguratorBoundUserInterface? ui, (string address, string name) savedDevice)
{ {
var row = new BoxContainer() var row = new BoxContainer()
{ {
@@ -50,10 +48,10 @@ public sealed partial class NetworkConfiguratorDeviceList : ScrollContainer
row.AddChild(name); row.AddChild(name);
row.AddChild(address); row.AddChild(address);
if (ui) if (ui != null)
{ {
row.AddChild(removeButton); row.AddChild(removeButton);
removeButton.OnPressed += _ => OnRemoveAddress?.Invoke(savedDevice.address); removeButton.OnPressed += _ => ui.OnRemoveButtonPressed(savedDevice.address);
} }
return row; return row;

View File

@@ -18,20 +18,20 @@ public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
private readonly LinksRender _links; private readonly LinksRender _links;
private readonly List<SourcePortPrototype> _sources = new(); private readonly List<SourcePortPrototype> _sources = new();
private readonly List<SinkPortPrototype> _sinks = new(); private readonly List<SinkPortPrototype> _sinks = new();
private readonly NetworkConfiguratorBoundUserInterface _userInterface;
private (ButtonPosition position, string id, int index)? _selectedButton; private (ButtonPosition position, string id, int index)? _selectedButton;
private List<(string left, string right)>? _defaults; private List<(string left, string right)>? _defaults;
public event Action? OnClearLinks; public NetworkConfiguratorLinkMenu(NetworkConfiguratorBoundUserInterface userInterface)
public event Action<string, string>? OnToggleLink;
public event Action<List<(string left, string right)>>? OnLinkDefaults;
public NetworkConfiguratorLinkMenu()
{ {
_userInterface = userInterface;
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
var footerStyleBox = new StyleBoxFlat() var footerStyleBox = new StyleBoxFlat()
@@ -52,7 +52,7 @@ public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
ButtonOk.OnPressed += _ => Close(); ButtonOk.OnPressed += _ => Close();
ButtonLinkDefault.OnPressed += _ => LinkDefaults(); ButtonLinkDefault.OnPressed += _ => LinkDefaults();
ButtonClear.OnPressed += _ => OnClearLinks?.Invoke(); ButtonClear.OnPressed += _ => _userInterface.SendMessage(new NetworkConfiguratorClearLinksMessage());
} }
public void UpdateState(DeviceLinkUserInterfaceState linkState) public void UpdateState(DeviceLinkUserInterfaceState linkState)
@@ -98,7 +98,7 @@ public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
if (_defaults == default) if (_defaults == default)
return; return;
OnLinkDefaults?.Invoke(_defaults); _userInterface.SendMessage(new NetworkConfiguratorLinksSaveMessage(_defaults));
} }
private Button CreateButton(ButtonPosition position, string name, string description, string id, int index) private Button CreateButton(ButtonPosition position, string name, string description, string id, int index)
@@ -138,7 +138,7 @@ public sealed partial class NetworkConfiguratorLinkMenu : FancyWindow
var left = _selectedButton.Value.position == ButtonPosition.Left ? _selectedButton.Value.id : id; var left = _selectedButton.Value.position == ButtonPosition.Left ? _selectedButton.Value.id : id;
var right = _selectedButton.Value.position == ButtonPosition.Left ? id : _selectedButton.Value.id; var right = _selectedButton.Value.position == ButtonPosition.Left ? id : _selectedButton.Value.id;
OnToggleLink?.Invoke(left, right); _userInterface.SendMessage(new NetworkConfiguratorToggleLinkMessage(left, right));
args.Button.Pressed = false; args.Button.Pressed = false;

View File

@@ -9,20 +9,17 @@ namespace Content.Client.NetworkConfigurator;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class NetworkConfiguratorListMenu : FancyWindow public sealed partial class NetworkConfiguratorListMenu : FancyWindow
{ {
public event Action<string>? OnRemoveAddress; private readonly NetworkConfiguratorBoundUserInterface _ui;
public NetworkConfiguratorListMenu(NetworkConfiguratorBoundUserInterface ui)
public NetworkConfiguratorListMenu()
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
DeviceList.OnRemoveAddress += args =>
{ _ui = ui;
OnRemoveAddress?.Invoke(args);
};
} }
public void UpdateState(NetworkConfiguratorUserInterfaceState state) public void UpdateState(NetworkConfiguratorUserInterfaceState state)
{ {
DeviceCountLabel.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count)); DeviceCountLabel.Text = Loc.GetString("network-configurator-ui-count-label", ("count", state.DeviceList.Count));
DeviceList.UpdateState(state.DeviceList, true); DeviceList.UpdateState(_ui, state.DeviceList);
} }
} }

View File

@@ -2,7 +2,6 @@ using Content.Shared.Containers.ItemSlots;
using Content.Shared.Nuke; using Content.Shared.Nuke;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Nuke namespace Content.Client.Nuke
{ {
@@ -12,13 +11,15 @@ namespace Content.Client.Nuke
[ViewVariables] [ViewVariables]
private NukeMenu? _menu; private NukeMenu? _menu;
public NukeBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) public NukeBoundUserInterface([NotNull] EntityUid owner, [NotNull] Enum uiKey) : base(owner, uiKey)
{ {
} }
protected override void Open() protected override void Open()
{ {
_menu = this.CreateWindow<NukeMenu>(); _menu = new NukeMenu();
_menu.OpenCentered();
_menu.OnClose += Close;
_menu.OnKeypadButtonPressed += i => _menu.OnKeypadButtonPressed += i =>
{ {
@@ -61,5 +62,15 @@ namespace Content.Client.Nuke
break; break;
} }
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Close();
_menu?.Dispose();
}
} }
} }

View File

@@ -2,7 +2,6 @@
using Content.Shared.Chat; using Content.Shared.Chat;
using Content.Shared.NukeOps; using Content.Shared.NukeOps;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -12,6 +11,8 @@ namespace Content.Client.NukeOps;
public sealed class WarDeclaratorBoundUserInterface : BoundUserInterface public sealed class WarDeclaratorBoundUserInterface : BoundUserInterface
{ {
[Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ILocalizationManager _localizationManager = default!;
[ViewVariables] [ViewVariables]
private WarDeclaratorWindow? _window; private WarDeclaratorWindow? _window;
@@ -22,7 +23,13 @@ public sealed class WarDeclaratorBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<WarDeclaratorWindow>(); _window = new WarDeclaratorWindow(_gameTiming, _localizationManager);
if (State != null)
UpdateState(State);
_window.OpenCentered();
_window.OnClose += Close;
_window.OnActivated += OnWarDeclaratorActivated; _window.OnActivated += OnWarDeclaratorActivated;
} }
@@ -35,6 +42,13 @@ public sealed class WarDeclaratorBoundUserInterface : BoundUserInterface
_window?.UpdateState(cast); _window?.UpdateState(cast);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
_window?.Dispose();
}
private void OnWarDeclaratorActivated(string message) private void OnWarDeclaratorActivated(string message)
{ {
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength); var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);

View File

@@ -11,8 +11,7 @@ namespace Content.Client.NukeOps;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class WarDeclaratorWindow : FancyWindow public sealed partial class WarDeclaratorWindow : FancyWindow
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!; private readonly IGameTiming _gameTiming;
[Dependency] private readonly ILocalizationManager _localizationManager = default!;
public event Action<string>? OnActivated; public event Action<string>? OnActivated;
@@ -20,13 +19,15 @@ public sealed partial class WarDeclaratorWindow : FancyWindow
private TimeSpan _shuttleDisabledTime; private TimeSpan _shuttleDisabledTime;
private WarConditionStatus _status; private WarConditionStatus _status;
public WarDeclaratorWindow() public WarDeclaratorWindow(IGameTiming gameTiming, ILocalizationManager localizationManager)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
_gameTiming = gameTiming;
WarButton.OnPressed += (_) => OnActivated?.Invoke(Rope.Collapse(MessageEdit.TextRope)); 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) protected override void FrameUpdate(FrameEventArgs args)

View File

@@ -24,13 +24,14 @@ namespace Content.Client.PDA
if (_menu == null) if (_menu == null)
CreateMenu(); CreateMenu();
_menu?.OpenCenteredLeft();
} }
private void CreateMenu() private void CreateMenu()
{ {
_menu = this.CreateWindow<PdaMenu>(); _menu = new PdaMenu();
_menu.OpenCenteredLeft(); _menu.OnClose += Close;
_menu.FlashLightToggleButton.OnToggled += _ => _menu.FlashLightToggleButton.OnToggled += _ =>
{ {
SendMessage(new PdaToggleFlashlightMessage()); SendMessage(new PdaToggleFlashlightMessage());
@@ -95,6 +96,7 @@ namespace Content.Client.PDA
_menu?.UpdateState(updateState); _menu?.UpdateState(updateState);
} }
protected override void AttachCartridgeUI(Control cartridgeUIFragment, string? title) protected override void AttachCartridgeUI(Control cartridgeUIFragment, string? title)
{ {
_menu?.ProgramView.AddChild(cartridgeUIFragment); _menu?.ProgramView.AddChild(cartridgeUIFragment);
@@ -116,6 +118,15 @@ namespace Content.Client.PDA
_menu?.UpdateAvailablePrograms(programs); _menu?.UpdateAvailablePrograms(programs);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
private PdaBorderColorComponent? GetBorderColorComponent() private PdaBorderColorComponent? GetBorderColorComponent()
{ {
return EntMan.GetComponentOrNull<PdaBorderColorComponent>(Owner); return EntMan.GetComponentOrNull<PdaBorderColorComponent>(Owner);

View File

@@ -1,7 +1,6 @@
using Content.Shared.PDA; using Content.Shared.PDA;
using Content.Shared.PDA.Ringer; using Content.Shared.PDA.Ringer;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Shared.Timing; using Robust.Shared.Timing;
namespace Content.Client.PDA.Ringer namespace Content.Client.PDA.Ringer
@@ -19,8 +18,9 @@ namespace Content.Client.PDA.Ringer
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<RingtoneMenu>(); _menu = new RingtoneMenu();
_menu.OpenToLeft(); _menu.OpenToLeft();
_menu.OnClose += Close;
_menu.TestRingerButton.OnPressed += _ => _menu.TestRingerButton.OnPressed += _ =>
{ {

View File

@@ -1,5 +1,4 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using static Content.Shared.Paper.SharedPaperComponent; using static Content.Shared.Paper.SharedPaperComponent;
@@ -20,13 +19,16 @@ public sealed class PaperBoundUserInterface : BoundUserInterface
{ {
base.Open(); base.Open();
_window = this.CreateWindow<PaperWindow>(); _window = new PaperWindow();
_window.OnSaved += InputOnTextEntered; _window.OnClose += Close;
_window.OnSaved += Input_OnTextEntered;
if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals)) if (EntMan.TryGetComponent<PaperVisualsComponent>(Owner, out var visuals))
{ {
_window.InitVisuals(Owner, visuals); _window.InitVisuals(Owner, visuals);
} }
_window.OpenCentered();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -35,7 +37,7 @@ public sealed class PaperBoundUserInterface : BoundUserInterface
_window?.Populate((PaperBoundUserInterfaceState) state); _window?.Populate((PaperBoundUserInterfaceState) state);
} }
private void InputOnTextEntered(string text) private void Input_OnTextEntered(string text)
{ {
SendMessage(new PaperInputTextMessage(text)); SendMessage(new PaperInputTextMessage(text));
@@ -45,4 +47,11 @@ public sealed class PaperBoundUserInterface : BoundUserInterface
_window.Input.CursorPosition = new TextEdit.CursorPos(0, TextEdit.LineBreakBias.Top); _window.Input.CursorPosition = new TextEdit.CursorPos(0, TextEdit.LineBreakBias.Top);
} }
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
} }

View File

@@ -17,7 +17,6 @@ namespace Content.Client.Paper.UI
public sealed partial class PaperWindow : BaseWindow public sealed partial class PaperWindow : BaseWindow
{ {
[Dependency] private readonly IInputManager _inputManager = default!; [Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IResourceCache _resCache = default!;
private static Color DefaultTextColor = new(25, 25, 25); private static Color DefaultTextColor = new(25, 25, 25);
@@ -86,10 +85,11 @@ namespace Content.Client.Paper.UI
// Randomize the placement of any stamps based on the entity UID // Randomize the placement of any stamps based on the entity UID
// so that there's some variety in different papers. // so that there's some variety in different papers.
StampDisplay.PlacementSeed = (int)entity; StampDisplay.PlacementSeed = (int)entity;
var resCache = IoCManager.Resolve<IResourceCache>();
// Initialize the background: // Initialize the background:
PaperBackground.ModulateSelfOverride = visuals.BackgroundModulate; 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) if (backgroundImage != null)
{ {
var backgroundImageMode = visuals.BackgroundImageTile ? StyleBoxTexture.StretchMode.Tile : StyleBoxTexture.StretchMode.Stretch; var backgroundImageMode = visuals.BackgroundImageTile ? StyleBoxTexture.StretchMode.Tile : StyleBoxTexture.StretchMode.Stretch;
@@ -127,7 +127,7 @@ namespace Content.Client.Paper.UI
PaperContent.ModulateSelfOverride = visuals.ContentImageModulate; PaperContent.ModulateSelfOverride = visuals.ContentImageModulate;
WrittenTextLabel.ModulateSelfOverride = visuals.FontAccentColor; 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) if (contentImage != null)
{ {
// Setup the paper content texture, but keep a reference to it, as we can't set // Setup the paper content texture, but keep a reference to it, as we can't set

View File

@@ -1,6 +1,5 @@
using Content.Shared.Singularity.Components; using Content.Shared.Singularity.Components;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.ParticleAccelerator.UI namespace Content.Client.ParticleAccelerator.UI
{ {
@@ -17,10 +16,9 @@ namespace Content.Client.ParticleAccelerator.UI
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<ParticleAcceleratorControlMenu>(); _menu = new ParticleAcceleratorControlMenu(this);
_menu.OnOverallState += SendEnableMessage; _menu.OnClose += Close;
_menu.OnPowerState += SendPowerStateMessage; _menu.OpenCentered();
_menu.OnScanPartsRequested += SendScanPartsMessage;
} }
public void SendEnableMessage(bool enable) public void SendEnableMessage(bool enable)
@@ -42,5 +40,13 @@ namespace Content.Client.ParticleAccelerator.UI
{ {
_menu?.DataUpdate((ParticleAcceleratorUIState) state); _menu?.DataUpdate((ParticleAcceleratorUIState) state);
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_menu?.Dispose();
_menu = null;
}
} }
} }

View File

@@ -18,11 +18,10 @@ namespace Content.Client.ParticleAccelerator.UI
{ {
public sealed class ParticleAcceleratorControlMenu : BaseWindow public sealed class ParticleAcceleratorControlMenu : BaseWindow
{ {
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IResourceCache _cache = default!;
private readonly ShaderInstance _greyScaleShader; private readonly ShaderInstance _greyScaleShader;
private readonly ParticleAcceleratorBoundUserInterface _owner;
private readonly Label _drawLabel; private readonly Label _drawLabel;
private readonly FastNoiseLite _drawNoiseGenerator; private readonly FastNoiseLite _drawNoiseGenerator;
private readonly Button _onButton; private readonly Button _onButton;
@@ -51,21 +50,19 @@ namespace Content.Client.ParticleAccelerator.UI
private bool _shouldContinueAnimating; private bool _shouldContinueAnimating;
private int _maxStrength = 3; private int _maxStrength = 3;
public event Action<bool>? OnOverallState; public ParticleAcceleratorControlMenu(ParticleAcceleratorBoundUserInterface owner)
public event Action<ParticleAcceleratorPowerState>? OnPowerState;
public event Action? OnScanPartsRequested;
public ParticleAcceleratorControlMenu()
{ {
SetSize = new Vector2(400, 320); SetSize = new Vector2(400, 320);
_greyScaleShader = _protoManager.Index<ShaderPrototype>("Greyscale").Instance(); _greyScaleShader = IoCManager.Resolve<IPrototypeManager>().Index<ShaderPrototype>("Greyscale").Instance();
_owner = owner;
_drawNoiseGenerator = new(); _drawNoiseGenerator = new();
_drawNoiseGenerator.SetFractalType(FastNoiseLite.FractalType.FBm); _drawNoiseGenerator.SetFractalType(FastNoiseLite.FractalType.FBm);
_drawNoiseGenerator.SetFrequency(0.5f); _drawNoiseGenerator.SetFrequency(0.5f);
var font = _cache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13); var resourceCache = IoCManager.Resolve<IResourceCache>();
var panelTex = _cache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png"); var font = resourceCache.GetFont("/Fonts/Boxfont-round/Boxfont Round.ttf", 13);
var panelTex = resourceCache.GetTexture("/Textures/Interface/Nano/button.svg.96dpi.png");
MouseFilter = MouseFilterMode.Stop; MouseFilter = MouseFilterMode.Stop;
@@ -115,8 +112,7 @@ namespace Content.Client.ParticleAccelerator.UI
Text = Loc.GetString("particle-accelerator-control-menu-off-button"), Text = Loc.GetString("particle-accelerator-control-menu-off-button"),
StyleClasses = { StyleBase.ButtonOpenRight }, StyleClasses = { StyleBase.ButtonOpenRight },
}; };
_offButton.OnPressed += args => owner.SendEnableMessage(false);
_offButton.OnPressed += args => OnOverallState?.Invoke(false);
_onButton = new Button _onButton = new Button
{ {
@@ -124,7 +120,7 @@ namespace Content.Client.ParticleAccelerator.UI
Text = Loc.GetString("particle-accelerator-control-menu-on-button"), Text = Loc.GetString("particle-accelerator-control-menu-on-button"),
StyleClasses = { StyleBase.ButtonOpenLeft }, StyleClasses = { StyleBase.ButtonOpenLeft },
}; };
_onButton.OnPressed += args => OnOverallState?.Invoke(true); _onButton.OnPressed += args => owner.SendEnableMessage(true);
var closeButton = new TextureButton var closeButton = new TextureButton
{ {
@@ -320,7 +316,7 @@ namespace Content.Client.ParticleAccelerator.UI
} }
}); });
_scanButton.OnPressed += args => OnScanPartsRequested?.Invoke(); _scanButton.OnPressed += args => _owner.SendScanPartsMessage();
_alarmControl.AnimationCompleted += s => _alarmControl.AnimationCompleted += s =>
{ {
@@ -336,7 +332,7 @@ namespace Content.Client.ParticleAccelerator.UI
PASegmentControl Segment(string name) PASegmentControl Segment(string name)
{ {
return new(this, _cache, name); return new(this, resourceCache, name);
} }
UpdateUI(false, false, false, false); UpdateUI(false, false, false, false);
@@ -372,7 +368,7 @@ namespace Content.Client.ParticleAccelerator.UI
} }
_stateSpinBox.SetButtonDisabled(true); _stateSpinBox.SetButtonDisabled(true);
OnPowerState?.Invoke(newState); _owner.SendPowerStateMessage(newState);
} }
protected override DragMode GetDragModeFor(Vector2 relativeMousePos) protected override DragMode GetDragModeFor(Vector2 relativeMousePos)

View File

@@ -1,6 +1,5 @@
using Content.Shared.Pinpointer; using Content.Shared.Pinpointer;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Pinpointer.UI; namespace Content.Client.Pinpointer.UI;
@@ -17,16 +16,19 @@ public sealed class NavMapBeaconBoundUserInterface : BoundUserInterface
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window = this.CreateWindow<NavMapBeaconWindow>(); _window = new NavMapBeaconWindow(Owner);
_window.OpenCentered();
if (EntMan.TryGetComponent(Owner, out NavMapBeaconComponent? beacon)) _window.OnClose += Close;
{
_window.SetEntity(Owner, beacon);
}
_window.OnApplyButtonPressed += (label, enabled, color) => _window.OnApplyButtonPressed += (label, enabled, color) =>
{ {
SendMessage(new NavMapBeaconConfigureBuiMessage(label, enabled, color)); SendMessage(new NavMapBeaconConfigureBuiMessage(label, enabled, color));
}; };
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
}
} }

View File

@@ -10,35 +10,36 @@ namespace Content.Client.Pinpointer.UI;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class NavMapBeaconWindow : FancyWindow public sealed partial class NavMapBeaconWindow : FancyWindow
{ {
[Dependency] private readonly IEntityManager _entityManager = default!;
private string? _defaultLabel; private string? _defaultLabel;
private bool _defaultEnabled; private bool _defaultEnabled;
private Color _defaultColor; private Color _defaultColor;
public event Action<string?, bool, Color>? OnApplyButtonPressed; public event Action<string?, bool, Color>? OnApplyButtonPressed;
public NavMapBeaconWindow() public NavMapBeaconWindow(EntityUid beaconEntity)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
if (!_entityManager.TryGetComponent<NavMapBeaconComponent>(beaconEntity, out var navMap))
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed); return;
LabelLineEdit.OnTextChanged += OnTextChanged;
ColorSelector.OnColorChanged += _ => TryEnableApplyButton();
TryEnableApplyButton();
ApplyButton.OnPressed += OnApplyPressed;
}
public void SetEntity(EntityUid uid, NavMapBeaconComponent navMap)
{
_defaultLabel = navMap.Text; _defaultLabel = navMap.Text;
_defaultEnabled = navMap.Enabled; _defaultEnabled = navMap.Enabled;
_defaultColor = navMap.Color; _defaultColor = navMap.Color;
UpdateVisibleButton(navMap.Enabled); UpdateVisibleButton(navMap.Enabled);
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed);
LabelLineEdit.Text = navMap.Text ?? string.Empty; LabelLineEdit.Text = navMap.Text ?? string.Empty;
LabelLineEdit.OnTextChanged += OnTextChanged;
ColorSelector.Color = navMap.Color; ColorSelector.Color = navMap.Color;
ColorSelector.OnColorChanged += _ => TryEnableApplyButton();
TryEnableApplyButton();
ApplyButton.OnPressed += OnApplyPressed;
} }
private void UpdateVisibleButton(bool value) private void UpdateVisibleButton(bool value)

View File

@@ -1,4 +1,4 @@
using Robust.Client.UserInterface; using Robust.Client.GameObjects;
namespace Content.Client.Pinpointer.UI; namespace Content.Client.Pinpointer.UI;
@@ -14,6 +14,7 @@ public sealed class StationMapBoundUserInterface : BoundUserInterface
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window?.Close();
EntityUid? gridUid = null; EntityUid? gridUid = null;
if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform)) if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
@@ -21,8 +22,14 @@ public sealed class StationMapBoundUserInterface : BoundUserInterface
gridUid = xform.GridUid; gridUid = xform.GridUid;
} }
_window = this.CreateWindow<StationMapWindow>(); _window = new StationMapWindow(gridUid, Owner);
_window.Title = EntMan.GetComponent<MetaDataComponent>(Owner).EntityName; _window.OpenCentered();
_window.Set(gridUid, Owner); _window.OnClose += Close;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
} }
} }

View File

@@ -9,18 +9,19 @@ namespace Content.Client.Pinpointer.UI;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class StationMapWindow : FancyWindow public sealed partial class StationMapWindow : FancyWindow
{ {
public StationMapWindow() public StationMapWindow(EntityUid? mapUid, EntityUid? trackedEntity)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
}
public void Set(EntityUid? mapUid, EntityUid? trackedEntity)
{
NavMapScreen.MapUid = mapUid; NavMapScreen.MapUid = mapUid;
if (trackedEntity != null) if (trackedEntity != null)
NavMapScreen.TrackedCoordinates.Add(new EntityCoordinates(trackedEntity.Value, Vector2.Zero), (true, Color.Cyan)); 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(); NavMapScreen.ForceNavMapUpdate();
} }
} }

View File

@@ -1,4 +1,4 @@
using Robust.Client.UserInterface; using Robust.Client.GameObjects;
namespace Content.Client.Pinpointer.UI; namespace Content.Client.Pinpointer.UI;
@@ -14,15 +14,22 @@ public sealed class UntrackedStationMapBoundUserInterface : BoundUserInterface
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window?.Close();
EntityUid? gridUid = null; 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)) if (EntMan.TryGetComponent<TransformComponent>(Owner, out var xform))
{ {
gridUid = xform.GridUid; gridUid = xform.GridUid;
} }
_window = this.CreateWindow<StationMapWindow>(); _window = new StationMapWindow(gridUid, null);
_window.Set(gridUid, Owner); _window.OpenCentered();
_window.OnClose += Close;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_window?.Dispose();
} }
} }

View File

@@ -2,7 +2,6 @@
using Content.Shared.APC; using Content.Shared.APC;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Power.APC namespace Content.Client.Power.APC
{ {
@@ -20,8 +19,9 @@ namespace Content.Client.Power.APC
{ {
base.Open(); base.Open();
_menu = this.CreateWindow<ApcMenu>(); _menu = new ApcMenu(this);
_menu.OnBreaker += BreakerPressed; _menu.OnClose += Close;
_menu.OpenCentered();
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -36,5 +36,15 @@ namespace Content.Client.Power.APC
{ {
SendMessage(new ApcToggleMainBreakerMessage()); SendMessage(new ApcToggleMainBreakerMessage());
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_menu?.Dispose();
}
}
} }
} }

View File

@@ -17,19 +17,13 @@ namespace Content.Client.Power.APC.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class ApcMenu : FancyWindow public sealed partial class ApcMenu : FancyWindow
{ {
public event Action? OnBreaker; public ApcMenu(ApcBoundUserInterface owner)
public ApcMenu()
{ {
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
BreakerButton.OnPressed += _ => OnBreaker?.Invoke(); EntityView.SetEntity(owner.Owner);
} BreakerButton.OnPressed += _ => owner.BreakerPressed();
public void SetEntity(EntityUid entity)
{
EntityView.SetEntity(entity);
} }
public void UpdateState(BoundUserInterfaceState state) public void UpdateState(BoundUserInterfaceState state)

View File

@@ -9,39 +9,35 @@ namespace Content.Client.Power.Generator;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class GeneratorWindow : FancyWindow public sealed partial class GeneratorWindow : FancyWindow
{ {
private readonly EntityUid _entity;
[Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly ILocalizationManager _loc = default!; [Dependency] private readonly ILocalizationManager _loc = default!;
private EntityUid _entity; private readonly SharedPowerSwitchableSystem _switchable;
private readonly FuelGeneratorComponent? _component;
private PortableGeneratorComponentBuiState? _lastState;
public float? MaximumPower; public GeneratorWindow(PortableGeneratorBoundUserInterface bui, EntityUid entity)
public event Action<int>? OnPower;
public event Action<bool>? OnState;
public event Action? OnSwitchOutput;
public event Action? OnEjectFuel;
public GeneratorWindow()
{ {
_entity = entity;
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
_entityManager.TryGetComponent(entity, out _component);
_switchable = _entityManager.System<SharedPowerSwitchableSystem>();
EntityView.SetEntity(entity);
TargetPower.IsValid += IsValid; TargetPower.IsValid += IsValid;
TargetPower.ValueChanged += (args) => TargetPower.ValueChanged += (args) =>
{ {
OnPower?.Invoke(args.Value); bui.SetTargetPower(args.Value);
}; };
StartButton.OnPressed += _ => OnState?.Invoke(true); StartButton.OnPressed += _ => bui.Start();
StopButton.OnPressed += _ => OnState?.Invoke(false); StopButton.OnPressed += _ => bui.Stop();
OutputSwitchButton.OnPressed += _ => OnSwitchOutput?.Invoke(); OutputSwitchButton.OnPressed += _ => bui.SwitchOutput();
FuelEject.OnPressed += _ => OnEjectFuel?.Invoke(); FuelEject.OnPressed += _ => bui.EjectFuel();
}
public void SetEntity(EntityUid entity)
{
_entity = entity;
EntityView.SetEntity(entity);
} }
private bool IsValid(int arg) private bool IsValid(int arg)
@@ -49,7 +45,7 @@ public sealed partial class GeneratorWindow : FancyWindow
if (arg < 0) if (arg < 0)
return false; return false;
if (arg > (MaximumPower / 1000.0f ?? 0)) if (arg > (_lastState?.MaximumPower / 1000.0f ?? 0))
return false; return false;
return true; return true;
@@ -57,17 +53,16 @@ public sealed partial class GeneratorWindow : FancyWindow
public void Update(PortableGeneratorComponentBuiState state) public void Update(PortableGeneratorComponentBuiState state)
{ {
MaximumPower = state.MaximumPower; if (_component == null)
if (!_entityManager.TryGetComponent(_entity, out FuelGeneratorComponent? component))
return; return;
_lastState = state;
if (!TargetPower.LineEditControl.HasKeyboardFocus()) if (!TargetPower.LineEditControl.HasKeyboardFocus())
TargetPower.OverrideValue((int)(state.TargetPower / 1000.0f)); 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"); Efficiency.Text = efficiency.ToString("P1");
var burnRate = component.OptimalBurnRate / efficiency; var burnRate = _component.OptimalBurnRate / efficiency;
var left = state.RemainingFuel / burnRate; var left = state.RemainingFuel / burnRate;
Eta.Text = Loc.GetString( Eta.Text = Loc.GetString(
@@ -107,15 +102,14 @@ public sealed partial class GeneratorWindow : FancyWindow
} }
var canSwitch = _entityManager.TryGetComponent(_entity, out PowerSwitchableComponent? switchable); var canSwitch = _entityManager.TryGetComponent(_entity, out PowerSwitchableComponent? switchable);
var switcher = _entityManager.System<SharedPowerSwitchableSystem>();
OutputSwitchLabel.Visible = canSwitch; OutputSwitchLabel.Visible = canSwitch;
OutputSwitchButton.Visible = canSwitch; OutputSwitchButton.Visible = canSwitch;
if (switchable != null) if (switchable != null)
{ {
var voltage = switcher.VoltageString(switcher.GetVoltage(_entity, switchable)); var voltage = _switchable.VoltageString(_switchable.GetVoltage(_entity, switchable));
OutputSwitchLabel.Text = Loc.GetString("portable-generator-ui-current-output", ("voltage", voltage)); OutputSwitchLabel.Text = Loc.GetString("portable-generator-ui-current-output", ("voltage", voltage));
var nextVoltage = switcher.VoltageString(switcher.GetNextVoltage(_entity, switchable)); var nextVoltage = _switchable.VoltageString(_switchable.GetNextVoltage(_entity, switchable));
OutputSwitchButton.Text = Loc.GetString("power-switchable-switch-voltage", ("voltage", nextVoltage)); OutputSwitchButton.Text = Loc.GetString("power-switchable-switch-voltage", ("voltage", nextVoltage));
OutputSwitchButton.Disabled = state.On; OutputSwitchButton.Disabled = state.On;
} }

View File

@@ -1,7 +1,6 @@
using Content.Shared.Power.Generator; using Content.Shared.Power.Generator;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
namespace Content.Client.Power.Generator; namespace Content.Client.Power.Generator;
@@ -17,25 +16,10 @@ public sealed class PortableGeneratorBoundUserInterface : BoundUserInterface
protected override void Open() protected override void Open()
{ {
base.Open(); base.Open();
_window = this.CreateWindow<GeneratorWindow>(); _window = new GeneratorWindow(this, Owner);
_window.SetEntity(Owner);
_window.OnState += args =>
{
if (args)
{
Start();
}
else
{
Stop();
}
};
_window.OnPower += SetTargetPower;
_window.OnEjectFuel += EjectFuel;
_window.OnSwitchOutput += SwitchOutput;
_window.OpenCenteredLeft(); _window.OpenCenteredLeft();
_window.OnClose += Close;
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -46,6 +30,11 @@ public sealed class PortableGeneratorBoundUserInterface : BoundUserInterface
_window?.Update(msg); _window?.Update(msg);
} }
protected override void Dispose(bool disposing)
{
_window?.Dispose();
}
public void SetTargetPower(int target) public void SetTargetPower(int target)
{ {
SendMessage(new PortableGeneratorSetTargetPowerMessage(target)); SendMessage(new PortableGeneratorSetTargetPowerMessage(target));

View File

@@ -1,5 +1,4 @@
using Content.Shared.Power; using Content.Shared.Power;
using Robust.Client.UserInterface;
namespace Content.Client.Power; namespace Content.Client.Power;
@@ -12,9 +11,9 @@ public sealed class PowerMonitoringConsoleBoundUserInterface : BoundUserInterfac
protected override void Open() protected override void Open()
{ {
_menu = this.CreateWindow<PowerMonitoringWindow>(); _menu = new PowerMonitoringWindow(this, Owner);
_menu.SetEntity(Owner); _menu.OpenCentered();
_menu.SendPowerMonitoringConsoleMessageAction += SendPowerMonitoringConsoleMessage; _menu.OnClose += Close;
} }
protected override void UpdateState(BoundUserInterfaceState state) protected override void UpdateState(BoundUserInterfaceState state)
@@ -23,6 +22,9 @@ public sealed class PowerMonitoringConsoleBoundUserInterface : BoundUserInterfac
var castState = (PowerMonitoringConsoleBoundInterfaceState) state; var castState = (PowerMonitoringConsoleBoundInterfaceState) state;
if (castState == null)
return;
EntMan.TryGetComponent<TransformComponent>(Owner, out var xform); EntMan.TryGetComponent<TransformComponent>(Owner, out var xform);
_menu?.ShowEntites _menu?.ShowEntites
(castState.TotalSources, (castState.TotalSources,
@@ -38,4 +40,13 @@ public sealed class PowerMonitoringConsoleBoundUserInterface : BoundUserInterfac
{ {
SendMessage(new PowerMonitoringConsoleMessage(netEntity, group)); SendMessage(new PowerMonitoringConsoleMessage(netEntity, group));
} }
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Dispose();
}
} }

View File

@@ -134,7 +134,7 @@ public sealed partial class PowerMonitoringWindow
subEntry.Button.OnButtonUp += args => { ButtonAction(subEntry, masterContainer); }; subEntry.Button.OnButtonUp += args => { ButtonAction(subEntry, masterContainer); };
} }
if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(Entity, out var console)) if (!_entManager.TryGetComponent<PowerMonitoringConsoleComponent>(_owner, out var console))
return; return;
// Update all children // Update all children

Some files were not shown because too many files have changed in this diff Show More