SpineRuntimeEditorPlugin.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated January 1, 2020. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2020, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #ifdef TOOLS_ENABLED
  30. #include "SpineRuntimeEditorPlugin.h"
  31. #include "SpineAtlasResource.h"
  32. #include "SpineSkeletonJsonDataResource.h"
  33. #include "SpineSpriteAnimateDialog.h"
  34. #include "SpineSprite.h"
  35. Error SpineAtlasResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata){
  36. Ref<SpineAtlasResource> res(memnew(SpineAtlasResource));
  37. res->set_normal_texture_prefix(p_options["normal_texture_prefix"]);
  38. res->load_from_atlas_file(p_source_file);
  39. String file_name = vformat("%s.%s", p_save_path, get_save_extension());
  40. auto err = ResourceSaver::save(file_name, res);
  41. return err;
  42. }
  43. void SpineAtlasResourceImportPlugin::get_import_options(List<ImportOption> *r_options, int p_preset) const {
  44. if (p_preset == 0) {
  45. ImportOption op;
  46. op.option.name = "normal_texture_prefix";
  47. op.option.type = Variant::STRING;
  48. op.option.hint_string = "String";
  49. op.default_value = String("n");
  50. r_options->push_back(op);
  51. }
  52. }
  53. Error SpineJsonResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata){
  54. Ref<SpineSkeletonJsonDataResource> res(memnew(SpineSkeletonJsonDataResource));
  55. res->load_from_file(p_source_file);
  56. String file_name = vformat("%s.%s", p_save_path, get_save_extension());
  57. auto err = ResourceSaver::save(file_name, res);
  58. return err;
  59. }
  60. //=======================| SpineRuntimeEditorPlugin |============================
  61. SpineRuntimeEditorPlugin::SpineRuntimeEditorPlugin(EditorNode *p_node) {
  62. add_import_plugin(memnew(SpineAtlasResourceImportPlugin));
  63. add_import_plugin(memnew(SpineJsonResourceImportPlugin));
  64. auto animate_button = memnew(ToolButton);
  65. animate_button->set_text("Animate");
  66. add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, animate_button);
  67. animate_dialog = memnew(SpineSpriteAnimateDialog);
  68. get_editor_interface()->get_base_control()->add_child(animate_dialog);
  69. animate_dialog->set_animate_button(animate_button);
  70. animate_dialog->set_plugin(this);
  71. }
  72. SpineRuntimeEditorPlugin::~SpineRuntimeEditorPlugin() {
  73. }
  74. bool SpineRuntimeEditorPlugin::handles(Object *p_object) const {
  75. return p_object->is_class("SpineSprite");
  76. }
  77. void SpineRuntimeEditorPlugin::make_visible(bool p_visible) {
  78. if (get_editor_interface()->get_selection()->get_selected_node_list().size() != 1) {
  79. p_visible = false;
  80. }
  81. animate_dialog->get_animate_button()->set_visible(p_visible);
  82. }
  83. #endif