TileMap Editor: Improve tile info setting using signal

The event-based approach avoids the need to query editor settings
and call show/hide on the Control at every mouse input.

Improves #9141.
This commit is contained in:
Rémi Verschelde 2017-08-16 19:58:16 +02:00
parent 29632aadfd
commit 3552755306
2 changed files with 15 additions and 9 deletions

View file

@ -52,8 +52,15 @@ void TileMapEditor::_notification(int p_what) {
rotate_270->set_icon(get_icon("Rotate270", "EditorIcons"));
} break;
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
bool new_show_tile_info = EditorSettings::get_singleton()->get("tile_map/show_tile_info_on_hover");
if (new_show_tile_info != show_tile_info) {
show_tile_info = new_show_tile_info;
tile_info->set_hidden(!show_tile_info);
}
if (is_visible()) {
_update_palette();
}
@ -912,18 +919,15 @@ bool TileMapEditor::forward_input_event(const InputEvent &p_event) {
canvas_item_editor->update();
}
int tile_under = node->get_cell(over_tile.x, over_tile.y);
String tile_name = "none";
if (show_tile_info) {
int tile_under = node->get_cell(over_tile.x, over_tile.y);
String tile_name = "none";
if (node->get_tileset()->has_tile(tile_under))
tile_name = node->get_tileset()->tile_get_name(tile_under);
if (bool(EDITOR_DEF("tile_map/show_tile_info_under_cursor", true))) {
if (node->get_tileset()->has_tile(tile_under))
tile_name = node->get_tileset()->tile_get_name(tile_under);
tile_info->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]");
tile_info->show();
}
else {
tile_info->hide();
}
if (tool == TOOL_PAINTING) {
@ -1448,6 +1452,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
tool = TOOL_NONE;
selection_active = false;
mouse_over = false;
show_tile_info = true;
flip_h = false;
flip_v = false;
@ -1610,7 +1615,7 @@ TileMapEditorPlugin::TileMapEditorPlugin(EditorNode *p_node) {
EDITOR_DEF("tile_map/show_tile_ids", true);
EDITOR_DEF("tile_map/sort_tiles_by_name", false);
EDITOR_DEF("tile_map/bucket_fill_preview", true);
EDITOR_DEF("tile_map/show_tile_info_under_cursor", true);
EDITOR_DEF("tile_map/show_tile_info_on_hover", true);
tile_map_editor = memnew(TileMapEditor(p_node));
add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE, tile_map_editor);

View file

@ -97,6 +97,7 @@ class TileMapEditor : public VBoxContainer {
bool selection_active;
bool mouse_over;
bool show_tile_info;
bool flip_h;
bool flip_v;