mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-10 17:18:44 +08:00
[godot] More animation mixes UI Work.
This commit is contained in:
parent
898743739d
commit
91a7a1f3cc
@ -1,22 +1,9 @@
|
||||
[gd_resource type="SpineSkeletonDataResource" load_steps=5 format=2]
|
||||
[gd_resource type="SpineSkeletonDataResource" load_steps=16 format=2]
|
||||
|
||||
[ext_resource path="res://assets/spineboy/spineboy.atlas" type="SpineAtlasResource" id=1]
|
||||
[ext_resource path="res://assets/spineboy/spineboy-pro.json" type="SpineSkeletonFileResource" id=2]
|
||||
|
||||
[sub_resource type="SpineAnimationMix" id=1]
|
||||
from = "run"
|
||||
to = "idle"
|
||||
mix = 1.0
|
||||
|
||||
[sub_resource type="SpineAnimationMix" id=2]
|
||||
from = "idle"
|
||||
to = "run"
|
||||
mix = 1.0
|
||||
|
||||
[resource]
|
||||
atlas_res = ExtResource( 1 )
|
||||
skeleton_file_res = ExtResource( 2 )
|
||||
default_mix = 0.2
|
||||
animation_mixes = [ SubResource( 1 ), SubResource( 2 ), null, null ]
|
||||
animations = null
|
||||
skins = null
|
||||
|
||||
@ -86,30 +86,75 @@ bool SpineEditorPlugin::handles(Object *object) const {
|
||||
return object->is_class("SpineSprite") || object->is_class("SpineSkeletonDataResource");
|
||||
}
|
||||
|
||||
SpineAnimationMixesInspectorPlugin::SpineAnimationMixesInspectorPlugin(): add_mix_button(nullptr) {
|
||||
add_mix_button = memnew(Button);
|
||||
add_mix_button->set_text("Add mix");
|
||||
}
|
||||
|
||||
SpineAnimationMixesInspectorPlugin::~SpineAnimationMixesInspectorPlugin() {
|
||||
|
||||
}
|
||||
|
||||
bool SpineAnimationMixesInspectorPlugin::can_handle(Object *object) {
|
||||
return object->is_class("SpineSkeletonDataResource");
|
||||
}
|
||||
|
||||
void SpineAnimationMixesInspectorPlugin::parse_begin(Object *object) {
|
||||
sprite = object->cast_to<SpineSprite>(object);
|
||||
}
|
||||
|
||||
bool SpineAnimationMixesInspectorPlugin::parse_property(Object *object, Variant::Type type, const String &path,
|
||||
PropertyHint hint, const String &hint_text, int usage) {
|
||||
if (path == "animation_mixes") {
|
||||
add_custom_control(add_mix_button);
|
||||
if (path == "animation_mixes" && object) {
|
||||
auto mixes_property = memnew(SpineEditorPropertyAnimationMixes);
|
||||
mixes_property->setup(Object::cast_to<SpineSkeletonDataResource>(object));
|
||||
add_property_editor(path, mixes_property);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
SpineEditorPropertyAnimationMixes::SpineEditorPropertyAnimationMixes() {
|
||||
container = memnew(VBoxContainer);
|
||||
add_child(container);
|
||||
set_bottom_editor(container);
|
||||
}
|
||||
|
||||
void SpineEditorPropertyAnimationMixes::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("add_mix"), &SpineEditorPropertyAnimationMixes::add_mix);
|
||||
}
|
||||
|
||||
|
||||
void SpineEditorPropertyAnimationMixes::add_mix() {
|
||||
if (!skeleton_data.is_valid() || !skeleton_data->is_skeleton_data_loaded() || updating) return;
|
||||
|
||||
Ref<SpineAnimationMix> mix = Ref<SpineAnimationMix>(memnew(SpineAnimationMix));
|
||||
Array mixes = skeleton_data->get_animation_mixes().duplicate();
|
||||
mixes.push_back(mix);
|
||||
skeleton_data->set_animation_mixes(mixes);
|
||||
emit_changed(get_edited_property(), mixes);
|
||||
}
|
||||
|
||||
void SpineEditorPropertyAnimationMixes::update_property() {
|
||||
if (updating) return;
|
||||
updating = true;
|
||||
|
||||
for (int i = 0; container->get_child_count() != 0; i++) {
|
||||
auto child = container->get_child(i);
|
||||
child->queue_delete();
|
||||
container->remove_child(child);
|
||||
}
|
||||
|
||||
Array mixes = skeleton_data->get_animation_mixes();
|
||||
for (int i = 0; i < mixes.size(); i++) {
|
||||
auto hbox = memnew(HBoxContainer);
|
||||
|
||||
auto from_label = memnew(Label);
|
||||
from_label->set_text("From:" );
|
||||
hbox->add_child(from_label);
|
||||
|
||||
auto to_label = memnew(Label);
|
||||
to_label->set_text("To: ");
|
||||
hbox->add_child(to_label);
|
||||
|
||||
container->add_child(hbox);
|
||||
}
|
||||
|
||||
add_mix_button = memnew(Button);
|
||||
add_mix_button->set_text("Add mix");
|
||||
add_mix_button->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
add_mix_button->connect("pressed", this, "add_mix");
|
||||
container->add_child(add_mix_button);
|
||||
|
||||
updating = false;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
#ifndef GODOT_SPINEEDITORPLUGIN_H
|
||||
#define GODOT_SPINEEDITORPLUGIN_H
|
||||
#include "editor/editor_properties_array_dict.h"
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#include "editor/editor_node.h"
|
||||
@ -127,37 +128,31 @@ public:
|
||||
class SpineAnimationMixesInspectorPlugin: public EditorInspectorPlugin {
|
||||
GDCLASS(SpineAnimationMixesInspectorPlugin, EditorInspectorPlugin)
|
||||
|
||||
SpineSprite *sprite;
|
||||
|
||||
Button *add_mix_button;
|
||||
Vector<Button *> delete_mix;
|
||||
|
||||
public:
|
||||
SpineAnimationMixesInspectorPlugin();
|
||||
~SpineAnimationMixesInspectorPlugin() override;
|
||||
SpineAnimationMixesInspectorPlugin() = default;
|
||||
|
||||
bool can_handle(Object *object) override;
|
||||
void parse_begin(Object *object) override;
|
||||
bool parse_property(Object *object, Variant::Type type, const String &path, PropertyHint hint, const String &hint_text, int usage) override;
|
||||
};
|
||||
|
||||
class SpineAnimationMixesProperty: public EditorProperty {
|
||||
GDCLASS(SpineAnimationMixesProperty, EditorProperty)
|
||||
class SpineEditorPropertyAnimationMixes: public EditorProperty {
|
||||
GDCLASS(SpineEditorPropertyAnimationMixes, EditorProperty)
|
||||
|
||||
Ref<SpineSkeletonDataResource> skeleton_data;
|
||||
VBoxContainer *container;
|
||||
Button *add_mix_button;
|
||||
Vector<HBoxContainer *> cells;
|
||||
Vector<Button *> delete_mix;
|
||||
bool updating;
|
||||
|
||||
static void _bind_methods();
|
||||
void add_mix();
|
||||
public:
|
||||
SpineAnimationMixesProperty();
|
||||
~SpineAnimationMixesProperty();
|
||||
SpineEditorPropertyAnimationMixes();
|
||||
void setup(Ref<SpineSkeletonDataResource> skeleton_data) { this->skeleton_data = skeleton_data; };
|
||||
virtual void update_property();
|
||||
};
|
||||
|
||||
class SpineEditorPropertyMix: public EditorProperty {
|
||||
GDCLASS(SpineEditorPropertyMix, EditorProperty)
|
||||
|
||||
EditorPropertyText *from_property;
|
||||
EditorPropertyText *to_property;
|
||||
EditorPropertyFloat *mix_property;
|
||||
public:
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif//GODOT_SPINEEDITORPLUGIN_H
|
||||
|
||||
@ -69,7 +69,7 @@ SpinePathConstraintData::SpinePathConstraintData() {}
|
||||
SpinePathConstraintData::~SpinePathConstraintData() {}
|
||||
|
||||
Array SpinePathConstraintData::get_bones() {
|
||||
auto bs = get_spine_data()->getBones();
|
||||
auto bs = get_spine_constraint_data()->getBones();
|
||||
Array gd_bs;
|
||||
gd_bs.resize(bs.size());
|
||||
for (size_t i = 0; i < bs.size(); ++i) {
|
||||
@ -84,7 +84,7 @@ Array SpinePathConstraintData::get_bones() {
|
||||
}
|
||||
|
||||
Ref<SpineSlotData> SpinePathConstraintData::get_target() {
|
||||
auto s = get_spine_data()->getTarget();
|
||||
auto s = get_spine_constraint_data()->getTarget();
|
||||
if (s == NULL) return NULL;
|
||||
Ref<SpineSlotData> gd_s(memnew(SpineSlotData));
|
||||
gd_s->set_spine_object(s);
|
||||
@ -92,77 +92,77 @@ Ref<SpineSlotData> SpinePathConstraintData::get_target() {
|
||||
}
|
||||
void SpinePathConstraintData::set_target(Ref<SpineSlotData> v) {
|
||||
if (v.is_valid()) {
|
||||
get_spine_data()->setTarget(v->get_spine_object());
|
||||
get_spine_constraint_data()->setTarget(v->get_spine_object());
|
||||
} else {
|
||||
get_spine_data()->setTarget(NULL);
|
||||
get_spine_constraint_data()->setTarget(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
SpinePathConstraintData::PositionMode SpinePathConstraintData::get_position_mode() {
|
||||
auto m = (int) get_spine_data()->getPositionMode();
|
||||
auto m = (int) get_spine_constraint_data()->getPositionMode();
|
||||
return (PositionMode) m;
|
||||
}
|
||||
void SpinePathConstraintData::set_position_mode(PositionMode v) {
|
||||
auto m = (int) v;
|
||||
get_spine_data()->setPositionMode((spine::PositionMode) m);
|
||||
get_spine_constraint_data()->setPositionMode((spine::PositionMode) m);
|
||||
}
|
||||
|
||||
SpinePathConstraintData::SpacingMode SpinePathConstraintData::get_spacing_mode() {
|
||||
auto m = (int) get_spine_data()->getSpacingMode();
|
||||
auto m = (int) get_spine_constraint_data()->getSpacingMode();
|
||||
return (SpacingMode) m;
|
||||
}
|
||||
void SpinePathConstraintData::set_spacing_mode(SpacingMode v) {
|
||||
auto m = (int) v;
|
||||
get_spine_data()->setSpacingMode((spine::SpacingMode) m);
|
||||
get_spine_constraint_data()->setSpacingMode((spine::SpacingMode) m);
|
||||
}
|
||||
|
||||
SpinePathConstraintData::RotateMode SpinePathConstraintData::get_rotate_mode() {
|
||||
auto m = (int) get_spine_data()->getRotateMode();
|
||||
auto m = (int) get_spine_constraint_data()->getRotateMode();
|
||||
return (RotateMode) m;
|
||||
}
|
||||
void SpinePathConstraintData::set_rotate_mode(RotateMode v) {
|
||||
auto m = (int) v;
|
||||
get_spine_data()->setRotateMode((spine::RotateMode) m);
|
||||
get_spine_constraint_data()->setRotateMode((spine::RotateMode) m);
|
||||
}
|
||||
|
||||
float SpinePathConstraintData::get_offset_rotation() {
|
||||
return get_spine_data()->getOffsetRotation();
|
||||
return get_spine_constraint_data()->getOffsetRotation();
|
||||
}
|
||||
void SpinePathConstraintData::set_offset_rotation(float v) {
|
||||
get_spine_data()->setOffsetRotation(v);
|
||||
get_spine_constraint_data()->setOffsetRotation(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraintData::get_position() {
|
||||
return get_spine_data()->getPosition();
|
||||
return get_spine_constraint_data()->getPosition();
|
||||
}
|
||||
void SpinePathConstraintData::set_position(float v) {
|
||||
get_spine_data()->setPosition(v);
|
||||
get_spine_constraint_data()->setPosition(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraintData::get_spacing() {
|
||||
return get_spine_data()->getSpacing();
|
||||
return get_spine_constraint_data()->getSpacing();
|
||||
}
|
||||
void SpinePathConstraintData::set_spacing(float v) {
|
||||
get_spine_data()->setSpacing(v);
|
||||
get_spine_constraint_data()->setSpacing(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraintData::get_mix_rotate() {
|
||||
return get_spine_data()->getMixRotate();
|
||||
return get_spine_constraint_data()->getMixRotate();
|
||||
}
|
||||
void SpinePathConstraintData::set_mix_rotate(float v) {
|
||||
get_spine_data()->setMixRotate(v);
|
||||
get_spine_constraint_data()->setMixRotate(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraintData::get_mix_x() {
|
||||
return get_spine_data()->getMixX();
|
||||
return get_spine_constraint_data()->getMixX();
|
||||
}
|
||||
void SpinePathConstraintData::set_mix_x(float v) {
|
||||
get_spine_data()->setMixX(v);
|
||||
get_spine_constraint_data()->setMixX(v);
|
||||
}
|
||||
|
||||
float SpinePathConstraintData::get_mix_y() {
|
||||
return get_spine_data()->getMixY();
|
||||
return get_spine_constraint_data()->getMixY();
|
||||
}
|
||||
void SpinePathConstraintData::set_mix_y(float v) {
|
||||
get_spine_data()->setMixY(v);
|
||||
get_spine_constraint_data()->setMixY(v);
|
||||
}
|
||||
@ -42,7 +42,7 @@ void SpineAnimationMix::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "mix"), "set_mix", "get_mix");
|
||||
}
|
||||
|
||||
SpineAnimationMix::SpineAnimationMix() {
|
||||
SpineAnimationMix::SpineAnimationMix(): from(""), to(""), mix(0) {
|
||||
}
|
||||
|
||||
SpineAnimationMix::~SpineAnimationMix() {
|
||||
@ -118,7 +118,6 @@ void SpineSkeletonDataResource::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "atlas_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineAtlasResource"), "set_atlas_res", "get_atlas_res");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_file_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonFileResource"), "set_skeleton_file_res", "get_skeleton_file_res");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "default_mix"), "set_default_mix", "get_default_mix");
|
||||
ADD_GROUP("Animation mixes", "");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animation_mixes"), "set_animation_mixes", "get_animation_mixes");
|
||||
}
|
||||
|
||||
|
||||
@ -72,6 +72,7 @@ static void editor_init_callback() {
|
||||
void register_spine_godot_types() {
|
||||
#ifdef TOOLS_ENABLED
|
||||
EditorNode::add_init_callback(editor_init_callback);
|
||||
ClassDB::register_class<SpineEditorPropertyAnimationMixes>();
|
||||
#endif
|
||||
ClassDB::register_class<SpineAtlasResource>();
|
||||
ClassDB::register_class<SpineSkeletonFileResource>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user