mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 09:39:48 +00:00
Improve tileset panel UI updating logic
This commit is contained in:
parent
1bb908638b
commit
7f82be13ab
|
@ -16,7 +16,6 @@ func _init(_tileset: TileSetCustom, _image: ImageExtended, _opacity := 1.0) -> v
|
|||
|
||||
|
||||
func update_texture() -> void:
|
||||
super.update_texture()
|
||||
if TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL:
|
||||
for i in indices.size():
|
||||
var index := indices[i]
|
||||
|
@ -27,6 +26,7 @@ func update_texture() -> void:
|
|||
var current_tile := tileset.tiles[index]
|
||||
var tile_size := current_tile.image.get_size()
|
||||
image.blit_rect(current_tile.image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
||||
super.update_texture()
|
||||
|
||||
|
||||
func update_tileset() -> void:
|
||||
|
|
|
@ -8,7 +8,6 @@ signal serialized(dict: Dictionary)
|
|||
signal about_to_deserialize(dict: Dictionary)
|
||||
signal resized
|
||||
signal timeline_updated
|
||||
signal tilesets_updated
|
||||
|
||||
const INDEXED_MODE := Image.FORMAT_MAX + 1
|
||||
|
||||
|
@ -937,4 +936,3 @@ func reorder_reference_image(from: int, to: int) -> void:
|
|||
|
||||
func add_tileset(tileset: TileSetCustom) -> void:
|
||||
tilesets.append(tileset)
|
||||
tilesets_updated.emit()
|
||||
|
|
|
@ -10,31 +10,28 @@ var current_tileset: TileSetCustom
|
|||
|
||||
|
||||
func _ready() -> void:
|
||||
Global.project_switched.connect(_on_project_switched)
|
||||
Global.project_switched.connect(_update_tilesets)
|
||||
Global.current_project.tilesets_updated.connect(_update_tilesets)
|
||||
Global.cel_switched.connect(_on_cel_switched)
|
||||
Global.project_switched.connect(_on_cel_switched)
|
||||
|
||||
|
||||
func _on_project_switched() -> void:
|
||||
if not Global.current_project.tilesets_updated.is_connected(_update_tilesets):
|
||||
Global.current_project.tilesets_updated.connect(_update_tilesets)
|
||||
|
||||
|
||||
# TODO: Handle signal methods better and rename them to avoid confusion.
|
||||
func _update_tilesets() -> void:
|
||||
for child in h_flow_container.get_children():
|
||||
child.queue_free()
|
||||
if Global.current_project.tilesets.size() == 0:
|
||||
func _on_cel_switched() -> void:
|
||||
if Global.current_project.get_current_cel() is not CelTileMap:
|
||||
_clear_tile_buttons()
|
||||
return
|
||||
var tileset := Global.current_project.tilesets[0]
|
||||
if not tileset.updated.is_connected(_update_tileset):
|
||||
tileset.updated.connect(_update_tileset)
|
||||
var cel := Global.current_project.get_current_cel() as CelTileMap
|
||||
if not cel.tileset.updated.is_connected(_update_tileset):
|
||||
cel.tileset.updated.connect(_update_tileset.bind(cel))
|
||||
_update_tileset(cel)
|
||||
|
||||
|
||||
func _update_tileset() -> void:
|
||||
for child in h_flow_container.get_children():
|
||||
child.queue_free()
|
||||
var tileset := Global.current_project.tilesets[0]
|
||||
func _update_tileset(cel: BaseCel) -> void:
|
||||
_clear_tile_buttons()
|
||||
if cel is not CelTileMap:
|
||||
return
|
||||
var tilemap_cel := cel as CelTileMap
|
||||
if tilemap_cel != Global.current_project.get_current_cel():
|
||||
tilemap_cel.tileset.updated.disconnect(_update_tileset)
|
||||
var tileset := tilemap_cel.tileset
|
||||
for tile in tileset.tiles:
|
||||
var texture_rect := TextureButton.new()
|
||||
texture_rect.custom_minimum_size = Vector2i(32, 32)
|
||||
|
@ -42,6 +39,11 @@ func _update_tileset() -> void:
|
|||
h_flow_container.add_child(texture_rect)
|
||||
|
||||
|
||||
func _clear_tile_buttons() -> void:
|
||||
for child in h_flow_container.get_children():
|
||||
child.queue_free()
|
||||
|
||||
|
||||
func _on_manual_toggled(toggled_on: bool) -> void:
|
||||
if toggled_on:
|
||||
tile_editing_mode = TileEditingMode.MANUAL
|
||||
|
|
Loading…
Reference in a new issue