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 "core/string/print_string.h"
34#include "editor/gui/scene_tree_editor.h"
35#include "scene/gui/box_container.h"
36#include "scene/gui/check_box.h"
37
38void ReparentDialog::_notification(int p_what) {
39 switch (p_what) {
40 case NOTIFICATION_ENTER_TREE: {
41 connect("confirmed", callable_mp(this, &ReparentDialog::_reparent));
42 } break;
43
44 case NOTIFICATION_EXIT_TREE: {
45 disconnect("confirmed", callable_mp(this, &ReparentDialog::_reparent));
46 } break;
47 }
48}
49
50void ReparentDialog::_cancel() {
51 hide();
52}
53
54void ReparentDialog::_reparent() {
55 if (tree->get_selected()) {
56 emit_signal(SNAME("reparent"), tree->get_selected()->get_path(), keep_transform->is_pressed());
57 hide();
58 }
59}
60
61void ReparentDialog::set_current(const HashSet<Node *> &p_selection) {
62 tree->set_marked(p_selection, false, false);
63 //tree->set_selected(p_node->get_parent());
64}
65
66void ReparentDialog::_bind_methods() {
67 ClassDB::bind_method("_cancel", &ReparentDialog::_cancel);
68
69 ADD_SIGNAL(MethodInfo("reparent", PropertyInfo(Variant::NODE_PATH, "path"), PropertyInfo(Variant::BOOL, "keep_global_xform")));
70}
71
72ReparentDialog::ReparentDialog() {
73 set_title(TTR("Reparent Node"));
74
75 VBoxContainer *vbc = memnew(VBoxContainer);
76 add_child(vbc);
77 //set_child_rect(vbc);
78
79 tree = memnew(SceneTreeEditor(false));
80 tree->set_show_enabled_subscene(true);
81 tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ReparentDialog::_reparent));
82 vbc->add_margin_child(TTR("Select new parent:"), tree, true);
83
84 keep_transform = memnew(CheckBox);
85 keep_transform->set_text(TTR("Keep Global Transform"));
86 keep_transform->set_pressed(true);
87 vbc->add_child(keep_transform);
88
89 //vbc->add_margin_child("Options:",node_only);
90
91 //cancel->connect("pressed", this,"_cancel");
92
93 set_ok_button_text(TTR("Reparent"));
94}
95
96ReparentDialog::~ReparentDialog() {
97}
98