2020-06-04 18:05:36 +00:00
|
|
|
|
class_name Project extends Reference
|
|
|
|
|
# A class for project properties.
|
|
|
|
|
|
|
|
|
|
|
2020-06-05 17:15:40 +00:00
|
|
|
|
var name := "" setget name_changed
|
2020-07-20 19:15:34 +00:00
|
|
|
|
var size : Vector2 setget size_changed
|
2020-06-04 18:05:36 +00:00
|
|
|
|
var undo_redo : UndoRedo
|
2021-01-20 14:59:42 +00:00
|
|
|
|
var tile_mode : int = Global.TileMode.NONE
|
2021-01-28 19:21:48 +00:00
|
|
|
|
var tile_mode_rects := [] # Cached to avoid recalculation
|
2020-06-04 18:05:36 +00:00
|
|
|
|
var undos := 0 # The number of times we added undo properties
|
2020-06-05 17:15:40 +00:00
|
|
|
|
var has_changed := false setget has_changed_changed
|
2020-06-04 18:05:36 +00:00
|
|
|
|
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
|
2020-06-05 13:21:19 +00:00
|
|
|
|
var guides := [] # Array of Guides
|
2020-06-04 18:05:36 +00:00
|
|
|
|
var brushes := [] # Array of Images
|
2020-12-17 00:20:47 +00:00
|
|
|
|
var fps := 6.0
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
2020-07-20 19:15:34 +00:00
|
|
|
|
var x_symmetry_point
|
|
|
|
|
var y_symmetry_point
|
2020-07-16 01:25:59 +00:00
|
|
|
|
var x_symmetry_axis : SymmetryGuide
|
|
|
|
|
var y_symmetry_axis : SymmetryGuide
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
2020-07-20 19:15:34 +00:00
|
|
|
|
var selected_pixels := []
|
2020-07-09 12:22:17 +00:00
|
|
|
|
var selected_rect := Rect2(0, 0, 0, 0) setget _set_selected_rect
|
|
|
|
|
|
2020-06-05 18:03:34 +00:00
|
|
|
|
# For every camera (currently there are 3)
|
|
|
|
|
var cameras_zoom := [Vector2(0.15, 0.15), Vector2(0.15, 0.15), Vector2(0.15, 0.15)] # Array of Vector2
|
|
|
|
|
var cameras_offset := [Vector2.ZERO, Vector2.ZERO, Vector2.ZERO] # Array of Vector2
|
|
|
|
|
|
2020-08-28 15:05:49 +00:00
|
|
|
|
# Export directory path and export file name
|
|
|
|
|
var directory_path := ""
|
|
|
|
|
var file_name := "untitled"
|
|
|
|
|
var file_format : int = Export.FileFormat.PNG
|
2020-10-24 21:58:37 +00:00
|
|
|
|
var was_exported := false
|
2020-08-28 15:05:49 +00:00
|
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
2020-07-20 19:15:34 +00:00
|
|
|
|
func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> void:
|
2020-06-05 01:30:31 +00:00
|
|
|
|
frames = _frames
|
2020-06-04 20:20:20 +00:00
|
|
|
|
name = _name
|
2020-07-20 19:15:34 +00:00
|
|
|
|
size = _size
|
2021-01-28 19:21:48 +00:00
|
|
|
|
update_tile_mode_rects()
|
2020-07-20 19:15:34 +00:00
|
|
|
|
|
2020-06-04 20:20:20 +00:00
|
|
|
|
undo_redo = UndoRedo.new()
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
2020-06-04 23:48:38 +00:00
|
|
|
|
Global.tabs.add_tab(name)
|
2020-06-05 23:16:53 +00:00
|
|
|
|
OpenSave.current_save_paths.append("")
|
|
|
|
|
OpenSave.backup_save_paths.append("")
|
2020-06-04 23:48:38 +00:00
|
|
|
|
|
2020-07-22 12:07:02 +00:00
|
|
|
|
x_symmetry_point = size.x / 2
|
|
|
|
|
y_symmetry_point = size.y / 2
|
2020-07-20 19:15:34 +00:00
|
|
|
|
|
2020-07-16 01:25:59 +00:00
|
|
|
|
if !x_symmetry_axis:
|
|
|
|
|
x_symmetry_axis = SymmetryGuide.new()
|
|
|
|
|
x_symmetry_axis.type = x_symmetry_axis.Types.HORIZONTAL
|
|
|
|
|
x_symmetry_axis.project = self
|
|
|
|
|
x_symmetry_axis.add_point(Vector2(-19999, y_symmetry_point))
|
|
|
|
|
x_symmetry_axis.add_point(Vector2(19999, y_symmetry_point))
|
|
|
|
|
Global.canvas.add_child(x_symmetry_axis)
|
|
|
|
|
|
|
|
|
|
if !y_symmetry_axis:
|
|
|
|
|
y_symmetry_axis = SymmetryGuide.new()
|
|
|
|
|
y_symmetry_axis.type = y_symmetry_axis.Types.VERTICAL
|
|
|
|
|
y_symmetry_axis.project = self
|
|
|
|
|
y_symmetry_axis.add_point(Vector2(x_symmetry_point, -19999))
|
|
|
|
|
y_symmetry_axis.add_point(Vector2(x_symmetry_point, 19999))
|
|
|
|
|
Global.canvas.add_child(y_symmetry_axis)
|
|
|
|
|
|
2020-08-28 15:05:49 +00:00
|
|
|
|
if OS.get_name() == "HTML5":
|
|
|
|
|
directory_path = "user://"
|
|
|
|
|
else:
|
|
|
|
|
directory_path = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)
|
|
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
2020-07-20 19:15:34 +00:00
|
|
|
|
func select_all_pixels() -> void:
|
|
|
|
|
clear_selection()
|
|
|
|
|
for x in size.x:
|
|
|
|
|
for y in size.y:
|
|
|
|
|
selected_pixels.append(Vector2(x, y))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func clear_selection() -> void:
|
|
|
|
|
selected_pixels.clear()
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 12:22:17 +00:00
|
|
|
|
func _set_selected_rect(value : Rect2) -> void:
|
|
|
|
|
selected_rect = value
|
|
|
|
|
Global.selection_rectangle.set_rect(value)
|
|
|
|
|
|
|
|
|
|
|
2020-06-05 01:30:31 +00:00
|
|
|
|
func change_project() -> void:
|
|
|
|
|
# Remove old nodes
|
|
|
|
|
for container in Global.layers_container.get_children():
|
|
|
|
|
container.queue_free()
|
|
|
|
|
|
|
|
|
|
remove_cel_buttons()
|
|
|
|
|
|
|
|
|
|
for frame_id in Global.frame_ids.get_children():
|
|
|
|
|
Global.frame_ids.remove_child(frame_id)
|
|
|
|
|
frame_id.queue_free()
|
|
|
|
|
|
|
|
|
|
# Create new ones
|
|
|
|
|
for i in range(layers.size() - 1, -1, -1):
|
|
|
|
|
# Create layer buttons
|
|
|
|
|
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()): # Create Cel buttons
|
|
|
|
|
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
|
|
|
|
|
if j == current_frame and i == current_layer:
|
|
|
|
|
cel_button.pressed = true
|
|
|
|
|
|
|
|
|
|
layers[i].frame_container.add_child(cel_button)
|
|
|
|
|
|
|
|
|
|
for j in range(frames.size()): # Create frame ID labels
|
|
|
|
|
var label := Label.new()
|
2021-01-30 21:57:33 +00:00
|
|
|
|
label.rect_min_size.x = Global.animation_timeline.cel_size
|
2020-06-05 01:30:31 +00:00
|
|
|
|
label.align = Label.ALIGN_CENTER
|
|
|
|
|
label.text = str(j + 1)
|
|
|
|
|
if j == current_frame:
|
|
|
|
|
label.add_color_override("font_color", Global.control.theme.get_color("Selected Color", "Label"))
|
|
|
|
|
Global.frame_ids.add_child(label)
|
|
|
|
|
|
|
|
|
|
var layer_button = Global.layers_container.get_child(Global.layers_container.get_child_count() - 1 - current_layer)
|
|
|
|
|
layer_button.pressed = true
|
|
|
|
|
|
|
|
|
|
Global.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
|
|
|
|
|
|
|
|
|
|
Global.disable_button(Global.remove_frame_button, frames.size() == 1)
|
2020-10-04 23:37:55 +00:00
|
|
|
|
Global.disable_button(Global.move_left_frame_button, frames.size() == 1 or current_frame == 0)
|
|
|
|
|
Global.disable_button(Global.move_right_frame_button, frames.size() == 1 or current_frame == frames.size() - 1)
|
2020-06-05 01:30:31 +00:00
|
|
|
|
toggle_layer_buttons_layers()
|
|
|
|
|
toggle_layer_buttons_current_layer()
|
|
|
|
|
|
|
|
|
|
self.animation_tags = animation_tags
|
|
|
|
|
|
2020-06-05 13:21:19 +00:00
|
|
|
|
# Change the selection rectangle
|
2020-07-09 12:22:17 +00:00
|
|
|
|
Global.selection_rectangle.set_rect(selected_rect)
|
2020-06-05 13:14:57 +00:00
|
|
|
|
|
2020-06-05 14:21:35 +00:00
|
|
|
|
# Change the guides
|
2020-06-05 13:21:19 +00:00
|
|
|
|
for guide in Global.canvas.get_children():
|
|
|
|
|
if guide is Guide:
|
|
|
|
|
if guide in guides:
|
2020-07-16 02:05:40 +00:00
|
|
|
|
guide.visible = Global.show_guides
|
|
|
|
|
if guide is SymmetryGuide:
|
|
|
|
|
if guide.type == Guide.Types.HORIZONTAL:
|
|
|
|
|
guide.visible = Global.show_x_symmetry_axis and Global.show_guides
|
|
|
|
|
else:
|
|
|
|
|
guide.visible = Global.show_y_symmetry_axis and Global.show_guides
|
2020-06-05 13:21:19 +00:00
|
|
|
|
else:
|
|
|
|
|
guide.visible = false
|
|
|
|
|
|
2020-06-05 14:21:35 +00:00
|
|
|
|
# Change the project brushes
|
2020-07-09 12:22:17 +00:00
|
|
|
|
Brushes.clear_project_brush()
|
2020-06-05 14:21:35 +00:00
|
|
|
|
for brush in brushes:
|
2020-07-09 12:22:17 +00:00
|
|
|
|
Brushes.add_project_brush(brush)
|
2020-06-05 14:21:35 +00:00
|
|
|
|
|
2020-06-05 18:03:34 +00:00
|
|
|
|
var cameras = [Global.camera, Global.camera2, Global.camera_preview]
|
|
|
|
|
var i := 0
|
|
|
|
|
for camera in cameras:
|
|
|
|
|
camera.zoom = cameras_zoom[i]
|
|
|
|
|
camera.offset = cameras_offset[i]
|
|
|
|
|
i += 1
|
|
|
|
|
Global.zoom_level_label.text = str(round(100 / Global.camera.zoom.x)) + " %"
|
2020-06-05 14:50:52 +00:00
|
|
|
|
Global.canvas.update()
|
2020-08-17 19:54:33 +00:00
|
|
|
|
Global.canvas.grid.update()
|
2021-01-16 18:24:46 +00:00
|
|
|
|
Global.canvas.pixel_grid.update()
|
2020-06-05 15:19:05 +00:00
|
|
|
|
Global.transparent_checker._ready()
|
2020-12-17 00:20:47 +00:00
|
|
|
|
Global.animation_timeline.fps_spinbox.value = fps
|
2020-06-05 23:16:53 +00:00
|
|
|
|
Global.horizontal_ruler.update()
|
|
|
|
|
Global.vertical_ruler.update()
|
2020-08-01 21:59:00 +00:00
|
|
|
|
Global.preview_zoom_slider.value = -Global.camera_preview.zoom.x
|
2020-09-14 14:51:35 +00:00
|
|
|
|
Global.cursor_position_label.text = "[%s×%s]" % [size.x, size.y]
|
2020-08-01 21:59:00 +00:00
|
|
|
|
|
2020-06-05 17:15:40 +00:00
|
|
|
|
Global.window_title = "%s - Pixelorama %s" % [name, Global.current_version]
|
|
|
|
|
if has_changed:
|
|
|
|
|
Global.window_title = Global.window_title + "(*)"
|
|
|
|
|
|
2020-06-09 17:19:55 +00:00
|
|
|
|
var save_path = OpenSave.current_save_paths[Global.current_project_index]
|
|
|
|
|
if save_path != "":
|
|
|
|
|
Global.open_sprites_dialog.current_path = save_path
|
|
|
|
|
Global.save_sprites_dialog.current_path = save_path
|
2020-10-29 20:33:15 +00:00
|
|
|
|
Global.file_menu.get_popup().set_item_text(4, tr("Save") + " %s" % save_path.get_file())
|
2020-06-09 17:19:55 +00:00
|
|
|
|
else:
|
2020-10-29 20:33:15 +00:00
|
|
|
|
Global.file_menu.get_popup().set_item_text(4, tr("Save"))
|
2020-06-09 17:19:55 +00:00
|
|
|
|
|
2020-08-28 15:05:49 +00:00
|
|
|
|
Export.directory_path = directory_path
|
|
|
|
|
Export.file_name = file_name
|
|
|
|
|
Export.file_format = file_format
|
2020-10-24 21:58:37 +00:00
|
|
|
|
Export.was_exported = was_exported
|
2020-08-28 15:05:49 +00:00
|
|
|
|
|
2020-10-24 21:58:37 +00:00
|
|
|
|
if !was_exported:
|
2020-10-29 20:33:15 +00:00
|
|
|
|
Global.file_menu.get_popup().set_item_text(6, tr("Export"))
|
2020-08-28 15:05:49 +00:00
|
|
|
|
else:
|
2020-10-29 20:33:15 +00:00
|
|
|
|
Global.file_menu.get_popup().set_item_text(6, tr("Export") + " %s" % (file_name + Export.file_format_string(file_format)))
|
2020-08-28 15:05:49 +00:00
|
|
|
|
|
2021-01-20 14:59:42 +00:00
|
|
|
|
for j in Global.TileMode.values():
|
2021-01-16 18:24:46 +00:00
|
|
|
|
Global.tile_mode_submenu.set_item_checked(j, j == tile_mode)
|
2020-12-03 01:49:53 +00:00
|
|
|
|
|
|
|
|
|
|
2020-06-10 01:17:39 +00:00
|
|
|
|
func serialize() -> Dictionary:
|
|
|
|
|
var layer_data := []
|
|
|
|
|
for layer in layers:
|
|
|
|
|
var linked_cels := []
|
|
|
|
|
for cel in layer.linked_cels:
|
|
|
|
|
linked_cels.append(frames.find(cel))
|
|
|
|
|
|
|
|
|
|
layer_data.append({
|
|
|
|
|
"name" : layer.name,
|
|
|
|
|
"visible" : layer.visible,
|
|
|
|
|
"locked" : layer.locked,
|
|
|
|
|
"new_cels_linked" : layer.new_cels_linked,
|
|
|
|
|
"linked_cels" : linked_cels,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var tag_data := []
|
|
|
|
|
for tag in animation_tags:
|
|
|
|
|
tag_data.append({
|
|
|
|
|
"name" : tag.name,
|
|
|
|
|
"color" : tag.color.to_html(),
|
|
|
|
|
"from" : tag.from,
|
|
|
|
|
"to" : tag.to,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var guide_data := []
|
|
|
|
|
for guide in guides:
|
2020-07-16 01:25:59 +00:00
|
|
|
|
if guide is SymmetryGuide:
|
|
|
|
|
continue
|
2020-07-27 17:03:15 +00:00
|
|
|
|
if !is_instance_valid(guide):
|
|
|
|
|
continue
|
2020-06-10 01:17:39 +00:00
|
|
|
|
var coords = guide.points[0].x
|
|
|
|
|
if guide.type == Guide.Types.HORIZONTAL:
|
|
|
|
|
coords = guide.points[0].y
|
|
|
|
|
|
|
|
|
|
guide_data.append({"type" : guide.type, "pos" : coords})
|
|
|
|
|
|
|
|
|
|
var frame_data := []
|
|
|
|
|
for frame in frames:
|
|
|
|
|
var cel_data := []
|
|
|
|
|
for cel in frame.cels:
|
|
|
|
|
cel_data.append({
|
|
|
|
|
"opacity" : cel.opacity,
|
|
|
|
|
# "image_data" : cel.image.get_data()
|
|
|
|
|
})
|
|
|
|
|
frame_data.append({
|
2020-12-16 20:54:08 +00:00
|
|
|
|
"cels" : cel_data,
|
|
|
|
|
"duration" : frame.duration
|
2020-06-10 01:17:39 +00:00
|
|
|
|
})
|
|
|
|
|
var brush_data := []
|
|
|
|
|
for brush in brushes:
|
|
|
|
|
brush_data.append({
|
|
|
|
|
"size_x" : brush.get_size().x,
|
|
|
|
|
"size_y" : brush.get_size().y
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
var project_data := {
|
|
|
|
|
"pixelorama_version" : Global.current_version,
|
|
|
|
|
"name" : name,
|
|
|
|
|
"size_x" : size.x,
|
|
|
|
|
"size_y" : size.y,
|
|
|
|
|
"save_path" : OpenSave.current_save_paths[Global.projects.find(self)],
|
|
|
|
|
"layers" : layer_data,
|
|
|
|
|
"tags" : tag_data,
|
|
|
|
|
"guides" : guide_data,
|
2020-07-16 01:25:59 +00:00
|
|
|
|
"symmetry_points" : [x_symmetry_point, y_symmetry_point],
|
2020-06-10 01:17:39 +00:00
|
|
|
|
"frames" : frame_data,
|
|
|
|
|
"brushes" : brush_data,
|
2020-08-28 15:05:49 +00:00
|
|
|
|
"export_directory_path" : directory_path,
|
|
|
|
|
"export_file_name" : file_name,
|
|
|
|
|
"export_file_format" : file_format,
|
2020-12-17 00:20:47 +00:00
|
|
|
|
"fps" : fps
|
2020-06-10 01:17:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return project_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func deserialize(dict : Dictionary) -> void:
|
|
|
|
|
if dict.has("name"):
|
|
|
|
|
name = dict.name
|
2020-08-19 22:27:21 +00:00
|
|
|
|
if dict.has("size_x") and dict.has("size_y"):
|
2020-06-10 01:17:39 +00:00
|
|
|
|
size.x = dict.size_x
|
|
|
|
|
size.y = dict.size_y
|
2021-01-30 18:43:10 +00:00
|
|
|
|
update_tile_mode_rects()
|
2020-06-10 01:17:39 +00:00
|
|
|
|
if dict.has("save_path"):
|
|
|
|
|
OpenSave.current_save_paths[Global.projects.find(self)] = dict.save_path
|
|
|
|
|
if dict.has("frames"):
|
2020-12-16 20:54:08 +00:00
|
|
|
|
var frame_i := 0
|
2020-06-10 01:17:39 +00:00
|
|
|
|
for frame in dict.frames:
|
|
|
|
|
var cels := []
|
|
|
|
|
for cel in frame.cels:
|
|
|
|
|
cels.append(Cel.new(Image.new(), cel.opacity))
|
2020-12-16 20:54:08 +00:00
|
|
|
|
var duration := 1.0
|
|
|
|
|
if frame.has("duration"):
|
|
|
|
|
duration = frame.duration
|
|
|
|
|
elif dict.has("frame_duration"):
|
|
|
|
|
duration = dict.frame_duration[frame_i]
|
|
|
|
|
|
|
|
|
|
frames.append(Frame.new(cels, duration))
|
|
|
|
|
frame_i += 1
|
|
|
|
|
|
2020-06-10 01:17:39 +00:00
|
|
|
|
if dict.has("layers"):
|
|
|
|
|
var layer_i := 0
|
|
|
|
|
for saved_layer in dict.layers:
|
|
|
|
|
var linked_cels := []
|
|
|
|
|
for linked_cel_number in saved_layer.linked_cels:
|
|
|
|
|
linked_cels.append(frames[linked_cel_number])
|
|
|
|
|
frames[linked_cel_number].cels[layer_i].image = linked_cels[0].cels[layer_i].image
|
|
|
|
|
frames[linked_cel_number].cels[layer_i].image_texture = linked_cels[0].cels[layer_i].image_texture
|
|
|
|
|
var layer := Layer.new(saved_layer.name, saved_layer.visible, saved_layer.locked, HBoxContainer.new(), saved_layer.new_cels_linked, linked_cels)
|
|
|
|
|
layers.append(layer)
|
|
|
|
|
layer_i += 1
|
|
|
|
|
if dict.has("tags"):
|
|
|
|
|
for tag in dict.tags:
|
|
|
|
|
animation_tags.append(AnimationTag.new(tag.name, Color(tag.color), tag.from, tag.to))
|
|
|
|
|
self.animation_tags = animation_tags
|
|
|
|
|
if dict.has("guides"):
|
|
|
|
|
for g in dict.guides:
|
|
|
|
|
var guide := Guide.new()
|
|
|
|
|
guide.type = g.type
|
|
|
|
|
if guide.type == Guide.Types.HORIZONTAL:
|
|
|
|
|
guide.add_point(Vector2(-99999, g.pos))
|
|
|
|
|
guide.add_point(Vector2(99999, g.pos))
|
|
|
|
|
else:
|
|
|
|
|
guide.add_point(Vector2(g.pos, -99999))
|
|
|
|
|
guide.add_point(Vector2(g.pos, 99999))
|
|
|
|
|
guide.has_focus = false
|
2020-11-25 16:25:56 +00:00
|
|
|
|
guide.project = self
|
2020-06-10 01:17:39 +00:00
|
|
|
|
Global.canvas.add_child(guide)
|
2020-07-16 01:25:59 +00:00
|
|
|
|
if dict.has("symmetry_points"):
|
|
|
|
|
x_symmetry_point = dict.symmetry_points[0]
|
|
|
|
|
y_symmetry_point = dict.symmetry_points[1]
|
|
|
|
|
x_symmetry_axis.points[0].y = floor(y_symmetry_point / 2 + 1)
|
|
|
|
|
x_symmetry_axis.points[1].y = floor(y_symmetry_point / 2 + 1)
|
|
|
|
|
y_symmetry_axis.points[0].x = floor(x_symmetry_point / 2 + 1)
|
|
|
|
|
y_symmetry_axis.points[1].x = floor(x_symmetry_point / 2 + 1)
|
2020-08-28 15:05:49 +00:00
|
|
|
|
if dict.has("export_directory_path"):
|
|
|
|
|
directory_path = dict.export_directory_path
|
|
|
|
|
if dict.has("export_file_name"):
|
|
|
|
|
file_name = dict.export_file_name
|
|
|
|
|
if dict.has("export_file_format"):
|
|
|
|
|
file_format = dict.export_file_format
|
2020-12-17 00:20:47 +00:00
|
|
|
|
if dict.has("fps"):
|
|
|
|
|
fps = dict.fps
|
2020-06-10 01:17:39 +00:00
|
|
|
|
|
2020-11-14 13:24:24 +00:00
|
|
|
|
|
2020-06-05 17:15:40 +00:00
|
|
|
|
func name_changed(value : String) -> void:
|
|
|
|
|
name = value
|
|
|
|
|
Global.tabs.set_tab_title(Global.tabs.current_tab, name)
|
2020-06-05 14:50:52 +00:00
|
|
|
|
|
2020-06-05 01:30:31 +00:00
|
|
|
|
|
2020-07-20 19:15:34 +00:00
|
|
|
|
func size_changed(value : Vector2) -> void:
|
|
|
|
|
size = value
|
2021-01-28 19:21:48 +00:00
|
|
|
|
update_tile_mode_rects()
|
2021-01-31 13:09:54 +00:00
|
|
|
|
Global.selection_rectangle.set_rect(Global.selection_rectangle.get_rect())
|
2020-07-20 19:15:34 +00:00
|
|
|
|
|
|
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
|
func frames_changed(value : Array) -> void:
|
|
|
|
|
frames = value
|
2020-06-05 01:30:31 +00:00
|
|
|
|
remove_cel_buttons()
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
|
|
|
|
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()
|
2021-01-30 21:57:33 +00:00
|
|
|
|
label.rect_min_size.x = Global.animation_timeline.cel_size
|
2020-06-04 18:05:36 +00:00
|
|
|
|
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)
|
|
|
|
|
|
2020-06-05 13:06:59 +00:00
|
|
|
|
set_timeline_first_and_last_frames()
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
2020-06-05 01:30:31 +00:00
|
|
|
|
remove_cel_buttons()
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
|
|
|
|
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
|
2020-06-05 01:30:31 +00:00
|
|
|
|
toggle_layer_buttons_layers()
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
|
|
|
|
|
2020-06-05 01:30:31 +00:00
|
|
|
|
func remove_cel_buttons() -> void:
|
|
|
|
|
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)
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func frame_changed(value : int) -> void:
|
|
|
|
|
current_frame = value
|
|
|
|
|
Global.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
|
|
|
|
|
|
2020-06-05 01:30:31 +00:00
|
|
|
|
for i in frames.size():
|
2020-06-04 18:05:36 +00:00
|
|
|
|
var text_color := Color.white
|
2021-01-20 14:59:42 +00:00
|
|
|
|
if Global.theme_type == Global.ThemeTypes.CARAMEL || Global.theme_type == Global.ThemeTypes.LIGHT:
|
2020-06-04 18:05:36 +00:00
|
|
|
|
text_color = Color.black
|
|
|
|
|
Global.frame_ids.get_child(i).add_color_override("font_color", text_color)
|
2020-06-05 01:30:31 +00:00
|
|
|
|
for layer in layers: # De-select all the other frames
|
2020-06-04 18:05:36 +00:00
|
|
|
|
if i < layer.frame_container.get_child_count():
|
|
|
|
|
layer.frame_container.get_child(i).pressed = false
|
|
|
|
|
|
|
|
|
|
# Select the new frame
|
2020-06-05 16:51:06 +00:00
|
|
|
|
if current_frame < Global.frame_ids.get_child_count():
|
|
|
|
|
Global.frame_ids.get_child(current_frame).add_color_override("font_color", Global.control.theme.get_color("Selected Color", "Label"))
|
2020-06-06 22:48:35 +00:00
|
|
|
|
if layers and current_frame < layers[current_layer].frame_container.get_child_count():
|
2020-06-04 18:05:36 +00:00
|
|
|
|
layers[current_layer].frame_container.get_child(current_frame).pressed = true
|
|
|
|
|
|
2020-06-05 01:30:31 +00:00
|
|
|
|
Global.disable_button(Global.remove_frame_button, frames.size() == 1)
|
2020-10-04 23:37:55 +00:00
|
|
|
|
Global.disable_button(Global.move_left_frame_button, frames.size() == 1 or current_frame == 0)
|
|
|
|
|
Global.disable_button(Global.move_right_frame_button, frames.size() == 1 or current_frame == frames.size() - 1)
|
2020-06-04 18:05:36 +00:00
|
|
|
|
|
2021-01-05 01:12:02 +00:00
|
|
|
|
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
|
|
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
|
Global.canvas.update()
|
|
|
|
|
Global.transparent_checker._ready() # To update the rect size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func layer_changed(value : int) -> void:
|
|
|
|
|
current_layer = value
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
2020-06-05 01:30:31 +00:00
|
|
|
|
toggle_layer_buttons_current_layer()
|
|
|
|
|
|
|
|
|
|
yield(Global.get_tree().create_timer(0.01), "timeout")
|
|
|
|
|
self.current_frame = current_frame # Call frame_changed to update UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func toggle_layer_buttons_layers() -> void:
|
2020-06-06 22:48:35 +00:00
|
|
|
|
if !layers:
|
|
|
|
|
return
|
2020-06-05 01:30:31 +00:00
|
|
|
|
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 toggle_layer_buttons_current_layer() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
2021-01-30 21:57:33 +00:00
|
|
|
|
var tag_base_size = Global.animation_timeline.cel_size + 3
|
|
|
|
|
var tag_c : Container = load("res://src/UI/Timeline/AnimationTagUI.tscn").instance()
|
2020-06-04 18:05:36 +00:00
|
|
|
|
Global.tag_container.add_child(tag_c)
|
2021-01-30 21:57:33 +00:00
|
|
|
|
tag_c.tag = tag
|
2020-06-04 18:05:36 +00:00
|
|
|
|
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
|
|
|
|
|
|
2021-01-30 21:57:33 +00:00
|
|
|
|
tag_c.rect_position.x = (tag.from - 1) * tag_base_size + tag.from
|
2020-06-13 12:25:12 +00:00
|
|
|
|
var tag_size : int = tag.to - tag.from
|
2021-01-30 21:57:33 +00:00
|
|
|
|
tag_c.rect_min_size.x = (tag_size + 1) * tag_base_size
|
2020-06-04 18:05:36 +00:00
|
|
|
|
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)
|
|
|
|
|
|
2020-06-05 13:06:59 +00:00
|
|
|
|
set_timeline_first_and_last_frames()
|
2020-06-05 01:30:31 +00:00
|
|
|
|
|
|
|
|
|
|
2020-06-05 13:06:59 +00:00
|
|
|
|
func set_timeline_first_and_last_frames() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
|
# 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
|
2020-06-05 01:30:31 +00:00
|
|
|
|
# when the play buttons get pressed anyway
|
2020-06-04 18:05:36 +00:00
|
|
|
|
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)
|
2020-06-05 17:15:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func has_changed_changed(value : bool) -> void:
|
|
|
|
|
has_changed = value
|
|
|
|
|
if value:
|
|
|
|
|
Global.tabs.set_tab_title(Global.tabs.current_tab, name + "(*)")
|
|
|
|
|
else:
|
|
|
|
|
Global.tabs.set_tab_title(Global.tabs.current_tab, name)
|
2021-01-18 20:59:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func get_tile_mode_rect() -> Rect2:
|
2021-01-28 19:21:48 +00:00
|
|
|
|
return tile_mode_rects[tile_mode]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func update_tile_mode_rects() -> void:
|
|
|
|
|
tile_mode_rects.resize(Global.TileMode.size())
|
|
|
|
|
tile_mode_rects[Global.TileMode.NONE] = Rect2(Vector2.ZERO, size)
|
|
|
|
|
tile_mode_rects[Global.TileMode.BOTH] = Rect2(Vector2(-1, -1) * size, Vector2(3, 3) * size)
|
|
|
|
|
tile_mode_rects[Global.TileMode.X_AXIS] = Rect2(Vector2(-1, 0) * size, Vector2(3, 1) * size)
|
|
|
|
|
tile_mode_rects[Global.TileMode.Y_AXIS] = Rect2(Vector2(0, -1) * size, Vector2(1, 3) * size)
|
2021-01-30 18:33:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func is_empty() -> bool:
|
|
|
|
|
return frames.size() == 1 and layers.size() == 1 and frames[0].cels[0].image.is_invisible() and animation_tags.size() == 0
|