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:
parent
0d69e45cab
commit
04c3173c4c
|
@ -96,14 +96,14 @@ func _process(delta) -> void:
|
|||
|
||||
#Handle Undo/Redo
|
||||
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 == "RectSelect":
|
||||
handle_undo("Rectangle Select")
|
||||
else:
|
||||
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":
|
||||
handle_redo("Draw")
|
||||
|
||||
|
@ -230,6 +230,7 @@ func _process(delta) -> void:
|
|||
update_texture(current_layer_index)
|
||||
|
||||
func handle_undo(action : String) -> void:
|
||||
Global.undos += 1
|
||||
#I'm not sure why I have to unlock it, but...
|
||||
#...if I don't, it doesn't work properly
|
||||
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)
|
||||
|
||||
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)
|
||||
if action == "Rectangle Select":
|
||||
Global.undo_redo.add_do_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
extends Node
|
||||
|
||||
var undo_redo : UndoRedo
|
||||
var undos := 0 #The number of times we added undo properties
|
||||
var current_frame := 0 setget set_current_frame_label
|
||||
# warning-ignore:unused_class_variable
|
||||
var can_draw := false
|
||||
|
@ -162,12 +163,15 @@ func find_node_by_name(root, node_name) -> Node:
|
|||
return null
|
||||
|
||||
func undo(canvas : Canvas, layer_index : int) -> void:
|
||||
undos -= 1
|
||||
var action_name : String = undo_redo.get_current_action_name()
|
||||
if action_name == "Draw" || action_name == "Rectangle Select":
|
||||
canvas.update_texture(layer_index)
|
||||
print("Undo: ", action_name)
|
||||
|
||||
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()
|
||||
if action_name == "Draw" || action_name == "Rectangle Select":
|
||||
canvas.update_texture(layer_index)
|
||||
|
|
Loading…
Reference in a new issue