|
@@ -97,15 +97,6 @@ Size2i TileAtlasView::_compute_base_tiles_control_size() {
|
|
if (texture.is_valid()) {
|
|
if (texture.is_valid()) {
|
|
size = texture->get_size();
|
|
size = texture->get_size();
|
|
}
|
|
}
|
|
-
|
|
|
|
- // Extend the size to all existing tiles.
|
|
|
|
- Size2i grid_size = tile_set_atlas_source->get_atlas_grid_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);
|
|
|
|
- grid_size = grid_size.max(tile_id + Vector2i(1, 1));
|
|
|
|
- }
|
|
|
|
- size = size.max(grid_size * (tile_set_atlas_source->get_texture_region_size() + tile_set_atlas_source->get_separation()) + tile_set_atlas_source->get_margins());
|
|
|
|
-
|
|
|
|
return size;
|
|
return size;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -213,43 +204,56 @@ void TileAtlasView::_draw_base_tiles() {
|
|
Ref<Texture2D> texture = tile_set_atlas_source->get_texture();
|
|
Ref<Texture2D> texture = tile_set_atlas_source->get_texture();
|
|
if (texture.is_valid()) {
|
|
if (texture.is_valid()) {
|
|
Vector2i margins = tile_set_atlas_source->get_margins();
|
|
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();
|
|
Vector2i texture_region_size = tile_set_atlas_source->get_texture_region_size();
|
|
-
|
|
|
|
- // Draw the texture, square by square.
|
|
|
|
Size2i grid_size = tile_set_atlas_source->get_atlas_grid_size();
|
|
Size2i grid_size = tile_set_atlas_source->get_atlas_grid_size();
|
|
|
|
+
|
|
|
|
+ // Draw the texture where there is no tile.
|
|
for (int x = 0; x < grid_size.x; x++) {
|
|
for (int x = 0; x < grid_size.x; x++) {
|
|
for (int y = 0; y < grid_size.y; y++) {
|
|
for (int y = 0; y < grid_size.y; y++) {
|
|
Vector2i coords = Vector2i(x, y);
|
|
Vector2i coords = Vector2i(x, y);
|
|
if (tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) {
|
|
if (tile_set_atlas_source->get_tile_at_coords(coords) == TileSetSource::INVALID_ATLAS_COORDS) {
|
|
- Rect2i rect = Rect2i(texture_region_size * coords + margins, texture_region_size);
|
|
|
|
- base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
|
|
|
|
+ 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);
|
|
|
|
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// Draw the texture around the grid.
|
|
// Draw the texture around the grid.
|
|
Rect2i rect;
|
|
Rect2i rect;
|
|
|
|
+
|
|
// Top.
|
|
// Top.
|
|
rect.position = Vector2i();
|
|
rect.position = Vector2i();
|
|
rect.set_end(Vector2i(texture->get_size().x, margins.y));
|
|
rect.set_end(Vector2i(texture->get_size().x, margins.y));
|
|
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
|
|
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
|
|
|
|
+
|
|
// Bottom
|
|
// Bottom
|
|
- int bottom_border = margins.y + (grid_size.y * texture_region_size.y);
|
|
|
|
|
|
+ int bottom_border = margins.y + (grid_size.y * (texture_region_size.y + separation.y));
|
|
if (bottom_border < texture->get_size().y) {
|
|
if (bottom_border < texture->get_size().y) {
|
|
rect.position = Vector2i(0, bottom_border);
|
|
rect.position = Vector2i(0, bottom_border);
|
|
rect.set_end(texture->get_size());
|
|
rect.set_end(texture->get_size());
|
|
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
|
|
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
|
|
}
|
|
}
|
|
|
|
+
|
|
// Left
|
|
// Left
|
|
rect.position = Vector2i(0, margins.y);
|
|
rect.position = Vector2i(0, margins.y);
|
|
- rect.set_end(Vector2i(margins.x, margins.y + (grid_size.y * texture_region_size.y)));
|
|
|
|
|
|
+ rect.set_end(Vector2i(margins.x, margins.y + (grid_size.y * (texture_region_size.y + separation.y))));
|
|
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
|
|
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
|
|
|
|
+
|
|
// Right.
|
|
// Right.
|
|
- int right_border = margins.x + (grid_size.x * texture_region_size.x);
|
|
|
|
|
|
+ int right_border = margins.x + (grid_size.x * (texture_region_size.x + separation.x));
|
|
if (right_border < texture->get_size().x) {
|
|
if (right_border < texture->get_size().x) {
|
|
rect.position = Vector2i(right_border, margins.y);
|
|
rect.position = Vector2i(right_border, margins.y);
|
|
- rect.set_end(Vector2i(texture->get_size().x, margins.y + (grid_size.y * texture_region_size.y)));
|
|
|
|
|
|
+ rect.set_end(Vector2i(texture->get_size().x, margins.y + (grid_size.y * (texture_region_size.y + separation.y))));
|
|
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
base_tiles_draw->draw_texture_rect_region(texture, rect, rect);
|
|
|
|
+ base_tiles_draw->draw_rect(rect, Color(0.0, 0.0, 0.0, 0.5));
|
|
}
|
|
}
|
|
|
|
|
|
// Draw actual tiles, using their properties (modulation, etc...)
|
|
// Draw actual tiles, using their properties (modulation, etc...)
|
|
@@ -258,12 +262,30 @@ void TileAtlasView::_draw_base_tiles() {
|
|
|
|
|
|
for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(atlas_coords); frame++) {
|
|
for (int frame = 0; frame < tile_set_atlas_source->get_tile_animation_frames_count(atlas_coords); frame++) {
|
|
// Update the y to max value.
|
|
// Update the y to max value.
|
|
- int animation_columns = tile_set_atlas_source->get_tile_animation_columns(atlas_coords);
|
|
|
|
- Vector2i frame_coords = atlas_coords + (tile_set_atlas_source->get_tile_size_in_atlas(atlas_coords) + tile_set_atlas_source->get_tile_animation_separation(atlas_coords)) * ((animation_columns > 0) ? Vector2i(frame % animation_columns, frame / animation_columns) : Vector2i(frame, 0));
|
|
|
|
- Vector2i offset_pos = (margins + (frame_coords * texture_region_size) + tile_set_atlas_source->get_tile_texture_region(atlas_coords, frame).size / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, 0));
|
|
|
|
|
|
+ Rect2i base_frame_rect = tile_set_atlas_source->get_tile_texture_region(atlas_coords, frame);
|
|
|
|
+ Vector2i offset_pos = base_frame_rect.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(atlas_coords, 0);
|
|
|
|
|
|
// Draw the tile.
|
|
// Draw the tile.
|
|
TileMap::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0, frame);
|
|
TileMap::draw_tile(base_tiles_draw->get_canvas_item(), offset_pos, tile_set, source_id, atlas_coords, 0, frame);
|
|
|
|
+
|
|
|
|
+ // Draw, the texture in the separation areas
|
|
|
|
+ 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));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -299,30 +321,6 @@ void TileAtlasView::_draw_base_tiles_texture_grid() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void TileAtlasView::_draw_base_tiles_dark() {
|
|
|
|
- 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));
|
|
|
|
-
|
|
|
|
- if (base_tile_coords == TileSetSource::INVALID_ATLAS_COORDS) {
|
|
|
|
- // Draw the grid.
|
|
|
|
- base_tiles_dark->draw_rect(Rect2i(origin, texture_region_size), Color(0.0, 0.0, 0.0, 0.5), true);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void TileAtlasView::_draw_base_tiles_shape_grid() {
|
|
void TileAtlasView::_draw_base_tiles_shape_grid() {
|
|
// Draw the shapes.
|
|
// Draw the shapes.
|
|
Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color");
|
|
Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color");
|
|
@@ -453,7 +451,6 @@ void TileAtlasView::set_atlas_source(TileSet *p_tile_set, TileSetAtlasSource *p_
|
|
base_tiles_draw->update();
|
|
base_tiles_draw->update();
|
|
base_tiles_texture_grid->update();
|
|
base_tiles_texture_grid->update();
|
|
base_tiles_shape_grid->update();
|
|
base_tiles_shape_grid->update();
|
|
- base_tiles_dark->update();
|
|
|
|
alternatives_draw->update();
|
|
alternatives_draw->update();
|
|
background_left->update();
|
|
background_left->update();
|
|
background_right->update();
|
|
background_right->update();
|
|
@@ -544,7 +541,6 @@ void TileAtlasView::update() {
|
|
base_tiles_draw->update();
|
|
base_tiles_draw->update();
|
|
base_tiles_texture_grid->update();
|
|
base_tiles_texture_grid->update();
|
|
base_tiles_shape_grid->update();
|
|
base_tiles_shape_grid->update();
|
|
- base_tiles_dark->update();
|
|
|
|
alternatives_draw->update();
|
|
alternatives_draw->update();
|
|
background_left->update();
|
|
background_left->update();
|
|
background_right->update();
|
|
background_right->update();
|
|
@@ -660,12 +656,6 @@ TileAtlasView::TileAtlasView() {
|
|
base_tiles_shape_grid->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_shape_grid));
|
|
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);
|
|
base_tiles_drawing_root->add_child(base_tiles_shape_grid);
|
|
|
|
|
|
- base_tiles_dark = memnew(Control);
|
|
|
|
- base_tiles_dark->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
|
|
|
|
- base_tiles_dark->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
|
|
|
|
- base_tiles_dark->connect("draw", callable_mp(this, &TileAtlasView::_draw_base_tiles_dark));
|
|
|
|
- base_tiles_drawing_root->add_child(base_tiles_dark);
|
|
|
|
-
|
|
|
|
// Alternative tiles.
|
|
// Alternative tiles.
|
|
Label *alternative_tiles_label = memnew(Label);
|
|
Label *alternative_tiles_label = memnew(Label);
|
|
alternative_tiles_label->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
|
|
alternative_tiles_label->set_mouse_filter(Control::MOUSE_FILTER_IGNORE);
|