summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/classes/Viewport.xml17
-rw-r--r--editor/action_map_editor.cpp33
-rw-r--r--editor/action_map_editor.h3
3 files changed, 34 insertions, 19 deletions
diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml
index ce466b2d0f..148c6d7064 100644
--- a/doc/classes/Viewport.xml
+++ b/doc/classes/Viewport.xml
@@ -75,17 +75,12 @@
<return type="ViewportTexture" />
<description>
Returns the viewport's texture.
- [b]Note:[/b] Due to the way OpenGL works, the resulting [ViewportTexture] is flipped vertically. You can use [method Image.flip_y] on the result of [method Texture2D.get_image] to flip it back, for example:
- [codeblocks]
- [gdscript]
- var img = get_viewport().get_texture().get_image()
- img.flip_y()
- [/gdscript]
- [csharp]
- Image img = GetViewport().GetTexture().GetImage();
- img.FlipY();
- [/csharp]
- [/codeblocks]
+ [b]Note:[/b] When trying to store the current texture (e.g. in a file), it might be completely black or outdated if used too early, especially when used in e.g. [method Node._ready]. To make sure the texture you get is correct, you can await [signal RenderingServer.frame_post_draw] signal.
+ [codeblock]
+ func _ready():
+ await RenderingServer.frame_post_draw
+ $Viewport.get_texture().get_image().save_png("user://Screenshot.png")
+ [/codeblock]
</description>
</method>
<method name="get_viewport_rid" qualifiers="const">
diff --git a/editor/action_map_editor.cpp b/editor/action_map_editor.cpp
index 49c79d709b..01be5ae4fe 100644
--- a/editor/action_map_editor.cpp
+++ b/editor/action_map_editor.cpp
@@ -791,6 +791,24 @@ void ActionMapEditor::_add_action_pressed() {
_add_action(add_edit->get_text());
}
+String ActionMapEditor::_check_new_action_name(const String &p_name) {
+ if (p_name.is_empty() || !_is_action_name_valid(p_name)) {
+ return TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'");
+ }
+
+ if (_has_action(p_name)) {
+ return vformat(TTR("An action with the name '%s' already exists."), p_name);
+ }
+
+ return "";
+}
+
+void ActionMapEditor::_add_edit_text_changed(const String &p_name) {
+ String error = _check_new_action_name(p_name);
+ add_button->set_tooltip(error);
+ add_button->set_disabled(!error.is_empty());
+}
+
bool ActionMapEditor::_has_action(const String &p_name) const {
for (const ActionInfo &action_info : actions_cache) {
if (p_name == action_info.name) {
@@ -801,13 +819,9 @@ bool ActionMapEditor::_has_action(const String &p_name) const {
}
void ActionMapEditor::_add_action(const String &p_name) {
- if (p_name.is_empty() || !_is_action_name_valid(p_name)) {
- show_message(TTR("Invalid action name. It cannot be empty nor contain '/', ':', '=', '\\' or '\"'"));
- return;
- }
-
- if (_has_action(p_name)) {
- show_message(vformat(TTR("An action with the name '%s' already exists."), p_name));
+ String error = _check_new_action_name(p_name);
+ if (!error.is_empty()) {
+ show_message(error);
return;
}
@@ -1208,13 +1222,16 @@ ActionMapEditor::ActionMapEditor() {
add_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL);
add_edit->set_placeholder(TTR("Add New Action"));
add_edit->set_clear_button_enabled(true);
+ add_edit->connect("text_changed", callable_mp(this, &ActionMapEditor::_add_edit_text_changed));
add_edit->connect("text_submitted", callable_mp(this, &ActionMapEditor::_add_action));
add_hbox->add_child(add_edit);
- Button *add_button = memnew(Button);
+ add_button = memnew(Button);
add_button->set_text(TTR("Add"));
add_button->connect("pressed", callable_mp(this, &ActionMapEditor::_add_action_pressed));
add_hbox->add_child(add_button);
+ // Disable the button and set its tooltip.
+ _add_edit_text_changed(add_edit->get_text());
main_vbox->add_child(add_hbox);
diff --git a/editor/action_map_editor.h b/editor/action_map_editor.h
index b676c55403..15a1501a67 100644
--- a/editor/action_map_editor.h
+++ b/editor/action_map_editor.h
@@ -171,10 +171,13 @@ private:
HBoxContainer *add_hbox = nullptr;
LineEdit *add_edit = nullptr;
+ Button *add_button = nullptr;
void _event_config_confirmed();
void _add_action_pressed();
+ void _add_edit_text_changed(const String &p_name);
+ String _check_new_action_name(const String &p_name);
bool _has_action(const String &p_name) const;
void _add_action(const String &p_name);
void _action_edited();