Adds UI to spell editor.

加入法术编辑器的UI。
This commit is contained in:
Cold-Mint 2024-09-30 22:13:51 +08:00
parent 67706ca9d7
commit 77f2bac36e
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
6 changed files with 164 additions and 3 deletions

View File

@ -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,スペルエディター

1 id zh en ja
34 ui_translator 翻译 translator 翻訳
35 ui_unordered_list_tip 排名不分先后 Ranking is not in order 順位は関係ありません
36 ui_loading 正在加载... Loading... 読み込み中...
37 ui_spell_editor 法术编辑器 Spell editor スペルエディター

View File

@ -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")

View File

@ -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"]

View File

@ -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

View File

@ -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
/// </remarks>
private Area2D? _operateArea2D;
/// <summary>
/// <para>Whether the player is within range of the operation</para>
/// <para>玩家是否在操作范围内</para>
/// </summary>
private bool _playerInRange;
[Export]
public string? Path;
/// <summary>
/// <para>There's a mouse hover</para>
/// <para>有鼠标悬停</para>
/// </summary>
private bool _hasMouseOver;
public override void _Ready()
{
base._Ready();
InputPickable = true;
_operateArea2D = GetNode<Area2D>("OperateArea2D");
_operateArea2D.BodyEntered += OnBodyEntered;
_operateArea2D.BodyExited += OnBodyExited;
_operateArea2D.SetCollisionMaskValue(Config.LayerNumber.Player, true);
if (Path != null)
{
GameSceneDepend.DynamicUiGroup?.RegisterControl(Path, () =>
{
var packedScene = GD.Load<PackedScene>(Path);
return NodeUtils.InstantiatePackedScene<SpellEditorUi>(packedScene);
});
}
}
/// <summary>
/// <para>Use furniture</para>
/// <para>使用家具</para>
/// </summary>
/// <param name="player"></param>
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()

View File

@ -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<Button>("ExitButton");
_itemSlot = GetNode<ItemSlotNode>("ItemSlot");
_itemContainer = new UniversalItemContainer(1);
_itemSlot.Update(_itemContainer.GetPlaceHolderItem(0));
}
public override void LoadUiActions()
{
if (_exitButton != null)
{
_exitButton.Pressed += () =>
{
GameSceneDepend.DynamicUiGroup?.HideControl(this);
};
}
}
}