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.png" />
<AvaloniaResource Include="Assets\hf-packages.json" />
<AvaloniaResource Include="Assets\santahat.png" />
</ItemGroup>
<ItemGroup>

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

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

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

@ -113,6 +113,9 @@ public partial class CivitAiBrowserViewModel : TabViewModelBase
[ObservableProperty]
private string selectedBaseModelType = "All";
[ObservableProperty]
private bool showSantaHats = true;
private List<CheckpointBrowserCardViewModel> allModelCards = new();
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]
private string? debugGpuInfo;
[ObservableProperty]
private bool enableHolidayMode;
#region System Info
private static Lazy<IReadOnlyList<GpuInfo>> GpuInfosLazy { get; } =
@ -181,6 +184,7 @@ public partial class MainSettingsViewModel : PageViewModelBase
SelectedLanguage = Cultures.GetSupportedCultureOrDefault(settingsManager.Settings.Language);
RemoveSymlinksOnShutdown = settingsManager.Settings.RemoveFolderLinksOnShutdown;
SelectedAnimationScale = settingsManager.Settings.AnimationScale;
EnableHolidayMode = settingsManager.Settings.EnableHolidayMode;
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.EnableHolidayMode, settings => settings.EnableHolidayMode);
DebugThrowAsyncExceptionCommand.WithNotificationErrorHandler(notificationService, LogLevel.Warn);

14
StabilityMatrix.Avalonia/Views/CivitAiBrowserPage.axaml

@ -100,7 +100,21 @@
CommandParameter="{Binding CivitModel}"
IsEnabled="{Binding !IsImporting}">
<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
Grid.Row="0"
Grid.RowSpan="2"
CornerRadius="8"
Width="330"

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

@ -99,7 +99,7 @@
Header="{x:Static lang:Resources.Label_RemoveSymlinksOnShutdown}"
IconSource="Folder">
<ui:SettingsExpander.Footer>
<CheckBox Margin="8" IsChecked="{Binding RemoveSymlinksOnShutdown}" />
<CheckBox IsChecked="{Binding RemoveSymlinksOnShutdown}" />
</ui:SettingsExpander.Footer>
</ui:SettingsExpander>
<ui:SettingsExpander
@ -115,7 +115,7 @@
</Grid>
<!-- General -->
<sg:SpacedGrid RowDefinitions="Auto,*" RowSpacing="4">
<sg:SpacedGrid RowDefinitions="Auto,*,*" RowSpacing="4">
<TextBlock
Margin="0,0,0,4"
FontWeight="Medium"
@ -136,6 +136,18 @@
Symbol="AppGeneric" />
</ui:SettingsExpander.IconSource>
</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>
<!-- Environment Options -->

Loading…
Cancel
Save