mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-20 12:33:14 +00:00
Created a Projects class
A Project class contains project-specific data like name, undo_redo, frames, layers, tags and brushes. These variables have been moved from Global. This is the first step towards multiple tab support, where each tab will be a different Project.
This commit is contained in:
parent
9d38cbd13e
commit
4e111a7ac0
21 changed files with 656 additions and 627 deletions
|
@ -58,6 +58,11 @@ _global_script_classes=[ {
|
|||
"class": "PaletteColor",
|
||||
"language": "GDScript",
|
||||
"path": "res://src/Palette/PaletteColor.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "Project",
|
||||
"language": "GDScript",
|
||||
"path": "res://src/Classes/Project.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"AnimationTag": "",
|
||||
|
@ -69,7 +74,8 @@ _global_script_class_icons={
|
|||
"Layer": "",
|
||||
"LayerButton": "",
|
||||
"Palette": "",
|
||||
"PaletteColor": ""
|
||||
"PaletteColor": "",
|
||||
"Project": ""
|
||||
}
|
||||
|
||||
[application]
|
||||
|
|
|
@ -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.custom_brush_images[current_mouse_button]
|
||||
custom_brush_image = Global.current_project.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,7 @@ 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.custom_brushes[brush_index])
|
||||
custom_brush.copy_from(Global.current_project.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)
|
||||
|
|
|
@ -24,22 +24,18 @@ var config_cache := ConfigFile.new()
|
|||
var XDGDataPaths = preload("res://src/XDGDataPaths.gd")
|
||||
var directory_module : Reference
|
||||
|
||||
var projects := [] # Array of Projects
|
||||
var current_project : Project
|
||||
var current_project_index := 0 setget project_changed
|
||||
|
||||
# Indices are as in the Direction enum
|
||||
# This is the total time the key for
|
||||
# that direction has been pressed.
|
||||
var key_move_press_time := [0.0, 0.0, 0.0, 0.0]
|
||||
|
||||
var loaded_locales : Array
|
||||
var undo_redo : UndoRedo
|
||||
var undos := 0 # The number of times we added undo properties
|
||||
var project_has_changed := false # Checks if the user has made changes to the project
|
||||
|
||||
# Canvas related stuff
|
||||
var frames := [] setget frames_changed
|
||||
var layers := [] setget layers_changed
|
||||
var layers_changed_skip := false
|
||||
var current_frame := 0 setget frame_changed
|
||||
var current_layer := 0 setget layer_changed
|
||||
|
||||
var can_draw := false
|
||||
|
||||
|
@ -51,9 +47,7 @@ var cursor_image = preload("res://assets/graphics/cursor_icons/cursor.png")
|
|||
var left_cursor_tool_texture : ImageTexture
|
||||
var right_cursor_tool_texture : ImageTexture
|
||||
|
||||
var selected_pixels := []
|
||||
var image_clipboard : Image
|
||||
var animation_tags := [] setget animation_tags_changed
|
||||
var play_only_tags := true
|
||||
|
||||
var theme_type : int = Theme_Types.DARK
|
||||
|
@ -116,10 +110,7 @@ var left_circle_points := []
|
|||
var right_circle_points := []
|
||||
|
||||
var brushes_from_files := 0
|
||||
var custom_brushes := []
|
||||
var custom_brush_indexes := [-1, -1]
|
||||
var custom_brush_images := [Image.new(), Image.new()]
|
||||
var custom_brush_textures := [ImageTexture.new(), ImageTexture.new()]
|
||||
|
||||
# Patterns
|
||||
var patterns := []
|
||||
|
@ -238,8 +229,8 @@ func _ready() -> void:
|
|||
# The fact that root_dir is set earlier than this is important
|
||||
# XDGDataDirs depends on it nyaa
|
||||
directory_module = XDGDataPaths.new()
|
||||
|
||||
undo_redo = UndoRedo.new()
|
||||
projects.append(Project.new())
|
||||
current_project = projects[0]
|
||||
image_clipboard = Image.new()
|
||||
|
||||
var root = get_tree().get_root()
|
||||
|
@ -361,8 +352,6 @@ func _ready() -> void:
|
|||
|
||||
error_dialog = find_node_by_name(root, "ErrorDialog")
|
||||
|
||||
layers.append(Layer.new())
|
||||
|
||||
|
||||
# Thanks to https://godotengine.org/qa/17524/how-to-find-an-instanced-scene-by-its-name
|
||||
func find_node_by_name(root : Node, node_name : String) -> Node:
|
||||
|
@ -386,28 +375,28 @@ func notification_label(text : String) -> void:
|
|||
|
||||
|
||||
func general_undo() -> void:
|
||||
undos -= 1
|
||||
var action_name := undo_redo.get_current_action_name()
|
||||
current_project.undos -= 1
|
||||
var action_name : String = current_project.undo_redo.get_current_action_name()
|
||||
notification_label("Undo: %s" % action_name)
|
||||
|
||||
|
||||
func general_redo() -> void:
|
||||
if undos < undo_redo.get_version(): # If we did undo and then redo
|
||||
undos = undo_redo.get_version()
|
||||
if current_project.undos < current_project.undo_redo.get_version(): # If we did undo and then redo
|
||||
current_project.undos = current_project.undo_redo.get_version()
|
||||
if control.redone:
|
||||
var action_name := undo_redo.get_current_action_name()
|
||||
var action_name : String = current_project.undo_redo.get_current_action_name()
|
||||
notification_label("Redo: %s" % action_name)
|
||||
|
||||
|
||||
func undo(_frame_index := -1, _layer_index := -1) -> void:
|
||||
general_undo()
|
||||
var action_name := undo_redo.get_current_action_name()
|
||||
var action_name : String = current_project.undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Link Cel" or action_name == "Unlink Cel":
|
||||
if _layer_index > -1 and _frame_index > -1:
|
||||
canvas.update_texture(_layer_index, _frame_index)
|
||||
else:
|
||||
for i in frames.size():
|
||||
for j in layers.size():
|
||||
for i in current_project.frames.size():
|
||||
for j in current_project.layers.size():
|
||||
canvas.update_texture(j, i)
|
||||
|
||||
if action_name == "Scale":
|
||||
|
@ -415,40 +404,40 @@ func undo(_frame_index := -1, _layer_index := -1) -> void:
|
|||
|
||||
elif "Frame" in action_name:
|
||||
# This actually means that frames.size is one, but it hasn't been updated yet
|
||||
if frames.size() == 2: # Stop animating
|
||||
if current_project.frames.size() == 2: # Stop animating
|
||||
play_forward.pressed = false
|
||||
play_backwards.pressed = false
|
||||
animation_timer.stop()
|
||||
|
||||
canvas.update()
|
||||
if !project_has_changed:
|
||||
project_has_changed = true
|
||||
if !current_project.has_changed:
|
||||
current_project.has_changed = true
|
||||
self.window_title = window_title + "(*)"
|
||||
|
||||
|
||||
func redo(_frame_index := -1, _layer_index := -1) -> void:
|
||||
general_redo()
|
||||
var action_name := undo_redo.get_current_action_name()
|
||||
var action_name : String = current_project.undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Link Cel" or action_name == "Unlink Cel":
|
||||
if _layer_index > -1 and _frame_index > -1:
|
||||
canvas.update_texture(_layer_index, _frame_index)
|
||||
else:
|
||||
for i in frames.size():
|
||||
for j in layers.size():
|
||||
for i in current_project.frames.size():
|
||||
for j in current_project.layers.size():
|
||||
canvas.update_texture(j, i)
|
||||
|
||||
if action_name == "Scale":
|
||||
canvas.camera_zoom()
|
||||
|
||||
elif "Frame" in action_name:
|
||||
if frames.size() == 1: # Stop animating
|
||||
if current_project.frames.size() == 1: # Stop animating
|
||||
play_forward.pressed = false
|
||||
play_backwards.pressed = false
|
||||
animation_timer.stop()
|
||||
|
||||
canvas.update()
|
||||
if !project_has_changed:
|
||||
project_has_changed = true
|
||||
if !current_project.has_changed:
|
||||
current_project.has_changed = true
|
||||
self.window_title = window_title + "(*)"
|
||||
|
||||
|
||||
|
@ -457,52 +446,15 @@ func title_changed(value : String) -> void:
|
|||
OS.set_window_title(value)
|
||||
|
||||
|
||||
func frames_changed(value : Array) -> void:
|
||||
frames = value
|
||||
for container in frames_container.get_children():
|
||||
for button in container.get_children():
|
||||
container.remove_child(button)
|
||||
button.queue_free()
|
||||
frames_container.remove_child(container)
|
||||
|
||||
for frame_id in frame_ids.get_children():
|
||||
frame_ids.remove_child(frame_id)
|
||||
frame_id.queue_free()
|
||||
|
||||
for i in range(layers.size() - 1, -1, -1):
|
||||
frames_container.add_child(layers[i].frame_container)
|
||||
|
||||
for j in range(frames.size()):
|
||||
var label := Label.new()
|
||||
label.rect_min_size.x = 36
|
||||
label.align = Label.ALIGN_CENTER
|
||||
label.text = str(j + 1)
|
||||
frame_ids.add_child(label)
|
||||
|
||||
for i in range(layers.size() - 1, -1, -1):
|
||||
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance()
|
||||
cel_button.frame = j
|
||||
cel_button.layer = i
|
||||
cel_button.get_child(0).texture = frames[j].cels[i].image_texture
|
||||
|
||||
layers[i].frame_container.add_child(cel_button)
|
||||
|
||||
# This is useful in case tagged frames get deleted DURING the animation is playing
|
||||
# otherwise, this code is useless in this context, since these values are being set
|
||||
# when the play buttons get pressed, anyway
|
||||
animation_timeline.first_frame = 0
|
||||
animation_timeline.last_frame = frames.size() - 1
|
||||
if play_only_tags:
|
||||
for tag in animation_tags:
|
||||
if current_frame + 1 >= tag.from && current_frame + 1 <= tag.to:
|
||||
animation_timeline.first_frame = tag.from - 1
|
||||
animation_timeline.last_frame = min(frames.size() - 1, tag.to - 1)
|
||||
func project_changed(value : int) -> void:
|
||||
current_project_index = value
|
||||
current_project = projects[value]
|
||||
|
||||
|
||||
func clear_frames() -> void:
|
||||
frames.clear()
|
||||
animation_tags.clear()
|
||||
self.animation_tags = animation_tags # To execute animation_tags_changed()
|
||||
current_project.frames.clear()
|
||||
current_project.animation_tags.clear()
|
||||
current_project.animation_tags = current_project.animation_tags # To execute animation_tags_changed()
|
||||
|
||||
# Stop playing the animation
|
||||
play_backwards.pressed = false
|
||||
|
@ -514,120 +466,7 @@ func clear_frames() -> void:
|
|||
control.get_node("ExportDialog").was_exported = false
|
||||
control.file_menu.set_item_text(3, tr("Save..."))
|
||||
control.file_menu.set_item_text(6, tr("Export..."))
|
||||
undo_redo.clear_history(false)
|
||||
|
||||
|
||||
func layers_changed(value : Array) -> void:
|
||||
layers = value
|
||||
if layers_changed_skip:
|
||||
layers_changed_skip = false
|
||||
return
|
||||
|
||||
for container in layers_container.get_children():
|
||||
container.queue_free()
|
||||
|
||||
for container in frames_container.get_children():
|
||||
for button in container.get_children():
|
||||
container.remove_child(button)
|
||||
button.queue_free()
|
||||
frames_container.remove_child(container)
|
||||
|
||||
for i in range(layers.size() - 1, -1, -1):
|
||||
var layer_container = load("res://src/UI/Timeline/LayerButton.tscn").instance()
|
||||
layer_container.i = i
|
||||
if layers[i].name == tr("Layer") + " 0":
|
||||
layers[i].name = tr("Layer") + " %s" % i
|
||||
|
||||
layers_container.add_child(layer_container)
|
||||
layer_container.label.text = layers[i].name
|
||||
layer_container.line_edit.text = layers[i].name
|
||||
|
||||
frames_container.add_child(layers[i].frame_container)
|
||||
for j in range(frames.size()):
|
||||
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance()
|
||||
cel_button.frame = j
|
||||
cel_button.layer = i
|
||||
cel_button.get_child(0).texture = frames[j].cels[i].image_texture
|
||||
|
||||
layers[i].frame_container.add_child(cel_button)
|
||||
|
||||
var layer_button = layers_container.get_child(layers_container.get_child_count() - 1 - current_layer)
|
||||
layer_button.pressed = true
|
||||
self.current_frame = current_frame # Call frame_changed to update UI
|
||||
|
||||
if layers[current_layer].locked:
|
||||
disable_button(remove_layer_button, true)
|
||||
|
||||
if layers.size() == 1:
|
||||
disable_button(remove_layer_button, true)
|
||||
disable_button(move_up_layer_button, true)
|
||||
disable_button(move_down_layer_button, true)
|
||||
disable_button(merge_down_layer_button, true)
|
||||
elif !layers[current_layer].locked:
|
||||
disable_button(remove_layer_button, false)
|
||||
|
||||
|
||||
func frame_changed(value : int) -> void:
|
||||
current_frame = value
|
||||
current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
|
||||
|
||||
for i in frames.size(): # De-select all the other frames
|
||||
var text_color := Color.white
|
||||
if theme_type == Theme_Types.CARAMEL || theme_type == Theme_Types.LIGHT:
|
||||
text_color = Color.black
|
||||
frame_ids.get_child(i).add_color_override("font_color", text_color)
|
||||
for layer in layers:
|
||||
if i < layer.frame_container.get_child_count():
|
||||
layer.frame_container.get_child(i).pressed = false
|
||||
|
||||
# Select the new frame
|
||||
frame_ids.get_child(current_frame).add_color_override("font_color", control.theme.get_color("Selected Color", "Label"))
|
||||
if current_frame < layers[current_layer].frame_container.get_child_count():
|
||||
layers[current_layer].frame_container.get_child(current_frame).pressed = true
|
||||
|
||||
if frames.size() == 1:
|
||||
disable_button(remove_frame_button, true)
|
||||
elif !layers[current_layer].locked:
|
||||
disable_button(remove_frame_button, false)
|
||||
|
||||
Global.canvas.update()
|
||||
Global.transparent_checker._ready() # To update the rect size
|
||||
|
||||
|
||||
func layer_changed(value : int) -> void:
|
||||
current_layer = value
|
||||
if current_frame < frames.size():
|
||||
layer_opacity_slider.value = frames[current_frame].cels[current_layer].opacity * 100
|
||||
layer_opacity_spinbox.value = frames[current_frame].cels[current_layer].opacity * 100
|
||||
|
||||
for container in layers_container.get_children():
|
||||
container.pressed = false
|
||||
|
||||
if current_layer < layers_container.get_child_count():
|
||||
var layer_button = layers_container.get_child(layers_container.get_child_count() - 1 - current_layer)
|
||||
layer_button.pressed = true
|
||||
|
||||
if current_layer < layers.size() - 1:
|
||||
disable_button(move_up_layer_button, false)
|
||||
else:
|
||||
disable_button(move_up_layer_button, true)
|
||||
|
||||
if current_layer > 0:
|
||||
disable_button(move_down_layer_button, false)
|
||||
disable_button(merge_down_layer_button, false)
|
||||
else:
|
||||
disable_button(move_down_layer_button, true)
|
||||
disable_button(merge_down_layer_button, true)
|
||||
|
||||
if current_layer < layers.size():
|
||||
if layers[current_layer].locked:
|
||||
disable_button(remove_layer_button, true)
|
||||
else:
|
||||
if layers.size() > 1:
|
||||
disable_button(remove_layer_button, false)
|
||||
|
||||
yield(get_tree().create_timer(0.01), "timeout")
|
||||
self.current_frame = current_frame # Call frame_changed to update UI
|
||||
current_project.undo_redo.clear_history(false)
|
||||
|
||||
|
||||
func dialog_open(open : bool) -> void:
|
||||
|
@ -668,39 +507,6 @@ func change_button_texturerect(texture_button : TextureRect, new_file_name : Str
|
|||
texture_button.texture = load(directory_path.plus_file(new_file_name))
|
||||
|
||||
|
||||
func animation_tags_changed(value : Array) -> void:
|
||||
animation_tags = value
|
||||
for child in tag_container.get_children():
|
||||
child.queue_free()
|
||||
|
||||
for tag in animation_tags:
|
||||
var tag_c : Container = load("res://src/UI/Timeline/AnimationTag.tscn").instance()
|
||||
tag_container.add_child(tag_c)
|
||||
var tag_position := tag_container.get_child_count() - 1
|
||||
tag_container.move_child(tag_c, tag_position)
|
||||
tag_c.get_node("Label").text = tag.name
|
||||
tag_c.get_node("Label").modulate = tag.color
|
||||
tag_c.get_node("Line2D").default_color = tag.color
|
||||
|
||||
tag_c.rect_position.x = (tag.from - 1) * 39 + tag.from
|
||||
|
||||
var size : int = tag.to - tag.from
|
||||
tag_c.rect_min_size.x = (size + 1) * 39
|
||||
tag_c.get_node("Line2D").points[2] = Vector2(tag_c.rect_min_size.x, 0)
|
||||
tag_c.get_node("Line2D").points[3] = Vector2(tag_c.rect_min_size.x, 32)
|
||||
|
||||
# This is useful in case tags get modified DURING the animation is playing
|
||||
# otherwise, this code is useless in this context, since these values are being set
|
||||
# when the play buttons get pressed, anyway
|
||||
animation_timeline.first_frame = 0
|
||||
animation_timeline.last_frame = frames.size() - 1
|
||||
if play_only_tags:
|
||||
for tag in animation_tags:
|
||||
if current_frame + 1 >= tag.from && current_frame + 1 <= tag.to:
|
||||
animation_timeline.first_frame = tag.from - 1
|
||||
animation_timeline.last_frame = min(frames.size() - 1, tag.to - 1)
|
||||
|
||||
|
||||
func update_hint_tooltips() -> void:
|
||||
var root = get_tree().get_root()
|
||||
|
||||
|
@ -785,7 +591,7 @@ 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 = custom_brushes.size() - 1
|
||||
brush_button.custom_brush_index = current_project.brushes.size() - 1
|
||||
if brush_type == Brush_Types.FILE || brush_type == Brush_Types.RANDOM_FILE:
|
||||
brush_container = file_brush_container
|
||||
else:
|
||||
|
@ -809,7 +615,7 @@ func remove_brush_buttons() -> void:
|
|||
|
||||
func undo_custom_brush(_brush_button : BaseButton = null) -> void:
|
||||
general_undo()
|
||||
var action_name := undo_redo.get_current_action_name()
|
||||
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)
|
||||
|
@ -818,7 +624,7 @@ func undo_custom_brush(_brush_button : BaseButton = null) -> void:
|
|||
|
||||
func redo_custom_brush(_brush_button : BaseButton = null) -> void:
|
||||
general_redo()
|
||||
var action_name := undo_redo.get_current_action_name()
|
||||
var action_name : String = current_project.undo_redo.get_current_action_name()
|
||||
if action_name == "Delete Custom Brush":
|
||||
project_brush_container.remove_child(_brush_button)
|
||||
|
||||
|
@ -842,13 +648,13 @@ 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(custom_brushes[custom_brush_indexes[mouse_button]])
|
||||
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)
|
||||
custom_brush_images[mouse_button] = blend_image_with_color(custom_brush, color_pickers[mouse_button].color, interpolate_spinboxes[mouse_button].value / 100)
|
||||
custom_brush_textures[mouse_button].create_from_image(custom_brush_images[mouse_button], 0)
|
||||
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_type_buttons[mouse_button].get_child(0).texture = custom_brush_textures[mouse_button]
|
||||
brush_type_buttons[mouse_button].get_child(0).texture = current_project.brush_textures[mouse_button]
|
||||
|
||||
|
||||
func blend_image_with_color(image : Image, color : Color, interpolate_factor : float) -> Image:
|
||||
|
@ -902,4 +708,5 @@ func _exit_tree() -> void:
|
|||
config_cache.save("user://cache.ini")
|
||||
|
||||
# Thanks to qarmin from GitHub for pointing this out
|
||||
undo_redo.free()
|
||||
for project in projects:
|
||||
project.undo_redo.free()
|
||||
|
|
|
@ -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.custom_brushes.append(first_image)
|
||||
Global.current_project.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.custom_brushes.append(image)
|
||||
Global.current_project.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.custom_brushes.size()
|
||||
Global.brushes_from_files = Global.current_project.brushes.size()
|
||||
|
||||
|
||||
func import_patterns(priority_ordered_search_path: Array) -> void:
|
||||
|
|
|
@ -53,7 +53,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
new_guides = false
|
||||
|
||||
var frame := 0
|
||||
Global.layers.clear()
|
||||
Global.current_project.layers.clear()
|
||||
|
||||
var linked_cels := []
|
||||
if file_major_version >= 0 and file_minor_version > 6:
|
||||
|
@ -66,7 +66,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
linked_cels.append(file.get_var())
|
||||
|
||||
var l := Layer.new(layer_name, layer_visibility, layer_lock, HBoxContainer.new(), layer_new_cels_linked, [])
|
||||
Global.layers.append(l)
|
||||
Global.current_project.layers.append(l)
|
||||
global_layer_line = file.get_line()
|
||||
|
||||
var frame_line := file.get_line()
|
||||
|
@ -84,7 +84,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
var layer_name_old_version = file.get_line()
|
||||
if frame == 0:
|
||||
var l := Layer.new(layer_name_old_version)
|
||||
Global.layers.append(l)
|
||||
Global.current_project.layers.append(l)
|
||||
var cel_opacity := 1.0
|
||||
if file_major_version >= 0 and file_minor_version > 5:
|
||||
cel_opacity = file.get_float()
|
||||
|
@ -94,7 +94,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
frame_class.cels.append(Cel.new(image, cel_opacity))
|
||||
if file_major_version >= 0 and file_minor_version >= 7:
|
||||
if frame in linked_cels[layer_i]:
|
||||
Global.layers[layer_i].linked_cels.append(frame_class)
|
||||
Global.current_project.layers[layer_i].linked_cels.append(frame_class)
|
||||
|
||||
layer_i += 1
|
||||
layer_line = file.get_line()
|
||||
|
@ -115,14 +115,14 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
guide_line = file.get_line()
|
||||
|
||||
Global.canvas.size = Vector2(width, height)
|
||||
Global.frames.append(frame_class)
|
||||
Global.current_project.frames.append(frame_class)
|
||||
frame_line = file.get_line()
|
||||
frame += 1
|
||||
|
||||
Global.frames = Global.frames # Just to call Global.frames_changed
|
||||
Global.current_layer = Global.layers.size() - 1
|
||||
Global.current_frame = frame - 1
|
||||
Global.layers = Global.layers # Just to call Global.layers_changed
|
||||
Global.current_project.frames = Global.current_project.frames # Just to call Global.frames_changed
|
||||
Global.current_project.current_layer = Global.current_project.layers.size() - 1
|
||||
Global.current_project.current_frame = frame - 1
|
||||
Global.current_project.layers = Global.current_project.layers # Just to call Global.layers_changed
|
||||
|
||||
if new_guides:
|
||||
var guide_line := file.get_line() # "guideline" no pun intended
|
||||
|
@ -155,7 +155,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
Global.color_pickers[1].get_picker().add_preset(color)
|
||||
|
||||
# Load custom brushes
|
||||
Global.custom_brushes.resize(Global.brushes_from_files)
|
||||
Global.current_project.brushes.resize(Global.brushes_from_files)
|
||||
Global.remove_brush_buttons()
|
||||
|
||||
var brush_line := file.get_line()
|
||||
|
@ -165,7 +165,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
var buffer := file.get_buffer(b_width * b_height * 4)
|
||||
var image := Image.new()
|
||||
image.create_from_data(b_width, b_height, false, Image.FORMAT_RGBA8, buffer)
|
||||
Global.custom_brushes.append(image)
|
||||
Global.current_project.brushes.append(image)
|
||||
Global.create_brush_button(image)
|
||||
brush_line = file.get_line()
|
||||
|
||||
|
@ -176,8 +176,8 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
var tag_color : Color = file.get_var()
|
||||
var tag_from := file.get_8()
|
||||
var tag_to := file.get_8()
|
||||
Global.animation_tags.append(AnimationTag.new(tag_name, tag_color, tag_from, tag_to))
|
||||
Global.animation_tags = Global.animation_tags # To execute animation_tags_changed()
|
||||
Global.current_project.animation_tags.append(AnimationTag.new(tag_name, tag_color, tag_from, tag_to))
|
||||
Global.current_project.animation_tags = Global.current_project.animation_tags # To execute animation_tags_changed()
|
||||
tag_line = file.get_line()
|
||||
|
||||
file.close()
|
||||
|
@ -187,7 +187,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
|
|||
# Untitled backup should not change window title and save path
|
||||
current_save_path = path
|
||||
Global.window_title = path.get_file() + " - Pixelorama " + Global.current_version
|
||||
Global.project_has_changed = false
|
||||
Global.current_project.has_changed = false
|
||||
|
||||
|
||||
func save_pxo_file(path : String, autosave : bool) -> void:
|
||||
|
@ -198,7 +198,7 @@ func save_pxo_file(path : String, autosave : bool) -> void:
|
|||
file.store_line(Global.current_version)
|
||||
|
||||
# Store Global layers
|
||||
for layer in Global.layers:
|
||||
for layer in Global.current_project.layers:
|
||||
file.store_line(".")
|
||||
file.store_line(layer.name)
|
||||
file.store_8(layer.visible)
|
||||
|
@ -206,13 +206,13 @@ func save_pxo_file(path : String, autosave : bool) -> void:
|
|||
file.store_8(layer.new_cels_linked)
|
||||
var linked_cels := []
|
||||
for frame in layer.linked_cels:
|
||||
linked_cels.append(Global.frames.find(frame))
|
||||
linked_cels.append(Global.current_project.frames.find(frame))
|
||||
file.store_var(linked_cels) # Linked cels as cel numbers
|
||||
|
||||
file.store_line("END_GLOBAL_LAYERS")
|
||||
|
||||
# Store frames
|
||||
for frame in Global.frames:
|
||||
for frame in Global.current_project.frames:
|
||||
file.store_line("--")
|
||||
file.store_16(Global.canvas.size.x)
|
||||
file.store_16(Global.canvas.size.y)
|
||||
|
@ -248,8 +248,8 @@ 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.custom_brushes.size()):
|
||||
var brush = Global.custom_brushes[i]
|
||||
for i in range(Global.brushes_from_files, Global.current_project.brushes.size()):
|
||||
var brush = Global.current_project.brushes[i]
|
||||
file.store_line("/")
|
||||
file.store_16(brush.get_size().x)
|
||||
file.store_16(brush.get_size().y)
|
||||
|
@ -257,7 +257,7 @@ func save_pxo_file(path : String, autosave : bool) -> void:
|
|||
file.store_line("END_BRUSHES")
|
||||
|
||||
# Store animation tags
|
||||
for tag in Global.animation_tags:
|
||||
for tag in Global.current_project.animation_tags:
|
||||
file.store_line(".T/")
|
||||
file.store_line(tag.name)
|
||||
file.store_var(tag.color)
|
||||
|
@ -267,8 +267,8 @@ func save_pxo_file(path : String, autosave : bool) -> void:
|
|||
|
||||
file.close()
|
||||
|
||||
if Global.project_has_changed and not autosave:
|
||||
Global.project_has_changed = false
|
||||
if Global.current_project.has_changed and not autosave:
|
||||
Global.current_project.has_changed = false
|
||||
|
||||
if autosave:
|
||||
Global.notification_label("File autosaved")
|
||||
|
@ -342,7 +342,7 @@ func reload_backup_file(project_path : String, backup_path : String) -> void:
|
|||
if project_path != backup_path:
|
||||
current_save_path = project_path
|
||||
Global.window_title = project_path.get_file() + " - Pixelorama(*) " + Global.current_version
|
||||
Global.project_has_changed = true
|
||||
Global.current_project.has_changed = true
|
||||
|
||||
Global.notification_label("Backup reloaded")
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ var pen_pressure := 1.0 # For tablet pressure sensitivity
|
|||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
var frame : Frame = new_empty_frame(true)
|
||||
Global.frames.append(frame)
|
||||
Global.current_project.frames.append(frame)
|
||||
camera_zoom()
|
||||
|
||||
line_2d = Line2D.new()
|
||||
|
@ -38,14 +38,14 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func _draw() -> void:
|
||||
var current_cels : Array = Global.frames[Global.current_frame].cels
|
||||
var current_cels : Array = Global.current_project.frames[Global.current_project.current_frame].cels
|
||||
if Global.onion_skinning:
|
||||
onion_skinning()
|
||||
|
||||
# Draw current frame layers
|
||||
for i in range(Global.layers.size()):
|
||||
for i in range(Global.current_project.layers.size()):
|
||||
var modulate_color := Color(1, 1, 1, current_cels[i].opacity)
|
||||
if Global.layers[i].visible: # if it's visible
|
||||
if Global.current_project.layers[i].visible: # if it's visible
|
||||
draw_texture(current_cels[i].image_texture, location, modulate_color)
|
||||
|
||||
if Global.tile_mode:
|
||||
|
@ -82,9 +82,9 @@ func _draw() -> void:
|
|||
draw_set_transform(position, rotation, scale)
|
||||
else:
|
||||
if Global.current_tools[i] == Global.Tools.PENCIL || Global.current_tools[i] == Global.Tools.ERASER:
|
||||
var custom_brush_size = Global.custom_brush_images[i].get_size() - Vector2.ONE
|
||||
var custom_brush_size = Global.current_project.brush_images[i].get_size() - Vector2.ONE
|
||||
var dst : Vector2 = DrawingAlgos.rectangle_center(mouse_pos, custom_brush_size)
|
||||
draw_texture(Global.custom_brush_textures[i], dst)
|
||||
draw_texture(Global.current_project.brush_textures[i], dst)
|
||||
|
||||
|
||||
func _input(event : InputEvent) -> void:
|
||||
|
@ -125,7 +125,7 @@ func _input(event : InputEvent) -> void:
|
|||
x_max = location.x + size.x
|
||||
y_min = location.y
|
||||
y_max = location.y + size.y
|
||||
if Global.selected_pixels.size() != 0:
|
||||
if Global.current_project.selected_pixels.size() != 0:
|
||||
x_min = max(x_min, Global.selection_rectangle.polygon[0].x)
|
||||
x_max = min(x_max, Global.selection_rectangle.polygon[2].x)
|
||||
y_min = max(y_min, Global.selection_rectangle.polygon[0].y)
|
||||
|
@ -169,7 +169,7 @@ func _input(event : InputEvent) -> void:
|
|||
else:
|
||||
handle_undo("Draw")
|
||||
elif (Input.is_action_just_released("left_mouse") && !Input.is_action_pressed("right_mouse")) || (Input.is_action_just_released("right_mouse") && !Input.is_action_pressed("left_mouse")):
|
||||
if can_handle || Global.undos == Global.undo_redo.get_version():
|
||||
if can_handle || Global.current_project.undos == Global.current_project.undo_redo.get_version():
|
||||
if previous_action != -1 && previous_action != Global.Tools.RECTSELECT && current_action != Global.Tools.COLORPICKER && current_action != Global.Tools.ZOOM:
|
||||
handle_redo("Draw")
|
||||
|
||||
|
@ -219,14 +219,14 @@ func _input(event : InputEvent) -> void:
|
|||
|
||||
for xx in range(start_pos.x, end_pos.x):
|
||||
for yy in range(start_pos.y, end_pos.y):
|
||||
Global.selected_pixels.append(Vector2(xx, yy))
|
||||
Global.current_project.selected_pixels.append(Vector2(xx, yy))
|
||||
is_making_selection = -1
|
||||
handle_redo("Rectangle Select")
|
||||
|
||||
previous_action = current_action
|
||||
previous_mouse_pos = current_pixel
|
||||
if sprite_changed_this_frame:
|
||||
update_texture(Global.current_layer)
|
||||
update_texture(Global.current_project.current_layer)
|
||||
|
||||
|
||||
func camera_zoom() -> void:
|
||||
|
@ -251,7 +251,7 @@ func camera_zoom() -> void:
|
|||
|
||||
func new_empty_frame(first_time := false) -> Frame:
|
||||
var frame := Frame.new()
|
||||
for l in Global.layers:
|
||||
for l in Global.current_project.layers:
|
||||
# The sprite itself
|
||||
var sprite := Image.new()
|
||||
if first_time:
|
||||
|
@ -271,7 +271,7 @@ func new_empty_frame(first_time := false) -> Frame:
|
|||
|
||||
|
||||
func handle_tools(current_mouse_button : int, current_action : int, mouse_pos : Vector2, can_handle : bool) -> void:
|
||||
var current_cel : Cel = Global.frames[Global.current_frame].cels[Global.current_layer]
|
||||
var current_cel : Cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer]
|
||||
var sprite : Image = current_cel.image
|
||||
var mouse_pos_floored := mouse_pos.floor()
|
||||
var mouse_pos_ceiled := mouse_pos.ceil()
|
||||
|
@ -354,7 +354,7 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
|||
# Check SelectionRectangle.gd for more code on Rectangle Selection
|
||||
if Global.can_draw && Global.has_focus:
|
||||
# If we're creating a new selection
|
||||
if Global.selected_pixels.size() == 0 || !point_in_rectangle(mouse_pos_floored, Global.selection_rectangle.polygon[0] - Vector2.ONE, Global.selection_rectangle.polygon[2]):
|
||||
if Global.current_project.selected_pixels.size() == 0 || !point_in_rectangle(mouse_pos_floored, Global.selection_rectangle.polygon[0] - Vector2.ONE, Global.selection_rectangle.polygon[2]):
|
||||
var mouse_button_string := "left_mouse" if current_mouse_button == Global.Mouse_Button.LEFT else "right_mouse"
|
||||
|
||||
if Input.is_action_just_pressed(mouse_button_string):
|
||||
|
@ -363,7 +363,7 @@ func handle_tools(current_mouse_button : int, current_action : int, mouse_pos :
|
|||
Global.selection_rectangle.polygon[2] = mouse_pos_floored
|
||||
Global.selection_rectangle.polygon[3] = mouse_pos_floored
|
||||
is_making_selection = current_mouse_button
|
||||
Global.selected_pixels.clear()
|
||||
Global.current_project.selected_pixels.clear()
|
||||
else:
|
||||
if is_making_selection != -1: # If we're making a new selection...
|
||||
var start_pos = Global.selection_rectangle.polygon[0]
|
||||
|
@ -413,25 +413,25 @@ func handle_undo(action : String) -> void:
|
|||
var frame_index := -1
|
||||
var layer_index := -1
|
||||
if Global.animation_timer.is_stopped(): # if we're not animating, store only the current canvas
|
||||
frames.append(Global.frames[Global.current_frame])
|
||||
frame_index = Global.current_frame
|
||||
layer_index = Global.current_layer
|
||||
frames.append(Global.current_project.frames[Global.current_project.current_frame])
|
||||
frame_index = Global.current_project.current_frame
|
||||
layer_index = Global.current_project.current_layer
|
||||
else: # If we're animating, store all frames
|
||||
frames = Global.frames
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action(action)
|
||||
frames = Global.current_project.frames
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action(action)
|
||||
for f in frames:
|
||||
# I'm not sure why I have to unlock it, but...
|
||||
# ...if I don't, it doesn't work properly
|
||||
f.cels[Global.current_layer].image.unlock()
|
||||
var data = f.cels[Global.current_layer].image.data
|
||||
f.cels[Global.current_layer].image.lock()
|
||||
Global.undo_redo.add_undo_property(f.cels[Global.current_layer].image, "data", data)
|
||||
f.cels[Global.current_project.current_layer].image.unlock()
|
||||
var data = f.cels[Global.current_project.current_layer].image.data
|
||||
f.cels[Global.current_project.current_layer].image.lock()
|
||||
Global.current_project.undo_redo.add_undo_property(f.cels[Global.current_project.current_layer].image, "data", data)
|
||||
if action == "Rectangle Select":
|
||||
var selected_pixels = Global.selected_pixels.duplicate()
|
||||
Global.undo_redo.add_undo_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon)
|
||||
Global.undo_redo.add_undo_property(Global, "selected_pixels", selected_pixels)
|
||||
Global.undo_redo.add_undo_method(Global, "undo", frame_index, layer_index)
|
||||
var selected_pixels = Global.current_project.selected_pixels.duplicate()
|
||||
Global.current_project.undo_redo.add_undo_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "selected_pixels", selected_pixels)
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo", frame_index, layer_index)
|
||||
|
||||
can_undo = false
|
||||
|
||||
|
@ -439,34 +439,34 @@ func handle_undo(action : String) -> void:
|
|||
func handle_redo(action : String) -> void:
|
||||
can_undo = true
|
||||
|
||||
if Global.undos < Global.undo_redo.get_version():
|
||||
if Global.current_project.undos < Global.current_project.undo_redo.get_version():
|
||||
return
|
||||
var frames := []
|
||||
var frame_index := -1
|
||||
var layer_index := -1
|
||||
if Global.animation_timer.is_stopped():
|
||||
frames.append(Global.frames[Global.current_frame])
|
||||
frame_index = Global.current_frame
|
||||
layer_index = Global.current_layer
|
||||
frames.append(Global.current_project.frames[Global.current_project.current_frame])
|
||||
frame_index = Global.current_project.current_frame
|
||||
layer_index = Global.current_project.current_layer
|
||||
else:
|
||||
frames = Global.frames
|
||||
frames = Global.current_project.frames
|
||||
for f in frames:
|
||||
Global.undo_redo.add_do_property(f.cels[Global.current_layer].image, "data", f.cels[Global.current_layer].image.data)
|
||||
Global.current_project.undo_redo.add_do_property(f.cels[Global.current_project.current_layer].image, "data", f.cels[Global.current_project.current_layer].image.data)
|
||||
if action == "Rectangle Select":
|
||||
Global.undo_redo.add_do_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon)
|
||||
Global.undo_redo.add_do_property(Global, "selected_pixels", Global.selected_pixels)
|
||||
Global.undo_redo.add_do_method(Global, "redo", frame_index, layer_index)
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_do_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "selected_pixels", Global.current_project.selected_pixels)
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo", frame_index, layer_index)
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func update_texture(layer_index : int, frame_index := -1) -> void:
|
||||
if frame_index == -1:
|
||||
frame_index = Global.current_frame
|
||||
var current_cel : Cel = Global.frames[frame_index].cels[layer_index]
|
||||
frame_index = Global.current_project.current_frame
|
||||
var current_cel : Cel = Global.current_project.frames[frame_index].cels[layer_index]
|
||||
current_cel.image_texture.create_from_image(current_cel.image, 0)
|
||||
|
||||
var frame_texture_rect : TextureRect
|
||||
frame_texture_rect = Global.find_node_by_name(Global.layers[layer_index].frame_container.get_child(frame_index), "CelTexture")
|
||||
frame_texture_rect = Global.find_node_by_name(Global.current_project.layers[layer_index].frame_container.get_child(frame_index), "CelTexture")
|
||||
frame_texture_rect.texture = current_cel.image_texture
|
||||
|
||||
|
||||
|
@ -479,10 +479,10 @@ func onion_skinning() -> void:
|
|||
else:
|
||||
color = Color.white
|
||||
for i in range(1, Global.onion_skinning_past_rate + 1):
|
||||
if Global.current_frame >= i:
|
||||
if Global.current_project.current_frame >= i:
|
||||
var layer_i := 0
|
||||
for layer in Global.frames[Global.current_frame - i].cels:
|
||||
if Global.layers[layer_i].visible:
|
||||
for layer in Global.current_project.frames[Global.current_project.current_frame - i].cels:
|
||||
if Global.current_project.layers[layer_i].visible:
|
||||
color.a = 0.6 / i
|
||||
draw_texture(layer.image_texture, location, color)
|
||||
layer_i += 1
|
||||
|
@ -495,10 +495,10 @@ func onion_skinning() -> void:
|
|||
else:
|
||||
color = Color.white
|
||||
for i in range(1, Global.onion_skinning_future_rate + 1):
|
||||
if Global.current_frame < Global.frames.size() - i:
|
||||
if Global.current_project.current_frame < Global.current_project.frames.size() - i:
|
||||
var layer_i := 0
|
||||
for layer in Global.frames[Global.current_frame + i].cels:
|
||||
if Global.layers[layer_i].visible:
|
||||
for layer in Global.current_project.frames[Global.current_project.current_frame + i].cels:
|
||||
if Global.current_project.layers[layer_i].visible:
|
||||
color.a = 0.6 / i
|
||||
draw_texture(layer.image_texture, location, color)
|
||||
layer_i += 1
|
||||
|
|
215
src/Classes/Project.gd
Normal file
215
src/Classes/Project.gd
Normal file
|
@ -0,0 +1,215 @@
|
|||
class_name Project extends Reference
|
||||
# A class for project properties.
|
||||
|
||||
|
||||
var name := ""
|
||||
#var size : Vector2
|
||||
var undo_redo : UndoRedo
|
||||
var undos := 0 # The number of times we added undo properties
|
||||
var has_changed := false
|
||||
var frames := [] setget frames_changed # Array of Frames (that contain Cels)
|
||||
var layers := [] setget layers_changed # Array of Layers
|
||||
var current_frame := 0 setget frame_changed
|
||||
var current_layer := 0 setget layer_changed
|
||||
var animation_tags := [] setget animation_tags_changed # Array of AnimationTags
|
||||
#var guides := [] # Array of Guides
|
||||
|
||||
var brushes := [] # Array of Images
|
||||
var brush_images := [Image.new(), Image.new()]
|
||||
var brush_textures := [ImageTexture.new(), ImageTexture.new()]
|
||||
|
||||
var selected_pixels := []
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
undo_redo = UndoRedo.new()
|
||||
name = tr("untitled")
|
||||
layers.append(Layer.new())
|
||||
|
||||
|
||||
func frames_changed(value : Array) -> void:
|
||||
frames = value
|
||||
for container in Global.frames_container.get_children():
|
||||
for button in container.get_children():
|
||||
container.remove_child(button)
|
||||
button.queue_free()
|
||||
Global.frames_container.remove_child(container)
|
||||
|
||||
for frame_id in Global.frame_ids.get_children():
|
||||
Global.frame_ids.remove_child(frame_id)
|
||||
frame_id.queue_free()
|
||||
|
||||
for i in range(layers.size() - 1, -1, -1):
|
||||
Global.frames_container.add_child(layers[i].frame_container)
|
||||
|
||||
for j in range(frames.size()):
|
||||
var label := Label.new()
|
||||
label.rect_min_size.x = 36
|
||||
label.align = Label.ALIGN_CENTER
|
||||
label.text = str(j + 1)
|
||||
Global.frame_ids.add_child(label)
|
||||
|
||||
for i in range(layers.size() - 1, -1, -1):
|
||||
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance()
|
||||
cel_button.frame = j
|
||||
cel_button.layer = i
|
||||
cel_button.get_child(0).texture = frames[j].cels[i].image_texture
|
||||
|
||||
layers[i].frame_container.add_child(cel_button)
|
||||
|
||||
# This is useful in case tagged frames get deleted DURING the animation is playing
|
||||
# otherwise, this code is useless in this context, since these values are being set
|
||||
# when the play buttons get pressed, anyway
|
||||
Global.animation_timeline.first_frame = 0
|
||||
Global.animation_timeline.last_frame = frames.size() - 1
|
||||
if Global.play_only_tags:
|
||||
for tag in animation_tags:
|
||||
if current_frame + 1 >= tag.from && current_frame + 1 <= tag.to:
|
||||
Global.animation_timeline.first_frame = tag.from - 1
|
||||
Global.animation_timeline.last_frame = min(frames.size() - 1, tag.to - 1)
|
||||
|
||||
|
||||
func layers_changed(value : Array) -> void:
|
||||
layers = value
|
||||
if Global.layers_changed_skip:
|
||||
Global.layers_changed_skip = false
|
||||
return
|
||||
|
||||
for container in Global.layers_container.get_children():
|
||||
container.queue_free()
|
||||
|
||||
for container in Global.frames_container.get_children():
|
||||
for button in container.get_children():
|
||||
container.remove_child(button)
|
||||
button.queue_free()
|
||||
Global.frames_container.remove_child(container)
|
||||
|
||||
for i in range(layers.size() - 1, -1, -1):
|
||||
var layer_container = load("res://src/UI/Timeline/LayerButton.tscn").instance()
|
||||
layer_container.i = i
|
||||
if layers[i].name == tr("Layer") + " 0":
|
||||
layers[i].name = tr("Layer") + " %s" % i
|
||||
|
||||
Global.layers_container.add_child(layer_container)
|
||||
layer_container.label.text = layers[i].name
|
||||
layer_container.line_edit.text = layers[i].name
|
||||
|
||||
Global.frames_container.add_child(layers[i].frame_container)
|
||||
for j in range(frames.size()):
|
||||
var cel_button = load("res://src/UI/Timeline/CelButton.tscn").instance()
|
||||
cel_button.frame = j
|
||||
cel_button.layer = i
|
||||
cel_button.get_child(0).texture = frames[j].cels[i].image_texture
|
||||
|
||||
layers[i].frame_container.add_child(cel_button)
|
||||
|
||||
var layer_button = Global.layers_container.get_child(Global.layers_container.get_child_count() - 1 - current_layer)
|
||||
layer_button.pressed = true
|
||||
self.current_frame = current_frame # Call frame_changed to update UI
|
||||
|
||||
if layers[current_layer].locked:
|
||||
Global.disable_button(Global.remove_layer_button, true)
|
||||
|
||||
if layers.size() == 1:
|
||||
Global.disable_button(Global.remove_layer_button, true)
|
||||
Global.disable_button(Global.move_up_layer_button, true)
|
||||
Global.disable_button(Global.move_down_layer_button, true)
|
||||
Global.disable_button(Global.merge_down_layer_button, true)
|
||||
elif !layers[current_layer].locked:
|
||||
Global.disable_button(Global.remove_layer_button, false)
|
||||
|
||||
|
||||
func frame_changed(value : int) -> void:
|
||||
current_frame = value
|
||||
Global.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
|
||||
|
||||
for i in frames.size(): # De-select all the other frames
|
||||
var text_color := Color.white
|
||||
if Global.theme_type == Global.Theme_Types.CARAMEL || Global.theme_type == Global.Theme_Types.LIGHT:
|
||||
text_color = Color.black
|
||||
Global.frame_ids.get_child(i).add_color_override("font_color", text_color)
|
||||
for layer in layers:
|
||||
if i < layer.frame_container.get_child_count():
|
||||
layer.frame_container.get_child(i).pressed = false
|
||||
|
||||
# Select the new frame
|
||||
Global.frame_ids.get_child(current_frame).add_color_override("font_color", Global.control.theme.get_color("Selected Color", "Label"))
|
||||
if current_frame < layers[current_layer].frame_container.get_child_count():
|
||||
layers[current_layer].frame_container.get_child(current_frame).pressed = true
|
||||
|
||||
if frames.size() == 1:
|
||||
Global.disable_button(Global.remove_frame_button, true)
|
||||
elif !layers[current_layer].locked:
|
||||
Global.disable_button(Global.remove_frame_button, false)
|
||||
|
||||
Global.canvas.update()
|
||||
Global.transparent_checker._ready() # To update the rect size
|
||||
|
||||
|
||||
func layer_changed(value : int) -> void:
|
||||
current_layer = value
|
||||
if current_frame < frames.size():
|
||||
Global.layer_opacity_slider.value = frames[current_frame].cels[current_layer].opacity * 100
|
||||
Global.layer_opacity_spinbox.value = frames[current_frame].cels[current_layer].opacity * 100
|
||||
|
||||
for container in Global.layers_container.get_children():
|
||||
container.pressed = false
|
||||
|
||||
if current_layer < Global.layers_container.get_child_count():
|
||||
var layer_button = Global.layers_container.get_child(Global.layers_container.get_child_count() - 1 - current_layer)
|
||||
layer_button.pressed = true
|
||||
|
||||
if current_layer < layers.size() - 1:
|
||||
Global.disable_button(Global.move_up_layer_button, false)
|
||||
else:
|
||||
Global.disable_button(Global.move_up_layer_button, true)
|
||||
|
||||
if current_layer > 0:
|
||||
Global.disable_button(Global.move_down_layer_button, false)
|
||||
Global.disable_button(Global.merge_down_layer_button, false)
|
||||
else:
|
||||
Global.disable_button(Global.move_down_layer_button, true)
|
||||
Global.disable_button(Global.merge_down_layer_button, true)
|
||||
|
||||
if current_layer < layers.size():
|
||||
if layers[current_layer].locked:
|
||||
Global.disable_button(Global.remove_layer_button, true)
|
||||
else:
|
||||
if layers.size() > 1:
|
||||
Global.disable_button(Global.remove_layer_button, false)
|
||||
|
||||
yield(Global.get_tree().create_timer(0.01), "timeout")
|
||||
self.current_frame = current_frame # Call frame_changed to update UI
|
||||
|
||||
|
||||
func animation_tags_changed(value : Array) -> void:
|
||||
animation_tags = value
|
||||
for child in Global.tag_container.get_children():
|
||||
child.queue_free()
|
||||
|
||||
for tag in animation_tags:
|
||||
var tag_c : Container = load("res://src/UI/Timeline/AnimationTag.tscn").instance()
|
||||
Global.tag_container.add_child(tag_c)
|
||||
var tag_position : int = Global.tag_container.get_child_count() - 1
|
||||
Global.tag_container.move_child(tag_c, tag_position)
|
||||
tag_c.get_node("Label").text = tag.name
|
||||
tag_c.get_node("Label").modulate = tag.color
|
||||
tag_c.get_node("Line2D").default_color = tag.color
|
||||
|
||||
tag_c.rect_position.x = (tag.from - 1) * 39 + tag.from
|
||||
|
||||
var size : int = tag.to - tag.from
|
||||
tag_c.rect_min_size.x = (size + 1) * 39
|
||||
tag_c.get_node("Line2D").points[2] = Vector2(tag_c.rect_min_size.x, 0)
|
||||
tag_c.get_node("Line2D").points[3] = Vector2(tag_c.rect_min_size.x, 32)
|
||||
|
||||
# This is useful in case tags get modified DURING the animation is playing
|
||||
# otherwise, this code is useless in this context, since these values are being set
|
||||
# when the play buttons get pressed, anyway
|
||||
Global.animation_timeline.first_frame = 0
|
||||
Global.animation_timeline.last_frame = frames.size() - 1
|
||||
if Global.play_only_tags:
|
||||
for tag in animation_tags:
|
||||
if current_frame + 1 >= tag.from && current_frame + 1 <= tag.to:
|
||||
Global.animation_timeline.first_frame = tag.from - 1
|
||||
Global.animation_timeline.last_frame = min(frames.size() - 1, tag.to - 1)
|
56
src/Main.gd
56
src/Main.gd
|
@ -21,9 +21,9 @@ func _ready() -> void:
|
|||
|
||||
Global.window_title = "(" + tr("untitled") + ") - Pixelorama " + Global.current_version
|
||||
|
||||
Global.layers[0].name = tr("Layer") + " 0"
|
||||
Global.layers_container.get_child(0).label.text = Global.layers[0].name
|
||||
Global.layers_container.get_child(0).line_edit.text = Global.layers[0].name
|
||||
Global.current_project.layers[0].name = tr("Layer") + " 0"
|
||||
Global.layers_container.get_child(0).label.text = Global.current_project.layers[0].name
|
||||
Global.layers_container.get_child(0).line_edit.text = Global.current_project.layers[0].name
|
||||
|
||||
Import.import_brushes(Global.directory_module.get_brushes_search_path_in_order())
|
||||
Import.import_patterns(Global.directory_module.get_patterns_search_path_in_order())
|
||||
|
@ -62,7 +62,7 @@ func _input(event : InputEvent) -> void:
|
|||
|
||||
if event.is_action_pressed("redo_secondary"): # Shift + Ctrl + Z
|
||||
redone = true
|
||||
Global.undo_redo.redo()
|
||||
Global.current_project.undo_redo.redo()
|
||||
redone = false
|
||||
|
||||
|
||||
|
@ -242,7 +242,7 @@ func _on_files_dropped(_files : PoolStringArray, _screen : int) -> void:
|
|||
|
||||
|
||||
func on_new_project_file_menu_option_pressed(id : int) -> void:
|
||||
if Global.project_has_changed:
|
||||
if Global.current_project.has_changed:
|
||||
unsaved_canvas_state = id
|
||||
$UnsavedCanvasDialog.popup_centered()
|
||||
else:
|
||||
|
@ -259,7 +259,7 @@ func open_project_file() -> void:
|
|||
func on_open_last_project_file_menu_option_pressed(id : int) -> void:
|
||||
# Check if last project path is set and if yes then open
|
||||
if Global.config_cache.has_section_key("preferences", "last_project_path"):
|
||||
if Global.project_has_changed:
|
||||
if Global.current_project.has_changed:
|
||||
unsaved_canvas_state = id
|
||||
$UnsavedCanvasDialog.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
|
@ -326,10 +326,10 @@ func file_menu_id_pressed(id : int) -> void:
|
|||
func edit_menu_id_pressed(id : int) -> void:
|
||||
match id:
|
||||
0: # Undo
|
||||
Global.undo_redo.undo()
|
||||
Global.current_project.undo_redo.undo()
|
||||
1: # Redo
|
||||
redone = true
|
||||
Global.undo_redo.redo()
|
||||
Global.current_project.undo_redo.redo()
|
||||
redone = false
|
||||
2: # Clear selection
|
||||
Global.canvas.handle_undo("Rectangle Select")
|
||||
|
@ -337,7 +337,7 @@ func edit_menu_id_pressed(id : int) -> void:
|
|||
Global.selection_rectangle.polygon[1] = Vector2.ZERO
|
||||
Global.selection_rectangle.polygon[2] = Vector2.ZERO
|
||||
Global.selection_rectangle.polygon[3] = Vector2.ZERO
|
||||
Global.selected_pixels.clear()
|
||||
Global.current_project.selected_pixels.clear()
|
||||
Global.canvas.handle_redo("Rectangle Select")
|
||||
3: # Preferences
|
||||
$PreferencesDialog.popup_centered(Vector2(400, 280))
|
||||
|
@ -398,9 +398,9 @@ func show_scale_image_popup() -> void:
|
|||
|
||||
func crop_image() -> void:
|
||||
# Use first cel as a starting rectangle
|
||||
var used_rect : Rect2 = Global.frames[0].cels[0].image.get_used_rect()
|
||||
var used_rect : Rect2 = Global.current_project.frames[0].cels[0].image.get_used_rect()
|
||||
|
||||
for f in Global.frames:
|
||||
for f in Global.current_project.frames:
|
||||
# However, if first cel is empty, loop through all cels until we find one that isn't
|
||||
for cel in f.cels:
|
||||
if used_rect != Rect2(0, 0, 0, 0):
|
||||
|
@ -420,24 +420,24 @@ func crop_image() -> void:
|
|||
|
||||
var width := used_rect.size.x
|
||||
var height := used_rect.size.y
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Scale")
|
||||
Global.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
|
||||
for f in Global.frames:
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Scale")
|
||||
Global.current_project.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
|
||||
for f in Global.current_project.frames:
|
||||
# Loop through all the layers to crop them
|
||||
for j in range(Global.layers.size() - 1, -1, -1):
|
||||
for j in range(Global.current_project.layers.size() - 1, -1, -1):
|
||||
var sprite : Image = f.cels[j].image.get_rect(used_rect)
|
||||
Global.undo_redo.add_do_property(f.cels[j].image, "data", sprite.data)
|
||||
Global.undo_redo.add_undo_property(f.cels[j].image, "data", f.cels[j].image.data)
|
||||
Global.current_project.undo_redo.add_do_property(f.cels[j].image, "data", sprite.data)
|
||||
Global.current_project.undo_redo.add_undo_property(f.cels[j].image, "data", f.cels[j].image.data)
|
||||
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size)
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size)
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func flip_image(horizontal : bool) -> void:
|
||||
var image : Image = Global.frames[Global.current_frame].cels[Global.current_layer].image
|
||||
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
|
||||
Global.canvas.handle_undo("Draw")
|
||||
image.unlock()
|
||||
if horizontal:
|
||||
|
@ -449,14 +449,14 @@ func flip_image(horizontal : bool) -> void:
|
|||
|
||||
|
||||
func show_rotate_image_popup() -> void:
|
||||
var image : Image = Global.frames[Global.current_frame].cels[Global.current_layer].image
|
||||
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
|
||||
$RotateImage.set_sprite(image)
|
||||
$RotateImage.popup_centered()
|
||||
Global.dialog_open(true)
|
||||
|
||||
|
||||
func invert_image_colors() -> void:
|
||||
var image : Image = Global.frames[Global.current_frame].cels[Global.current_layer].image
|
||||
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
|
||||
Global.canvas.handle_undo("Draw")
|
||||
for xx in image.get_size().x:
|
||||
for yy in image.get_size().y:
|
||||
|
@ -468,7 +468,7 @@ func invert_image_colors() -> void:
|
|||
|
||||
|
||||
func desaturate_image() -> void:
|
||||
var image : Image = Global.frames[Global.current_frame].cels[Global.current_layer].image
|
||||
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
|
||||
Global.canvas.handle_undo("Draw")
|
||||
for xx in image.get_size().x:
|
||||
for yy in image.get_size().y:
|
||||
|
@ -492,7 +492,7 @@ func show_hsv_configuration_popup() -> void:
|
|||
|
||||
|
||||
func image_menu_id_pressed(id : int) -> void:
|
||||
if Global.layers[Global.current_layer].locked: # No changes if the layer is locked
|
||||
if Global.current_project.layers[Global.current_project.current_layer].locked: # No changes if the layer is locked
|
||||
return
|
||||
match id:
|
||||
0: # Scale Image
|
||||
|
@ -602,7 +602,7 @@ func _can_draw_true() -> void:
|
|||
|
||||
func show_quit_dialog() -> void:
|
||||
if !$QuitDialog.visible:
|
||||
if !Global.project_has_changed:
|
||||
if !Global.current_project.has_changed:
|
||||
$QuitDialog.call_deferred("popup_centered")
|
||||
else:
|
||||
$QuitAndSaveDialog.call_deferred("popup_centered")
|
||||
|
|
|
@ -118,6 +118,6 @@ func change_theme(ID : int) -> void:
|
|||
texture.texture = load("res://assets/graphics/%s_themes/%s/%s" % [theme_type_string, button_category, normal_file_name])
|
||||
|
||||
# Make sure the frame text gets updated
|
||||
Global.current_frame = Global.current_frame
|
||||
Global.current_project.current_frame = Global.current_project.current_frame
|
||||
|
||||
Global.preferences_dialog.get_node("Popups/ShortcutSelector").theme = main_theme
|
||||
|
|
|
@ -20,21 +20,21 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func _process(_delta : float) -> void:
|
||||
if Global.layers[Global.current_layer].locked:
|
||||
if Global.current_project.layers[Global.current_project.current_layer].locked:
|
||||
return
|
||||
var mouse_pos: Vector2 = get_local_mouse_position() - Global.canvas.location
|
||||
var mouse_pos_floored := mouse_pos.floor()
|
||||
var start_pos := polygon[0]
|
||||
var end_pos := polygon[2]
|
||||
var current_layer_index : int = Global.current_layer
|
||||
var layer : Image = Global.frames[Global.current_frame].cels[current_layer_index].image
|
||||
var current_layer_index : int = Global.current_project.current_layer
|
||||
var layer : Image = Global.current_project.frames[Global.current_project.current_frame].cels[current_layer_index].image
|
||||
|
||||
if end_pos == start_pos:
|
||||
visible = false
|
||||
else:
|
||||
visible = true
|
||||
|
||||
if Global.can_draw and Global.has_focus and point_in_rectangle(mouse_pos, polygon[0], polygon[2]) and Global.selected_pixels.size() > 0 and (Global.current_tools[0] == Global.Tools.RECTSELECT or Global.current_tools[1] == Global.Tools.RECTSELECT):
|
||||
if Global.can_draw and Global.has_focus and point_in_rectangle(mouse_pos, polygon[0], polygon[2]) and Global.current_project.selected_pixels.size() > 0 and (Global.current_tools[0] == Global.Tools.RECTSELECT or Global.current_tools[1] == Global.Tools.RECTSELECT):
|
||||
get_parent().get_parent().mouse_default_cursor_shape = Input.CURSOR_MOVE
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
if (Global.current_tools[0] == Global.Tools.RECTSELECT && Input.is_action_just_pressed("left_mouse")) || (Global.current_tools[1] == Global.Tools.RECTSELECT && Input.is_action_just_pressed("right_mouse")):
|
||||
|
@ -53,11 +53,11 @@ func _process(_delta : float) -> void:
|
|||
img.unlock()
|
||||
img.resize(polygon[2].x - polygon[0].x, polygon[2].y - polygon[0].y, 0)
|
||||
img.lock()
|
||||
for i in range(Global.selected_pixels.size()):
|
||||
var curr_px = Global.selected_pixels[i]
|
||||
for i in range(Global.current_project.selected_pixels.size()):
|
||||
var curr_px = Global.current_project.selected_pixels[i]
|
||||
if point_in_rectangle(curr_px, Global.canvas.location - Vector2.ONE, Global.canvas.size):
|
||||
orig_colors.append(layer.get_pixelv(curr_px)) # Color of pixel
|
||||
var px = curr_px - Global.selected_pixels[0]
|
||||
var px = curr_px - Global.current_project.selected_pixels[0]
|
||||
img.set_pixelv(px, orig_colors[i])
|
||||
layer.set_pixelv(curr_px, Color(0, 0, 0, 0))
|
||||
else: # If part of selection is outside canvas
|
||||
|
@ -90,7 +90,7 @@ func _process(_delta : float) -> void:
|
|||
if move_pixels:
|
||||
for i in range(orig_colors.size()):
|
||||
if orig_colors[i].a > 0:
|
||||
var px = polygon[0] + Global.selected_pixels[i] - Global.selected_pixels[0]
|
||||
var px = polygon[0] + Global.current_project.selected_pixels[i] - Global.current_project.selected_pixels[0]
|
||||
if point_in_rectangle(px, Global.canvas.location - Vector2.ONE, Global.canvas.size):
|
||||
layer.set_pixelv(px, orig_colors[i])
|
||||
Global.canvas.update_texture(current_layer_index)
|
||||
|
@ -99,17 +99,17 @@ func _process(_delta : float) -> void:
|
|||
update()
|
||||
|
||||
orig_colors.clear()
|
||||
Global.selected_pixels.clear()
|
||||
Global.current_project.selected_pixels.clear()
|
||||
for xx in range(start_pos.x, end_pos.x):
|
||||
for yy in range(start_pos.y, end_pos.y):
|
||||
Global.selected_pixels.append(Vector2(xx, yy))
|
||||
Global.current_project.selected_pixels.append(Vector2(xx, yy))
|
||||
|
||||
Global.canvas.handle_redo("Rectangle Select") # Redo
|
||||
|
||||
# Makes line2d visible
|
||||
Global.canvas.line_2d.default_color = Color.darkgray
|
||||
|
||||
if Global.selected_pixels.size() > 0:
|
||||
if Global.current_project.selected_pixels.size() > 0:
|
||||
# Handle copy
|
||||
if Input.is_action_just_pressed("copy"):
|
||||
# Save as custom brush
|
||||
|
@ -118,7 +118,7 @@ func _process(_delta : float) -> void:
|
|||
if brush_img.is_invisible():
|
||||
return
|
||||
brush_img = brush_img.get_rect(brush_img.get_used_rect()) # Save only the visible pixels
|
||||
Global.custom_brushes.append(brush_img)
|
||||
Global.current_project.brushes.append(brush_img)
|
||||
Global.create_brush_button(brush_img)
|
||||
|
||||
# Have it in the clipboard so it can be pasted later
|
||||
|
|
|
@ -50,8 +50,8 @@ func _on_DeleteButton_pressed() -> void:
|
|||
Global.update_custom_brush(1)
|
||||
|
||||
var project_brush_index = custom_brush_index - Global.brushes_from_files
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Delete Custom Brush")
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Delete Custom Brush")
|
||||
for i in range(project_brush_index, 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:
|
||||
|
@ -59,17 +59,17 @@ func _on_DeleteButton_pressed() -> void:
|
|||
if Global.custom_brush_indexes[1] == bb.custom_brush_index:
|
||||
Global.custom_brush_indexes[1] -= 1
|
||||
|
||||
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)
|
||||
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.custom_brushes.duplicate()
|
||||
var custom_brushes: Array = Global.current_project.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()
|
||||
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()
|
||||
|
||||
|
||||
func _on_BrushButton_mouse_entered() -> void:
|
||||
|
|
|
@ -74,22 +74,22 @@ func _on_CreateNewImage_confirmed() -> void:
|
|||
var height : int = height_value.value
|
||||
var fill_color : Color = fill_color_node.color
|
||||
Global.clear_frames()
|
||||
Global.layers.clear()
|
||||
Global.layers.append(Layer.new())
|
||||
Global.current_project.layers.clear()
|
||||
Global.current_project.layers.append(Layer.new())
|
||||
Global.canvas.size = Vector2(width, height).floor()
|
||||
Global.canvas.fill_color = fill_color
|
||||
var frame : Frame = Global.canvas.new_empty_frame()
|
||||
Global.canvas.camera_zoom()
|
||||
Global.frames.append(frame)
|
||||
Global.current_project.frames.append(frame)
|
||||
|
||||
Global.current_layer = 0
|
||||
Global.frames = Global.frames # To trigger Global.frames_changed()
|
||||
Global.current_frame = 0
|
||||
Global.layers = Global.layers # To trigger Global.layers_changed()
|
||||
Global.project_has_changed = false
|
||||
Global.current_project.current_layer = 0
|
||||
Global.current_project.frames = Global.current_project.frames # To trigger Global.frames_changed()
|
||||
Global.current_project.current_frame = 0
|
||||
Global.current_project.layers = Global.current_project.layers # To trigger Global.layers_changed()
|
||||
Global.current_project.has_changed = false
|
||||
if fill_color.a > 0:
|
||||
Global.frames[0].cels[0].image.fill(fill_color)
|
||||
Global.frames[0].cels[0].image.lock()
|
||||
Global.current_project.frames[0].cels[0].image.fill(fill_color)
|
||||
Global.current_project.frames[0].cels[0].image.lock()
|
||||
Global.canvas.update_texture(0)
|
||||
|
||||
|
||||
|
|
|
@ -89,8 +89,8 @@ func show_tab() -> void:
|
|||
$VBoxContainer/File/FileFormat.selected = FileFormat.PNG
|
||||
$FrameTimer.stop()
|
||||
if not was_exported:
|
||||
frame_number = Global.current_frame + 1
|
||||
$VBoxContainer/FrameOptions/FrameNumber/FrameNumber.max_value = Global.frames.size() + 1
|
||||
frame_number = Global.current_project.current_frame + 1
|
||||
$VBoxContainer/FrameOptions/FrameNumber/FrameNumber.max_value = Global.current_project.frames.size() + 1
|
||||
var prev_frame_number = $VBoxContainer/FrameOptions/FrameNumber/FrameNumber.value
|
||||
$VBoxContainer/FrameOptions/FrameNumber/FrameNumber.value = frame_number
|
||||
if prev_frame_number == frame_number:
|
||||
|
@ -135,7 +135,7 @@ func external_export() -> void:
|
|||
|
||||
|
||||
func process_frame() -> void:
|
||||
var frame = Global.frames[frame_number - 1]
|
||||
var frame = Global.current_project.frames[frame_number - 1]
|
||||
var image := Image.new()
|
||||
image.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
|
||||
blend_layers(image, frame)
|
||||
|
@ -147,11 +147,11 @@ func process_spritesheet() -> void:
|
|||
# Range of frames determined by tags
|
||||
var frames := []
|
||||
if frame_current_tag > 0:
|
||||
var frame_start = Global.animation_tags[frame_current_tag - 1].from
|
||||
var frame_end = Global.animation_tags[frame_current_tag - 1].to
|
||||
frames = Global.frames.slice(frame_start-1, frame_end-1, 1, true)
|
||||
var frame_start = Global.current_project.animation_tags[frame_current_tag - 1].from
|
||||
var frame_end = Global.current_project.animation_tags[frame_current_tag - 1].to
|
||||
frames = Global.current_project.frames.slice(frame_start-1, frame_end-1, 1, true)
|
||||
else:
|
||||
frames = Global.frames
|
||||
frames = Global.current_project.frames
|
||||
|
||||
# Then store the size of frames for other functions
|
||||
number_of_frames = frames.size()
|
||||
|
@ -197,7 +197,7 @@ func process_spritesheet() -> void:
|
|||
|
||||
func process_animation() -> void:
|
||||
processed_images.clear()
|
||||
for frame in Global.frames:
|
||||
for frame in Global.current_project.frames:
|
||||
var image := Image.new()
|
||||
image.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
|
||||
blend_layers(image, frame)
|
||||
|
@ -280,7 +280,7 @@ func remove_previews() -> void:
|
|||
|
||||
func get_proccessed_image_animation_tag_and_start_id(processed_image_id : int) -> Array:
|
||||
var result_animation_tag_and_start_id = null
|
||||
for animation_tag in Global.animation_tags:
|
||||
for animation_tag in Global.current_project.animation_tags:
|
||||
# Check if processed image is in frame tag and assign frame tag and start id if yes
|
||||
# Then stop
|
||||
if (processed_image_id + 1) >= animation_tag.from and (processed_image_id + 1) <= animation_tag.to:
|
||||
|
@ -365,7 +365,7 @@ func blend_layers(image : Image, frame : Frame, origin : Vector2 = Vector2(0, 0)
|
|||
image.lock()
|
||||
var layer_i := 0
|
||||
for cel in frame.cels:
|
||||
if Global.layers[layer_i].visible:
|
||||
if Global.current_project.layers[layer_i].visible:
|
||||
var cel_image := Image.new()
|
||||
cel_image.copy_from(cel.image)
|
||||
cel_image.lock()
|
||||
|
@ -453,7 +453,7 @@ func create_frame_tag_list() -> void:
|
|||
frame_container.add_item("All Frames", 0) # Re-add removed 'All Frames' item
|
||||
|
||||
# Repopulate list with current tag list
|
||||
for item in Global.animation_tags:
|
||||
for item in Global.current_project.animation_tags:
|
||||
frame_container.add_item(item.name)
|
||||
|
||||
|
||||
|
@ -476,8 +476,8 @@ func store_export_settings() -> void:
|
|||
# Fill the dialog with previous export settings
|
||||
func restore_previous_export_settings() -> void:
|
||||
current_tab = exported_tab
|
||||
frame_number = exported_frame_number if exported_frame_number <= Global.frames.size() else Global.frames.size()
|
||||
frame_current_tag = exported_frame_current_tag if exported_frame_current_tag <= Global.animation_tags.size() else 0
|
||||
frame_number = exported_frame_number if exported_frame_number <= Global.current_project.frames.size() else Global.current_project.frames.size()
|
||||
frame_current_tag = exported_frame_current_tag if exported_frame_current_tag <= Global.current_project.animation_tags.size() else 0
|
||||
orientation = exported_orientation
|
||||
lines_count = exported_lines_count
|
||||
animation_type = exported_animation_type
|
||||
|
|
|
@ -23,7 +23,7 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func _on_HSVDialog_about_to_show() -> void:
|
||||
current_cel = Global.frames[Global.current_frame].cels[Global.current_layer].image
|
||||
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
|
||||
preview_image.copy_from(current_cel)
|
||||
update_preview()
|
||||
|
||||
|
@ -38,7 +38,7 @@ func _on_Apply_pressed() -> void:
|
|||
DrawingAlgos.adjust_hsv(current_cel,0,hue_slider.value)
|
||||
DrawingAlgos.adjust_hsv(current_cel,1,sat_slider.value)
|
||||
DrawingAlgos.adjust_hsv(current_cel,2,val_slider.value)
|
||||
Global.canvas.update_texture(Global.current_layer)
|
||||
Global.canvas.update_texture(Global.current_project.current_layer)
|
||||
Global.canvas.handle_redo("Draw")
|
||||
reset()
|
||||
visible = false
|
||||
|
|
|
@ -38,12 +38,12 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
|
|||
Global.control.opensprite_file_selected = true
|
||||
if !new_frame: # If we're not adding a new frame, delete the previous
|
||||
Global.clear_frames()
|
||||
Global.layers.clear()
|
||||
Global.layers.append(Layer.new())
|
||||
Global.current_layer = 0
|
||||
Global.current_project.layers.clear()
|
||||
Global.current_project.layers.append(Layer.new())
|
||||
Global.current_project.current_layer = 0
|
||||
|
||||
var first_path : String = paths[0]
|
||||
var i : int = Global.frames.size()
|
||||
var i : int = Global.current_project.frames.size()
|
||||
if !import_spritesheet:
|
||||
for path in paths:
|
||||
var image := Image.new()
|
||||
|
@ -61,14 +61,14 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
|
|||
image.lock()
|
||||
frame.cels.append(Cel.new(image, 1))
|
||||
|
||||
for _i in range(1, Global.layers.size()):
|
||||
for _i in range(1, Global.current_project.layers.size()):
|
||||
var empty_sprite := Image.new()
|
||||
empty_sprite.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
|
||||
empty_sprite.fill(Color(0, 0, 0, 0))
|
||||
empty_sprite.lock()
|
||||
frame.cels.append(Cel.new(empty_sprite, 1))
|
||||
|
||||
Global.frames.append(frame)
|
||||
Global.current_project.frames.append(frame)
|
||||
|
||||
i += 1
|
||||
|
||||
|
@ -96,26 +96,26 @@ func _on_ImportSprites_files_selected(paths : PoolStringArray) -> void:
|
|||
cropped_image.lock()
|
||||
frame.cels.append(Cel.new(cropped_image, 1))
|
||||
|
||||
for _i in range(1, Global.layers.size()):
|
||||
for _i in range(1, Global.current_project.layers.size()):
|
||||
var empty_sprite := Image.new()
|
||||
empty_sprite.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
|
||||
empty_sprite.fill(Color(0, 0, 0, 0))
|
||||
empty_sprite.lock()
|
||||
frame.cels.append(Cel.new(empty_sprite, 1))
|
||||
|
||||
Global.frames.append(frame)
|
||||
Global.current_project.frames.append(frame)
|
||||
|
||||
i += 1
|
||||
|
||||
Global.canvas.camera_zoom()
|
||||
|
||||
Global.frames = Global.frames # Just to call Global.frames_changed
|
||||
Global.current_frame = i - 1
|
||||
Global.current_project.frames = Global.current_project.frames # Just to call Global.frames_changed
|
||||
Global.current_project.current_frame = i - 1
|
||||
if !new_frame:
|
||||
Global.layers = Global.layers # Just to call Global.layers_changed
|
||||
Global.current_project.layers = Global.current_project.layers # Just to call Global.layers_changed
|
||||
|
||||
Global.window_title = first_path.get_file() + " (" + tr("imported") + ") - Pixelorama " + Global.current_version
|
||||
if Global.project_has_changed:
|
||||
if Global.current_project.has_changed:
|
||||
Global.window_title = Global.window_title + "(*)"
|
||||
var file_name := first_path.get_basename().get_file()
|
||||
var directory_path := first_path.get_basename().replace(file_name, "")
|
||||
|
|
|
@ -10,7 +10,7 @@ func _on_OutlineDialog_confirmed() -> void:
|
|||
var diagonal : bool = $OptionsContainer/DiagonalCheckBox.pressed
|
||||
var inside_image : bool = $OptionsContainer/InsideImageCheckBox.pressed
|
||||
|
||||
var image : Image = Global.frames[Global.current_frame].cels[Global.current_layer].image
|
||||
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
|
||||
if image.is_invisible():
|
||||
return
|
||||
var new_image := Image.new()
|
||||
|
|
|
@ -5,19 +5,19 @@ func _on_ScaleImage_confirmed() -> void:
|
|||
var width : int = $VBoxContainer/OptionsContainer/WidthValue.value
|
||||
var height : int = $VBoxContainer/OptionsContainer/HeightValue.value
|
||||
var interpolation : int = $VBoxContainer/OptionsContainer/InterpolationType.selected
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Scale")
|
||||
Global.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Scale")
|
||||
Global.current_project.undo_redo.add_do_property(Global.canvas, "size", Vector2(width, height).floor())
|
||||
|
||||
for f in Global.frames:
|
||||
for f in Global.current_project.frames:
|
||||
for i in range(f.cels.size() - 1, -1, -1):
|
||||
var sprite := Image.new()
|
||||
sprite.copy_from(f.cels[i].image)
|
||||
sprite.resize(width, height, interpolation)
|
||||
Global.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
|
||||
Global.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)
|
||||
Global.current_project.undo_redo.add_do_property(f.cels[i].image, "data", sprite.data)
|
||||
Global.current_project.undo_redo.add_undo_property(f.cels[i].image, "data", f.cels[i].image.data)
|
||||
|
||||
Global.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size)
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size)
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
|
|
@ -4,13 +4,14 @@ var fps := 6.0
|
|||
var animation_loop := 1 # 0 is no loop, 1 is cycle loop, 2 is ping-pong loop
|
||||
var animation_forward := true
|
||||
var first_frame := 0
|
||||
var last_frame : int = Global.frames.size() - 1
|
||||
var last_frame := 0
|
||||
|
||||
var timeline_scroll : ScrollContainer
|
||||
var tag_scroll_container : ScrollContainer
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
last_frame = Global.current_project.frames.size() - 1
|
||||
timeline_scroll = Global.find_node_by_name(self, "TimelineScroll")
|
||||
tag_scroll_container = Global.find_node_by_name(self, "TagScroll")
|
||||
timeline_scroll.get_h_scrollbar().connect("value_changed", self, "_h_scroll_changed")
|
||||
|
@ -25,9 +26,9 @@ func _h_scroll_changed(value : float) -> void:
|
|||
|
||||
func add_frame() -> void:
|
||||
var frame : Frame = Global.canvas.new_empty_frame()
|
||||
var new_frames : Array = Global.frames.duplicate()
|
||||
var new_frames : Array = Global.current_project.frames.duplicate()
|
||||
new_frames.append(frame)
|
||||
var new_layers : Array = Global.layers.duplicate()
|
||||
var new_layers : Array = Global.current_project.layers.duplicate()
|
||||
# Loop through the array to create new classes for each element, so that they
|
||||
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
|
||||
for i in new_layers.size():
|
||||
|
@ -40,37 +41,37 @@ func add_frame() -> void:
|
|||
frame.cels[l_i].image = new_layers[l_i].linked_cels[0].cels[l_i].image
|
||||
frame.cels[l_i].image_texture = new_layers[l_i].linked_cels[0].cels[l_i].image_texture
|
||||
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Add Frame")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Add Frame")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
|
||||
Global.undo_redo.add_do_property(Global, "frames", new_frames)
|
||||
Global.undo_redo.add_do_property(Global, "current_frame", new_frames.size() - 1)
|
||||
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", new_frames.size() - 1)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
||||
|
||||
Global.undo_redo.add_undo_property(Global, "frames", Global.frames)
|
||||
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
|
||||
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func _on_DeleteFrame_pressed(frame := -1) -> void:
|
||||
if Global.frames.size() == 1:
|
||||
if Global.current_project.frames.size() == 1:
|
||||
return
|
||||
if frame == -1:
|
||||
frame = Global.current_frame
|
||||
frame = Global.current_project.current_frame
|
||||
|
||||
var frame_to_delete : Frame = Global.frames[frame]
|
||||
var new_frames : Array = Global.frames.duplicate()
|
||||
var frame_to_delete : Frame = Global.current_project.frames[frame]
|
||||
var new_frames : Array = Global.current_project.frames.duplicate()
|
||||
new_frames.erase(frame_to_delete)
|
||||
var current_frame := Global.current_frame
|
||||
var current_frame := Global.current_project.current_frame
|
||||
if current_frame > 0 && current_frame == new_frames.size(): # If it's the last frame
|
||||
current_frame -= 1
|
||||
|
||||
var new_animation_tags := Global.animation_tags.duplicate()
|
||||
var new_animation_tags := Global.current_project.animation_tags.duplicate()
|
||||
# Loop through the tags to create new classes for them, so that they won't be the same
|
||||
# as Global.animation_tags's classes. Needed for undo/redo to work properly.
|
||||
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
|
||||
for i in new_animation_tags.size():
|
||||
new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to)
|
||||
|
||||
|
@ -88,7 +89,7 @@ func _on_DeleteFrame_pressed(frame := -1) -> void:
|
|||
# Check if one of the cels of the frame is linked
|
||||
# if they are, unlink them too
|
||||
# this prevents removed cels being kept in linked memory
|
||||
var new_layers : Array = Global.layers.duplicate()
|
||||
var new_layers : Array = Global.current_project.layers.duplicate()
|
||||
# Loop through the array to create new classes for each element, so that they
|
||||
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
|
||||
for i in new_layers.size():
|
||||
|
@ -97,45 +98,45 @@ func _on_DeleteFrame_pressed(frame := -1) -> void:
|
|||
|
||||
for layer in new_layers:
|
||||
for linked in layer.linked_cels:
|
||||
if linked == Global.frames[frame]:
|
||||
if linked == Global.current_project.frames[frame]:
|
||||
layer.linked_cels.erase(linked)
|
||||
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Remove Frame")
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Remove Frame")
|
||||
|
||||
Global.undo_redo.add_do_property(Global, "frames", new_frames)
|
||||
Global.undo_redo.add_do_property(Global, "current_frame", current_frame)
|
||||
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
|
||||
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", current_frame)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
||||
|
||||
Global.undo_redo.add_undo_property(Global, "frames", Global.frames)
|
||||
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
|
||||
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
|
||||
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
||||
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func _on_CopyFrame_pressed(frame := -1) -> void:
|
||||
if frame == -1:
|
||||
frame = Global.current_frame
|
||||
frame = Global.current_project.current_frame
|
||||
|
||||
var new_frame := Frame.new()
|
||||
|
||||
var new_frames := Global.frames.duplicate()
|
||||
var new_frames := Global.current_project.frames.duplicate()
|
||||
new_frames.insert(frame + 1, new_frame)
|
||||
|
||||
for cel in Global.frames[frame].cels: # Copy every cel
|
||||
for cel in Global.current_project.frames[frame].cels: # Copy every cel
|
||||
var sprite := Image.new()
|
||||
sprite.copy_from(cel.image)
|
||||
sprite.lock()
|
||||
new_frame.cels.append(Cel.new(sprite, cel.opacity))
|
||||
|
||||
var new_animation_tags := Global.animation_tags.duplicate()
|
||||
var new_animation_tags := Global.current_project.animation_tags.duplicate()
|
||||
# Loop through the tags to create new classes for them, so that they won't be the same
|
||||
# as Global.animation_tags's classes. Needed for undo/redo to work properly.
|
||||
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
|
||||
for i in new_animation_tags.size():
|
||||
new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to)
|
||||
|
||||
|
@ -144,23 +145,23 @@ func _on_CopyFrame_pressed(frame := -1) -> void:
|
|||
if frame + 1 >= tag.from && frame + 1 <= tag.to:
|
||||
tag.to += 1
|
||||
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Add Frame")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Add Frame")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
|
||||
Global.undo_redo.add_do_property(Global, "frames", new_frames)
|
||||
Global.undo_redo.add_do_property(Global, "current_frame", frame + 1)
|
||||
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
|
||||
for i in range(Global.layers.size()):
|
||||
for child in Global.layers[i].frame_container.get_children():
|
||||
Global.undo_redo.add_do_property(child, "pressed", false)
|
||||
Global.undo_redo.add_undo_property(child, "pressed", child.pressed)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", frame + 1)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
|
||||
for i in range(Global.current_project.layers.size()):
|
||||
for child in Global.current_project.layers[i].frame_container.get_children():
|
||||
Global.current_project.undo_redo.add_do_property(child, "pressed", false)
|
||||
Global.current_project.undo_redo.add_undo_property(child, "pressed", child.pressed)
|
||||
|
||||
Global.undo_redo.add_undo_property(Global, "frames", Global.frames)
|
||||
Global.undo_redo.add_undo_property(Global, "current_frame", frame)
|
||||
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", frame)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func _on_FrameTagButton_pressed() -> void:
|
||||
|
@ -222,8 +223,8 @@ func _on_AnimationTimer_timeout() -> void:
|
|||
return
|
||||
|
||||
if animation_forward:
|
||||
if Global.current_frame < last_frame:
|
||||
Global.current_frame += 1
|
||||
if Global.current_project.current_frame < last_frame:
|
||||
Global.current_project.current_frame += 1
|
||||
else:
|
||||
match animation_loop:
|
||||
0: # No loop
|
||||
|
@ -231,14 +232,14 @@ func _on_AnimationTimer_timeout() -> void:
|
|||
Global.play_backwards.pressed = false
|
||||
Global.animation_timer.stop()
|
||||
1: # Cycle loop
|
||||
Global.current_frame = first_frame
|
||||
Global.current_project.current_frame = first_frame
|
||||
2: # Ping pong loop
|
||||
animation_forward = false
|
||||
_on_AnimationTimer_timeout()
|
||||
|
||||
else:
|
||||
if Global.current_frame > first_frame:
|
||||
Global.current_frame -= 1
|
||||
if Global.current_project.current_frame > first_frame:
|
||||
Global.current_project.current_frame -= 1
|
||||
else:
|
||||
match animation_loop:
|
||||
0: # No loop
|
||||
|
@ -246,7 +247,7 @@ func _on_AnimationTimer_timeout() -> void:
|
|||
Global.play_forward.pressed = false
|
||||
Global.animation_timer.stop()
|
||||
1: # Cycle loop
|
||||
Global.current_frame = last_frame
|
||||
Global.current_project.current_frame = last_frame
|
||||
2: # Ping pong loop
|
||||
animation_forward = true
|
||||
_on_AnimationTimer_timeout()
|
||||
|
@ -254,12 +255,12 @@ func _on_AnimationTimer_timeout() -> void:
|
|||
|
||||
func play_animation(play : bool, forward_dir : bool) -> void:
|
||||
first_frame = 0
|
||||
last_frame = Global.frames.size() - 1
|
||||
last_frame = Global.current_project.frames.size() - 1
|
||||
if Global.play_only_tags:
|
||||
for tag in Global.animation_tags:
|
||||
if Global.current_frame + 1 >= tag.from && Global.current_frame + 1 <= tag.to:
|
||||
for tag in Global.current_project.animation_tags:
|
||||
if Global.current_project.current_frame + 1 >= tag.from && Global.current_project.current_frame + 1 <= tag.to:
|
||||
first_frame = tag.from - 1
|
||||
last_frame = min(Global.frames.size() - 1, tag.to - 1)
|
||||
last_frame = min(Global.current_project.frames.size() - 1, tag.to - 1)
|
||||
|
||||
if first_frame == last_frame:
|
||||
if forward_dir:
|
||||
|
@ -288,21 +289,21 @@ func play_animation(play : bool, forward_dir : bool) -> void:
|
|||
|
||||
|
||||
func _on_NextFrame_pressed() -> void:
|
||||
if Global.current_frame < Global.frames.size() - 1:
|
||||
Global.current_frame += 1
|
||||
if Global.current_project.current_frame < Global.current_project.frames.size() - 1:
|
||||
Global.current_project.current_frame += 1
|
||||
|
||||
|
||||
func _on_PreviousFrame_pressed() -> void:
|
||||
if Global.current_frame > 0:
|
||||
Global.current_frame -= 1
|
||||
if Global.current_project.current_frame > 0:
|
||||
Global.current_project.current_frame -= 1
|
||||
|
||||
|
||||
func _on_LastFrame_pressed() -> void:
|
||||
Global.current_frame = Global.frames.size() - 1
|
||||
Global.current_project.current_frame = Global.current_project.frames.size() - 1
|
||||
|
||||
|
||||
func _on_FirstFrame_pressed() -> void:
|
||||
Global.current_frame = 0
|
||||
Global.current_project.current_frame = 0
|
||||
|
||||
|
||||
func _on_FPSValue_value_changed(value : float) -> void:
|
||||
|
@ -328,142 +329,142 @@ func _on_BlueRedMode_toggled(button_pressed : bool) -> void:
|
|||
# Layer buttons
|
||||
|
||||
func add_layer(is_new := true) -> void:
|
||||
var new_layers : Array = Global.layers.duplicate()
|
||||
var new_layers : Array = Global.current_project.layers.duplicate()
|
||||
var l := Layer.new()
|
||||
if !is_new: # Clone layer
|
||||
l.name = Global.layers[Global.current_layer].name + " (" + tr("copy") + ")"
|
||||
l.name = Global.current_project.layers[Global.current_project.current_layer].name + " (" + tr("copy") + ")"
|
||||
new_layers.append(l)
|
||||
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Add Layer")
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Add Layer")
|
||||
|
||||
for f in Global.frames:
|
||||
for f in Global.current_project.frames:
|
||||
var new_layer := Image.new()
|
||||
if is_new:
|
||||
new_layer.create(Global.canvas.size.x, Global.canvas.size.y, false, Image.FORMAT_RGBA8)
|
||||
else: # Clone layer
|
||||
new_layer.copy_from(f.cels[Global.current_layer].image)
|
||||
new_layer.copy_from(f.cels[Global.current_project.current_layer].image)
|
||||
|
||||
new_layer.lock()
|
||||
|
||||
var new_cels : Array = f.cels.duplicate()
|
||||
new_cels.append(Cel.new(new_layer, 1))
|
||||
Global.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
|
||||
Global.undo_redo.add_do_property(Global, "current_layer", Global.current_layer + 1)
|
||||
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
||||
Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer)
|
||||
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer + 1)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
||||
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func _on_RemoveLayer_pressed() -> void:
|
||||
var new_layers : Array = Global.layers.duplicate()
|
||||
new_layers.remove(Global.current_layer)
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Remove Layer")
|
||||
if Global.current_layer > 0:
|
||||
Global.undo_redo.add_do_property(Global, "current_layer", Global.current_layer - 1)
|
||||
var new_layers : Array = Global.current_project.layers.duplicate()
|
||||
new_layers.remove(Global.current_project.current_layer)
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Remove Layer")
|
||||
if Global.current_project.current_layer > 0:
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer - 1)
|
||||
else:
|
||||
Global.undo_redo.add_do_property(Global, "current_layer", Global.current_layer)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
||||
|
||||
for f in Global.frames:
|
||||
for f in Global.current_project.frames:
|
||||
var new_cels : Array = f.cels.duplicate()
|
||||
new_cels.remove(Global.current_layer)
|
||||
Global.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
new_cels.remove(Global.current_project.current_layer)
|
||||
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
|
||||
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
||||
Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer)
|
||||
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func change_layer_order(rate : int) -> void:
|
||||
var change = Global.current_layer + rate
|
||||
var change = Global.current_project.current_layer + rate
|
||||
|
||||
var new_layers : Array = Global.layers.duplicate()
|
||||
var temp = new_layers[Global.current_layer]
|
||||
new_layers[Global.current_layer] = new_layers[change]
|
||||
var new_layers : Array = Global.current_project.layers.duplicate()
|
||||
var temp = new_layers[Global.current_project.current_layer]
|
||||
new_layers[Global.current_project.current_layer] = new_layers[change]
|
||||
new_layers[change] = temp
|
||||
Global.undo_redo.create_action("Change Layer Order")
|
||||
for f in Global.frames:
|
||||
Global.current_project.undo_redo.create_action("Change Layer Order")
|
||||
for f in Global.current_project.frames:
|
||||
var new_cels : Array = f.cels.duplicate()
|
||||
var temp_canvas = new_cels[Global.current_layer]
|
||||
new_cels[Global.current_layer] = new_cels[change]
|
||||
var temp_canvas = new_cels[Global.current_project.current_layer]
|
||||
new_cels[Global.current_project.current_layer] = new_cels[change]
|
||||
new_cels[change] = temp_canvas
|
||||
Global.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
|
||||
Global.undo_redo.add_do_property(Global, "current_layer", change)
|
||||
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
||||
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
||||
Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", change)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
||||
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func _on_MergeDownLayer_pressed() -> void:
|
||||
var new_layers : Array = Global.layers.duplicate()
|
||||
var new_layers : Array = Global.current_project.layers.duplicate()
|
||||
# Loop through the array to create new classes for each element, so that they
|
||||
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
|
||||
for i in new_layers.size():
|
||||
var new_linked_cels = new_layers[i].linked_cels.duplicate()
|
||||
new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels)
|
||||
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Merge Layer")
|
||||
for f in Global.frames:
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Merge Layer")
|
||||
for f in Global.current_project.frames:
|
||||
var new_cels : Array = f.cels.duplicate()
|
||||
for i in new_cels.size():
|
||||
new_cels[i] = Cel.new(new_cels[i].image, new_cels[i].opacity)
|
||||
var selected_layer := Image.new()
|
||||
selected_layer.copy_from(new_cels[Global.current_layer].image)
|
||||
selected_layer.copy_from(new_cels[Global.current_project.current_layer].image)
|
||||
selected_layer.lock()
|
||||
|
||||
if f.cels[Global.current_layer].opacity < 1: # If we have layer transparency
|
||||
if f.cels[Global.current_project.current_layer].opacity < 1: # If we have layer transparency
|
||||
for xx in selected_layer.get_size().x:
|
||||
for yy in selected_layer.get_size().y:
|
||||
var pixel_color : Color = selected_layer.get_pixel(xx, yy)
|
||||
var alpha : float = pixel_color.a * f.cels[Global.current_layer].opacity
|
||||
var alpha : float = pixel_color.a * f.cels[Global.current_project.current_layer].opacity
|
||||
selected_layer.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
||||
|
||||
var new_layer := Image.new()
|
||||
new_layer.copy_from(f.cels[Global.current_layer - 1].image)
|
||||
new_layer.copy_from(f.cels[Global.current_project.current_layer - 1].image)
|
||||
new_layer.lock()
|
||||
DrawingAlgos.blend_rect(new_layer, selected_layer, Rect2(Global.canvas.location, Global.canvas.size), Vector2.ZERO)
|
||||
new_cels.remove(Global.current_layer)
|
||||
if !selected_layer.is_invisible() and Global.layers[Global.current_layer - 1].linked_cels.size() > 1 and (f in Global.layers[Global.current_layer - 1].linked_cels):
|
||||
new_layers[Global.current_layer - 1].linked_cels.erase(f)
|
||||
new_cels[Global.current_layer - 1].image = new_layer
|
||||
new_cels.remove(Global.current_project.current_layer)
|
||||
if !selected_layer.is_invisible() and Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels.size() > 1 and (f in Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels):
|
||||
new_layers[Global.current_project.current_layer - 1].linked_cels.erase(f)
|
||||
new_cels[Global.current_project.current_layer - 1].image = new_layer
|
||||
else:
|
||||
Global.undo_redo.add_do_property(f.cels[Global.current_layer - 1].image, "data", new_layer.data)
|
||||
Global.undo_redo.add_undo_property(f.cels[Global.current_layer - 1].image, "data", f.cels[Global.current_layer - 1].image.data)
|
||||
Global.current_project.undo_redo.add_do_property(f.cels[Global.current_project.current_layer - 1].image, "data", new_layer.data)
|
||||
Global.current_project.undo_redo.add_undo_property(f.cels[Global.current_project.current_layer - 1].image, "data", f.cels[Global.current_project.current_layer - 1].image.data)
|
||||
|
||||
Global.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
|
||||
new_layers.remove(Global.current_layer)
|
||||
Global.undo_redo.add_do_property(Global, "current_layer", Global.current_layer - 1)
|
||||
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
||||
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
||||
Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer)
|
||||
new_layers.remove(Global.current_project.current_layer)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer - 1)
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
||||
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func _on_OpacitySlider_value_changed(value) -> void:
|
||||
Global.frames[Global.current_frame].cels[Global.current_layer].opacity = value / 100
|
||||
Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].opacity = value / 100
|
||||
Global.layer_opacity_slider.value = value
|
||||
Global.layer_opacity_slider.value = value
|
||||
Global.layer_opacity_spinbox.value = value
|
||||
|
|
|
@ -8,7 +8,7 @@ onready var popup_menu : PopupMenu = $PopupMenu
|
|||
|
||||
func _ready() -> void:
|
||||
hint_tooltip = "Frame: %s, Layer: %s" % [frame + 1, layer]
|
||||
if Global.frames[frame] in Global.layers[layer].linked_cels:
|
||||
if Global.current_project.frames[frame] in Global.current_project.layers[layer].linked_cels:
|
||||
get_node("LinkedIndicator").visible = true
|
||||
popup_menu.set_item_text(4, "Unlink Cel")
|
||||
popup_menu.set_item_metadata(4, "Unlink Cel")
|
||||
|
@ -20,10 +20,10 @@ func _ready() -> void:
|
|||
|
||||
func _on_CelButton_pressed() -> void:
|
||||
if Input.is_action_just_released("left_mouse"):
|
||||
Global.current_frame = frame
|
||||
Global.current_layer = layer
|
||||
Global.current_project.current_frame = frame
|
||||
Global.current_project.current_layer = layer
|
||||
elif Input.is_action_just_released("right_mouse"):
|
||||
if Global.frames.size() == 1:
|
||||
if Global.current_project.frames.size() == 1:
|
||||
popup_menu.set_item_disabled(0, true)
|
||||
popup_menu.set_item_disabled(2, true)
|
||||
popup_menu.set_item_disabled(3, true)
|
||||
|
@ -31,7 +31,7 @@ func _on_CelButton_pressed() -> void:
|
|||
popup_menu.set_item_disabled(0, false)
|
||||
if frame > 0:
|
||||
popup_menu.set_item_disabled(2, false)
|
||||
if frame < Global.frames.size() - 1:
|
||||
if frame < Global.current_project.frames.size() - 1:
|
||||
popup_menu.set_item_disabled(3, false)
|
||||
popup_menu.popup(Rect2(get_global_mouse_position(), Vector2.ONE))
|
||||
pressed = !pressed
|
||||
|
@ -53,9 +53,9 @@ func _on_PopupMenu_id_pressed(ID : int) -> void:
|
|||
3: # Move Right
|
||||
change_frame_order(1)
|
||||
4: # Unlink Cel
|
||||
var cel_index : int = Global.layers[layer].linked_cels.find(Global.frames[frame])
|
||||
var f = Global.frames[frame]
|
||||
var new_layers : Array = Global.layers.duplicate()
|
||||
var cel_index : int = Global.current_project.layers[layer].linked_cels.find(Global.current_project.frames[frame])
|
||||
var f = Global.current_project.frames[frame]
|
||||
var new_layers : Array = Global.current_project.layers.duplicate()
|
||||
# Loop through the array to create new classes for each element, so that they
|
||||
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
|
||||
for i in new_layers.size():
|
||||
|
@ -68,53 +68,53 @@ func _on_PopupMenu_id_pressed(ID : int) -> void:
|
|||
if popup_menu.get_item_metadata(4) == "Unlink Cel":
|
||||
new_layers[layer].linked_cels.remove(cel_index)
|
||||
var sprite := Image.new()
|
||||
sprite.copy_from(Global.frames[frame].cels[layer].image)
|
||||
sprite.copy_from(Global.current_project.frames[frame].cels[layer].image)
|
||||
sprite.lock()
|
||||
new_cels[layer].image = sprite
|
||||
|
||||
Global.undo_redo.create_action("Unlink Cel")
|
||||
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
||||
Global.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
||||
Global.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
Global.current_project.undo_redo.create_action("Unlink Cel")
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
||||
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
||||
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
elif popup_menu.get_item_metadata(4) == "Link Cel":
|
||||
new_layers[layer].linked_cels.append(Global.frames[frame])
|
||||
Global.undo_redo.create_action("Link Cel")
|
||||
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
||||
new_layers[layer].linked_cels.append(Global.current_project.frames[frame])
|
||||
Global.current_project.undo_redo.create_action("Link Cel")
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
||||
if new_layers[layer].linked_cels.size() > 1:
|
||||
# If there are already linked cels, set the current cel's image
|
||||
# to the first linked cel's image
|
||||
new_cels[layer].image = new_layers[layer].linked_cels[0].cels[layer].image
|
||||
new_cels[layer].image_texture = new_layers[layer].linked_cels[0].cels[layer].image_texture
|
||||
Global.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
||||
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
||||
|
||||
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func change_frame_order(rate : int) -> void:
|
||||
var change = frame + rate
|
||||
var new_frames : Array = Global.frames.duplicate()
|
||||
var new_frames : Array = Global.current_project.frames.duplicate()
|
||||
var temp = new_frames[frame]
|
||||
new_frames[frame] = new_frames[change]
|
||||
new_frames[change] = temp
|
||||
|
||||
Global.undo_redo.create_action("Change Frame Order")
|
||||
Global.undo_redo.add_do_property(Global, "frames", new_frames)
|
||||
Global.current_project.undo_redo.create_action("Change Frame Order")
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
||||
|
||||
if Global.current_frame == frame:
|
||||
Global.undo_redo.add_do_property(Global, "current_frame", change)
|
||||
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
|
||||
if Global.current_project.current_frame == frame:
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", change)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
|
||||
|
||||
Global.undo_redo.add_undo_property(Global, "frames", Global.frames)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
|
||||
|
||||
Global.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.undo_redo.add_do_method(Global, "redo")
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
|
|
@ -21,7 +21,7 @@ func _on_FrameTagDialog_about_to_show() -> void:
|
|||
tag_vboxes.clear()
|
||||
|
||||
var i := 0
|
||||
for tag in Global.animation_tags:
|
||||
for tag in Global.current_project.animation_tags:
|
||||
var vbox_cont := VBoxContainer.new()
|
||||
var hbox_cont := HBoxContainer.new()
|
||||
var tag_label := Label.new()
|
||||
|
@ -62,18 +62,18 @@ func _on_FrameTagDialog_popup_hide() -> void:
|
|||
|
||||
func _on_AddTag_pressed() -> void:
|
||||
options_dialog.popup_centered()
|
||||
current_tag_id = Global.animation_tags.size()
|
||||
options_dialog.get_node("GridContainer/FromSpinBox").value = Global.current_frame + 1
|
||||
options_dialog.get_node("GridContainer/ToSpinBox").value = Global.current_frame + 1
|
||||
current_tag_id = Global.current_project.animation_tags.size()
|
||||
options_dialog.get_node("GridContainer/FromSpinBox").value = Global.current_project.current_frame + 1
|
||||
options_dialog.get_node("GridContainer/ToSpinBox").value = Global.current_project.current_frame + 1
|
||||
|
||||
|
||||
func _on_EditButton_pressed(_tag_id : int) -> void:
|
||||
options_dialog.popup_centered()
|
||||
current_tag_id = _tag_id
|
||||
options_dialog.get_node("GridContainer/NameLineEdit").text = Global.animation_tags[_tag_id].name
|
||||
options_dialog.get_node("GridContainer/ColorPickerButton").color = Global.animation_tags[_tag_id].color
|
||||
options_dialog.get_node("GridContainer/FromSpinBox").value = Global.animation_tags[_tag_id].from
|
||||
options_dialog.get_node("GridContainer/ToSpinBox").value = Global.animation_tags[_tag_id].to
|
||||
options_dialog.get_node("GridContainer/NameLineEdit").text = Global.current_project.animation_tags[_tag_id].name
|
||||
options_dialog.get_node("GridContainer/ColorPickerButton").color = Global.current_project.animation_tags[_tag_id].color
|
||||
options_dialog.get_node("GridContainer/FromSpinBox").value = Global.current_project.animation_tags[_tag_id].from
|
||||
options_dialog.get_node("GridContainer/ToSpinBox").value = Global.current_project.animation_tags[_tag_id].to
|
||||
if !delete_tag_button:
|
||||
delete_tag_button = options_dialog.add_button("Delete Tag", true, "delete_tag")
|
||||
else:
|
||||
|
@ -86,19 +86,19 @@ func _on_TagOptions_confirmed() -> void:
|
|||
var tag_from : int = options_dialog.get_node("GridContainer/FromSpinBox").value
|
||||
var tag_to : int = options_dialog.get_node("GridContainer/ToSpinBox").value
|
||||
|
||||
if tag_to > Global.frames.size():
|
||||
tag_to = Global.frames.size()
|
||||
if tag_to > Global.current_project.frames.size():
|
||||
tag_to = Global.current_project.frames.size()
|
||||
|
||||
if tag_from > tag_to:
|
||||
tag_from = tag_to
|
||||
|
||||
var new_animation_tags := Global.animation_tags.duplicate()
|
||||
var new_animation_tags := Global.current_project.animation_tags.duplicate()
|
||||
# Loop through the tags to create new classes for them, so that they won't be the same
|
||||
# as Global.animation_tags's classes. Needed for undo/redo to work properly.
|
||||
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
|
||||
for i in new_animation_tags.size():
|
||||
new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to)
|
||||
|
||||
if current_tag_id == Global.animation_tags.size():
|
||||
if current_tag_id == Global.current_project.animation_tags.size():
|
||||
new_animation_tags.append(AnimationTag.new(tag_name, tag_color, tag_from, tag_to))
|
||||
else:
|
||||
new_animation_tags[current_tag_id].name = tag_name
|
||||
|
@ -107,28 +107,28 @@ func _on_TagOptions_confirmed() -> void:
|
|||
new_animation_tags[current_tag_id].to = tag_to
|
||||
|
||||
# Handle Undo/Redo
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Modify Frame Tag")
|
||||
Global.undo_redo.add_do_method(Global, "general_redo")
|
||||
Global.undo_redo.add_undo_method(Global, "general_undo")
|
||||
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
|
||||
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Modify Frame Tag")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "general_redo")
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "general_undo")
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
_on_FrameTagDialog_about_to_show()
|
||||
|
||||
|
||||
func _on_TagOptions_custom_action(action : String) -> void:
|
||||
if action == "delete_tag":
|
||||
var new_animation_tags := Global.animation_tags.duplicate()
|
||||
var new_animation_tags := Global.current_project.animation_tags.duplicate()
|
||||
new_animation_tags.remove(current_tag_id)
|
||||
# Handle Undo/Redo
|
||||
Global.undos += 1
|
||||
Global.undo_redo.create_action("Delete Frame Tag")
|
||||
Global.undo_redo.add_do_method(Global, "general_redo")
|
||||
Global.undo_redo.add_undo_method(Global, "general_undo")
|
||||
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
|
||||
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
|
||||
Global.undo_redo.commit_action()
|
||||
Global.current_project.undos += 1
|
||||
Global.current_project.undo_redo.create_action("Delete Frame Tag")
|
||||
Global.current_project.undo_redo.add_do_method(Global, "general_redo")
|
||||
Global.current_project.undo_redo.add_undo_method(Global, "general_undo")
|
||||
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
|
||||
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
|
||||
Global.current_project.undo_redo.commit_action()
|
||||
|
||||
options_dialog.hide()
|
||||
_on_FrameTagDialog_about_to_show()
|
||||
|
|
|
@ -16,7 +16,7 @@ func _ready() -> void:
|
|||
label = Global.find_node_by_name(self, "Label")
|
||||
line_edit = Global.find_node_by_name(self, "LineEdit")
|
||||
|
||||
if Global.layers[i].visible:
|
||||
if Global.current_project.layers[i].visible:
|
||||
Global.change_button_texturerect(visibility_button.get_child(0), "layer_visible.png")
|
||||
visibility_button.get_child(0).rect_size = Vector2(24, 14)
|
||||
visibility_button.get_child(0).rect_position = Vector2(4, 9)
|
||||
|
@ -25,12 +25,12 @@ func _ready() -> void:
|
|||
visibility_button.get_child(0).rect_size = Vector2(24, 8)
|
||||
visibility_button.get_child(0).rect_position = Vector2(4, 12)
|
||||
|
||||
if Global.layers[i].locked:
|
||||
if Global.current_project.layers[i].locked:
|
||||
Global.change_button_texturerect(lock_button.get_child(0), "lock.png")
|
||||
else:
|
||||
Global.change_button_texturerect(lock_button.get_child(0), "unlock.png")
|
||||
|
||||
if Global.layers[i].new_cels_linked: # If new layers will be linked
|
||||
if Global.current_project.layers[i].new_cels_linked: # If new layers will be linked
|
||||
Global.change_button_texturerect(linked_button.get_child(0), "linked_layer.png")
|
||||
else:
|
||||
Global.change_button_texturerect(linked_button.get_child(0), "unlinked_layer.png")
|
||||
|
@ -59,21 +59,21 @@ func save_layer_name(new_name : String) -> void:
|
|||
line_edit.editable = false
|
||||
label.text = new_name
|
||||
Global.layers_changed_skip = true
|
||||
Global.layers[i].name = new_name
|
||||
Global.current_project.layers[i].name = new_name
|
||||
|
||||
|
||||
func _on_VisibilityButton_pressed() -> void:
|
||||
Global.layers[i].visible = !Global.layers[i].visible
|
||||
Global.current_project.layers[i].visible = !Global.current_project.layers[i].visible
|
||||
Global.canvas.update()
|
||||
|
||||
|
||||
func _on_LockButton_pressed() -> void:
|
||||
Global.layers[i].locked = !Global.layers[i].locked
|
||||
Global.current_project.layers[i].locked = !Global.current_project.layers[i].locked
|
||||
|
||||
|
||||
func _on_LinkButton_pressed() -> void:
|
||||
Global.layers[i].new_cels_linked = !Global.layers[i].new_cels_linked
|
||||
if Global.layers[i].new_cels_linked && !Global.layers[i].linked_cels:
|
||||
Global.current_project.layers[i].new_cels_linked = !Global.current_project.layers[i].new_cels_linked
|
||||
if Global.current_project.layers[i].new_cels_linked && !Global.current_project.layers[i].linked_cels:
|
||||
# If button is pressed and there are no linked cels in the layer
|
||||
Global.layers[i].linked_cels.append(Global.frames[Global.current_frame])
|
||||
Global.layers[i].frame_container.get_child(Global.current_frame)._ready()
|
||||
Global.current_project.layers[i].linked_cels.append(Global.current_project.frames[Global.current_project.current_frame])
|
||||
Global.current_project.layers[i].frame_container.get_child(Global.current_project.current_frame)._ready()
|
||||
|
|
Loading…
Add table
Reference in a new issue