Skip to content

Commit aece44b

Browse files
committed
Refine legend weapon upgrade UI and logic experience
Significantly enhance the legend weapon upgrade experience by introducing a visually improved, animated confirmation UI and smarter upgrade logic that adapts to different gameplay contexts. Players now enjoy a more immersive and less intrusive upgrade process, with confirmation prompts only for cross-world upgrades and seamless, silent upgrades in other scenarios. The UI features richer animations, particle effects, and localized text, providing a more polished and ceremonial feel to weapon progression.
1 parent 1007667 commit aece44b

File tree

3 files changed

+758
-245
lines changed

3 files changed

+758
-245
lines changed

Content/CWRItem.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ public override void SaveData(Item item, TagCompound tag) {
641641

642642

643643
try {
644-
LegendData?.DoUpdate(item);
644+
//存储操作使用StorageOperation上下文,静默升级不弹窗
645+
LegendData?.DoUpdate(item, LegendUpdateContext.StorageOperation);
645646
LegendData?.SaveData(item, tag);
646647
} catch (Exception ex) {
647648
CWRMod.Instance.Logger.Error($"[LegendData:SaveData] an error has occurred:{ex.Message}");
@@ -699,7 +700,8 @@ public override void LoadData(Item item, TagCompound tag) {
699700

700701
try {
701702
LegendData?.LoadData(item, tag);
702-
LegendData?.DoUpdate(item);
703+
//加载操作使用StorageOperation上下文,静默升级不弹窗
704+
LegendData?.DoUpdate(item, LegendUpdateContext.StorageOperation);
703705
} catch (Exception ex) {
704706
CWRMod.Instance.Logger.Error($"[LegendData:LoadData] an error has occurred:{ex.Message}");
705707
}
@@ -712,7 +714,8 @@ public override void LoadData(Item item, TagCompound tag) {
712714
}
713715

714716
public override void HoldItem(Item item, Player player) {
715-
LegendData?.DoUpdate(item);
717+
//玩家手持物品,使用PlayerHolding上下文,跨世界需要确认
718+
LegendData?.DoUpdate(item, LegendUpdateContext.PlayerHolding);
716719
if (heldProjType > 0) {
717720
//使用GetProjectileHasNum即时检测,而不是使用ownedProjectileCounts,这样获得的弹幕数量最为保险
718721
if (player.CountProjectilesOfID(heldProjType) <= 0 && Main.myPlayer == player.whoAmI) {//player.ownedProjectileCounts[heldProjType] == 0
@@ -740,12 +743,14 @@ public override bool CanUseItem(Item item, Player player) {
740743
}
741744

742745
public override void UpdateInventory(Item item, Player player) {
743-
LegendData?.DoUpdate(item);
746+
//玩家背包中的物品,使用PlayerInventory上下文,跨世界需要确认
747+
LegendData?.DoUpdate(item, LegendUpdateContext.PlayerInventory);
744748
RecoverUnloadedItem.UpdateInventory(item);
745749
}
746750

747751
public override void Update(Item item, ref float gravity, ref float maxFallSpeed) {
748-
LegendData?.DoUpdate(item);
752+
//世界掉落物,使用WorldItem上下文,静默升级不弹窗
753+
LegendData?.DoUpdate(item, LegendUpdateContext.WorldItem);
749754
}
750755

751756
public static void OverModifyTooltip(Item item, List<TooltipLine> tooltips) {

Content/LegendWeapon/LegendData.cs

Lines changed: 104 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,30 @@
88
using Terraria.ModLoader.IO;
99

1010
namespace CalamityOverhaul.Content.LegendWeapon
11-
{
11+
{
12+
/// <summary>
13+
/// 传奇武器升级更新的调用上下文,用于区分不同场景下的升级行为
14+
/// </summary>
15+
public enum LegendUpdateContext
16+
{
17+
/// <summary>
18+
/// 玩家正在手持该物品
19+
/// </summary>
20+
PlayerHolding,
21+
/// <summary>
22+
/// 物品在玩家背包中
23+
/// </summary>
24+
PlayerInventory,
25+
/// <summary>
26+
/// 物品正在被存储或加载(存档操作)
27+
/// </summary>
28+
StorageOperation,
29+
/// <summary>
30+
/// 物品在世界中(掉落物、箱子等)
31+
/// </summary>
32+
WorldItem
33+
}
34+
1235
public abstract class LegendData
1336
{
1437
/// <summary>
@@ -131,37 +154,92 @@ public virtual void LoadData(Item item, TagCompound tag) {
131154
}
132155
}
133156

134-
public virtual void Update(Item item) {
157+
/// <summary>
158+
/// 检查物品是否需要升级
159+
/// </summary>
160+
/// <returns>如果需要升级返回true</returns>
161+
public bool NeedUpgrade() {
135162
if (DontUpgradeName == SaveWorld.WorldFullName) {
136-
return;//跳过升级
163+
return false;
137164
}
138-
//检测是否需要升级
139-
if (TargetLevel <= Level && !UpgradeTagNameIsEmpty) {
140-
return;
141-
}
142-
//确保不是在同一个世界内多次升级
143-
if (UpgradeWorldFullName != string.Empty && UpgradeWorldFullName != SaveWorld.WorldFullName) {
144-
if (item != null && item.type > ItemID.None) {
145-
//检查该物品是否就是当前LegendData所属的物品
146-
if (item.CWR().LegendData == this) {
147-
//弹出确认UI
148-
LegendUpgradeConfirmUI.RequestUpgrade(item, this, TargetLevel);
149-
return;//等待用户确认,不自动升级
150-
}
151-
}
152-
}
153-
154-
//如果不是手持状态,或者确认UI已经处理完毕,则自动升级(保持原有行为)
155-
//这样可以兼容旧存档和非手持情况
156-
if (!LegendUpgradeConfirmUI.Instance.Active) {
157-
UpgradeWorldName = Main.worldName;
158-
UpgradeWorldFullName = SaveWorld.WorldFullName;
159-
Level = TargetLevel;
165+
if (TargetLevel <= Level && !UpgradeTagNameIsEmpty) {
166+
return false;
160167
}
168+
return true;
169+
}
170+
171+
/// <summary>
172+
/// 检查是否需要跨世界升级确认(即从别的世界带过来的传奇武器)
173+
/// </summary>
174+
/// <returns>如果需要跨世界确认返回true</returns>
175+
public bool NeedCrossWorldConfirm() {
176+
return UpgradeWorldFullName != string.Empty && UpgradeWorldFullName != SaveWorld.WorldFullName;
161177
}
162178

179+
/// <summary>
180+
/// 执行实际的升级操作
181+
/// </summary>
182+
private void PerformUpgrade() {
183+
UpgradeWorldName = Main.worldName;
184+
UpgradeWorldFullName = SaveWorld.WorldFullName;
185+
Level = TargetLevel;
186+
}
187+
188+
public virtual void Update(Item item, LegendUpdateContext context) {
189+
//基础检查,如果不需要升级就直接返回
190+
if (!NeedUpgrade()) {
191+
return;
192+
}
193+
194+
//验证物品有效性
195+
if (item == null || item.type <= ItemID.None) {
196+
return;
197+
}
198+
199+
//验证物品的LegendData是否就是当前实例
200+
CWRItem cwrItem = item.CWR();
201+
if (cwrItem == null || cwrItem.LegendData != this) {
202+
return;
203+
}
204+
205+
//根据上下文决定升级行为
206+
switch (context) {
207+
case LegendUpdateContext.PlayerHolding:
208+
case LegendUpdateContext.PlayerInventory:
209+
//玩家背包或手持中的物品,如果是跨世界升级需要确认
210+
if (NeedCrossWorldConfirm()) {
211+
//弹出确认UI,等待用户确认
212+
LegendUpgradeConfirmUI.RequestUpgrade(item, this, TargetLevel);
213+
return;
214+
}
215+
//同世界或首次升级,直接执行
216+
if (!LegendUpgradeConfirmUI.Instance.Active) {
217+
PerformUpgrade();
218+
}
219+
break;
220+
221+
case LegendUpdateContext.StorageOperation:
222+
case LegendUpdateContext.WorldItem:
223+
//存储操作或世界物品,静默升级不弹窗
224+
//这样可以保证箱子里的传奇武器也能正常升级而不会干扰玩家
225+
PerformUpgrade();
226+
break;
227+
}
228+
}
229+
230+
/// <summary>
231+
/// 带上下文的更新调用,推荐使用此方法
232+
/// </summary>
233+
public void DoUpdate(Item item, LegendUpdateContext context) {
234+
Update(item, context);
235+
}
236+
237+
/// <summary>
238+
/// 无上下文的更新调用,默认为世界物品上下文(静默升级)
239+
/// 保留此重载以兼容旧代码
240+
/// </summary>
163241
public void DoUpdate(Item item) {
164-
Update(item);
242+
Update(item, LegendUpdateContext.WorldItem);
165243
}
166244
}
167245
}

0 commit comments

Comments
 (0)