Skip to content

Commit

Permalink
fix close bug bgm modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Deinonychus71 committed Mar 19, 2021
1 parent c7fa567 commit f688691
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class BgmPropertiesModalWindowViewModel : ModalBaseViewModel<BgmEntryView
public ReactiveCommand<Window, Unit> ActionNewGame { get; }
public ReactiveCommand<BgmPropertyEntryViewModel, Unit> ActionChangeFile { get; }
public ReactiveCommand<BgmPropertyEntryViewModel, Unit> ActionCalculateLoopCues { get; }
public ReactiveCommand<Window, Unit> ActionClosing { get; }

public BgmPropertiesModalWindowViewModel(IOptions<ApplicationSettings> config, ILogger<BgmPropertiesModalWindowViewModel> logger, IFileDialog fileDialog,
IMapper mapper, IGUIStateManager guiStateManager, IObservable<IChangeSet<SeriesEntryViewModel, string>> observableSeries,
Expand Down Expand Up @@ -164,6 +165,7 @@ public BgmPropertiesModalWindowViewModel(IOptions<ApplicationSettings> config, I
ActionNewGame = ReactiveCommand.Create<Window>(AddNewGame);
ActionChangeFile = ReactiveCommand.CreateFromTask<BgmPropertyEntryViewModel>(ChangeFile);
ActionCalculateLoopCues = ReactiveCommand.CreateFromTask<BgmPropertyEntryViewModel>(CalculateAudioCues);
ActionClosing = ReactiveCommand.Create<Window>(ClosingWindow);
}

private bool ValidateStreamPropertyTime(string value)
Expand Down Expand Up @@ -261,10 +263,9 @@ private void SetGameTitleId(GameTitleEntryViewModel gameTitle)
}
}

protected override Task CancelChanges()
private void ClosingWindow(Window w)
{
BgmPropertyViewModel?.MusicPlayer?.ChangeFilename(_originalFilename);
return base.CancelChanges();
}

protected override Task<bool> SaveChanges()
Expand All @@ -275,6 +276,8 @@ protected override Task<bool> SaveChanges()
if (BgmPropertyViewModel.AudioVolume > Constants.MaximumGameVolume)
BgmPropertyViewModel.AudioVolume = Constants.MaximumGameVolume;

_originalFilename = BgmPropertyViewModel.Filename;

DbRootViewModel.TestDispOrder = (short)(IsInSoundTest ? DbRootViewModel.TestDispOrder > -1 ? DbRootViewModel.TestDispOrder : short.MaxValue : -1);
if (SelectedRecordType != null)
DbRootViewModel.RecordType = SelectedRecordType.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public IncidencePickerModalWindowViewModel()

private void CancelChanges(Window w)
{
Incidence = ushort.MaxValue;
w.Close();
}

Expand Down
6 changes: 2 additions & 4 deletions Sma5hMusic.GUI/ViewModels/Modals/ModalBaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public T SelectedItem
public ModalBaseViewModel()
{
var canExecute = GetValidationRule();
ActionCancel = ReactiveCommand.CreateFromTask<Window>(CancelChanges);
ActionCancel = ReactiveCommand.Create<Window>(CancelChanges);
ActionOK = ReactiveCommand.CreateFromTask<Window>(SaveChanges, canExecute);
}

Expand All @@ -37,11 +37,9 @@ protected virtual IObservable<bool> GetValidationRule()

protected virtual void LoadItem(T item) { }
protected virtual Task<bool> SaveChanges() { return Task.FromResult(true); }
protected virtual Task CancelChanges() { return Task.CompletedTask; }

private async Task CancelChanges(Window w)
private void CancelChanges(Window w)
{
await CancelChanges();
w.Close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void LoadToneId(string toneId)

private void Cancel(Window w)
{
_logger.LogDebug("Clicked Cancel");
w.Close();
}

Expand Down
2 changes: 1 addition & 1 deletion Sma5hMusic.GUI/ViewModels/Views/MusicPlayerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public MusicPlayerViewModel(IVGMMusicPlayer musicPlayer, string filename, bool i

public async Task ChangeFilename(string filename)
{
if (_isPlaying)
if (_isPlaying && Filename != filename)
await StopSong();
Filename = filename;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
x:Class="Sma5hMusic.GUI.Views.BgmAdvancedPropertiesModalWindow"
WindowStartupLocation="CenterScreen" ShowInTaskbar="False"
xmlns:fields="clr-namespace:Sma5hMusic.GUI.Views.Fields"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:ia="clr-namespace:Avalonia.Xaml.Interactions.Core;assembly=Avalonia.Xaml.Interactions"
Title="BGM Properties">
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="Closing">
<ia:InvokeCommandAction Command="{Binding ActionClosing}" CommandParameter="{Binding $self}"/>
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<Window.Styles>
<Style Selector=".content Button:pointerover">
<Setter Property="Background" Value="Gray"/>
Expand Down
7 changes: 7 additions & 0 deletions Sma5hMusic.GUI/Views/Modals/BgmPropertiesModalWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
x:Class="Sma5hMusic.GUI.Views.BgmPropertiesModalWindow"
xmlns:fields="clr-namespace:Sma5hMusic.GUI.Views.Fields"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:ia="clr-namespace:Avalonia.Xaml.Interactions.Core;assembly=Avalonia.Xaml.Interactions"
Title="BGM Properties">
<i:Interaction.Behaviors>
<ia:EventTriggerBehavior EventName="Closing">
<ia:InvokeCommandAction Command="{Binding ActionClosing}" CommandParameter="{Binding $self}"/>
</ia:EventTriggerBehavior>
</i:Interaction.Behaviors>
<Window.Styles>
<Style Selector=".content Button:pointerover">
<Setter Property="Background" Value="Gray"/>
Expand Down

0 comments on commit f688691

Please sign in to comment.