Editor: Dim UI when a WindowDialog is shown.

Darkens the editor on WindowDialog popup.

This adds the following new Editor settings:

- interface/dim_editor_on_dialog_popup (true) # Enable/Disable editor dimming
- interface/dim_amount (0.6) # Percentage of how much the editor will be darkened (0-1)
- interface/dim_transition_time # The duration (in seconds) of the color blending effect (0-1), 0 is instant.

Please test this thoroughly, I haven't yet seen a case where it fails to work properly but I'm sure I didn't test all
windows of the editor :P
This commit is contained in:
Andreas Haas 2017-03-06 20:11:56 +01:00
parent 15c4d5006e
commit 9080232f17
No known key found for this signature in database
GPG key ID: B5FFAE1B65FBD2E1
4 changed files with 74 additions and 0 deletions

View file

@ -4716,6 +4716,44 @@ void EditorNode::_open_imported() {
load_scene(open_import_request, true, false, true, true);
}
void EditorNode::dim_editor(bool p_dimming) {
static int dim_count = 0;
bool dim_ui = EditorSettings::get_singleton()->get("interface/dim_editor_on_dialog_popup");
if (p_dimming) {
if (dim_ui && dim_count == 0)
_start_dimming(true);
dim_count++;
} else {
dim_count--;
if (dim_count < 1)
_start_dimming(false);
}
}
void EditorNode::_start_dimming(bool p_dimming) {
_dimming = p_dimming;
_dim_time = 0.0f;
_dim_timer->start();
}
void EditorNode::_dim_timeout() {
_dim_time += _dim_timer->get_wait_time();
float wait_time = EditorSettings::get_singleton()->get("interface/dim_transition_time");
float c = 1.0f - (float)EditorSettings::get_singleton()->get("interface/dim_amount");
Color base = _dimming ? Color(1, 1, 1) : Color(c, c, c);
Color final = _dimming ? Color(c, c, c) : Color(1, 1, 1);
if (_dim_time + _dim_timer->get_wait_time() >= wait_time) {
gui_base->set_modulate(final);
_dim_timer->stop();
} else {
gui_base->set_modulate(base.linear_interpolate(final, _dim_time / wait_time));
}
}
void EditorNode::_bind_methods() {
ClassDB::bind_method("_menu_option", &EditorNode::_menu_option);
@ -4792,6 +4830,7 @@ void EditorNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("_open_imported"), &EditorNode::_open_imported);
ClassDB::bind_method(D_METHOD("_inherit_imported"), &EditorNode::_inherit_imported);
ClassDB::bind_method(D_METHOD("_dim_timeout"), &EditorNode::_dim_timeout);
ADD_SIGNAL(MethodInfo("play_pressed"));
ADD_SIGNAL(MethodInfo("pause_pressed"));
@ -6102,6 +6141,13 @@ EditorNode::EditorNode() {
FileAccess::set_file_close_fail_notify_callback(_file_access_close_error_notify);
waiting_for_first_scan = true;
_dimming = false;
_dim_time = 0.0f;
_dim_timer = memnew(Timer);
_dim_timer->set_wait_time(0.01666f);
_dim_timer->connect("timeout", this, "_dim_timeout");
add_child(_dim_timer);
}
EditorNode::~EditorNode() {

View file

@ -598,6 +598,13 @@ private:
void _tool_menu_insert_item(const ToolMenuItem &p_item);
void _rebuild_tool_menu() const;
bool _dimming;
float _dim_time;
Timer *_dim_timer;
void _start_dimming(bool p_dimming);
void _dim_timeout();
protected:
void _notification(int p_what);
static void _bind_methods();
@ -753,6 +760,8 @@ public:
void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
void remove_tool_menu_item(const String &p_name);
void dim_editor(bool p_dimming);
EditorNode();
~EditorNode();
void get_singleton(const char *arg1, bool arg2);

View file

@ -502,6 +502,11 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
hints["interface/custom_font"] = PropertyInfo(Variant::STRING, "interface/custom_font", PROPERTY_HINT_GLOBAL_FILE, "*.fnt", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
set("interface/custom_theme", "");
hints["interface/custom_theme"] = PropertyInfo(Variant::STRING, "interface/custom_theme", PROPERTY_HINT_GLOBAL_FILE, "*.res,*.tres,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED);
set("interface/dim_editor_on_dialog_popup", true);
set("interface/dim_amount", 0.6f);
hints["interface/dim_amount"] = PropertyInfo(Variant::REAL, "interface/dim_amount", PROPERTY_HINT_RANGE, "0,1,0.01", PROPERTY_USAGE_DEFAULT);
set("interface/dim_transition_time", 0.11f);
hints["interface/dim_transition_time"] = PropertyInfo(Variant::REAL, "interface/dim_transition_time", PROPERTY_HINT_RANGE, "0,1,0.001", PROPERTY_USAGE_DEFAULT);
set("filesystem/directories/autoscan_project_path", "");
hints["filesystem/directories/autoscan_project_path"] = PropertyInfo(Variant::STRING, "filesystem/directories/autoscan_project_path", PROPERTY_HINT_GLOBAL_DIR);

View file

@ -31,6 +31,10 @@
#include "print_string.h"
#include "translation.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_node.h"
#endif
void WindowDialog::_post_popup() {
drag_type = DRAG_NONE; // just in case
@ -199,6 +203,16 @@ void WindowDialog::_notification(int p_what) {
set_default_cursor_shape(CURSOR_ARROW);
}
} break;
#ifdef TOOLS_ENABLED
case NOTIFICATION_POST_POPUP: {
if (get_tree() && get_tree()->is_editor_hint())
EditorNode::get_singleton()->dim_editor(true);
} break;
case NOTIFICATION_POPUP_HIDE: {
if (get_tree() && get_tree()->is_editor_hint())
EditorNode::get_singleton()->dim_editor(false);
} break;
#endif
}
}