Content changes for file dialog stuff.
This commit is contained in:
@@ -349,12 +349,11 @@ namespace Content.Client.GameObjects.Components.Instruments
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="MidiRenderer.OpenMidi(string)"/>
|
public bool OpenMidi(ReadOnlySpan<byte> data)
|
||||||
public bool OpenMidi(string filename)
|
|
||||||
{
|
{
|
||||||
SetupRenderer();
|
SetupRenderer();
|
||||||
|
|
||||||
if (_renderer == null || !_renderer.OpenMidi(filename))
|
if (_renderer == null || !_renderer.OpenMidi(data))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Content.Client.GameObjects.Components.Instruments;
|
using Content.Client.GameObjects.Components.Instruments;
|
||||||
using Content.Client.UserInterface.Stylesheets;
|
using Content.Client.UserInterface.Stylesheets;
|
||||||
using Content.Client.Utility;
|
using Content.Client.Utility;
|
||||||
@@ -174,25 +177,31 @@ namespace Content.Client.Instruments
|
|||||||
private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||||
{
|
{
|
||||||
var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
|
var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
|
||||||
var filename = await _fileDialogManager.OpenFile(filters);
|
var file = await _fileDialogManager.OpenFile(filters);
|
||||||
|
|
||||||
// The following checks are only in place to prevent players from playing MIDI songs locally.
|
// The following checks are only in place to prevent players from playing MIDI songs locally.
|
||||||
// There are equivalents for these checks on the server.
|
// There are equivalents for these checks on the server.
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(filename)) return;
|
if (file == null) return;
|
||||||
|
|
||||||
if (!_midiManager.IsMidiFile(filename))
|
/*if (!_midiManager.IsMidiFile(filename))
|
||||||
{
|
{
|
||||||
Logger.Warning($"Not a midi file! Chosen file: {filename}");
|
Logger.Warning($"Not a midi file! Chosen file: {filename}");
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if (!PlayCheck())
|
if (!PlayCheck())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MidiStopButtonOnPressed(null);
|
MidiStopButtonOnPressed(null);
|
||||||
await Timer.Delay(100);
|
var memStream = new MemoryStream((int) file.Length);
|
||||||
if (!_owner.Instrument.OpenMidi(filename)) return;
|
// 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));
|
||||||
|
|
||||||
|
if (!_owner.Instrument.OpenMidi(memStream.GetBuffer().AsSpan(0, (int) memStream.Length)))
|
||||||
|
return;
|
||||||
|
|
||||||
MidiPlaybackSetButtonsDisabled(false);
|
MidiPlaybackSetButtonsDisabled(false);
|
||||||
if (_midiInputButton.Pressed)
|
if (_midiInputButton.Pressed)
|
||||||
_midiInputButton.Pressed = false;
|
_midiInputButton.Pressed = false;
|
||||||
@@ -229,7 +238,8 @@ namespace Content.Client.Instruments
|
|||||||
|| conMan.Owner != localPlayer.ControlledEntity))) return false;
|
|| conMan.Owner != localPlayer.ControlledEntity))) 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 localPlayer.InRangeUnobstructed(instrumentEnt, predicate:(e) => e == instrumentEnt || e == localPlayer.ControlledEntity);
|
return localPlayer.InRangeUnobstructed(instrumentEnt,
|
||||||
|
predicate: (e) => e == instrumentEnt || e == localPlayer.ControlledEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MidiStopButtonOnPressed(BaseButton.ButtonEventArgs obj)
|
private void MidiStopButtonOnPressed(BaseButton.ButtonEventArgs obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user