Skip to content

Commit

Permalink
Mod install and more
Browse files Browse the repository at this point in the history
  • Loading branch information
thesupersonic16 committed Nov 26, 2024
1 parent b3b7787 commit 7de7cba
Show file tree
Hide file tree
Showing 14 changed files with 478 additions and 33 deletions.
26 changes: 20 additions & 6 deletions Source/HedgeModManager.UI/CLI/Commands/CliCommandGameBanana.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using HedgeModManager.UI.Controls.Modals;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using HedgeModManager.UI.Controls.Modals;
using HedgeModManager.UI.ViewModels;
using System;
using System.Collections.Generic;
Expand All @@ -18,20 +21,20 @@ public bool Execute(List<CommandLine.Command> commands, CommandLine.Command comm
{
string uri = (string)command.Inputs[0];

string[] sections = uri.Split(':');
if (sections.Length < 2)
int schemaIndex = uri.IndexOf(":");
if (schemaIndex == -1)
{
Console.WriteLine("Invalid URI format (sections < 2)");
Console.WriteLine("Invalid URI format (schemaIndex == -1)");
return true;
}
string[] parts = uri.Split(',');
string[] parts = uri[(schemaIndex + 1)..].Split(',');
if (parts.Length != 3)
{
Console.WriteLine("Invalid URI format (parts != 3)");
return true;
}

SchemaName = sections[0];
SchemaName = uri[0..schemaIndex];
DownloadURL = parts[0];
ItemType = parts[1];
ItemID = parts[2];
Expand All @@ -51,6 +54,17 @@ public Task ExecuteUI(MainWindowViewModel mainWindowViewModel)
return await GameBanana.GetDownloadInfo(SchemaName, DownloadURL, ItemType, ItemID);
}).Open(mainWindowViewModel);

// Put window on top
if (Application.Current?.ApplicationLifetime
is IClassicDesktopStyleApplicationLifetime desktop &&
desktop.MainWindow is Window mainWindow)
{
mainWindow.Topmost = true;
mainWindow.Topmost = false;
if (mainWindow.WindowState == WindowState.Minimized)
mainWindow.WindowState = WindowState.Normal;
}

return Task.CompletedTask;
}
}
33 changes: 15 additions & 18 deletions Source/HedgeModManager.UI/Controls/MainWindow/Mods.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,31 @@
using Avalonia.Controls;
using Avalonia.Data;
using Avalonia.Interactivity;
using HedgeModManager.Foundation;
using HedgeModManager.UI.Controls.Mods;
using HedgeModManager.UI.Models;
using HedgeModManager.UI.ViewModels;
using HedgeModManager.UI.ViewModels.Mods;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;

namespace HedgeModManager.UI.Controls.MainWindow;

