@@ -28,6 +28,19 @@ public partial class LevelUp : Button, IController
2828 // 静态缓存:参考陨石实现方法的备选方案
2929 private static SkillRoot ? _cachedSkillRoot = null ;
3030 private static bool _hasTriedLoadStatic = false ;
31+
32+ // NPC对话框文本打字机
33+ private TextTyper ? _npcTextTyper = null ;
34+
35+ /// <summary>
36+ /// 设置NPC对话框文本打字机
37+ /// </summary>
38+ /// <param name="textTyper">TextTyper实例</param>
39+ public void SetNpcTextTyper ( TextTyper textTyper )
40+ {
41+ _npcTextTyper = textTyper ;
42+ GD . Print ( $ "LevelUp: 已设置TextTyper引用") ;
43+ }
3144
3245 public override void _Ready ( )
3346 {
@@ -73,7 +86,14 @@ public void OnPressed()
7386 // 检查是否有选中的技能
7487 if ( _currentSkillData == null || _currentSkillLevel == null )
7588 {
76- GD . Print ( "请先选择一个技能" ) ;
89+ if ( _npcTextTyper != null )
90+ {
91+ _npcTextTyper . SetTyperText ( Tr ( "没有选中技能" ) ) ;
92+ }
93+ else
94+ {
95+ GD . Print ( Tr ( "没有选中技能" ) ) ;
96+ }
7797 return ;
7898 }
7999
@@ -87,7 +107,15 @@ public void OnPressed()
87107 // 检查是否已满级
88108 if ( currentLevel >= _currentSkillData . MaxLevel )
89109 {
90- GD . Print ( $ "{ _currentSkillData . DisplayName } 已满级,无法继续升级") ;
110+ string fullLevelText = $ "{ Tr ( _currentSkillData . DisplayName ) } { Tr ( "已满级" ) } ";
111+ if ( _npcTextTyper != null )
112+ {
113+ _npcTextTyper . SetTyperText ( fullLevelText ) ;
114+ }
115+ else
116+ {
117+ GD . Print ( fullLevelText ) ;
118+ }
91119 return ;
92120 }
93121
@@ -98,17 +126,56 @@ public void OnPressed()
98126 return ;
99127 }
100128
101- // 检查散矿是否足够
102- if ( PlayerManager . Instance . TotalOreCount < OreCost )
129+ // 检查资源是否足够
130+ bool oreShortage = PlayerManager . Instance . TotalOreCount < OreCost ;
131+ bool gemShortage = PlayerManager . Instance . TotalGemCount < GemCost ;
132+
133+ // 如果两种资源都缺
134+ if ( oreShortage && gemShortage )
103135 {
104- GD . Print ( $ "矿石不足!需要{ OreCost } 散矿,当前只有{ PlayerManager . Instance . TotalOreCount } 散矿") ;
136+ int oreNeeded = OreCost - PlayerManager . Instance . TotalOreCount ;
137+ int gemNeeded = GemCost - PlayerManager . Instance . TotalGemCount ;
138+ string shortageText = $ "{ Tr ( "升级失败" ) } ,{ Tr ( "缺少" ) } { oreNeeded } { Tr ( "散矿" ) } +{ gemNeeded } { Tr ( "宝石" ) } ";
139+ if ( _npcTextTyper != null )
140+ {
141+ _npcTextTyper . SetTyperText ( shortageText ) ;
142+ }
143+ else
144+ {
145+ GD . Print ( shortageText ) ;
146+ }
147+ return ;
148+ }
149+
150+ // 如果只缺散矿
151+ if ( oreShortage )
152+ {
153+ int oreNeeded = OreCost - PlayerManager . Instance . TotalOreCount ;
154+ string oreShortageText = $ "{ Tr ( "升级失败" ) } ,{ Tr ( "缺少" ) } { oreNeeded } { Tr ( "散矿" ) } ";
155+ if ( _npcTextTyper != null )
156+ {
157+ _npcTextTyper . SetTyperText ( oreShortageText ) ;
158+ }
159+ else
160+ {
161+ GD . Print ( oreShortageText ) ;
162+ }
105163 return ;
106164 }
107165
108- // 检查宝石是否足够
109- if ( PlayerManager . Instance . TotalGemCount < GemCost )
166+ // 如果只缺宝石
167+ if ( gemShortage )
110168 {
111- GD . Print ( $ "宝石不足!需要{ GemCost } 宝石,当前只有{ PlayerManager . Instance . TotalGemCount } 宝石") ;
169+ int gemNeeded = GemCost - PlayerManager . Instance . TotalGemCount ;
170+ string gemShortageText = $ "{ Tr ( "升级失败" ) } ,{ Tr ( "缺少" ) } { gemNeeded } { Tr ( "宝石" ) } ";
171+ if ( _npcTextTyper != null )
172+ {
173+ _npcTextTyper . SetTyperText ( gemShortageText ) ;
174+ }
175+ else
176+ {
177+ GD . Print ( gemShortageText ) ;
178+ }
112179 return ;
113180 }
114181
@@ -133,8 +200,16 @@ public void OnPressed()
133200 // 保存存档
134201 _saveStorageUtility . Save ( ) ;
135202
136- GD . Print ( $ "升级成功!{ _currentSkillData . DisplayName } 从等级{ currentLevel } 提升到等级{ nextLevel } ") ;
137- GD . Print ( $ "消耗了{ OreCost } 散矿和{ GemCost } 宝石") ;
203+ // 显示升级成功信息
204+ string successText = $ "{ Tr ( "升级成功" ) } !{ Tr ( _currentSkillData . DisplayName ) } { Tr ( "从等级" ) } { currentLevel } { Tr ( "提升到等级" ) } { nextLevel } ";
205+ if ( _npcTextTyper != null )
206+ {
207+ _npcTextTyper . SetTyperText ( successText ) ;
208+ }
209+ else
210+ {
211+ GD . Print ( successText ) ;
212+ }
138213
139214 // 更新PlayerManager中的对应变量
140215 UpdatePlayerManagerVariable ( _currentSkillData . Name , ( float ) _currentSkillLevel . Value ) ;
@@ -320,7 +395,7 @@ private void SelectSkill(string skillName)
320395
321396 if ( _currentSkillData != null )
322397 {
323- GD . Print ( $ "选中{ _currentSkillData . DisplayName } : { _currentSkillData . Description } ") ;
398+ GD . Print ( $ "选中{ Tr ( _currentSkillData . DisplayName ) } : { Tr ( _currentSkillData . Description ) } ") ;
324399
325400 // 从存档中获取当前技能等级
326401 int currentLevel = _saveStorageUtility . GetSkillLevel ( skillName ) ;
@@ -357,7 +432,7 @@ private void SelectSkill(string skillName)
357432
358433 if ( currentLevel < _currentSkillData . MaxLevel )
359434 {
360- GD . Print ( $ "当前等级{ currentLevel } -> 下一等级{ nextLevel } : 数值={ _currentSkillLevel . Value } , 消耗={ OreCost } 矿石 , { GemCost } 宝石 ") ;
435+ GD . Print ( $ "当前等级{ currentLevel } -> 下一等级{ nextLevel } : 数值={ _currentSkillLevel . Value } , 消耗={ OreCost } { Tr ( "散矿" ) } , { GemCost } { Tr ( "宝石" ) } ") ;
361436 }
362437 else
363438 {
0 commit comments