初始化 monorepo: Go后端(7微服务) + Unity客户端(9模块) + 启动器 HTML5原型: Three.js 3D体素世界, Perlin噪声地形, 原版材质, 22种方块 Minecraft创造模式背包: 双栏布局, 拖拽移动物品, 方向性元件引脚 AI助搭策划文档 + 客户端/服务端骨架 + Docker Compose + CI
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
using PCL.Core.UI;
|
||||
using PCL.Core.UI.Controls.SvgIcon;
|
||||
|
||||
namespace PCL;
|
||||
|
||||
internal static class SvgIconControlHelper
|
||||
{
|
||||
internal static bool HasSvgIcon(string? icon)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(icon);
|
||||
}
|
||||
|
||||
internal static void ApplyVisibility(
|
||||
Path legacyIcon,
|
||||
SvgIcon svgIcon,
|
||||
bool useSvgIcon)
|
||||
{
|
||||
legacyIcon.Visibility = useSvgIcon ? Visibility.Collapsed : Visibility.Visible;
|
||||
svgIcon.Visibility = useSvgIcon ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
internal static void ApplyIcon(Path legacyIcon, SvgIcon svgIcon, string? svgIconName)
|
||||
{
|
||||
var useSvgIcon = HasSvgIcon(svgIconName);
|
||||
svgIcon.Icon = svgIconName ?? string.Empty;
|
||||
ApplyVisibility(legacyIcon, svgIcon, useSvgIcon);
|
||||
}
|
||||
|
||||
internal static void SetIconBrush(Path legacyIcon, SvgIcon svgIcon, bool useSvgIcon, Brush brush)
|
||||
{
|
||||
if (useSvgIcon)
|
||||
svgIcon.IconBrush = brush;
|
||||
else
|
||||
legacyIcon.Fill = brush;
|
||||
}
|
||||
|
||||
internal static void SetIconResource(Path legacyIcon, SvgIcon svgIcon, bool useSvgIcon, string resourceKey)
|
||||
{
|
||||
if (useSvgIcon)
|
||||
svgIcon.SetResourceReference(SvgIcon.IconBrushProperty, resourceKey);
|
||||
else
|
||||
legacyIcon.SetResourceReference(Shape.FillProperty, resourceKey);
|
||||
}
|
||||
|
||||
internal static void AnimateSvgIconBrushTo(
|
||||
SvgIcon svgIcon,
|
||||
string resourceKey,
|
||||
int duration,
|
||||
string? animationKey = null)
|
||||
{
|
||||
if (svgIcon.Visibility == Visibility.Visible)
|
||||
svgIcon.AnimateIconBrushTo(
|
||||
ResolveResourceColor(resourceKey),
|
||||
TimeSpan.FromMilliseconds(duration),
|
||||
animationKey: animationKey);
|
||||
}
|
||||
|
||||
internal static void AnimateSvgIconBrushTo(
|
||||
SvgIcon svgIcon,
|
||||
ModBase.MyColor color,
|
||||
int duration,
|
||||
string? animationKey = null)
|
||||
{
|
||||
if (svgIcon.Visibility == Visibility.Visible)
|
||||
svgIcon.AnimateIconBrushTo(
|
||||
new NColor((Color)color),
|
||||
TimeSpan.FromMilliseconds(duration),
|
||||
animationKey: animationKey);
|
||||
}
|
||||
|
||||
private static NColor ResolveResourceColor(string resourceKey)
|
||||
{
|
||||
if (!ThemeManager.AppResources.Contains(resourceKey))
|
||||
return new NColor(resourceKey);
|
||||
|
||||
var resource = ThemeManager.AppResources[resourceKey];
|
||||
return resource switch
|
||||
{
|
||||
SolidColorBrush brush => new NColor(brush),
|
||||
Color color => new NColor(color),
|
||||
Brush brush => new NColor(brush),
|
||||
_ => new NColor(resourceKey)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user