瀏覽代碼

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.
Rémi Verschelde 8 年之前
父節點
當前提交
3552755306
共有 2 個文件被更改,包括 15 次插入9 次删除
  1. 14 9
      editor/plugins/tile_map_editor_plugin.cpp
  2. 1 0
      editor/plugins/tile_map_editor_plugin.h

+ 14 - 9
editor/plugins/tile_map_editor_plugin.cpp

@@ -52,8 +52,15 @@ void TileMapEditor::_notification(int p_what) {
 			rotate_270->set_icon(get_icon("Rotate270", "EditorIcons"));
 			rotate_270->set_icon(get_icon("Rotate270", "EditorIcons"));
 
 
 		} break;
 		} break;
+
 		case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
 		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()) {
 			if (is_visible()) {
 				_update_palette();
 				_update_palette();
 			}
 			}
@@ -912,18 +919,15 @@ bool TileMapEditor::forward_input_event(const InputEvent &p_event) {
 				canvas_item_editor->update();
 				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->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]");
 				tile_info->show();
 				tile_info->show();
 			}
 			}
-			else {
-				tile_info->hide();
-			}
 
 
 			if (tool == TOOL_PAINTING) {
 			if (tool == TOOL_PAINTING) {
 
 
@@ -1448,6 +1452,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) {
 	tool = TOOL_NONE;
 	tool = TOOL_NONE;
 	selection_active = false;
 	selection_active = false;
 	mouse_over = false;
 	mouse_over = false;
+	show_tile_info = true;
 
 
 	flip_h = false;
 	flip_h = false;
 	flip_v = 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/show_tile_ids", true);
 	EDITOR_DEF("tile_map/sort_tiles_by_name", false);
 	EDITOR_DEF("tile_map/sort_tiles_by_name", false);
 	EDITOR_DEF("tile_map/bucket_fill_preview", true);
 	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));
 	tile_map_editor = memnew(TileMapEditor(p_node));
 	add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE, tile_map_editor);
 	add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE, tile_map_editor);

+ 1 - 0
editor/plugins/tile_map_editor_plugin.h

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