Add playback slider to instruments. (#3071)
This commit is contained in:
committed by
GitHub
parent
b2c1ab2795
commit
655316a67c
@@ -1,18 +1,23 @@
|
||||
<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:MarginContainer Name="Margin" SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="Fill">
|
||||
<uic:VBoxContainer SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="FillExpand" SeparationOverride="5">
|
||||
<uic:HBoxContainer SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="FillExpand">
|
||||
<uic:Button Name="InputButton" ToggleMode="True" 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:HBoxContainer SizeFlagsVertical="FillExpand" SizeFlagsHorizontal="Fill">
|
||||
<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:HBoxContainer SizeFlagsVertical="ShrinkEnd" SizeFlagsHorizontal="FillExpand">
|
||||
<ui:Control SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="0.125"/>
|
||||
<uic:Slider Name="PlaybackSlider" SizeFlagsHorizontal="FillExpand" />
|
||||
<ui:Control SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="0.125"/>
|
||||
</uic:HBoxContainer>
|
||||
</uic:VBoxContainer>
|
||||
</uic:MarginContainer>
|
||||
</cc:SS14Window>
|
||||
|
||||
@@ -14,11 +14,14 @@ using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timers;
|
||||
using Robust.Shared.Timing;
|
||||
using Range = Robust.Client.UserInterface.Controls.Range;
|
||||
|
||||
namespace Content.Client.Instruments
|
||||
{
|
||||
@@ -46,6 +49,7 @@ namespace Content.Client.Instruments
|
||||
LoopButton.Disabled = !_owner.Instrument.IsMidiOpen;
|
||||
LoopButton.Pressed = _owner.Instrument.LoopMidi;
|
||||
StopButton.Disabled = !_owner.Instrument.IsMidiOpen;
|
||||
PlaybackSlider.MouseFilter = _owner.Instrument.IsMidiOpen ? MouseFilterMode.Pass : MouseFilterMode.Ignore;
|
||||
|
||||
if (!_midiManager.IsAvailable)
|
||||
{
|
||||
@@ -74,6 +78,8 @@ namespace Content.Client.Instruments
|
||||
FileButton.OnPressed += MidiFileButtonOnOnPressed;
|
||||
LoopButton.OnToggled += MidiLoopButtonOnOnToggled;
|
||||
StopButton.OnPressed += MidiStopButtonOnPressed;
|
||||
PlaybackSlider.OnValueChanged += PlaybackSliderSeek;
|
||||
PlaybackSlider.OnKeyBindUp += PlaybackSliderKeyUp;
|
||||
}
|
||||
|
||||
private void InstrumentOnMidiPlaybackEnded()
|
||||
@@ -85,12 +91,15 @@ namespace Content.Client.Instruments
|
||||
{
|
||||
LoopButton.Disabled = disabled;
|
||||
StopButton.Disabled = disabled;
|
||||
|
||||
// Whether to allow the slider to receive events..
|
||||
PlaybackSlider.MouseFilter = !disabled ? MouseFilterMode.Pass : MouseFilterMode.Ignore;
|
||||
}
|
||||
|
||||
private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
|
||||
var file = await _fileDialogManager.OpenFile(filters);
|
||||
await using var file = await _fileDialogManager.OpenFile(filters);
|
||||
|
||||
// The following checks are only in place to prevent players from playing MIDI songs locally.
|
||||
// There are equivalents for these checks on the server.
|
||||
@@ -107,7 +116,7 @@ namespace Content.Client.Instruments
|
||||
return;
|
||||
|
||||
MidiStopButtonOnPressed(null);
|
||||
var memStream = new MemoryStream((int) file.Length);
|
||||
await using var memStream = new MemoryStream((int) file.Length);
|
||||
// 100ms delay is due to a race condition or something idk.
|
||||
// While we're waiting, load it into memory.
|
||||
await Task.WhenAll(Timer.Delay(100), file.CopyToAsync(memStream));
|
||||
@@ -165,5 +174,36 @@ namespace Content.Client.Instruments
|
||||
{
|
||||
_owner.Instrument.LoopMidi = obj.Pressed;
|
||||
}
|
||||
|
||||
private void PlaybackSliderSeek(Range _)
|
||||
{
|
||||
// Do not seek while still grabbing.
|
||||
if (PlaybackSlider.Grabbed) return;
|
||||
|
||||
_owner.Instrument.PlayerTick = (int)Math.Ceiling(PlaybackSlider.Value);
|
||||
}
|
||||
|
||||
private void PlaybackSliderKeyUp(GUIBoundKeyEventArgs args)
|
||||
{
|
||||
if (args.Function != EngineKeyFunctions.UIClick) return;
|
||||
_owner.Instrument.PlayerTick = (int)Math.Ceiling(PlaybackSlider.Value);
|
||||
}
|
||||
|
||||
protected override void Update(FrameEventArgs args)
|
||||
{
|
||||
base.Update(args);
|
||||
|
||||
if (!_owner.Instrument.IsMidiOpen)
|
||||
{
|
||||
PlaybackSlider.MaxValue = 1;
|
||||
PlaybackSlider.SetValueWithoutEvent(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (PlaybackSlider.Grabbed) return;
|
||||
|
||||
PlaybackSlider.MaxValue = _owner.Instrument.PlayerTotalTick;
|
||||
PlaybackSlider.SetValueWithoutEvent(_owner.Instrument.PlayerTick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user