Backpack Ui will not prevent clicking the button below anymore.

背包Ui不会阻止点击下面的按钮了。
This commit is contained in:
Cold-Mint 2024-06-17 22:12:51 +08:00
parent 8391396191
commit c1f0e30671
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
10 changed files with 90 additions and 54 deletions

View File

@ -13,7 +13,10 @@ size = Vector2(21, 29)
collision_layer = 8 collision_layer = 8
collision_mask = 38 collision_mask = 38
script = ExtResource("1_slakl") script = ExtResource("1_slakl")
NumberSlots = 30
Id = "packsack" Id = "packsack"
UniqueName = null
UniqueDescription = null
_minContactInjury = null _minContactInjury = null
_maxContactInjury = null _maxContactInjury = null

View File

@ -7,6 +7,7 @@
offset_right = 38.0 offset_right = 38.0
offset_bottom = 38.0 offset_bottom = 38.0
size_flags_vertical = 3 size_flags_vertical = 3
mouse_filter = 0
theme_override_constants/margin_left = 3 theme_override_constants/margin_left = 3
theme_override_constants/margin_top = 3 theme_override_constants/margin_top = 3
theme_override_constants/margin_right = 3 theme_override_constants/margin_right = 3
@ -15,6 +16,7 @@ script = ExtResource("1_fbwot")
[node name="BackgroundTexture" type="TextureRect" parent="."] [node name="BackgroundTexture" type="TextureRect" parent="."]
layout_mode = 2 layout_mode = 2
mouse_filter = 2
texture = ExtResource("1_y2wyt") texture = ExtResource("1_y2wyt")
[node name="IconTextureRect" type="TextureRect" parent="BackgroundTexture"] [node name="IconTextureRect" type="TextureRect" parent="BackgroundTexture"]
@ -28,10 +30,12 @@ offset_right = -3.0
offset_bottom = -3.0 offset_bottom = -3.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
mouse_filter = 2
expand_mode = 1 expand_mode = 1
[node name="Control" type="Control" parent="."] [node name="Control" type="Control" parent="."]
layout_mode = 2 layout_mode = 2
mouse_filter = 2
[node name="QuantityLabel" type="Label" parent="Control"] [node name="QuantityLabel" type="Label" parent="Control"]
layout_mode = 1 layout_mode = 1

View File

