|
|
|
@ -6,8 +6,12 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Threading.Tasks; |
|
|
|
using System.Windows.Input; |
|
|
|
using System.Windows.Input; |
|
|
|
|
|
|
|
using Avalonia.Controls; |
|
|
|
|
|
|
|
using Lib.Audio.Factories; |
|
|
|
using Lib.Audio.Interfaces; |
|
|
|
using Lib.Audio.Interfaces; |
|
|
|
|
|
|
|
using Lib.Logging; |
|
|
|
using Lib.Tools; |
|
|
|
using Lib.Tools; |
|
|
|
using Mystify.Views; |
|
|
|
using Mystify.Views; |
|
|
|
using ReactiveUI; |
|
|
|
using ReactiveUI; |
|
|
|
@ -16,8 +20,11 @@ namespace Mystify.ViewModels |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class ControllableSelectionViewModel : ViewModelBase |
|
|
|
public class ControllableSelectionViewModel : ViewModelBase |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
private readonly IControllableFactory? _controllableFactory; |
|
|
|
private readonly ControllableSelectionWindow? _window; |
|
|
|
private readonly ControllableSelectionWindow? _window; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string _customControllableExecutablePath = ""; |
|
|
|
|
|
|
|
|
|
|
|
public ControllableSelectionViewModel() |
|
|
|
public ControllableSelectionViewModel() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!IsInDesignMode) |
|
|
|
if (!IsInDesignMode) |
|
|
|
@ -26,9 +33,10 @@ namespace Mystify.ViewModels |
|
|
|
Controllables = new ObservableCollection<ControllableViewModel>(); |
|
|
|
Controllables = new ObservableCollection<ControllableViewModel>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ControllableSelectionViewModel(List<IControllable>? controllables, ControllableSelectionWindow window) |
|
|
|
public ControllableSelectionViewModel(List<IControllable>? controllables, ControllableSelectionWindow window, IControllableFactory controllableFactory) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_window = window; |
|
|
|
_window = window; |
|
|
|
|
|
|
|
_controllableFactory = controllableFactory; |
|
|
|
|
|
|
|
|
|
|
|
Controllables = controllables == null ? new ObservableCollection<ControllableViewModel>() : |
|
|
|
Controllables = controllables == null ? new ObservableCollection<ControllableViewModel>() : |
|
|
|
controllables.Select(c => new ControllableViewModel(c)).ToObservableCollection(); |
|
|
|
controllables.Select(c => new ControllableViewModel(c)).ToObservableCollection(); |
|
|
|
@ -40,9 +48,44 @@ namespace Mystify.ViewModels |
|
|
|
public ObservableCollection<ControllableViewModel> Controllables { get; } |
|
|
|
public ObservableCollection<ControllableViewModel> Controllables { get; } |
|
|
|
private ControllableViewModel? SelectedControllable { get; set; } |
|
|
|
private ControllableViewModel? SelectedControllable { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string CustomControllableExecutablePath |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
get => _customControllableExecutablePath; |
|
|
|
|
|
|
|
set |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
_customControllableExecutablePath = value; |
|
|
|
|
|
|
|
RaisePropertyChanged(() => CustomControllableExecutablePath); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ICommand CloseCommand => ReactiveCommand.Create(CloseWindow); |
|
|
|
public ICommand CloseCommand => ReactiveCommand.Create(CloseWindow); |
|
|
|
|
|
|
|
public ICommand SelectCustomControllableCommand => ReactiveCommand.CreateFromTask(SelectCustomControllable); |
|
|
|
|
|
|
|
|
|
|
|
private void CloseWindow() => _window?.Close(SelectedControllable); |
|
|
|
private void CloseWindow() => _window?.Close(SelectedControllable); |
|
|
|
|
|
|
|
private async Task SelectCustomControllable() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (_controllableFactory == null) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OpenFileDialog openFileDialog = new() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Filters = new List<FileDialogFilter> {new() {Extensions = new List<string> {"exe"}, Name = "Executable"}} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string[] selectedPaths = await openFileDialog.ShowAsync(_window); |
|
|
|
|
|
|
|
if (selectedPaths.Length == 0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
await Log.Write<MainWindowViewModel>("No Executable selected."); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CustomControllableExecutablePath = selectedPaths[0]; |
|
|
|
|
|
|
|
IControllable controllable = _controllableFactory.Create(CustomControllableExecutablePath); |
|
|
|
|
|
|
|
SelectedControllable = new ControllableViewModel(controllable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CloseWindow(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void OnControllableSelected(object? sender, bool isSelected) |
|
|
|
private void OnControllableSelected(object? sender, bool isSelected) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!isSelected) |
|
|
|
if (!isSelected) |
|
|
|
|