2022-03-15 13:29:32 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "prop_editor_plugin.h"
|
|
|
|
|
|
|
|
#include "../props/prop_data.h"
|
|
|
|
#include "../singleton/prop_utils.h"
|
|
|
|
#include "core/os/keyboard.h"
|
|
|
|
|
2022-08-17 17:02:24 +02:00
|
|
|
#include "core/input/input.h"
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2022-03-19 04:08:34 +01:00
|
|
|
#include "scene/gui/separator.h"
|
|
|
|
#include "editor/editor_settings.h"
|
2023-09-03 13:09:56 +02:00
|
|
|
#include "scene/gui/box_container.h"
|
2022-03-19 04:08:34 +01:00
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
void PropEditorPlugin::convert_active_scene_to_prop_data() {
|
|
|
|
SceneTree *st = SceneTree::get_singleton();
|
|
|
|
|
|
|
|
if (st) {
|
|
|
|
Node *scene = st->get_edited_scene_root();
|
|
|
|
|
|
|
|
if (scene) {
|
|
|
|
EditorData &ed = EditorNode::get_editor_data();
|
|
|
|
String path = ed.get_scene_path(ed.get_edited_scene());
|
|
|
|
|
|
|
|
convert_scene(scene, path.get_basename() + ".tres");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void PropEditorPlugin::convert_selected_scene_to_prop_data() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropEditorPlugin::convert_scene(Node *root, const String &path) {
|
|
|
|
Ref<PropData> data = PropUtils::get_singleton()->convert_tree(root);
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!data.is_valid());
|
|
|
|
|
|
|
|
ResourceLoader l;
|
|
|
|
if (l.exists(path)) {
|
|
|
|
Ref<PropData> res = l.load(path, "PropData");
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!res.is_valid());
|
|
|
|
|
|
|
|
res->copy_from(data);
|
|
|
|
|
|
|
|
ResourceSaver s;
|
|
|
|
s.save(path, res);
|
|
|
|
|
|
|
|
res.unref();
|
|
|
|
} else {
|
|
|
|
ResourceSaver s;
|
|
|
|
s.save(path, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropEditorPlugin::find_room_points(Variant param) {
|
|
|
|
SceneTree *st = SceneTree::get_singleton();
|
|
|
|
|
|
|
|
if (st) {
|
|
|
|
Node *scene = st->get_edited_scene_root();
|
|
|
|
|
|
|
|
if (scene) {
|
|
|
|
PropUtils::get_singleton()->generate_room_points_node(scene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropEditorPlugin::_quick_convert_button_pressed() {
|
|
|
|
convert_active_scene_to_prop_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropEditorPlugin::_convert_active_scene_to_prop_data(Variant param) {
|
|
|
|
convert_active_scene_to_prop_data();
|
|
|
|
}
|
|
|
|
void PropEditorPlugin::_convert_selected_scene_to_prop_data(Variant param) {
|
|
|
|
convert_selected_scene_to_prop_data();
|
|
|
|
}
|
|
|
|
|
|
|
|
PropEditorPlugin::PropEditorPlugin(EditorNode *p_node) {
|
|
|
|
editor = p_node;
|
|
|
|
|
|
|
|
editor->add_tool_menu_item("Convert active scene to PropData", this, "convert_active_scene_to_prop_data");
|
|
|
|
editor->add_tool_menu_item("Convert selected scene(s) to PropData", this, "convert_selected_scene_to_prop_data");
|
|
|
|
editor->add_tool_menu_item("(Prop) Find room points.", this, "find_room_points");
|
|
|
|
|
2023-09-03 13:09:56 +02:00
|
|
|
HBoxContainer *bc = memnew(HBoxContainer);
|
|
|
|
bc->add_child(memnew(VSeparator));
|
|
|
|
|
2022-03-15 13:29:32 +01:00
|
|
|
Button *b = memnew(Button);
|
2023-09-03 13:09:56 +02:00
|
|
|
bc->add_child(b);
|
2022-03-15 13:29:32 +01:00
|
|
|
b->set_flat(true);
|
|
|
|
|
2022-03-18 10:32:50 +01:00
|
|
|
b->connect("pressed", this, "_quick_convert_button_pressed");
|
2023-09-03 13:15:23 +02:00
|
|
|
b->set_icon(editor->get_scene_tree_dock()->get_theme_icon("AssetLib", "EditorIcons"));
|
|
|
|
//b->set_text("To Prop");
|
2023-09-03 13:25:00 +02:00
|
|
|
b->set_tooltip(TTR("Quick convert this scene to a Prop Resource."));
|
2023-10-13 19:36:17 +02:00
|
|
|
b->set_shortcut(ED_SHORTCUT("spatial_editor/quick_prop_convert", "Quick convert scene to Prop.", KEY_MASK_ALT + KEY_U));
|
2022-03-15 13:29:32 +01:00
|
|
|
|
2023-09-03 13:09:56 +02:00
|
|
|
add_control_to_container(EditorPlugin::CONTAINER_SPATIAL_EDITOR_MENU, bc);
|
2022-03-15 13:29:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PropEditorPlugin::~PropEditorPlugin() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void PropEditorPlugin::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("convert_active_scene_to_prop_data"), &PropEditorPlugin::_convert_active_scene_to_prop_data);
|
|
|
|
ClassDB::bind_method(D_METHOD("convert_selected_scene_to_prop_data"), &PropEditorPlugin::_convert_active_scene_to_prop_data);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("find_room_points"), &PropEditorPlugin::find_room_points);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_quick_convert_button_pressed"), &PropEditorPlugin::_quick_convert_button_pressed);
|
|
|
|
}
|