Browse Source

added some festivity to model browser

pull/324/head
JT 11 months ago
parent
commit
7f6d369332
  1. BIN
      StabilityMatrix.Avalonia/Assets/santahat.png
  2. 1
      StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj
  3. 38
      StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CheckpointBrowserCardViewModel.cs
  4. 3
      StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CivitAiBrowserViewModel.cs
  5. 5
      StabilityMatrix.Avalonia/ViewModels/Settings/MainSettingsViewModel.cs
  6. 14
      StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml
  7. 16
      StabilityMatrix.Avalonia/Views/Settings/MainSettingsPage.axaml

BIN
StabilityMatrix.Avalonia/Assets/santahat.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

1
StabilityMatrix.Avalonia/StabilityMatrix.Avalonia.csproj

@ -82,6 +82,7 @@
<AvaloniaResource Include="Assets\Icon.ico" /> <AvaloniaResource Include="Assets\Icon.ico" />
<AvaloniaResource Include="Assets\Icon.png" /> <AvaloniaResource Include="Assets\Icon.png" />
<AvaloniaResource Include="Assets\hf-packages.json" /> <AvaloniaResource Include="Assets\hf-packages.json" />
<AvaloniaResource Include="Assets\santahat.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

38
StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CheckpointBrowserCardViewModel.cs

