mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Better tile buttons
This commit is contained in:
parent
6b77e30e08
commit
b87bfdf7e8
|
@ -3,6 +3,8 @@ extends PanelContainer
|
|||
|
||||
enum TileEditingMode { MANUAL, AUTO, STACK }
|
||||
|
||||
const TRANSPARENT_CHECKER := preload("res://src/UI/Nodes/TransparentChecker.tscn")
|
||||
|
||||
static var tile_editing_mode := TileEditingMode.AUTO
|
||||
var current_tileset: TileSetCustom
|
||||
|
||||
|
@ -32,11 +34,38 @@ func _update_tileset(cel: BaseCel) -> void:
|
|||
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)
|
||||
texture_rect.texture_normal = ImageTexture.create_from_image(tile.image)
|
||||
h_flow_container.add_child(texture_rect)
|
||||
for i in tileset.tiles.size():
|
||||
var tile = tileset.tiles[i]
|
||||
var button := _create_tile_button(ImageTexture.create_from_image(tile.image), i)
|
||||
h_flow_container.add_child(button)
|
||||
|
||||
|
||||
func _create_tile_button(texture: Texture2D, index: int) -> Button:
|
||||
var button := Button.new()
|
||||
button.custom_minimum_size = Vector2i(36, 36)
|
||||
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
var texture_rect := TextureRect.new()
|
||||
texture_rect.texture = texture
|
||||
texture_rect.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||||
texture_rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
texture_rect.set_anchor_and_offset(SIDE_LEFT, 0, 6)
|
||||
texture_rect.set_anchor_and_offset(SIDE_RIGHT, 1, -6)
|
||||
texture_rect.set_anchor_and_offset(SIDE_TOP, 0, 6)
|
||||
texture_rect.set_anchor_and_offset(SIDE_BOTTOM, 1, -6)
|
||||
texture_rect.grow_horizontal = Control.GROW_DIRECTION_BOTH
|
||||
texture_rect.grow_vertical = Control.GROW_DIRECTION_BOTH
|
||||
var transparent_checker := TRANSPARENT_CHECKER.instantiate()
|
||||
transparent_checker.set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
transparent_checker.show_behind_parent = true
|
||||
texture_rect.add_child(transparent_checker)
|
||||
button.add_child(texture_rect)
|
||||
button.tooltip_text = str(index)
|
||||
button.pressed.connect(_on_tile_button_pressed.bind(index))
|
||||
return button
|
||||
|
||||
|
||||
func _on_tile_button_pressed(index: int) -> void:
|
||||
print(index)
|
||||
|
||||
|
||||
func _clear_tile_buttons() -> void:
|
||||
|
|
Loading…
Reference in a new issue