diff --git a/Knossos.NET/ViewModels/Templates/NebulaLoginViewModel.cs b/Knossos.NET/ViewModels/Templates/NebulaLoginViewModel.cs index 42da868f..52ebc85b 100644 --- a/Knossos.NET/ViewModels/Templates/NebulaLoginViewModel.cs +++ b/Knossos.NET/ViewModels/Templates/NebulaLoginViewModel.cs @@ -1,7 +1,10 @@ -using Avalonia.Threading; +using Avalonia.Controls; +using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; using Knossos.NET.Models; using Knossos.NET.Views; +using System.Collections.ObjectModel; +using System.Linq; namespace Knossos.NET.ViewModels { @@ -26,10 +29,10 @@ public partial class NebulaLoginViewModel : ViewModelBase internal string userEmail = string.Empty; [ObservableProperty] - internal string editableIDs = string.Empty; + internal ObservableCollection editableIDs = new ObservableCollection(); [ObservableProperty] - internal string privateMods = string.Empty; + internal ObservableCollection privateMods = new ObservableCollection(); public async void UpdateUI() { @@ -37,16 +40,20 @@ public async void UpdateUI() RegisterNewUser = false; UserName = Nebula.userName; UserPass = Nebula.userPass; - PrivateMods = string.Empty; + EditableIDs.Clear(); + PrivateMods.Clear(); if(UserLoggedIn) { var ids = await Nebula.GetEditableModIDs().ConfigureAwait(false); if (ids != null) { - Dispatcher.UIThread.Invoke(() => + foreach (var id in ids) { - EditableIDs = string.Join(", ", ids); - }); + Dispatcher.UIThread.Invoke(() => + { + EditableIDs.Add(id); + }); + } } var privMods = await Nebula.GetPrivateMods(true).ConfigureAwait(false); if (privMods != null) @@ -55,13 +62,39 @@ public async void UpdateUI() { Dispatcher.UIThread.Invoke(() => { - PrivateMods += mod + ", "; + var item = new ListBoxItem(); + item.Tag = mod; + item.Content = mod.ToString(); + PrivateMods.Add(item); }); } } } } + internal async void Install() + { + var selected = PrivateMods.FirstOrDefault(x => x.IsSelected); + if (selected != null) + { + if (selected.Tag is Mod mod) + { + if (CustomLauncher.IsCustomMode && CustomLauncher.ModID != mod.id) + { + await MessageBox.Show(MainWindow.instance, "You cannot install a different mod ID than the defined Total Conversion ID while in Custom Launcher mode.", "Different mod or Total Conversion", MessageBox.MessageBoxButtons.OK); + return; + } + var dialog = new ModInstallView(); + dialog.DataContext = new ModInstallViewModel(mod, dialog, mod.version); + await dialog.ShowDialog(MainWindow.instance!); + } + } + else + { + await MessageBox.Show(MainWindow.instance, "Select a private mod from the list first.", "No selected mod", MessageBox.MessageBoxButtons.OK); + } + } + internal async void LogIn() { if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(UserPass) || string.IsNullOrWhiteSpace(UserName) || string.IsNullOrWhiteSpace(UserPass)) diff --git a/Knossos.NET/Views/Templates/NebulaLoginView.axaml b/Knossos.NET/Views/Templates/NebulaLoginView.axaml index d816e53a..16083494 100644 --- a/Knossos.NET/Views/Templates/NebulaLoginView.axaml +++ b/Knossos.NET/Views/Templates/NebulaLoginView.axaml @@ -12,7 +12,7 @@ - +