@@ -4246,108 +4246,113 @@ void TileMapLayerEditor::_draw_overlay() {
42464246 Transform2D xform_inv = xform.affine_inverse ();
42474247 Vector2i tile_shape_size = tile_set->get_tile_size ();
42484248
4249- // Draw tiles with invalid IDs in the grid.
4250- TypedArray<Vector2i> used_cells = edited_layer->get_used_cells ();
4251- for (int i = 0 ; i < used_cells.size (); i++) {
4252- Vector2i coords = used_cells[i];
4253- int tile_source_id = edited_layer->get_cell_source_id (coords);
4254- if (tile_source_id >= 0 ) {
4255- Vector2i tile_atlas_coords = edited_layer->get_cell_atlas_coords (coords);
4256- int tile_alternative_tile = edited_layer->get_cell_alternative_tile (coords);
4257-
4258- TileSetSource *source = nullptr ;
4259- if (tile_set->has_source (tile_source_id)) {
4260- source = *tile_set->get_source (tile_source_id);
4261- }
4262-
4263- if (!source || !source->has_tile (tile_atlas_coords) || !source->has_alternative_tile (tile_atlas_coords, tile_alternative_tile)) {
4264- // Generate a random color from the hashed identifier of the tiles.
4265- Array to_hash = { tile_source_id, tile_atlas_coords, tile_alternative_tile };
4266- uint32_t hash = RandomPCG (to_hash.hash ()).rand ();
4267-
4268- Color color;
4269- color = color.from_hsv (
4270- (float )((hash >> 24 ) & 0xFF ) / 256.0 ,
4271- Math::lerp (0.5 , 1.0 , (float )((hash >> 16 ) & 0xFF ) / 256.0 ),
4272- Math::lerp (0.5 , 1.0 , (float )((hash >> 8 ) & 0xFF ) / 256.0 ),
4273- 0.8 );
4249+ // Fade the overlay out when size too small.
4250+ Vector2 hint_distance = xform.get_scale () * tile_shape_size;
4251+ float scale_fading = MIN (1 , (MIN (hint_distance.x , hint_distance.y ) - 5 ) / 5 );
4252+ if (scale_fading > 0 ) {
4253+ // Draw tiles with invalid IDs in the grid.
4254+ TypedArray<Vector2i> used_cells = edited_layer->get_used_cells ();
4255+ for (int i = 0 ; i < used_cells.size (); i++) {
4256+ Vector2i coords = used_cells[i];
4257+ int tile_source_id = edited_layer->get_cell_source_id (coords);
4258+ if (tile_source_id >= 0 ) {
4259+ Vector2i tile_atlas_coords = edited_layer->get_cell_atlas_coords (coords);
4260+ int tile_alternative_tile = edited_layer->get_cell_alternative_tile (coords);
4261+
4262+ TileSetSource *source = nullptr ;
4263+ if (tile_set->has_source (tile_source_id)) {
4264+ source = *tile_set->get_source (tile_source_id);
4265+ }
42744266
4275- // Display the warning pattern.
4276- Transform2D tile_xform;
4277- tile_xform.set_origin (tile_set->map_to_local (coords));
4278- tile_xform.set_scale (tile_shape_size);
4279- tile_set->draw_tile_shape (custom_overlay, xform * tile_xform, color, true , warning_pattern_texture);
4280-
4281- // Draw the warning icon.
4282- Vector2::Axis min_axis = missing_tile_texture->get_size ().min_axis_index ();
4283- Vector2 icon_size;
4284- icon_size[min_axis] = tile_set->get_tile_size ()[min_axis] / 3 ;
4285- icon_size[(min_axis + 1 ) % 2 ] = (icon_size[min_axis] * missing_tile_texture->get_size ()[(min_axis + 1 ) % 2 ] / missing_tile_texture->get_size ()[min_axis]);
4286- Rect2 rect = Rect2 (xform.xform (tile_set->map_to_local (coords)) - (icon_size * xform.get_scale () / 2 ), icon_size * xform.get_scale ());
4287- custom_overlay->draw_texture_rect (missing_tile_texture, rect);
4267+ if (!source || !source->has_tile (tile_atlas_coords) || !source->has_alternative_tile (tile_atlas_coords, tile_alternative_tile)) {
4268+ // Generate a random color from the hashed identifier of the tiles.
4269+ Array to_hash = { tile_source_id, tile_atlas_coords, tile_alternative_tile };
4270+ uint32_t hash = RandomPCG (to_hash.hash ()).rand ();
4271+
4272+ Color color;
4273+ color = color.from_hsv (
4274+ (float )((hash >> 24 ) & 0xFF ) / 256.0 ,
4275+ Math::lerp (0.5 , 1.0 , (float )((hash >> 16 ) & 0xFF ) / 256.0 ),
4276+ Math::lerp (0.5 , 1.0 , (float )((hash >> 8 ) & 0xFF ) / 256.0 ),
4277+ 0.8 * scale_fading);
4278+
4279+ // Display the warning pattern.
4280+ Transform2D tile_xform;
4281+ tile_xform.set_origin (tile_set->map_to_local (coords));
4282+ tile_xform.set_scale (tile_shape_size);
4283+ tile_set->draw_tile_shape (custom_overlay, xform * tile_xform, color, true , warning_pattern_texture);
4284+
4285+ // Draw the warning icon.
4286+ Vector2::Axis min_axis = missing_tile_texture->get_size ().min_axis_index ();
4287+ Vector2 icon_size;
4288+ icon_size[min_axis] = tile_set->get_tile_size ()[min_axis] / 3 ;
4289+ icon_size[(min_axis + 1 ) % 2 ] = (icon_size[min_axis] * missing_tile_texture->get_size ()[(min_axis + 1 ) % 2 ] / missing_tile_texture->get_size ()[min_axis]);
4290+ Rect2 rect = Rect2 (xform.xform (tile_set->map_to_local (coords)) - (icon_size * xform.get_scale () / 2 ), icon_size * xform.get_scale ());
4291+ custom_overlay->draw_texture_rect (missing_tile_texture, rect, false , Color (1 , 1 , 1 , scale_fading));
4292+ }
42884293 }
42894294 }
4290- }
42914295
4292- // Fading on the border.
4293- const int fading = 5 ;
4296+ // Fading on the border.
4297+ const int fading = 5 ;
42944298
4295- // Determine the drawn area.
4296- Size2 screen_size = custom_overlay->get_size ();
4297- Rect2i screen_rect;
4298- screen_rect.position = tile_set->local_to_map (xform_inv.xform (Vector2 ()));
4299- screen_rect.expand_to (tile_set->local_to_map (xform_inv.xform (Vector2 (0 , screen_size.height ))));
4300- screen_rect.expand_to (tile_set->local_to_map (xform_inv.xform (Vector2 (screen_size.width , 0 ))));
4301- screen_rect.expand_to (tile_set->local_to_map (xform_inv.xform (screen_size)));
4302- screen_rect = screen_rect.grow (1 );
4299+ // Determine the drawn area.
4300+ Size2 screen_size = custom_overlay->get_size ();
4301+ Rect2i screen_rect;
4302+ screen_rect.position = tile_set->local_to_map (xform_inv.xform (Vector2 ()));
4303+ screen_rect.expand_to (tile_set->local_to_map (xform_inv.xform (Vector2 (0 , screen_size.height ))));
4304+ screen_rect.expand_to (tile_set->local_to_map (xform_inv.xform (Vector2 (screen_size.width , 0 ))));
4305+ screen_rect.expand_to (tile_set->local_to_map (xform_inv.xform (screen_size)));
4306+ screen_rect = screen_rect.grow (1 );
43034307
4304- Rect2i tilemap_used_rect = edited_layer->get_used_rect ();
4308+ Rect2i tilemap_used_rect = edited_layer->get_used_rect ();
43054309
4306- Rect2i displayed_rect = tilemap_used_rect.intersection (screen_rect);
4307- displayed_rect = displayed_rect.grow (fading);
4310+ Rect2i displayed_rect = tilemap_used_rect.intersection (screen_rect);
4311+ displayed_rect = displayed_rect.grow (fading);
43084312
4309- // Reduce the drawn area to avoid crashes if needed.
4310- int max_size = 100 ;
4311- if (displayed_rect.size .x > max_size) {
4312- displayed_rect = displayed_rect.grow_individual (-(displayed_rect.size .x - max_size) / 2 , 0 , -(displayed_rect.size .x - max_size) / 2 , 0 );
4313- }
4314- if (displayed_rect.size .y > max_size) {
4315- displayed_rect = displayed_rect.grow_individual (0 , -(displayed_rect.size .y - max_size) / 2 , 0 , -(displayed_rect.size .y - max_size) / 2 );
4316- }
4313+ // Reduce the drawn area to avoid crashes if needed.
4314+ int max_size = 100 ;
4315+ if (displayed_rect.size .x > max_size) {
4316+ displayed_rect = displayed_rect.grow_individual (-(displayed_rect.size .x - max_size) / 2 , 0 , -(displayed_rect.size .x - max_size) / 2 , 0 );
4317+ }
4318+ if (displayed_rect.size .y > max_size) {
4319+ displayed_rect = displayed_rect.grow_individual (0 , -(displayed_rect.size .y - max_size) / 2 , 0 , -(displayed_rect.size .y - max_size) / 2 );
4320+ }
4321+
4322+ // Draw the grid.
4323+ bool display_grid = EDITOR_GET (" editors/tiles_editor/display_grid" );
4324+ if (display_grid) {
4325+ Color grid_color = EDITOR_GET (" editors/tiles_editor/grid_color" );
4326+ for (int x = displayed_rect.position .x ; x < (displayed_rect.position .x + displayed_rect.size .x ); x++) {
4327+ for (int y = displayed_rect.position .y ; y < (displayed_rect.position .y + displayed_rect.size .y ); y++) {
4328+ Vector2i pos_in_rect = Vector2i (x, y) - displayed_rect.position ;
4329+
4330+ // Fade out the border of the grid.
4331+ float left_opacity = CLAMP (Math::inverse_lerp (0 .0f , (float )fading, (float )pos_in_rect.x ), 0 .0f , 1 .0f );
4332+ float right_opacity = CLAMP (Math::inverse_lerp ((float )displayed_rect.size .x , (float )(displayed_rect.size .x - fading), (float )(pos_in_rect.x + 1 )), 0 .0f , 1 .0f );
4333+ float top_opacity = CLAMP (Math::inverse_lerp (0 .0f , (float )fading, (float )pos_in_rect.y ), 0 .0f , 1 .0f );
4334+ float bottom_opacity = CLAMP (Math::inverse_lerp ((float )displayed_rect.size .y , (float )(displayed_rect.size .y - fading), (float )(pos_in_rect.y + 1 )), 0 .0f , 1 .0f );
4335+ float opacity = CLAMP (MIN (left_opacity, MIN (right_opacity, MIN (top_opacity, bottom_opacity))) + 0.1 , 0 .0f , 1 .0f );
4336+
4337+ Transform2D tile_xform;
4338+ tile_xform.set_origin (tile_set->map_to_local (Vector2 (x, y)));
4339+ tile_xform.set_scale (tile_shape_size);
4340+ Color color = grid_color;
4341+ color.a = color.a * opacity * scale_fading;
4342+ tile_set->draw_tile_shape (custom_overlay, xform * tile_xform, color, false );
4343+ }
4344+ }
4345+ }
43174346
4318- // Draw the grid.
4319- bool display_grid = EDITOR_GET (" editors/tiles_editor/display_grid" );
4320- if (display_grid) {
4321- Color grid_color = EDITOR_GET (" editors/tiles_editor/grid_color" );
4347+ // Draw the IDs for debug.
4348+ /* Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Label"));
43224349 for (int x = displayed_rect.position.x; x < (displayed_rect.position.x + displayed_rect.size.x); x++) {
43234350 for (int y = displayed_rect.position.y; y < (displayed_rect.position.y + displayed_rect.size.y); y++) {
4324- Vector2i pos_in_rect = Vector2i (x, y) - displayed_rect.position ;
4325-
4326- // Fade out the border of the grid.
4327- float left_opacity = CLAMP (Math::inverse_lerp (0 .0f , (float )fading, (float )pos_in_rect.x ), 0 .0f , 1 .0f );
4328- float right_opacity = CLAMP (Math::inverse_lerp ((float )displayed_rect.size .x , (float )(displayed_rect.size .x - fading), (float )(pos_in_rect.x + 1 )), 0 .0f , 1 .0f );
4329- float top_opacity = CLAMP (Math::inverse_lerp (0 .0f , (float )fading, (float )pos_in_rect.y ), 0 .0f , 1 .0f );
4330- float bottom_opacity = CLAMP (Math::inverse_lerp ((float )displayed_rect.size .y , (float )(displayed_rect.size .y - fading), (float )(pos_in_rect.y + 1 )), 0 .0f , 1 .0f );
4331- float opacity = CLAMP (MIN (left_opacity, MIN (right_opacity, MIN (top_opacity, bottom_opacity))) + 0.1 , 0 .0f , 1 .0f );
4332-
4333- Transform2D tile_xform;
4334- tile_xform.set_origin (tile_set->map_to_local (Vector2 (x, y)));
4335- tile_xform.set_scale (tile_shape_size);
4336- Color color = grid_color;
4337- color.a = color.a * opacity;
4338- tile_set->draw_tile_shape (custom_overlay, xform * tile_xform, color, false );
4351+ custom_overlay->draw_string(font, xform.xform(tile_set->map_to_local(Vector2(x, y))) + Vector2i(-tile_shape_size.x / 2, 0), vformat("%s", Vector2(x, y)));
43394352 }
4340- }
4353+ }*/
43414354 }
43424355
4343- // Draw the IDs for debug.
4344- /* Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Label"));
4345- for (int x = displayed_rect.position.x; x < (displayed_rect.position.x + displayed_rect.size.x); x++) {
4346- for (int y = displayed_rect.position.y; y < (displayed_rect.position.y + displayed_rect.size.y); y++) {
4347- custom_overlay->draw_string(font, xform.xform(tile_set->map_to_local(Vector2(x, y))) + Vector2i(-tile_shape_size.x / 2, 0), vformat("%s", Vector2(x, y)));
4348- }
4349- }*/
4350-
43514356 // Draw the plugins.
43524357 tabs_plugins[tabs_bar->get_current_tab ()]->forward_canvas_draw_over_viewport (custom_overlay);
43534358}
0 commit comments