2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* script_create_dialog.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 22:01:57 +01:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-08 00:11:42 +02:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "script_create_dialog.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "editor_file_system.h"
|
2017-02-21 04:05:15 +01:00
|
|
|
#include "global_config.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "io/resource_saver.h"
|
|
|
|
#include "os/file_access.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "script_language.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ScriptCreateDialog::config(const String &p_base_name, const String &p_base_path) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
class_name->set_text("");
|
|
|
|
parent_name->set_text(p_base_name);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_base_path != "") {
|
|
|
|
initial_bp = p_base_path.get_basename();
|
|
|
|
file_path->set_text(initial_bp + "." + ScriptServer::get_language(language_menu->get_selected())->get_extension());
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
initial_bp = "";
|
2014-02-10 02:10:30 +01:00
|
|
|
file_path->set_text("");
|
|
|
|
}
|
|
|
|
_class_name_changed("");
|
|
|
|
_path_changed(file_path->get_text());
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool ScriptCreateDialog::_validate(const String &p_string) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_string.length() == 0)
|
2014-02-10 02:10:30 +01:00
|
|
|
return false;
|
|
|
|
|
2017-04-15 17:35:06 +02:00
|
|
|
String path_chars = "\"res://";
|
|
|
|
bool is_val_path = ScriptServer::get_language(language_menu->get_selected())->can_inherit_from_file();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_string.length(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i == 0) {
|
|
|
|
if (p_string[0] >= '0' && p_string[0] <= '9')
|
2014-02-10 02:10:30 +01:00
|
|
|
return false; // no start with number plz
|
|
|
|
}
|
|
|
|
|
2017-04-15 17:35:06 +02:00
|
|
|
if (i == p_string.length() - 1 && is_val_path)
|
|
|
|
return p_string[i] == '\"';
|
|
|
|
|
|
|
|
if (is_val_path && i < path_chars.length()) {
|
|
|
|
if (p_string[i] != path_chars[i])
|
|
|
|
is_val_path = false;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool valid_char = (p_string[i] >= '0' && p_string[i] <= '9') || (p_string[i] >= 'a' && p_string[i] <= 'z') || (p_string[i] >= 'A' && p_string[i] <= 'Z') || p_string[i] == '_' || (is_val_path && (p_string[i] == '/' || p_string[i] == '.'));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!valid_char)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ScriptCreateDialog::_class_name_changed(const String &p_name) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!_validate(parent_name->get_text())) {
|
2017-04-15 17:35:06 +02:00
|
|
|
error_label->set_text(TTR("Invalid parent class name or path"));
|
2017-03-05 16:44:50 +01:00
|
|
|
error_label->add_color_override("font_color", Color(1, 0.4, 0.0, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
} else if (class_name->is_editable()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (class_name->get_text() == "") {
|
|
|
|
error_label->set_text(TTR("Valid chars:") + " a-z A-Z 0-9 _");
|
|
|
|
error_label->add_color_override("font_color", Color(1, 1, 1, 0.6));
|
2014-02-10 02:10:30 +01:00
|
|
|
} else if (!_validate(class_name->get_text())) {
|
2016-05-04 03:25:37 +02:00
|
|
|
error_label->set_text(TTR("Invalid class name"));
|
2017-03-05 16:44:50 +01:00
|
|
|
error_label->add_color_override("font_color", Color(1, 0.2, 0.2, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2016-05-19 00:08:12 +02:00
|
|
|
error_label->set_text(TTR("Valid name"));
|
2017-03-05 16:44:50 +01:00
|
|
|
error_label->add_color_override("font_color", Color(0, 1.0, 0.8, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
error_label->set_text(TTR("N/A"));
|
2017-03-05 16:44:50 +01:00
|
|
|
error_label->add_color_override("font_color", Color(0, 1.0, 0.8, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptCreateDialog::ok_pressed() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (create_new) {
|
2016-11-09 17:29:15 +01:00
|
|
|
_create_new();
|
|
|
|
} else {
|
|
|
|
_load_exist();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
create_new = true;
|
2016-11-09 17:29:15 +01:00
|
|
|
_update_controls();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptCreateDialog::_create_new() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-11-09 17:29:15 +01:00
|
|
|
if (class_name->is_editable() && !_validate(class_name->get_text())) {
|
2016-05-19 00:08:12 +02:00
|
|
|
alert->set_text(TTR("Class name is invalid!"));
|
2015-04-08 19:02:13 +02:00
|
|
|
alert->popup_centered_minsize();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_validate(parent_name->get_text())) {
|
2016-05-19 00:08:12 +02:00
|
|
|
alert->set_text(TTR("Parent class name is invalid!"));
|
2015-04-08 19:02:13 +02:00
|
|
|
alert->popup_centered_minsize();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
String cname;
|
|
|
|
if (class_name->is_editable())
|
2017-03-05 16:44:50 +01:00
|
|
|
cname = class_name->get_text();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<Script> scr = ScriptServer::get_language(language_menu->get_selected())->get_template(cname, parent_name->get_text());
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2016-10-12 22:23:48 +02:00
|
|
|
String selected_language = language_menu->get_item_text(language_menu->get_selected());
|
2017-02-08 06:18:48 +01:00
|
|
|
editor_settings->set_project_metadata("script_setup", "last_selected_language", selected_language);
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cname != "")
|
2016-08-06 03:46:45 +02:00
|
|
|
scr->set_name(cname);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (!internal->is_pressed()) {
|
2017-01-05 13:16:00 +01:00
|
|
|
String lpath = GlobalConfig::get_singleton()->localize_path(file_path->get_text());
|
2016-08-06 03:46:45 +02:00
|
|
|
scr->set_path(lpath);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!path_valid) {
|
2016-05-19 00:08:12 +02:00
|
|
|
alert->set_text(TTR("Invalid path!"));
|
2015-04-08 19:02:13 +02:00
|
|
|
alert->popup_centered_minsize();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Error err = ResourceSaver::save(lpath, scr, ResourceSaver::FLAG_CHANGE_PATH);
|
|
|
|
if (err != OK) {
|
2016-05-19 00:08:12 +02:00
|
|
|
alert->set_text(TTR("Could not create script in filesystem."));
|
2015-04-08 19:02:13 +02:00
|
|
|
alert->popup_centered_minsize();
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-11-09 17:29:15 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-11-09 17:29:15 +01:00
|
|
|
hide();
|
2017-03-05 16:44:50 +01:00
|
|
|
emit_signal("script_created", scr);
|
2016-11-09 17:29:15 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-11-09 17:29:15 +01:00
|
|
|
void ScriptCreateDialog::_load_exist() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String path = file_path->get_text();
|
2016-11-09 17:29:15 +01:00
|
|
|
RES p_script = ResourceLoader::load(path, "Script");
|
|
|
|
if (p_script.is_null()) {
|
|
|
|
alert->get_ok()->set_text(TTR("Ugh"));
|
|
|
|
alert->set_text(vformat(TTR("Error loading script from %s"), path));
|
|
|
|
alert->popup_centered_minsize();
|
|
|
|
return;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hide();
|
2017-03-05 16:44:50 +01:00
|
|
|
emit_signal("script_created", p_script.get_ref_ptr());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptCreateDialog::_lang_changed(int l) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
l = language_menu->get_selected();
|
|
|
|
if (ScriptServer::get_language(l)->has_named_classes()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
class_name->set_editable(true);
|
|
|
|
} else {
|
|
|
|
class_name->set_editable(false);
|
|
|
|
}
|
2016-11-09 17:29:15 +01:00
|
|
|
|
2017-04-15 17:35:06 +02:00
|
|
|
if (ScriptServer::get_language(l)->can_inherit_from_file()) {
|
|
|
|
parent_browse_button->show();
|
|
|
|
} else {
|
|
|
|
parent_browse_button->hide();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String selected_ext = "." + ScriptServer::get_language(l)->get_extension();
|
|
|
|
String path = file_path->get_text();
|
|
|
|
String extension = "";
|
|
|
|
if (path.find(".") >= 0) {
|
|
|
|
extension = path.get_extension();
|
2016-11-09 17:29:15 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (extension.length() == 0) {
|
2016-11-09 17:29:15 +01:00
|
|
|
// add extension if none
|
2017-03-05 16:44:50 +01:00
|
|
|
path += selected_ext;
|
2016-11-09 17:29:15 +01:00
|
|
|
_path_changed(path);
|
|
|
|
} else {
|
|
|
|
// change extension by selected language
|
|
|
|
List<String> extensions;
|
|
|
|
// get all possible extensions for script
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int l = 0; l < language_menu->get_item_count(); l++) {
|
|
|
|
ScriptServer::get_language(l)->get_recognized_extensions(&extensions);
|
2016-11-09 17:29:15 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
|
|
|
if (E->get().nocasecmp_to(extension) == 0) {
|
|
|
|
path = path.get_basename() + selected_ext;
|
2016-11-09 17:29:15 +01:00
|
|
|
_path_changed(path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-11-09 17:29:15 +01:00
|
|
|
file_path->set_text(path);
|
2014-02-10 02:10:30 +01:00
|
|
|
_class_name_changed(class_name->get_text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScriptCreateDialog::_built_in_pressed() {
|
|
|
|
|
|
|
|
if (internal->is_pressed()) {
|
|
|
|
path_vb->hide();
|
|
|
|
} else {
|
|
|
|
path_vb->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-15 17:35:06 +02:00
|
|
|
void ScriptCreateDialog::_browse_path(bool browse_parent) {
|
|
|
|
|
|
|
|
is_browsing_parent = browse_parent;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-06-19 00:30:21 +02:00
|
|
|
file_browse->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
2016-06-20 05:38:13 +02:00
|
|
|
file_browse->set_disable_overwrite_warning(true);
|
2014-02-10 02:10:30 +01:00
|
|
|
file_browse->clear_filters();
|
|
|
|
List<String> extensions;
|
|
|
|
|
2016-11-09 17:29:15 +01:00
|
|
|
// get all possible extensions for script
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int l = 0; l < language_menu->get_item_count(); l++) {
|
|
|
|
ScriptServer::get_language(l)->get_recognized_extensions(&extensions);
|
2016-11-09 17:29:15 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
|
|
|
file_browse->add_filter("*." + E->get());
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
file_browse->set_current_path(file_path->get_text());
|
2014-02-10 02:10:30 +01:00
|
|
|
file_browse->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ScriptCreateDialog::_file_selected(const String &p_file) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
String p = GlobalConfig::get_singleton()->localize_path(p_file);
|
2017-04-15 17:35:06 +02:00
|
|
|
if (is_browsing_parent) {
|
|
|
|
parent_name->set_text("\"" + p + "\"");
|
|
|
|
_class_name_changed("\"" + p + "\"");
|
|
|
|
} else {
|
|
|
|
file_path->set_text(p);
|
|
|
|
_path_changed(p);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void ScriptCreateDialog::_path_changed(const String &p_path) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
path_valid = false;
|
|
|
|
String p = p_path;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p == "") {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-19 00:08:12 +02:00
|
|
|
path_error_label->set_text(TTR("Path is empty"));
|
2017-03-05 16:44:50 +01:00
|
|
|
path_error_label->add_color_override("font_color", Color(1, 0.4, 0.0, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-05 13:16:00 +01:00
|
|
|
p = GlobalConfig::get_singleton()->localize_path(p);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!p.begins_with("res://")) {
|
|
|
|
|
2016-05-04 03:25:37 +02:00
|
|
|
path_error_label->set_text(TTR("Path is not local"));
|
2017-03-05 16:44:50 +01:00
|
|
|
path_error_label->add_color_override("font_color", Color(1, 0.4, 0.0, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p.find("/") || p.find("\\")) {
|
|
|
|
DirAccess *d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (d->change_dir(p.get_base_dir()) != OK) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-05-19 00:08:12 +02:00
|
|
|
path_error_label->set_text(TTR("Invalid base path"));
|
2017-03-05 16:44:50 +01:00
|
|
|
path_error_label->add_color_override("font_color", Color(1, 0.4, 0.0, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(d);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memdelete(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileAccess *f = FileAccess::create(FileAccess::ACCESS_RESOURCES);
|
2017-03-05 16:44:50 +01:00
|
|
|
create_new = !f->file_exists(p);
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(f);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String extension = p.get_extension();
|
2014-02-10 02:10:30 +01:00
|
|
|
List<String> extensions;
|
|
|
|
|
2016-11-09 17:29:15 +01:00
|
|
|
// get all possible extensions for script
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int l = 0; l < language_menu->get_item_count(); l++) {
|
|
|
|
ScriptServer::get_language(l)->get_recognized_extensions(&extensions);
|
2016-11-09 17:29:15 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool found = false;
|
|
|
|
int index = 0;
|
|
|
|
for (List<String>::Element *E = extensions.front(); E; E = E->next()) {
|
|
|
|
if (E->get().nocasecmp_to(extension) == 0) {
|
2016-11-09 17:29:15 +01:00
|
|
|
language_menu->select(index); // change Language option by extension
|
2017-03-05 16:44:50 +01:00
|
|
|
found = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
break;
|
|
|
|
}
|
2016-11-09 17:29:15 +01:00
|
|
|
index++;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2016-05-19 00:08:12 +02:00
|
|
|
path_error_label->set_text(TTR("Invalid extension"));
|
2017-03-05 16:44:50 +01:00
|
|
|
path_error_label->add_color_override("font_color", Color(1, 0.4, 0.0, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-09 17:29:15 +01:00
|
|
|
_update_controls();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
path_error_label->add_color_override("font_color", Color(0, 1.0, 0.8, 0.8));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
path_valid = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-11-09 17:29:15 +01:00
|
|
|
void ScriptCreateDialog::_update_controls() {
|
|
|
|
|
|
|
|
if (create_new) {
|
|
|
|
path_error_label->set_text(TTR("Create new script"));
|
|
|
|
get_ok()->set_text(TTR("Create"));
|
|
|
|
} else {
|
|
|
|
path_error_label->set_text(TTR("Load existing script"));
|
|
|
|
get_ok()->set_text(TTR("Load"));
|
|
|
|
}
|
|
|
|
parent_name->set_editable(create_new);
|
|
|
|
internal->set_disabled(!create_new);
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void ScriptCreateDialog::_bind_methods() {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method("_class_name_changed", &ScriptCreateDialog::_class_name_changed);
|
|
|
|
ClassDB::bind_method("_lang_changed", &ScriptCreateDialog::_lang_changed);
|
|
|
|
ClassDB::bind_method("_built_in_pressed", &ScriptCreateDialog::_built_in_pressed);
|
|
|
|
ClassDB::bind_method("_browse_path", &ScriptCreateDialog::_browse_path);
|
|
|
|
ClassDB::bind_method("_file_selected", &ScriptCreateDialog::_file_selected);
|
|
|
|
ClassDB::bind_method("_path_changed", &ScriptCreateDialog::_path_changed);
|
|
|
|
ADD_SIGNAL(MethodInfo("script_created", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptCreateDialog::ScriptCreateDialog() {
|
|
|
|
|
|
|
|
/* SNAP DIALOG */
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VBoxContainer *vb = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(vb);
|
2017-01-10 05:49:55 +01:00
|
|
|
//set_child_rect(vb);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
class_name = memnew(LineEdit);
|
|
|
|
VBoxContainer *vb2 = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
vb2->add_child(class_name);
|
2017-03-05 16:44:50 +01:00
|
|
|
class_name->connect("text_changed", this, "_class_name_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
error_label = memnew(Label);
|
|
|
|
error_label->set_text("valid chars: a-z A-Z 0-9 _");
|
|
|
|
error_label->set_align(Label::ALIGN_CENTER);
|
|
|
|
vb2->add_child(error_label);
|
2017-03-05 16:44:50 +01:00
|
|
|
vb->add_margin_child(TTR("Class Name:"), vb2);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-15 17:35:06 +02:00
|
|
|
HBoxContainer *hb1 = memnew(HBoxContainer);
|
2017-03-05 16:44:50 +01:00
|
|
|
parent_name = memnew(LineEdit);
|
|
|
|
parent_name->connect("text_changed", this, "_class_name_changed");
|
2017-04-15 17:35:06 +02:00
|
|
|
parent_name->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
hb1->add_child(parent_name);
|
|
|
|
parent_browse_button = memnew(Button);
|
|
|
|
parent_browse_button->set_text(" .. ");
|
|
|
|
parent_browse_button->connect("pressed", this, "_browse_path", varray(true));
|
|
|
|
hb1->add_child(parent_browse_button);
|
|
|
|
parent_browse_button->hide();
|
|
|
|
vb->add_margin_child(TTR("Inherits:"), hb1);
|
|
|
|
is_browsing_parent = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
language_menu = memnew(OptionButton);
|
|
|
|
vb->add_margin_child(TTR("Language"), language_menu);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-06 13:40:00 +02:00
|
|
|
int default_lang = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-06 13:40:00 +02:00
|
|
|
String lang = ScriptServer::get_language(i)->get_name();
|
|
|
|
language_menu->add_item(lang);
|
|
|
|
if (lang == "GDScript") {
|
|
|
|
default_lang = i;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2016-10-12 22:23:48 +02:00
|
|
|
editor_settings = EditorSettings::get_singleton();
|
2017-02-08 06:18:48 +01:00
|
|
|
String last_selected_language = editor_settings->get_project_metadata("script_setup", "last_selected_language", "");
|
2017-04-06 13:40:00 +02:00
|
|
|
if (last_selected_language != "") {
|
|
|
|
for (int i = 0; i < language_menu->get_item_count(); i++) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (language_menu->get_item_text(i) == last_selected_language) {
|
2016-10-12 22:23:48 +02:00
|
|
|
language_menu->select(i);
|
|
|
|
break;
|
2017-04-06 13:40:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
language_menu->select(default_lang);
|
|
|
|
}
|
2016-10-12 22:23:48 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
language_menu->connect("item_selected", this, "_lang_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//parent_name->set_text();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
vb2 = memnew(VBoxContainer);
|
|
|
|
path_vb = memnew(VBoxContainer);
|
2014-02-10 02:10:30 +01:00
|
|
|
vb2->add_child(path_vb);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
HBoxContainer *hbc = memnew(HBoxContainer);
|
|
|
|
file_path = memnew(LineEdit);
|
|
|
|
file_path->connect("text_changed", this, "_path_changed");
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(file_path);
|
|
|
|
file_path->set_h_size_flags(SIZE_EXPAND_FILL);
|
2017-03-05 16:44:50 +01:00
|
|
|
Button *b = memnew(Button);
|
2014-02-10 02:10:30 +01:00
|
|
|
b->set_text(" .. ");
|
2017-04-15 17:35:06 +02:00
|
|
|
b->connect("pressed", this, "_browse_path", varray(false));
|
2014-02-10 02:10:30 +01:00
|
|
|
hbc->add_child(b);
|
|
|
|
path_vb->add_child(hbc);
|
2017-03-05 16:44:50 +01:00
|
|
|
path_error_label = memnew(Label);
|
|
|
|
path_vb->add_child(path_error_label);
|
2016-05-04 03:25:37 +02:00
|
|
|
path_error_label->set_text(TTR("Error!"));
|
2014-02-10 02:10:30 +01:00
|
|
|
path_error_label->set_align(Label::ALIGN_CENTER);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
internal = memnew(CheckButton);
|
2016-05-04 03:25:37 +02:00
|
|
|
internal->set_text(TTR("Built-In Script"));
|
2014-02-10 02:10:30 +01:00
|
|
|
vb2->add_child(internal);
|
2017-03-05 16:44:50 +01:00
|
|
|
internal->connect("pressed", this, "_built_in_pressed");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
vb->add_margin_child(TTR("Path:"), vb2);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
set_size(Size2(200, 150));
|
2014-02-10 02:10:30 +01:00
|
|
|
set_hide_on_ok(false);
|
2016-11-09 17:29:15 +01:00
|
|
|
set_title(TTR("Attach Node Script"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
file_browse = memnew(EditorFileDialog);
|
|
|
|
file_browse->connect("file_selected", this, "_file_selected");
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(file_browse);
|
2016-05-04 03:25:37 +02:00
|
|
|
get_ok()->set_text(TTR("Create"));
|
2017-03-05 16:44:50 +01:00
|
|
|
alert = memnew(AcceptDialog);
|
2014-02-10 02:10:30 +01:00
|
|
|
add_child(alert);
|
|
|
|
_lang_changed(0);
|
2016-11-09 17:29:15 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
create_new = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|