Skip to content

Commit

Permalink
partial #2403
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Jan 31, 2025
1 parent 81c3ec6 commit d5cbe81
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 9 deletions.
47 changes: 46 additions & 1 deletion src/Snap.Hutao/Snap.Hutao/Model/Calculable/CalculableAvatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using CommunityToolkit.Mvvm.ComponentModel;
using Snap.Hutao.Core.ExceptionService;
using Snap.Hutao.Core.Setting;
using Snap.Hutao.Model.Intrinsic;
using Snap.Hutao.Model.Metadata.Avatar;
Expand All @@ -28,6 +29,7 @@ private CalculableAvatar(Avatar avatar)
Name = avatar.Name;
Icon = AvatarIconConverter.IconNameToUri(avatar.Icon);
Quality = avatar.Quality;
PromoteLevel = 0;

LevelCurrent = LevelMin;
}
Expand All @@ -43,6 +45,12 @@ private CalculableAvatar(AvatarView avatar)
Name = avatar.Name;
Icon = avatar.Icon;
Quality = avatar.Quality;
IsPromoted = (avatar.LevelNumber, avatar.PromoteLevel.Value) switch
{
(20, 1U) or (40, 2U) or (50, 3U) or (60, 4U) or (70, 5U) or (80, 6U) => true,
_ => false,
};
PromoteLevel = avatar.PromoteLevel;

LevelCurrent = LevelMin;
}
Expand All @@ -61,10 +69,35 @@ private CalculableAvatar(AvatarView avatar)

public QualityType Quality { get; }

public PromoteLevel PromoteLevel { get; private set; }

public bool IsPromotionAvailable
{
get => LevelCurrent is 20U or 40U or 50U or 60U or 70U or 80U;
}

public uint LevelCurrent
{
get => persistsLevel ? LocalSetting.Get(SettingKeys.CultivationAvatarLevelCurrent, LevelMin) : field;
set => _ = persistsLevel ? SetProperty(LevelCurrent, value, v => LocalSetting.Set(SettingKeys.CultivationAvatarLevelCurrent, v)) : SetProperty(ref field, value);
set
{
if (persistsLevel ? SetProperty(LevelCurrent, value, v => LocalSetting.Set(SettingKeys.CultivationAvatarLevelCurrent, v)) : SetProperty(ref field, value))
{
OnPropertyChanged(nameof(IsPromotionAvailable));
IsPromoted = false;
PromoteLevel = value switch
{
> 0 and <= 20 => 0,
<= 40 => 1,
<= 50 => 2,
<= 60 => 3,
<= 70 => 4,
<= 80 => 5,
<= 90 => 6,
_ => throw HutaoException.InvalidOperation("Invalid avatar level."),
};
}
}
}

public uint LevelTarget
Expand All @@ -73,6 +106,18 @@ public uint LevelTarget
set => SetProperty(LevelTarget, value, v => LocalSetting.Set(SettingKeys.CultivationAvatarLevelTarget, v));
}

public bool IsPromoted
{
get;
set
{
if (SetProperty(ref field, value) && value)
{
PromoteLevel++;
}
}
}

