From 889e93e548e3db5fa47365b0b1260fce59f05404 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 2 Dec 2024 23:42:08 +0200 Subject: [PATCH] Add support for the draw tile mode for the rest of the draw tools, except bucket Also fixes issues with the draw tile mode with the pencil and eraser tools, such as leaving gaps if the mouse is moving fast, and support for spacing and fill inside tool options. --- src/Tools/BaseDraw.gd | 10 +++++++--- src/Tools/BaseShapeDrawer.gd | 9 ++++++--- src/Tools/DesignTools/CurveTool.gd | 9 ++++++--- src/Tools/DesignTools/Eraser.gd | 12 +----------- src/Tools/DesignTools/LineTool.gd | 11 +++++++---- src/Tools/DesignTools/Pencil.gd | 11 ----------- 6 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/Tools/BaseDraw.gd b/src/Tools/BaseDraw.gd index f8cd6e201..a54b05c35 100644 --- a/src/Tools/BaseDraw.gd +++ b/src/Tools/BaseDraw.gd @@ -18,6 +18,7 @@ var _brush_image := Image.new() var _orignal_brush_image := Image.new() ## Contains the original _brush_image, without resizing var _brush_texture := ImageTexture.new() var _strength := 1.0 +var _is_eraser := false @warning_ignore("unused_private_class_variable") var _picking_color := false @@ -320,12 +321,12 @@ func draw_end(pos: Vector2i) -> void: _polylines = _create_polylines(_indicator) -func draw_tile(pos: Vector2i, tile_index: int) -> void: +func draw_tile(pos: Vector2i) -> void: + var tile_position := get_cell_position(pos) + var tile_index := 0 if _is_eraser else TileSetPanel.selected_tile_index for cel in _get_selected_draw_cels(): if cel is not CelTileMap: return - pos = Global.current_project.tiles.get_canon_position(pos) - var tile_position := get_cell_position(pos) (cel as CelTileMap).set_index(tile_position, tile_index) @@ -570,6 +571,9 @@ func _set_pixel_no_cache(pos: Vector2i, ignore_mirroring := false) -> void: pos = _stroke_project.tiles.get_canon_position(pos) if Global.current_project.has_selection: pos = Global.current_project.selection_map.get_canon_position(pos) + if is_placing_tiles(): + draw_tile(pos) + return if !_stroke_project.can_pixel_get_drawn(pos): return diff --git a/src/Tools/BaseShapeDrawer.gd b/src/Tools/BaseShapeDrawer.gd index 0e7550092..3050d7be0 100644 --- a/src/Tools/BaseShapeDrawer.gd +++ b/src/Tools/BaseShapeDrawer.gd @@ -189,9 +189,12 @@ func _draw_shape(origin: Vector2i, dest: Vector2i) -> void: _drawer.reset() # Draw each point offsetted based on the shape's thickness var draw_pos := point + thickness_vector - if Global.current_project.can_pixel_get_drawn(draw_pos): - for image in images: - _drawer.set_pixel(image, draw_pos, tool_slot.color) + if is_placing_tiles(): + draw_tile(draw_pos) + else: + if Global.current_project.can_pixel_get_drawn(draw_pos): + for image in images: + _drawer.set_pixel(image, draw_pos, tool_slot.color) commit_undo() diff --git a/src/Tools/DesignTools/CurveTool.gd b/src/Tools/DesignTools/CurveTool.gd index fc690b584..2ebcc875e 100644 --- a/src/Tools/DesignTools/CurveTool.gd +++ b/src/Tools/DesignTools/CurveTool.gd @@ -195,9 +195,12 @@ func _draw_shape() -> void: func _draw_pixel(point: Vector2i, images: Array[ImageExtended]) -> void: - if Global.current_project.can_pixel_get_drawn(point): - for image in images: - _drawer.set_pixel(image, point, tool_slot.color) + if is_placing_tiles(): + draw_tile(point) + else: + if Global.current_project.can_pixel_get_drawn(point): + for image in images: + _drawer.set_pixel(image, point, tool_slot.color) func _clear() -> void: diff --git a/src/Tools/DesignTools/Eraser.gd b/src/Tools/DesignTools/Eraser.gd index a2ea9b501..e28868d87 100644 --- a/src/Tools/DesignTools/Eraser.gd +++ b/src/Tools/DesignTools/Eraser.gd @@ -19,6 +19,7 @@ class EraseOp: func _init() -> void: _drawer.color_op = EraseOp.new() + _is_eraser = true _clear_image = Image.create(1, 1, false, Image.FORMAT_RGBA8) _clear_image.fill(Color(0, 0, 0, 0)) @@ -44,9 +45,6 @@ func draw_start(pos: Vector2i) -> void: _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 @@ -75,9 +73,6 @@ 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: @@ -99,11 +94,6 @@ 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: diff --git a/src/Tools/DesignTools/LineTool.gd b/src/Tools/DesignTools/LineTool.gd index f856cd6ac..668bfcc21 100644 --- a/src/Tools/DesignTools/LineTool.gd +++ b/src/Tools/DesignTools/LineTool.gd @@ -174,10 +174,13 @@ func _draw_shape() -> void: for point in points: # Reset drawer every time because pixel perfect sometimes breaks the tool _drawer.reset() - # Draw each point offsetted based on the shape's thickness - if Global.current_project.can_pixel_get_drawn(point): - for image in images: - _drawer.set_pixel(image, point, tool_slot.color) + if is_placing_tiles(): + draw_tile(point) + else: + # Draw each point offsetted based on the shape's thickness + if Global.current_project.can_pixel_get_drawn(point): + for image in images: + _drawer.set_pixel(image, point, tool_slot.color) commit_undo() diff --git a/src/Tools/DesignTools/Pencil.gd b/src/Tools/DesignTools/Pencil.gd index 825645b51..1817d8db1 100644 --- a/src/Tools/DesignTools/Pencil.gd +++ b/src/Tools/DesignTools/Pencil.gd @@ -104,9 +104,6 @@ func draw_start(pos: Vector2i) -> void: Global.canvas.selection.transform_content_confirm() prepare_undo("Draw") - if is_placing_tiles(): - draw_tile(pos, TileSetPanel.selected_tile_index) - return var can_skip_mask := true if tool_slot.color.a < 1 and !_overwrite: can_skip_mask = false @@ -145,9 +142,6 @@ 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, TileSetPanel.selected_tile_index) - return if _draw_line: _spacing_mode = false # spacing mode is disabled during line mode @@ -173,11 +167,6 @@ 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, TileSetPanel.selected_tile_index) - commit_undo() - return if _draw_line: _spacing_mode = false # spacing mode is disabled during line mode