/**************************************************************************/1/* reparent_dialog.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "reparent_dialog.h"3132#include "editor/scene/scene_tree_editor.h"33#include "scene/gui/box_container.h"34#include "scene/gui/check_box.h"3536void ReparentDialog::_notification(int p_what) {37switch (p_what) {38case NOTIFICATION_ENTER_TREE: {39connect(SceneStringName(confirmed), callable_mp(this, &ReparentDialog::_reparent));40} break;4142case NOTIFICATION_EXIT_TREE: {43disconnect(SceneStringName(confirmed), callable_mp(this, &ReparentDialog::_reparent));44} break;45}46}4748void ReparentDialog::_cancel() {49hide();50}5152void ReparentDialog::_reparent() {53if (tree->get_selected()) {54emit_signal(SNAME("reparent"), tree->get_selected()->get_path(), keep_transform->is_pressed());55hide();56}57}5859void ReparentDialog::set_current(const HashSet<Node *> &p_selection) {60tree->set_marked(p_selection, false, false);61tree->set_selected(nullptr);62}6364void ReparentDialog::_bind_methods() {65ClassDB::bind_method("_cancel", &ReparentDialog::_cancel);6667ADD_SIGNAL(MethodInfo("reparent", PropertyInfo(Variant::NODE_PATH, "path"), PropertyInfo(Variant::BOOL, "keep_global_xform")));68}6970ReparentDialog::ReparentDialog() {71set_title(TTR("Reparent Node"));7273VBoxContainer *vbc = memnew(VBoxContainer);74add_child(vbc);7576tree = memnew(SceneTreeEditor(false));77tree->set_update_when_invisible(false);78tree->set_show_enabled_subscene(true);79tree->get_scene_tree()->connect("item_activated", callable_mp(this, &ReparentDialog::_reparent));80vbc->add_margin_child(TTR("Select new parent:"), tree, true);8182keep_transform = memnew(CheckBox);83keep_transform->set_text(TTR("Keep Global Transform"));84keep_transform->set_pressed(true);85vbc->add_child(keep_transform);8687set_ok_button_text(TTR("Reparent"));88}899091