Add animation to spell editor.

加入法术编辑器的动画。
This commit is contained in:
Cold-Mint 2024-10-01 15:01:34 +08:00
parent 77f2bac36e
commit 81344faa3e
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
11 changed files with 211 additions and 19 deletions

View File

@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://djsh4unystlf0"] [gd_scene load_steps=16 format=3 uid="uid://djsh4unystlf0"]
[ext_resource type="Texture2D" uid="uid://qowlv0viyqbb" path="res://sprites/ui/Null.png" id="1_346je"]
[ext_resource type="Script" path="res://scripts/furniture/GuiFurniture.cs" id="1_t1qdg"] [ext_resource type="Script" path="res://scripts/furniture/GuiFurniture.cs" id="1_t1qdg"]
[ext_resource type="Texture2D" uid="uid://cyciw4drjvrs8" path="res://sprites/furnitures/SpellEditor.png" id="2_sbshw"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vx4tg"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_vx4tg"]
size = Vector2(31, 31) size = Vector2(31, 31)
@ -9,15 +9,90 @@ size = Vector2(31, 31)
[sub_resource type="CircleShape2D" id="CircleShape2D_in1f7"] [sub_resource type="CircleShape2D" id="CircleShape2D_in1f7"]
radius = 52.6118 radius = 52.6118
[sub_resource type="AtlasTexture" id="AtlasTexture_yq6e3"]
atlas = ExtResource("2_sbshw")
region = Rect2(0, 0, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_ljyfv"]
atlas = ExtResource("2_sbshw")
region = Rect2(44, 0, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_46j2i"]
atlas = ExtResource("2_sbshw")
region = Rect2(88, 0, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_q6a2v"]
atlas = ExtResource("2_sbshw")
region = Rect2(132, 0, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_lyh2i"]
atlas = ExtResource("2_sbshw")
region = Rect2(0, 43, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_84sml"]
atlas = ExtResource("2_sbshw")
region = Rect2(44, 43, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_xncbb"]
atlas = ExtResource("2_sbshw")
region = Rect2(88, 43, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_eaqhr"]
atlas = ExtResource("2_sbshw")
region = Rect2(132, 43, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_bcdl4"]
atlas = ExtResource("2_sbshw")
region = Rect2(0, 86, 44, 43)
[sub_resource type="AtlasTexture" id="AtlasTexture_a4mgy"]
atlas = ExtResource("2_sbshw")
region = Rect2(44, 86, 44, 43)
[sub_resource type="SpriteFrames" id="SpriteFrames_mppe5"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_yq6e3")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ljyfv")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_46j2i")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_q6a2v")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_lyh2i")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_84sml")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xncbb")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_eaqhr")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_bcdl4")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_a4mgy")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}]
[node name="RigidBody2D" type="RigidBody2D"] [node name="RigidBody2D" type="RigidBody2D"]
collision_layer = 256 collision_layer = 256
collision_mask = 160 collision_mask = 160
script = ExtResource("1_t1qdg") script = ExtResource("1_t1qdg")
Path = "res://prefab/ui/SpellEditorUI.tscn" Path = "res://prefab/ui/SpellEditorUI.tscn"
[node name="Null" type="Sprite2D" parent="."]
texture = ExtResource("1_346je")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(-0.5, -0.5) position = Vector2(-0.5, -0.5)
shape = SubResource("RectangleShape2D_vx4tg") shape = SubResource("RectangleShape2D_vx4tg")
@ -27,3 +102,9 @@ visible = false
[node name="CollisionShape2D" type="CollisionShape2D" parent="OperateArea2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="OperateArea2D"]
shape = SubResource("CircleShape2D_in1f7") shape = SubResource("CircleShape2D_in1f7")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
scale = Vector2(0.7, 0.7)
sprite_frames = SubResource("SpriteFrames_mppe5")
autoplay = "default"
frame_progress = 0.717769

View File

@ -84,13 +84,16 @@ text = "ui_re_create_map"
[node name="SeedLabel" type="Label" parent="CanvasLayer/Control"] [node name="SeedLabel" type="Label" parent="CanvasLayer/Control"]
layout_mode = 1 layout_mode = 1
anchors_preset = 5 anchors_preset = 3
anchor_left = 0.5 anchor_left = 1.0
anchor_right = 0.5 anchor_top = 1.0
offset_left = -20.0 anchor_right = 1.0
offset_right = 20.0 anchor_bottom = 1.0
offset_bottom = 25.0 offset_left = -45.0
grow_horizontal = 2 offset_top = -16.0
grow_horizontal = 0
grow_vertical = 0
theme_override_font_sizes/font_size = 10
[node name="MapContainer" parent="CanvasLayer/Control" instance=ExtResource("6_ljdj4")] [node name="MapContainer" parent="CanvasLayer/Control" instance=ExtResource("6_ljdj4")]
layout_mode = 1 layout_mode = 1

View File

@ -784,6 +784,7 @@ public partial class CharacterTemplate : CharacterBody2D
{ {
//Remove the item from the item container //Remove the item from the item container
//从物品容器内取出物品 //从物品容器内取出物品
originalItem.OnThrow(velocity);
var item = originalItem.CreateItem(1); var item = originalItem.CreateItem(1);
if (item is not Node2D node2D) if (item is not Node2D node2D)
{ {

View File

@ -89,7 +89,6 @@ public partial class Player : CharacterTemplate
private void SelectedItemChangeEvent(SelectedItemChangeEvent selectedItemChangeEvent) private void SelectedItemChangeEvent(SelectedItemChangeEvent selectedItemChangeEvent)
{ {
var item = selectedItemChangeEvent.NewItem; var item = selectedItemChangeEvent.NewItem;
GameSceneDepend.DynamicUiGroup?.HideAllControl();
if (item is Node2D node2D) if (item is Node2D node2D)
{ {
CurrentItem = node2D; CurrentItem = node2D;
@ -229,9 +228,6 @@ public partial class Player : CharacterTemplate
{ {
UseItem(GetGlobalMousePosition()); UseItem(GetGlobalMousePosition());
} }
//Pick up an item //Pick up an item
//捡起物品 //捡起物品
if (Input.IsActionJustPressed("pick_up")) if (Input.IsActionJustPressed("pick_up"))
@ -305,7 +301,6 @@ public partial class Player : CharacterTemplate
} }
ThrowItem(ItemContainer.GetSelectIndex(), 1, GetThrowVelocity()); ThrowItem(ItemContainer.GetSelectIndex(), 1, GetThrowVelocity());
GameSceneDepend.DynamicUiGroup?.HideAllControl();
CurrentItem = null; CurrentItem = null;
} }
} }

View File

@ -121,4 +121,11 @@ public interface IItem
/// <param name="owner">Owner of current item, if any</param> /// <param name="owner">Owner of current item, if any</param>
/// <param name="targetGlobalPosition">Target position, such as the position of the cursor when used by the player</param> /// <param name="targetGlobalPosition">Target position, such as the position of the cursor when used by the player</param>
void Use(Node2D? owner, Vector2 targetGlobalPosition); void Use(Node2D? owner, Vector2 targetGlobalPosition);
/// <summary>
/// <para>When the item is thrown</para>
/// <para>当物品被抛出时</para>
/// </summary>
/// <param name="velocity"></param>
void OnThrow(Vector2 velocity);
} }

View File

@ -25,6 +25,20 @@ public partial class Packsack : PickAbleTemplate
}); });
} }
protected override void OnSelectChange(bool isSelected)
{
if (isSelected)
{
return;
}
GameSceneDepend.DynamicUiGroup?.HideControl(Path);
}
public override void OnThrow(Vector2 velocity)
{
GameSceneDepend.DynamicUiGroup?.HideControl(Path);
}
public override void CopyAttributes(Node node) public override void CopyAttributes(Node node)
{ {
base.CopyAttributes(node); base.CopyAttributes(node);

View File

@ -48,5 +48,11 @@ public class PlaceholderItem : IItem
public void Use(Node2D? owner, Vector2 targetGlobalPosition) public void Use(Node2D? owner, Vector2 targetGlobalPosition)
{ {
throw new System.NotImplementedException();
}
public void OnThrow(Vector2 velocity)
{
throw new System.NotImplementedException();
} }
} }

