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