Fixes TileSet Y-sort not working and TileSet not saving correctly
This commit is contained in:
parent
f2d55f3c0f
commit
7d80480b72
@ -229,7 +229,7 @@
|
|||||||
</member>
|
</member>
|
||||||
<member name="transpose" type="bool" setter="set_transpose" getter="get_transpose" default="false">
|
<member name="transpose" type="bool" setter="set_transpose" getter="get_transpose" default="false">
|
||||||
</member>
|
</member>
|
||||||
<member name="y_sort_origin" type="Vector2i" setter="set_y_sort_origin" getter="get_y_sort_origin" default="Vector2i( 0, 0 )">
|
<member name="y_sort_origin" type="int" setter="set_y_sort_origin" getter="get_y_sort_origin" default="0">
|
||||||
</member>
|
</member>
|
||||||
<member name="z_index" type="int" setter="set_z_index" getter="get_z_index" default="0">
|
<member name="z_index" type="int" setter="set_z_index" getter="get_z_index" default="0">
|
||||||
</member>
|
</member>
|
||||||
|
@ -113,7 +113,22 @@ void TileDataPositionEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform
|
|||||||
ERR_FAIL_COND(value.get_type() != Variant::VECTOR2I && value.get_type() != Variant::VECTOR2);
|
ERR_FAIL_COND(value.get_type() != Variant::VECTOR2I && value.get_type() != Variant::VECTOR2);
|
||||||
|
|
||||||
Ref<Texture2D> position_icon = TileSetEditor::get_singleton()->get_theme_icon("EditorPosition", "EditorIcons");
|
Ref<Texture2D> position_icon = TileSetEditor::get_singleton()->get_theme_icon("EditorPosition", "EditorIcons");
|
||||||
p_canvas_item->draw_texture(position_icon, p_transform.get_origin() + Vector2(value) - position_icon->get_size() / 2);
|
p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(value)) - position_icon->get_size() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileDataYSortEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) {
|
||||||
|
TileData *tile_data = _get_tile_data(p_tile_set, p_atlas_source_id, p_atlas_coords, p_alternative_tile);
|
||||||
|
ERR_FAIL_COND(!tile_data);
|
||||||
|
|
||||||
|
bool valid;
|
||||||
|
Variant value = tile_data->get(p_property, &valid);
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ERR_FAIL_COND(value.get_type() != Variant::INT);
|
||||||
|
|
||||||
|
Ref<Texture2D> position_icon = TileSetEditor::get_singleton()->get_theme_icon("EditorPosition", "EditorIcons");
|
||||||
|
p_canvas_item->draw_texture(position_icon, p_transform.xform(Vector2(0, value)) - position_icon->get_size() / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileDataOcclusionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) {
|
void TileDataOcclusionShapeEditor::draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) {
|
||||||
|
@ -79,6 +79,13 @@ public:
|
|||||||
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class TileDataYSortEditor : public TileDataEditor {
|
||||||
|
GDCLASS(TileDataYSortEditor, TileDataEditor);
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void draw_over_tile(CanvasItem *p_canvas_item, Transform2D p_transform, TileSet *p_tile_set, int p_atlas_source_id, Vector2i p_atlas_coords, int p_alternative_tile, String p_property) override;
|
||||||
|
};
|
||||||
|
|
||||||
class TileDataOcclusionShapeEditor : public TileDataEditor {
|
class TileDataOcclusionShapeEditor : public TileDataEditor {
|
||||||
GDCLASS(TileDataOcclusionShapeEditor, TileDataEditor);
|
GDCLASS(TileDataOcclusionShapeEditor, TileDataEditor);
|
||||||
|
|
||||||
|
@ -298,6 +298,9 @@ void TileSetEditor::_notification(int p_what) {
|
|||||||
break;
|
break;
|
||||||
case NOTIFICATION_INTERNAL_PROCESS:
|
case NOTIFICATION_INTERNAL_PROCESS:
|
||||||
if (tile_set_changed_needs_update) {
|
if (tile_set_changed_needs_update) {
|
||||||
|
if (tile_set.is_valid()) {
|
||||||
|
tile_set->set_edited(true);
|
||||||
|
}
|
||||||
_update_atlas_sources_list();
|
_update_atlas_sources_list();
|
||||||
tile_set_changed_needs_update = false;
|
tile_set_changed_needs_update = false;
|
||||||
}
|
}
|
||||||
@ -445,7 +448,7 @@ TileDataEditor *TileSetEditor::get_tile_data_editor(String p_property) {
|
|||||||
} else if (p_property == "probability") {
|
} else if (p_property == "probability") {
|
||||||
return tile_data_float_editor;
|
return tile_data_float_editor;
|
||||||
} else if (p_property == "y_sort_origin") {
|
} else if (p_property == "y_sort_origin") {
|
||||||
return tile_data_position_editor;
|
return tile_data_y_sort_editor;
|
||||||
} else if (p_property == "texture_offset") {
|
} else if (p_property == "texture_offset") {
|
||||||
return tile_data_texture_offset_editor;
|
return tile_data_texture_offset_editor;
|
||||||
} else if (components.size() >= 1 && components[0].begins_with("occlusion_layer_")) {
|
} else if (components.size() >= 1 && components[0].begins_with("occlusion_layer_")) {
|
||||||
@ -575,7 +578,7 @@ TileSetEditor::~TileSetEditor() {
|
|||||||
|
|
||||||
// Delete tile data editors.
|
// Delete tile data editors.
|
||||||
memdelete(tile_data_texture_offset_editor);
|
memdelete(tile_data_texture_offset_editor);
|
||||||
memdelete(tile_data_position_editor);
|
memdelete(tile_data_y_sort_editor);
|
||||||
memdelete(tile_data_integer_editor);
|
memdelete(tile_data_integer_editor);
|
||||||
memdelete(tile_data_float_editor);
|
memdelete(tile_data_float_editor);
|
||||||
memdelete(tile_data_occlusion_shape_editor);
|
memdelete(tile_data_occlusion_shape_editor);
|
||||||
|
@ -56,7 +56,7 @@ private:
|
|||||||
|
|
||||||
// List of tile data editors.
|
// List of tile data editors.
|
||||||
TileDataTextureOffsetEditor *tile_data_texture_offset_editor = memnew(TileDataTextureOffsetEditor);
|
TileDataTextureOffsetEditor *tile_data_texture_offset_editor = memnew(TileDataTextureOffsetEditor);
|
||||||
TileDataPositionEditor *tile_data_position_editor = memnew(TileDataPositionEditor);
|
TileDataYSortEditor *tile_data_y_sort_editor = memnew(TileDataYSortEditor);
|
||||||
TileDataIntegerEditor *tile_data_integer_editor = memnew(TileDataIntegerEditor);
|
TileDataIntegerEditor *tile_data_integer_editor = memnew(TileDataIntegerEditor);
|
||||||
TileDataFloatEditor *tile_data_float_editor = memnew(TileDataFloatEditor);
|
TileDataFloatEditor *tile_data_float_editor = memnew(TileDataFloatEditor);
|
||||||
TileDataOcclusionShapeEditor *tile_data_occlusion_shape_editor = memnew(TileDataOcclusionShapeEditor);
|
TileDataOcclusionShapeEditor *tile_data_occlusion_shape_editor = memnew(TileDataOcclusionShapeEditor);
|
||||||
|
@ -2351,11 +2351,11 @@ int TileData::get_z_index() const {
|
|||||||
return z_index;
|
return z_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileData::set_y_sort_origin(Vector2i p_y_sort_origin) {
|
void TileData::set_y_sort_origin(int p_y_sort_origin) {
|
||||||
y_sort_origin = p_y_sort_origin;
|
y_sort_origin = p_y_sort_origin;
|
||||||
emit_signal("changed");
|
emit_signal("changed");
|
||||||
}
|
}
|
||||||
Vector2i TileData::get_y_sort_origin() const {
|
int TileData::get_y_sort_origin() const {
|
||||||
return y_sort_origin;
|
return y_sort_origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3020,7 +3020,7 @@ void TileData::_bind_methods() {
|
|||||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "texture_offset"), "set_texture_offset", "get_texture_offset");
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "texture_offset"), "set_texture_offset", "get_texture_offset");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
|
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index"), "set_z_index", "get_z_index");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "z_index"), "set_z_index", "get_z_index");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "y_sort_origin"), "set_y_sort_origin", "get_y_sort_origin");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "y_sort_origin"), "set_y_sort_origin", "get_y_sort_origin");
|
||||||
|
|
||||||
ADD_GROUP("Terrains", "");
|
ADD_GROUP("Terrains", "");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "terrain_set"), "set_terrain_set", "get_terrain_set");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "terrain_set"), "set_terrain_set", "get_terrain_set");
|
||||||
@ -3866,6 +3866,12 @@ void TileSetPluginAtlasRendering::tilemap_notification(TileMap *p_tile_map, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
case CanvasItem::NOTIFICATION_DRAW: {
|
||||||
|
Ref<TileSet> tile_set = p_tile_map->get_tileset();
|
||||||
|
if (tile_set.is_valid()) {
|
||||||
|
RenderingServer::get_singleton()->canvas_item_set_sort_children_by_y(p_tile_map->get_canvas_item(), tile_set->is_y_sorting());
|
||||||
|
}
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3978,7 +3984,11 @@ void TileSetPluginAtlasRendering::update_dirty_quadrants(TileMap *p_tile_map, Se
|
|||||||
int z_index = tile_data->get_z_index();
|
int z_index = tile_data->get_z_index();
|
||||||
|
|
||||||
// Quandrant pos.
|
// Quandrant pos.
|
||||||
Vector2 position = p_tile_map->map_to_world(q.coords * p_tile_map->get_effective_quadrant_size()) - tile_set->get_tile_size() / 2;
|
Vector2 position = p_tile_map->map_to_world(q.coords * p_tile_map->get_effective_quadrant_size());
|
||||||
|
if (tile_set->is_y_sorting()) {
|
||||||
|
// When Y-sorting, the quandrant size is sure to be 1, we can thus offset the CanvasItem.
|
||||||
|
position.y += tile_data->get_y_sort_origin();
|
||||||
|
}
|
||||||
|
|
||||||
// --- CanvasItems ---
|
// --- CanvasItems ---
|
||||||
// Create two canvas items, for rendering and debug.
|
// Create two canvas items, for rendering and debug.
|
||||||
@ -3986,16 +3996,18 @@ void TileSetPluginAtlasRendering::update_dirty_quadrants(TileMap *p_tile_map, Se
|
|||||||
|
|
||||||
// Check if the material or the z_index changed.
|
// Check if the material or the z_index changed.
|
||||||
if (prev_canvas_item == RID() || prev_material != mat || prev_z_index != z_index) {
|
if (prev_canvas_item == RID() || prev_material != mat || prev_z_index != z_index) {
|
||||||
|
// If so, create a new CanvasItem.
|
||||||
canvas_item = rs->canvas_item_create();
|
canvas_item = rs->canvas_item_create();
|
||||||
if (mat.is_valid()) {
|
if (mat.is_valid()) {
|
||||||
rs->canvas_item_set_material(canvas_item, mat->get_rid());
|
rs->canvas_item_set_material(canvas_item, mat->get_rid());
|
||||||
}
|
}
|
||||||
rs->canvas_item_set_parent(canvas_item, p_tile_map->get_canvas_item());
|
rs->canvas_item_set_parent(canvas_item, p_tile_map->get_canvas_item());
|
||||||
rs->canvas_item_set_use_parent_material(canvas_item, p_tile_map->get_use_parent_material() || p_tile_map->get_material().is_valid());
|
rs->canvas_item_set_use_parent_material(canvas_item, p_tile_map->get_use_parent_material() || p_tile_map->get_material().is_valid());
|
||||||
|
|
||||||
Transform2D xform;
|
Transform2D xform;
|
||||||
xform.set_origin(position);
|
xform.set_origin(position);
|
||||||
|
|
||||||
rs->canvas_item_set_transform(canvas_item, xform);
|
rs->canvas_item_set_transform(canvas_item, xform);
|
||||||
|
|
||||||
rs->canvas_item_set_light_mask(canvas_item, p_tile_map->get_light_mask());
|
rs->canvas_item_set_light_mask(canvas_item, p_tile_map->get_light_mask());
|
||||||
rs->canvas_item_set_z_index(canvas_item, z_index);
|
rs->canvas_item_set_z_index(canvas_item, z_index);
|
||||||
|
|
||||||
|
@ -504,7 +504,7 @@ private:
|
|||||||
Ref<ShaderMaterial> material = Ref<ShaderMaterial>();
|
Ref<ShaderMaterial> material = Ref<ShaderMaterial>();
|
||||||
Color modulate = Color(1.0, 1.0, 1.0, 1.0);
|
Color modulate = Color(1.0, 1.0, 1.0, 1.0);
|
||||||
int z_index = 0;
|
int z_index = 0;
|
||||||
Vector2i y_sort_origin = Vector2i();
|
int y_sort_origin = 0;
|
||||||
Vector<Ref<OccluderPolygon2D>> occluders;
|
Vector<Ref<OccluderPolygon2D>> occluders;
|
||||||
|
|
||||||
// Physics
|
// Physics
|
||||||
@ -563,8 +563,8 @@ public:
|
|||||||
Color get_modulate() const;
|
Color get_modulate() const;
|
||||||
void set_z_index(int p_z_index);
|
void set_z_index(int p_z_index);
|
||||||
int get_z_index() const;
|
int get_z_index() const;
|
||||||
void set_y_sort_origin(Vector2i p_y_sort_origin);
|
void set_y_sort_origin(int p_y_sort_origin);
|
||||||
Vector2i get_y_sort_origin() const;
|
int get_y_sort_origin() const;
|
||||||
|
|
||||||
void set_occluder(int p_layer_id, Ref<OccluderPolygon2D> p_occluder_polygon);
|
void set_occluder(int p_layer_id, Ref<OccluderPolygon2D> p_occluder_polygon);
|
||||||
Ref<OccluderPolygon2D> get_occluder(int p_layer_id) const;
|
Ref<OccluderPolygon2D> get_occluder(int p_layer_id) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user