Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions Knossos.NET/ViewModels/Templates/NebulaLoginViewModel.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -26,27 +29,31 @@ public partial class NebulaLoginViewModel : ViewModelBase
internal string userEmail = string.Empty;

[ObservableProperty]
internal string editableIDs = string.Empty;
internal ObservableCollection<string> editableIDs = new ObservableCollection<string>();

[ObservableProperty]
internal string privateMods = string.Empty;
internal ObservableCollection<ListBoxItem> privateMods = new ObservableCollection<ListBoxItem>();

public async void UpdateUI()
{
UserLoggedIn = Nebula.userIsLoggedIn;
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)
Expand All @@ -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<ModInstallView?>(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))
Expand Down
15 changes: 10 additions & 5 deletions Knossos.NET/Views/Templates/NebulaLoginView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</Design.DataContext>

<ScrollViewer Background="Transparent">
<StackPanel Background="Transparent" HorizontalAlignment="Center">
<StackPanel Background="Transparent" HorizontalAlignment="Center" Name="MainPanel">
<Label Content="{Binding Title}" HorizontalContentAlignment="Center" FontWeight="Black" FontSize="24"/>
<TextBox Text="{Binding UserName}" Watermark="Username" Width="300" Margin="5"></TextBox>
<TextBox Text="{Binding UserPass}" Watermark="Password" PasswordChar="*" Width="300" Margin="5"></TextBox>
Expand All @@ -26,10 +26,15 @@
<Button IsVisible="{Binding RegisterNewUser}" Width="135" Command="{Binding SwitchToLogin}" Margin="5" Classes="Cancel">Cancel</Button>
<Button IsVisible="{Binding RegisterNewUser}" Width="135" Command="{Binding Register}" Margin="5" Classes="Accept">Register</Button>
</WrapPanel>
<Label HorizontalAlignment="Center" IsVisible="{Binding UserLoggedIn}" Margin="20" FontSize="20">Mods IDs you have write access to</Label>
<TextBox Background="Transparent" IsReadOnly="True" IsVisible="{Binding UserLoggedIn}" TextWrapping="Wrap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding EditableIDs}"></TextBox>
<Label HorizontalAlignment="Center" IsVisible="{Binding UserLoggedIn}" Margin="20" FontSize="20">Private mods you have access to</Label>
<TextBox Background="Transparent" IsReadOnly="True" IsVisible="{Binding UserLoggedIn}" TextWrapping="Wrap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Text="{Binding PrivateMods}"></TextBox>
<Grid HorizontalAlignment="Center" ColumnDefinitions="Auto, Auto" RowDefinitions="Auto,*">
<Label HorizontalAlignment="Center" Grid.Row="0" Grid.Column="0" IsVisible="{Binding UserLoggedIn}" Margin="20" FontSize="20">Mods IDs you have write access to</Label>
<ListBox MaxHeight="700" Grid.Row="1" Margin="5" Grid.Column="0" Background="Transparent" IsVisible="{Binding UserLoggedIn}" ItemsSource="{Binding EditableIDs}"></ListBox>
<Label HorizontalAlignment="Center" Grid.Row="0" Grid.Column="1" IsVisible="{Binding UserLoggedIn}" Margin="20" FontSize="20">Private mods you have access to</Label>
<StackPanel Grid.Row="1" Grid.Column="1" IsVisible="{Binding UserLoggedIn}">
<ListBox MaxHeight="700" Margin="5" Background="Transparent" ItemsSource="{Binding PrivateMods}"/>
<Button Command="{Binding Install}" HorizontalAlignment="Center" Classes="Accept" Margin="5">Install Selected</Button>
</StackPanel>
</Grid>
</StackPanel>
</ScrollViewer>
</UserControl>