Remove the drag and drop item code.
移除拖拽物品的代码。
This commit is contained in:
parent
b9a9349596
commit
b53f5bc2df
|
@ -51,12 +51,7 @@ log_patrol_to_next_point,下一个点{0},当前位置{1},偏移量{2},距
|
|||
log_patrol_arrival_point,到达巡逻点{0}。,Arrival at patrol point {0}.,巡回ポイント{0}に到着します。
|
||||
log_patrol_origin_position,巡逻路径的起始位置是{0}。,The starting position of the patrol path is {0}.,巡回路の開始位置は{0}です。
|
||||
log_patrol_not_on_floor,不能将初始路径设置在空中。,The initial path cannot be set in the air.,初期パスを空中に設定できません。
|
||||
log_item_container_is_null,物品容器为空。,Item container is null.,アイテム・コンテナが空です。
|
||||
log_can_add_item,可以添加物品{0}。,Can add item {0}.,アイテム{0}を追加できます。
|
||||
log_backpack_not_allowed,不允许添加到背包。,Not allowed to add to backpack.,バックパックに追加することは許可されていません。
|
||||
log_item_is_null,物品为空。,Item is null.,アイテムが空です。
|
||||
log_item_id_not_same,物品ID不同。,Item ID is different.,アイテムIDが異なります。
|
||||
log_max_quantity_exceeded,超过最大数量。,Exceeded maximum quantity.,最大数量を超えました。
|
||||
log_patrol_enemy_detected,检测到敌人。,Enemy detected.,敵を検出しました。
|
||||
log_attacker_or_target_is_null,攻击者或目标为空。,Attacker or target is null.,攻撃者またはターゲットが空です。
|
||||
log_in_the_same_camp,在同一阵营。,In the same camp.,同じ陣営です。
|
||||
|
|
|
|
@ -19,6 +19,12 @@ public interface IItemDisplay
|
|||
/// </remarks>
|
||||
void Update(IItem? item);
|
||||
|
||||
/// <summary>
|
||||
/// <para>Gets the item that is being displayed</para>
|
||||
/// <para>获取正在显示的物品</para>
|
||||
/// </summary>
|
||||
IItem? Item { get; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Show item Display</para>
|
||||
/// <para>显示物品显示器</para>
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.utils;
|
||||
using Godot;
|
||||
|
||||
|
@ -16,7 +15,8 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
|||
private Control? _control;
|
||||
private Texture2D? _backgroundTexture;
|
||||
private Texture2D? _backgroundTextureWhenSelect;
|
||||
private IItem? _item;
|
||||
public IItem? Item { get; private set; }
|
||||
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
@ -47,83 +47,19 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
|||
|
||||
public override bool _CanDropData(Vector2 atPosition, Variant data)
|
||||
{
|
||||
//If the preplaced slot does not have an icon, the preplaced slot is not allowed.
|
||||
//如果预放置的槽位没有图标,那么不允许放置。
|
||||
if (_iconTextureRect == null)
|
||||
if (Item == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var type = data.VariantType;
|
||||
if (type == Variant.Type.Nil)
|
||||
if (Item is PlaceholderItem)
|
||||
{
|
||||
//The preplaced data is null.
|
||||
//预放置的数据为null。
|
||||
return false;
|
||||
}
|
||||
|
||||
var itemSlotNode = data.As<ItemSlotNode>();
|
||||
var item = itemSlotNode.GetItem();
|
||||
if (item == null)
|
||||
{
|
||||
//Return null when trying to get the source item.
|
||||
//尝试获取源物品时返回null。
|
||||
return false;
|
||||
}
|
||||
|
||||
if (item is Packsack packsack)
|
||||
{
|
||||
if (_item == null)
|
||||
{
|
||||
//If the dragged item is a backpack and there are no items in the current slot, return whether the backpack is allowed.
|
||||
//如果拖拽的物品是背包,且当前槽位没有物品,那么返回是否允许放置背包。
|
||||
return BackpackAllowed;
|
||||
}
|
||||
|
||||
if (packsack.ItemContainer == null)
|
||||
{
|
||||
LogCat.Log("item_container_is_null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return packsack.ItemContainer.CanAddItem(_item);
|
||||
}
|
||||
|
||||
if (_item is Packsack currentPacksack)
|
||||
{
|
||||
if (currentPacksack.ItemContainer == null)
|
||||
{
|
||||
LogCat.Log("item_container_is_null");
|
||||
return false;
|
||||
}
|
||||
|
||||
return currentPacksack.ItemContainer.CanAddItem(item);
|
||||
}
|
||||
|
||||
return CanAddItem(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Get the items in the item container</para>
|
||||
/// <para>获取物品容器内的物品</para>
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
///<para>There may be multiple quantities</para>
|
||||
///<para>数量可能有多个</para>
|
||||
/// </returns>
|
||||
public IItem? GetItem()
|
||||
{
|
||||
return _item;
|
||||
}
|
||||
|
||||
|
||||
public override void _DropData(Vector2 atPosition, Variant data)
|
||||
{
|
||||
if (_iconTextureRect == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var type = data.VariantType;
|
||||
if (type == Variant.Type.Nil)
|
||||
{
|
||||
|
@ -131,42 +67,14 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
|||
//传入的变量为null。
|
||||
return;
|
||||
}
|
||||
|
||||
var itemSlotNode = data.As<ItemSlotNode>();
|
||||
var sourceItem = itemSlotNode.GetItem();
|
||||
var sourceItem = itemSlotNode.Item;
|
||||
if (sourceItem == null)
|
||||
{
|
||||
//Return null when trying to get the source item.
|
||||
//尝试获取源物品时返回null。
|
||||
return;
|
||||
}
|
||||
|
||||
if (sourceItem is Packsack packsack)
|
||||
{
|
||||
//If the source item is a backpack.
|
||||
//如果源物品是背包。
|
||||
if (packsack.ItemContainer != null && _item != null)
|
||||
{
|
||||
packsack.ItemContainer.AddItem(_item);
|
||||
// ClearItem(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (_item is Packsack customPacksack)
|
||||
{
|
||||
if (customPacksack.ItemContainer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
customPacksack.ItemContainer.AddItem(sourceItem);
|
||||
// itemSlotNode.ClearItem(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// AddItem(sourceItem);
|
||||
// itemSlotNode.ClearItem(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -206,7 +114,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
|||
/// </summary>
|
||||
private void UpdateTooltipText()
|
||||
{
|
||||
if (_item == null)
|
||||
if (Item == null)
|
||||
{
|
||||
TooltipText = null;
|
||||
return;
|
||||
|
@ -217,16 +125,16 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
|||
var debugText = TranslationServerUtils.Translate("item_prompt_debug");
|
||||
if (debugText != null)
|
||||
{
|
||||
TooltipText = string.Format(debugText, _item.Id,
|
||||
TranslationServerUtils.Translate(_item.Name),
|
||||
_item.Quantity, _item.MaxQuantity, _item.GetType().Name,
|
||||
TranslationServerUtils.Translate(_item.Description));
|
||||
TooltipText = string.Format(debugText, Item.Id,
|
||||
TranslationServerUtils.Translate(Item.Name),
|
||||
Item.Quantity, Item.MaxQuantity, Item.GetType().Name,
|
||||
TranslationServerUtils.Translate(Item.Description));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TooltipText = TranslationServerUtils.Translate(_item.Name) + "\n" +
|
||||
TranslationServerUtils.Translate(_item.Description);
|
||||
TooltipText = TranslationServerUtils.Translate(Item.Name) + "\n" +
|
||||
TranslationServerUtils.Translate(Item.Description);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -241,7 +149,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
|||
return;
|
||||
}
|
||||
|
||||
switch (_item?.Quantity)
|
||||
switch (Item?.Quantity)
|
||||
{
|
||||
case null or 1:
|
||||
_quantityLabel.Hide();
|
||||
|
@ -249,7 +157,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
|||
default:
|
||||
//When the quantity is not null or 1, we display the quantity.
|
||||
//当数量不为null或1时,我们显示数量
|
||||
_quantityLabel.Text = _item?.Quantity.ToString();
|
||||
_quantityLabel.Text = Item?.Quantity.ToString();
|
||||
_quantityLabel.Show();
|
||||
break;
|
||||
}
|
||||
|
@ -264,53 +172,15 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
|||
{
|
||||
if (_iconTextureRect != null)
|
||||
{
|
||||
_iconTextureRect.Texture = _item?.Icon;
|
||||
_iconTextureRect.Texture = Item?.Icon;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanAddItem(IItem item)
|
||||
{
|
||||
if (!BackpackAllowed && item is Packsack)
|
||||
{
|
||||
//如果禁止放置背包,且新物品是背包
|
||||
LogCat.Log("backpack_not_allowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_item == null)
|
||||
{
|
||||
//If there is no item in the current item slot, it is allowed to add.
|
||||
//如果当前物品槽内没物品,那么允许添加。
|
||||
LogCat.Log("item_is_null");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.Id != _item.Id)
|
||||
{
|
||||
//If the item ID you want to add is different from the current item ID, disable.
|
||||
//如果要添加的物品ID和当前的物品ID不一样,那么禁止。
|
||||
LogCat.Log("item_id_not_same");
|
||||
return false;
|
||||
}
|
||||
|
||||
var newQuantity = item.Quantity + _item.Quantity;
|
||||
if (newQuantity > _item.MaxQuantity)
|
||||
{
|
||||
//The maximum number is exceeded and items cannot be added.
|
||||
//超过了最大数量,无法添加物品。
|
||||
LogCat.Log("max_quantity_exceeded");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void Update(IItem? item)
|
||||
{
|
||||
if (item is not PlaceholderItem)
|
||||
{
|
||||
_item = item;
|
||||
Item = item;
|
||||
UpdateAllDisplay();
|
||||
}
|
||||
UpdateBackground(item is { IsSelect: true });
|
||||
|
|
Loading…
Reference in New Issue
Block a user