The player will no longer always use items when interacting with the UI or furniture.

当玩家与UI或家具交互时不再一直使用持有的物品了。
This commit is contained in:
Cold-Mint 2024-10-10 14:11:34 +08:00
parent f3c46f2668
commit c2e84783e8
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
4 changed files with 51 additions and 3 deletions

View File

@ -113,4 +113,18 @@ public static class GameSceneDepend
///<para>动态生成的Ui对象将放置在此节点下</para> ///<para>动态生成的Ui对象将放置在此节点下</para>
/// </remarks> /// </remarks>
public static UiGroup? DynamicUiGroup { get; set; } public static UiGroup? DynamicUiGroup { get; set; }
/// <summary>
/// <para>Whether the player's mouse is hovering over GUI furniture</para>
/// <para>玩家的鼠标是否悬浮在GUI家具上</para>
/// </summary>
public static bool IsMouseOverFurnitureGui;
/// <summary>
/// <para>Whether the mouse is suspended over the item slot</para>
/// <para>鼠标是否悬浮在物品槽上</para>
/// </summary>
public static bool IsMouseOverItemSlotNode;
} }

View File

@ -31,6 +31,8 @@ public partial class Player : CharacterTemplate
//射线是否与平台碰撞 //射线是否与平台碰撞
private bool _collidingWithPlatform; private bool _collidingWithPlatform;
private bool _canUseItem;
//How long does it take for the character to recover from a collision with the platform after jumping off the platform (in seconds) //How long does it take for the character to recover from a collision with the platform after jumping off the platform (in seconds)
//角色从平台上跳下后,多少时间后恢复与平台的碰撞(单位:秒) //角色从平台上跳下后,多少时间后恢复与平台的碰撞(单位:秒)
private double _platformCollisionRecoveryTime = 0.2f; private double _platformCollisionRecoveryTime = 0.2f;
@ -124,12 +126,20 @@ public partial class Player : CharacterTemplate
var axis = Input.GetAxis("ui_left", "ui_right"); var axis = Input.GetAxis("ui_left", "ui_right");
velocity.X = axis * Speed * Config.CellSize * ProtectedSpeedScale; velocity.X = axis * Speed * Config.CellSize * ProtectedSpeedScale;
if (Input.IsActionJustPressed("use_item"))
{
_canUseItem = !GameSceneDepend.IsMouseOverFurnitureGui && !GameSceneDepend.IsMouseOverItemSlotNode;
}
//Use items //Use items
//使用物品 //使用物品
if (Input.IsActionPressed("use_item")) if (Input.IsActionPressed("use_item"))
{
if (_canUseItem)
{ {
UseItem(GetGlobalMousePosition()); UseItem(GetGlobalMousePosition());
} }
}
//Pick up an item //Pick up an item
//捡起物品 //捡起物品
if (Input.IsActionJustPressed("pick_up")) if (Input.IsActionJustPressed("pick_up"))

View File

@ -70,12 +70,14 @@ public partial class GuiFurniture : Furniture
{ {
base._MouseEnter(); base._MouseEnter();
_hasMouseOver = true; _hasMouseOver = true;
GameSceneDepend.IsMouseOverFurnitureGui = true;
} }
public override void _MouseExit() public override void _MouseExit()
{ {
base._MouseExit(); base._MouseExit();
_hasMouseOver = false; _hasMouseOver = false;
GameSceneDepend.IsMouseOverFurnitureGui = false;
} }
private void OnBodyEntered(Node node) private void OnBodyEntered(Node node)

View File

@ -30,6 +30,28 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
_quantityLabel.Hide(); _quantityLabel.Hide();
} }
public override void _EnterTree()
{
MouseEntered += OnMouseEntered;
MouseExited += OnMouseExited;
}
public override void _ExitTree()
{
MouseEntered -= OnMouseEntered;
MouseExited -= OnMouseExited;
}
private void OnMouseExited()
{
GameSceneDepend.IsMouseOverItemSlotNode = false;
}
private void OnMouseEntered()
{
GameSceneDepend.IsMouseOverItemSlotNode = true;
}
public override Variant _GetDragData(Vector2 atPosition) public override Variant _GetDragData(Vector2 atPosition)
{ {
switch (Item) switch (Item)