[godot] Fixes for latest Godot master commits.

This commit is contained in:
Mario Zechner 2022-05-05 15:26:16 +02:00
parent ce73d3c986
commit b96db92250
5 changed files with 81 additions and 40 deletions

View File

@ -29,8 +29,11 @@
#include "SpineBoneNode.h" #include "SpineBoneNode.h"
#if VERSION_MAJOR > 3
#include "core/config/engine.h"
#else
#include "core/engine.h" #include "core/engine.h"
#include "editor/editor_about.h" #endif
void SpineBoneNode::_bind_methods() { void SpineBoneNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_bone_mode"), &SpineBoneNode::set_bone_mode); ClassDB::bind_method(D_METHOD("set_bone_mode"), &SpineBoneNode::set_bone_mode);
@ -56,7 +59,7 @@ void SpineBoneNode::_notification(int what) {
SpineSprite *sprite = find_parent_sprite(); SpineSprite *sprite = find_parent_sprite();
if (sprite) { if (sprite) {
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
sprite->connect("world_transforms_changed", callable_mp(this, &SpineSlotNode::on_world_transforms_changed)); sprite->connect("world_transforms_changed", callable_mp(this, &SpineBoneNode::on_world_transforms_changed));
#else #else
sprite->connect("world_transforms_changed", this, "_on_world_transforms_changed"); sprite->connect("world_transforms_changed", this, "_on_world_transforms_changed");
#endif #endif
@ -71,7 +74,7 @@ void SpineBoneNode::_notification(int what) {
_change_notify("scale"); _change_notify("scale");
#endif #endif
} else { } else {
WARN_PRINT("SpineSlotNode parent is not a SpineSprite."); WARN_PRINT("SpineBoneNode parent is not a SpineSprite.");
} }
NOTIFY_PROPERTY_LIST_CHANGED(); NOTIFY_PROPERTY_LIST_CHANGED();
break; break;
@ -80,7 +83,7 @@ void SpineBoneNode::_notification(int what) {
SpineSprite *sprite = find_parent_sprite(); SpineSprite *sprite = find_parent_sprite();
if (sprite) { if (sprite) {
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
sprite->disconnect("world_transforms_changed", callable_mp(this, &SpineSlotNode::on_world_transforms_changed)); sprite->disconnect("world_transforms_changed", callable_mp(this, &SpineBoneNode::on_world_transforms_changed));
#else #else
sprite->disconnect("world_transforms_changed", this, "_on_world_transforms_changed"); sprite->disconnect("world_transforms_changed", this, "_on_world_transforms_changed");
#endif #endif

View File

@ -41,6 +41,9 @@
#define NOTIFY_PROPERTY_LIST_CHANGED() notify_property_list_changed() #define NOTIFY_PROPERTY_LIST_CHANGED() notify_property_list_changed()
#define VARIANT_FLOAT Variant::FLOAT #define VARIANT_FLOAT Variant::FLOAT
#define PROPERTY_USAGE_NOEDITOR PROPERTY_USAGE_NO_EDITOR #define PROPERTY_USAGE_NOEDITOR PROPERTY_USAGE_NO_EDITOR
#define RES Ref<Resource>
#define REF Ref<RefCounted>
#define GEOMETRY2D Geometry2D
#else #else
#include "core/object.h" #include "core/object.h"
#include "core/reference.h" #include "core/reference.h"
@ -51,6 +54,8 @@
#define INSTANTIATE(x) (x).instance() #define INSTANTIATE(x) (x).instance()
#define NOTIFY_PROPERTY_LIST_CHANGED() property_list_changed_notify() #define NOTIFY_PROPERTY_LIST_CHANGED() property_list_changed_notify()
#define VARIANT_FLOAT Variant::REAL #define VARIANT_FLOAT Variant::REAL
#define GDREGISTER_CLASS(x) ClassDB::register_class<x>()
#define GEOMETRY2D Geometry
#endif #endif
#define SPINE_CHECK(obj, ret) \ #define SPINE_CHECK(obj, ret) \

View File

@ -33,9 +33,17 @@
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineRendererObject.h" #include "SpineRendererObject.h"
#include "SpineSlotNode.h" #include "SpineSlotNode.h"
#if VERSION_MAJOR > 3
#include "core/config/engine.h"
#include "core/math/geometry_2d.h"
#else
#include "core/engine.h" #include "core/engine.h"
#endif
#include "scene/gui/control.h" #include "scene/gui/control.h"
#include "scene/main/viewport.h" #include "scene/main/viewport.h"
#if TOOLS_ENABLED #if TOOLS_ENABLED
#include "editor/editor_plugin.h" #include "editor/editor_plugin.h"
#endif #endif
@ -461,14 +469,14 @@ static void add_triangles(MeshInstance2D *mesh_instance,
Ref<Texture> texture, Ref<Texture> texture,
Ref<Texture> normal_map) { Ref<Texture> normal_map) {
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
RenderingServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(), RenderingServer::get_singleton()->canvas_item_add_triangle_array(mesh_instance->get_canvas_item(),
indices, indices,
vertices, vertices,
colors, colors,
uvs, uvs,
Vector<int>(), Vector<int>(),
Vector<float>(), Vector<float>(),
tex.is_null() ? RID() : tex->get_rid(), texture.is_null() ? RID() : texture->get_rid(),
-1); -1);
#else #else
VisualServer::get_singleton()->canvas_item_add_triangle_array(mesh_instance->get_canvas_item(), VisualServer::get_singleton()->canvas_item_add_triangle_array(mesh_instance->get_canvas_item(),
@ -642,7 +650,7 @@ void SpineSprite::draw() {
scratch_points.push_back(Vector2(vertices->buffer()[0], vertices->buffer()[1])); scratch_points.push_back(Vector2(vertices->buffer()[0], vertices->buffer()[1]));
Color color = debug_regions_color; Color color = debug_regions_color;
if (Geometry::is_point_in_polygon(mouse_position, scratch_points)) { if (GEOMETRY2D::is_point_in_polygon(mouse_position, scratch_points)) {
hovered_slot = slot; hovered_slot = slot;
color = Color(1, 1, 1, 1); color = Color(1, 1, 1, 1);
} }
@ -672,7 +680,7 @@ void SpineSprite::draw() {
} }
Color color = debug_meshes_color; Color color = debug_meshes_color;
if (Geometry::is_point_in_polygon(mouse_position, scratch_points)) { if (GEOMETRY2D::is_point_in_polygon(mouse_position, scratch_points)) {
hovered_slot = slot; hovered_slot = slot;
color = Color(1, 1, 1, 1); color = Color(1, 1, 1, 1);
} }
@ -744,7 +752,7 @@ void SpineSprite::draw() {
Transform2D bone_transform(Math::deg2rad(bone->getWorldRotationX()), Vector2(bone->getWorldX(), bone->getWorldY())); Transform2D bone_transform(Math::deg2rad(bone->getWorldRotationX()), Vector2(bone->getWorldX(), bone->getWorldY()));
bone_transform.scale_basis(Vector2(bone->getWorldScaleX(), bone->getWorldScaleY())); bone_transform.scale_basis(Vector2(bone->getWorldScaleX(), bone->getWorldScaleY()));
auto mouse_local_position = bone_transform.affine_inverse().xform(mouse_position); auto mouse_local_position = bone_transform.affine_inverse().xform(mouse_position);
if (Geometry::is_point_in_polygon(mouse_local_position, scratch_points)) { if (GEOMETRY2D::is_point_in_polygon(mouse_local_position, scratch_points)) {
hovered_bone = bone; hovered_bone = bone;
} }
} }
@ -753,7 +761,11 @@ void SpineSprite::draw() {
#if TOOLS_ENABLED #if TOOLS_ENABLED
Ref<Font> default_font; Ref<Font> default_font;
auto control = memnew(Control); auto control = memnew(Control);
#if VERSION_MAJOR > 3
default_font = control->get_theme_default_font();
#else
default_font = control->get_font("font", "Label"); default_font = control->get_font("font", "Label");
#endif
memfree(control); memfree(control);
float editor_scale = EditorInterface::get_singleton()->get_editor_scale(); float editor_scale = EditorInterface::get_singleton()->get_editor_scale();
@ -782,7 +794,11 @@ void SpineSprite::draw() {
Rect2 background_rect(0, -default_font->get_height() - 5, rect_width + 20, line_height * hover_text_lines.size() + 10); Rect2 background_rect(0, -default_font->get_height() - 5, rect_width + 20, line_height * hover_text_lines.size() + 10);
if (hover_text_lines.size() > 0) draw_rect(background_rect, Color(0, 0, 0 ,0.8)); if (hover_text_lines.size() > 0) draw_rect(background_rect, Color(0, 0, 0 ,0.8));
for (int i = 0; i < hover_text_lines.size(); i++) { for (int i = 0; i < hover_text_lines.size(); i++) {
#if VERSION_MAJOR > 3
draw_string(default_font, Vector2(10, 0 + i * default_font->get_height()), hover_text_lines[i], HORIZONTAL_ALIGNMENT_LEFT, -1, Font::DEFAULT_FONT_SIZE, Color (1, 1, 1, 1));
#else
draw_string(default_font, Vector2(10, 0 + i * default_font->get_height()), hover_text_lines[i], Color (1, 1, 1, 1)); draw_string(default_font, Vector2(10, 0 + i * default_font->get_height()), hover_text_lines[i], Color (1, 1, 1, 1));
#endif
} }
#endif #endif
} }

View File

@ -51,6 +51,7 @@
#include "SpineConstant.h" #include "SpineConstant.h"
#include "SpineSlotNode.h" #include "SpineSlotNode.h"
#include "SpineBoneNode.h" #include "SpineBoneNode.h"
#include "spine/Bone.h"
static Ref<SpineAtlasResourceFormatLoader> atlas_loader; static Ref<SpineAtlasResourceFormatLoader> atlas_loader;
static Ref<SpineAtlasResourceFormatSaver> atlas_saver; static Ref<SpineAtlasResourceFormatSaver> atlas_saver;
@ -67,44 +68,48 @@ static void editor_init_callback() {
#endif #endif
#if VERSION_MAJOR > 3
void initialize_spine_godot_module(ModuleInitializationLevel level) {
#else
void register_spine_godot_types() { void register_spine_godot_types() {
#endif
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
EditorNode::add_init_callback(editor_init_callback); EditorNode::add_init_callback(editor_init_callback);
ClassDB::register_class<SpineEditorPropertyAnimationMixes>(); GDREGISTER_CLASS(SpineEditorPropertyAnimationMixes);
#endif #endif
spine::Bone::setYDown(true); spine::Bone::setYDown(true);
ClassDB::register_class<SpineAtlasResource>(); GDREGISTER_CLASS(SpineAtlasResource);
ClassDB::register_class<SpineSkeletonFileResource>(); GDREGISTER_CLASS(SpineSkeletonFileResource);
ClassDB::register_class<SpineSkeletonDataResource>(); GDREGISTER_CLASS(SpineSkeletonDataResource);
ClassDB::register_class<SpineAnimationMix>(); GDREGISTER_CLASS(SpineAnimationMix);
ClassDB::register_class<SpineSprite>(); GDREGISTER_CLASS(SpineSprite);
ClassDB::register_class<SpineSkeleton>(); GDREGISTER_CLASS(SpineSkeleton);
ClassDB::register_class<SpineAnimationState>(); GDREGISTER_CLASS(SpineAnimationState);
ClassDB::register_class<SpineAnimation>(); GDREGISTER_CLASS(SpineAnimation);
ClassDB::register_class<SpineEventData>(); GDREGISTER_CLASS(SpineEventData);
ClassDB::register_class<SpineTrackEntry>(); GDREGISTER_CLASS(SpineTrackEntry);
ClassDB::register_class<SpineEvent>(); GDREGISTER_CLASS(SpineEvent);
ClassDB::register_class<SpineBoneData>(); GDREGISTER_CLASS(SpineBoneData);
ClassDB::register_class<SpineSlotData>(); GDREGISTER_CLASS(SpineSlotData);
ClassDB::register_class<SpineAttachment>(); GDREGISTER_CLASS(SpineAttachment);
ClassDB::register_class<SpineSkinEntry>(); GDREGISTER_CLASS(SpineSkinEntry);
ClassDB::register_class<SpineConstraintData>(); GDREGISTER_CLASS(SpineConstraintData);
ClassDB::register_class<SpineSkin>(); GDREGISTER_CLASS(SpineSkin);
ClassDB::register_class<SpineIkConstraintData>(); GDREGISTER_CLASS(SpineIkConstraintData);
ClassDB::register_class<SpineTransformConstraintData>(); GDREGISTER_CLASS(SpineTransformConstraintData);
ClassDB::register_class<SpinePathConstraintData>(); GDREGISTER_CLASS(SpinePathConstraintData);
ClassDB::register_class<SpineBone>(); GDREGISTER_CLASS(SpineBone);
ClassDB::register_class<SpineSlot>(); GDREGISTER_CLASS(SpineSlot);
ClassDB::register_class<SpineIkConstraint>(); GDREGISTER_CLASS(SpineIkConstraint);
ClassDB::register_class<SpinePathConstraint>(); GDREGISTER_CLASS(SpinePathConstraint);
ClassDB::register_class<SpineTransformConstraint>(); GDREGISTER_CLASS(SpineTransformConstraint);
ClassDB::register_class<SpineTimeline>(); GDREGISTER_CLASS(SpineTimeline);
ClassDB::register_class<SpineConstant>(); GDREGISTER_CLASS(SpineConstant);
ClassDB::register_class<SpineSlotNode>(); GDREGISTER_CLASS(SpineSlotNode);
ClassDB::register_class<SpineBoneNode>(); GDREGISTER_CLASS(SpineBoneNode);
ClassDB::register_class<SpineAnimationTrack>(); GDREGISTER_CLASS(SpineAnimationTrack);
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
atlas_loader.instantiate(); atlas_loader.instantiate();
@ -133,7 +138,11 @@ void register_spine_godot_types() {
#endif #endif
} }
#if VERSION_MAJOR > 3
void uninitialize_spine_godot_module(ModuleInitializationLevel level) {
#else
void unregister_spine_godot_types() { void unregister_spine_godot_types() {
#endif
ResourceLoader::remove_resource_format_loader(atlas_loader); ResourceLoader::remove_resource_format_loader(atlas_loader);
atlas_loader.unref(); atlas_loader.unref();

View File

@ -29,5 +29,13 @@
#pragma once #pragma once
#include "SpineCommon.h"
#if VERSION_MAJOR > 3
#include "modules/register_module_types.h"
void initialize_spine_godot_module(ModuleInitializationLevel level);
void uninitialize_spine_godot_module(ModuleInitializationLevel level);
#else
void register_spine_godot_types(); void register_spine_godot_types();
void unregister_spine_godot_types(); void unregister_spine_godot_types();
#endif