Add New Shader
option to the FileSystemDock popup menu.
This commit is contained in:
parent
8762d8fa5d
commit
771491d358
5 changed files with 30 additions and 9 deletions
|
@ -46,6 +46,7 @@
|
|||
#include "scene/main/window.h"
|
||||
#include "scene/resources/packed_scene.h"
|
||||
#include "servers/display_server.h"
|
||||
#include "shader_create_dialog.h"
|
||||
|
||||
Ref<Texture2D> FileSystemDock::_get_tree_item_icon(bool p_is_valid, String p_file_type) {
|
||||
Ref<Texture2D> file_icon;
|
||||
|
@ -1967,6 +1968,22 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
|
|||
}
|
||||
|
||||
void FileSystemDock::_resource_created() {
|
||||
String fpath = path;
|
||||
if (!fpath.ends_with("/")) {
|
||||
fpath = fpath.get_base_dir();
|
||||
}
|
||||
|
||||
String type_name = new_resource_dialog->get_selected_type();
|
||||
if (type_name == "Shader") {
|
||||
make_shader_dialog->config(fpath.plus_file("new_shader"), false, false, 0);
|
||||
make_shader_dialog->popup_centered();
|
||||
return;
|
||||
} else if (type_name == "VisualShader") {
|
||||
make_shader_dialog->config(fpath.plus_file("new_shader"), false, false, 1);
|
||||
make_shader_dialog->popup_centered();
|
||||
return;
|
||||
}
|
||||
|
||||
Variant c = new_resource_dialog->instance_selected();
|
||||
|
||||
ERR_FAIL_COND(!c);
|
||||
|
@ -1982,12 +1999,6 @@ void FileSystemDock::_resource_created() {
|
|||
}
|
||||
|
||||
editor->push_item(r);
|
||||
|
||||
String fpath = path;
|
||||
if (!fpath.ends_with("/")) {
|
||||
fpath = fpath.get_base_dir();
|
||||
}
|
||||
|
||||
editor->save_resource_as(RES(r), fpath);
|
||||
}
|
||||
|
||||
|
@ -2997,6 +3008,9 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) {
|
|||
make_script_dialog->set_title(TTR("Create Script"));
|
||||
add_child(make_script_dialog);
|
||||
|
||||
make_shader_dialog = memnew(ShaderCreateDialog);
|
||||
add_child(make_shader_dialog);
|
||||
|
||||
new_resource_dialog = memnew(CreateDialog);
|
||||
add_child(new_resource_dialog);
|
||||
new_resource_dialog->set_base_type("Resource");
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include "script_create_dialog.h"
|
||||
|
||||
class EditorNode;
|
||||
class ShaderCreateDialog;
|
||||
|
||||
class FileSystemDock : public VBoxContainer {
|
||||
GDCLASS(FileSystemDock, VBoxContainer);
|
||||
|
@ -158,6 +159,7 @@ private:
|
|||
LineEdit *make_scene_dialog_text;
|
||||
ConfirmationDialog *overwrite_dialog;
|
||||
ScriptCreateDialog *make_script_dialog;
|
||||
ShaderCreateDialog *make_shader_dialog;
|
||||
CreateDialog *new_resource_dialog;
|
||||
|
||||
bool always_show_folders;
|
||||
|
|
|
@ -2977,7 +2977,7 @@ void SceneTreeDock::attach_shader_to_selected(int p_preferred_mode) {
|
|||
shader_create_dialog->connect("shader_created", callable_mp(this, &SceneTreeDock::_shader_created));
|
||||
shader_create_dialog->connect("confirmed", callable_mp(this, &SceneTreeDock::_shader_creation_closed));
|
||||
shader_create_dialog->connect("cancelled", callable_mp(this, &SceneTreeDock::_shader_creation_closed));
|
||||
shader_create_dialog->config(path, true, true, p_preferred_mode);
|
||||
shader_create_dialog->config(path, true, true, -1, p_preferred_mode);
|
||||
shader_create_dialog->popup_centered();
|
||||
}
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ void ShaderCreateDialog::_path_submitted(const String &p_path) {
|
|||
ok_pressed();
|
||||
}
|
||||
|
||||
void ShaderCreateDialog::config(const String &p_base_path, bool p_built_in_enabled, bool p_load_enabled, int p_preferred_mode) {
|
||||
void ShaderCreateDialog::config(const String &p_base_path, bool p_built_in_enabled, bool p_load_enabled, int p_preferred_type, int p_preferred_mode) {
|
||||
if (p_base_path != "") {
|
||||
initial_base_path = p_base_path.get_basename();
|
||||
file_path->set_text(initial_base_path + "." + language_data[language_menu->get_selected()].default_extension);
|
||||
|
@ -338,6 +338,11 @@ void ShaderCreateDialog::config(const String &p_base_path, bool p_built_in_enabl
|
|||
built_in_enabled = p_built_in_enabled;
|
||||
load_enabled = p_load_enabled;
|
||||
|
||||
if (p_preferred_type > -1) {
|
||||
language_menu->select(p_preferred_type);
|
||||
_language_changed(p_preferred_type);
|
||||
}
|
||||
|
||||
if (p_preferred_mode > -1) {
|
||||
mode_menu->select(p_preferred_mode);
|
||||
_mode_changed(p_preferred_mode);
|
||||
|
|
|
@ -108,7 +108,7 @@ protected:
|
|||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
void config(const String &p_base_path, bool p_built_in_enabled = true, bool p_load_enabled = true, int p_preferred_mode = -1);
|
||||
void config(const String &p_base_path, bool p_built_in_enabled = true, bool p_load_enabled = true, int p_preferred_type = -1, int p_preferred_mode = -1);
|
||||
ShaderCreateDialog();
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue