-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
48 changed files
with
1,379 additions
and
216 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
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
58 changes: 58 additions & 0 deletions
58
src/Snap.Hutao/Snap.Hutao/Control/Behavior/AutoWidthBehavior.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,58 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using CommunityToolkit.WinUI.UI.Behaviors; | ||
using Microsoft.UI.Xaml; | ||
using Snap.Hutao.Core; | ||
|
||
namespace Snap.Hutao.Control.Behavior; | ||
|
||
/// <summary> | ||
/// 按给定比例自动调整高度的行为 | ||
/// </summary> | ||
internal class AutoWidthBehavior : BehaviorBase<FrameworkElement> | ||
{ | ||
private static readonly DependencyProperty TargetWidthProperty = Property<AutoWidthBehavior>.Depend(nameof(TargetWidth), 320D); | ||
private static readonly DependencyProperty TargetHeightProperty = Property<AutoWidthBehavior>.Depend(nameof(TargetHeight), 1024D); | ||
|
||
/// <summary> | ||
/// 目标宽度 | ||
/// </summary> | ||
public double TargetWidth | ||
{ | ||
get => (double)GetValue(TargetWidthProperty); | ||
set => SetValue(TargetWidthProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// 目标高度 | ||
/// </summary> | ||
public double TargetHeight | ||
{ | ||
get => (double)GetValue(TargetHeightProperty); | ||
set => SetValue(TargetHeightProperty, value); | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void OnAssociatedObjectLoaded() | ||
{ | ||
UpdateElementWidth(); | ||
AssociatedObject.SizeChanged += OnSizeChanged; | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void OnDetaching() | ||
{ | ||
AssociatedObject.SizeChanged -= OnSizeChanged; | ||
} | ||
|
||
private void OnSizeChanged(object sender, SizeChangedEventArgs e) | ||
{ | ||
UpdateElementWidth(); | ||
} | ||
|
||
private void UpdateElementWidth() | ||
{ | ||
AssociatedObject.Width = (double)AssociatedObject.Height * (TargetWidth / TargetHeight); | ||
} | ||
} |
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,63 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System.Text; | ||
|
||
namespace Snap.Hutao.Core; | ||
|
||
/// <summary> | ||
/// 命令行建造器 | ||
/// </summary> | ||
public class CommandLineBuilder | ||
{ | ||
private const char WhiteSpace = ' '; | ||
private readonly Dictionary<string, string?> options = new(); | ||
|
||
/// <summary> | ||
/// 当符合条件时添加参数 | ||
/// </summary> | ||
/// <param name="name">参数名称</param> | ||
/// <param name="condition">条件</param> | ||
/// <param name="value">值</param> | ||
/// <returns>命令行建造器</returns> | ||
public CommandLineBuilder AppendIf(string name, bool condition, object? value = null) | ||
{ | ||
return condition ? Append(name, value) : this; | ||
} | ||
|
||
/// <summary> | ||
/// 添加参数 | ||
/// </summary> | ||
/// <param name="name">参数名称</param> | ||
/// <param name="value">值</param> | ||
/// <returns>命令行建造器</returns> | ||
public CommandLineBuilder Append(string name, object? value = null) | ||
{ | ||
options.Add(name, value?.ToString()); | ||
return this; | ||
} | ||
|
||
/// <inheritdoc cref="ToString"/> | ||
public string Build() | ||
{ | ||
return ToString(); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
StringBuilder s = new(); | ||
foreach ((string key, string? value) in options) | ||
{ | ||
s.Append(WhiteSpace); | ||
s.Append(key); | ||
if (!string.IsNullOrEmpty(value)) | ||
{ | ||
s.Append(WhiteSpace); | ||
s.Append(value); | ||
} | ||
} | ||
|
||
return s.ToString(); | ||
} | ||
} |
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,35 @@ | ||
// Copyright (c) DGP Studio. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using Snap.Hutao.Core.LifeCycle; | ||
using Windows.UI.StartScreen; | ||
|
||
namespace Snap.Hutao.Core; | ||
|
||
/// <summary> | ||
/// 跳转列表帮助类 | ||
/// </summary> | ||
public static class JumpListHelper | ||
{ | ||
/// <summary> | ||
/// 异步配置跳转列表 | ||
/// </summary> | ||
/// <returns>任务</returns> | ||
public static async Task ConfigAsync() | ||
{ | ||
if (JumpList.IsSupported()) | ||
{ | ||
JumpList list = await JumpList.LoadCurrentAsync(); | ||
|
||
list.Items.Clear(); | ||
|
||
JumpListItem launchGameItem = JumpListItem.CreateWithArguments(Activation.LaunchGame, "启动游戏"); | ||
launchGameItem.GroupName = "快捷操作"; | ||
launchGameItem.Logo = new("ms-appx:///Resource/Icon/UI_GuideIcon_PlayMethod.png"); | ||
|
||
list.Items.Add(launchGameItem); | ||
|
||
await list.SaveAsync(); | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -41,4 +41,4 @@ public static class ProcessHelper | |
}; | ||
return Process.Start(processInfo); | ||
} | ||
} | ||
} |
Oops, something went wrong.