Fixed an issue where Hotbar did not select item A by default, from slot 1 to slot 2, and then from slot 2.
解决Hotbar没有默认选中,将物品A从槽1放到槽2,再从槽2取出时报错的问题。
This commit is contained in:
parent
1b440b828f
commit
2dd5525adf
|
@ -2,6 +2,10 @@
|
||||||
scene_path: res://prefab/weapons/staffOfTheUndead.tscn
|
scene_path: res://prefab/weapons/staffOfTheUndead.tscn
|
||||||
icon_path: res://sprites/weapon/staffOfTheUndead_icon.png
|
icon_path: res://sprites/weapon/staffOfTheUndead_icon.png
|
||||||
max_stack_value: 1
|
max_stack_value: 1
|
||||||
|
custom_args:
|
||||||
|
- name: UniqueName
|
||||||
|
type: string
|
||||||
|
value: 爱你!
|
||||||
|
|
||||||
- id: degraded_staff_of_the_undead
|
- id: degraded_staff_of_the_undead
|
||||||
scene_path: res://prefab/weapons/staffOfTheUndead.tscn
|
scene_path: res://prefab/weapons/staffOfTheUndead.tscn
|
||||||
|
|
|
@ -6,10 +6,10 @@ uid="uid://dl2r1rydlm7pa"
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
|
|
||||||
files=["res://locals/slogan.zh.translation", "res://locals/slogan.en.translation", "res://locals/slogan.ja.translation"]
|
files=["res://locals/Slogan.zh.translation", "res://locals/Slogan.en.translation", "res://locals/Slogan.ja.translation"]
|
||||||
|
|
||||||
source_file="res://locals/slogan.csv"
|
source_file="res://locals/Slogan.csv"
|
||||||
dest_files=["res://locals/slogan.zh.translation", "res://locals/slogan.en.translation", "res://locals/slogan.ja.translation"]
|
dest_files=["res://locals/Slogan.zh.translation", "res://locals/Slogan.en.translation", "res://locals/Slogan.ja.translation"]
|
||||||
|
|
||||||
[params]
|
[params]
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
_quantityLabel = GetNode<Label>("Control/QuantityLabel");
|
_quantityLabel = GetNode<Label>("Control/QuantityLabel");
|
||||||
_control = GetNode<Control>("Control");
|
_control = GetNode<Control>("Control");
|
||||||
_quantityLabel.Hide();
|
_quantityLabel.Hide();
|
||||||
|
UpdateBackground(_isSelect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Variant _GetDragData(Vector2 atPosition)
|
public override Variant _GetDragData(Vector2 atPosition)
|
||||||
|
@ -106,8 +107,8 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
/// <para>创建物品槽内的物品实例</para>
|
/// <para>创建物品槽内的物品实例</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="number">
|
/// <param name="number">
|
||||||
///<para>number</para>
|
///<para>Quantity (pass in a value less than 0 to create an instance using all the quantities of built-in items)</para>
|
||||||
///<para>数量</para>
|
///<para>数量(传入小于0的值,使用内置物品的所有数量创建实例)</para>
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
///<para>Newly created item</para>
|
///<para>Newly created item</para>
|
||||||
|
@ -115,6 +116,11 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
/// </returns>
|
/// </returns>
|
||||||
public IItem? CreateItemInstance(int number)
|
public IItem? CreateItemInstance(int number)
|
||||||
{
|
{
|
||||||
|
if (number == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (_item is not Node2D node2D)
|
if (_item is not Node2D node2D)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -132,30 +138,38 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (number > _item.Quantity)
|
if (number < 0)
|
||||||
{
|
{
|
||||||
//The number of item instances created exceeds the current number of items
|
newItem.Quantity = _item.Quantity;
|
||||||
//创建的物品实例数量,超过了当前物品的数量
|
}
|
||||||
duplicate.QueueFree();
|
else
|
||||||
return null;
|
{
|
||||||
|
newItem.Quantity = number >= _item.Quantity ? _item.Quantity : number;
|
||||||
}
|
}
|
||||||
|
|
||||||
newItem.Quantity = number;
|
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Empty the inventory</para>
|
/// <para>Clean out the items in the item slot</para>
|
||||||
/// <para>清空物品栏内的物品</para>
|
/// <para>清理物品槽内的物品</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void ClearItem()
|
/// <param name="queueFree">
|
||||||
|
///<para>Whether to release a node</para>
|
||||||
|
///<para>是否释放节点</para>
|
||||||
|
/// </param>
|
||||||
|
/// <remarks>
|
||||||
|
///<para>Clean up item object references in item slots.</para>
|
||||||
|
///<para>清理物品槽内的物品对象引用。</para>
|
||||||
|
/// </remarks>
|
||||||
|
public void ClearItem(bool queueFree = true)
|
||||||
{
|
{
|
||||||
if (_item == null)
|
if (_item == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_item is Node node)
|
if (queueFree && _item is Node node)
|
||||||
{
|
{
|
||||||
node.QueueFree();
|
node.QueueFree();
|
||||||
}
|
}
|
||||||
|
@ -180,7 +194,7 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
var itemSlotNode = data.As<ItemSlotNode>();
|
var itemSlotNode = data.As<ItemSlotNode>();
|
||||||
var item = itemSlotNode._item;
|
var item = itemSlotNode.GetItem();
|
||||||
if (item == null)
|
if (item == null)
|
||||||
{
|
{
|
||||||
//Return null when trying to get the source item.
|
//Return null when trying to get the source item.
|
||||||
|
@ -188,7 +202,7 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
itemSlotNode.ClearItem();
|
itemSlotNode.ClearItem(false);
|
||||||
AddItem(item);
|
AddItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,15 +217,21 @@ public partial class ItemSlotNode : MarginContainer
|
||||||
get => _isSelect;
|
get => _isSelect;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (_backgroundTextureRect != null)
|
UpdateBackground(value);
|
||||||
{
|
|
||||||
_backgroundTextureRect.Texture = value ? _backgroundTextureWhenSelect : _backgroundTexture;
|
|
||||||
}
|
|
||||||
|
|
||||||
_isSelect = value;
|
_isSelect = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateBackground(bool isSelect)
|
||||||
|
{
|
||||||
|
if (_backgroundTextureRect == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_backgroundTextureRect.Texture = isSelect ? _backgroundTextureWhenSelect : _backgroundTexture;
|
||||||
|
}
|
||||||
|
|
||||||
public TextureRect? BackgroundTextureRect => _backgroundTextureRect;
|
public TextureRect? BackgroundTextureRect => _backgroundTextureRect;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user