1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-30 23:19:49 +00:00

UndoRedo vol 3 - Fixed bug when user clicked both mouse buttons

Drawing outside canvas needs fixing next in our UndoRedo adventure
This commit is contained in:
OverloadedOrama 2019-11-01 01:41:02 +02:00
parent 0d69e45cab
commit 04c3173c4c
2 changed files with 9 additions and 2 deletions

View file

@ -96,14 +96,14 @@ func _process(delta) -> void:
#Handle Undo/Redo #Handle Undo/Redo
if point_in_rectangle(mouse_pos, location, location + size) && Global.can_draw && Global.has_focus && Global.current_frame == frame: if point_in_rectangle(mouse_pos, location, location + size) && Global.can_draw && Global.has_focus && Global.current_frame == frame:
if Input.is_action_just_pressed("left_mouse") || (Input.is_action_just_pressed("right_mouse") && !Input.is_action_pressed("left_mouse")): if (Input.is_action_just_pressed("left_mouse") && !Input.is_action_pressed("right_mouse")) || (Input.is_action_just_pressed("right_mouse") && !Input.is_action_pressed("left_mouse")):
if current_action != "None": if current_action != "None":
if current_action == "RectSelect": if current_action == "RectSelect":
handle_undo("Rectangle Select") handle_undo("Rectangle Select")
else: else:
handle_undo("Draw") handle_undo("Draw")
elif Input.is_action_just_released("left_mouse") || (Input.is_action_just_released("right_mouse") && !Input.is_action_pressed("left_mouse")): 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 previous_action != "None" && previous_action != "RectSelect": if previous_action != "None" && previous_action != "RectSelect":
handle_redo("Draw") handle_redo("Draw")
@ -230,6 +230,7 @@ func _process(delta) -> void:
update_texture(current_layer_index) update_texture(current_layer_index)
func handle_undo(action : String) -> void: func handle_undo(action : String) -> void:
Global.undos += 1
#I'm not sure why I have to unlock it, but... #I'm not sure why I have to unlock it, but...
#...if I don't, it doesn't work properly #...if I don't, it doesn't work properly
layers[current_layer_index][0].unlock() layers[current_layer_index][0].unlock()
@ -244,6 +245,8 @@ func handle_undo(action : String) -> void:
Global.undo_redo.add_undo_method(Global, "undo", self, current_layer_index) Global.undo_redo.add_undo_method(Global, "undo", self, current_layer_index)
func handle_redo(action : String) -> void: func handle_redo(action : String) -> void:
if Global.undos < Global.undo_redo.get_version():
return
Global.undo_redo.add_do_property(layers[current_layer_index][0], "data", layers[current_layer_index][0].data) Global.undo_redo.add_do_property(layers[current_layer_index][0], "data", layers[current_layer_index][0].data)
if action == "Rectangle Select": 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.selection_rectangle, "polygon", Global.selection_rectangle.polygon)

View file

@ -1,6 +1,7 @@
extends Node extends Node
var undo_redo : UndoRedo var undo_redo : UndoRedo
var undos := 0 #The number of times we added undo properties
var current_frame := 0 setget set_current_frame_label var current_frame := 0 setget set_current_frame_label
# warning-ignore:unused_class_variable # warning-ignore:unused_class_variable
var can_draw := false var can_draw := false
@ -162,12 +163,15 @@ func find_node_by_name(root, node_name) -> Node:
return null return null
func undo(canvas : Canvas, layer_index : int) -> void: func undo(canvas : Canvas, layer_index : int) -> void:
undos -= 1
var action_name : String = undo_redo.get_current_action_name() var action_name : String = undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select": if action_name == "Draw" || action_name == "Rectangle Select":
canvas.update_texture(layer_index) canvas.update_texture(layer_index)
print("Undo: ", action_name) print("Undo: ", action_name)
func redo(canvas : Canvas, layer_index : int) -> void: func redo(canvas : Canvas, layer_index : int) -> void:
if undos < undo_redo.get_version(): #If we did undo and then redo
undos = undo_redo.get_version()
var action_name : String = undo_redo.get_current_action_name() var action_name : String = undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select": if action_name == "Draw" || action_name == "Rectangle Select":
canvas.update_texture(layer_index) canvas.update_texture(layer_index)