The player will no longer always use items when interacting with the UI or furniture.
当玩家与UI或家具交互时不再一直使用持有的物品了。
This commit is contained in:
parent
f3c46f2668
commit
c2e84783e8
|
@ -113,4 +113,18 @@ public static class GameSceneDepend
|
|||
///<para>动态生成的Ui对象将放置在此节点下</para>
|
||||
/// </remarks>
|
||||
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;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <para>当玩家手动抛出物品时,施加到物品上的速度值</para>
|
||||
/// </summary>
|
||||
|
@ -312,7 +322,7 @@ public partial class Player : CharacterTemplate
|
|||
|
||||
EventBus.GameOverEvent.Invoke(gameOverEvent);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override void OnHit(DamageTemplate damageTemplate)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user