Improve plugin manager UI

This commit is contained in:
Stone_Red
2023-12-21 12:06:13 +01:00
parent 5bd2a630e0
commit 1adcce95de
9 changed files with 95 additions and 29 deletions
@@ -1,9 +1,10 @@
using Modio.NET.Models; using Modio.NET.Models;
using System; using System;
using System.Windows.Input;
namespace DesktopMagic.DataContexts; namespace DesktopMagic.DataContexts;
internal class ModEntryDataContext(Mod mod) internal class ModEntryDataContext(Mod mod, ICommand installCommand)
{ {
public string Name => mod.Name!; public string Name => mod.Name!;
@@ -13,4 +14,6 @@ internal class ModEntryDataContext(Mod mod)
public DateTime FormattedDateAdded => DateTimeOffset.FromUnixTimeSeconds(mod.DateAdded).LocalDateTime; public DateTime FormattedDateAdded => DateTimeOffset.FromUnixTimeSeconds(mod.DateAdded).LocalDateTime;
public DateTime FormattedDateUpdated => DateTimeOffset.FromUnixTimeSeconds(mod.DateUpdated).LocalDateTime; public DateTime FormattedDateUpdated => DateTimeOffset.FromUnixTimeSeconds(mod.DateUpdated).LocalDateTime;
public ICommand InstallCommand => installCommand;
} }
@@ -0,0 +1,26 @@
using System;
using System.Windows.Input;
namespace DesktopMagic.Helpers;
public class CommandHandler(Action action, Func<bool>? canExecute = null) : ICommand
{
private readonly Action action = action;
private readonly Func<bool> canExecute = canExecute ?? new Func<bool>(() => true);
public event EventHandler? CanExecuteChanged
{
add => CommandManager.RequerySuggested += value;
remove => CommandManager.RequerySuggested -= value;
}
public bool CanExecute(object? parameter)
{
return canExecute.Invoke();
}
public void Execute(object? parameter)
{
action();
}
}
+2 -2
View File
@@ -136,11 +136,11 @@
<Button x:Name="removeLayoutButton" Content="{DynamicResource deleteLayout}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="170" Click="RemoveLayoutButton_Click" FontWeight="Regular" /> <Button x:Name="removeLayoutButton" Content="{DynamicResource deleteLayout}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="170" Click="RemoveLayoutButton_Click" FontWeight="Regular" />
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Bottom"> <StackPanel Grid.Column="1" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Bottom">
<Button x:Name="downloadPluginsButton" Content="{DynamicResource downloadPlugins}" Margin="0,0,0,5" HorizontalAlignment="Center" Width="170" Click="DownloadPluginsButton_Click" FontWeight="Regular" Cursor="Hand" /> <Button x:Name="updatePluginsButton" Content="{DynamicResource updatePlugins}" Margin="0,0,0,5" HorizontalAlignment="Center" Width="170" Click="UpdatePluginsButton_Click" FontWeight="Regular" />
<Button x:Name="githubButton" Content="GitHub" HorizontalAlignment="Center" Width="170" Click="GithubButton_Click" FontWeight="Regular" Cursor="Hand" /> <Button x:Name="githubButton" Content="GitHub" HorizontalAlignment="Center" Width="170" Click="GithubButton_Click" FontWeight="Regular" Cursor="Hand" />
</StackPanel> </StackPanel>
<StackPanel Grid.Column="2" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Bottom"> <StackPanel Grid.Column="2" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Bottom">
<Button x:Name="updatePluginsButton" Content="{DynamicResource updatePlugins}" Margin="0,0,0,5" HorizontalAlignment="Right" Width="170" Click="UpdatePluginsButton_Click" FontWeight="Regular" /> <Button x:Name="downloadPluginsButton" Content="{DynamicResource pluginManager}" Margin="0,0,0,5" HorizontalAlignment="Right" Width="170" Click="PluginManagerButton_Click" FontWeight="Regular" Cursor="Hand" />
<Button x:Name="openPluginsFolderButton" Content="{DynamicResource openPluginsFolder}" HorizontalAlignment="Right" Width="170" Click="OpenPluginsFolderButton_Click" FontWeight="Regular" /> <Button x:Name="openPluginsFolderButton" Content="{DynamicResource openPluginsFolder}" HorizontalAlignment="Right" Width="170" Click="OpenPluginsFolderButton_Click" FontWeight="Regular" />
</StackPanel> </StackPanel>
</Grid> </Grid>
+3 -11
View File
@@ -131,7 +131,7 @@ namespace DesktopMagic
foreach (string directory in Directory.GetDirectories(pluginsPath)) foreach (string directory in Directory.GetDirectories(pluginsPath))
{ {
foreach (string fileName in Directory.GetFiles(directory).Where(s => s.EndsWith(".dll", StringComparison.InvariantCulture) || s.EndsWith(".cs", StringComparison.InvariantCulture))) foreach (string fileName in Directory.GetFiles(directory).Where(s => s.EndsWith(".dll", StringComparison.InvariantCulture)))
{ {
string badChars = ",#-<>?!=()*,. "; string badChars = ",#-<>?!=()*,. ";
string pluginName = fileName[(fileName.LastIndexOf('\\') + 1)..].Replace(fileName[fileName.LastIndexOf('.')..], ""); string pluginName = fileName[(fileName.LastIndexOf('\\') + 1)..].Replace(fileName[fileName.LastIndexOf('.')..], "");
@@ -641,19 +641,11 @@ namespace DesktopMagic
_ = Process.Start(psi); _ = Process.Start(psi);
} }
private void DownloadPluginsButton_Click(object sender, RoutedEventArgs e) private void PluginManagerButton_Click(object sender, RoutedEventArgs e)
{ {
PluginManager pluginManager = new PluginManager(); PluginManager pluginManager = new PluginManager();
pluginManager.ShowDialog(); pluginManager.ShowDialog();
LoadPlugins();
return;
string uri = "https://github.com/Stone-Red-Code/DesktopMagic-Plugins";
ProcessStartInfo psi = new ProcessStartInfo
{
UseShellExecute = true,
FileName = uri
};
_ = Process.Start(psi);
} }
private void SetLanguageDictionary() private void SetLanguageDictionary()
+11 -8
View File
@@ -3,11 +3,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:DesktopMagic.Plugins" xmlns:local="clr-namespace:DesktopMagic.Plugins"
xmlns:dataContext="clr-namespace:DesktopMagic.DataContexts" xmlns:dataContext="clr-namespace:DesktopMagic.DataContexts"
d:DataContext="{d:DesignInstance Type=dataContext:ModEntryDataContext}" d:DataContext="{d:DesignInstance Type=dataContext:ModEntryDataContext}"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}">
<Grid Background="White" Margin="10"> <Grid Background="White" Margin="10">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition/> <RowDefinition/>
@@ -15,22 +18,22 @@
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition/> <ColumnDefinition Width="auto"/>
<ColumnDefinition/> <ColumnDefinition/>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border HorizontalAlignment="Left" Width="100" Height="100" BorderThickness="1" BorderBrush="Black"> <Border HorizontalAlignment="Left" Width="100" Height="100" BorderThickness="1" BorderBrush="LightGray">
<Image Source="{Binding Logo}" Width="100" Height="100"/> <Image Source="{Binding Logo}" Width="100" Height="100"/>
</Border> </Border>
<StackPanel Grid.Column="1" HorizontalAlignment="Right"> <StackPanel Grid.Column="1" HorizontalAlignment="Stretch">
<Label Content="{Binding FormattedDateAdded}" ContentStringFormat="Added: {0}"/> <Label Content="{Binding FormattedDateAdded}" HorizontalAlignment="Center" ContentStringFormat="Added: {0}"/>
<Label Content="{Binding FormattedDateUpdated}" ContentStringFormat="Updated: {0}"/> <Label Content="{Binding FormattedDateUpdated}" HorizontalAlignment="Center" ContentStringFormat="Updated: {0}"/>
<Button Margin="10" Content="Download"/> <Button Command="{Binding InstallCommand}" HorizontalAlignment="Stretch" Margin="10" Content="Install"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1"> <StackPanel Grid.Row="1" Grid.ColumnSpan="2">
<Label Content="{Binding Name}" FontSize="20"/> <Label Content="{Binding Name}" FontSize="20"/>
<Label Content="{Binding Description}"/> <Label Content="{Binding Description}"/>
</StackPanel> </StackPanel>
+38 -3
View File
@@ -3,13 +3,48 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="clr-namespace:DesktopMagic.Plugins" xmlns:local="clr-namespace:DesktopMagic.Plugins"
xmlns:dataContexts="clr-namespace:DesktopMagic.DataContexts" xmlns:dataContexts="clr-namespace:DesktopMagic.DataContexts"
mc:Ignorable="d" mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=dataContexts:PluginManagerDataContext}" d:DataContext="{d:DesignInstance Type=dataContexts:PluginManagerDataContext}"
Title="PluginManager" Height="450" Width="800"> Title="PluginManager"
<Grid> Height="450"
<ItemsControl ItemsSource="{Binding Mods}"> Width="800"
MinHeight="520"
MinWidth="700"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}">
<Grid Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Label Content="All plugins" FontSize="20"/>
<TextBox Grid.Row="1" materialDesign:HintAssist.Hint="Search..." materialDesign:TextFieldAssist.HasLeadingIcon="True" materialDesign:TextFieldAssist.LeadingIcon="Search"/>
<ItemsControl Grid.Row="2" ItemsSource="{Binding Mods}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderBrush="LightGray" BorderThickness="1">
<local:ModEntry/>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Label Grid.Column="1" Content="Installed plugins" FontSize="20"/>
<TextBox Grid.Row="1" Grid.Column="1" materialDesign:HintAssist.Hint="Search..." materialDesign:TextFieldAssist.HasLeadingIcon="True" materialDesign:TextFieldAssist.LeadingIcon="Search"/>
<ItemsControl Grid.Row="2" Grid.Column="1" ItemsSource="{Binding Mods}">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border BorderBrush="LightGray" BorderThickness="1"> <Border BorderBrush="LightGray" BorderThickness="1">
@@ -1,10 +1,13 @@
using DesktopMagic.DataContexts; using DesktopMagic.DataContexts;
using DesktopMagic.Helpers;
using Modio.NET; using Modio.NET;
using Modio.NET.Models; using Modio.NET.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows; using System.Windows;
namespace DesktopMagic.Plugins; namespace DesktopMagic.Plugins;
@@ -16,6 +19,7 @@ public partial class PluginManager : Window
private readonly Client client = new Client(new Credentials("88e6ea774c3a502b06114e7fee0829ac")); private readonly Client client = new Client(new Credentials("88e6ea774c3a502b06114e7fee0829ac"));
private readonly PluginManagerDataContext pluginManagerDataContext = new(); private readonly PluginManagerDataContext pluginManagerDataContext = new();
private readonly string pluginsPath = Path.Combine(App.ApplicationDataPath, "Plugins");
public PluginManager() public PluginManager()
{ {
@@ -31,9 +35,12 @@ public partial class PluginManager : Window
IReadOnlyList<Mod> mods = await client.Games[5665].Mods.Search().ToListAsync(); IReadOnlyList<Mod> mods = await client.Games[5665].Mods.Search().ToListAsync();
foreach (Mod mod in mods) foreach (Mod mod in mods)
{ {
pluginManagerDataContext.Mods.Add(new ModEntryDataContext(mod)); pluginManagerDataContext.Mods.Add(new ModEntryDataContext(mod, new CommandHandler(() => Install(mod))));
} }
}
pluginManagerDataContext.Mods.Add(new ModEntryDataContext(new Mod() { Name = "yes", DescriptionPlaintext = "treoith34895z93" })); private void Install(Mod mod)
{
Debug.WriteLine(mod.Modfile?.Download?.BinaryUrl + " | " + pluginsPath);
} }
} }
@@ -7,7 +7,7 @@
<system:String x:Key="mirrorMode">Spiegeln</system:String> <system:String x:Key="mirrorMode">Spiegeln</system:String>
<system:String x:Key="updatePlugins">Plugins Neu Laden</system:String> <system:String x:Key="updatePlugins">Plugins Neu Laden</system:String>
<system:String x:Key="openPluginsFolder">Plugins Ordner Öffnen</system:String> <system:String x:Key="openPluginsFolder">Plugins Ordner Öffnen</system:String>
<system:String x:Key="downloadPlugins">Plugins Herunterladen</system:String> <system:String x:Key="pluginManager">Plugin Manager</system:String>
<system:String x:Key="color">Farbe:</system:String> <system:String x:Key="color">Farbe:</system:String>
<system:String x:Key="default">Standard</system:String> <system:String x:Key="default">Standard</system:String>
<system:String x:Key="wantToCloseProgram">Wollen sie das Programm wirklich schließen?</system:String> <system:String x:Key="wantToCloseProgram">Wollen sie das Programm wirklich schließen?</system:String>
@@ -7,7 +7,7 @@
<system:String x:Key="mirrorMode">Mirror</system:String> <system:String x:Key="mirrorMode">Mirror</system:String>
<system:String x:Key="updatePlugins">Reload Plugins</system:String> <system:String x:Key="updatePlugins">Reload Plugins</system:String>
<system:String x:Key="openPluginsFolder">Open Plugins Folder</system:String> <system:String x:Key="openPluginsFolder">Open Plugins Folder</system:String>
<system:String x:Key="downloadPlugins">Download Plugins</system:String> <system:String x:Key="pluginManager">Plugin Manager</system:String>
<system:String x:Key="color">Color:</system:String> <system:String x:Key="color">Color:</system:String>
<system:String x:Key="default">Default</system:String> <system:String x:Key="default">Default</system:String>
<system:String x:Key="wantToCloseProgram">Do you really want to close the program?</system:String> <system:String x:Key="wantToCloseProgram">Do you really want to close the program?</system:String>