2019-11-29 22:41:34 +00:00
|
|
|
extends BaseButton
|
2019-09-25 19:59:48 +00:00
|
|
|
|
|
|
|
var brush_type = Global.BRUSH_TYPES.PIXEL
|
|
|
|
var custom_brush_index := -1
|
|
|
|
|
|
|
|
func _on_BrushButton_pressed() -> void:
|
2019-11-29 22:41:34 +00:00
|
|
|
if Global.brushes_popup.rect_global_position == Global.left_brush_type_button.rect_global_position:
|
2019-09-25 19:59:48 +00:00
|
|
|
Global.current_left_brush_type = brush_type
|
2019-10-02 18:58:19 +00:00
|
|
|
Global.left_brush_indicator.get_parent().remove_child(Global.left_brush_indicator)
|
|
|
|
add_child(Global.left_brush_indicator)
|
2019-11-29 22:41:34 +00:00
|
|
|
if custom_brush_index > -1: #Custom brush
|
2019-09-25 19:59:48 +00:00
|
|
|
Global.custom_left_brush_index = custom_brush_index
|
2019-11-29 22:41:34 +00:00
|
|
|
if hint_tooltip == "":
|
|
|
|
Global.left_brush_type_label.text = "Custom brush"
|
|
|
|
else:
|
|
|
|
Global.left_brush_type_label.text = "Brush: %s" % hint_tooltip
|
|
|
|
else: #Pixel brush
|
|
|
|
Global.left_brush_type_label.text = "Brush: Pixel"
|
|
|
|
|
|
|
|
Global.update_left_custom_brush()
|
2019-10-25 14:38:38 +00:00
|
|
|
|
2019-11-29 22:41:34 +00:00
|
|
|
else:
|
2019-09-25 19:59:48 +00:00
|
|
|
Global.current_right_brush_type = brush_type
|
2019-10-02 18:58:19 +00:00
|
|
|
Global.right_brush_indicator.get_parent().remove_child(Global.right_brush_indicator)
|
|
|
|
add_child(Global.right_brush_indicator)
|
2019-09-25 19:59:48 +00:00
|
|
|
if custom_brush_index > -1:
|
|
|
|
Global.custom_right_brush_index = custom_brush_index
|
2019-11-29 22:41:34 +00:00
|
|
|
if hint_tooltip == "":
|
|
|
|
Global.right_brush_type_label.text = "Custom brush"
|
|
|
|
else:
|
|
|
|
Global.right_brush_type_label.text = "Brush: %s" % hint_tooltip
|
|
|
|
else: #Pixel brush
|
|
|
|
Global.right_brush_type_label.text = "Brush: Pixel"
|
|
|
|
|
|
|
|
Global.update_right_custom_brush()
|
2019-11-11 13:55:28 +00:00
|
|
|
|
|
|
|
func _on_DeleteButton_pressed() -> void:
|
|
|
|
if brush_type == Global.BRUSH_TYPES.CUSTOM:
|
|
|
|
if Global.custom_left_brush_index == custom_brush_index:
|
|
|
|
Global.custom_left_brush_index = -1
|
|
|
|
Global.current_left_brush_type = Global.BRUSH_TYPES.PIXEL
|
|
|
|
remove_child(Global.left_brush_indicator)
|
2019-11-20 12:41:02 +00:00
|
|
|
Global.file_brush_container.get_child(0).add_child(Global.left_brush_indicator)
|
2019-11-11 13:55:28 +00:00
|
|
|
if Global.custom_right_brush_index == custom_brush_index:
|
|
|
|
Global.custom_right_brush_index = -1
|
|
|
|
Global.current_right_brush_type = Global.BRUSH_TYPES.PIXEL
|
|
|
|
remove_child(Global.right_brush_indicator)
|
2019-11-20 12:41:02 +00:00
|
|
|
Global.file_brush_container.get_child(0).add_child(Global.right_brush_indicator)
|
2019-11-11 13:55:28 +00:00
|
|
|
|
2019-11-11 16:41:43 +00:00
|
|
|
Global.undos += 1
|
|
|
|
Global.undo_redo.create_action("Delete Custom Brush")
|
2019-11-20 12:41:02 +00:00
|
|
|
for i in range(custom_brush_index - 1, Global.project_brush_container.get_child_count()):
|
|
|
|
var bb = Global.project_brush_container.get_child(i)
|
2019-11-11 16:41:43 +00:00
|
|
|
if Global.custom_left_brush_index == bb.custom_brush_index:
|
2019-11-11 13:55:28 +00:00
|
|
|
Global.custom_left_brush_index -= 1
|
2019-11-11 16:41:43 +00:00
|
|
|
if Global.custom_right_brush_index == bb.custom_brush_index:
|
2019-11-11 13:55:28 +00:00
|
|
|
Global.custom_right_brush_index -= 1
|
|
|
|
|
2019-11-11 16:41:43 +00:00
|
|
|
Global.undo_redo.add_do_property(bb, "custom_brush_index", bb.custom_brush_index - 1)
|
|
|
|
Global.undo_redo.add_undo_property(bb, "custom_brush_index", bb.custom_brush_index)
|
|
|
|
|
|
|
|
var custom_brushes := Global.custom_brushes.duplicate()
|
|
|
|
custom_brushes.remove(custom_brush_index)
|
|
|
|
|
|
|
|
Global.undo_redo.add_do_property(Global, "custom_brushes", custom_brushes)
|
|
|
|
Global.undo_redo.add_undo_property(Global, "custom_brushes", Global.custom_brushes)
|
|
|
|
Global.undo_redo.add_do_method(Global, "redo_custom_brush", self)
|
|
|
|
Global.undo_redo.add_undo_method(Global, "undo_custom_brush", self)
|
|
|
|
Global.undo_redo.commit_action()
|
2019-11-11 13:55:28 +00:00
|
|
|
|
|
|
|
func _on_BrushButton_mouse_entered() -> void:
|
|
|
|
if brush_type == Global.BRUSH_TYPES.CUSTOM:
|
|
|
|
$DeleteButton.visible = true
|
|
|
|
|
|
|
|
func _on_BrushButton_mouse_exited() -> void:
|
|
|
|
if brush_type == Global.BRUSH_TYPES.CUSTOM:
|
|
|
|
$DeleteButton.visible = false
|