View File

@ -1,4 +1,5 @@
using ColdMint.scripts.inventory; using ColdMint.scripts.inventory;
using ColdMint.scripts.map.events;
using Godot; using Godot;
namespace ColdMint.scripts.loader.uiLoader; namespace ColdMint.scripts.loader.uiLoader;
@ -14,9 +15,28 @@ public partial class SpellEditorUi : UiLoaderTemplate
_exitButton = GetNode<Button>("ExitButton"); _exitButton = GetNode<Button>("ExitButton");
_itemSlot = GetNode<ItemSlotNode>("ItemSlot"); _itemSlot = GetNode<ItemSlotNode>("ItemSlot");
_itemContainer = new UniversalItemContainer(1); _itemContainer = new UniversalItemContainer(1);
_itemContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
_itemSlot.Update(_itemContainer.GetPlaceHolderItem(0)); _itemSlot.Update(_itemContainer.GetPlaceHolderItem(0));
} }
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
{
if (_itemSlot == null)
{
return;
}
_itemSlot.Update(itemDataChangeEvent.NewItem);
}
public override void _ExitTree()
{
base._ExitTree();
if (_itemContainer != null)
{
_itemContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
}
}
public override void LoadUiActions() public override void LoadUiActions()
{ {
if (_exitButton != null) if (_exitButton != null)

View File

@ -46,7 +46,7 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
return TranslationServerUtils.Translate(key) ?? key; return TranslationServerUtils.Translate(key) ?? key;
} }
} }
/// <summary> /// <summary>
/// <para>Owner</para> /// <para>Owner</para>
/// <para>主人</para> /// <para>主人</para>
@ -92,12 +92,38 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
public bool Picked { get; set; } public bool Picked { get; set; }
public int MaxQuantity { get; set; } = 1; public int MaxQuantity { get; set; } = 1;
public bool IsSelect { get; set; }
private bool _isSelected;
public bool IsSelect
{
get => _isSelected;
set
{
if (_isSelected == value)
{
return;
}
_isSelected = value;
OnSelectChange(value);
}
}
public IItemContainer? ItemContainer { get; set; } public IItemContainer? ItemContainer { get; set; }
public IItemContainer? SelfItemContainer { get; set; } public IItemContainer? SelfItemContainer { get; set; }
private Label? _tipLabel; private Label? _tipLabel;
/// <summary>
/// <para></para>
/// <para>当选中状态发生改变时</para>
/// </summary>
/// <param name="isSelected"></param>
protected virtual void OnSelectChange(bool isSelected)
{
}
public IItem? CreateItem(int number) public IItem? CreateItem(int number)
{ {
if (number == 0) if (number == 0)
@ -156,6 +182,11 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
{ {
} }
public virtual void OnThrow(Vector2 velocity)
{
}
public override void _Ready() public override void _Ready()
{ {
_damageArea2D = GetNode<Area2D>("DamageArea2D"); _damageArea2D = GetNode<Area2D>("DamageArea2D");

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cyciw4drjvrs8"
path="res://.godot/imported/SpellEditor.png-a8650f7f0135f5be6d7d33b867de82ab.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/furnitures/SpellEditor.png"
dest_files=["res://.godot/imported/SpellEditor.png-a8650f7f0135f5be6d7d33b867de82ab.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1