Remove CustomPropertyEditor completely

This commit is contained in:
Yuri Sizov 2022-08-01 21:01:48 +03:00
parent c596369d7a
commit 86798d36db
7 changed files with 177 additions and 2094 deletions

View File

@ -1660,6 +1660,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
style_dictionary_add_item->set_expand_margin_size(SIDE_RIGHT, 4 * EDSCALE);
theme->set_stylebox("DictionaryAddItem", "EditorStyles", style_dictionary_add_item);
Ref<StyleBoxEmpty> vshader_label_style = make_empty_stylebox(2, 1, 2, 1);
theme->set_stylebox("label_style", "VShaderEditor", vshader_label_style);
// adaptive script theme constants
// for comments and elements with lower relevance
const Color dim_color = Color(font_color.r, font_color.g, font_color.b, 0.5);

View File

@ -40,10 +40,17 @@
#include "editor/editor_node.h"
#include "editor/editor_properties.h"
#include "editor/editor_scale.h"
#include "editor/plugins/curve_editor_plugin.h"
#include "editor/plugins/shader_editor_plugin.h"
#include "scene/animation/animation_player.h"
#include "scene/gui/button.h"
#include "scene/gui/code_edit.h"
#include "scene/gui/graph_edit.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/panel.h"
#include "scene/gui/popup.h"
#include "scene/gui/rich_text_label.h"
#include "scene/gui/tree.h"
#include "scene/gui/view_panner.h"
#include "scene/main/window.h"
#include "scene/resources/visual_shader_nodes.h"
@ -91,17 +98,6 @@ void VisualShaderNodePlugin::_bind_methods() {
///////////////////
static Ref<StyleBoxEmpty> make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {
Ref<StyleBoxEmpty> style(memnew(StyleBoxEmpty));
style->set_default_margin(SIDE_LEFT, p_margin_left * EDSCALE);
style->set_default_margin(SIDE_RIGHT, p_margin_right * EDSCALE);
style->set_default_margin(SIDE_BOTTOM, p_margin_bottom * EDSCALE);
style->set_default_margin(SIDE_TOP, p_margin_top * EDSCALE);
return style;
}
///////////////////
VisualShaderGraphPlugin::VisualShaderGraphPlugin() {
}
@ -364,8 +360,6 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
Control *offset;
static Ref<StyleBoxEmpty> label_style = make_empty_stylebox(2, 1, 2, 1);
static const Color type_color[] = {
Color(0.38, 0.85, 0.96), // scalar (float)
Color(0.49, 0.78, 0.94), // scalar (int)
@ -765,14 +759,14 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
} else {
Label *label = memnew(Label);
label->set_text(name_left);
label->add_theme_style_override("normal", label_style); //more compact
label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact
hb->add_child(label);
if (vsnode->is_input_port_default(i, mode) && !port_left_used) {
Label *hint_label = memnew(Label);
hint_label->set_text(TTR("[default]"));
hint_label->add_theme_color_override("font_color", editor->get_theme_color(SNAME("font_readonly_color"), SNAME("TextEdit")));
hint_label->add_theme_style_override("normal", label_style);
hint_label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor")));
hb->add_child(hint_label);
}
}
@ -813,7 +807,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
} else {
Label *label = memnew(Label);
label->set_text(name_right);
label->add_theme_style_override("normal", label_style); //more compact
label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact
hb->add_child(label);
}
}
@ -1080,6 +1074,23 @@ VisualShaderGraphPlugin::~VisualShaderGraphPlugin() {
/////////////////
void VisualShaderEditedProperty::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_edited_property", "value"), &VisualShaderEditedProperty::set_edited_property);
ClassDB::bind_method(D_METHOD("get_edited_property"), &VisualShaderEditedProperty::get_edited_property);
ADD_PROPERTY(PropertyInfo(Variant::NIL, "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_edited_property", "get_edited_property");
}
void VisualShaderEditedProperty::set_edited_property(Variant p_variant) {
edited_property = p_variant;
}
Variant VisualShaderEditedProperty::get_edited_property() const {
return edited_property;
}
/////////////////
Vector2 VisualShaderEditor::selection_center;
List<VisualShaderEditor::CopyItem> VisualShaderEditor::copy_items_buffer;
List<VisualShader::Connection> VisualShaderEditor::copy_connections_buffer;
@ -2287,10 +2298,8 @@ void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id,
}
}
void VisualShaderEditor::_port_edited() {
void VisualShaderEditor::_port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
VisualShader::Type type = get_current_shader_type();
Variant value = property_editor->get_variant();
Ref<VisualShaderNode> vsn = visual_shader->get_node(type, editing_node);
ERR_FAIL_COND(!vsn.is_valid());
@ -2298,30 +2307,51 @@ void VisualShaderEditor::_port_edited() {
Ref<VisualShaderNodeCustom> custom = Object::cast_to<VisualShaderNodeCustom>(vsn.ptr());
if (custom.is_valid()) {
undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, value);
undo_redo->add_do_method(custom.ptr(), "_set_input_port_default_value", editing_port, p_value);
undo_redo->add_undo_method(custom.ptr(), "_set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
} else {
undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, value);
undo_redo->add_do_method(vsn.ptr(), "set_input_port_default_value", editing_port, p_value);
undo_redo->add_undo_method(vsn.ptr(), "set_input_port_default_value", editing_port, vsn->get_input_port_default_value(editing_port));
}
undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, value);
undo_redo->add_do_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, p_value);
undo_redo->add_undo_method(graph_plugin.ptr(), "set_input_port_default_value", type, editing_node, editing_port, vsn->get_input_port_default_value(editing_port));
undo_redo->commit_action();
property_editor->hide();
}
void VisualShaderEditor::_edit_port_default_input(Object *p_button, int p_node, int p_port) {
VisualShader::Type type = get_current_shader_type();
Ref<VisualShaderNode> vs_node = visual_shader->get_node(type, p_node);
Variant value = vs_node->get_input_port_default_value(p_port);
Ref<VisualShaderNode> vsn = visual_shader->get_node(type, p_node);
edited_property_holder->set_edited_property(value);
if (property_editor) {
property_editor->disconnect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
property_editor_popup->remove_child(property_editor);
}
// TODO: Define these properties with actual PropertyInfo and feed it to the property editor widget.
property_editor = EditorInspector::instantiate_property_editor(edited_property_holder.ptr(), value.get_type(), "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE);
if (property_editor) {
property_editor->set_object_and_property(edited_property_holder.ptr(), "edited_property");
property_editor->update_property();
property_editor->set_name_split_ratio(0);
property_editor_popup->add_child(property_editor);
property_editor->connect("property_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
Button *button = Object::cast_to<Button>(p_button);
if (button) {
property_editor_popup->set_position(button->get_screen_position() + Vector2(0, button->get_size().height) * graph->get_zoom());
}
property_editor_popup->reset_size();
if (button) {
property_editor_popup->popup();
} else {
property_editor_popup->popup_centered_ratio();
}
}
Button *button = Object::cast_to<Button>(p_button);
ERR_FAIL_COND(!button);
Variant value = vsn->get_input_port_default_value(p_port);
property_editor->set_position(button->get_screen_position() + Vector2(0, button->get_size().height));
property_editor->edit(nullptr, "", value.get_type(), value, 0, "");
property_editor->popup();
editing_node = p_node;
editing_port = p_port;
}
@ -5636,10 +5666,11 @@ VisualShaderEditor::VisualShaderEditor() {
graph_plugin.instantiate();
graph_plugin->set_editor(this);
property_editor = memnew(CustomPropertyEditor);
add_child(property_editor);
property_editor_popup = memnew(PopupPanel);
property_editor_popup->set_min_size(Size2i(180, 0) * EDSCALE);
add_child(property_editor_popup);
property_editor->connect("variant_changed", callable_mp(this, &VisualShaderEditor::_port_edited));
edited_property_holder.instantiate();
}
class VisualShaderNodePluginInputEditor : public OptionButton {

View File

@ -32,17 +32,21 @@
#define VISUAL_SHADER_EDITOR_PLUGIN_H
#include "editor/editor_plugin.h"
#include "editor/plugins/curve_editor_plugin.h"
#include "editor/plugins/editor_resource_conversion_plugin.h"
#include "editor/property_editor.h"
#include "scene/gui/button.h"
#include "scene/gui/code_edit.h"
#include "scene/gui/graph_edit.h"
#include "scene/gui/popup.h"
#include "scene/gui/rich_text_label.h"
#include "scene/gui/tree.h"
#include "scene/resources/visual_shader.h"
class Button;
class CodeEdit;
class CodeHighlighter;
class CurveEditor;
class GraphEdit;
class GraphNode;
class PopupMenu;
class PopupPanel;
class RichTextLabel;
class TextEdit;
class Tree;
class VisualShaderEditor;
class VisualShaderNodePlugin : public RefCounted {
@ -138,13 +142,31 @@ public:
~VisualShaderGraphPlugin();
};
class VisualShaderEditedProperty : public RefCounted {
GDCLASS(VisualShaderEditedProperty, RefCounted);
private:
Variant edited_property;
protected:
static void _bind_methods();
public:
void set_edited_property(Variant p_variant);
Variant get_edited_property() const;
VisualShaderEditedProperty() {}
};
class VisualShaderEditor : public VBoxContainer {
GDCLASS(VisualShaderEditor, VBoxContainer);
friend class VisualShaderGraphPlugin;
CustomPropertyEditor *property_editor = nullptr;
PopupPanel *property_editor_popup = nullptr;
EditorProperty *property_editor = nullptr;
int editing_node = -1;
int editing_port = -1;
Ref<VisualShaderEditedProperty> edited_property_holder;
Ref<VisualShader> visual_shader;
GraphEdit *graph = nullptr;
@ -359,7 +381,7 @@ class VisualShaderEditor : public VBoxContainer {
void _node_changed(int p_id);
void _edit_port_default_input(Object *p_button, int p_node, int p_port);
void _port_edited();
void _port_edited(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
int to_node = -1;
int to_slot = -1;

File diff suppressed because it is too large Load Diff

View File

@ -1,168 +0,0 @@
/*************************************************************************/
/* property_editor.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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. */
/*************************************************************************/
#ifndef PROPERTY_EDITOR_H
#define PROPERTY_EDITOR_H
#include "editor/editor_locale_dialog.h"
#include "editor/scene_tree_editor.h"
#include "scene/gui/button.h"
#include "scene/gui/check_box.h"
#include "scene/gui/check_button.h"
#include "scene/gui/color_picker.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/grid_container.h"
#include "scene/gui/label.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/split_container.h"
#include "scene/gui/text_edit.h"
#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"
class CreateDialog;
class EditorFileDialog;
class PropertyValueEvaluator;
class PropertySelector;
class CustomPropertyEditor : public PopupPanel {
GDCLASS(CustomPropertyEditor, PopupPanel);
enum {
MAX_VALUE_EDITORS = 12,
MAX_ACTION_BUTTONS = 5,
OBJ_MENU_LOAD = 0,
OBJ_MENU_EDIT = 1,
OBJ_MENU_CLEAR = 2,
OBJ_MENU_MAKE_UNIQUE = 3,
OBJ_MENU_COPY = 4,
OBJ_MENU_PASTE = 5,
OBJ_MENU_NEW_SCRIPT = 6,
OBJ_MENU_EXTEND_SCRIPT = 7,
OBJ_MENU_SHOW_IN_FILE_SYSTEM = 8,
TYPE_BASE_ID = 100,
CONVERT_BASE_ID = 1000
};
enum {
EASING_LINEAR,
EASING_EASE_IN,
EASING_EASE_OUT,
EASING_ZERO,
EASING_IN_OUT,
EASING_OUT_IN
};
PopupMenu *menu = nullptr;
SceneTreeDialog *scene_tree = nullptr;
EditorFileDialog *file = nullptr;
EditorLocaleDialog *locale = nullptr;
ConfirmationDialog *error = nullptr;
String name;
Variant::Type type;
Variant v;
List<String> field_names;
int hint = 0;
String hint_text;
HBoxContainer *value_hboxes[MAX_VALUE_EDITORS / 4];
VBoxContainer *value_vbox = nullptr;
LineEdit *value_editor[MAX_VALUE_EDITORS];
int focused_value_editor;
Label *value_label[MAX_VALUE_EDITORS];
HScrollBar *scroll[4];
HBoxContainer *action_hboxes = nullptr;
Button *action_buttons[MAX_ACTION_BUTTONS];
MenuButton *type_button = nullptr;
Vector<String> inheritors_array;
TextureRect *texture_preview = nullptr;
ColorPicker *color_picker = nullptr;
TextEdit *text_edit = nullptr;
bool read_only = false;
bool picking_viewport = false;
GridContainer *checks20gc = nullptr;
CheckBox *checks20[20];
SpinBox *spinbox = nullptr;
HSlider *slider = nullptr;
Control *easing_draw = nullptr;
CreateDialog *create_dialog = nullptr;
PropertySelector *property_select = nullptr;
Object *owner = nullptr;
bool updating = false;
PropertyValueEvaluator *evaluator = nullptr;
void _text_edit_changed();
void _file_selected(String p_file);
void _locale_selected(String p_locale);
void _modified(String p_string);
real_t _parse_real_expression(String text);
void _range_modified(double p_value);
void _focus_enter();
void _focus_exit();
void _action_pressed(int p_which);
void _type_create_selected(int p_idx);
void _create_dialog_callback();
void _create_selected_property(const String &p_prop);
void _color_changed(const Color &p_color);
void _draw_easing();
void _menu_option(int p_which);
void _drag_easing(const Ref<InputEvent> &p_ev);
void _node_path_selected(NodePath p_path);
void show_value_editors(int p_amount);
void config_value_editors(int p_amount, int p_columns, int p_label_w, const List<String> &p_strings);
void config_action_buttons(const List<String> &p_strings);
void _emit_changed_whole_or_field();
protected:
void _notification(int p_what);
static void _bind_methods();
public:
void hide_menu();
Variant get_variant() const;
String get_name() const;
void set_read_only(bool p_read_only) { read_only = p_read_only; }
bool edit(Object *p_owner, const String &p_name, Variant::Type p_type, const Variant &p_variant, int p_hint, String p_hint_text);
CustomPropertyEditor();
};
#endif // PROPERTY_EDITOR_H

View File

@ -42,10 +42,32 @@
#include "editor/editor_node.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/gui/check_button.h"
#include "scene/gui/graph_edit.h"
#include "scene/gui/separator.h"
#include "scene/gui/view_panner.h"
#include "scene/main/window.h"
#ifdef TOOLS_ENABLED
void VisualScriptEditedProperty::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_edited_property", "value"), &VisualScriptEditedProperty::set_edited_property);
ClassDB::bind_method(D_METHOD("get_edited_property"), &VisualScriptEditedProperty::get_edited_property);
ADD_PROPERTY(PropertyInfo(Variant::NIL, "edited_property", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_edited_property", "get_edited_property");
}
void VisualScriptEditedProperty::set_edited_property(Variant p_variant) {
edited_property = p_variant;
}
Variant VisualScriptEditedProperty::get_edited_property() const {
return edited_property;
}
/////////////////
class VisualScriptEditorSignalEdit : public Object {
GDCLASS(VisualScriptEditorSignalEdit, Object);
@ -3898,14 +3920,14 @@ int VisualScriptEditor::_create_new_node_from_name(const String &p_text, const V
return new_id;
}
void VisualScriptEditor::_default_value_changed() {
void VisualScriptEditor::_default_value_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
Ref<VisualScriptNode> vsn = script->get_node(editing_id);
if (vsn.is_null()) {
return;
}
undo_redo->create_action(TTR("Change Input Value"));
undo_redo->add_do_method(vsn.ptr(), "set_default_input_value", editing_input, default_value_edit->get_variant());
undo_redo->add_do_method(vsn.ptr(), "set_default_input_value", editing_input, p_value);
undo_redo->add_undo_method(vsn.ptr(), "set_default_input_value", editing_input, vsn->get_default_input_value(editing_input));
undo_redo->add_do_method(this, "_update_graph", editing_id);
@ -3928,9 +3950,6 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i
Variant::construct(pinfo.type, existing, &existingp, 1, ce);
}
default_value_edit->set_position(Object::cast_to<Control>(p_button)->get_screen_position() + Vector2(0, Object::cast_to<Control>(p_button)->get_size().y) * graph->get_zoom());
default_value_edit->reset_size();
if (pinfo.type == Variant::NODE_PATH) {
Node *edited_scene = get_tree()->get_edited_scene_root();
if (edited_scene) { // Fixing an old crash bug ( Visual Script Crashes on editing NodePath with an empty scene open).
@ -3948,11 +3967,33 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i
}
}
if (default_value_edit->edit(nullptr, pinfo.name, pinfo.type, existing, pinfo.hint, pinfo.hint_string)) {
if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) {
default_value_edit->popup_centered_ratio();
edited_default_property_holder->set_edited_property(existing);
if (default_property_editor) {
default_property_editor->disconnect("property_changed", callable_mp(this, &VisualScriptEditor::_default_value_changed));
default_property_editor_popup->remove_child(default_property_editor);
}
default_property_editor = EditorInspector::instantiate_property_editor(edited_default_property_holder.ptr(), pinfo.type, "edited_property", pinfo.hint, pinfo.hint_string, PROPERTY_USAGE_NONE);
if (default_property_editor) {
default_property_editor->set_object_and_property(edited_default_property_holder.ptr(), "edited_property");
default_property_editor->update_property();
default_property_editor->set_name_split_ratio(0);
default_property_editor_popup->add_child(default_property_editor);
default_property_editor->connect("property_changed", callable_mp(this, &VisualScriptEditor::_default_value_changed));
Button *button = Object::cast_to<Button>(p_button);
if (button) {
default_property_editor_popup->set_position(button->get_screen_position() + Vector2(0, button->get_size().height) * graph->get_zoom());
}
default_property_editor_popup->reset_size();
if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT || !button) {
default_property_editor_popup->popup_centered_ratio();
} else {
default_value_edit->popup();
default_property_editor_popup->popup();
}
}
@ -4795,9 +4836,11 @@ VisualScriptEditor::VisualScriptEditor() {
set_process_input(true);
default_value_edit = memnew(CustomPropertyEditor);
add_child(default_value_edit);
default_value_edit->connect("variant_changed", callable_mp(this, &VisualScriptEditor::_default_value_changed));
default_property_editor_popup = memnew(PopupPanel);
default_property_editor_popup->set_min_size(Size2i(180, 0) * EDSCALE);
add_child(default_property_editor_popup);
edited_default_property_holder.instantiate();
new_connect_node_select = memnew(VisualScriptPropertySelector);
add_child(new_connect_node_select);

View File

@ -34,15 +34,31 @@
#include "../visual_script.h"
#include "editor/create_dialog.h"
#include "editor/plugins/script_editor_plugin.h"
#include "editor/property_editor.h"
#include "scene/gui/graph_edit.h"
#include "visual_script_property_selector.h"
class GraphEdit;
class VisualScriptEditorSignalEdit;
class VisualScriptEditorVariableEdit;
#ifdef TOOLS_ENABLED
class VisualScriptEditedProperty : public RefCounted {
GDCLASS(VisualScriptEditedProperty, RefCounted);
private:
Variant edited_property;
protected:
static void _bind_methods();
public:
void set_edited_property(Variant p_variant);
Variant get_edited_property() const;
VisualScriptEditedProperty() {}
};
// TODO: Maybe this class should be refactored.
// See https://github.com/godotengine/godot/issues/51913
class VisualScriptEditor : public ScriptEditorBase {
@ -115,7 +131,9 @@ class VisualScriptEditor : public ScriptEditorBase {
AcceptDialog *edit_variable_dialog = nullptr;
EditorInspector *edit_variable_edit = nullptr;
CustomPropertyEditor *default_value_edit = nullptr;
PopupPanel *default_property_editor_popup = nullptr;
EditorProperty *default_property_editor = nullptr;
Ref<VisualScriptEditedProperty> edited_default_property_holder;
UndoRedo *undo_redo = nullptr;
@ -276,7 +294,7 @@ class VisualScriptEditor : public ScriptEditorBase {
int data_disconnect_node = 0;
int data_disconnect_port = 0;
void _default_value_changed();
void _default_value_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
void _default_value_edited(Node *p_button, int p_id, int p_input_port);
void _menu_option(int p_what);