2023-01-05 13:25:55 +01:00
/**************************************************************************/
/* tile_atlas_view.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2021-05-07 15:41:39 +02:00
# include "tile_atlas_view.h"
# include "core/input/input.h"
# include "core/os/keyboard.h"
2021-07-28 18:10:01 +02:00
# include "scene/2d/tile_map.h"
2021-05-07 15:41:39 +02:00
# include "scene/gui/box_container.h"
# include "scene/gui/label.h"
# include "scene/gui/panel.h"
2021-09-28 18:00:16 +02:00
# include "scene/gui/view_panner.h"
2021-05-07 15:41:39 +02:00
# include "editor/editor_scale.h"
2021-05-21 17:28:28 +02:00
# include "editor/editor_settings.h"
2021-05-07 15:41:39 +02:00
2021-08-22 17:37:22 +02:00
void TileAtlasView : : gui_input ( const Ref < InputEvent > & p_event ) {
2021-09-28 18:00:16 +02:00
if ( panner - > gui_input ( p_event ) ) {
accept_event ( ) ;
}
}
2021-07-19 23:35:07 +02:00
2023-01-19 17:50:51 +01:00
void TileAtlasView : : _pan_callback ( Vector2 p_scroll_vec , Ref < InputEvent > p_event ) {
2021-09-28 18:00:16 +02:00
panning + = p_scroll_vec ;
_update_zoom_and_panning ( true ) ;
2023-01-05 21:54:00 +01:00
emit_signal ( SNAME ( " transform_changed " ) , zoom_widget - > get_zoom ( ) , panning ) ;
2021-09-28 18:00:16 +02:00
}
2021-06-09 20:01:08 +02:00
2023-01-19 17:50:51 +01:00
void TileAtlasView : : _zoom_callback ( float p_zoom_factor , Vector2 p_origin , Ref < InputEvent > p_event ) {
zoom_widget - > set_zoom ( zoom_widget - > get_zoom ( ) * p_zoom_factor ) ;
2021-09-28 18:00:16 +02:00
_update_zoom_and_panning ( true ) ;
2023-01-05 21:54:00 +01:00
emit_signal ( SNAME ( " transform_changed " ) , zoom_widget - > get_zoom ( ) , panning ) ;
2021-05-07 15:41:39 +02:00
}
Size2i TileAtlasView : : _compute_base_tiles_control_size ( ) {
// Update the texture.
Vector2i size ;
Ref < Texture2D > texture = tile_set_atlas_source - > get_texture ( ) ;
if ( texture . is_valid ( ) ) {
size = texture - > get_size ( ) ;
}
return size ;
}
Size2i TileAtlasView : : _compute_alternative_tiles_control_size ( ) {
Vector2i size ;
for ( int i = 0 ; i < tile_set_atlas_source - > get_tiles_count ( ) ; i + + ) {
Vector2i tile_id = tile_set_atlas_source - > get_tile_id ( i ) ;
int alternatives_count = tile_set_atlas_source - > get_alternative_tiles_count ( tile_id ) ;
Vector2i line_size ;
Size2i texture_region_size = tile_set_atlas_source - > get_tile_texture_region ( tile_id ) . size ;
for ( int j = 1 ; j < alternatives_count ; j + + ) {
int alternative_id = tile_set_atlas_source - > get_alternative_tile_id ( tile_id , j ) ;
2022-01-28 14:26:35 +01:00
bool transposed = tile_set_atlas_source - > get_tile_data ( tile_id , alternative_id ) - > get_transpose ( ) ;
2021-05-07 15:41:39 +02:00
line_size . x + = transposed ? texture_region_size . y : texture_region_size . x ;
line_size . y = MAX ( line_size . y , transposed ? texture_region_size . x : texture_region_size . y ) ;
}
size . x = MAX ( size . x , line_size . x ) ;
size . y + = line_size . y ;
}
return size ;
}
2021-06-09 20:01:08 +02:00
void TileAtlasView : : _update_zoom_and_panning ( bool p_zoom_on_mouse_pos ) {
2022-01-28 00:15:23 +01:00
// Don't allow zoom to go below 1% or above 10000%
zoom_widget - > set_zoom ( CLAMP ( zoom_widget - > get_zoom ( ) , 0.01f , 100.f ) ) ;
2021-06-09 20:01:08 +02:00
float zoom = zoom_widget - > get_zoom ( ) ;
2021-05-07 15:41:39 +02:00
// Compute the minimum sizes.
Size2i base_tiles_control_size = _compute_base_tiles_control_size ( ) ;
2021-06-09 20:01:08 +02:00
base_tiles_root_control - > set_custom_minimum_size ( Vector2 ( base_tiles_control_size ) * zoom ) ;
2021-05-07 15:41:39 +02:00
Size2i alternative_tiles_control_size = _compute_alternative_tiles_control_size ( ) ;
2021-06-09 20:01:08 +02:00
alternative_tiles_root_control - > set_custom_minimum_size ( Vector2 ( alternative_tiles_control_size ) * zoom ) ;
2021-05-07 15:41:39 +02:00
// Set the texture for the base tiles.
Ref < Texture2D > texture = tile_set_atlas_source - > get_texture ( ) ;
// Set the scales.
if ( base_tiles_control_size . x > 0 & & base_tiles_control_size . y > 0 ) {
2021-06-09 20:01:08 +02:00
base_tiles_drawing_root - > set_scale ( Vector2 ( zoom , zoom ) ) ;
2021-05-07 15:41:39 +02:00
} else {
base_tiles_drawing_root - > set_scale ( Vector2 ( 1 , 1 ) ) ;
}
if ( alternative_tiles_control_size . x > 0 & & alternative_tiles_control_size . y > 0 ) {
2021-06-09 20:01:08 +02:00
alternative_tiles_drawing_root - > set_scale ( Vector2 ( zoom , zoom ) ) ;
2021-05-07 15:41:39 +02:00
} else {
alternative_tiles_drawing_root - > set_scale ( Vector2 ( 1 , 1 ) ) ;
}
// Update the margin container's margins.
const char * constants [ ] = { " margin_left " , " margin_top " , " margin_right " , " margin_bottom " } ;
for ( int i = 0 ; i < 4 ; i + + ) {
2021-06-09 20:01:08 +02:00
margin_container - > add_theme_constant_override ( constants [ i ] , margin_container_paddings [ i ] * zoom ) ;
2021-05-07 15:41:39 +02:00
}
// Update the backgrounds.
2022-08-19 03:20:55 +02:00
background_left - > set_size ( base_tiles_root_control - > get_custom_minimum_size ( ) ) ;
background_right - > set_size ( alternative_tiles_root_control - > get_custom_minimum_size ( ) ) ;
2021-05-07 15:41:39 +02:00
// Zoom on the position.
2021-06-09 20:01:08 +02:00
if ( p_zoom_on_mouse_pos ) {
// Offset the panning relative to the center of panel.
Vector2 relative_mpos = get_local_mouse_position ( ) - get_size ( ) / 2 ;
panning = ( panning - relative_mpos ) * zoom / previous_zoom + relative_mpos ;
} else {
// Center of panel.
panning = panning * zoom / previous_zoom ;
}
2022-09-02 02:32:33 +02:00
button_center_view - > set_disabled ( panning . is_zero_approx ( ) ) ;
2021-05-07 15:41:39 +02:00
2021-06-09 20:01:08 +02:00
previous_zoom = zoom ;
2021-05-07 15:41:39 +02:00
2021-06-09 20:01:08 +02:00
center_container - > set_begin ( panning - center_container - > get_minimum_size ( ) / 2 ) ;
center_container - > set_size ( center_container - > get_minimum_size ( ) ) ;
2021-05-07 15:41:39 +02:00
}
2021-06-09 20:01:08 +02:00
void TileAtlasView : : _zoom_widget_changed ( ) {
_update_zoom_and_panning ( ) ;
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " transform_changed " ) , zoom_widget - > get_zoom ( ) , panning ) ;
2021-05-07 15:41:39 +02:00
}
2021-06-09 20:01:08 +02:00
void TileAtlasView : : _center_view ( ) {
panning = Vector2 ( ) ;
button_center_view - > set_disabled ( true ) ;
_update_zoom_and_panning ( ) ;
2021-07-17 23:22:52 +02:00
emit_signal ( SNAME ( " transform_changed " ) , zoom_widget - > get_zoom ( ) , panning ) ;
2021-05-07 15:41:39 +02:00
}
void TileAtlasView : : _base_tiles_root_control_gui_input ( const Ref < InputEvent > & p_event ) {
2022-08-25 12:42:17 +02:00
base_tiles_root_control - > set_tooltip_text ( " " ) ;
2021-05-07 15:41:39 +02:00
Ref < InputEventMouseMotion > mm = p_event ;
if ( mm . is_valid ( ) ) {
Transform2D xform = base_tiles_drawing_root - > get_transform ( ) . affine_inverse ( ) ;
Vector2i coords = get_atlas_tile_coords_at_pos ( xform . xform ( mm - > get_position ( ) ) ) ;
2021-05-18 15:40:52 +02:00
if ( coords ! = TileSetSource : : INVALID_ATLAS_COORDS ) {
2021-05-07 15:41:39 +02:00
coords = tile_set_atlas_source - > get_tile_at_coords ( coords ) ;
2021-05-18 15:40:52 +02:00
if ( coords ! = TileSetSource : : INVALID_ATLAS_COORDS ) {
2022-08-25 12:42:17 +02:00
base_tiles_root_control - > set_tooltip_text ( vformat ( TTR ( " Source: %d \n Atlas coordinates: %s \n Alternative: 0 " ) , source_id , coords ) ) ;
2021-05-07 15:41:39 +02:00
}
}
}
}
void TileAtlasView : : _draw_base_tiles ( ) {
Ref < Texture2D > texture = tile_set_atlas_source - > get_texture ( ) ;
if ( texture . is_valid ( ) ) {
Vector2i margins = tile_set_atlas_source - > get_margins ( ) ;
2021-10-11 12:04:40 +02:00
Vector2i separation = tile_set_atlas_source - > get_separation ( ) ;
2021-05-07 15:41:39 +02:00
Vector2i texture_region_size = tile_set_atlas_source - > get_texture_region_size ( ) ;
Size2i grid_size = tile_set_atlas_source - > get_atlas_grid_size ( ) ;
2021-10-11 12:04:40 +02:00
// Draw the texture where there is no tile.
2021-05-07 15:41:39 +02:00
for ( int x = 0 ; x < grid_size . x ; x + + ) {
for ( int y = 0 ; y < grid_size . y ; y + + ) {
Vector2i coords = Vector2i ( x , y ) ;
2021-05-18 15:40:52 +02:00
if ( tile_set_atlas_source - > get_tile_at_coords ( coords ) = = TileSetSource : : INVALID_ATLAS_COORDS ) {
2021-10-11 12:04:40 +02:00
Rect2i rect = Rect2i ( ( texture_region_size + separation ) * coords + margins , texture_region_size + separation ) ;
rect = rect . intersection ( Rect2i ( Vector2 ( ) , texture - > get_size ( ) ) ) ;
if ( rect . size . x > 0 & & rect . size . y > 0 ) {
base_tiles_draw - > draw_texture_rect_region ( texture , rect , rect ) ;
2022-11-04 21:04:20 +01:00
}
}
}
}
// Draw dark overlay after for performance reasons.
for ( int x = 0 ; x < grid_size . x ; x + + ) {
for ( int y = 0 ; y < grid_size . y ; y + + ) {
Vector2i coords = Vector2i ( x , y ) ;
if ( tile_set_atlas_source - > get_tile_at_coords ( coords ) = = TileSetSource : : INVALID_ATLAS_COORDS ) {
Rect2i rect = Rect2i ( ( texture_region_size + separation ) * coords + margins , texture_region_size + separation ) ;
rect = rect . intersection ( Rect2i ( Vector2 ( ) , texture - > get_size ( ) ) ) ;
if ( rect . size . x > 0 & & rect . size . y > 0 ) {
2021-10-11 12:04:40 +02:00
base_tiles_draw - > draw_rect ( rect , Color ( 0.0 , 0.0 , 0.0 , 0.5 ) ) ;
}
2021-05-07 15:41:39 +02:00
}
}
}
// Draw the texture around the grid.
Rect2i rect ;
2021-10-11 12:04:40 +02:00
2021-05-07 15:41:39 +02:00
// Top.
rect . position = Vector2i ( ) ;
rect . set_end ( Vector2i ( texture - > get_size ( ) . x , margins . y ) ) ;
base_tiles_draw - > draw_texture_rect_region ( texture , rect , rect ) ;
2021-10-11 12:04:40 +02:00
base_tiles_draw - > draw_rect ( rect , Color ( 0.0 , 0.0 , 0.0 , 0.5 ) ) ;
2021-05-07 15:41:39 +02:00
// Bottom
2021-10-11 12:04:40 +02:00
int bottom_border = margins . y + ( grid_size . y * ( texture_region_size . y + separation . y ) ) ;
2021-05-18 15:40:52 +02:00
if ( bottom_border < texture - > get_size ( ) . y ) {
rect . position = Vector2i ( 0 , bottom_border ) ;
rect . set_end ( texture - > get_size ( ) ) ;
base_tiles_draw - > draw_texture_rect_region ( texture , rect , rect ) ;
2021-10-11 12:04:40 +02:00
base_tiles_draw - > draw_rect ( rect , Color ( 0.0 , 0.0 , 0.0 , 0.5 ) ) ;
2021-05-18 15:40:52 +02:00
}
2021-10-11 12:04:40 +02:00
2021-05-07 15:41:39 +02:00
// Left
rect . position = Vector2i ( 0 , margins . y ) ;
2021-10-11 12:04:40 +02:00
rect . set_end ( Vector2i ( margins . x , margins . y + ( grid_size . y * ( texture_region_size . y + separation . y ) ) ) ) ;
2021-05-07 15:41:39 +02:00
base_tiles_draw - > draw_texture_rect_region ( texture , rect , rect ) ;
2021-10-11 12:04:40 +02:00
base_tiles_draw - > draw_rect ( rect , Color ( 0.0 , 0.0 , 0.0 , 0.5 ) ) ;
2021-05-07 15:41:39 +02:00
// Right.
2021-10-11 12:04:40 +02:00
int right_border = margins . x + ( grid_size . x * ( texture_region_size . x + separation . x ) ) ;
2021-05-18 15:40:52 +02:00
if ( right_border < texture - > get_size ( ) . x ) {
rect . position = Vector2i ( right_border , margins . y ) ;
2021-10-11 12:04:40 +02:00
rect . set_end ( Vector2i ( texture - > get_size ( ) . x , margins . y + ( grid_size . y * ( texture_region_size . y + separation . y ) ) ) ) ;
2021-05-18 15:40:52 +02:00
base_tiles_draw - > draw_texture_rect_region ( texture , rect , rect ) ;
2021-10-11 12:04:40 +02:00
base_tiles_draw - > draw_rect ( rect , Color ( 0.0 , 0.0 , 0.0 , 0.5 ) ) ;
2021-05-18 15:40:52 +02:00
}
2021-05-07 15:41:39 +02:00
// Draw actual tiles, using their properties (modulation, etc...)
for ( int i = 0 ; i < tile_set_atlas_source - > get_tiles_count ( ) ; i + + ) {
Vector2i atlas_coords = tile_set_atlas_source - > get_tile_id ( i ) ;
2023-06-06 14:42:27 +02:00
// Different materials need to be drawn with different CanvasItems.
RID ci_rid = _get_canvas_item_to_draw ( tile_set_atlas_source - > get_tile_data ( atlas_coords , 0 ) , base_tiles_draw , material_tiles_draw ) ;
2021-09-10 16:23:36 +02:00
for ( int frame = 0 ; frame < tile_set_atlas_source - > get_tile_animation_frames_count ( atlas_coords ) ; frame + + ) {
// Update the y to max value.
2021-10-11 12:04:40 +02:00
Rect2i base_frame_rect = tile_set_atlas_source - > get_tile_texture_region ( atlas_coords , frame ) ;
2023-03-12 12:53:46 +01:00
Vector2 offset_pos = Rect2 ( base_frame_rect ) . get_center ( ) + Vector2 ( tile_set_atlas_source - > get_tile_data ( atlas_coords , 0 ) - > get_texture_origin ( ) ) ;
2021-05-07 15:41:39 +02:00
2021-09-10 16:23:36 +02:00
// Draw the tile.
2023-06-06 14:42:27 +02:00
TileMap : : draw_tile ( ci_rid , offset_pos , tile_set , source_id , atlas_coords , 0 , frame ) ;
2022-11-04 21:04:20 +01:00
}
}
2021-10-11 12:04:40 +02:00
2022-11-04 21:04:20 +01:00
// Draw Dark overlay on separation in its own pass.
if ( separation . x > 0 | | separation . y > 0 ) {
for ( int i = 0 ; i < tile_set_atlas_source - > get_tiles_count ( ) ; i + + ) {
Vector2i atlas_coords = tile_set_atlas_source - > get_tile_id ( i ) ;
for ( int frame = 0 ; frame < tile_set_atlas_source - > get_tile_animation_frames_count ( atlas_coords ) ; frame + + ) {
// Update the y to max value.
Rect2i base_frame_rect = tile_set_atlas_source - > get_tile_texture_region ( atlas_coords , frame ) ;
if ( separation . x > 0 ) {
Rect2i right_sep_rect = Rect2i ( base_frame_rect . get_position ( ) + Vector2i ( base_frame_rect . size . x , 0 ) , Vector2i ( separation . x , base_frame_rect . size . y ) ) ;
right_sep_rect = right_sep_rect . intersection ( Rect2i ( Vector2 ( ) , texture - > get_size ( ) ) ) ;
if ( right_sep_rect . size . x > 0 & & right_sep_rect . size . y > 0 ) {
//base_tiles_draw->draw_texture_rect_region(texture, right_sep_rect, right_sep_rect);
base_tiles_draw - > draw_rect ( right_sep_rect , Color ( 0.0 , 0.0 , 0.0 , 0.5 ) ) ;
}
2021-10-11 12:04:40 +02:00
}
2022-11-04 21:04:20 +01:00
if ( separation . y > 0 ) {
Rect2i bottom_sep_rect = Rect2i ( base_frame_rect . get_position ( ) + Vector2i ( 0 , base_frame_rect . size . y ) , Vector2i ( base_frame_rect . size . x + separation . x , separation . y ) ) ;
bottom_sep_rect = bottom_sep_rect . intersection ( Rect2i ( Vector2 ( ) , texture - > get_size ( ) ) ) ;
if ( bottom_sep_rect . size . x > 0 & & bottom_sep_rect . size . y > 0 ) {
//base_tiles_draw->draw_texture_rect_region(texture, bottom_sep_rect, bottom_sep_rect);
base_tiles_draw - > draw_rect ( bottom_sep_rect , Color ( 0.0 , 0.0 , 0.0 , 0.5 ) ) ;
}
2021-10-11 12:04:40 +02:00
}
}
2021-09-10 16:23:36 +02:00
}
2021-05-07 15:41:39 +02:00
}
}
}
2023-06-06 14:42:27 +02:00
RID TileAtlasView : : _get_canvas_item_to_draw ( const TileData * p_for_data , const CanvasItem * p_base_item , HashMap < Ref < Material > , RID > & p_material_map ) {
Ref < Material > mat = p_for_data - > get_material ( ) ;
if ( mat . is_null ( ) ) {
return p_base_item - > get_canvas_item ( ) ;
} else if ( p_material_map . has ( mat ) ) {
return p_material_map [ mat ] ;
} else {
RID ci_rid = RS : : get_singleton ( ) - > canvas_item_create ( ) ;
RS : : get_singleton ( ) - > canvas_item_set_parent ( ci_rid , p_base_item - > get_canvas_item ( ) ) ;
RS : : get_singleton ( ) - > canvas_item_set_material ( ci_rid , mat - > get_rid ( ) ) ;
p_material_map [ mat ] = ci_rid ;
return ci_rid ;
}
}
void TileAtlasView : : _clear_material_canvas_items ( ) {
for ( KeyValue < Ref < Material > , RID > kv : material_tiles_draw ) {
RS : : get_singleton ( ) - > free ( kv . value ) ;
}
material_tiles_draw . clear ( ) ;
for ( KeyValue < Ref < Material > , RID > kv : material_alternatives_draw ) {
RS : : get_singleton ( ) - > free ( kv . value ) ;
}
material_alternatives_draw . clear ( ) ;
}
2021-05-07 15:41:39 +02:00
void TileAtlasView : : _draw_base_tiles_texture_grid ( ) {
Ref < Texture2D > texture = tile_set_atlas_source - > get_texture ( ) ;
if ( texture . is_valid ( ) ) {
Vector2i margins = tile_set_atlas_source - > get_margins ( ) ;
Vector2i separation = tile_set_atlas_source - > get_separation ( ) ;
Vector2i texture_region_size = tile_set_atlas_source - > get_texture_region_size ( ) ;
Size2i grid_size = tile_set_atlas_source - > get_atlas_grid_size ( ) ;
// Draw each tile texture region.
for ( int x = 0 ; x < grid_size . x ; x + + ) {
for ( int y = 0 ; y < grid_size . y ; y + + ) {
Vector2i origin = margins + ( Vector2i ( x , y ) * ( texture_region_size + separation ) ) ;
Vector2i base_tile_coords = tile_set_atlas_source - > get_tile_at_coords ( Vector2i ( x , y ) ) ;
2021-05-18 15:40:52 +02:00
if ( base_tile_coords ! = TileSetSource : : INVALID_ATLAS_COORDS ) {
2021-05-07 15:41:39 +02:00
if ( base_tile_coords = = Vector2i ( x , y ) ) {
// Draw existing tile.
Vector2i size_in_atlas = tile_set_atlas_source - > get_tile_size_in_atlas ( base_tile_coords ) ;
Vector2 region_size = texture_region_size * size_in_atlas + separation * ( size_in_atlas - Vector2i ( 1 , 1 ) ) ;
base_tiles_texture_grid - > draw_rect ( Rect2i ( origin , region_size ) , Color ( 1.0 , 1.0 , 1.0 , 0.8 ) , false ) ;
}
} else {
// Draw the grid.
base_tiles_texture_grid - > draw_rect ( Rect2i ( origin , texture_region_size ) , Color ( 0.7 , 0.7 , 0.7 , 0.1 ) , false ) ;
}
}
}
}
}
void TileAtlasView : : _draw_base_tiles_shape_grid ( ) {
// Draw the shapes.
2022-10-18 16:43:37 +02:00
Color grid_color = EDITOR_GET ( " editors/tiles_editor/grid_color " ) ;
2021-05-07 15:41:39 +02:00
Vector2i tile_shape_size = tile_set - > get_tile_size ( ) ;
for ( int i = 0 ; i < tile_set_atlas_source - > get_tiles_count ( ) ; i + + ) {
Vector2i tile_id = tile_set_atlas_source - > get_tile_id ( i ) ;
2023-01-26 18:47:54 +01:00
Vector2 in_tile_base_offset = tile_set_atlas_source - > get_tile_data ( tile_id , 0 ) - > get_texture_origin ( ) ;
if ( tile_set_atlas_source - > is_position_in_tile_texture_region ( tile_id , 0 , - tile_shape_size / 2 ) & & tile_set_atlas_source - > is_position_in_tile_texture_region ( tile_id , 0 , tile_shape_size / 2 - Vector2 ( 1 , 1 ) ) ) {
for ( int frame = 0 ; frame < tile_set_atlas_source - > get_tile_animation_frames_count ( tile_id ) ; frame + + ) {
Color color = grid_color ;
if ( frame > 0 ) {
color . a * = 0.3 ;
}
Rect2i texture_region = tile_set_atlas_source - > get_tile_texture_region ( tile_id , frame ) ;
Transform2D tile_xform ;
2023-03-12 12:53:46 +01:00
tile_xform . set_origin ( Rect2 ( texture_region ) . get_center ( ) + in_tile_base_offset ) ;
2023-01-26 18:47:54 +01:00
tile_xform . set_scale ( tile_shape_size ) ;
tile_set - > draw_tile_shape ( base_tiles_shape_grid , tile_xform , color ) ;
2021-09-10 16:23:36 +02:00
}
}
2021-05-07 15:41:39 +02:00
}
}
void TileAtlasView : : _alternative_tiles_root_control_gui_input ( const Ref < InputEvent > & p_event ) {
2022-08-25 12:42:17 +02:00
alternative_tiles_root_control - > set_tooltip_text ( " " ) ;
2021-05-07 15:41:39 +02:00
Ref < InputEventMouseMotion > mm = p_event ;
if ( mm . is_valid ( ) ) {
Transform2D xform = alternative_tiles_drawing_root - > get_transform ( ) . affine_inverse ( ) ;
Vector3i coords3 = get_alternative_tile_at_pos ( xform . xform ( mm - > get_position ( ) ) ) ;
Vector2i coords = Vector2i ( coords3 . x , coords3 . y ) ;
int alternative_id = coords3 . z ;
2021-05-18 15:40:52 +02:00
if ( coords ! = TileSetSource : : INVALID_ATLAS_COORDS & & alternative_id ! = TileSetSource : : INVALID_TILE_ALTERNATIVE ) {
2022-08-25 12:42:17 +02:00
alternative_tiles_root_control - > set_tooltip_text ( vformat ( TTR ( " Source: %d \n Atlas coordinates: %s \n Alternative: %d " ) , source_id , coords , alternative_id ) ) ;
2021-05-07 15:41:39 +02:00
}
}
}
void TileAtlasView : : _draw_alternatives ( ) {
// Draw the alternative tiles.
Ref < Texture2D > texture = tile_set_atlas_source - > get_texture ( ) ;
if ( texture . is_valid ( ) ) {
Vector2 current_pos ;
for ( int i = 0 ; i < tile_set_atlas_source - > get_tiles_count ( ) ; i + + ) {
Vector2i atlas_coords = tile_set_atlas_source - > get_tile_id ( i ) ;
current_pos . x = 0 ;
int y_increment = 0 ;
2021-09-10 16:23:36 +02:00
Size2i texture_region_size = tile_set_atlas_source - > get_tile_texture_region ( atlas_coords ) . size ;
2021-05-07 15:41:39 +02:00
int alternatives_count = tile_set_atlas_source - > get_alternative_tiles_count ( atlas_coords ) ;
for ( int j = 1 ; j < alternatives_count ; j + + ) {
int alternative_id = tile_set_atlas_source - > get_alternative_tile_id ( atlas_coords , j ) ;
2022-01-28 14:26:35 +01:00
TileData * tile_data = tile_set_atlas_source - > get_tile_data ( atlas_coords , alternative_id ) ;
2021-05-07 15:41:39 +02:00
bool transposed = tile_data - > get_transpose ( ) ;
2023-06-06 14:42:27 +02:00
// Different materials need to be drawn with different CanvasItems.
RID ci_rid = _get_canvas_item_to_draw ( tile_data , alternatives_draw , material_alternatives_draw ) ;
2021-05-07 15:41:39 +02:00
// Update the y to max value.
2022-04-07 12:23:40 +02:00
Vector2i offset_pos ;
2021-05-07 15:41:39 +02:00
if ( transposed ) {
2023-01-26 18:47:54 +01:00
offset_pos = ( current_pos + Vector2 ( texture_region_size . y , texture_region_size . x ) / 2 + tile_data - > get_texture_origin ( ) ) ;
2021-09-10 16:23:36 +02:00
y_increment = MAX ( y_increment , texture_region_size . x ) ;
2021-05-07 15:41:39 +02:00
} else {
2023-01-26 18:47:54 +01:00
offset_pos = ( current_pos + texture_region_size / 2 + tile_data - > get_texture_origin ( ) ) ;
2021-09-10 16:23:36 +02:00
y_increment = MAX ( y_increment , texture_region_size . y ) ;
2021-05-07 15:41:39 +02:00
}
// Draw the tile.
2023-06-06 14:42:27 +02:00
TileMap : : draw_tile ( ci_rid , offset_pos , tile_set , source_id , atlas_coords , alternative_id ) ;
2021-05-07 15:41:39 +02:00
// Increment the x position.
2021-09-10 16:23:36 +02:00
current_pos . x + = transposed ? texture_region_size . y : texture_region_size . x ;
2021-05-07 15:41:39 +02:00
}
if ( alternatives_count > 1 ) {
current_pos . y + = y_increment ;
}
}
}
}
void TileAtlasView : : _draw_background_left ( ) {
2023-04-03 18:01:11 +02:00
background_left - > draw_texture_rect ( theme_cache . checkerboard , Rect2 ( Vector2 ( ) , background_left - > get_size ( ) ) , true ) ;
2021-05-07 15:41:39 +02:00
}
void TileAtlasView : : _draw_background_right ( ) {
2023-04-03 18:01:11 +02:00
background_right - > draw_texture_rect ( theme_cache . checkerboard , Rect2 ( Vector2 ( ) , background_right - > get_size ( ) ) , true ) ;
2021-05-07 15:41:39 +02:00
}
void TileAtlasView : : set_atlas_source ( TileSet * p_tile_set , TileSetAtlasSource * p_tile_set_atlas_source , int p_source_id ) {
2023-02-14 00:39:41 +01:00
tile_set = p_tile_set ;
tile_set_atlas_source = p_tile_set_atlas_source ;
2023-06-06 14:42:27 +02:00
_clear_material_canvas_items ( ) ;
2023-02-14 00:39:41 +01:00
if ( ! tile_set ) {
return ;
}
2021-05-07 15:41:39 +02:00
ERR_FAIL_COND ( p_source_id < 0 ) ;
ERR_FAIL_COND ( p_tile_set - > get_source ( p_source_id ) ! = p_tile_set_atlas_source ) ;
source_id = p_source_id ;
// Show or hide the view.
bool valid = tile_set_atlas_source - > get_texture ( ) . is_valid ( ) ;
hbox - > set_visible ( valid ) ;
missing_source_label - > set_visible ( ! valid ) ;
// Update the rect cache.
_update_alternative_tiles_rect_cache ( ) ;
// Update everything.
2021-06-09 20:01:08 +02:00
_update_zoom_and_panning ( ) ;
2021-05-07 15:41:39 +02:00
2022-09-17 19:07:56 +02:00
base_tiles_drawing_root - > set_size ( _compute_base_tiles_control_size ( ) ) ;
alternative_tiles_drawing_root - > set_size ( _compute_alternative_tiles_control_size ( ) ) ;
2021-05-07 15:41:39 +02:00
// Update.
2022-08-13 23:21:24 +02:00
base_tiles_draw - > queue_redraw ( ) ;
base_tiles_texture_grid - > queue_redraw ( ) ;
base_tiles_shape_grid - > queue_redraw ( ) ;
alternatives_draw - > queue_redraw ( ) ;
background_left - > queue_redraw ( ) ;
background_right - > queue_redraw ( ) ;
2021-05-07 15:41:39 +02:00
}
float TileAtlasView : : get_zoom ( ) const {
return zoom_widget - > get_zoom ( ) ;
} ;
2021-06-09 20:01:08 +02:00
void TileAtlasView : : set_transform ( float p_zoom , Vector2i p_panning ) {
2021-05-07 15:41:39 +02:00
zoom_widget - > set_zoom ( p_zoom ) ;
2021-06-09 20:01:08 +02:00
panning = p_panning ;
_update_zoom_and_panning ( ) ;
2021-05-07 15:41:39 +02:00
} ;
void TileAtlasView : : set_padding ( Side p_side , int p_padding ) {
ERR_FAIL_COND ( p_padding < 0 ) ;
margin_container_paddings [ p_side ] = p_padding ;
}
2023-01-17 10:26:10 +01:00
Vector2i TileAtlasView : : get_atlas_tile_coords_at_pos ( const Vector2 p_pos , bool p_clamp ) const {
2021-05-07 15:41:39 +02:00
Ref < Texture2D > texture = tile_set_atlas_source - > get_texture ( ) ;
2023-01-17 10:26:10 +01:00
if ( ! texture . is_valid ( ) ) {
return TileSetSource : : INVALID_ATLAS_COORDS ;
}
Vector2i margins = tile_set_atlas_source - > get_margins ( ) ;
Vector2i separation = tile_set_atlas_source - > get_separation ( ) ;
Vector2i texture_region_size = tile_set_atlas_source - > get_texture_region_size ( ) ;
2021-05-07 15:41:39 +02:00
2023-06-19 18:36:37 +02:00
// Compute index in atlas.
2023-01-17 10:26:10 +01:00
Vector2 pos = p_pos - margins ;
Vector2i ret = ( pos / ( texture_region_size + separation ) ) . floor ( ) ;
2021-05-07 15:41:39 +02:00
2023-01-17 10:26:10 +01:00
// Clamp.
2023-06-19 18:36:37 +02:00
if ( p_clamp ) {
Vector2i size = tile_set_atlas_source - > get_atlas_grid_size ( ) ;
ret . x = CLAMP ( ret . x , 0 , size . x - 1 ) ;
ret . y = CLAMP ( ret . y , 0 , size . y - 1 ) ;
}
2023-01-17 10:26:10 +01:00
return ret ;
2021-05-07 15:41:39 +02:00
}
void TileAtlasView : : _update_alternative_tiles_rect_cache ( ) {
alternative_tiles_rect_cache . clear ( ) ;
Rect2i current ;
for ( int i = 0 ; i < tile_set_atlas_source - > get_tiles_count ( ) ; i + + ) {
Vector2i tile_id = tile_set_atlas_source - > get_tile_id ( i ) ;
int alternatives_count = tile_set_atlas_source - > get_alternative_tiles_count ( tile_id ) ;
Size2i texture_region_size = tile_set_atlas_source - > get_tile_texture_region ( tile_id ) . size ;
int line_height = 0 ;
for ( int j = 1 ; j < alternatives_count ; j + + ) {
int alternative_id = tile_set_atlas_source - > get_alternative_tile_id ( tile_id , j ) ;
2022-01-28 14:26:35 +01:00
TileData * tile_data = tile_set_atlas_source - > get_tile_data ( tile_id , alternative_id ) ;
2021-05-07 15:41:39 +02:00
bool transposed = tile_data - > get_transpose ( ) ;
current . size = transposed ? Vector2i ( texture_region_size . y , texture_region_size . x ) : texture_region_size ;
// Update the rect.
if ( ! alternative_tiles_rect_cache . has ( tile_id ) ) {
2022-05-13 15:04:37 +02:00
alternative_tiles_rect_cache [ tile_id ] = HashMap < int , Rect2i > ( ) ;
2021-05-07 15:41:39 +02:00
}
alternative_tiles_rect_cache [ tile_id ] [ alternative_id ] = current ;
current . position . x + = transposed ? texture_region_size . y : texture_region_size . x ;
line_height = MAX ( line_height , transposed ? texture_region_size . x : texture_region_size . y ) ;
}
current . position . x = 0 ;
current . position . y + = line_height ;
}
}
Vector3i TileAtlasView : : get_alternative_tile_at_pos ( const Vector2 p_pos ) const {
2022-05-13 15:04:37 +02:00
for ( const KeyValue < Vector2 , HashMap < int , Rect2i > > & E_coords : alternative_tiles_rect_cache ) {
2021-08-09 22:13:42 +02:00
for ( const KeyValue < int , Rect2i > & E_alternative : E_coords . value ) {
if ( E_alternative . value . has_point ( p_pos ) ) {
return Vector3i ( E_coords . key . x , E_coords . key . y , E_alternative . key ) ;
2021-05-07 15:41:39 +02:00
}
}
}
2021-05-18 15:40:52 +02:00
return Vector3i ( TileSetSource : : INVALID_ATLAS_COORDS . x , TileSetSource : : INVALID_ATLAS_COORDS . y , TileSetSource : : INVALID_TILE_ALTERNATIVE ) ;
2021-05-07 15:41:39 +02:00
}
Rect2i TileAtlasView : : get_alternative_tile_rect ( const Vector2i p_coords , int p_alternative_tile ) {
ERR_FAIL_COND_V_MSG ( ! alternative_tiles_rect_cache . has ( p_coords ) , Rect2i ( ) , vformat ( " No cached rect for tile coords:%s " , p_coords ) ) ;
ERR_FAIL_COND_V_MSG ( ! alternative_tiles_rect_cache [ p_coords ] . has ( p_alternative_tile ) , Rect2i ( ) , vformat ( " No cached rect for tile coords:%s alternative_id:%d " , p_coords , p_alternative_tile ) ) ;
return alternative_tiles_rect_cache [ p_coords ] [ p_alternative_tile ] ;
}
2022-08-13 23:21:24 +02:00
void TileAtlasView : : queue_redraw ( ) {
base_tiles_draw - > queue_redraw ( ) ;
base_tiles_texture_grid - > queue_redraw ( ) ;
base_tiles_shape_grid - > queue_redraw ( ) ;
alternatives_draw - > queue_redraw ( ) ;
background_left - > queue_redraw ( ) ;
background_right - > queue_redraw ( ) ;
2021-05-07 15:41:39 +02:00
}
2023-04-03 18:01:11 +02:00
void TileAtlasView : : _update_theme_item_cache ( ) {
Control : : _update_theme_item_cache ( ) ;
theme_cache . center_view_icon = get_theme_icon ( SNAME ( " CenterView " ) , SNAME ( " EditorIcons " ) ) ;
theme_cache . checkerboard = get_theme_icon ( SNAME ( " Checkerboard " ) , SNAME ( " EditorIcons " ) ) ;
}
2021-06-09 20:01:08 +02:00
void TileAtlasView : : _notification ( int p_what ) {
switch ( p_what ) {
2021-09-28 18:00:16 +02:00
case NOTIFICATION_ENTER_TREE :
2022-02-16 15:17:55 +01:00
case EditorSettings : : NOTIFICATION_EDITOR_SETTINGS_CHANGED : {
2022-10-18 16:43:37 +02:00
panner - > setup ( ( ViewPanner : : ControlScheme ) EDITOR_GET ( " editors/panning/sub_editors_panning_scheme " ) . operator int ( ) , ED_GET_SHORTCUT ( " canvas_item_editor/pan_view " ) , bool ( EDITOR_GET ( " editors/panning/simple_panning " ) ) ) ;
2022-02-16 15:17:55 +01:00
} break ;
2021-09-28 18:00:16 +02:00
2023-04-03 18:01:11 +02:00
case NOTIFICATION_THEME_CHANGED : {
button_center_view - > set_icon ( theme_cache . center_view_icon ) ;
2022-02-16 15:17:55 +01:00
} break ;
2021-06-09 20:01:08 +02:00
}
}
2021-05-07 15:41:39 +02:00
void TileAtlasView : : _bind_methods ( ) {
ADD_SIGNAL ( MethodInfo ( " transform_changed " , PropertyInfo ( Variant : : FLOAT , " zoom " ) , PropertyInfo ( Variant : : VECTOR2 , " scroll " ) ) ) ;
}
TileAtlasView : : TileAtlasView ( ) {
2021-06-09 20:01:08 +02:00
set_texture_filter ( CanvasItem : : TEXTURE_FILTER_NEAREST ) ;
Panel * panel = memnew ( Panel ) ;
panel - > set_clip_contents ( true ) ;
panel - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2022-03-19 01:02:57 +01:00
panel - > set_anchors_and_offsets_preset ( Control : : PRESET_FULL_RECT ) ;
2021-06-09 20:01:08 +02:00
panel - > set_h_size_flags ( SIZE_EXPAND_FILL ) ;
panel - > set_v_size_flags ( SIZE_EXPAND_FILL ) ;
add_child ( panel ) ;
2021-05-07 15:41:39 +02:00
zoom_widget = memnew ( EditorZoomWidget ) ;
add_child ( zoom_widget ) ;
zoom_widget - > set_anchors_and_offsets_preset ( Control : : PRESET_TOP_LEFT , Control : : PRESET_MODE_MINSIZE , 2 * EDSCALE ) ;
zoom_widget - > connect ( " zoom_changed " , callable_mp ( this , & TileAtlasView : : _zoom_widget_changed ) . unbind ( 1 ) ) ;
2022-03-24 14:03:43 +01:00
zoom_widget - > set_shortcut_context ( this ) ;
2021-05-07 15:41:39 +02:00
2021-06-09 20:01:08 +02:00
button_center_view = memnew ( Button ) ;
button_center_view - > set_anchors_and_offsets_preset ( Control : : PRESET_TOP_RIGHT , Control : : PRESET_MODE_MINSIZE , 5 ) ;
2023-06-01 03:22:04 +02:00
button_center_view - > set_grow_direction_preset ( Control : : PRESET_TOP_RIGHT ) ;
2021-06-09 20:01:08 +02:00
button_center_view - > connect ( " pressed " , callable_mp ( this , & TileAtlasView : : _center_view ) ) ;
button_center_view - > set_flat ( true ) ;
button_center_view - > set_disabled ( true ) ;
2022-08-25 12:42:17 +02:00
button_center_view - > set_tooltip_text ( TTR ( " Center View " ) ) ;
2021-06-09 20:01:08 +02:00
add_child ( button_center_view ) ;
2022-01-19 19:59:12 +01:00
panner . instantiate ( ) ;
2023-01-19 17:50:51 +01:00
panner - > set_callbacks ( callable_mp ( this , & TileAtlasView : : _pan_callback ) , callable_mp ( this , & TileAtlasView : : _zoom_callback ) ) ;
2022-01-19 19:59:12 +01:00
panner - > set_enable_rmb ( true ) ;
2021-06-09 20:01:08 +02:00
center_container = memnew ( CenterContainer ) ;
center_container - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
center_container - > set_anchors_preset ( Control : : PRESET_CENTER ) ;
2021-08-22 17:37:22 +02:00
center_container - > connect ( " gui_input " , callable_mp ( this , & TileAtlasView : : gui_input ) ) ;
2022-01-19 19:59:12 +01:00
center_container - > connect ( " focus_exited " , callable_mp ( panner . ptr ( ) , & ViewPanner : : release_pan_key ) ) ;
center_container - > set_focus_mode ( FOCUS_CLICK ) ;
2021-06-09 20:01:08 +02:00
panel - > add_child ( center_container ) ;
2021-05-07 15:41:39 +02:00
missing_source_label = memnew ( Label ) ;
missing_source_label - > set_text ( TTR ( " No atlas source with a valid texture selected. " ) ) ;
center_container - > add_child ( missing_source_label ) ;
margin_container = memnew ( MarginContainer ) ;
2021-06-09 20:01:08 +02:00
margin_container - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2021-05-07 15:41:39 +02:00
center_container - > add_child ( margin_container ) ;
hbox = memnew ( HBoxContainer ) ;
2021-06-09 20:01:08 +02:00
hbox - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2022-02-08 10:14:58 +01:00
hbox - > add_theme_constant_override ( " separation " , 10 ) ;
2021-05-07 15:41:39 +02:00
hbox - > hide ( ) ;
margin_container - > add_child ( hbox ) ;
VBoxContainer * left_vbox = memnew ( VBoxContainer ) ;
2021-06-09 20:01:08 +02:00
left_vbox - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2021-05-07 15:41:39 +02:00
hbox - > add_child ( left_vbox ) ;
VBoxContainer * right_vbox = memnew ( VBoxContainer ) ;
2021-06-09 20:01:08 +02:00
right_vbox - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2021-05-07 15:41:39 +02:00
hbox - > add_child ( right_vbox ) ;
// Base tiles.
Label * base_tile_label = memnew ( Label ) ;
2021-06-09 20:01:08 +02:00
base_tile_label - > set_mouse_filter ( Control : : MOUSE_FILTER_PASS ) ;
2021-05-10 23:01:08 +02:00
base_tile_label - > set_text ( TTR ( " Base Tiles " ) ) ;
2021-11-25 03:58:47 +01:00
base_tile_label - > set_horizontal_alignment ( HORIZONTAL_ALIGNMENT_CENTER ) ;
2021-05-07 15:41:39 +02:00
left_vbox - > add_child ( base_tile_label ) ;
base_tiles_root_control = memnew ( Control ) ;
2021-06-09 20:01:08 +02:00
base_tiles_root_control - > set_mouse_filter ( Control : : MOUSE_FILTER_PASS ) ;
2021-05-07 15:41:39 +02:00
base_tiles_root_control - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
base_tiles_root_control - > connect ( " gui_input " , callable_mp ( this , & TileAtlasView : : _base_tiles_root_control_gui_input ) ) ;
left_vbox - > add_child ( base_tiles_root_control ) ;
background_left = memnew ( Control ) ;
2021-06-09 20:01:08 +02:00
background_left - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2022-08-19 03:20:55 +02:00
background_left - > set_anchors_and_offsets_preset ( Control : : PRESET_TOP_LEFT ) ;
2021-05-07 15:41:39 +02:00
background_left - > set_texture_repeat ( TextureRepeat : : TEXTURE_REPEAT_ENABLED ) ;
background_left - > connect ( " draw " , callable_mp ( this , & TileAtlasView : : _draw_background_left ) ) ;
base_tiles_root_control - > add_child ( background_left ) ;
base_tiles_drawing_root = memnew ( Control ) ;
2021-06-09 20:01:08 +02:00
base_tiles_drawing_root - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2021-05-07 15:41:39 +02:00
base_tiles_drawing_root - > set_texture_filter ( TEXTURE_FILTER_NEAREST ) ;
base_tiles_root_control - > add_child ( base_tiles_drawing_root ) ;
base_tiles_draw = memnew ( Control ) ;
2021-06-09 20:01:08 +02:00
base_tiles_draw - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2022-03-19 01:02:57 +01:00
base_tiles_draw - > set_anchors_and_offsets_preset ( Control : : PRESET_FULL_RECT ) ;
2021-05-07 15:41:39 +02:00
base_tiles_draw - > connect ( " draw " , callable_mp ( this , & TileAtlasView : : _draw_base_tiles ) ) ;
base_tiles_drawing_root - > add_child ( base_tiles_draw ) ;
base_tiles_texture_grid = memnew ( Control ) ;
2021-06-09 20:01:08 +02:00
base_tiles_texture_grid - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2022-03-19 01:02:57 +01:00
base_tiles_texture_grid - > set_anchors_and_offsets_preset ( Control : : PRESET_FULL_RECT ) ;
2021-05-07 15:41:39 +02:00
base_tiles_texture_grid - > connect ( " draw " , callable_mp ( this , & TileAtlasView : : _draw_base_tiles_texture_grid ) ) ;
base_tiles_drawing_root - > add_child ( base_tiles_texture_grid ) ;
base_tiles_shape_grid = memnew ( Control ) ;
2021-06-09 20:01:08 +02:00
base_tiles_shape_grid - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2022-03-19 01:02:57 +01:00
base_tiles_shape_grid - > set_anchors_and_offsets_preset ( Control : : PRESET_FULL_RECT ) ;
2021-05-07 15:41:39 +02:00
base_tiles_shape_grid - > connect ( " draw " , callable_mp ( this , & TileAtlasView : : _draw_base_tiles_shape_grid ) ) ;
base_tiles_drawing_root - > add_child ( base_tiles_shape_grid ) ;
// Alternative tiles.
Label * alternative_tiles_label = memnew ( Label ) ;
2021-06-09 20:01:08 +02:00
alternative_tiles_label - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2021-05-10 23:01:08 +02:00
alternative_tiles_label - > set_text ( TTR ( " Alternative Tiles " ) ) ;
2021-11-25 03:58:47 +01:00
alternative_tiles_label - > set_horizontal_alignment ( HORIZONTAL_ALIGNMENT_CENTER ) ;
2021-05-07 15:41:39 +02:00
right_vbox - > add_child ( alternative_tiles_label ) ;
alternative_tiles_root_control = memnew ( Control ) ;
2021-06-09 20:01:08 +02:00
alternative_tiles_root_control - > set_mouse_filter ( Control : : MOUSE_FILTER_PASS ) ;
2022-08-19 03:20:55 +02:00
alternative_tiles_root_control - > set_v_size_flags ( Control : : SIZE_EXPAND_FILL ) ;
2021-05-07 15:41:39 +02:00
alternative_tiles_root_control - > connect ( " gui_input " , callable_mp ( this , & TileAtlasView : : _alternative_tiles_root_control_gui_input ) ) ;
right_vbox - > add_child ( alternative_tiles_root_control ) ;
background_right = memnew ( Control ) ;
2021-06-09 20:01:08 +02:00
background_right - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2022-08-19 03:20:55 +02:00
background_right - > set_anchors_and_offsets_preset ( Control : : PRESET_TOP_LEFT ) ;
2021-05-07 15:41:39 +02:00
background_right - > set_texture_repeat ( TextureRepeat : : TEXTURE_REPEAT_ENABLED ) ;
background_right - > connect ( " draw " , callable_mp ( this , & TileAtlasView : : _draw_background_right ) ) ;
alternative_tiles_root_control - > add_child ( background_right ) ;
alternative_tiles_drawing_root = memnew ( Control ) ;
alternative_tiles_drawing_root - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2021-06-09 20:01:08 +02:00
alternative_tiles_drawing_root - > set_texture_filter ( TEXTURE_FILTER_NEAREST ) ;
2021-05-07 15:41:39 +02:00
alternative_tiles_root_control - > add_child ( alternative_tiles_drawing_root ) ;
alternatives_draw = memnew ( Control ) ;
alternatives_draw - > set_mouse_filter ( Control : : MOUSE_FILTER_IGNORE ) ;
2022-08-19 03:20:55 +02:00
alternatives_draw - > set_anchors_and_offsets_preset ( Control : : PRESET_FULL_RECT ) ;
2021-06-09 20:01:08 +02:00
alternatives_draw - > connect ( " draw " , callable_mp ( this , & TileAtlasView : : _draw_alternatives ) ) ;
2021-05-07 15:41:39 +02:00
alternative_tiles_drawing_root - > add_child ( alternatives_draw ) ;
}
2023-06-06 14:42:27 +02:00
TileAtlasView : : ~ TileAtlasView ( ) {
_clear_material_canvas_items ( ) ;
}