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:
|
func update_texture() -> void:
|
||||||
super.update_texture()
|
|
||||||
if TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL:
|
if TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL:
|
||||||
for i in indices.size():
|
for i in indices.size():
|
||||||
var index := indices[i]
|
var index := indices[i]
|
||||||
|
@ -27,6 +26,7 @@ func update_texture() -> void:
|
||||||
var current_tile := tileset.tiles[index]
|
var current_tile := tileset.tiles[index]
|
||||||
var tile_size := current_tile.image.get_size()
|
var tile_size := current_tile.image.get_size()
|
||||||
image.blit_rect(current_tile.image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
image.blit_rect(current_tile.image, Rect2i(Vector2i.ZERO, tile_size), coords)
|
||||||
|
super.update_texture()
|
||||||
|
|
||||||
|
|
||||||
func update_tileset() -> void:
|
func update_tileset() -> void:
|
||||||
|
|
|
@ -8,7 +8,6 @@ signal serialized(dict: Dictionary)
|
||||||
signal about_to_deserialize(dict: Dictionary)
|
signal about_to_deserialize(dict: Dictionary)
|
||||||
signal resized
|
signal resized
|
||||||
signal timeline_updated
|
signal timeline_updated
|
||||||
signal tilesets_updated
|
|
||||||
|
|
||||||
const INDEXED_MODE := Image.FORMAT_MAX + 1
|
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:
|
func add_tileset(tileset: TileSetCustom) -> void:
|
||||||
tilesets.append(tileset)
|
tilesets.append(tileset)
|
||||||
tilesets_updated.emit()
|
|
||||||
|
|
|
@ -10,31 +10,28 @@ var current_tileset: TileSetCustom
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
Global.project_switched.connect(_on_project_switched)
|
Global.cel_switched.connect(_on_cel_switched)
|
||||||
Global.project_switched.connect(_update_tilesets)
|
Global.project_switched.connect(_on_cel_switched)
|
||||||
Global.current_project.tilesets_updated.connect(_update_tilesets)
|
|
||||||
|
|
||||||
|
|
||||||
func _on_project_switched() -> void:
|
func _on_cel_switched() -> void:
|
||||||
if not Global.current_project.tilesets_updated.is_connected(_update_tilesets):
|
if Global.current_project.get_current_cel() is not CelTileMap:
|
||||||
Global.current_project.tilesets_updated.connect(_update_tilesets)
|
_clear_tile_buttons()
|
||||||
|
|
||||||
|
|
||||||
# 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:
|
|
||||||
return
|
return
|
||||||
var tileset := Global.current_project.tilesets[0]
|
var cel := Global.current_project.get_current_cel() as CelTileMap
|
||||||
if not tileset.updated.is_connected(_update_tileset):
|
if not cel.tileset.updated.is_connected(_update_tileset):
|
||||||
tileset.updated.connect(_update_tileset)
|
cel.tileset.updated.connect(_update_tileset.bind(cel))
|
||||||
|
_update_tileset(cel)
|
||||||
|
|
||||||
|
|
||||||
func _update_tileset() -> void:
|
func _update_tileset(cel: BaseCel) -> void:
|
||||||
for child in h_flow_container.get_children():
|
_clear_tile_buttons()
|
||||||
child.queue_free()
|
if cel is not CelTileMap:
|
||||||
var tileset := Global.current_project.tilesets[0]
|
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:
|
for tile in tileset.tiles:
|
||||||
var texture_rect := TextureButton.new()
|
var texture_rect := TextureButton.new()
|
||||||
texture_rect.custom_minimum_size = Vector2i(32, 32)
|
texture_rect.custom_minimum_size = Vector2i(32, 32)
|
||||||
|
@ -42,6 +39,11 @@ func _update_tileset() -> void:
|
||||||
h_flow_container.add_child(texture_rect)
|
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:
|
func _on_manual_toggled(toggled_on: bool) -> void:
|
||||||
if toggled_on:
|
if toggled_on:
|
||||||
tile_editing_mode = TileEditingMode.MANUAL
|
tile_editing_mode = TileEditingMode.MANUAL
|
||||||
|
|
Loading…
Reference in a new issue