2019-11-29 22:41:34 +00:00
|
|
|
extends BaseButton
|
2019-09-25 19:59:48 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-06-05 14:21:35 +00:00
|
|
|
export var brush_type := 0 # Global.Brush_Types.PIXEL
|
2019-12-27 20:02:47 +00:00
|
|
|
export var custom_brush_index := -3
|
2019-12-26 19:36:56 +00:00
|
|
|
var random_brushes := []
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-09-25 19:59:48 +00:00
|
|
|
|
|
|
|
func _on_BrushButton_pressed() -> void:
|
2020-01-27 22:19:55 +00:00
|
|
|
# Delete the brush on middle mouse press
|
|
|
|
if Input.is_action_just_released("middle_mouse"):
|
|
|
|
_on_DeleteButton_pressed()
|
|
|
|
return
|
2020-03-28 03:15:09 +00:00
|
|
|
|
2020-05-31 15:40:47 +00:00
|
|
|
# Change brush
|
|
|
|
Global.current_brush_types[Global.brush_type_window_position] = brush_type
|
|
|
|
Global.custom_brush_indexes[Global.brush_type_window_position] = custom_brush_index
|
2020-06-05 14:21:35 +00:00
|
|
|
if brush_type == Global.Brush_Types.FILE or brush_type == Global.Brush_Types.RANDOM_FILE or brush_type == Global.Brush_Types.CUSTOM:
|
2020-05-31 21:44:53 +00:00
|
|
|
if Global.current_tools[Global.brush_type_window_position] == Global.Tools.PENCIL:
|
2020-05-31 15:40:47 +00:00
|
|
|
Global.color_interpolation_containers[Global.brush_type_window_position].visible = true
|
2020-06-05 14:21:35 +00:00
|
|
|
else:
|
2020-05-31 15:40:47 +00:00
|
|
|
Global.color_interpolation_containers[Global.brush_type_window_position].visible = false
|
2019-11-29 22:41:34 +00:00
|
|
|
|
2020-05-31 15:40:47 +00:00
|
|
|
Global.update_custom_brush(Global.brush_type_window_position)
|
|
|
|
Global.brushes_popup.hide()
|
2019-11-11 13:55:28 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-11-11 13:55:28 +00:00
|
|
|
func _on_DeleteButton_pressed() -> void:
|
2020-06-05 14:21:35 +00:00
|
|
|
if brush_type != Global.Brush_Types.CUSTOM:
|
|
|
|
return
|
|
|
|
|
|
|
|
if Global.custom_brush_indexes[0] == custom_brush_index:
|
|
|
|
Global.custom_brush_indexes[0] = -3
|
|
|
|
Global.current_brush_types[0] = Global.Brush_Types.PIXEL
|
|
|
|
Global.update_custom_brush(0)
|
|
|
|
if Global.custom_brush_indexes[1] == custom_brush_index:
|
|
|
|
Global.custom_brush_indexes[1] = -3
|
|
|
|
Global.current_brush_types[1] = Global.Brush_Types.PIXEL
|
|
|
|
Global.update_custom_brush(1)
|
|
|
|
|
|
|
|
Global.current_project.undos += 1
|
|
|
|
Global.current_project.undo_redo.create_action("Delete Custom Brush")
|
|
|
|
for i in range(Global.project_brush_container.get_child_count()):
|
|
|
|
var bb = Global.project_brush_container.get_child(i)
|
|
|
|
if Global.custom_brush_indexes[0] == bb.custom_brush_index:
|
|
|
|
Global.custom_brush_indexes[0] -= 1
|
|
|
|
if Global.custom_brush_indexes[1] == bb.custom_brush_index:
|
|
|
|
Global.custom_brush_indexes[1] -= 1
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.add_do_property(bb, "custom_brush_index", bb.custom_brush_index - 1)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(bb, "custom_brush_index", bb.custom_brush_index)
|
|
|
|
|
|
|
|
var custom_brushes: Array = Global.current_project.brushes.duplicate()
|
|
|
|
custom_brushes.remove(custom_brush_index)
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "brushes", custom_brushes)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "brushes", Global.current_project.brushes)
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "redo_custom_brush", self)
|
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo_custom_brush", self)
|
|
|
|
Global.current_project.undo_redo.commit_action()
|
2019-11-11 13:55:28 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-11-11 13:55:28 +00:00
|
|
|
func _on_BrushButton_mouse_entered() -> void:
|
2020-02-10 22:06:24 +00:00
|
|
|
if brush_type == Global.Brush_Types.CUSTOM:
|
2019-11-11 13:55:28 +00:00
|
|
|
$DeleteButton.visible = true
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-11-11 13:55:28 +00:00
|
|
|
func _on_BrushButton_mouse_exited() -> void:
|
2020-02-10 22:06:24 +00:00
|
|
|
if brush_type == Global.Brush_Types.CUSTOM:
|
2019-11-11 13:55:28 +00:00
|
|
|
$DeleteButton.visible = false
|