diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-06-28 01:08:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-28 01:08:24 +0200 |
commit | b863c40356b4b95192d1a1e2718db7d7aced4235 (patch) | |
tree | f07da843fb5c9a1c034abf526030c7b21f2777f2 /editor | |
parent | 8fd0b4d1f84867c6727e2e233ad08b1fed801eb7 (diff) | |
parent | 9ddebc0c22866d6b7a7ff3fa64b67cc86c8664da (diff) |
Merge pull request #62468 from V-Sekai/core-const-expressions
Add a const call mode to Object, Variant and Script.
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_properties.cpp | 14 | ||||
-rw-r--r-- | editor/editor_properties.h | 3 | ||||
-rw-r--r-- | editor/editor_spin_slider.cpp | 2 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 2 | ||||
-rw-r--r-- | editor/property_editor.cpp | 4 |
5 files changed, 19 insertions, 6 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 0e6c9162ce..e5105fdedc 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -165,6 +165,9 @@ void EditorPropertyMultilineText::_notification(int p_what) { Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); int font_size = get_theme_font_size(SNAME("font_size"), SNAME("Label")); text->set_custom_minimum_size(Vector2(0, font->get_height(font_size) * 6)); + text->add_theme_font_override("font", get_theme_font("expression", "EditorFonts")); + text->add_theme_font_size_override("font_size", get_theme_font_size("expression_size", "EditorFonts")); + } break; } } @@ -172,7 +175,7 @@ void EditorPropertyMultilineText::_notification(int p_what) { void EditorPropertyMultilineText::_bind_methods() { } -EditorPropertyMultilineText::EditorPropertyMultilineText() { +EditorPropertyMultilineText::EditorPropertyMultilineText(bool p_expression) { HBoxContainer *hb = memnew(HBoxContainer); hb->add_theme_constant_override("separation", 0); add_child(hb); @@ -189,6 +192,12 @@ EditorPropertyMultilineText::EditorPropertyMultilineText() { hb->add_child(open_big_text); big_text_dialog = nullptr; big_text = nullptr; + if (p_expression) { + expression = true; + Ref<EditorStandardSyntaxHighlighter> highlighter; + highlighter.instantiate(); + text->set_syntax_highlighter(highlighter); + } } ///////////////////// TEXT ENUM ///////////////////////// @@ -3771,6 +3780,9 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_ } else if (p_hint == PROPERTY_HINT_MULTILINE_TEXT) { EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText); return editor; + } else if (p_hint == PROPERTY_HINT_EXPRESSION) { + EditorPropertyMultilineText *editor = memnew(EditorPropertyMultilineText(true)); + return editor; } else if (p_hint == PROPERTY_HINT_TYPE_STRING) { EditorPropertyClassName *editor = memnew(EditorPropertyClassName); editor->setup("Object", p_hint_text); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 72b2b0b283..7cd6ea4f6b 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -81,6 +81,7 @@ class EditorPropertyMultilineText : public EditorProperty { void _big_text_changed(); void _text_changed(); void _open_big_text(); + bool expression = false; protected: virtual void _set_read_only(bool p_read_only) override; @@ -89,7 +90,7 @@ protected: public: virtual void update_property() override; - EditorPropertyMultilineText(); + EditorPropertyMultilineText(bool p_expression = false); }; class EditorPropertyTextEnum : public EditorProperty { diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index a0c818ba84..f23f0cf758 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -530,7 +530,7 @@ void EditorSpinSlider::_evaluate_input_text() { return; } - Variant v = expr->execute(Array(), nullptr, false); + Variant v = expr->execute(Array(), nullptr, false, true); if (v.get_type() == Variant::NIL) { return; } diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 05c707c065..7d4ffd1a25 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -1196,7 +1196,7 @@ void ScriptTextEditor::_edit_option(int p_op) { String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning if (expression.parse(line) == OK) { - Variant result = expression.execute(Array(), Variant(), false); + Variant result = expression.execute(Array(), Variant(), false, true); if (expression.get_error_text().is_empty()) { results.push_back(whitespace + result.get_construct_string()); } else { diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 771d34d841..d936e821df 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -1474,7 +1474,7 @@ void CustomPropertyEditor::_modified(String p_string) { v = value_editor[0]->get_text().to_int(); return; } else { - v = expr->execute(Array(), nullptr, false); + v = expr->execute(Array(), nullptr, false, false); } if (v != prev_v) { @@ -1650,7 +1650,7 @@ real_t CustomPropertyEditor::_parse_real_expression(String text) { if (err != OK) { out = value_editor[0]->get_text().to_float(); } else { - out = expr->execute(Array(), nullptr, false); + out = expr->execute(Array(), nullptr, false, true); } return out; } |