1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 01:29:49 +00:00

Place tiles mode works with eraser and color picker tools

This commit is contained in:
Emmanouil Papadeas 2024-11-25 00:15:06 +02:00
parent c1028131a1
commit 6b95908ef3
7 changed files with 38 additions and 10 deletions

View file

@ -2,6 +2,8 @@
extends Node
signal color_changed(color_info: Dictionary, button: int)
@warning_ignore("unused_signal")
signal selected_tile_index_changed(tile_index: int)
signal config_changed(slot_idx: int, config: Dictionary)
@warning_ignore("unused_signal")
signal flip_rotated(flip_x, flip_y, rotate_90, rotate_180, rotate_270)

View file

@ -46,6 +46,10 @@ func update_tileset(undo: bool) -> void:
var rect := Rect2i(coords, tileset.tile_size)
var image_portion := image.get_region(rect)
var index := indices[i]
if index >= tileset.tiles.size():
print(i, " is out of bounds")
index = 0
indices[i] = 0
var current_tile := tileset.tiles[index]
if TileSetPanel.tile_editing_mode == TileSetPanel.TileEditingMode.MANUAL:
if image_portion.is_invisible():

View file

@ -354,7 +354,11 @@ func _pick_color(pos: Vector2i) -> void:
if pos.x < 0 or pos.y < 0:
return
if is_placing_tiles():
var tile_position := get_tile_position(pos)
var cel := Global.current_project.get_current_cel() as CelTileMap
Tools.selected_tile_index_changed.emit(cel.indices[tile_position])
return
var image := Image.new()
image.copy_from(_get_draw_image())
if pos.x > image.get_width() - 1 or pos.y > image.get_height() - 1:

View file

@ -42,13 +42,14 @@ func draw_start(pos: Vector2i) -> void:
_pick_color(pos)
return
_picking_color = false
Global.canvas.selection.transform_content_confirm()
prepare_undo("Draw")
if is_placing_tiles():
draw_tile(pos, 0)
return
update_mask(_strength == 1)
_changed = false
_drawer.color_op.changed = false
prepare_undo("Draw")
_drawer.reset()
_draw_line = Input.is_action_pressed("draw_create_line")
@ -74,6 +75,9 @@ func draw_move(pos_i: Vector2i) -> void:
if Input.is_action_pressed(&"draw_color_picker", true):
_pick_color(pos)
return
if is_placing_tiles():
draw_tile(pos, 0)
return
if _draw_line:
if Global.mirror_view:
@ -95,6 +99,11 @@ func draw_end(pos: Vector2i) -> void:
if _picking_color:
super.draw_end(pos)
return
if is_placing_tiles():
super.draw_end(pos)
draw_tile(pos, 0)
commit_undo()
return
if _draw_line:
if Global.mirror_view:

View file

@ -63,10 +63,13 @@ func draw_end(pos: Vector2i) -> void:
func _pick_color(pos: Vector2i) -> void:
var project := Global.current_project
pos = project.tiles.get_canon_position(pos)
if pos.x < 0 or pos.y < 0:
return
if is_placing_tiles():
var tile_position := get_tile_position(pos)
var cel := Global.current_project.get_current_cel() as CelTileMap
Tools.selected_tile_index_changed.emit(cel.indices[tile_position])
return
var image := Image.new()
image.copy_from(_get_draw_image())
if pos.x > image.get_width() - 1 or pos.y > image.get_height() - 1:

View file

@ -10,10 +10,11 @@ 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
@onready var tile_button_container: HFlowContainer = %TileButtonContainer
func _ready() -> void:
Tools.selected_tile_index_changed.connect(select_tile)
Global.cel_switched.connect(_on_cel_switched)
Global.project_switched.connect(_on_cel_switched)
@ -45,7 +46,7 @@ func _update_tileset(cel: BaseCel) -> void:
var button := _create_tile_button(texture, i, button_group)
if i == selected_tile_index:
button.button_pressed = true
h_flow_container.add_child(button)
tile_button_container.add_child(button)
func _create_tile_button(texture: Texture2D, index: int, button_group: ButtonGroup) -> Button:
@ -74,13 +75,17 @@ func _create_tile_button(texture: Texture2D, index: int, button_group: ButtonGro
return button
func select_tile(tile_index: int) -> void:
tile_button_container.get_child(tile_index).button_pressed = true
func _on_tile_button_toggled(toggled_on: bool, index: int) -> void:
if toggled_on:
selected_tile_index = index
func _clear_tile_buttons() -> void:
for child in h_flow_container.get_children():
for child in tile_button_container.get_children():
child.queue_free()

View file

@ -46,7 +46,8 @@ text = "Stack"
layout_mode = 2
size_flags_vertical = 3
[node name="HFlowContainer" type="HFlowContainer" parent="VBoxContainer/ScrollContainer"]
[node name="TileButtonContainer" type="HFlowContainer" parent="VBoxContainer/ScrollContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3