mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Make manual tile editing mode automatically update all other image portions that have the same tile index
This commit is contained in:
parent
c1fd209588
commit
2301ba9fcc
|
@ -983,7 +983,7 @@ func undo_or_redo(
|
||||||
var cel := project.frames[frame_index].cels[layer_index]
|
var cel := project.frames[frame_index].cels[layer_index]
|
||||||
if action_name == "Scale":
|
if action_name == "Scale":
|
||||||
cel.size_changed(project.size)
|
cel.size_changed(project.size)
|
||||||
canvas.update_texture(layer_index, frame_index, project)
|
canvas.update_texture(layer_index, frame_index, project, undo)
|
||||||
cel.on_undo_redo(undo)
|
cel.on_undo_redo(undo)
|
||||||
else:
|
else:
|
||||||
for i in project.frames.size():
|
for i in project.frames.size():
|
||||||
|
@ -991,7 +991,7 @@ func undo_or_redo(
|
||||||
var cel := project.frames[i].cels[j]
|
var cel := project.frames[i].cels[j]
|
||||||
if action_name == "Scale":
|
if action_name == "Scale":
|
||||||
cel.size_changed(project.size)
|
cel.size_changed(project.size)
|
||||||
canvas.update_texture(j, i, project)
|
canvas.update_texture(j, i, project, undo)
|
||||||
cel.on_undo_redo(undo)
|
cel.on_undo_redo(undo)
|
||||||
|
|
||||||
canvas.selection.queue_redraw()
|
canvas.selection.queue_redraw()
|
||||||
|
|
|
@ -67,7 +67,7 @@ func get_image() -> Image:
|
||||||
|
|
||||||
|
|
||||||
## Used to update the texture of the cel.
|
## Used to update the texture of the cel.
|
||||||
func update_texture() -> void:
|
func update_texture(_undo := false) -> void:
|
||||||
texture_changed.emit()
|
texture_changed.emit()
|
||||||
if link_set != null:
|
if link_set != null:
|
||||||
var frame := Global.current_project.current_frame
|
var frame := Global.current_project.current_frame
|
||||||
|
|
|
@ -14,6 +14,12 @@ var indices_y: int
|
||||||
## Dictionary of [int] and an [Array] of [bool] ([member TileSetPanel.placing_tiles])
|
## Dictionary of [int] and an [Array] of [bool] ([member TileSetPanel.placing_tiles])
|
||||||
## and [enum TileSetPanel.TileEditingMode].
|
## and [enum TileSetPanel.TileEditingMode].
|
||||||
var undo_redo_modes := {}
|
var undo_redo_modes := {}
|
||||||
|
## Dictionary of [int] and [Array].
|
||||||
|
## The key is the index of the tile in the tileset,
|
||||||
|
## and the value is the index of the tilemap tile that changed first, along with
|
||||||
|
## its image that is being changed when manual mode is enabled.
|
||||||
|
## Gets reset on [method update_tileset].
|
||||||
|
var editing_images := {}
|
||||||
|
|
||||||
|
|
||||||
func _init(_tileset: TileSetCustom, _image: ImageExtended, _opacity := 1.0) -> void:
|
func _init(_tileset: TileSetCustom, _image: ImageExtended, _opacity := 1.0) -> void:
|
||||||
|
@ -30,6 +36,7 @@ func set_index(tile_position: int, index: int) -> void:
|
||||||
|
|
||||||
|
|
||||||
func update_tileset(undo: bool) -> void:
|
func update_tileset(undo: bool) -> void:
|
||||||
|
editing_images.clear()
|
||||||
var undos := tileset.project.undos
|
var undos := tileset.project.undos
|
||||||
if not undo and not _is_redo():
|
if not undo and not _is_redo():
|
||||||
undo_redo_modes[undos] = [TileSetPanel.placing_tiles, TileSetPanel.tile_editing_mode]
|
undo_redo_modes[undos] = [TileSetPanel.placing_tiles, TileSetPanel.tile_editing_mode]
|
||||||
|
@ -42,7 +49,7 @@ func update_tileset(undo: bool) -> void:
|
||||||
var image_portion := image.get_region(rect)
|
var image_portion := image.get_region(rect)
|
||||||
var index := indices[i]
|
var index := indices[i]
|
||||||
if index >= tileset.tiles.size():
|
if index >= tileset.tiles.size():
|
||||||
print(i, " is out of bounds")
|
printerr("Tile at position ", i, ", mapped to ", index, " is out of bounds!")
|
||||||
index = 0
|
index = 0
|
||||||
indices[i] = 0
|
indices[i] = 0
|
||||||
var current_tile := tileset.tiles[index]
|
var current_tile := tileset.tiles[index]
|
||||||
|
@ -57,7 +64,6 @@ func update_tileset(undo: bool) -> void:
|
||||||
continue
|
continue
|
||||||
if image_portion.get_data() != current_tile.image.get_data():
|
if image_portion.get_data() != current_tile.image.get_data():
|
||||||
tileset.replace_tile_at(image_portion, index)
|
tileset.replace_tile_at(image_portion, index)
|
||||||
update_cel_portions()
|
|
||||||
elif tile_editing_mode == TileSetPanel.TileEditingMode.AUTO:
|
elif tile_editing_mode == TileSetPanel.TileEditingMode.AUTO:
|
||||||
handle_auto_editing_mode(i, image_portion)
|
handle_auto_editing_mode(i, image_portion)
|
||||||
else: # Stack
|
else: # Stack
|
||||||
|
@ -195,6 +201,7 @@ func update_cel_portion(tile_position: int) -> void:
|
||||||
image.blit_rect(current_tile.image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
image.blit_rect(current_tile.image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
||||||
|
|
||||||
|
|
||||||
|
## Unused, should delete.
|
||||||
func update_cel_portions() -> void:
|
func update_cel_portions() -> void:
|
||||||
for i in indices.size():
|
for i in indices.size():
|
||||||
update_cel_portion(i)
|
update_cel_portion(i)
|
||||||
|
@ -247,21 +254,35 @@ func _get_tile_editing_mode(undos: int) -> TileSetPanel.TileEditingMode:
|
||||||
|
|
||||||
|
|
||||||
# Overridden Methods:
|
# Overridden Methods:
|
||||||
func update_texture() -> void:
|
func update_texture(undo := false) -> void:
|
||||||
var undos := tileset.project.undos
|
var tile_editing_mode := TileSetPanel.tile_editing_mode
|
||||||
#if undo:
|
if undo or _is_redo() or tile_editing_mode != TileSetPanel.TileEditingMode.MANUAL:
|
||||||
#undos += 1
|
super.update_texture(undo)
|
||||||
var tile_editing_mode := _get_tile_editing_mode(undos)
|
return
|
||||||
if tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL:
|
|
||||||
for i in indices.size():
|
for i in indices.size():
|
||||||
var index := indices[i]
|
var index := indices[i]
|
||||||
|
var coords := get_tile_coords(i)
|
||||||
|
var rect := Rect2i(coords, tileset.tile_size)
|
||||||
|
var image_portion := image.get_region(rect)
|
||||||
|
var current_tile := tileset.tiles[index]
|
||||||
|
if index == 0 and tileset.tiles.size() > 1:
|
||||||
# Prevent from drawing on empty image portions.
|
# Prevent from drawing on empty image portions.
|
||||||
if index == 0 and tileset.tiles.size() > 1:
|
var tile_size := current_tile.image.get_size()
|
||||||
var coords := get_tile_coords(i)
|
image.blit_rect(current_tile.image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
||||||
var current_tile := tileset.tiles[index]
|
continue
|
||||||
var tile_size := current_tile.image.get_size()
|
if editing_images.has(index):
|
||||||
image.blit_rect(current_tile.image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
var editing_portion := editing_images[index][0] as int
|
||||||
super.update_texture()
|
if i == editing_portion:
|
||||||
|
editing_images[index] = [i, image_portion]
|
||||||
|
var editing_image := editing_images[index][1] as Image
|
||||||
|
if editing_image.get_data() != image_portion.get_data():
|
||||||
|
var tile_size := image_portion.get_size()
|
||||||
|
image.blit_rect(editing_image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
||||||
|
else:
|
||||||
|
if image_portion.get_data() != current_tile.image.get_data():
|
||||||
|
editing_images[index] = [i, image_portion]
|
||||||
|
super.update_texture(undo)
|
||||||
|
|
||||||
|
|
||||||
func size_changed(new_size: Vector2i) -> void:
|
func size_changed(new_size: Vector2i) -> void:
|
||||||
|
|
|
@ -54,9 +54,9 @@ func get_image() -> ImageExtended:
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
func update_texture() -> void:
|
func update_texture(undo := false) -> void:
|
||||||
image_texture.set_image(image)
|
image_texture.set_image(image)
|
||||||
super.update_texture()
|
super.update_texture(undo)
|
||||||
|
|
||||||
|
|
||||||
func get_class_name() -> String:
|
func get_class_name() -> String:
|
||||||
|
|
|
@ -110,13 +110,15 @@ func camera_zoom() -> void:
|
||||||
Global.transparent_checker.update_rect()
|
Global.transparent_checker.update_rect()
|
||||||
|
|
||||||
|
|
||||||
func update_texture(layer_i: int, frame_i := -1, project := Global.current_project) -> void:
|
func update_texture(
|
||||||
|
layer_i: int, frame_i := -1, project := Global.current_project, undo := false
|
||||||
|
) -> void:
|
||||||
if frame_i == -1:
|
if frame_i == -1:
|
||||||
frame_i = project.current_frame
|
frame_i = project.current_frame
|
||||||
|
|
||||||
if frame_i < project.frames.size() and layer_i < project.layers.size():
|
if frame_i < project.frames.size() and layer_i < project.layers.size():
|
||||||
var current_cel := project.frames[frame_i].cels[layer_i]
|
var current_cel := project.frames[frame_i].cels[layer_i]
|
||||||
current_cel.update_texture()
|
current_cel.update_texture(undo)
|
||||||
# Needed so that changes happening to the non-selected layer(s) are also visible
|
# Needed so that changes happening to the non-selected layer(s) are also visible
|
||||||
# e.g. when undoing/redoing, when applying image effects to the entire frame, etc
|
# e.g. when undoing/redoing, when applying image effects to the entire frame, etc
|
||||||
if frame_i != project.current_frame:
|
if frame_i != project.current_frame:
|
||||||
|
|
Loading…
Reference in a new issue