diff --git a/prefab/roomTemplates/dungeon/initialRoom.tscn b/prefab/roomTemplates/dungeon/initialRoom.tscn index 06fa45b..ec59b74 100644 --- a/prefab/roomTemplates/dungeon/initialRoom.tscn +++ b/prefab/roomTemplates/dungeon/initialRoom.tscn @@ -37,26 +37,11 @@ position = Vector2(491, 193) [node name="CollisionShape2D" type="CollisionShape2D" parent="RoomSlotList/Slot1"] position = Vector2(5, 0) shape = SubResource("RectangleShape2D_jxmys") -debug_color = Color(0.854902, 0.14902, 0.823529, 0.419608) +debug_color = Color(0, 0.6, 0.701961, 0.419608) [node name="Marker2D" type="Marker2D" parent="."] position = Vector2(216, 113) script = ExtResource("2_6p8mv") -[node name="StaffOfTheUndead" parent="." instance=ExtResource("3_ud0w8")] -position = Vector2(231, 116) - -[node name="StaffOfTheUndead2" parent="." instance=ExtResource("3_ud0w8")] -position = Vector2(113, 149) - -[node name="StaffOfTheUndead5" parent="." instance=ExtResource("3_ud0w8")] -position = Vector2(213, 177) - [node name="StaffOfTheUndead6" parent="." instance=ExtResource("3_ud0w8")] position = Vector2(290, 167) - -[node name="StaffOfTheUndead3" parent="." instance=ExtResource("3_ud0w8")] -position = Vector2(70, 88) - -[node name="StaffOfTheUndead4" parent="." instance=ExtResource("3_ud0w8")] -position = Vector2(367, 85) diff --git a/prefab/ui/packsackUI.tscn b/prefab/ui/packsackUI.tscn index 97249e6..07b1811 100644 --- a/prefab/ui/packsackUI.tscn +++ b/prefab/ui/packsackUI.tscn @@ -1,32 +1,54 @@ [gd_scene load_steps=2 format=3 uid="uid://dsat7xk63bfg2"] -[ext_resource type="Script" path="res://scripts/inventory/PacksackUi.cs" id="1_jgs18"] +[ext_resource type="Script" path="res://scripts/loader/uiLoader/PacksackUi.cs" id="1_wm4bu"] [node name="PacksackUi" type="Control"] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = 33.0 -offset_top = 81.0 -offset_right = -58.0 -offset_bottom = -35.0 grow_horizontal = 2 grow_vertical = 2 -script = ExtResource("1_jgs18") +script = ExtResource("1_wm4bu") -[node name="GridContainer" type="GridContainer" parent="."] +[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="Label" type="Label" parent="."] -layout_mode = 0 -offset_left = 3.0 -offset_top = -43.0 -offset_right = 43.0 -offset_bottom = -18.0 -text = "背包" +[node name="TitleLabel" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 10 +anchor_right = 1.0 +offset_bottom = 30.0 +grow_horizontal = 2 +text = "ui_name" +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="."] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -75.0 +offset_top = 8.0 +offset_right = -8.0 +offset_bottom = 41.0 +grow_horizontal = 0 +text = "ui_close" diff --git a/scenes/LevelGraphEditor.tscn b/scenes/LevelGraphEditor.tscn index 98dbcd7..9e9f07d 100644 --- a/scenes/LevelGraphEditor.tscn +++ b/scenes/LevelGraphEditor.tscn @@ -211,7 +211,7 @@ text = "ui_load" layout_mode = 2 text = "ui_create_room" -[node name="ReturnButton" type="Button" parent="HBoxContainer"] +[node name="ExitButton" type="Button" parent="HBoxContainer"] layout_mode = 2 text = "ui_close" diff --git a/scenes/game.tscn b/scenes/game.tscn index 7d03926..739ca48 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -84,6 +84,14 @@ offset_right = 20.0 offset_bottom = 25.0 grow_horizontal = 2 +[node name="BackpackUIContainer" type="Control" parent="CanvasLayer"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + [node name="GameOverMenu" parent="CanvasLayer" instance=ExtResource("6_yjmrv")] visible = false diff --git a/scripts/GameSceneNodeHolder.cs b/scripts/GameSceneNodeHolder.cs index 30bf59b..7ef8d08 100644 --- a/scripts/GameSceneNodeHolder.cs +++ b/scripts/GameSceneNodeHolder.cs @@ -75,4 +75,14 @@ public static class GameSceneNodeHolder /// 操作提示 /// public static RichTextLabel? OperationTipLabel { get; set; } + + /// + /// BackpackUiContainer + /// 背包Ui容器 + /// + /// + ///The knapsack Ui container houses the container of the knapsack ui node. When a user uses a backpack, the node to which his backpack is attached is displayed from within the backpack ui container. + ///背包Ui容器内存放的是背包ui节点的容器。当用户使用背包时,会从背包ui容器内将其背包对于的节点展示出来。 + /// + public static Control? BackpackUiContainer { get; set; } } \ No newline at end of file diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs index c9e7801..87b1d64 100644 --- a/scripts/inventory/UniversalItemContainer.cs +++ b/scripts/inventory/UniversalItemContainer.cs @@ -176,7 +176,8 @@ public class UniversalItemContainer : IItemContainer public ItemSlotNode? Match(IItemStack stack) { - return _itemSlotNodes?.FirstOrDefault(itemSlotNode => itemSlotNode.CanAddItem(stack.GetItem()!)); + var item = stack.GetItem(); + return item == null ? null : _itemSlotNodes?.FirstOrDefault(itemSlotNode => itemSlotNode.CanAddItem(item)); } public ItemSlotNode? Match(Func predicate) diff --git a/scripts/item/Packsack.cs b/scripts/item/Packsack.cs index a8f0bf4..6c334e9 100644 --- a/scripts/item/Packsack.cs +++ b/scripts/item/Packsack.cs @@ -3,6 +3,7 @@ using ColdMint.scripts.pickable; using ColdMint.scripts.utils; using Godot; +using PacksackUi = ColdMint.scripts.loader.uiLoader.PacksackUi; namespace ColdMint.scripts.item; @@ -37,7 +38,12 @@ public partial class Packsack : PickAbleTemplate if (_packsackUi == null) { - _packsackUi = NodeUtils.InstantiatePackedScene(_packedScene, this); + _packsackUi = NodeUtils.InstantiatePackedScene(_packedScene,this); + if (_packsackUi != null) + { + _packsackUi.Title = Name; + _packsackUi.ItemContainer = ItemContainer; + } } _packsackUi?.Show(); diff --git a/scripts/loader/sceneLoader/GameSceneLoader.cs b/scripts/loader/sceneLoader/GameSceneLoader.cs index 6352775..f433c7d 100644 --- a/scripts/loader/sceneLoader/GameSceneLoader.cs +++ b/scripts/loader/sceneLoader/GameSceneLoader.cs @@ -27,6 +27,10 @@ public partial class GameSceneLoader : SceneLoaderTemplate //加载HotBar var hotBar = GetNode("CanvasLayer/Control/VBoxContainer/HotBar"); GameSceneNodeHolder.HotBar = hotBar; + //Backpack Ui container + //背包Ui容器 + var backpackUiContainer = GetNode("CanvasLayer/BackpackUIContainer"); + GameSceneNodeHolder.BackpackUiContainer = backpackUiContainer; //Load operation prompt //加载操作提示 var operationTip = GetNode("CanvasLayer/Control/VBoxContainer/OperationTip"); diff --git a/scripts/loader/uiLoader/LevelGraphEditorLoader.cs b/scripts/loader/uiLoader/LevelGraphEditorLoader.cs index 111458c..57de62d 100644 --- a/scripts/loader/uiLoader/LevelGraphEditorLoader.cs +++ b/scripts/loader/uiLoader/LevelGraphEditorLoader.cs @@ -308,9 +308,9 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate }; } - if (_nodeBinding.ReturnButton != null) + if (_nodeBinding.ExitButton != null) { - _nodeBinding.ReturnButton.Pressed += () => + _nodeBinding.ExitButton.Pressed += () => { if (_mainMenu == null) { diff --git a/scripts/inventory/PacksackUi.cs b/scripts/loader/uiLoader/PacksackUi.cs similarity index 55% rename from scripts/inventory/PacksackUi.cs rename to scripts/loader/uiLoader/PacksackUi.cs index ae778e5..0b94223 100644 --- a/scripts/inventory/PacksackUi.cs +++ b/scripts/loader/uiLoader/PacksackUi.cs @@ -1,13 +1,15 @@ -using ColdMint.scripts.utils; +using ColdMint.scripts.debug; +using ColdMint.scripts.inventory; +using ColdMint.scripts.utils; using Godot; -namespace ColdMint.scripts.inventory; +namespace ColdMint.scripts.loader.uiLoader; /// /// Backpack UI /// 背包UI /// -public partial class PacksackUi : Control +public partial class PacksackUi : UiLoaderTemplate { private IItemContainer? _itemContainer; @@ -15,6 +17,26 @@ public partial class PacksackUi : Control private GridContainer? _gridContainer; + private Label? _titleLabel; + + private string? _title; + + private Button? _exitButton; + + /// + /// title + /// 标题 + /// + public string? Title + { + get => _title; + set + { + _title = value; + SetTile(value); + } + } + /// /// Packsack /// 背包 @@ -48,13 +70,43 @@ public partial class PacksackUi : Control } } - public override void _Ready() + /// + /// SetTile + /// 设置标题 + /// + /// + private void SetTile(string? title) + { + if (_titleLabel == null) + { + return; + } + + _titleLabel.Text = title; + } + + public override void InitializeData() { _packedScene = GD.Load("res://prefab/ui/ItemSlot.tscn"); + } + + public override void InitializeUi() + { _gridContainer = GetNode("GridContainer"); + _titleLabel = GetNode