mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Added UI for dependencies
This commit is contained in:
@@ -7,16 +7,18 @@ namespace ZuneModCore
|
||||
{
|
||||
public class ModDependency
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public ReleaseVersion Version { get; set; }
|
||||
|
||||
public ModDependency(string id, ReleaseVersion? version = null)
|
||||
{
|
||||
Id = id;
|
||||
Version = version ?? ModManager.CurrentVersion;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
|
||||
public ReleaseVersion Version { get; set; }
|
||||
|
||||
public bool Status => CheckStatus();
|
||||
|
||||
/// <summary>
|
||||
/// DO NOT USE DIRECTLY. This constructor is only for
|
||||
/// JSON de/serialization.
|
||||
@@ -24,7 +26,9 @@ namespace ZuneModCore
|
||||
[Obsolete]
|
||||
internal ModDependency() { }
|
||||
|
||||
public Task<bool> CheckStatus() => ModManager.CheckStatus(Id);
|
||||
public Task<bool> CheckStatusAsync() => ModManager.CheckStatus(Id);
|
||||
|
||||
private bool CheckStatus() => CheckStatusAsync().Result;
|
||||
|
||||
public override string ToString() => $"{Id} / {Version}";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace ZuneModdingHelper.Converters
|
||||
{
|
||||
internal class BoolToSymbolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is not bool val)
|
||||
return null;
|
||||
|
||||
var resultsStr = parameter.ToString().Split(',');
|
||||
object trueReturnVal = null;
|
||||
object falseReturnVal = null;
|
||||
|
||||
if (targetType == typeof(string))
|
||||
{
|
||||
trueReturnVal = resultsStr[0];
|
||||
falseReturnVal = resultsStr[1];
|
||||
}
|
||||
else if (targetType == typeof(Brush))
|
||||
{
|
||||
var brushConverter = new BrushConverter();
|
||||
trueReturnVal = brushConverter.ConvertFrom(resultsStr[0]);
|
||||
falseReturnVal = brushConverter.ConvertFrom(resultsStr[1]);
|
||||
}
|
||||
|
||||
return val ? trueReturnVal : falseReturnVal;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var results = parameter.ToString().Split(',');
|
||||
return value.ToString() == results[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace ZuneModdingHelper.Converters
|
||||
{
|
||||
internal class NullToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value != null ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:ZuneModdingHelper"
|
||||
xmlns:convert="clr-namespace:ZuneModdingHelper.Converters"
|
||||
xmlns:mod="clr-namespace:ZuneModCore;assembly=ZuneModCore"
|
||||
xmlns:absui="clr-namespace:OwlCore.Wpf.AbstractUI.Controls;assembly=OwlCore.Wpf"
|
||||
xmlns:mah="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
|
||||
mc:Ignorable="d"
|
||||
@@ -14,6 +16,9 @@
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/OwlCore.Wpf;component/AbstractUI/Themes/AbstractUIGroupPresenterStyle.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<convert:BoolToSymbolConverter x:Key="BoolToSymbolConverter"/>
|
||||
<convert:NullToVisibilityConverter x:Key="NullToVisibilityConverter"/>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
@@ -25,11 +30,27 @@
|
||||
|
||||
<ScrollViewer>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<StackPanel Margin="10,10,10,0" Visibility="{Binding CurrentMod.DependentMods, Converter={StaticResource NullToVisibilityConverter}}">
|
||||
<TextBlock Text="Dependencies" FontSize="26"/>
|
||||
<ItemsControl x:Name="DependenciesPresenter" ItemsSource="{Binding CurrentMod.DependentMods}">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type mod:ModDependency}">
|
||||
<TextBlock Margin="4" FontSize="14">
|
||||
<Run Text="{Binding Status, ConverterParameter=',', Mode=OneWay, Converter={StaticResource BoolToSymbolConverter}}"
|
||||
Foreground="{Binding Status, ConverterParameter='#16c60c,#f03a17', Mode=OneWay, Converter={StaticResource BoolToSymbolConverter}}"
|
||||
FontFamily="Segoe MDL2 Assets" BaselineAlignment="Center"/>
|
||||
<Run Text="{Binding Id}" BaselineAlignment="Center"/>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
<Rectangle Fill="{StaticResource MahApps.Brushes.Control.Border}"
|
||||
Height="2" Margin="0,10,0,-7"/>
|
||||
</StackPanel>
|
||||
|
||||
<absui:AbstractUIGroupPresenter x:Name="OptionsUIPresenter" ViewModel="{Binding OptionsViewModel}"
|
||||
TemplateSelector="{StaticResource GroupTemplateSelector}"/>
|
||||
|
||||
<HeaderedItemsControl x:Name="DependenciesPresenter" Header="Dependencies"
|
||||
ItemsSource="{Binding CurrentMod.DependentMods}"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user