public static CalculableAvatar From(Avatar source)
{
return new(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ internal interface ICalculableAvatar : ICalculableMinMaxLevel
AvatarId AvatarId { get; }

ImmutableArray<ICalculableSkill> Skills { get; }

PromoteLevel PromoteLevel { get; }

bool IsPromoted { get; }

bool IsPromotionAvailable { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static TBuilder SetNameCard<TBuilder>(this TBuilder builder, Uri nameCard
return builder.Configure(b => b.View.NameCard = nameCard);
}

public static TBuilder SetPromoteList<TBuilder>(this TBuilder builder, PromoteLevel promoteLevel)
public static TBuilder SetPromoteLevel<TBuilder>(this TBuilder builder, PromoteLevel promoteLevel)
where TBuilder : IAvatarViewBuilder
{
bool[] promoteListBuilder = new bool[6];
Expand All @@ -112,7 +112,10 @@ public static TBuilder SetPromoteList<TBuilder>(this TBuilder builder, PromoteLe
promoteListBuilder[i] = true;
}

return builder.Configure(b => b.View.PromoteList = promoteListBuilder.ToImmutableArray());
builder.View.PromoteLevel = promoteLevel;
builder.View.PromoteList = promoteListBuilder.ToImmutableArray();

return builder;
}

public static TBuilder SetProperties<TBuilder>(this TBuilder builder, ImmutableArray<AvatarProperty> properties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static TBuilder SetName<TBuilder>(this TBuilder builder, string name)
return builder.SetName<TBuilder, WeaponView>(name);
}

public static TBuilder SetPromoteList<TBuilder>(this TBuilder builder, PromoteLevel promoteLevel)
public static TBuilder SetPromoteLevel<TBuilder>(this TBuilder builder, PromoteLevel promoteLevel)
where TBuilder : IWeaponViewBuilder
{
bool[] promoteListBuilder = new bool[6];
Expand All @@ -87,7 +87,10 @@ public static TBuilder SetPromoteList<TBuilder>(this TBuilder builder, PromoteLe
promoteListBuilder[i] = true;
}

return builder.Configure(b => b.View.PromoteList = promoteListBuilder.ToImmutableArray());
builder.View.PromoteLevel = promoteLevel;
builder.View.PromoteList = promoteListBuilder.ToImmutableArray();

return builder;
}

public static TBuilder SetQuality<TBuilder>(this TBuilder builder, QualityType quality)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public AvatarView Create()
.SetReliquaries(character.Relics.SelectAsArray(relic => SummaryReliquaryFactory.Create(context, relic)))
.SetRefreshTimeFormat(refreshTime, obj => string.Format(CultureInfo.CurrentCulture, "{0:MM-dd HH:mm}", obj), SH.ServiceAvatarInfoSummaryNotRefreshed)
.SetCostumeIconOrDefault(character, avatar)
.SetPromoteList(character.Base.PromoteLevel)
.SetPromoteLevel(character.Base.PromoteLevel)
.View;

return propertyAvatar;
Expand Down Expand Up @@ -143,7 +143,7 @@ private WeaponView CreateWeapon(DetailedWeapon detailedWeapon)
.SetAffixName(metadataWeapon.Affix?.Name)
.SetAffixDescription(metadataWeapon.Affix?.Descriptions.Single(a => a.Level == (detailedWeapon.AffixLevel - 1)).Description)
.SetWeaponType(metadataWeapon.WeaponType)
.SetPromoteList(detailedWeapon.PromoteLevel)
.SetPromoteLevel(detailedWeapon.PromoteLevel)
.View;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
xmlns:shuxm="using:Snap.Hutao.UI.Xaml.Markup"
xmlns:shuxvd="using:Snap.Hutao.UI.Xaml.View.Dialog"
Title="{shuxm:ResourceString Name=ViewDialogCultivatePromotionDeltaBatchTitle}"
d:DataContext="{d:DesignInstance shuxvd:CultivatePromotionDeltaDialog}"
CloseButtonText="{shuxm:ResourceString Name=ContentDialogCancelCloseButtonText}"
DefaultButton="Primary"
PrimaryButtonText="{shuxm:ResourceString Name=ContentDialogConfirmPrimaryButtonText}"
Expand Down Expand Up @@ -80,4 +79,4 @@
<RadioButton Content="{shuxm:ResourceString Name=ViewDialogCultivationConsumptionSaveStrategyCreateNewEntry}"/>
</RadioButtons>
</StackPanel>
</ContentDialog>
</ContentDialog>
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@
Height="36"
Icon="{Binding Icon}"
Quality="{Binding Quality}"/>
<!-- TODO -->
<!-- <StackPanel -->
<!-- HorizontalAlignment="Right" -->
<!-- Orientation="Horizontal"> -->
<!-- <TextBlock VerticalAlignment="Center" Text="已突破"/> -->
<!-- <CheckBox -->
<!-- VerticalAlignment="Center" -->
<!-- IsChecked="{Binding IsPromoted, Mode=TwoWay}" -->
<!-- Visibility="{Binding IsPromotionAvailable}"/> -->
<!-- </StackPanel> -->
<TextBlock
Grid.Column="1"
Margin="16,0,0,0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public async ValueTask<ValueResult<bool, CultivatePromotionDeltaOptions>> GetPro
AvatarId = Avatar?.AvatarId ?? 0,
AvatarLevelCurrent = Avatar is not null ? Math.Clamp(Avatar.LevelCurrent, Avatar.LevelMin, Avatar.LevelMax) : 0,
AvatarLevelTarget = Avatar is not null ? Math.Clamp(Avatar.LevelTarget, Avatar.LevelMin, Avatar.LevelMax) : 0,
AvatarPromoteLevel = Avatar?.PromoteLevel ?? 0,
SkillList = Avatar?.Skills.SelectAsArray(skill => new PromotionDelta
{
Id = skill.GroupId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ internal sealed partial class AvatarView : INameIconSide<Uri>,

internal uint LevelNumber { get; set; }

internal PromoteLevel PromoteLevel { get; set; }

public ICalculableAvatar ToCalculable()
{
return CalculableAvatar.From(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ internal sealed class WeaponView : EquipView, ICalculableSource<ICalculableWeapo

internal WeaponType WeaponType { get; set; }

internal PromoteLevel PromoteLevel { get; set; }

public ICalculableWeapon ToCalculable()
{
return CalculableWeapon.From(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ internal sealed class AvatarPromotionDelta
[JsonPropertyName("weapon")]
public PromotionDelta? Weapon { get; set; }

[JsonPropertyName("from_user_sync")]
public bool FromUserSync { get; set; } = true;

[JsonPropertyName("avatar_promote_level")]
public uint AvatarPromoteLevel { get; set; }

Expand Down

0 comments on commit d5cbe81

Please sign in to comment.