Port instrument menu UI to use XAML (#3066)
This commit is contained in:
committed by
GitHub
parent
afb8e5a782
commit
044040effe
18
Content.Client/Instruments/InstrumentMenu.xaml
Normal file
18
Content.Client/Instruments/InstrumentMenu.xaml
Normal file
@@ -0,0 +1,18 @@
|
||||
<cc:SS14Window xmlns:cc="clr-namespace:Robust.Client.UserInterface.CustomControls;assembly=Robust.Client"
|
||||
xmlns:uic="clr-namespace:Robust.Client.UserInterface.Controls;assembly=Robust.Client"
|
||||
xmlns:ui="clr-namespace:Robust.Client.UserInterface;assembly=Robust.Client">
|
||||
<uic:MarginContainer Name="Margin" SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="FillExpand">
|
||||
<uic:VBoxContainer SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="FillExpand" SeparationOverride="5">
|
||||
<uic:HBoxContainer SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="FillExpand">
|
||||
<uic:Button Name="InputButton" Text="MIDI Input" TextAlign="Center" SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="1"/>
|
||||
<ui:Control SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="2" />
|
||||
<uic:Button Name="FileButton" Text="Play MIDI File" TextAlign="Center" SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="1"/>
|
||||
</uic:HBoxContainer>
|
||||
<uic:HBoxContainer SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="FillExpand">
|
||||
<uic:Button Name="LoopButton" ToggleMode="True" Text="Loop" TextAlign="Center" SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="1"/>
|
||||
<ui:Control SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="2" />
|
||||
<uic:Button Name="StopButton" Text="Stop" TextAlign="Center" SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="1"/>
|
||||
</uic:HBoxContainer>
|
||||
</uic:VBoxContainer>
|
||||
</uic:MarginContainer>
|
||||
</cc:SS14Window>
|
||||
@@ -5,12 +5,14 @@ using Content.Client.GameObjects.Components.Instruments;
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Content.Client.Utility;
|
||||
using Robust.Client.Audio.Midi;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.Interfaces.UserInterface;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -20,20 +22,19 @@ using Robust.Shared.Timers;
|
||||
|
||||
namespace Content.Client.Instruments
|
||||
{
|
||||
public class InstrumentMenu : SS14Window
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class InstrumentMenu : SS14Window
|
||||
{
|
||||
[Dependency] private readonly IMidiManager _midiManager = default!;
|
||||
[Dependency] private readonly IFileDialogManager _fileDialogManager = default!;
|
||||
|
||||
private readonly InstrumentBoundUserInterface _owner;
|
||||
private readonly Button _midiLoopButton;
|
||||
private readonly Button _midiStopButton;
|
||||
private readonly Button _midiInputButton;
|
||||
|
||||
protected override Vector2? CustomSize => (400, 150);
|
||||
|
||||
public InstrumentMenu(InstrumentBoundUserInterface owner)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_owner = owner;
|
||||
@@ -42,108 +43,13 @@ namespace Content.Client.Instruments
|
||||
|
||||
Title = _owner.Instrument.Owner.Name;
|
||||
|
||||
var margin = new MarginContainer()
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
};
|
||||
|
||||
var vBox = new VBoxContainer()
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SeparationOverride = 5,
|
||||
};
|
||||
|
||||
var hBoxTopButtons = new HBoxContainer()
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
Align = BoxContainer.AlignMode.Center
|
||||
};
|
||||
|
||||
_midiInputButton = new Button()
|
||||
{
|
||||
Text = Loc.GetString("MIDI Input"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
ToggleMode = true,
|
||||
Pressed = _owner.Instrument.IsInputOpen,
|
||||
};
|
||||
|
||||
_midiInputButton.OnToggled += MidiInputButtonOnOnToggled;
|
||||
|
||||
var topSpacer = new Control()
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 2,
|
||||
};
|
||||
|
||||
var midiFileButton = new Button()
|
||||
{
|
||||
Text = Loc.GetString("Play MIDI File"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
};
|
||||
|
||||
midiFileButton.OnPressed += MidiFileButtonOnOnPressed;
|
||||
|
||||
var hBoxBottomButtons = new HBoxContainer()
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
Align = BoxContainer.AlignMode.Center
|
||||
};
|
||||
|
||||
_midiLoopButton = new Button()
|
||||
{
|
||||
Text = Loc.GetString("Loop"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
ToggleMode = true,
|
||||
Disabled = !_owner.Instrument.IsMidiOpen,
|
||||
Pressed = _owner.Instrument.LoopMidi,
|
||||
};
|
||||
|
||||
_midiLoopButton.OnToggled += MidiLoopButtonOnOnToggled;
|
||||
|
||||
var bottomSpacer = new Control()
|
||||
{
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 2,
|
||||
};
|
||||
|
||||
_midiStopButton = new Button()
|
||||
{
|
||||
Text = Loc.GetString("Stop"),
|
||||
TextAlign = Label.AlignMode.Center,
|
||||
SizeFlagsHorizontal = SizeFlags.FillExpand,
|
||||
SizeFlagsStretchRatio = 1,
|
||||
Disabled = !_owner.Instrument.IsMidiOpen,
|
||||
};
|
||||
|
||||
_midiStopButton.OnPressed += MidiStopButtonOnPressed;
|
||||
|
||||
hBoxBottomButtons.AddChild(_midiLoopButton);
|
||||
hBoxBottomButtons.AddChild(bottomSpacer);
|
||||
hBoxBottomButtons.AddChild(_midiStopButton);
|
||||
|
||||
hBoxTopButtons.AddChild(_midiInputButton);
|
||||
hBoxTopButtons.AddChild(topSpacer);
|
||||
hBoxTopButtons.AddChild(midiFileButton);
|
||||
|
||||
vBox.AddChild(hBoxTopButtons);
|
||||
vBox.AddChild(hBoxBottomButtons);
|
||||
|
||||
margin.AddChild(vBox);
|
||||
LoopButton.Disabled = !_owner.Instrument.IsMidiOpen;
|
||||
LoopButton.Pressed = _owner.Instrument.LoopMidi;
|
||||
StopButton.Disabled = !_owner.Instrument.IsMidiOpen;
|
||||
|
||||
if (!_midiManager.IsAvailable)
|
||||
{
|
||||
margin.AddChild(new PanelContainer
|
||||
Margin.AddChild(new PanelContainer
|
||||
{
|
||||
MouseFilter = MouseFilterMode.Stop,
|
||||
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.Black.WithAlpha(0.90f)},
|
||||
@@ -159,9 +65,15 @@ namespace Content.Client.Instruments
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// We return early as to not give the buttons behavior.
|
||||
return;
|
||||
}
|
||||
|
||||
Contents.AddChild(margin);
|
||||
InputButton.OnToggled += MidiInputButtonOnOnToggled;
|
||||
FileButton.OnPressed += MidiFileButtonOnOnPressed;
|
||||
LoopButton.OnToggled += MidiLoopButtonOnOnToggled;
|
||||
StopButton.OnPressed += MidiStopButtonOnPressed;
|
||||
}
|
||||
|
||||
private void InstrumentOnMidiPlaybackEnded()
|
||||
@@ -171,8 +83,8 @@ namespace Content.Client.Instruments
|
||||
|
||||
public void MidiPlaybackSetButtonsDisabled(bool disabled)
|
||||
{
|
||||
_midiLoopButton.Disabled = disabled;
|
||||
_midiStopButton.Disabled = disabled;
|
||||
LoopButton.Disabled = disabled;
|
||||
StopButton.Disabled = disabled;
|
||||
}
|
||||
|
||||
private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
@@ -204,8 +116,8 @@ namespace Content.Client.Instruments
|
||||
return;
|
||||
|
||||
MidiPlaybackSetButtonsDisabled(false);
|
||||
if (_midiInputButton.Pressed)
|
||||
_midiInputButton.Pressed = false;
|
||||
if (InputButton.Pressed)
|
||||
InputButton.Pressed = false;
|
||||
}
|
||||
|
||||
private void MidiInputButtonOnOnToggled(BaseButton.ButtonToggledEventArgs obj)
|
||||
Reference in New Issue
Block a user