Skip to content

Commit

Permalink
better game selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Dec 3, 2024
1 parent 0a454ee commit dccdec3
Show file tree
Hide file tree
Showing 18 changed files with 1,156 additions and 42 deletions.
18 changes: 9 additions & 9 deletions src/Starward.Core/GameBiz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ public GameBiz(string? value)
public static ReadOnlyCollection<GameBiz> AllGameBizs { get; private set; } = new List<GameBiz>
{
bh3_cn,
//bh3_global,
bh3_os,
bh3_jp,
bh3_kr,
bh3_usa,
bh3_asia,
bh3_eur,
bh3_global,
//bh3_os,
//bh3_jp,
//bh3_kr,
//bh3_usa,
//bh3_asia,
//bh3_eur,
hk4e_cn,
hk4e_global,
hk4e_bilibili,
clgm_cn,
//clgm_cn,
//clgm_global,
hkrpg_cn,
hkrpg_global,
Expand Down Expand Up @@ -102,7 +102,7 @@ public static class GameBizExtension
{
GameBiz.bh3_cn or GameBiz.bh3_global => true,
GameBiz.hk4e_cn or GameBiz.hk4e_global or GameBiz.hk4e_bilibili => true,
GameBiz.clgm_cn or GameBiz.clgm_global => true,
//GameBiz.clgm_cn or GameBiz.clgm_global => true,
GameBiz.hkrpg_cn or GameBiz.hkrpg_global or GameBiz.hkrpg_bilibili => true,
GameBiz.nap_cn or GameBiz.nap_global or GameBiz.nap_bilibili => true,
_ => false,
Expand Down
6 changes: 6 additions & 0 deletions src/Starward.Core/HoYoPlay/GameImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ namespace Starward.Core.HoYoPlay;
public class GameImage
{

/// <summary>
/// 图片链接
/// </summary>
[JsonPropertyName("url")]
public string Url { get; set; }

[JsonPropertyName("hover_url")]
public string? HoverUrl { get; set; }

/// <summary>
/// 点击图片后打开的链接
/// </summary>
[JsonPropertyName("link")]
public string Link { get; set; }

Expand Down
95 changes: 95 additions & 0 deletions src/Starward/Features/GameSelector/GameBizIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Starward.Core;
using Starward.Core.HoYoPlay;
using System;


namespace Starward.Features.GameSelector;

public partial class GameBizIcon : ObservableObject, IEquatable<GameBizIcon>
{


public GameId GameId { get; set; }

public GameBiz GameBiz { get; set; }


public string GameIcon { get; set => SetProperty(ref field, value); }

public string GameName { get; set => SetProperty(ref field, value); }

public string ServerIcon { get; set => SetProperty(ref field, value); }

public string ServerName { get; set => SetProperty(ref field, value); }

public double MaskOpacity { get; set => SetProperty(ref field, value); } = 1.0;

public bool IsSelected
{
get;
set
{
field = value;
MaskOpacity = value ? 0 : 1;
}
}



public GameBizIcon(GameBiz gameBiz)
{
GameBiz = gameBiz;
GameId = GameId.FromGameBiz(gameBiz)!;
GameIcon = GameBizToIcon(gameBiz);
ServerIcon = GameBizToServerIcon(gameBiz);
GameName = gameBiz.ToGameName();
ServerName = gameBiz.ToGameServerName();
}



public GameBizIcon(GameInfo gameInfo)
{
// todo icon 和 name 按照 gamebiz 匹配 _cn / _global
GameId = gameInfo;
GameBiz = gameInfo.GameBiz;
GameIcon = gameInfo.Display.Icon.Url;
ServerIcon = "";
GameName = gameInfo.Display.Name;
ServerName = "";
}



private static string GameBizToIcon(GameBiz gameBiz)
{
return gameBiz.ToGame().Value switch
{
GameBiz.bh3 => "ms-appx:///Assets/Image/icon_bh3.jpg",
GameBiz.hk4e => "ms-appx:///Assets/Image/icon_ys.jpg",
GameBiz.hkrpg => "ms-appx:///Assets/Image/icon_sr.jpg",
GameBiz.nap => "ms-appx:///Assets/Image/icon_zzz.jpg",
_ => "ms-appx:///Assets/Image/Transparent.png",
};
}


private static string GameBizToServerIcon(GameBiz gameBiz)
{
return gameBiz.Value switch
{
GameBiz.hk4e_cn or GameBiz.hkrpg_cn or GameBiz.bh3_cn or GameBiz.nap_cn => "ms-appx:///Assets/Image/gameicon_hyperion.png",
GameBiz.hk4e_global or GameBiz.hkrpg_global or GameBiz.bh3_global or GameBiz.nap_global => "ms-appx:///Assets/Image/gameicon_hoyolab.png",
GameBiz.hk4e_bilibili or GameBiz.hkrpg_bilibili or GameBiz.nap_bilibili => "ms-appx:///Assets/Image/gameicon_bilibili.png",
_ => "ms-appx:///Assets/Image/Transparent.png",
};
}


public bool Equals(GameBizIcon? other)
{
return ReferenceEquals(this, other) || GameBiz == other?.GameBiz;
}

}
223 changes: 223 additions & 0 deletions src/Starward/Features/GameSelector/GameSelector.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl x:Class="Starward.Features.GameSelector.GameSelector"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="using:Starward.Language"
xmlns:local="using:Starward.Features.GameSelector"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sh="using:Starward.Helpers"
xmlns:sm="using:Starward.Models"
x:DefaultBindMode="OneWay"
mc:Ignorable="d">

<UserControl.Resources>
<BitmapImage x:Key="hyperion"
DecodePixelHeight="20"
DecodePixelType="Logical"
DecodePixelWidth="20"
UriSource="ms-appx:///Assets/Image/gameicon_hyperion.png" />
<BitmapImage x:Key="hoyolab"
DecodePixelHeight="20"
DecodePixelType="Logical"
DecodePixelWidth="20"
UriSource="ms-appx:///Assets/Image/gameicon_hoyolab.png" />
<BitmapImage x:Key="cloud"
DecodePixelHeight="20"
DecodePixelType="Logical"
DecodePixelWidth="20"
UriSource="ms-appx:///Assets/Image/gameicon_cloud.png" />
<BitmapImage x:Key="bilibili"
DecodePixelHeight="20"
DecodePixelType="Logical"
DecodePixelWidth="20"
UriSource="ms-appx:///Assets/Image/gameicon_bilibili.png" />
</UserControl.Resources>

<Grid>



<!-- 左上角当前的游戏图标 -->
<Border Name="Border_CurrentGameIcon"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="Transparent"
PointerEntered="Border_CurrentGameIcon_PointerEntered"
PointerExited="Border_CurrentGameIcon_PointerExited">
<Button Name="Button_CurrentGameIcon"
Width="40"
Height="40"
Margin="8,10,8,8"
Padding="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
sh:PointerCursor.CursorShape="Hand"
BorderThickness="0"
Command="{x:Bind ShowFullBackgroundCommand}"
CornerRadius="8"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<Grid>
<FontIcon HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
Glyph="&#xE8A9;"
IsTextScaleFactorEnabled="False" />
<!-- 游戏图标 -->
<Image Width="40"
Height="40"
Visibility="{x:Bind IsPinned, Converter={StaticResource BoolToVisibilityReversedConverter}}">
<Image.Source>
<BitmapImage DecodePixelHeight="40"
DecodePixelType="Logical"
DecodePixelWidth="40"
UriSource="{x:Bind CurrentGameBizIcon.GameIcon, FallbackValue={x:Null}}" />
</Image.Source>
</Image>
<!-- 服务器图标 -->
<Image Width="20"
Height="20"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Visibility="{x:Bind IsPinned, Converter={StaticResource BoolToVisibilityReversedConverter}}">
<Image.Source>
<BitmapImage DecodePixelHeight="20"
DecodePixelType="Logical"
DecodePixelWidth="20"
UriSource="{x:Bind CurrentGameBizIcon.ServerIcon, FallbackValue={x:Null}}" />
</Image.Source>
</Image>
</Grid>
</Button>
</Border>


<!-- 黑色半透明背景 -->
<Border x:Name="Border_FullBackground"
Background="#66000000"
IsHitTestVisible="False"
Opacity="0"
Tapped="Border_FullBackground_Tapped">
<Border.OpacityTransition>
<ScalarTransition />
</Border.OpacityTransition>
</Border>



<!-- 横排待选游戏图标 -->
<Border x:Name="Border_GameIconsArea"
Margin="56,0,0,0"
Padding="12,10,12,10"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Background="Transparent"
PointerExited="Border_GameIconsArea_PointerExited"
SizeChanged="Border_GameIconsArea_SizeChanged"
Translation="0,-100,0">
<Border.TranslationTransition>
<Vector3Transition />
</Border.TranslationTransition>
<StackPanel Orientation="Horizontal" Spacing="12">
<StackPanel.ChildrenTransitions>
<TransitionCollection>
<RepositionThemeTransition />
</TransitionCollection>
</StackPanel.ChildrenTransitions>
<!-- 游戏图标 -->
<ItemsControl ItemsSource="{x:Bind GameBizIcons}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="12">
<StackPanel.ChildrenTransitions>
<TransitionCollection>
<AddDeleteThemeTransition />
</TransitionCollection>
</StackPanel.ChildrenTransitions>
</StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="local:GameBizIcon">
<Button x:Name="Button_GameIcon"
Grid.RowSpan="2"
Width="40"
Height="40"
Padding="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
sh:PointerCursor.CursorShape="Hand"
BorderThickness="0"
CornerRadius="8"
DoubleTapped="Button_GameIcon_DoubleTapped"
IsDoubleTapEnabled="True"
IsTapEnabled="True"
PointerEntered="Button_GameIcon_PointerEntered"
PointerExited="Button_GameIcon_PointerExited"
Shadow="{ThemeResource ThemeShadow}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}"
Tag="{x:Bind GameId}"
Tapped="Button_GameIcon_Tapped"
Translation="0,0,16">
<Grid>
<Image Width="40" Height="40">
<Image.Source>
<BitmapImage DecodePixelHeight="40"
DecodePixelType="Logical"
DecodePixelWidth="40"
UriSource="{x:Bind GameIcon}" />
</Image.Source>
</Image>
<Image Width="20"
Height="20"
HorizontalAlignment="Right"
VerticalAlignment="Bottom">
<Image.Source>
<BitmapImage DecodePixelHeight="20"
DecodePixelType="Logical"
DecodePixelWidth="20"
UriSource="{x:Bind ServerIcon}" />
</Image.Source>
</Image>
<Border Background="#60000000" Opacity="{x:Bind MaskOpacity}">
<Border.OpacityTransition>
<ScalarTransition />
</Border.OpacityTransition>
</Border>
</Grid>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- 固定 -->
<Border Name="Button_Pin"
Width="40"
Height="40"
sh:PointerCursor.CursorShape="Hand"
Background="{ThemeResource CustomAcrylicBrush}"
CornerRadius="8"
Shadow="{ThemeResource ThemeShadow}"
Translation="0,0,16">
<Button Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Command="{x:Bind PinCommand}"
Style="{ThemeResource DateTimePickerFlyoutButtonStyle}">
<FontIcon x:Name="FontIcon_Pin"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="16"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Glyph="&#xE718;"
IsTextScaleFactorEnabled="False" />
</Button>
</Border>
</StackPanel>
</Border>



</Grid>


</UserControl>
Loading

0 comments on commit dccdec3

Please sign in to comment.