@ -9,46 +9,37 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
mouse_filter = 2
script = ExtResource("1_wm4bu") script = ExtResource("1_wm4bu")
[node name="ColorRect" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.294118)
[node name="TitleLabel" type="Label" parent="."] [node name="TitleLabel" type="Label" parent="."]
layout_mode = 1 layout_mode = 1
anchors_preset = 10 anchors_preset = 10
anchor_right = 1.0 anchor_right = 1.0
offset_bottom = 30.0 offset_bottom = 25.0
grow_horizontal = 2 grow_horizontal = 2
text = "ui_name" text = "ui_name"
horizontal_alignment = 1 horizontal_alignment = 1
[node name="GridContainer" type="GridContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 36.0
offset_top = 57.0
offset_right = -34.0
offset_bottom = -23.0
grow_horizontal = 2
grow_vertical = 2
[node name="ExitButton" type="Button" parent="."] [node name="ExitButton" type="Button" parent="."]
layout_mode = 1 layout_mode = 1
anchors_preset = 1 anchors_preset = 1
anchor_left = 1.0 anchor_left = 1.0
anchor_right = 1.0 anchor_right = 1.0
offset_left = -75.0 offset_left = -91.0
offset_top = 8.0 offset_top = 11.0
offset_right = -8.0 offset_right = -24.0
offset_bottom = 41.0 offset_bottom = 44.0
grow_horizontal = 0 grow_horizontal = 0
text = "ui_close" text = "ui_close"
[node name="HFlowContainer" type="HFlowContainer" parent="."]
layout_mode = 1
anchors_preset = 10
anchor_right = 1.0
offset_left = 26.0
offset_top = 70.0
offset_right = -29.0
offset_bottom = 389.0
grow_horizontal = 2
mouse_filter = 2

View File

@ -91,6 +91,7 @@ anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
grow_horizontal = 2 grow_horizontal = 2
grow_vertical = 2 grow_vertical = 2
mouse_filter = 2
[node name="GameOverMenu" parent="CanvasLayer" instance=ExtResource("6_yjmrv")] [node name="GameOverMenu" parent="CanvasLayer" instance=ExtResource("6_yjmrv")]
visible = false visible = false

View File

@ -219,7 +219,7 @@ public interface IItemContainer : IEnumerable<ItemSlotNode>
/// <para>添加物品槽</para> /// <para>添加物品槽</para>
/// </summary> /// </summary>
/// <param name="rootNode"></param> /// <param name="rootNode"></param>
void AddItemSlot(Node rootNode); ItemSlotNode? AddItemSlot(Node rootNode);
/// <summary> /// <summary>
/// <para>SelectTheNextItemSlot</para> /// <para>SelectTheNextItemSlot</para>

View File

@ -1,7 +1,7 @@
using ColdMint.scripts.debug;
using ColdMint.scripts.item; using ColdMint.scripts.item;
using ColdMint.scripts.item.itemStacks; using ColdMint.scripts.item.itemStacks;
using ColdMint.scripts.utils; using ColdMint.scripts.utils;
using Godot; using Godot;
namespace ColdMint.scripts.inventory; namespace ColdMint.scripts.inventory;
@ -21,6 +21,34 @@ public partial class ItemSlotNode : MarginContainer
private Texture2D? _backgroundTexture; private Texture2D? _backgroundTexture;
private Texture2D? _backgroundTextureWhenSelect; private Texture2D? _backgroundTextureWhenSelect;
public override Variant _GetDragData(Vector2 atPosition)
{
if (_iconTextureRect == null)
{
return base._GetDragData(atPosition);
}
var textureRect = new TextureRect();
textureRect.ExpandMode = _iconTextureRect.ExpandMode;
textureRect.Size = _iconTextureRect.Size;
textureRect.Texture = _iconTextureRect.Texture;
SetDragPreview(textureRect);
return Variant.From(this);
}
public override bool _CanDropData(Vector2 atPosition, Variant data)
{
if (_iconTextureRect == null)
{
return false;
}
//TODO:在这里判断是否可以放置物品。物品槽必须是空的。
// var itemSlotNode = data.As<ItemSlotNode>();
// itemSlotNode._itemStack
return true;
}
public bool IsSelect public bool IsSelect
{ {
get => _isSelect; get => _isSelect;

View File

@ -2,14 +2,11 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ColdMint.scripts.character; using ColdMint.scripts.character;
using ColdMint.scripts.item; using ColdMint.scripts.item;
using ColdMint.scripts.item.itemStacks; using ColdMint.scripts.item.itemStacks;
using ColdMint.scripts.utils; using ColdMint.scripts.utils;
using Godot; using Godot;
using JetBrains.Annotations; using JetBrains.Annotations;
namespace ColdMint.scripts.inventory; namespace ColdMint.scripts.inventory;
@ -222,21 +219,22 @@ public class UniversalItemContainer : IItemContainer
/// <para>Add items tank</para> /// <para>Add items tank</para>
/// <para>添加物品槽</para> /// <para>添加物品槽</para>
/// </summary> /// </summary>
public void AddItemSlot(Node rootNode) public ItemSlotNode? AddItemSlot(Node rootNode)
{ {
if (_itemSlotNodes == null || _itemSlotPackedScene == null) if (_itemSlotNodes == null || _itemSlotPackedScene == null)
{ {
return; return null;
} }
var itemSlotNode = NodeUtils.InstantiatePackedScene<ItemSlotNode>(_itemSlotPackedScene, rootNode); var itemSlotNode = NodeUtils.InstantiatePackedScene<ItemSlotNode>(_itemSlotPackedScene, rootNode);
if (itemSlotNode == null) if (itemSlotNode == null)
{ {
return; return null;
} }
itemSlotNode.IsSelect = (_itemSlotNodes.Count) == _selectIndex; itemSlotNode.IsSelect = (_itemSlotNodes.Count) == _selectIndex;
_itemSlotNodes.Add(itemSlotNode); _itemSlotNodes.Add(itemSlotNode);
return itemSlotNode;
} }
public void SelectTheNextItemSlot() public void SelectTheNextItemSlot()

View File

@ -15,6 +15,8 @@ public partial class Packsack : PickAbleTemplate
{ {
private PackedScene? _packedScene; private PackedScene? _packedScene;
private PacksackUi? _packsackUi; private PacksackUi? _packsackUi;
[Export]
public int NumberSlots { get; set; }
public override bool CanPutInPack => false; public override bool CanPutInPack => false;
@ -45,7 +47,7 @@ public partial class Packsack : PickAbleTemplate
_packsackUi.ItemContainer = ItemContainer; _packsackUi.ItemContainer = ItemContainer;
} }
} }
GameSceneNodeHolder.BackpackUiContainer?.Show();
_packsackUi?.Show(); _packsackUi?.Show();
} }
@ -55,6 +57,12 @@ public partial class Packsack : PickAbleTemplate
{ {
base._Ready(); base._Ready();
ItemContainer = new UniversalItemContainer(); ItemContainer = new UniversalItemContainer();
//When the backpack is created, the item slot is generated.
//当背包被创建时,物品槽就被生成出来了。
for (var i = 0; i < NumberSlots; i++)
{
ItemContainer.AddItemSlot(this)?.Hide();
}
_packedScene = GD.Load<PackedScene>("res://prefab/ui/packsackUI.tscn"); _packedScene = GD.Load<PackedScene>("res://prefab/ui/packsackUI.tscn");
} }
} }

