Fix the issue of picking up lost attributes after losing weapons.
修复失去武器后再捡起丢失属性的问题。
This commit is contained in:
parent
cff0507d25
commit
d3f2076b11
|
@ -1,4 +1,3 @@
|
|||
id,zh,en,ja
|
||||
de,的,"'s",の
|
||||
default_player_name,白纸,blankPaper,しらかみ
|
||||
item_prompt_debug,ID:{0}\n名称:{1}\n数量:{2}\n最大叠加数量:{3}\n数据类型:{4}\n描述:{5},ID: {0}\nName: {1}\nQuantity: {2}\nMaximum stacking quantity: {3}\nData type: {4}\nDescription:{5},id:{0}\n名称:{1}\nの数は最大{2}\nシナジー数:{3}\nデータタイプ:{4}\n述べ表わす:{5}
|
|
|
@ -30,3 +30,8 @@ shape = SubResource("RectangleShape2D_xqyue")
|
|||
[node name="Packsack" type="Sprite2D" parent="."]
|
||||
scale = Vector2(0.5, 0.5)
|
||||
texture = ExtResource("2_l0fbh")
|
||||
|
||||
[node name="TipLabel" type="Label" parent="."]
|
||||
offset_top = 31.0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 56.0
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
[gd_scene format=3 uid="uid://b7se73tsnlpd6"]
|
||||
|
||||
[node name="FloatLabel" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Label" type="Label" parent="."]
|
||||
layout_mode = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 23.0
|
|
@ -45,3 +45,9 @@ position = Vector2(65, 0)
|
|||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="Marker2D"]
|
||||
stream = ExtResource("4_ffr2k")
|
||||
bus = &"SoundEffect"
|
||||
|
||||
[node name="TipLabel" type="Label" parent="."]
|
||||
offset_left = 6.0
|
||||
offset_top = 48.0
|
||||
offset_right = 46.0
|
||||
offset_bottom = 73.0
|
||||
|
|
|
@ -322,26 +322,15 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
}
|
||||
|
||||
|
||||
private bool _mouseEntered;
|
||||
|
||||
public override void _InputEvent(Viewport viewport, InputEvent @event, int shapeIdx)
|
||||
{
|
||||
if (!_mouseEntered)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void _MouseEnter()
|
||||
{
|
||||
_mouseEntered = true;
|
||||
var canCauseHarm = false;
|
||||
if (GameSceneNodeHolder.Player != null)
|
||||
{
|
||||
var targetCamp = CampManager.GetCamp(CampId);
|
||||
var playerCamp = CampManager.GetCamp(GameSceneNodeHolder.Player.CampId);
|
||||
canCauseHarm = CampManager.CanCauseHarm(targetCamp, playerCamp);
|
||||
if (canCauseHarm)
|
||||
if (CampManager.CanCauseHarm(targetCamp, playerCamp))
|
||||
{
|
||||
GameSceneNodeHolder.TemporaryTargetNode = this;
|
||||
}
|
||||
|
@ -350,7 +339,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
if (_tipLabel != null)
|
||||
{
|
||||
_tipLabel.Visible = true;
|
||||
_tipLabel.Text = canCauseHarm + CharacterName;
|
||||
_tipLabel.Text = CharacterName;
|
||||
//Vertical Centering Tip
|
||||
//垂直居中提示
|
||||
var oldPosition = _tipLabel.Position;
|
||||
|
@ -361,7 +350,6 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
|
||||
public override void _MouseExit()
|
||||
{
|
||||
_mouseEntered = false;
|
||||
if (_tipLabel != null)
|
||||
{
|
||||
_tipLabel.Visible = false;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ColdMint.scripts.damage;
|
||||
|
@ -17,8 +16,6 @@ namespace ColdMint.scripts.character;
|
|||
/// </summary>
|
||||
public partial class Player : CharacterTemplate
|
||||
{
|
||||
private Control? _floatLabel;
|
||||
|
||||
//Empty object projectile
|
||||
//空的物品抛射线
|
||||
private readonly Vector2[] _emptyVector2Array = [Vector2.Zero];
|
||||
|
@ -29,10 +26,6 @@ public partial class Player : CharacterTemplate
|
|||
//用于检测玩家是否站在平台上的射线
|
||||
private RayCast2D? _platformDetectionRayCast2D;
|
||||
|
||||
|
||||
private const float PromptTextDistance = 50;
|
||||
|
||||
|
||||
//抛出物品的飞行速度
|
||||
private float _throwingVelocity = Config.CellSize * 13;
|
||||
|
||||
|
@ -50,17 +43,6 @@ public partial class Player : CharacterTemplate
|
|||
CharacterName = TranslationServerUtils.Translate("default_player_name");
|
||||
LogCat.LogWithFormat("player_spawn_debug", LogCat.LogLabel.Default, LogCat.UploadFormat, ReadOnlyCharacterName,
|
||||
GlobalPosition);
|
||||
var floatLabelPackedScene = GD.Load<PackedScene>("res://prefab/ui/FloatLabel.tscn");
|
||||
//Initializes the float label.
|
||||
//初始化悬浮标签。
|
||||
_floatLabel = NodeUtils.InstantiatePackedScene<Control>(floatLabelPackedScene);
|
||||
if (_floatLabel == null)
|
||||
{
|
||||
throw new NullReferenceException(TranslationServer.Translate("float_label_instantiate_failed"));
|
||||
}
|
||||
|
||||
_floatLabel.Hide();
|
||||
NodeUtils.CallDeferredAddChild(this, _floatLabel);
|
||||
_parabola = GetNode<Line2D>("Parabola");
|
||||
_platformDetectionRayCast2D = GetNode<RayCast2D>("PlatformDetectionRayCast");
|
||||
UpdateOperationTip();
|
||||
|
@ -109,6 +91,14 @@ public partial class Player : CharacterTemplate
|
|||
}
|
||||
}
|
||||
|
||||
public override void _MouseEnter()
|
||||
{
|
||||
}
|
||||
|
||||
public override void _MouseExit()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Update operation prompt</para>
|
||||
/// <para>更新操作提示</para>
|
||||
|
@ -243,8 +233,6 @@ public partial class Player : CharacterTemplate
|
|||
{
|
||||
PickingRangeBodiesList?.Remove(pickAbleItem);
|
||||
}
|
||||
|
||||
RecycleFloatLabel();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -430,48 +418,11 @@ public partial class Player : CharacterTemplate
|
|||
return;
|
||||
}
|
||||
|
||||
if (node is not Node2D node2D)
|
||||
if (node is not Node2D)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_floatLabel != null)
|
||||
{
|
||||
if (node is not PickAbleTemplate pickAbleTemplate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (pickAbleTemplate.Picked)
|
||||
{
|
||||
//If the pickables are picked up, the label is not displayed.
|
||||
//如果可拾捡物被捡起了,那么不显示标签。
|
||||
LogCat.LogWarning("pickable_picked_up");
|
||||
return;
|
||||
}
|
||||
|
||||
NodeUtils.CallDeferredReparent(node, _floatLabel);
|
||||
var rotationDegreesNode2D = node2D.RotationDegrees;
|
||||
var rotationDegreesNode2DAbs = Math.Abs(rotationDegreesNode2D);
|
||||
_floatLabel.GlobalPosition = node2D.GlobalPosition;
|
||||
_floatLabel.Position = rotationDegreesNode2DAbs > 90
|
||||
? new Vector2(0, PromptTextDistance)
|
||||
: new Vector2(0, -PromptTextDistance);
|
||||
_floatLabel.RotationDegrees = 0 - rotationDegreesNode2D;
|
||||
var label = _floatLabel.GetNode<Label>("Label");
|
||||
|
||||
var stringBuilder = new StringBuilder();
|
||||
if (pickAbleTemplate.Owner is CharacterTemplate characterTemplate)
|
||||
{
|
||||
stringBuilder.Append(characterTemplate.ReadOnlyCharacterName);
|
||||
stringBuilder.Append(TranslationServerUtils.Translate("de"));
|
||||
}
|
||||
|
||||
stringBuilder.Append(TranslationServerUtils.Translate(pickAbleTemplate.Name));
|
||||
label.Text = stringBuilder.ToString();
|
||||
_floatLabel.Show();
|
||||
}
|
||||
|
||||
UpdateOperationTip();
|
||||
}
|
||||
|
||||
|
@ -483,25 +434,9 @@ public partial class Player : CharacterTemplate
|
|||
return;
|
||||
}
|
||||
|
||||
RecycleFloatLabel();
|
||||
UpdateOperationTip();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Recycle Float Label</para>
|
||||
/// <para>回收悬浮标签</para>
|
||||
/// </summary>
|
||||
private void RecycleFloatLabel()
|
||||
{
|
||||
if (_floatLabel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_floatLabel.Hide();
|
||||
NodeUtils.CallDeferredReparent(this, _floatLabel);
|
||||
}
|
||||
|
||||
protected override void OnHit(DamageTemplate damageTemplate)
|
||||
{
|
||||
base.OnHit(damageTemplate);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.pickable;
|
||||
using ColdMint.scripts.utils;
|
||||
using ColdMint.scripts.weapon;
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.inventory;
|
||||
|
@ -109,7 +111,7 @@ public partial class ItemSlotNode : MarginContainer
|
|||
LogCat.Log("item_container_is_null");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return packsack.ItemContainer.CanAddItem(_item);
|
||||
}
|
||||
|
||||
|
@ -165,6 +167,11 @@ public partial class ItemSlotNode : MarginContainer
|
|||
}
|
||||
|
||||
var duplicate = node2D.Duplicate();
|
||||
if (node2D is PickAbleTemplate pickAbleTemplate)
|
||||
{
|
||||
pickAbleTemplate.CopyAttributes(duplicate);
|
||||
}
|
||||
|
||||
if (duplicate is not Node2D newNode2D)
|
||||
{
|
||||
return null;
|
||||
|
|
|
@ -77,6 +77,8 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
|
|||
public bool Picked { get; set; }
|
||||
|
||||
public int MaxQuantity { get; set; }
|
||||
|
||||
private Label? _tipLabel;
|
||||
|
||||
public virtual void Use(Node2D? owner, Vector2 targetGlobalPosition)
|
||||
{
|
||||
|
@ -87,6 +89,8 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
|
|||
_damageArea2D = GetNode<Area2D>("DamageArea2D");
|
||||
_damageArea2D.BodyEntered += OnBodyEnter;
|
||||
_damageArea2D.BodyExited += OnBodyExited;
|
||||
_tipLabel = GetNodeOrNull<Label>("TipLabel");
|
||||
InputPickable = true;
|
||||
}
|
||||
|
||||
private void OnBodyExited(Node node)
|
||||
|
@ -183,6 +187,35 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
|
|||
}
|
||||
|
||||
|
||||
public override void _MouseEnter()
|
||||
{
|
||||
if (Picked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (_tipLabel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_tipLabel.Visible = true;
|
||||
_tipLabel.Text = Name;
|
||||
//Vertical Centering Tip
|
||||
//垂直居中提示
|
||||
var oldPosition = _tipLabel.Position;
|
||||
oldPosition.X = -_tipLabel.Size.X / 2;
|
||||
_tipLabel.Rotation = -Rotation;
|
||||
_tipLabel.Position = oldPosition;
|
||||
}
|
||||
|
||||
public override void _MouseExit()
|
||||
{
|
||||
if (_tipLabel == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_tipLabel.Visible = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Flip item</para>
|
||||
/// <para>翻转物品</para>
|
||||
|
@ -192,6 +225,20 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Please copy node properties within this function</para>
|
||||
/// <para>请在此函数内复制节点属性</para>
|
||||
/// </summary>
|
||||
/// <param name="node"></param>
|
||||
public void CopyAttributes(Node node)
|
||||
{
|
||||
if (node is not PickAbleTemplate pickAbleTemplate)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pickAbleTemplate.Id = Id;
|
||||
}
|
||||
|
||||
public virtual void Destroy()
|
||||
{
|
||||
QueueFree();
|
||||
|
|
Loading…
Reference in New Issue
Block a user