From a58ddeb039fab655e953f2e31d4e00aa029c41d3 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Tue, 18 Jun 2024 23:37:18 +0800 Subject: [PATCH] =?UTF-8?q?Optimized=20drag=20and=20drop=20of=20items.=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=89=A9=E5=93=81=E7=9A=84=E6=8B=96=E6=8B=BD?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locals/slogan.csv.import | 2 +- scripts/character/CharacterTemplate.cs | 31 ++-- scripts/inventory/ItemSlotNode.cs | 149 +++++++++++++++----- scripts/inventory/UniversalItemContainer.cs | 66 ++++++++- scripts/map/events/ItemStackChangeEvent.cs | 16 +++ 5 files changed, 207 insertions(+), 57 deletions(-) create mode 100644 scripts/map/events/ItemStackChangeEvent.cs diff --git a/locals/slogan.csv.import b/locals/slogan.csv.import index b9d7c86..2ffa9fd 100644 --- a/locals/slogan.csv.import +++ b/locals/slogan.csv.import @@ -2,7 +2,7 @@ importer="csv_translation" type="Translation" -uid="uid://bgfmprv2sm645" +uid="uid://cc0k86apkvut7" [deps] diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index eb61728..90c5c6e 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -1,18 +1,17 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; - using ColdMint.scripts.camp; using ColdMint.scripts.damage; using ColdMint.scripts.debug; using ColdMint.scripts.health; using ColdMint.scripts.inventory; using ColdMint.scripts.item; +using ColdMint.scripts.item.itemStacks; using ColdMint.scripts.utils; using ColdMint.scripts.item.weapon; using ColdMint.scripts.loot; using ColdMint.scripts.pickable; - using Godot; namespace ColdMint.scripts.character; @@ -67,7 +66,9 @@ public partial class CharacterTemplate : CharacterBody2D ///Update finished items ///更新完成后的物品 /// - protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) { } + protected virtual void WhenUpdateCurrentItem(Node2D? currentItem) + { + } //Define a pickup range //定义一个拾起范围 @@ -203,8 +204,8 @@ public partial class CharacterTemplate : CharacterBody2D base._Ready(); PickingRangeBodiesList = new List(); CharacterName = GetMeta("Name", Name).AsString(); - CampId = GetMeta("CampId", Config.CampId.Default).AsString(); - MaxHp = GetMeta("MaxHp", Config.DefaultMaxHp).AsInt32(); + CampId = GetMeta("CampId", Config.CampId.Default).AsString(); + MaxHp = GetMeta("MaxHp", Config.DefaultMaxHp).AsInt32(); // var lootListId = GetMeta("LootListId", string.Empty).AsString(); if (MaxHp <= 0) @@ -275,8 +276,8 @@ public partial class CharacterTemplate : CharacterBody2D //Get the currently selected node //拿到当前选择的节点 - var itemSlotNode = ItemContainer.GetSelectItemSlotNode(); - if (itemSlotNode == null) + var selectItemSlotNode = ItemContainer.GetSelectItemSlotNode(); + if (selectItemSlotNode == null) { return false; } @@ -306,12 +307,14 @@ public partial class CharacterTemplate : CharacterBody2D pickAbleTemplate.Owner = this; pickAbleTemplate.Picked = true; pickAbleTemplate.SetCollisionMaskValue(Config.LayerNumber.Platform, false); - pickAbleTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, false); + pickAbleTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, false); pickAbleTemplate.EnableContactInjury = false; pickAbleTemplate.Sleeping = true; } - if (itemSlotNode.GetItem() != null && itemSlotNode.GetItem() == item && _currentItem == null) + var itemStack = selectItemSlotNode.GetItemStack(); + var itemFromStack = itemStack?.GetItem(); + if (itemFromStack != null && itemFromStack == item && _currentItem == null) { //If the selected item slot in the item container is a newly picked item, and there is no item in the hand, then we put the selected item into the hand. //如果物品容器内选中的物品槽是刚刚捡到的物品,且手里没有物品持有,那么我们将选中的物品放到手上。 @@ -466,8 +469,8 @@ public partial class CharacterTemplate : CharacterBody2D /// /// public void GenerateLootObjects(Node parentNode, - IEnumerable lootData, - Vector2 position) + IEnumerable lootData, + Vector2 position) { foreach (var lootDatum in lootData) { @@ -486,7 +489,9 @@ public partial class CharacterTemplate : CharacterBody2D _additionalForce = force; } - protected virtual void OnHit(DamageTemplate damageTemplate) { } + protected virtual void OnHit(DamageTemplate damageTemplate) + { + } /// /// Handle the event of character death @@ -669,7 +674,7 @@ public partial class CharacterTemplate : CharacterBody2D //We cannot immediately resume the physical collision when the weapon is discharged, which will cause the weapon to collide with the ground and platform earlier, preventing the weapon from flying. //仍出武器时,我们不能立即恢复物理碰撞,立即恢复会导致武器更早的与地面和平台碰撞,阻止武器的飞行。 pickAbleTemplate.EnableContactInjury = true; - pickAbleTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, true); + pickAbleTemplate.SetCollisionMaskValue(Config.LayerNumber.Ground, true); pickAbleTemplate.SetCollisionMaskValue(Config.LayerNumber.Platform, true); timer.QueueFree(); }; diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index 87ae9a8..1ada763 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -1,6 +1,7 @@ -using ColdMint.scripts.debug; +using System; using ColdMint.scripts.item; using ColdMint.scripts.item.itemStacks; +using ColdMint.scripts.map.events; using ColdMint.scripts.utils; using Godot; @@ -20,12 +21,27 @@ public partial class ItemSlotNode : MarginContainer private bool _isSelect; private Texture2D? _backgroundTexture; private Texture2D? _backgroundTextureWhenSelect; + public Action? ItemStackChangeEvent; + + public override void _Ready() + { + _backgroundTexture = GD.Load("res://sprites/ui/ItemBarEmpty.png"); + _backgroundTextureWhenSelect = GD.Load("res://sprites/ui/ItemBarFocus.png"); + _backgroundTextureRect = + GetNode("BackgroundTexture"); + _iconTextureRect = GetNode("BackgroundTexture/IconTextureRect"); + _quantityLabel = GetNode