Fixes pickups flying out of walls, supports pushing furniture by pressing f.

修复可拾捡物飞出墙壁,支持按下f键推动家具。
This commit is contained in:
Cold-Mint 2024-09-18 21:28:54 +08:00
parent cb19423cb0
commit 899337e8e3
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
4 changed files with 28 additions and 1 deletions

View File

@ -147,6 +147,11 @@ hotbar_previous={
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":4,"axis_value":1.0,"script":null)
]
}
push={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":70,"physical_keycode":0,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
]
}
[internationalization]

View File

@ -230,6 +230,8 @@ public partial class Player : CharacterTemplate
UseItem(GetGlobalMousePosition());
}
//Pick up an item
//捡起物品
if (Input.IsActionJustPressed("pick_up"))

View File

@ -36,6 +36,19 @@ public partial class Furniture : RigidBody2D
SetCollisionMaskValue(Config.LayerNumber.Floor, true);
}
public override void _PhysicsProcess(double delta)
{
if (Input.IsActionJustReleased("push"))
{
SetCollisionMaskValue(Config.LayerNumber.Player, false);
}
if (Input.IsActionJustPressed("push"))
{
SetCollisionMaskValue(Config.LayerNumber.Player, true);
}
}
/// <summary>
/// <para>This method is called when furniture is damaged</para>
/// <para>当家具损害时调用此方法</para>

View File

@ -77,7 +77,7 @@ 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)
@ -91,6 +91,9 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
_damageArea2D.BodyExited += OnBodyExited;
_tipLabel = GetNodeOrNull<Label>("TipLabel");
InputPickable = true;
SetCollisionMaskValue(Config.LayerNumber.Wall, true);
SetCollisionMaskValue(Config.LayerNumber.Platform, true);
SetCollisionMaskValue(Config.LayerNumber.Floor, true);
}
private void OnBodyExited(Node node)
@ -193,10 +196,12 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
{
return;
}
if (_tipLabel == null)
{
return;
}
_tipLabel.Visible = true;
_tipLabel.Text = Name;
//Vertical Centering Tip
@ -213,6 +218,7 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
{
return;
}
_tipLabel.Visible = false;
}
@ -236,6 +242,7 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
{
return;
}
pickAbleTemplate.Id = Id;
}