mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
fix panel selector global group name
This commit is contained in:
@@ -5,12 +5,13 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:shcm="using:Snap.Hutao.Control.Markup"
|
||||
Loaded="OnRootControlLoaded"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<SplitButton
|
||||
Name="RootSplitButton"
|
||||
Padding="0,6"
|
||||
Click="SplitButtonClick"
|
||||
Loaded="SplitButtonLoaded">
|
||||
Click="SplitButtonClick">
|
||||
<SplitButton.Content>
|
||||
<FontIcon Name="IconPresenter" Glyph=""/>
|
||||
</SplitButton.Content>
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Snap.Hutao.Control.Panel;
|
||||
/// </summary>
|
||||
public sealed partial class PanelSelector : UserControl
|
||||
{
|
||||
private static readonly DependencyProperty CurrentProperty = Property<PanelSelector>.Depend(nameof(Current), "List");
|
||||
private static readonly DependencyProperty CurrentProperty = Property<PanelSelector>.Depend(nameof(Current), "List", OnCurrentChanged);
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的面板选择器
|
||||
@@ -30,51 +30,60 @@ public sealed partial class PanelSelector : UserControl
|
||||
set => SetValue(CurrentProperty, value);
|
||||
}
|
||||
|
||||
private void SplitButtonLoaded(object sender, RoutedEventArgs e)
|
||||
private static void OnCurrentChanged(PanelSelector sender, string current)
|
||||
{
|
||||
MenuFlyout menuFlyout = (MenuFlyout)((SplitButton)sender).Flyout;
|
||||
((RadioMenuFlyoutItem)menuFlyout.Items[0]).IsChecked = true;
|
||||
MenuFlyout menuFlyout = (MenuFlyout)sender.RootSplitButton.Flyout;
|
||||
RadioMenuFlyoutItem targetItem = menuFlyout.Items
|
||||
.Cast<RadioMenuFlyoutItem>()
|
||||
.Single(i => (string)i.Tag == current);
|
||||
targetItem.IsChecked = true;
|
||||
sender.IconPresenter.Glyph = ((FontIcon)targetItem.Icon).Glyph;
|
||||
}
|
||||
|
||||
private static void OnCurrentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
OnCurrentChanged((PanelSelector)obj, (string)args.NewValue);
|
||||
}
|
||||
|
||||
private void OnRootControlLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// because the GroupName shares in global
|
||||
// we have to impl a control scoped GroupName.
|
||||
PanelSelector selector = (PanelSelector)sender;
|
||||
MenuFlyout menuFlyout = (MenuFlyout)selector.RootSplitButton.Flyout;
|
||||
int hash = GetHashCode();
|
||||
foreach (RadioMenuFlyoutItem item in menuFlyout.Items.Cast<RadioMenuFlyoutItem>())
|
||||
{
|
||||
item.GroupName = $"PanelSelector{hash}Group";
|
||||
}
|
||||
|
||||
OnCurrentChanged(selector, Current);
|
||||
}
|
||||
|
||||
private void SplitButtonClick(SplitButton sender, SplitButtonClickEventArgs args)
|
||||
{
|
||||
MenuFlyout menuFlyout = (MenuFlyout)sender.Flyout;
|
||||
|
||||
int i = 0;
|
||||
for (; i < menuFlyout.Items.Count; i++)
|
||||
{
|
||||
RadioMenuFlyoutItem current = (RadioMenuFlyoutItem)menuFlyout.Items[i];
|
||||
if (current.IsChecked)
|
||||
if ((string)menuFlyout.Items[i].Tag == Current)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if (i > menuFlyout.Items.Count)
|
||||
{
|
||||
i = 1;
|
||||
}
|
||||
|
||||
if (i == menuFlyout.Items.Count)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
++i;
|
||||
i %= menuFlyout.Items.Count; // move the count index to 0
|
||||
|
||||
RadioMenuFlyoutItem item = (RadioMenuFlyoutItem)menuFlyout.Items[i];
|
||||
item.IsChecked = true;
|
||||
UpdateState(item);
|
||||
Current = (string)item.Tag;
|
||||
}
|
||||
|
||||
private void RadioMenuFlyoutItemClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
RadioMenuFlyoutItem item = (RadioMenuFlyoutItem)sender;
|
||||
UpdateState(item);
|
||||
}
|
||||
|
||||
private void UpdateState(RadioMenuFlyoutItem item)
|
||||
{
|
||||
Current = (string)item.Tag;
|
||||
IconPresenter.Glyph = ((FontIcon)item.Icon).Glyph;
|
||||
}
|
||||
}
|
||||
@@ -27,4 +27,9 @@ internal static class SettingKeys
|
||||
/// 静态资源合约V1
|
||||
/// </summary>
|
||||
public const string StaticResourceV1Contract = "StaticResourceV1Contract";
|
||||
|
||||
/// <summary>
|
||||
/// 静态资源合约V2 成就图标与物品图标
|
||||
/// </summary>
|
||||
public const string StaticResourceV2Contract = "StaticResourceV2Contract";
|
||||
}
|
||||
@@ -33,9 +33,11 @@ public sealed partial class MainWindow : Window, IExtendedWindowSource, IRecipie
|
||||
|
||||
Ioc.Default.GetRequiredService<IMessenger>().Register(this);
|
||||
|
||||
// Query the StaticResourceV1Contract.
|
||||
// Query the StaticResourceV1Contract & StaticResourceV2Contract.
|
||||
// If not complete we should present the welcome view.
|
||||
ContentSwitchPresenter.Value = !LocalSetting.Get(SettingKeys.StaticResourceV1Contract, false);
|
||||
ContentSwitchPresenter.Value =
|
||||
!LocalSetting.Get(SettingKeys.StaticResourceV1Contract, false)
|
||||
|| (!LocalSetting.Get(SettingKeys.StaticResourceV2Contract, false));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -92,7 +92,6 @@
|
||||
</Border>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
|
||||
</UserControl.Resources>
|
||||
|
||||
<Border Background="{StaticResource CardBackgroundFillColorDefaultBrush}" CornerRadius="{StaticResource CompatCornerRadius}">
|
||||
@@ -124,7 +123,10 @@
|
||||
FontSize="24"
|
||||
Text="{Binding TotalCount}"
|
||||
Visibility="{Binding ElementName=DetailExpander, Path=IsExpanded, Converter={StaticResource BoolToVisibilityRevertConverter}}"/>
|
||||
<shcp:PanelSelector x:Name="ItemsPanelSelector" Margin="6,0,6,0"/>
|
||||
<shcp:PanelSelector
|
||||
x:Name="ItemsPanelSelector"
|
||||
Margin="6,0"
|
||||
Current="Grid"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Expander.Header>
|
||||
|
||||
@@ -51,18 +51,27 @@ internal class WelcomeViewModel : ObservableObject
|
||||
|
||||
private async Task OpenUIAsync()
|
||||
{
|
||||
List<DownloadSummary> downloadSummaries = new()
|
||||
List<DownloadSummary> downloadSummaries = new();
|
||||
|
||||
if (!LocalSetting.Get(SettingKeys.StaticResourceV1Contract, false))
|
||||
{
|
||||
new(serviceProvider, "基础图标", "Bg"),
|
||||
new(serviceProvider, "角色图标", "AvatarIcon"),
|
||||
new(serviceProvider, "角色立绘图标", "GachaAvatarIcon"),
|
||||
new(serviceProvider, "角色立绘图像", "GachaAvatarImg"),
|
||||
new(serviceProvider, "武器图标", "EquipIcon"),
|
||||
new(serviceProvider, "武器立绘图标", "GachaEquipIcon"),
|
||||
new(serviceProvider, "名片图像", "NameCardPic"),
|
||||
new(serviceProvider, "天赋图标", "Skill"),
|
||||
new(serviceProvider, "命之座图标", "Talent"),
|
||||
};
|
||||
downloadSummaries.Add(new(serviceProvider, "基础图标", "Bg"));
|
||||
downloadSummaries.Add(new(serviceProvider, "角色图标", "AvatarIcon"));
|
||||
downloadSummaries.Add(new(serviceProvider, "角色立绘图标", "GachaAvatarIcon"));
|
||||
downloadSummaries.Add(new(serviceProvider, "角色立绘图像", "GachaAvatarImg"));
|
||||
downloadSummaries.Add(new(serviceProvider, "武器图标", "EquipIcon"));
|
||||
downloadSummaries.Add(new(serviceProvider, "武器立绘图标", "GachaEquipIcon"));
|
||||
downloadSummaries.Add(new(serviceProvider, "名片图像", "NameCardPic"));
|
||||
downloadSummaries.Add(new(serviceProvider, "天赋图标", "Skill"));
|
||||
downloadSummaries.Add(new(serviceProvider, "命之座图标", "Talent"));
|
||||
}
|
||||
|
||||
if (!LocalSetting.Get(SettingKeys.StaticResourceV2Contract, false))
|
||||
{
|
||||
downloadSummaries.Add(new(serviceProvider, "成就图标", "AchievementIcon"));
|
||||
downloadSummaries.Add(new(serviceProvider, "物品图标", "ItemIcon"));
|
||||
downloadSummaries.Add(new(serviceProvider, "元素图标", "IconElement"));
|
||||
}
|
||||
|
||||
DownloadSummaries = new(downloadSummaries);
|
||||
|
||||
@@ -70,8 +79,9 @@ internal class WelcomeViewModel : ObservableObject
|
||||
|
||||
serviceProvider.GetRequiredService<IMessenger>().Send(new Message.WelcomeStateCompleteMessage());
|
||||
|
||||
// Complete the StaticResourceV1Contract
|
||||
// Complete StaticResourceContracts
|
||||
LocalSetting.Set(SettingKeys.StaticResourceV1Contract, true);
|
||||
LocalSetting.Set(SettingKeys.StaticResourceV2Contract, true);
|
||||
|
||||
new ToastContentBuilder()
|
||||
.AddText("下载完成")
|
||||
|
||||
@@ -11,7 +11,6 @@ public interface IJsResult
|
||||
/// <summary>
|
||||
/// 转换到Json字符串表示
|
||||
/// </summary>
|
||||
/// <param name="options">序列化参数</param>
|
||||
/// <returns>JSON字符串</returns>
|
||||
string ToString(JsonSerializerOptions options);
|
||||
string ToString();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class JsResult<TData> : IJsResult
|
||||
public TData Data { get; set; } = default!;
|
||||
|
||||
/// <inheritdoc/>
|
||||
string IJsResult.ToString(JsonSerializerOptions options)
|
||||
string IJsResult.ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Snap.Hutao.Web.Response;
|
||||
/// <summary>
|
||||
/// 已知的返回代码
|
||||
/// </summary>
|
||||
public enum KnownReturnCode : int
|
||||
public enum KnownReturnCode
|
||||
{
|
||||
/// <summary>
|
||||
/// 无效请求
|
||||
|
||||
@@ -94,7 +94,7 @@ public class Response<TData> : Response, IJsResult
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
string IJsResult.ToString(JsonSerializerOptions options)
|
||||
string IJsResult.ToString()
|
||||
{
|
||||
return JsonSerializer.Serialize(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user