mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 15:39:49 +00:00
Tileset panel UI improvements
This commit is contained in:
parent
3f26e859dc
commit
65895374ab
|
@ -22,7 +22,6 @@ func update_texture() -> void:
|
|||
# Prevent from drawing on empty image portions.
|
||||
if index == 0 and tileset.tiles.size() > 1:
|
||||
var coords := get_tile_coords(i)
|
||||
var rect := Rect2i(coords, tileset.tile_size)
|
||||
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)
|
||||
|
|
|
@ -5,7 +5,9 @@ enum TileEditingMode { MANUAL, AUTO, STACK }
|
|||
|
||||
const TRANSPARENT_CHECKER := preload("res://src/UI/Nodes/TransparentChecker.tscn")
|
||||
|
||||
static var placing_tiles := false
|
||||
static var tile_editing_mode := TileEditingMode.AUTO
|
||||
static var selected_tile_index := 0
|
||||
var current_tileset: TileSetCustom
|
||||
|
||||
@onready var h_flow_container: HFlowContainer = $VBoxContainer/ScrollContainer/HFlowContainer
|
||||
|
@ -34,14 +36,22 @@ 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
|
||||
var button_group := ButtonGroup.new()
|
||||
if selected_tile_index >= tileset.tiles.size():
|
||||
selected_tile_index = 0
|
||||
for i in tileset.tiles.size():
|
||||
var tile = tileset.tiles[i]
|
||||
var button := _create_tile_button(ImageTexture.create_from_image(tile.image), i)
|
||||
var tile := tileset.tiles[i]
|
||||
var texture := ImageTexture.create_from_image(tile.image)
|
||||
var button := _create_tile_button(texture, i, button_group)
|
||||
if i == selected_tile_index:
|
||||
button.button_pressed = true
|
||||
h_flow_container.add_child(button)
|
||||
|
||||
|
||||
func _create_tile_button(texture: Texture2D, index: int) -> Button:
|
||||
func _create_tile_button(texture: Texture2D, index: int, button_group: ButtonGroup) -> Button:
|
||||
var button := Button.new()
|
||||
button.button_group = button_group
|
||||
button.toggle_mode = true
|
||||
button.custom_minimum_size = Vector2i(36, 36)
|
||||
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
||||
var texture_rect := TextureRect.new()
|
||||
|
@ -54,18 +64,19 @@ func _create_tile_button(texture: Texture2D, index: int) -> Button:
|
|||
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()
|
||||
var transparent_checker := TRANSPARENT_CHECKER.instantiate() as ColorRect
|
||||
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))
|
||||
button.toggled.connect(_on_tile_button_toggled.bind(index))
|
||||
return button
|
||||
|
||||
|
||||
func _on_tile_button_pressed(index: int) -> void:
|
||||
print(index)
|
||||
func _on_tile_button_toggled(toggled_on: bool, index: int) -> void:
|
||||
if toggled_on:
|
||||
selected_tile_index = index
|
||||
|
||||
|
||||
func _clear_tile_buttons() -> void:
|
||||
|
@ -73,6 +84,10 @@ func _clear_tile_buttons() -> void:
|
|||
child.queue_free()
|
||||
|
||||
|
||||
func _on_place_tiles_toggled(toggled_on: bool) -> void:
|
||||
placing_tiles = toggled_on
|
||||
|
||||
|
||||
func _on_manual_toggled(toggled_on: bool) -> void:
|
||||
if toggled_on:
|
||||
tile_editing_mode = TileEditingMode.MANUAL
|
||||
|
|
|
@ -15,6 +15,11 @@ script = ExtResource("1_d2oc5")
|
|||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="PlaceTiles" type="CheckBox" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
mouse_default_cursor_shape = 2
|
||||
text = "Place tiles"
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
|
@ -46,6 +51,7 @@ layout_mode = 2
|
|||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
||||
[connection signal="toggled" from="VBoxContainer/PlaceTiles" to="." method="_on_place_tiles_toggled"]
|
||||
[connection signal="toggled" from="VBoxContainer/HBoxContainer/Manual" to="." method="_on_manual_toggled"]
|
||||
[connection signal="toggled" from="VBoxContainer/HBoxContainer/Auto" to="." method="_on_auto_toggled"]
|
||||
[connection signal="toggled" from="VBoxContainer/HBoxContainer/Stack" to="." method="_on_stack_toggled"]
|
||||
|
|
Loading…
Reference in a new issue