mirror of
https://github.com/tonytins/CozyPixelStudio.git
synced 2025-06-25 05:04:43 -04:00
v0.4 - Undo/Redo, mirrored drawing, lighten/darken tool and more!
In this commit: - Added notification labels that appear when the user does an action (for undoing, redoing and saving) - Fixed symmetry with custom brushes. - In Main.gd, current_save_path and current_export_path get cleared when the user creates a new drawing or opens one. v0.4 of Pixelorama is out! Check https://functionoverload590613498.wordpress.com/2019/11/13/pixelorama-v0-4-is-out/ for the full changelog.
This commit is contained in:
parent
17d117a0b1
commit
d66c501b5c
9 changed files with 79 additions and 18 deletions
|
@ -542,8 +542,12 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String, cur
|
|||
src_rect.size.y = min(src_rect.size.y, selection_rect.size.y)
|
||||
|
||||
#Handle mirroring
|
||||
var mirror_x := east_limit + west_limit - pos.x - (pos.x - dst.x) - 1
|
||||
var mirror_y := south_limit + north_limit - pos.y - (pos.y - dst.y) - 1
|
||||
var mirror_x := east_limit + west_limit - pos.x - (pos.x - dst.x)
|
||||
var mirror_y := south_limit + north_limit - pos.y - (pos.y - dst.y)
|
||||
if int(pos_rect_clipped.size.x) % 2 != 0:
|
||||
mirror_x -= 1
|
||||
if int(pos_rect_clipped.size.y) % 2 != 0:
|
||||
mirror_y -= 1
|
||||
|
||||
if color.a > 0: #If it's the pencil
|
||||
layers[current_layer_index][0].blend_rect(custom_brush_image, src_rect, dst)
|
||||
|
|
|
@ -20,6 +20,7 @@ var draw_grid := false
|
|||
var canvases := []
|
||||
# warning-ignore:unused_class_variable
|
||||
var hidden_canvases := []
|
||||
var control : Node
|
||||
var canvas : Canvas
|
||||
var canvas_parent : Node
|
||||
var second_viewport : ViewportContainer
|
||||
|
@ -109,6 +110,7 @@ var custom_right_brush_texture := ImageTexture.new()
|
|||
func _ready() -> void:
|
||||
undo_redo = UndoRedo.new()
|
||||
var root = get_tree().get_root()
|
||||
control = find_node_by_name(root, "Control")
|
||||
canvas = find_node_by_name(root, "Canvas")
|
||||
canvases.append(canvas)
|
||||
canvas_parent = canvas.get_parent()
|
||||
|
@ -165,6 +167,12 @@ func find_node_by_name(root, node_name) -> Node:
|
|||
return found
|
||||
return null
|
||||
|
||||
func notification_label(text : String) -> void:
|
||||
var notification : Label = load("res://Prefabs/NotificationLabel.tscn").instance()
|
||||
notification.text = text
|
||||
notification.rect_position = Vector2(240, OS.window_size.y - 150)
|
||||
get_tree().get_root().add_child(notification)
|
||||
|
||||
func undo(_canvases : Array, layer_index : int = -1) -> void:
|
||||
undos -= 1
|
||||
var action_name := undo_redo.get_current_action_name()
|
||||
|
@ -202,7 +210,8 @@ func undo(_canvases : Array, layer_index : int = -1) -> void:
|
|||
frame_container.move_child(_canvases[0].frame_button, current_frame)
|
||||
canvas_parent.move_child(_canvases[0], current_frame)
|
||||
|
||||
print("Undo: ", action_name)
|
||||
notification_label("Undo: %s" % action_name)
|
||||
|
||||
|
||||
func redo(_canvases : Array, layer_index : int = -1) -> void:
|
||||
if undos < undo_redo.get_version(): #If we did undo and then redo
|
||||
|
@ -241,7 +250,8 @@ func redo(_canvases : Array, layer_index : int = -1) -> void:
|
|||
frame_container.move_child(_canvases[0].frame_button, current_frame)
|
||||
canvas_parent.move_child(_canvases[0], current_frame)
|
||||
|
||||
print("Redo: ", action_name)
|
||||
if control.redone:
|
||||
notification_label("Redo: %s" % action_name)
|
||||
|
||||
func frame_changed(value : int) -> void:
|
||||
current_frame = value
|
||||
|
@ -302,7 +312,7 @@ func undo_custom_brush(_brush_button : Button = null) -> void:
|
|||
hbox_container.add_child(_brush_button)
|
||||
hbox_container.move_child(_brush_button, _brush_button.custom_brush_index - brushes_from_files)
|
||||
_brush_button.get_node("DeleteButton").visible = false
|
||||
print("Undo: ", action_name)
|
||||
notification_label("Undo: %s" % action_name)
|
||||
|
||||
func redo_custom_brush(_brush_button : Button = null) -> void:
|
||||
if undos < undo_redo.get_version(): #If we did undo and then redo
|
||||
|
@ -311,7 +321,8 @@ func redo_custom_brush(_brush_button : Button = null) -> void:
|
|||
var hbox_container := find_node_by_name(get_tree().get_root(), "CustomBrushHBoxContainer")
|
||||
if action_name == "Delete Custom Brush":
|
||||
hbox_container.remove_child(_brush_button)
|
||||
print("Redo: ", action_name)
|
||||
if control.redone:
|
||||
notification_label("Redo: %s" % action_name)
|
||||
|
||||
func update_left_custom_brush() -> void:
|
||||
if custom_left_brush_index > -1:
|
||||
|
|
|
@ -9,6 +9,7 @@ var import_as_new_frame : CheckBox
|
|||
var export_all_frames : CheckBox
|
||||
var export_as_single_file : CheckBox
|
||||
var export_vertical_spritesheet : CheckBox
|
||||
var redone := false
|
||||
var fps := 1.0
|
||||
var animation_loop := 0 #0 is no loop, 1 is cycle loop, 2 is ping-pong loop
|
||||
var animation_forward := true
|
||||
|
@ -168,7 +169,9 @@ func edit_menu_id_pressed(id : int) -> void:
|
|||
0: #Undo
|
||||
Global.undo_redo.undo()
|
||||
1: #Redo
|
||||
redone = true
|
||||
Global.undo_redo.redo()
|
||||
redone = false
|
||||
2: #Scale Image
|
||||
$ScaleImage.popup_centered()
|
||||
Global.can_draw = false
|
||||
|
@ -382,6 +385,7 @@ func _on_SaveSprite_file_selected(path) -> void:
|
|||
file.store_buffer(brush.get_data())
|
||||
file.store_line("END_BRUSHES")
|
||||
file.close()
|
||||
Global.notification_label("File saved")
|
||||
|
||||
func _on_ImportSprites_files_selected(paths) -> void:
|
||||
if !import_as_new_frame.pressed: #If we're not adding a new frame, delete the previous
|
||||
|
@ -442,6 +446,8 @@ func clear_canvases() -> void:
|
|||
if child is Canvas:
|
||||
child.queue_free()
|
||||
Global.canvases.clear()
|
||||
current_save_path = ""
|
||||
current_export_path = ""
|
||||
|
||||
func _on_ExportSprites_file_selected(path : String) -> void:
|
||||
current_export_path = path
|
||||
|
@ -461,6 +467,7 @@ func export_project() -> void:
|
|||
save_spritesheet()
|
||||
else:
|
||||
save_sprite(Global.canvas, current_export_path)
|
||||
Global.notification_label("File exported")
|
||||
|
||||
func save_sprite(canvas : Canvas, path : String) -> void:
|
||||
var whole_image := Image.new()
|
||||
|
|
15
Scripts/NotificationLabel.gd
Normal file
15
Scripts/NotificationLabel.gd
Normal file
|
@ -0,0 +1,15 @@
|
|||
extends Label
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
var tween := $Tween
|
||||
tween.interpolate_property(self, "rect_position", rect_position, Vector2(rect_position.x, rect_position.y - 100), 1, Tween.TRANS_LINEAR, Tween.EASE_OUT)
|
||||
tween.interpolate_property(self, "modulate", modulate, Color(modulate.r, modulate.g, modulate.b, 0), 1, Tween.TRANS_LINEAR, Tween.EASE_OUT)
|
||||
tween.start()
|
||||
|
||||
func _on_Timer_timeout() -> void:
|
||||
queue_free()
|
Loading…
Add table
Add a link
Reference in a new issue