From c2e84783e8434360e26d39bba65ce99b6ffb9a82 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Thu, 10 Oct 2024 14:11:34 +0800 Subject: [PATCH] =?UTF-8?q?The=20player=20will=20no=20longer=20always=20us?= =?UTF-8?q?e=20items=20when=20interacting=20with=20the=20UI=20or=20furnitu?= =?UTF-8?q?re.=20=E5=BD=93=E7=8E=A9=E5=AE=B6=E4=B8=8EUI=E6=88=96=E5=AE=B6?= =?UTF-8?q?=E5=85=B7=E4=BA=A4=E4=BA=92=E6=97=B6=E4=B8=8D=E5=86=8D=E4=B8=80?= =?UTF-8?q?=E7=9B=B4=E4=BD=BF=E7=94=A8=E6=8C=81=E6=9C=89=E7=9A=84=E7=89=A9?= =?UTF-8?q?=E5=93=81=E4=BA=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/GameSceneDepend.cs | 14 ++++++++++++++ scripts/character/Player.cs | 16 +++++++++++++--- scripts/furniture/GuiFurniture.cs | 2 ++ scripts/inventory/ItemSlotNode.cs | 22 ++++++++++++++++++++++ 4 files changed, 51 insertions(+), 3 deletions(-) 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)