View File

@ -14,7 +14,7 @@ public partial class PacksackUi : UiLoaderTemplate
private PackedScene? _packedScene; private PackedScene? _packedScene;
private GridContainer? _gridContainer; private HFlowContainer? _hFlowContainer;
private Label? _titleLabel; private Label? _titleLabel;
@ -57,15 +57,16 @@ public partial class PacksackUi : UiLoaderTemplate
/// <param name="itemContainer"></param> /// <param name="itemContainer"></param>
private void PlaceItemSlot(IItemContainer? itemContainer) private void PlaceItemSlot(IItemContainer? itemContainer)
{ {
if (_gridContainer == null || itemContainer == null) if (_hFlowContainer == null || itemContainer == null)
{ {
return; return;
} }
NodeUtils.DeleteAllChild(_gridContainer); NodeUtils.DeleteAllChild(_hFlowContainer);
foreach (var itemSlotNode in itemContainer) foreach (var itemSlotNode in itemContainer)
{ {
itemSlotNode.Reparent(_gridContainer); itemSlotNode.Reparent(_hFlowContainer);
itemSlotNode.Show();
} }
} }
@ -91,10 +92,9 @@ public partial class PacksackUi : UiLoaderTemplate
public override void InitializeUi() public override void InitializeUi()
{ {
_gridContainer = GetNode<GridContainer>("GridContainer"); _hFlowContainer = GetNode<HFlowContainer>("HFlowContainer");
_titleLabel = GetNode<Label>("TitleLabel"); _titleLabel = GetNode<Label>("TitleLabel");
_exitButton = GetNode<Button>("ExitButton"); _exitButton = GetNode<Button>("ExitButton");
_gridContainer.Columns = Config.HotBarSize;
//If the item container was set before this node was placed in the node tree, load it here. //If the item container was set before this node was placed in the node tree, load it here.
//若物品容器在此节点放置到节点树之前被设置了,那么在这里加载。 //若物品容器在此节点放置到节点树之前被设置了,那么在这里加载。
PlaceItemSlot(_itemContainer); PlaceItemSlot(_itemContainer);
@ -105,7 +105,11 @@ public partial class PacksackUi : UiLoaderTemplate
{ {
if (_exitButton != null) if (_exitButton != null)
{ {
_exitButton.Pressed += Hide; _exitButton.Pressed += () =>
{
GameSceneNodeHolder.BackpackUiContainer?.Hide();
Hide();
};
} }
} }
} }

View File

@ -1,10 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using ColdMint.scripts.debug; using ColdMint.scripts.debug;
using ColdMint.scripts.item; using ColdMint.scripts.item;
using ColdMint.scripts.item.weapon; using ColdMint.scripts.item.weapon;
using Godot; using Godot;
using PacksackUi = ColdMint.scripts.loader.uiLoader.PacksackUi; using PacksackUi = ColdMint.scripts.loader.uiLoader.PacksackUi;
@ -136,6 +134,7 @@ public static class NodeUtils
{ {
return GameSceneNodeHolder.BackpackUiContainer; return GameSceneNodeHolder.BackpackUiContainer;
} }
return defaultParentNode; return defaultParentNode;
} }