mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 21:44:42 -04:00
Project brushes change when switching projects
A new Global.file_brushes array is used for the file brushes, and the Project class has its own brushes array for the project brushes
This commit is contained in:
parent
736521246d
commit
4af130bc61
7 changed files with 67 additions and 63 deletions
|
@ -86,7 +86,7 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
var brush_index : int = Global.custom_brush_indexes[current_mouse_button]
|
||||
var custom_brush_image : Image
|
||||
if brush_type != Global.Brush_Types.RANDOM_FILE:
|
||||
custom_brush_image = Global.current_project.brush_images[current_mouse_button]
|
||||
custom_brush_image = Global.brush_images[current_mouse_button]
|
||||
else: # Handle random brush
|
||||
var brush_button = Global.file_brush_container.get_child(brush_index + 3)
|
||||
var random_index = randi() % brush_button.random_brushes.size()
|
||||
|
@ -145,7 +145,10 @@ func draw_brush(sprite : Image, pos : Vector2, color : Color, current_mouse_butt
|
|||
|
||||
else: # if it's transparent - if it's the eraser
|
||||
var custom_brush := Image.new()
|
||||
custom_brush.copy_from(Global.current_project.brushes[brush_index])
|
||||
if brush_type == Global.Brush_Types.CUSTOM:
|
||||
custom_brush.copy_from(Global.current_project.brushes[brush_index])
|
||||
else:
|
||||
custom_brush.copy_from(Global.file_brushes[brush_index])
|
||||
custom_brush_size = custom_brush.get_size()
|
||||
custom_brush.resize(custom_brush_size.x * brush_size, custom_brush_size.y * brush_size, Image.INTERPOLATE_NEAREST)
|
||||
var custom_brush_blended = Global.blend_image_with_color(custom_brush, color, 1)
|
||||
|
|
|
@ -103,8 +103,11 @@ var onion_skinning_future_rate := 1.0
|
|||
var onion_skinning_blue_red := false
|
||||
|
||||
# Brushes
|
||||
var file_brushes := []
|
||||
var brush_sizes := [1, 1]
|
||||
var current_brush_types := [Brush_Types.PIXEL, Brush_Types.PIXEL]
|
||||
var brush_images := [Image.new(), Image.new()]
|
||||
var brush_textures := [ImageTexture.new(), ImageTexture.new()]
|
||||
|
||||
var brush_type_window_position : int = Mouse_Button.LEFT
|
||||
var left_circle_points := []
|
||||
|
@ -596,10 +599,11 @@ func create_brush_button(brush_img : Image, brush_type := Brush_Types.CUSTOM, hi
|
|||
var brush_container
|
||||
var brush_button = load("res://src/UI/BrushButton.tscn").instance()
|
||||
brush_button.brush_type = brush_type
|
||||
brush_button.custom_brush_index = current_project.brushes.size() - 1
|
||||
if brush_type == Brush_Types.FILE || brush_type == Brush_Types.RANDOM_FILE:
|
||||
brush_button.custom_brush_index = file_brushes.size() - 1
|
||||
brush_container = file_brush_container
|
||||
else:
|
||||
brush_button.custom_brush_index = current_project.brushes.size() - 1
|
||||
brush_container = project_brush_container
|
||||
var brush_tex := ImageTexture.new()
|
||||
brush_tex.create_from_image(brush_img, 0)
|
||||
|
@ -623,7 +627,7 @@ func undo_custom_brush(_brush_button : BaseButton = null) -> void:
|
|||
var action_name : String = current_project.undo_redo.get_current_action_name()
|
||||
if action_name == "Delete Custom Brush":
|
||||
project_brush_container.add_child(_brush_button)
|
||||
project_brush_container.move_child(_brush_button, _brush_button.custom_brush_index - brushes_from_files)
|
||||
project_brush_container.move_child(_brush_button, _brush_button.custom_brush_index)
|
||||
_brush_button.get_node("DeleteButton").visible = false
|
||||
|
||||
|
||||
|
@ -635,17 +639,18 @@ func redo_custom_brush(_brush_button : BaseButton = null) -> void:
|
|||
|
||||
|
||||
func update_custom_brush(mouse_button : int) -> void:
|
||||
if current_brush_types[mouse_button] == Brush_Types.PIXEL:
|
||||
var brush_type : int = current_brush_types[mouse_button]
|
||||
if brush_type == Brush_Types.PIXEL:
|
||||
var pixel := Image.new()
|
||||
pixel = preload("res://assets/graphics/pixel_image.png")
|
||||
brush_type_buttons[mouse_button].get_child(0).texture.create_from_image(pixel, 0)
|
||||
elif current_brush_types[mouse_button] == Brush_Types.CIRCLE:
|
||||
elif brush_type == Brush_Types.CIRCLE:
|
||||
var pixel := Image.new()
|
||||
pixel = preload("res://assets/graphics/circle_9x9.png")
|
||||
brush_type_buttons[mouse_button].get_child(0).texture.create_from_image(pixel, 0)
|
||||
left_circle_points = plot_circle(brush_sizes[0])
|
||||
right_circle_points = plot_circle(brush_sizes[1])
|
||||
elif current_brush_types[mouse_button] == Brush_Types.FILLED_CIRCLE:
|
||||
elif brush_type == Brush_Types.FILLED_CIRCLE:
|
||||
var pixel := Image.new()
|
||||
pixel = preload("res://assets/graphics/circle_filled_9x9.png")
|
||||
brush_type_buttons[mouse_button].get_child(0).texture.create_from_image(pixel, 0)
|
||||
|
@ -653,13 +658,16 @@ func update_custom_brush(mouse_button : int) -> void:
|
|||
right_circle_points = plot_circle(brush_sizes[1])
|
||||
else:
|
||||
var custom_brush := Image.new()
|
||||
custom_brush.copy_from(current_project.brushes[custom_brush_indexes[mouse_button]])
|
||||
if brush_type == Brush_Types.FILE or brush_type == Brush_Types.RANDOM_FILE:
|
||||
custom_brush.copy_from(file_brushes[custom_brush_indexes[mouse_button]])
|
||||
else:
|
||||
custom_brush.copy_from(current_project.brushes[custom_brush_indexes[mouse_button]])
|
||||
var custom_brush_size = custom_brush.get_size()
|
||||
custom_brush.resize(custom_brush_size.x * brush_sizes[mouse_button], custom_brush_size.y * brush_sizes[mouse_button], Image.INTERPOLATE_NEAREST)
|
||||
current_project.brush_images[mouse_button] = blend_image_with_color(custom_brush, color_pickers[mouse_button].color, interpolate_spinboxes[mouse_button].value / 100)
|
||||
current_project.brush_textures[mouse_button].create_from_image(current_project.brush_images[mouse_button], 0)
|
||||
brush_images[mouse_button] = blend_image_with_color(custom_brush, color_pickers[mouse_button].color, interpolate_spinboxes[mouse_button].value / 100)
|
||||
brush_textures[mouse_button].create_from_image(brush_images[mouse_button], 0)
|
||||
|
||||
brush_type_buttons[mouse_button].get_child(0).texture = current_project.brush_textures[mouse_button]
|
||||
brush_type_buttons[mouse_button].get_child(0).texture = brush_textures[mouse_button]
|
||||
|
||||
|
||||
func blend_image_with_color(image : Image, color : Color, interpolate_factor : float) -> Image:
|
||||
|
|
|
@ -111,7 +111,7 @@ func add_randomised_brush(fpaths : Array, tooltip_name : String) -> void:
|
|||
# The index which this random brush will be at
|
||||
var next_random_brush_index := Global.file_brush_container.get_child_count()
|
||||
|
||||
Global.current_project.brushes.append(first_image)
|
||||
Global.file_brushes.append(first_image)
|
||||
Global.create_brush_button(first_image, Global.Brush_Types.RANDOM_FILE, tooltip_name)
|
||||
# # Process the rest
|
||||
for remaining_image in loaded_images:
|
||||
|
@ -127,7 +127,7 @@ func add_plain_brush(path: String, tooltip_name: String) -> void:
|
|||
return
|
||||
# do the standard conversion thing...
|
||||
image.convert(Image.FORMAT_RGBA8)
|
||||
Global.current_project.brushes.append(image)
|
||||
Global.file_brushes.append(image)
|
||||
Global.create_brush_button(image, Global.Brush_Types.FILE, tooltip_name)
|
||||
|
||||
|
||||
|
@ -214,7 +214,7 @@ func import_brushes(priority_ordered_search_path: Array) -> void:
|
|||
# Mark this as a processed relpath
|
||||
processed_subdir_paths[nonrandomised_subdir][relative_path] = true
|
||||
|
||||
Global.brushes_from_files = Global.current_project.brushes.size()
|
||||
Global.brushes_from_files = Global.file_brushes.size()
|
||||
|
||||
|
||||
func import_patterns(priority_ordered_search_path: Array) -> void:
|
||||
|
|
|
@ -155,7 +155,6 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
Global.color_pickers[1].get_picker().add_preset(color)
|
||||
|
||||
# Load custom brushes
|
||||
Global.current_project.brushes.resize(Global.brushes_from_files)
|
||||
Global.remove_brush_buttons()
|
||||
|
||||
var brush_line := file.get_line()
|
||||
|
@ -248,7 +247,7 @@ func save_pxo_file(path : String, autosave : bool) -> void:
|
|||
file.store_8(right_brush_size)
|
||||
|
||||
# Save custom brushes
|
||||
for i in range(Global.brushes_from_files, Global.current_project.brushes.size()):
|
||||
for i in range(Global.current_project.brushes.size()):
|
||||
var brush = Global.current_project.brushes[i]
|
||||
file.store_line("/")
|
||||
file.store_16(brush.get_size().x)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue