-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
152 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
namespace Snap.Hutao.Service.Game; | ||
|
||
internal sealed class AspectRatio : IEquatable<AspectRatio> | ||
{ | ||
public AspectRatio(double width, double height) | ||
{ | ||
Width = width; | ||
Height = height; | ||
} | ||
|
||
[JsonPropertyName("width")] | ||
public double Width { get; } | ||
|
||
[JsonPropertyName("height")] | ||
public double Height { get; } | ||
|
||
public override string ToString() | ||
{ | ||
return Width + ":" + Height; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return HashCode.Combine(Width, Height); | ||
} | ||
|
||
public bool Equals(AspectRatio? other) | ||
{ | ||
if (other is null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, other)) | ||
{ | ||
return true; | ||
} | ||
|
||
return Width.Equals(other.Width) && Height.Equals(other.Height); | ||
} | ||
|
||
public override bool Equals(object? obj) | ||
{ | ||
return ReferenceEquals(this, obj) || (obj is AspectRatio other && Equals(other)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Snap.Hutao/Snap.Hutao/Service/Game/LaunchOptionsExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System.Collections.Immutable; | ||
|
||
namespace Snap.Hutao.Service.Game; | ||
|
||
internal static class LaunchOptionsExtension | ||
{ | ||
public static ImmutableArray<AspectRatio> SaveAspectRatio(this LaunchOptions options, AspectRatio aspectRatio) | ||
{ | ||
if (options.AspectRatios.Contains(aspectRatio)) | ||
{ | ||
return options.AspectRatios; | ||
} | ||
|
||
options.AspectRatios = options.AspectRatios.Add(aspectRatio); | ||
return options.AspectRatios; | ||
} | ||
|
||
public static ImmutableArray<AspectRatio> RemoveAspectRatio(this LaunchOptions options, AspectRatio aspectRatio) | ||
{ | ||
options.SelectedAspectRatio = default; | ||
options.AspectRatios = options.AspectRatios.Remove(aspectRatio); | ||
return options.AspectRatios; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Snap.Hutao/Snap.Hutao/ViewModel/Game/AspectRatioComboBoxTemplateSelector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Snap.Hutao.ViewModel.Game; | ||
|
||
internal sealed partial class AspectRatioComboBoxTemplateSelector : DataTemplateSelector | ||
{ | ||
public DataTemplate ListTemplate { get; set; } = default!; | ||
|
||
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) | ||
{ | ||
if (container is ContentPresenter) | ||
{ | ||
return default!; | ||
} | ||
|
||
return ListTemplate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters