From 77f2bac36e943175246ad483131d669ae09c92f6 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Mon, 30 Sep 2024 22:13:51 +0800 Subject: [PATCH] =?UTF-8?q?Adds=20UI=20to=20spell=20editor.=20=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E6=B3=95=E6=9C=AF=E7=BC=96=E8=BE=91=E5=99=A8=E7=9A=84?= =?UTF-8?q?UI=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locals/UI.csv | 1 + .../{MagicSeparator.tscn => SpellEditor.tscn} | 1 + prefab/roomTemplates/dungeon/initialRoom.tscn | 2 +- prefab/ui/SpellEditorUI.tscn | 53 ++++++++++++ scripts/furniture/GuiFurniture.cs | 80 ++++++++++++++++++- scripts/loader/uiLoader/SpellEditorUi.cs | 30 +++++++ 6 files changed, 164 insertions(+), 3 deletions(-) rename prefab/furnitures/{MagicSeparator.tscn => SpellEditor.tscn} (95%) create mode 100644 prefab/ui/SpellEditorUI.tscn create mode 100644 scripts/loader/uiLoader/SpellEditorUi.cs diff --git a/locals/UI.csv b/locals/UI.csv index cc5e626..039f953 100644 --- a/locals/UI.csv +++ b/locals/UI.csv @@ -34,3 +34,4 @@ ui_character_voice,角色配音,character_voice,キャラクターボイスで ui_translator,翻译,translator,翻訳 ui_unordered_list_tip,排名不分先后,Ranking is not in order,順位は関係ありません ui_loading,正在加载...,Loading...,読み込み中... +ui_spell_editor,法术编辑器,Spell editor,スペルエディター diff --git a/prefab/furnitures/MagicSeparator.tscn b/prefab/furnitures/SpellEditor.tscn similarity index 95% rename from prefab/furnitures/MagicSeparator.tscn rename to prefab/furnitures/SpellEditor.tscn index 2a88e09..b4e33cd 100644 --- a/prefab/furnitures/MagicSeparator.tscn +++ b/prefab/furnitures/SpellEditor.tscn @@ -13,6 +13,7 @@ radius = 52.6118 collision_layer = 256 collision_mask = 160 script = ExtResource("1_t1qdg") +Path = "res://prefab/ui/SpellEditorUI.tscn" [node name="Null" type="Sprite2D" parent="."] texture = ExtResource("1_346je") diff --git a/prefab/roomTemplates/dungeon/initialRoom.tscn b/prefab/roomTemplates/dungeon/initialRoom.tscn index b822d1e..ca37f5c 100644 --- a/prefab/roomTemplates/dungeon/initialRoom.tscn +++ b/prefab/roomTemplates/dungeon/initialRoom.tscn @@ -4,7 +4,7 @@ [ext_resource type="Script" path="res://scripts/map/PlayerSpawn.cs" id="2_6p8mv"] [ext_resource type="Script" path="res://scripts/map/ItemSpawn.cs" id="3_v1tlc"] [ext_resource type="Texture2D" uid="uid://drw45jlmfo0su" path="res://sprites/light/White_100.png" id="5_4pssd"] -[ext_resource type="PackedScene" uid="uid://djsh4unystlf0" path="res://prefab/furnitures/MagicSeparator.tscn" id="5_7c8bh"] +[ext_resource type="PackedScene" uid="uid://djsh4unystlf0" path="res://prefab/furnitures/SpellEditor.tscn" id="5_7c8bh"] [ext_resource type="PackedScene" uid="uid://bq5d2w22wnxrf" path="res://prefab/packsacks/PortableBackpacks.tscn" id="6_0iot7"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_kiih8"] diff --git a/prefab/ui/SpellEditorUI.tscn b/prefab/ui/SpellEditorUI.tscn new file mode 100644 index 0000000..39b44fc --- /dev/null +++ b/prefab/ui/SpellEditorUI.tscn @@ -0,0 +1,53 @@ +[gd_scene load_steps=3 format=3 uid="uid://h7lvaqqlsi4t"] + +[ext_resource type="Script" path="res://scripts/loader/uiLoader/SpellEditorUi.cs" id="1_1pxjs"] +[ext_resource type="PackedScene" uid="uid://d2i4udh0hho41" path="res://prefab/ui/ItemSlot.tscn" id="2_3ut57"] + +[node name="SpellEditorUi" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +script = ExtResource("1_1pxjs") + +[node name="TitleLabel" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 10 +anchor_right = 1.0 +offset_bottom = 25.0 +grow_horizontal = 2 +text = "ui_spell_editor" +horizontal_alignment = 1 + +[node name="ExitButton" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 1 +anchor_left = 1.0 +anchor_right = 1.0 +offset_left = -91.0 +offset_top = 11.0 +offset_right = -24.0 +offset_bottom = 44.0 +grow_horizontal = 0 +text = "ui_close" + +[node name="HFlowContainer" type="HFlowContainer" parent="."] +layout_mode = 1 +anchors_preset = 10 +anchor_right = 1.0 +offset_left = 35.0 +offset_top = 127.0 +offset_right = -20.0 +offset_bottom = 446.0 +grow_horizontal = 2 +mouse_filter = 2 + +[node name="ItemSlot" parent="." instance=ExtResource("2_3ut57")] +layout_mode = 1 +offset_left = 34.0 +offset_top = 73.0 +offset_right = 72.0 +offset_bottom = 111.0 diff --git a/scripts/furniture/GuiFurniture.cs b/scripts/furniture/GuiFurniture.cs index e5e4caa..ebb5cc7 100644 --- a/scripts/furniture/GuiFurniture.cs +++ b/scripts/furniture/GuiFurniture.cs @@ -1,3 +1,6 @@ +using ColdMint.scripts.character; +using ColdMint.scripts.loader.uiLoader; +using ColdMint.scripts.utils; using Godot; namespace ColdMint.scripts.furniture; @@ -18,22 +21,95 @@ public partial class GuiFurniture : Furniture /// private Area2D? _operateArea2D; + /// + /// Whether the player is within range of the operation + /// 玩家是否在操作范围内 + /// + private bool _playerInRange; + [Export] + public string? Path; + + /// + /// There's a mouse hover + /// 有鼠标悬停 + /// + private bool _hasMouseOver; + public override void _Ready() { base._Ready(); + InputPickable = true; _operateArea2D = GetNode("OperateArea2D"); _operateArea2D.BodyEntered += OnBodyEntered; _operateArea2D.BodyExited += OnBodyExited; + _operateArea2D.SetCollisionMaskValue(Config.LayerNumber.Player, true); + if (Path != null) + { + GameSceneDepend.DynamicUiGroup?.RegisterControl(Path, () => + { + var packedScene = GD.Load(Path); + return NodeUtils.InstantiatePackedScene(packedScene); + }); + } + } + + /// + /// Use furniture + /// 使用家具 + /// + /// + private void Use(Player player) + { + if (Path == null) + { + return; + } + GameSceneDepend.DynamicUiGroup?.ShowControl(Path, control => + { + if (control is SpellEditorUi spellEditorUi) + { + // spellEditorUi.Title = Name; + // spellEditorUi.ItemContainer = SelfItemContainer; + } + }); + } + + public override void _MouseEnter() + { + _hasMouseOver = true; + } + + public override void _MouseExit() + { + _hasMouseOver = false; } private void OnBodyEntered(Node node) { - + if (node is Player) + { + _playerInRange = true; + } + } + + public override void _PhysicsProcess(double delta) + { + if (GameSceneDepend.Player == null || !_playerInRange || !_hasMouseOver) + { + return; + } + if (Input.IsActionJustPressed("use_item")) + { + Use(GameSceneDepend.Player); + } } private void OnBodyExited(Node2D node2D) { - + if (node2D is Player) + { + _playerInRange = false; + } } public override void _ExitTree() diff --git a/scripts/loader/uiLoader/SpellEditorUi.cs b/scripts/loader/uiLoader/SpellEditorUi.cs new file mode 100644 index 0000000..9052a3c --- /dev/null +++ b/scripts/loader/uiLoader/SpellEditorUi.cs @@ -0,0 +1,30 @@ +using ColdMint.scripts.inventory; +using Godot; + +namespace ColdMint.scripts.loader.uiLoader; + +public partial class SpellEditorUi : UiLoaderTemplate +{ + private Button? _exitButton; + private IItemContainer? _itemContainer; + private ItemSlotNode? _itemSlot; + + public override void InitializeUi() + { + _exitButton = GetNode