public partial class Mods : UserControl
{
public static readonly StyledProperty<UIGame> GameProperty =
AvaloniaProperty.Register<Mods, UIGame>(nameof(Game));

public static readonly StyledProperty<string?> SearchProperty =
AvaloniaProperty.Register<Mods, string?>(nameof(Search),
defaultValue: string.Empty,
defaultBindingMode: BindingMode.TwoWay);

public UIGame Game
{
get => GetValue(GameProperty);
set => SetValue(GameProperty, value);
}

public string? Search
{
get => GetValue(SearchProperty);
set => SetValue(SearchProperty, value);
}

public ModsViewModel ModsViewModel { get; set; } = new();
public ObservableCollection<IMod>? ModList { get; set; }

public Mods()
{
Expand All @@ -42,7 +35,7 @@ public Mods()

public void UpdateModList()
{
if (Game == null)
if (ModList == null)
{
ModsViewModel.ModsList.Clear();
ModsViewModel.Authors.Clear();
Expand All @@ -51,14 +44,14 @@ public void UpdateModList()
}

ModsViewModel.ModsList.Clear();
Game.Game.ModDatabase.Mods
ModList
.Select(x => new ModEntryViewModel(x, DataContext as MainWindowViewModel, ModsViewModel))
.ToList()
.ForEach(ModsViewModel.ModsList.Add);

ModsViewModel.Authors.Clear();
ModsViewModel.Authors.Add("Show All");
Game.Game.ModDatabase.Mods
ModList
.SelectMany(x => x.Authors)
.Select(x => x.Name)
.Distinct()
Expand All @@ -76,10 +69,17 @@ private void OnFilterClick(object? sender, RoutedEventArgs e)

private void OnLoaded(object? sender, RoutedEventArgs e)
{
var viewModel = DataContext as MainWindowViewModel;
if (viewModel == null)
if (DataContext is not MainWindowViewModel viewModel)
return;

// Subscribe to changes
if (ModList == null)
{
ModList = viewModel.Mods;
ModList.CollectionChanged += (s, e) => UpdateModList();
UpdateModList();
}

AuthorComboBox.SelectedIndex = 0;

// Add buttons
Expand Down Expand Up @@ -126,9 +126,6 @@ private void OnAuthorSelectionChanged(object? sender, SelectionChangedEventArgs

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
if (change.Property == GameProperty)
UpdateModList();

if (change.Property == SearchProperty)
{
if (string.IsNullOrEmpty(Search))
Expand Down
32 changes: 31 additions & 1 deletion Source/HedgeModManager.UI/Controls/MainWindow/Test.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
mc:Ignorable="d" d:DesignWidth="920" d:DesignHeight="390"
x:Class="HedgeModManager.UI.Controls.MainWindow.Test"
x:DataType="vm:MainWindowViewModel"
Loaded="OnLoaded">
Loaded="OnLoaded"
Background="{DynamicResource BackgroundL0Brush}">
<Grid>
<StackPanel Margin="16,16,0,0" HorizontalAlignment="Left">
<TextBlock Text="Config" Margin="0,8,0,0" />
Expand All @@ -26,12 +27,41 @@
<Button Click="RunGame_Click">Run</Button>
<Button Click="ChangeGame_Click">Change</Button>
<Button Click="ClearGame_Click">Clear</Button>
<Button Click="OpenGame_Click">Open</Button>
</StackPanel>

<TextBlock Text="Functions" Margin="0,8,0,0" />
<StackPanel Spacing="4" Orientation="Horizontal">
<Button Click="CreateDownload_Click">Create Download</Button>
</StackPanel>

<TextBlock Text="Downloads" Margin="0,8,0,0" />
<ItemsControl ItemsSource="{Binding Downloads}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal"
Margin="0,4,0,4" Spacing="4">
<TextBlock Text="{Binding Name}"
VerticalAlignment="Center" />
<ProgressBar Height="24"
Value="{Binding Progress}"
ShowProgressText="True"
Minimum="0"
Maximum="{Binding ProgressMax}"
Foreground="Green" />
<Button Content="{DynamicResource Common.Button.Cancel}"
Click="DownloadCancel_Click" />
<Button Content="{DynamicResource Common.Button.Delete}"
Click="DownloadDelete_Click" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
<Grid Margin="0,16,0,0"
RowDefinitions="Auto,*"
Expand Down
60 changes: 59 additions & 1 deletion Source/HedgeModManager.UI/Controls/MainWindow/Test.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
using Avalonia.Layout;
using Avalonia.Styling;
using HedgeModManager.UI.Controls.Modals;
using HedgeModManager.UI.Models;
using HedgeModManager.UI.ViewModels;
using System.Diagnostics;
using System.Threading.Tasks;

namespace HedgeModManager.UI.Controls.MainWindow;

Expand All @@ -30,7 +33,7 @@ private void OnLoaded(object? sender, RoutedEventArgs e)
{
await viewModel.SaveAndRun();
}));
viewModel.CurrentTabInfo.Buttons.Add(new("Change Theme", Buttons.Y, async (s, e) =>
viewModel.CurrentTabInfo.Buttons.Add(new("Change Theme", Buttons.Y, (s, e) =>
{
if (Application.Current != null)
{
Expand Down Expand Up @@ -166,6 +169,18 @@ private void ClearGame_Click(object? sender, RoutedEventArgs e)
viewModel.SelectedGame = null;
}

private void OpenGame_Click(object? sender, RoutedEventArgs e)
{
if (DataContext is not MainWindowViewModel viewModel ||
viewModel.SelectedGame is not UIGame game)
return;
Process.Start(new ProcessStartInfo
{
FileName = game.Game.Root,
UseShellExecute = true
});
}

private void ClearLog_Click(object? sender, RoutedEventArgs e)
{
UILogger.Clear();
Expand All @@ -176,4 +191,47 @@ private async void ExportLog_Click(object? sender, RoutedEventArgs e)
if (DataContext is MainWindowViewModel viewModel)
await viewModel.ExportLog(this);
}

private void CreateDownload_Click(object? sender, RoutedEventArgs e)
{
if (DataContext is MainWindowViewModel viewModel)
{
var download = new Download("Test Download", 1000);

download.OnRun(async (d, c) =>
{
for (int i = 0; i <= 1000; i++)
{
if (c.IsCancellationRequested)
break;
d.Progress = i;
await Task.Delay(10, c);
}
}).OnComplete((d) =>
{
Logger.Debug("Download complete");
return Task.CompletedTask;
}).OnError((d, e) =>
{
Logger.Debug("Download failed");
return Task.CompletedTask;
}).OnCancel((d) =>
{
Logger.Debug("Download cancelled");
return Task.CompletedTask;
}).Run(viewModel.Downloads);
}
}

private void DownloadCancel_Click(object? sender, RoutedEventArgs e)
{
if (sender is Control control && control.DataContext is Download download)
download.Cancel();
}

private void DownloadDelete_Click(object? sender, RoutedEventArgs e)
{
if (sender is Control control && control.DataContext is Download download)
download.Destroy();
}
}
Loading

0 comments on commit 7de7cba

Please sign in to comment.