diff --git a/locals/Log.csv b/locals/Log.csv index a23ea4d..7186f21 100644 --- a/locals/Log.csv +++ b/locals/Log.csv @@ -72,4 +72,7 @@ log_state_processor_not_found,找不到状态处理器{0}。,State processor {0} log_chase_no_enemy,追逐没有敌人。,Chase no enemy.,敵がいない追跡です。 log_bubble_not_found,找不到气泡{0}。,Bubble {0} not found.,バブル{0}が見つかりません。 log_owner_is_not_AiCharacter,所有者不是AiCharacter。,Owner is not AiCharacter.,所有者はAiCharacterではありません。 -log_weaponContainer_is_null,武器容器为空。,Weapon container is null.,武器コンテナが空です。 \ No newline at end of file +log_weaponContainer_is_null,武器容器为空。,Weapon container is null.,武器コンテナが空です。 +log_find_nearest_item,查找最近的物品。,Find the nearest item.,最も近いアイテムを見つけます。 +log_float_label_instantiate_failed,浮动标签实例化失败。,Float label instantiation failed.,フロートラベルのインスタンス化に失敗しました。 +log_pickable_picked_up,可拾捡物被捡起了,那么不显示标签。,"If the pickable item is picked up, the label is not displayed.",でも、拾得物が拾い上げられたら、ラベルは表示されません。 \ No newline at end of file diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index 10282f1..0a540dd 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -218,6 +218,7 @@ public partial class CharacterTemplate : CharacterBody2D /// public Node2D? FindTheNearestItem() { + LogCat.Log("find_nearest_item"); if (PickingRangeBodiesList == null || PickingRangeBodiesList.Count == 0) { return null; diff --git a/scripts/character/Player.cs b/scripts/character/Player.cs index 7548cc4..380ee9e 100644 --- a/scripts/character/Player.cs +++ b/scripts/character/Player.cs @@ -17,8 +17,6 @@ namespace ColdMint.scripts.character; /// public partial class Player : CharacterTemplate { - private PackedScene? _floatLabelPackedScene; - private Control? _floatLabel; //Empty object projectile @@ -52,7 +50,17 @@ public partial class Player : CharacterTemplate CharacterName = TranslationServerUtils.Translate("default_player_name"); LogCat.LogWithFormat("player_spawn_debug", LogCat.LogLabel.Default, ReadOnlyCharacterName, GlobalPosition); - _floatLabelPackedScene = GD.Load("res://prefab/ui/FloatLabel.tscn"); + var floatLabelPackedScene = GD.Load("res://prefab/ui/FloatLabel.tscn"); + //Initializes the float label. + //初始化悬浮标签。 + _floatLabel = NodeUtils.InstantiatePackedScene(floatLabelPackedScene); + if (_floatLabel == null) + { + throw new NullReferenceException(TranslationServer.Translate("float_label_instantiate_failed")); + } + + _floatLabel.Hide(); + NodeUtils.CallDeferredAddChild(this, _floatLabel); _parabola = GetNode("Parabola"); _platformDetectionRayCast2D = GetNode("PlatformDetectionRayCast"); UpdateOperationTip(); @@ -147,9 +155,8 @@ public partial class Player : CharacterTemplate operationTipBuilder.Append(TranslationServerUtils.Translate("action_jump_down")); } - //If the PickingRangeBodiesList is not null and the length is greater than 0 - //如果PickingRangeBodiesList不是null,且长度大于0 - if (PickingRangeBodiesList is { Count: > 0 }) + var nearestItem = FindTheNearestItem(); + if (nearestItem != null) { operationTipBuilder.Append(' '); operationTipBuilder.Append("[color="); @@ -159,6 +166,11 @@ public partial class Player : CharacterTemplate TranslationServerUtils.Translate(InputMap.ActionGetEvents("pick_up")[0].AsText())); operationTipBuilder.Append("[/color]"); operationTipBuilder.Append(TranslationServerUtils.Translate("action_pick_up")); + if (nearestItem is IItem item) + { + operationTipBuilder.Append(item.Name); + } + operationTipLabel.Text = operationTipBuilder.ToString(); } @@ -232,11 +244,7 @@ public partial class Player : CharacterTemplate PickingRangeBodiesList?.Remove(pickAbleItem); } - if (_floatLabel != null) - { - _floatLabel.QueueFree(); - _floatLabel = null; - } + RecycleFloatLabel(); } } @@ -427,35 +435,41 @@ public partial class Player : CharacterTemplate return; } - if (_floatLabelPackedScene != null) + if (_floatLabel != null) { - //If there is a scene of floating text, then we generate floating text. - //如果有悬浮文本的场景,那么我们生成悬浮文本。 - _floatLabel?.QueueFree(); - _floatLabel = NodeUtils.InstantiatePackedScene(_floatLabelPackedScene); - if (_floatLabel != null) + if (node is not PickAbleTemplate pickAbleTemplate) { - NodeUtils.CallDeferredAddChild(node, _floatLabel); - var rotationDegreesNode2D = node2D.RotationDegrees; - var rotationDegreesNode2DAbs = Math.Abs(rotationDegreesNode2D); - _floatLabel.Position = rotationDegreesNode2DAbs > 90 - ? new Vector2(0, PromptTextDistance) - : new Vector2(0, -PromptTextDistance); - _floatLabel.RotationDegrees = 0 - rotationDegreesNode2D; - var label = _floatLabel.GetNode