Debian Codegraph @

editor/scene/3d/skeleton_ik_3d_editor_plugin.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* skeleton_ik_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 "skeleton_ik_3d_editor_plugin.h"
32
33 #include "editor/editor_node.h"
34 #include "editor/editor_string_names.h"
35 #include "scene/3d/skeleton_ik_3d.h"
36 #include "scene/gui/button.h"
37
38 void SkeletonIK3DEditorPlugin::_play() {
39 if (!skeleton_ik) {
40 return;
41 }
42
43 if (!skeleton_ik->get_parent_skeleton()) {
44 return;
45 }
46
47 if (play_btn->is_pressed()) {
48 skeleton_ik->start();
49 } else {
50 skeleton_ik->stop();
51 }
52 }
53
54 void SkeletonIK3DEditorPlugin::edit(Object *p_object) {
55 SkeletonIK3D *s = Object::cast_to<SkeletonIK3D>(p_object);
56 if (!s) {
57 return;
58 }
59
60 skeleton_ik = s;
61 play_btn->set_pressed(skeleton_ik->is_running());
62 }
63
64 bool SkeletonIK3DEditorPlugin::handles(Object *p_object) const {
65 return p_object->is_class("SkeletonIK3D");
66 }
67
68 void SkeletonIK3DEditorPlugin::make_visible(bool p_visible) {
69 if (p_visible) {
70 play_btn->show();
71 } else {
72 play_btn->hide();
73 }
74 }
75
76 SkeletonIK3DEditorPlugin::SkeletonIK3DEditorPlugin() {
77 play_btn = memnew(Button);
78 play_btn->set_button_icon(EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("Play"), EditorStringName(EditorIcons)));
79 play_btn->set_text(TTR("Play IK"));
80 play_btn->set_toggle_mode(true);
81 play_btn->hide();
82 play_btn->connect(SceneStringName(pressed), callable_mp(this, &SkeletonIK3DEditorPlugin::_play));
83 add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, play_btn);
84 skeleton_ik = nullptr;
85 }