mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 22:44:42 -04:00
Changed Global node variables to arrays for left/right
Instead of having 2 variables for left & right nodes, use an array instead. This will help with better looking code, automation and less repetitive code, as seen in ToolButtons.gd. Move related refactoring will follow.
This commit is contained in:
parent
37a8ad2447
commit
c538140de2
12 changed files with 187 additions and 230 deletions
|
@ -14,46 +14,46 @@ func _on_BrushButton_pressed() -> void:
|
|||
|
||||
# Change left brush
|
||||
if Global.brush_type_window_position == "left":
|
||||
Global.current_left_brush_type = brush_type
|
||||
Global.current_brush_type[0] = brush_type
|
||||
Global.custom_left_brush_index = custom_brush_index
|
||||
if custom_brush_index > -1: # Custom brush
|
||||
if Global.current_left_tool == Global.Tools.PENCIL:
|
||||
Global.left_color_interpolation_container.visible = true
|
||||
Global.color_interpolation_containers[0].visible = true
|
||||
# if hint_tooltip == "":
|
||||
# Global.left_brush_type_label.text = tr("Custom brush")
|
||||
# else:
|
||||
# Global.left_brush_type_label.text = tr("Brush:") + " %s" % hint_tooltip
|
||||
elif custom_brush_index == -3: # Pixel brush
|
||||
Global.left_color_interpolation_container.visible = false
|
||||
Global.color_interpolation_containers[0].visible = false
|
||||
# Global.left_brush_type_label.text = tr("Brush: Pixel")
|
||||
elif custom_brush_index == -2: # Circle brush
|
||||
Global.left_color_interpolation_container.visible = false
|
||||
Global.color_interpolation_containers[0].visible = false
|
||||
# Global.left_brush_type_label.text = tr("Brush: Circle")
|
||||
elif custom_brush_index == -1: # Filled Circle brush
|
||||
Global.left_color_interpolation_container.visible = false
|
||||
Global.color_interpolation_containers[0].visible = false
|
||||
# Global.left_brush_type_label.text = tr("Brush: Filled Circle")
|
||||
|
||||
Global.update_left_custom_brush()
|
||||
Global.brushes_popup.hide()
|
||||
|
||||
else: # Change right brush
|
||||
Global.current_right_brush_type = brush_type
|
||||
Global.current_brush_type[1] = brush_type
|
||||
Global.custom_right_brush_index = custom_brush_index
|
||||
if custom_brush_index > -1:
|
||||
if Global.current_right_tool == Global.Tools.PENCIL:
|
||||
Global.right_color_interpolation_container.visible = true
|
||||
Global.color_interpolation_containers[1].visible = true
|
||||
# if hint_tooltip == "":
|
||||
# Global.right_brush_type_label.text = tr("Custom brush")
|
||||
# else:
|
||||
# Global.right_brush_type_label.text = tr("Brush:") + " %s" % hint_tooltip
|
||||
elif custom_brush_index == -3: # Pixel brush
|
||||
Global.right_color_interpolation_container.visible = false
|
||||
Global.color_interpolation_containers[1].visible = false
|
||||
# Global.right_brush_type_label.text = tr("Brush: Pixel")
|
||||
elif custom_brush_index == -2: # Circle brush
|
||||
Global.right_color_interpolation_container.visible = false
|
||||
Global.color_interpolation_containers[1].visible = false
|
||||
# Global.right_brush_type_label.text = tr("Brush: Circle")
|
||||
elif custom_brush_index == -1: # Filled Circle brush
|
||||
Global.right_color_interpolation_container.visible = false
|
||||
Global.color_interpolation_containers[1].visible = false
|
||||
# Global.right_brush_type_label.text = tr("Brush: Filled Circle")
|
||||
|
||||
Global.update_right_custom_brush()
|
||||
|
@ -64,12 +64,12 @@ 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 = -3
|
||||
Global.current_left_brush_type = Global.Brush_Types.PIXEL
|
||||
Global.current_brush_type[0] = Global.Brush_Types.PIXEL
|
||||
# Global.left_brush_type_label.text = "Brush: Pixel"
|
||||
Global.update_left_custom_brush()
|
||||
if Global.custom_right_brush_index == custom_brush_index:
|
||||
Global.custom_right_brush_index = -3
|
||||
Global.current_right_brush_type = Global.Brush_Types.PIXEL
|
||||
Global.current_brush_type[1] = Global.Brush_Types.PIXEL
|
||||
# Global.right_brush_type_label.text = "Brush: Pixel"
|
||||
Global.update_right_custom_brush()
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ var previous_right_color := Color.white
|
|||
|
||||
|
||||
func _on_ColorSwitch_pressed() -> void:
|
||||
var temp: Color = Global.left_color_picker.color
|
||||
Global.left_color_picker.color = Global.right_color_picker.color
|
||||
Global.right_color_picker.color = temp
|
||||
var temp: Color = Global.color_pickers[0].color
|
||||
Global.color_pickers[0].color = Global.color_pickers[1].color
|
||||
Global.color_pickers[1].color = temp
|
||||
Global.update_left_custom_brush()
|
||||
Global.update_right_custom_brush()
|
||||
|
||||
|
@ -18,13 +18,13 @@ func _on_ColorPickerButton_color_changed(color : Color, right : bool):
|
|||
if right:
|
||||
if color.a == 0:
|
||||
if previous_right_color.r != color.r or previous_right_color.g != color.g or previous_right_color.b != color.b:
|
||||
Global.right_color_picker.color.a = 1
|
||||
Global.color_pickers[1].color.a = 1
|
||||
Global.update_right_custom_brush()
|
||||
previous_right_color = color
|
||||
else:
|
||||
if color.a == 0:
|
||||
if previous_left_color.r != color.r or previous_left_color.g != color.g or previous_left_color.b != color.b:
|
||||
Global.left_color_picker.color.a = 1
|
||||
Global.color_pickers[0].color.a = 1
|
||||
Global.update_left_custom_brush()
|
||||
previous_left_color = color
|
||||
|
||||
|
@ -38,8 +38,8 @@ func _on_ColorPickerButton_popup_closed() -> void:
|
|||
|
||||
|
||||
func _on_ColorDefaults_pressed() -> void:
|
||||
Global.left_color_picker.color = Color.black
|
||||
Global.right_color_picker.color = Color.white
|
||||
Global.color_pickers[0].color = Color.black
|
||||
Global.color_pickers[1].color = Color.white
|
||||
Global.update_left_custom_brush()
|
||||
Global.update_right_custom_brush()
|
||||
|
||||
|
@ -58,23 +58,23 @@ func _on_100ZoomButton_pressed() -> void:
|
|||
|
||||
func _on_BrushTypeButton_pressed(right : bool) -> void:
|
||||
if right:
|
||||
Global.brushes_popup.popup(Rect2(Global.right_brush_type_button.rect_global_position, Vector2(226, 72)))
|
||||
Global.brushes_popup.popup(Rect2(Global.brush_type_buttons[1].rect_global_position, Vector2(226, 72)))
|
||||
Global.brush_type_window_position = "right"
|
||||
else:
|
||||
Global.brushes_popup.popup(Rect2(Global.left_brush_type_button.rect_global_position, Vector2(226, 72)))
|
||||
Global.brushes_popup.popup(Rect2(Global.brush_type_buttons[0].rect_global_position, Vector2(226, 72)))
|
||||
Global.brush_type_window_position = "left"
|
||||
|
||||
|
||||
func _on_BrushSizeEdit_value_changed(value : float, right : bool) -> void:
|
||||
var new_size = int(value)
|
||||
if right:
|
||||
Global.right_brush_size_edit.value = value
|
||||
Global.right_brush_size_slider.value = value
|
||||
Global.brush_size_edits[1].value = value
|
||||
Global.brush_size_sliders[1].value = value
|
||||
Global.right_brush_size = new_size
|
||||
Global.update_right_custom_brush()
|
||||
else:
|
||||
Global.left_brush_size_edit.value = value
|
||||
Global.left_brush_size_slider.value = value
|
||||
Global.brush_size_edits[0].value = value
|
||||
Global.brush_size_sliders[0].value = value
|
||||
Global.left_brush_size = new_size
|
||||
Global.update_left_custom_brush()
|
||||
|
||||
|
@ -88,12 +88,12 @@ func _on_PixelPerfectMode_toggled(button_pressed : bool, right : bool) -> void:
|
|||
|
||||
func _on_InterpolateFactor_value_changed(value : float, right : bool) -> void:
|
||||
if right:
|
||||
Global.right_interpolate_spinbox.value = value
|
||||
Global.right_interpolate_slider.value = value
|
||||
Global.interpolate_spinboxes[1].value = value
|
||||
Global.interpolate_sliders[1].value = value
|
||||
Global.update_right_custom_brush()
|
||||
else:
|
||||
Global.left_interpolate_spinbox.value = value
|
||||
Global.left_interpolate_slider.value = value
|
||||
Global.interpolate_spinboxes[0].value = value
|
||||
Global.interpolate_sliders[0].value = value
|
||||
Global.update_left_custom_brush()
|
||||
|
||||
|
||||
|
@ -108,24 +108,24 @@ func _on_FillWithOptions_item_selected(ID : int, right : bool) -> void:
|
|||
if right:
|
||||
Global.right_fill_with = ID
|
||||
if ID == 1:
|
||||
Global.right_fill_pattern_container.visible = true
|
||||
Global.fill_pattern_containers[1].visible = true
|
||||
else:
|
||||
Global.right_fill_pattern_container.visible = false
|
||||
Global.fill_pattern_containers[1].visible = false
|
||||
else:
|
||||
Global.left_fill_with = ID
|
||||
if ID == 1:
|
||||
Global.left_fill_pattern_container.visible = true
|
||||
Global.fill_pattern_containers[0].visible = true
|
||||
else:
|
||||
Global.left_fill_pattern_container.visible = false
|
||||
Global.fill_pattern_containers[0].visible = false
|
||||
|
||||
|
||||
func _on_PatternTypeButton_pressed(right : bool) -> void:
|
||||
if right:
|
||||
Global.pattern_window_position = "right"
|
||||
Global.patterns_popup.popup(Rect2(Global.right_brush_type_button.rect_global_position, Vector2(226, 72)))
|
||||
Global.patterns_popup.popup(Rect2(Global.brush_type_buttons[1].rect_global_position, Vector2(226, 72)))
|
||||
else:
|
||||
Global.pattern_window_position = "left"
|
||||
Global.patterns_popup.popup(Rect2(Global.left_brush_type_button.rect_global_position, Vector2(226, 72)))
|
||||
Global.patterns_popup.popup(Rect2(Global.brush_type_buttons[0].rect_global_position, Vector2(226, 72)))
|
||||
|
||||
|
||||
func _on_PatternOffsetX_value_changed(value : float, right : bool) -> void:
|
||||
|
@ -152,12 +152,12 @@ func _on_LightenDarken_item_selected(ID : int, right : bool) -> void:
|
|||
func _on_LDAmount_value_changed(value : float, right : bool) -> void:
|
||||
if right:
|
||||
Global.right_ld_amount = value / 100
|
||||
Global.right_ld_amount_slider.value = value
|
||||
Global.right_ld_amount_spinbox.value = value
|
||||
Global.ld_amount_sliders[1].value = value
|
||||
Global.ld_amount_spinboxes[1].value = value
|
||||
else:
|
||||
Global.left_ld_amount = value / 100
|
||||
Global.left_ld_amount_slider.value = value
|
||||
Global.left_ld_amount_spinbox.value = value
|
||||
Global.ld_amount_sliders[0].value = value
|
||||
Global.ld_amount_spinboxes[0].value = value
|
||||
|
||||
|
||||
func _on_ForColorOptions_item_selected(ID : int, right : bool) -> void:
|
||||
|
|
|
@ -16,14 +16,14 @@ func _ready() -> void:
|
|||
func _on_PatternButton_pressed() -> void:
|
||||
if Global.pattern_window_position == "left":
|
||||
Global.pattern_left_image = image
|
||||
Global.left_fill_pattern_container.get_child(0).get_child(0).texture = texture
|
||||
Global.left_fill_pattern_container.get_child(2).get_child(1).max_value = image_size.x - 1
|
||||
Global.left_fill_pattern_container.get_child(3).get_child(1).max_value = image_size.y - 1
|
||||
Global.fill_pattern_containers[0].get_child(0).get_child(0).texture = texture
|
||||
Global.fill_pattern_containers[0].get_child(2).get_child(1).max_value = image_size.x - 1
|
||||
Global.fill_pattern_containers[0].get_child(3).get_child(1).max_value = image_size.y - 1
|
||||
|
||||
elif Global.pattern_window_position == "right":
|
||||
Global.pattern_right_image = image
|
||||
Global.right_fill_pattern_container.get_child(0).get_child(0).texture = texture
|
||||
Global.right_fill_pattern_container.get_child(2).get_child(1).max_value = image_size.x - 1
|
||||
Global.right_fill_pattern_container.get_child(3).get_child(1).max_value = image_size.y - 1
|
||||
Global.fill_pattern_containers[1].get_child(0).get_child(0).texture = texture
|
||||
Global.fill_pattern_containers[1].get_child(2).get_child(1).max_value = image_size.x - 1
|
||||
Global.fill_pattern_containers[1].get_child(3).get_child(1).max_value = image_size.y - 1
|
||||
|
||||
Global.patterns_popup.hide()
|
||||
|
|
|
@ -36,78 +36,51 @@ func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_le
|
|||
var current_tool : int = Global.Tools.keys().find(current_action.to_upper())
|
||||
var left_tool_name := str(Global.Tools.keys()[Global.current_left_tool]).to_lower()
|
||||
var right_tool_name := str(Global.Tools.keys()[Global.current_right_tool]).to_lower()
|
||||
var current_mouse_button := -1
|
||||
|
||||
if (mouse_press and Input.is_action_just_released("left_mouse")) or (!mouse_press and key_for_left):
|
||||
Global.current_left_tool = current_tool
|
||||
left_tool_name = current_action.to_lower()
|
||||
|
||||
# Start from 1, so the label won't get invisible
|
||||
for i in range(1, Global.left_tool_options_container.get_child_count()):
|
||||
Global.left_tool_options_container.get_child(i).visible = false
|
||||
|
||||
Global.left_tool_options_container.get_node("EmptySpacer").visible = true
|
||||
|
||||
# Tool options visible depending on the selected tool
|
||||
if current_tool == Global.Tools.PENCIL:
|
||||
Global.left_brush_type_container.visible = true
|
||||
Global.left_brush_size_slider.visible = true
|
||||
Global.left_pixel_perfect_container.visible = true
|
||||
Global.left_mirror_container.visible = true
|
||||
if Global.current_left_brush_type == Global.Brush_Types.FILE or Global.current_left_brush_type == Global.Brush_Types.CUSTOM or Global.current_left_brush_type == Global.Brush_Types.RANDOM_FILE:
|
||||
Global.left_color_interpolation_container.visible = true
|
||||
elif current_tool == Global.Tools.ERASER:
|
||||
Global.left_brush_type_container.visible = true
|
||||
Global.left_brush_size_slider.visible = true
|
||||
Global.left_pixel_perfect_container.visible = true
|
||||
Global.left_mirror_container.visible = true
|
||||
elif current_tool == Global.Tools.BUCKET:
|
||||
Global.left_fill_area_container.visible = true
|
||||
Global.left_mirror_container.visible = true
|
||||
elif current_tool == Global.Tools.LIGHTENDARKEN:
|
||||
Global.left_brush_type_container.visible = true
|
||||
Global.left_brush_size_slider.visible = true
|
||||
Global.left_pixel_perfect_container.visible = true
|
||||
Global.left_ld_container.visible = true
|
||||
Global.left_mirror_container.visible = true
|
||||
elif current_tool == Global.Tools.COLORPICKER:
|
||||
Global.left_colorpicker_container.visible = true
|
||||
elif current_tool == Global.Tools.ZOOM:
|
||||
Global.left_zoom_container.visible = true
|
||||
current_mouse_button = Global.Mouse_Button.LEFT
|
||||
|
||||
elif (mouse_press and Input.is_action_just_released("right_mouse")) or (!mouse_press and !key_for_left):
|
||||
Global.current_right_tool = current_tool
|
||||
right_tool_name = current_action.to_lower()
|
||||
# Start from 1, so the label won't get invisible
|
||||
for i in range(1, Global.right_tool_options_container.get_child_count()):
|
||||
Global.right_tool_options_container.get_child(i).visible = false
|
||||
current_mouse_button = Global.Mouse_Button.RIGHT
|
||||
|
||||
Global.right_tool_options_container.get_node("EmptySpacer").visible = true
|
||||
if current_mouse_button != -1:
|
||||
# Start from 1, so the label won't get invisible
|
||||
for i in range(1, Global.tool_options_containers[current_mouse_button].get_child_count()):
|
||||
Global.tool_options_containers[current_mouse_button].get_child(i).visible = false
|
||||
|
||||
Global.tool_options_containers[current_mouse_button].get_node("EmptySpacer").visible = true
|
||||
|
||||
# Tool options visible depending on the selected tool
|
||||
if current_tool == Global.Tools.PENCIL:
|
||||
Global.right_brush_type_container.visible = true
|
||||
Global.right_brush_size_slider.visible = true
|
||||
Global.right_pixel_perfect_container.visible = true
|
||||
Global.right_mirror_container.visible = true
|
||||
if Global.current_right_brush_type == Global.Brush_Types.FILE or Global.current_right_brush_type == Global.Brush_Types.CUSTOM or Global.current_right_brush_type == Global.Brush_Types.RANDOM_FILE:
|
||||
Global.right_color_interpolation_container.visible = true
|
||||
Global.brush_type_containers[current_mouse_button].visible = true
|
||||
Global.brush_size_sliders[current_mouse_button].visible = true
|
||||
Global.pixel_perfect_containers[current_mouse_button].visible = true
|
||||
Global.mirror_containers[current_mouse_button].visible = true
|
||||
if Global.current_brush_type[current_mouse_button] == Global.Brush_Types.FILE or Global.current_brush_type[current_mouse_button] == Global.Brush_Types.CUSTOM or Global.current_brush_type[current_mouse_button] == Global.Brush_Types.RANDOM_FILE:
|
||||
Global.color_interpolation_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.ERASER:
|
||||
Global.right_brush_type_container.visible = true
|
||||
Global.right_brush_size_slider.visible = true
|
||||
Global.right_pixel_perfect_container.visible = true
|
||||
Global.right_mirror_container.visible = true
|
||||
Global.brush_type_containers[current_mouse_button].visible = true
|
||||
Global.brush_size_sliders[current_mouse_button].visible = true
|
||||
Global.pixel_perfect_containers[current_mouse_button].visible = true
|
||||
Global.mirror_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.BUCKET:
|
||||
Global.right_fill_area_container.visible = true
|
||||
Global.right_mirror_container.visible = true
|
||||
Global.fill_area_containers[current_mouse_button].visible = true
|
||||
Global.mirror_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.LIGHTENDARKEN:
|
||||
Global.right_brush_type_container.visible = true
|
||||
Global.right_brush_size_slider.visible = true
|
||||
Global.right_pixel_perfect_container.visible = true
|
||||
Global.right_ld_container.visible = true
|
||||
Global.right_mirror_container.visible = true
|
||||
Global.brush_type_containers[current_mouse_button].visible = true
|
||||
Global.brush_size_sliders[current_mouse_button].visible = true
|
||||
Global.pixel_perfect_containers[current_mouse_button].visible = true
|
||||
Global.ld_containers[current_mouse_button].visible = true
|
||||
Global.mirror_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.COLORPICKER:
|
||||
Global.right_colorpicker_container.visible = true
|
||||
Global.colorpicker_containers[current_mouse_button].visible = true
|
||||
elif current_tool == Global.Tools.ZOOM:
|
||||
Global.right_zoom_container.visible = true
|
||||
Global.zoom_containers[current_mouse_button].visible = true
|
||||
|
||||
for t in tools:
|
||||
var tool_name : String = t[0].name.to_lower()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue