Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/reparent_dialog.cpp
9902 views
1
/**************************************************************************/
2
/* reparent_dialog.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 "reparent_dialog.h"
32
33
#include "editor/scene/scene_tree_editor.h"
34
#include "scene/gui/box_container.h"
35
#include "scene/gui/check_box.h"
36
37
void ReparentDialog::_notification(int p_what) {
38
switch (p_what) {
39
case NOTIFICATION_ENTER_TREE: {
40
connect(SceneStringName(confirmed), callable_mp(this, &ReparentDialog::_reparent));
41
} break;
42
43
case NOTIFICATION_EXIT_TREE: {
44
disconnect(SceneStringName(confirmed), callable_mp(this, &ReparentDialog::_reparent));
45
} break;
46
}
47
}
48
49
void ReparentDialog::_cancel() {
50
hide();
51
}
52
53
void ReparentDialog::_reparent() {
54
if (tree->get_selected()) {
55
emit_signal(SNAME("reparent"), tree->get_selected()->get_path(), keep_transform->is_pressed());
56
hide();
57
}
58
}
59
60
void ReparentDialog::set_current(const HashSet<Node *> &p_selection) {
61
tree->set_marked(p_selection, false, false);
62
tree->set_selected(nullptr);
63
}
64
65
void ReparentDialog::_bind_methods() {
66
ClassDB::bind_method("_cancel", &ReparentDialog::_cancel);
67
68
ADD_SIGNAL(MethodInfo("reparent", PropertyInfo(Variant::NODE_PATH, "path"), PropertyInfo(Variant::BOOL, "keep_global_xform")));
69
}
70
71
ReparentDialog::ReparentDialog() {
72
set_title(TTR("Reparent Node"));
73
74
VBoxContainer *vbc = memnew(VBoxContainer);
75
add_child(vbc);
76
77
tree = memnew(SceneTreeEditor(false));
78
tree->set_update_when_invisible(false);
79
tree->set_show_enabled_subscene(true);
80
tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ReparentDialog::_reparent));
81
vbc->add_margin_child(TTR("Select new parent:"), tree, true);
82
83
keep_transform = memnew(CheckBox);
84
keep_transform->set_text(TTR("Keep Global Transform"));
85
keep_transform->set_pressed(true);
86
vbc->add_child(keep_transform);
87
88
set_ok_button_text(TTR("Reparent"));
89
}
90
91