diff --git a/scripts/GameSceneDepend.cs b/scripts/GameSceneDepend.cs
index 722fb28..0480a7d 100644
--- a/scripts/GameSceneDepend.cs
+++ b/scripts/GameSceneDepend.cs
@@ -113,4 +113,18 @@ public static class GameSceneDepend
///动态生成的Ui对象将放置在此节点下
///
public static UiGroup? DynamicUiGroup { get; set; }
+
+
+ ///
+ /// Whether the player's mouse is hovering over GUI furniture
+ /// 玩家的鼠标是否悬浮在GUI家具上
+ ///
+ public static bool IsMouseOverFurnitureGui;
+
+
+ ///
+ /// Whether the mouse is suspended over the item slot
+ /// 鼠标是否悬浮在物品槽上
+ ///
+ public static bool IsMouseOverItemSlotNode;
}
\ No newline at end of file
diff --git a/scripts/character/Player.cs b/scripts/character/Player.cs
index 08bd2c3..3c881d6 100644
--- a/scripts/character/Player.cs
+++ b/scripts/character/Player.cs
@@ -31,6 +31,8 @@ public partial class Player : CharacterTemplate
//射线是否与平台碰撞
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)
//角色从平台上跳下后,多少时间后恢复与平台的碰撞(单位:秒)
private double _platformCollisionRecoveryTime = 0.2f;
@@ -124,11 +126,19 @@ public partial class Player : CharacterTemplate
var axis = Input.GetAxis("ui_left", "ui_right");
velocity.X = axis * Speed * Config.CellSize * ProtectedSpeedScale;
+
+ if (Input.IsActionJustPressed("use_item"))
+ {
+ _canUseItem = !GameSceneDepend.IsMouseOverFurnitureGui && !GameSceneDepend.IsMouseOverItemSlotNode;
+ }
//Use items
//使用物品
if (Input.IsActionPressed("use_item"))
{
- UseItem(GetGlobalMousePosition());
+ if (_canUseItem)
+ {
+ UseItem(GetGlobalMousePosition());
+ }
}
//Pick up an item
//捡起物品
@@ -206,7 +216,7 @@ public partial class Player : CharacterTemplate
CurrentItem = null;
}
}
-
+
///
/// 当玩家手动抛出物品时,施加到物品上的速度值
///
@@ -312,7 +322,7 @@ public partial class Player : CharacterTemplate
EventBus.GameOverEvent.Invoke(gameOverEvent);
}
-
+
protected override void OnHit(DamageTemplate damageTemplate)
{
diff --git a/scripts/furniture/GuiFurniture.cs b/scripts/furniture/GuiFurniture.cs
index 031739a..3fed73e 100644
--- a/scripts/furniture/GuiFurniture.cs
+++ b/scripts/furniture/GuiFurniture.cs
@@ -70,12 +70,14 @@ public partial class GuiFurniture : Furniture
{
base._MouseEnter();
_hasMouseOver = true;
+ GameSceneDepend.IsMouseOverFurnitureGui = true;
}
public override void _MouseExit()
{
base._MouseExit();
_hasMouseOver = false;
+ GameSceneDepend.IsMouseOverFurnitureGui = false;
}
private void OnBodyEntered(Node node)
diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs
index 281e651..46ba678 100644
--- a/scripts/inventory/ItemSlotNode.cs
+++ b/scripts/inventory/ItemSlotNode.cs
@@ -30,6 +30,28 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
_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)
{
switch (Item)