mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 08:56:15 +02:00
Improve plugin manager UI
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
using Modio.NET.Models;
|
||||
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace DesktopMagic.DataContexts;
|
||||
internal class ModEntryDataContext(Mod mod)
|
||||
internal class ModEntryDataContext(Mod mod, ICommand installCommand)
|
||||
{
|
||||
public string Name => mod.Name!;
|
||||
|
||||
@@ -13,4 +14,6 @@ internal class ModEntryDataContext(Mod mod)
|
||||
|
||||
public DateTime FormattedDateAdded => DateTimeOffset.FromUnixTimeSeconds(mod.DateAdded).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();
|
||||
}
|
||||
}
|
||||
@@ -136,11 +136,11 @@
|
||||
<Button x:Name="removeLayoutButton" Content="{DynamicResource deleteLayout}" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="170" Click="RemoveLayoutButton_Click" FontWeight="Regular" />
|
||||
</StackPanel>
|
||||
<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" />
|
||||
</StackPanel>
|
||||
<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" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace DesktopMagic
|
||||
|
||||
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 pluginName = fileName[(fileName.LastIndexOf('\\') + 1)..].Replace(fileName[fileName.LastIndexOf('.')..], "");
|
||||
@@ -641,19 +641,11 @@ namespace DesktopMagic
|
||||
_ = Process.Start(psi);
|
||||
}
|
||||
|
||||
private void DownloadPluginsButton_Click(object sender, RoutedEventArgs e)
|
||||
private void PluginManagerButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
PluginManager pluginManager = new PluginManager();
|
||||
pluginManager.ShowDialog();
|
||||
|
||||
return;
|
||||
string uri = "https://github.com/Stone-Red-Code/DesktopMagic-Plugins";
|
||||
ProcessStartInfo psi = new ProcessStartInfo
|
||||
{
|
||||
UseShellExecute = true,
|
||||
FileName = uri
|
||||
};
|
||||
_ = Process.Start(psi);
|
||||
LoadPlugins();
|
||||
}
|
||||
|
||||
private void SetLanguageDictionary()
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:local="clr-namespace:DesktopMagic.Plugins"
|
||||
xmlns:dataContext="clr-namespace:DesktopMagic.DataContexts"
|
||||
d:DataContext="{d:DesignInstance Type=dataContext:ModEntryDataContext}"
|
||||
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.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
@@ -15,22 +18,22 @@
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="auto"/>
|
||||
<ColumnDefinition/>
|
||||
</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"/>
|
||||
</Border>
|
||||
|
||||
|
||||
<StackPanel Grid.Column="1" HorizontalAlignment="Right">
|
||||
<Label Content="{Binding FormattedDateAdded}" ContentStringFormat="Added: {0}"/>
|
||||
<Label Content="{Binding FormattedDateUpdated}" ContentStringFormat="Updated: {0}"/>
|
||||
<Button Margin="10" Content="Download"/>
|
||||
<StackPanel Grid.Column="1" HorizontalAlignment="Stretch">
|
||||
<Label Content="{Binding FormattedDateAdded}" HorizontalAlignment="Center" ContentStringFormat="Added: {0}"/>
|
||||
<Label Content="{Binding FormattedDateUpdated}" HorizontalAlignment="Center" ContentStringFormat="Updated: {0}"/>
|
||||
<Button Command="{Binding InstallCommand}" HorizontalAlignment="Stretch" Margin="10" Content="Install"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1">
|
||||
<StackPanel Grid.Row="1" Grid.ColumnSpan="2">
|
||||
<Label Content="{Binding Name}" FontSize="20"/>
|
||||
<Label Content="{Binding Description}"/>
|
||||
</StackPanel>
|
||||
|
||||
@@ -3,13 +3,48 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:local="clr-namespace:DesktopMagic.Plugins"
|
||||
xmlns:dataContexts="clr-namespace:DesktopMagic.DataContexts"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=dataContexts:PluginManagerDataContext}"
|
||||
Title="PluginManager" Height="450" Width="800">
|
||||
<Grid>
|
||||
<ItemsControl ItemsSource="{Binding Mods}">
|
||||
Title="PluginManager"
|
||||
Height="450"
|
||||
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>
|
||||
<DataTemplate>
|
||||
<Border BorderBrush="LightGray" BorderThickness="1">
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using DesktopMagic.DataContexts;
|
||||
using DesktopMagic.Helpers;
|
||||
|
||||
using Modio.NET;
|
||||
using Modio.NET.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace DesktopMagic.Plugins;
|
||||
@@ -16,6 +19,7 @@ public partial class PluginManager : Window
|
||||
private readonly Client client = new Client(new Credentials("88e6ea774c3a502b06114e7fee0829ac"));
|
||||
|
||||
private readonly PluginManagerDataContext pluginManagerDataContext = new();
|
||||
private readonly string pluginsPath = Path.Combine(App.ApplicationDataPath, "Plugins");
|
||||
|
||||
public PluginManager()
|
||||
{
|
||||
@@ -31,9 +35,12 @@ public partial class PluginManager : Window
|
||||
IReadOnlyList<Mod> mods = await client.Games[5665].Mods.Search().ToListAsync();
|
||||
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="updatePlugins">Plugins Neu Laden</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="default">Standard</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="updatePlugins">Reload Plugins</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="default">Default</system:String>
|
||||
<system:String x:Key="wantToCloseProgram">Do you really want to close the program?</system:String>
|
||||
|
||||
Reference in New Issue
Block a user