Skip to content

Commit 03e2db4

Browse files
authored
Fix UI bugs (#54)
* stop sound from playing when object selection is changed * default background colour to SteelBlue instead of white * whitespace
1 parent 2f5fecd commit 03e2db4

File tree

3 files changed

+13
-60
lines changed

3 files changed

+13
-60
lines changed

AvaGui/ViewModels/ObjectEditorViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public DatFileInfo CurrentlySelectedUiObjectDatInfo
6262

6363
public void SelectedObjectChanged()
6464
{
65+
// this stops any currently-playing sounds
66+
if (ExtraContentViewModel is SoundViewModel svm)
67+
{
68+
svm.Dispose();
69+
}
70+
6571
if (CurrentObject?.LocoObject != null)
6672
{
6773
StringTableViewModel = new(CurrentObject.LocoObject.StringTable);

AvaGui/ViewModels/SoundViewModel.cs

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
using System.Threading;
1111
using System.Runtime.InteropServices;
1212
using AvaGui.Models;
13+
using System;
1314

1415
namespace AvaGui.ViewModels
1516
{
16-
public class SoundViewModel : ReactiveObject, IExtraContentViewModel
17+
public class SoundViewModel : ReactiveObject, IExtraContentViewModel, IDisposable
1718
{
1819
ILocoObject parent; // currently not needed
1920

@@ -107,63 +108,9 @@ public void PlaySound()
107108
[Reactive]
108109
public ICommand StopSoundCommand { get; set; }
109110

110-
//public async Task ImportSound()
111-
//{
112-
// var folders = await PlatformSpecific.OpenFolderPicker();
113-
// var dir = folders.FirstOrDefault();
114-
// if (dir == null)
115-
// {
116-
// return;
117-
// }
118-
119-
// var dirPath = dir.Path.LocalPath;
120-
// if (Directory.Exists(dirPath) && Directory.EnumerateFiles(dirPath).Any())
121-
// {
122-
// var files = Directory.GetFiles(dirPath);
123-
// var sorted = files.OrderBy(f => int.Parse(Path.GetFileNameWithoutExtension(f).Split('-')[0]));
124-
125-
// var g1Elements = new List<G1Element32>();
126-
// var i = 0;
127-
// //foreach (var file in sorted)
128-
// //{
129-
// // var img = SixLabors.ImageSharp.Image.Load<Rgb24>(file);
130-
// // var data = PaletteMap.ConvertRgb24ImageToG1Data(img);
131-
// // var hasTransparency = data.Any(b => b == 0);
132-
// // var oldImage = Parent.G1Elements[i++];
133-
// // oldImage.ImageData = PaletteMap.ConvertRgb24ImageToG1Data(img); // simply overwrite existing pixel data
134-
// //}
135-
// }
136-
137-
// //this.RaisePropertyChanged(nameof(Images));
138-
//}
139-
140-
//public async Task ExportSound()
141-
//{
142-
// var folders = await PlatformSpecific.OpenFolderPicker();
143-
// var dir = folders.FirstOrDefault();
144-
// if (dir == null)
145-
// {
146-
// return;
147-
// }
148-
149-
// var dirPath = dir.Path.LocalPath;
150-
// if (Directory.Exists(dirPath))
151-
// {
152-
// var counter = 0;
153-
// //foreach (var image in Images)
154-
// //{
155-
// // var imageName = counter++.ToString(); // todo: use GetImageName from winforms project
156-
// // var path = Path.Combine(dir.Path.LocalPath, $"{imageName}.png");
157-
// // //logger.Debug($"Saving image to {path}");
158-
// // image.Save(path);
159-
// //}
160-
// }
161-
//}
162-
163-
//[Reactive]
164-
//public ICommand ImportSoundCommand { get; set; }
165-
166-
//[Reactive]
167-
//public ICommand ExportSoundCommand { get; set; }
111+
public void Dispose()
112+
{
113+
CurrentWOEvent?.Stop();
114+
}
168115
}
169116
}

AvaGui/Views/MainWindow.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
</DockPanel>
141141
<Button.Flyout >
142142
<Flyout>
143-
<ColorView Name="ImageBackgroundColorView" IsColorModelVisible="False" IsColorSpectrumVisible="False" IsColorComponentsVisible="False" />
143+
<ColorView Name="ImageBackgroundColorView" Color="SteelBlue" IsColorModelVisible="False" IsColorSpectrumVisible="False" IsColorComponentsVisible="False" />
144144
</Flyout>
145145
</Button.Flyout>
146146
</Button>

0 commit comments

Comments
 (0)