This commit is contained in:
Hakoyu 2023-12-14 23:41:15 +08:00
parent f75f2970ad
commit 1e7b3751ac
9 changed files with 50 additions and 13 deletions

View File

@ -14,4 +14,5 @@
<c:NotEqualsConverter x:Key="NotEqualsConverter" />
<c:NullToFalseConverter x:Key="NullToFalseConverter" />
<c:AllTrueToCollapsedConverter x:Key="AllTrueToCollapsedConverter" />
<c:BoolInverter x:Key="BoolInverter" />
</ResourceDictionary>

View File

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace VPet.ModMaker.Converters;
public class BoolInverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is not bool b)
throw new ArgumentException("Value type not bool", nameof(value));
return !b;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

View File

@ -34,7 +34,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
/// <summary>
/// 不显示本体宠物
/// </summary>
public ObservableValue<bool> DontShowMainPet { get; } = new(true);
public ObservableValue<bool> ShowMainPet { get; } = new(true);
#region ModInfo
/// <summary>
@ -138,7 +138,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
DescriptionId.Value = $"{n}_{nameof(DescriptionId)}";
};
Pets.CollectionChanged += Pets_CollectionChanged;
DontShowMainPet.ValueChanged += ShowMainPet_ValueChanged;
ShowMainPet.ValueChanged += ShowMainPet_ValueChanged;
}
private void ShowMainPet_ValueChanged(
@ -151,10 +151,10 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
private void Pets_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (DontShowMainPet.Value)
PetDisplayedCount.Value = Pets.Count - Pets.Count(m => m.FromMain.Value);
else
if (ShowMainPet.Value)
PetDisplayedCount.Value = Pets.Count;
else
PetDisplayedCount.Value = Pets.Count - Pets.Count(m => m.FromMain.Value);
}
public ModInfoModel(ModLoader loader)

View File

@ -100,6 +100,7 @@
</Compile>
<Compile Include="Converters\AllTrueToCollapsedConverter.cs" />
<Compile Include="Converters\AnyFalseToVisibleConverter.cs" />
<Compile Include="Converters\BoolInverter.cs" />
<Compile Include="Models\I18nModelBase.cs" />
<Compile Include="Usings.cs" />
<Compile Include="Converters\BrushToMediaColorConverter.cs" />

View File

@ -48,7 +48,10 @@
<Setter Property="Visibility">
<Setter.Value>
<MultiBinding Converter="{StaticResource AllTrueToCollapsedConverter}">
<Binding Path="DataContext.ModInfo.DontShowMainPet.Value" RelativeSource="{RelativeSource AncestorType=Page}" />
<Binding
Converter="{StaticResource BoolInverter}"
Path="DataContext.ModInfo.ShowMainPet.Value"
RelativeSource="{RelativeSource AncestorType=Page}" />
<Binding Path="FromMain.Value" />
</MultiBinding>
</Setter.Value>

View File

@ -48,7 +48,10 @@
<Setter Property="Visibility">
<Setter.Value>
<MultiBinding Converter="{StaticResource AllTrueToCollapsedConverter}">
<Binding Path="DataContext.ModInfo.DontShowMainPet.Value" RelativeSource="{RelativeSource AncestorType=Page}" />
<Binding
Converter="{StaticResource BoolInverter}"
Path="DataContext.ModInfo.ShowMainPet.Value"
RelativeSource="{RelativeSource AncestorType=Page}" />
<Binding Path="FromMain.Value" />
</MultiBinding>
</Setter.Value>

View File

@ -29,8 +29,8 @@
Text="{Binding Search.Value, UpdateSourceTrigger=PropertyChanged}" />
<pu:Switch
Grid.Column="1"
Content="{ll:Str 显示本体宠物}"
IsChecked="{Binding ModInfo.DontShowMainPet.Value}" />
Content="{ll:Str 显示本体宠物}"
IsChecked="{Binding ModInfo.ShowMainPet.Value}" />
</Grid>
<DataGrid
Grid.Row="1"
@ -53,7 +53,10 @@
<Setter Property="Visibility">
<Setter.Value>
<MultiBinding Converter="{StaticResource AllTrueToCollapsedConverter}">
<Binding Path="DataContext.ModInfo.DontShowMainPet.Value" RelativeSource="{RelativeSource AncestorType=Page}" />
<Binding
Converter="{StaticResource BoolInverter}"
Path="DataContext.ModInfo.ShowMainPet.Value"
RelativeSource="{RelativeSource AncestorType=Page}" />
<Binding Path="FromMain.Value" />
</MultiBinding>
</Setter.Value>

View File

@ -52,7 +52,10 @@
<Setter Property="Visibility">
<Setter.Value>
<MultiBinding Converter="{StaticResource AllTrueToCollapsedConverter}">
<Binding Path="DataContext.ModInfo.DontShowMainPet.Value" RelativeSource="{RelativeSource AncestorType=Page}" />
<Binding
Converter="{StaticResource BoolInverter}"
Path="DataContext.ModInfo.ShowMainPet.Value"
RelativeSource="{RelativeSource AncestorType=Page}" />
<Binding Path="FromMain.Value" />
</MultiBinding>
</Setter.Value>

View File

@ -92,8 +92,7 @@
Grid.Row="1"
VerticalAlignment="Bottom"
d:Text="{ll:Str 路径}"
Text="{Binding SourcePath}"
TextWrapping="Wrap" />
Text="{Binding SourcePath}" />
</Grid>
</Grid>
</ControlTemplate>