Debian Codegraph @

editor/scene/3d/physics/physical_bone_3d_editor_plugin.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* physical_bone_3d_editor_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
31 #include "physical_bone_3d_editor_plugin.h"
32
33 #include "editor/editor_node.h"
34 #include "editor/editor_string_names.h"
35 #include "editor/scene/3d/node_3d_editor_plugin.h"
36 #include "scene/3d/physics/physical_bone_3d.h"
37
38 void PhysicalBone3DEditor::_on_toggle_button_transform_joint(bool p_is_pressed) {
39 _set_move_joint();
40 }
41
42 void PhysicalBone3DEditor::_set_move_joint() {
43 if (selected) {
44 selected->_set_gizmo_move_joint(button_transform_joint->is_pressed());
45 Node3DEditor::get_singleton()->update_transform_gizmo();
46 }
47 }
48
49 PhysicalBone3DEditor::PhysicalBone3DEditor() {
50 spatial_editor_hb = memnew(HBoxContainer);
51 spatial_editor_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
52 spatial_editor_hb->set_alignment(BoxContainer::ALIGNMENT_BEGIN);
53 Node3DEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb);
54
55 button_transform_joint = memnew(Button);
56 button_transform_joint->set_theme_type_variation(SceneStringName(FlatButton));
57 spatial_editor_hb->add_child(button_transform_joint);
58
59 button_transform_joint->set_text(TTR("Move Joint"));
60 // TODO: Rework this as a dedicated toolbar control so we can hook into theme changes and update it
61 // when the editor theme updates.
62 button_transform_joint->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("PhysicalBone3D"), EditorStringName(EditorIcons)));
63 button_transform_joint->set_toggle_mode(true);
64 button_transform_joint->connect(SceneStringName(toggled), callable_mp(this, &PhysicalBone3DEditor::_on_toggle_button_transform_joint));
65
66 hide();
67 }
68
69 void PhysicalBone3DEditor::set_selected(PhysicalBone3D *p_pb) {
70 button_transform_joint->set_pressed(false);
71
72 _set_move_joint();
73 selected = p_pb;
74 _set_move_joint();
75 }
76
77 void PhysicalBone3DEditor::hide() {
78 spatial_editor_hb->hide();
79 }
80
81 void PhysicalBone3DEditor::show() {
82 spatial_editor_hb->show();
83 }
84
85 void PhysicalBone3DEditorPlugin::make_visible(bool p_visible) {
86 if (p_visible) {
87 physical_bone_editor.show();
88 } else {
89 physical_bone_editor.hide();
90 physical_bone_editor.set_selected(nullptr);
91 selected = nullptr;
92 }
93 }
94
95 void PhysicalBone3DEditorPlugin::edit(Object *p_node) {
96 PhysicalBone3D *bone = Object::cast_to<PhysicalBone3D>(p_node);
97 if (bone) {
98 selected = bone;
99 physical_bone_editor.set_selected(selected);
100 }
101 }