@ -71,6 +71,9 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
[ObservableProperty] [ObservableProperty]
private bool isFavorite; private bool isFavorite;
[ObservableProperty]
private bool showSantaHats = true;
public CheckpointBrowserCardViewModel( public CheckpointBrowserCardViewModel(
IDownloadService downloadService, IDownloadService downloadService,
ITrackedDownloadService trackedDownloadService, ITrackedDownloadService trackedDownloadService,
@ -90,6 +93,8 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
s => s.ModelBrowserNsfwEnabled, s => s.ModelBrowserNsfwEnabled,
_ => Dispatcher.UIThread.Post(UpdateImage) _ => Dispatcher.UIThread.Post(UpdateImage)
); );
ShowSantaHats = settingsManager.Settings.EnableHolidayMode;
} }
private void CheckIfInstalled() private void CheckIfInstalled()
@ -115,7 +120,9 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
var latestVersionInstalled = var latestVersionInstalled =
latestVersion.Files != null latestVersion.Files != null
&& latestVersion.Files.Any( && latestVersion
.Files
.Any(
file => file =>
file is { Type: CivitFileType.Model, Hashes.BLAKE3: not null } file is { Type: CivitFileType.Model, Hashes.BLAKE3: not null }
&& installedModels.Contains(file.Hashes.BLAKE3) && installedModels.Contains(file.Hashes.BLAKE3)
@ -124,10 +131,14 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
// check if any of the ModelVersion.Files.Hashes.BLAKE3 hashes are in the installedModels list // check if any of the ModelVersion.Files.Hashes.BLAKE3 hashes are in the installedModels list
var anyVersionInstalled = var anyVersionInstalled =
latestVersionInstalled latestVersionInstalled
|| CivitModel.ModelVersions.Any( || CivitModel
.ModelVersions
.Any(
version => version =>
version.Files != null version.Files != null
&& version.Files.Any( && version
.Files
.Any(
file => file =>
file is { Type: CivitFileType.Model, Hashes.BLAKE3: not null } file is { Type: CivitFileType.Model, Hashes.BLAKE3: not null }
&& installedModels.Contains(file.Hashes.BLAKE3) && installedModels.Contains(file.Hashes.BLAKE3)
@ -258,7 +269,8 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
private static string PruneDescription(CivitModel model) private static string PruneDescription(CivitModel model)
{ {
var prunedDescription = var prunedDescription =
model.Description model
.Description
?.Replace("<br/>", $"{Environment.NewLine}{Environment.NewLine}") ?.Replace("<br/>", $"{Environment.NewLine}{Environment.NewLine}")
.Replace("<br />", $"{Environment.NewLine}{Environment.NewLine}") .Replace("<br />", $"{Environment.NewLine}{Environment.NewLine}")
.Replace("</p>", $"{Environment.NewLine}{Environment.NewLine}") .Replace("</p>", $"{Environment.NewLine}{Environment.NewLine}")
@ -294,10 +306,7 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
/// <param name="modelVersion"></param> /// <param name="modelVersion"></param>
/// <param name="modelFilePath"></param> /// <param name="modelFilePath"></param>
/// <returns>The file path of the saved preview image</returns> /// <returns>The file path of the saved preview image</returns>
private async Task<FilePath?> SavePreviewImage( private async Task<FilePath?> SavePreviewImage(CivitModelVersion modelVersion, FilePath modelFilePath)
CivitModelVersion modelVersion,
FilePath modelFilePath
)
{ {
// Skip if model has no images // Skip if model has no images
if (modelVersion.Images == null || modelVersion.Images.Count == 0) if (modelVersion.Images == null || modelVersion.Images.Count == 0)
@ -309,9 +318,9 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
var imageExtension = Path.GetExtension(image.Url).TrimStart('.'); var imageExtension = Path.GetExtension(image.Url).TrimStart('.');
if (imageExtension is "jpg" or "jpeg" or "png") if (imageExtension is "jpg" or "jpeg" or "png")
{ {
var imageDownloadPath = modelFilePath.Directory!.JoinFile( var imageDownloadPath = modelFilePath
$"{modelFilePath.NameWithoutExtension}.preview.{imageExtension}" .Directory!
); .JoinFile($"{modelFilePath.NameWithoutExtension}.preview.{imageExtension}");
var imageTask = downloadService.DownloadToFileAsync(image.Url, imageDownloadPath); var imageTask = downloadService.DownloadToFileAsync(image.Url, imageDownloadPath);
await notificationService.TryAsync(imageTask, "Could not download preview image"); await notificationService.TryAsync(imageTask, "Could not download preview image");
@ -349,8 +358,7 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
} }
// Get latest version file // Get latest version file
var modelFile = var modelFile = selectedFile ?? modelVersion.Files?.FirstOrDefault(x => x.Type == CivitFileType.Model);
selectedFile ?? modelVersion.Files?.FirstOrDefault(x => x.Type == CivitFileType.Model);
if (modelFile is null) if (modelFile is null)
{ {
notificationService.Show( notificationService.Show(
@ -366,9 +374,7 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel
var rootModelsDirectory = new DirectoryPath(settingsManager.ModelsDirectory); var rootModelsDirectory = new DirectoryPath(settingsManager.ModelsDirectory);
var downloadDirectory = rootModelsDirectory.JoinDir( var downloadDirectory = rootModelsDirectory.JoinDir(model.Type.ConvertTo<SharedFolderType>().GetStringValue());
model.Type.ConvertTo<SharedFolderType>().GetStringValue()
);
// Folders might be missing if user didn't install any packages yet // Folders might be missing if user didn't install any packages yet
downloadDirectory.Create(); downloadDirectory.Create();

3
StabilityMatrix.Avalonia/ViewModels/CheckpointBrowser/CivitAiBrowserViewModel.cs

@ -113,6 +113,9 @@ public partial class CivitAiBrowserViewModel : TabViewModelBase
[ObservableProperty] [ObservableProperty]
private string selectedBaseModelType = "All"; private string selectedBaseModelType = "All";
[ObservableProperty]
private bool showSantaHats = true;
private List<CheckpointBrowserCardViewModel> allModelCards = new(); private List<CheckpointBrowserCardViewModel> allModelCards = new();
public IEnumerable<CivitPeriod> AllCivitPeriods => Enum.GetValues(typeof(CivitPeriod)).Cast<CivitPeriod>(); public IEnumerable<CivitPeriod> AllCivitPeriods => Enum.GetValues(typeof(CivitPeriod)).Cast<CivitPeriod>();

5
StabilityMatrix.Avalonia/ViewModels/Settings/MainSettingsViewModel.cs

@ -116,6 +116,9 @@ public partial class MainSettingsViewModel : PageViewModelBase
[ObservableProperty] [ObservableProperty]
private string? debugGpuInfo; private string? debugGpuInfo;
[ObservableProperty]
private bool enableHolidayMode;
#region System Info #region System Info
private static Lazy<IReadOnlyList<GpuInfo>> GpuInfosLazy { get; } = private static Lazy<IReadOnlyList<GpuInfo>> GpuInfosLazy { get; } =
@ -181,6 +184,7 @@ public partial class MainSettingsViewModel : PageViewModelBase
SelectedLanguage = Cultures.GetSupportedCultureOrDefault(settingsManager.Settings.Language); SelectedLanguage = Cultures.GetSupportedCultureOrDefault(settingsManager.Settings.Language);
RemoveSymlinksOnShutdown = settingsManager.Settings.RemoveFolderLinksOnShutdown; RemoveSymlinksOnShutdown = settingsManager.Settings.RemoveFolderLinksOnShutdown;
SelectedAnimationScale = settingsManager.Settings.AnimationScale; SelectedAnimationScale = settingsManager.Settings.AnimationScale;
EnableHolidayMode = settingsManager.Settings.EnableHolidayMode;
settingsManager.RelayPropertyFor(this, vm => vm.SelectedTheme, settings => settings.Theme); settingsManager.RelayPropertyFor(this, vm => vm.SelectedTheme, settings => settings.Theme);
@ -192,6 +196,7 @@ public partial class MainSettingsViewModel : PageViewModelBase
); );
settingsManager.RelayPropertyFor(this, vm => vm.SelectedAnimationScale, settings => settings.AnimationScale); settingsManager.RelayPropertyFor(this, vm => vm.SelectedAnimationScale, settings => settings.AnimationScale);
settingsManager.RelayPropertyFor(this, vm => vm.EnableHolidayMode, settings => settings.EnableHolidayMode);
DebugThrowAsyncExceptionCommand.WithNotificationErrorHandler(notificationService, LogLevel.Warn); DebugThrowAsyncExceptionCommand.WithNotificationErrorHandler(notificationService, LogLevel.Warn);

14
StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml

@ -100,7 +100,21 @@
CommandParameter="{Binding CivitModel}" CommandParameter="{Binding CivitModel}"
IsEnabled="{Binding !IsImporting}"> IsEnabled="{Binding !IsImporting}">
<Grid RowDefinitions="*, Auto"> <Grid RowDefinitions="*, Auto">
<controls:BetterAdvancedImage Grid.Row="0"
CornerRadius="8"
VerticalAlignment="Top"
HorizontalAlignment="Left"
Height="50"
ZIndex="10"
IsVisible="{Binding ShowSantaHats}"
Margin="0,36,0,0"
Source="avares://StabilityMatrix.Avalonia/Assets/santahat.png">
<controls:BetterAdvancedImage.RenderTransform>
<RotateTransform Angle="315"></RotateTransform>
</controls:BetterAdvancedImage.RenderTransform>
</controls:BetterAdvancedImage>
<controls:BetterAdvancedImage <controls:BetterAdvancedImage
Grid.Row="0"
Grid.RowSpan="2" Grid.RowSpan="2"
CornerRadius="8" CornerRadius="8"
Width="330" Width="330"

16
StabilityMatrix.Avalonia/Views/Settings/MainSettingsPage.axaml

@ -99,7 +99,7 @@
Header="{x:Static lang:Resources.Label_RemoveSymlinksOnShutdown}" Header="{x:Static lang:Resources.Label_RemoveSymlinksOnShutdown}"
IconSource="Folder"> IconSource="Folder">
<ui:SettingsExpander.Footer> <ui:SettingsExpander.Footer>
<CheckBox Margin="8" IsChecked="{Binding RemoveSymlinksOnShutdown}" /> <CheckBox IsChecked="{Binding RemoveSymlinksOnShutdown}" />
</ui:SettingsExpander.Footer> </ui:SettingsExpander.Footer>
</ui:SettingsExpander> </ui:SettingsExpander>
<ui:SettingsExpander <ui:SettingsExpander
@ -115,7 +115,7 @@
</Grid> </Grid>
<!-- General --> <!-- General -->
<sg:SpacedGrid RowDefinitions="Auto,*" RowSpacing="4"> <sg:SpacedGrid RowDefinitions="Auto,*,*" RowSpacing="4">
<TextBlock <TextBlock
Margin="0,0,0,4" Margin="0,0,0,4"
FontWeight="Medium" FontWeight="Medium"
@ -136,6 +136,18 @@
Symbol="AppGeneric" /> Symbol="AppGeneric" />
</ui:SettingsExpander.IconSource> </ui:SettingsExpander.IconSource>
</ui:SettingsExpander> </ui:SettingsExpander>
<ui:SettingsExpander Grid.Row="2"
Header="Enable Holiday Mode">
<ui:SettingsExpander.IconSource>
<fluentIcons:SymbolIconSource
FontSize="10"
IsFilled="True"
Symbol="WeatherSnowflake" />
</ui:SettingsExpander.IconSource>
<ui:SettingsExpander.Footer>
<CheckBox IsChecked="{Binding EnableHolidayMode}" />
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
</sg:SpacedGrid> </sg:SpacedGrid>
<!-- Environment Options --> <!-- Environment Options -->

Loading…
Cancel
Save