physical_bone_plugin.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**************************************************************************/
  2. /* physical_bone_plugin.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "physical_bone_plugin.h"
  31. #include "editor/plugins/spatial_editor_plugin.h"
  32. #include "scene/3d/physics_body.h"
  33. void PhysicalBoneEditor::_bind_methods() {
  34. ClassDB::bind_method(D_METHOD("_on_toggle_button_transform_joint", "is_pressed"), &PhysicalBoneEditor::_on_toggle_button_transform_joint);
  35. }
  36. void PhysicalBoneEditor::_on_toggle_button_transform_joint(bool p_is_pressed) {
  37. _set_move_joint();
  38. }
  39. void PhysicalBoneEditor::_set_move_joint() {
  40. if (selected) {
  41. selected->_set_gizmo_move_joint(button_transform_joint->is_pressed());
  42. }
  43. }
  44. PhysicalBoneEditor::PhysicalBoneEditor(EditorNode *p_editor) :
  45. editor(p_editor),
  46. selected(nullptr) {
  47. spatial_editor_hb = memnew(HBoxContainer);
  48. spatial_editor_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  49. spatial_editor_hb->set_alignment(BoxContainer::ALIGN_BEGIN);
  50. SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
  51. spatial_editor_hb->add_child(memnew(VSeparator));
  52. button_transform_joint = memnew(ToolButton);
  53. spatial_editor_hb->add_child(button_transform_joint);
  54. button_transform_joint->set_text(TTR("Move Joint"));
  55. button_transform_joint->set_icon(SpatialEditor::get_singleton()->get_icon("PhysicalBone", "EditorIcons"));
  56. button_transform_joint->set_toggle_mode(true);
  57. button_transform_joint->connect("toggled", this, "_on_toggle_button_transform_joint");
  58. hide();
  59. }
  60. PhysicalBoneEditor::~PhysicalBoneEditor() {}
  61. void PhysicalBoneEditor::set_selected(PhysicalBone *p_pb) {
  62. button_transform_joint->set_pressed(false);
  63. _set_move_joint();
  64. selected = p_pb;
  65. _set_move_joint();
  66. }
  67. void PhysicalBoneEditor::hide() {
  68. spatial_editor_hb->hide();
  69. }
  70. void PhysicalBoneEditor::show() {
  71. spatial_editor_hb->show();
  72. }
  73. PhysicalBonePlugin::PhysicalBonePlugin(EditorNode *p_editor) :
  74. editor(p_editor),
  75. selected(nullptr),
  76. physical_bone_editor(editor) {}
  77. void PhysicalBonePlugin::make_visible(bool p_visible) {
  78. if (p_visible) {
  79. physical_bone_editor.show();
  80. } else {
  81. physical_bone_editor.hide();
  82. physical_bone_editor.set_selected(nullptr);
  83. selected = nullptr;
  84. }
  85. }
  86. void PhysicalBonePlugin::edit(Object *p_node) {
  87. selected = static_cast<PhysicalBone *>(p_node); // Trust it
  88. ERR_FAIL_COND(!selected);
  89. physical_bone_editor.set_selected(selected);
  90. }