From 122f42b361cdc82dd15190c226e581ba6ed93368 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 23 Nov 2019 01:02:53 +0200 Subject: [PATCH] UndoRedo v12 - Guide support - Guides now have undo/redo support when being moved. If they are moved outside the canvas they get queue_freed. - Updated icon. --- Scripts/Guides.gd | 56 +++++++++++++++++++++++++++++++++------------- icon.png | Bin 1096 -> 2342 bytes 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Scripts/Guides.gd b/Scripts/Guides.gd index 9c42ad3ef..5384524cf 100644 --- a/Scripts/Guides.gd +++ b/Scripts/Guides.gd @@ -6,6 +6,7 @@ enum TYPE {HORIZONTAL, VERTICAL} var font := preload("res://Assets/Fonts/Roboto-Regular.tres") var has_focus := true var mouse_pos := Vector2.ZERO +var previous_points := points var type = TYPE.HORIZONTAL func _ready() -> void: @@ -28,24 +29,29 @@ func _process(delta) -> void: has_focus = true Global.has_focus = false update() - if has_focus && Input.is_action_pressed("left_mouse"): - if type == TYPE.HORIZONTAL: - points[0].y = round(mouse_pos.y) - points[1].y = round(mouse_pos.y) - else: - points[0].x = round(mouse_pos.x) - points[1].x = round(mouse_pos.x) - if Input.is_action_just_released("left_mouse"): - if has_focus: + if has_focus: + if Input.is_action_just_pressed("left_mouse"): + previous_points = points + if Input.is_action_pressed("left_mouse"): + if type == TYPE.HORIZONTAL: + points[0].y = round(mouse_pos.y) + points[1].y = round(mouse_pos.y) + else: + points[0].x = round(mouse_pos.x) + points[1].x = round(mouse_pos.x) + if Input.is_action_just_released("left_mouse"): Global.has_focus = true has_focus = false - update() - if type == TYPE.HORIZONTAL: - if points[0].y < 0 || points[0].y > Global.canvas.size.y: - queue_free() - else: - if points[0].x < 0 || points[0].x > Global.canvas.size.x: - queue_free() + if !outside_canvas(): + Global.undos += 1 + Global.undo_redo.create_action("Move Guide") + Global.undo_redo.add_do_method(self, "outside_canvas") + Global.undo_redo.add_do_property(self, "points", points) + Global.undo_redo.add_undo_property(self, "points", previous_points) + Global.undo_redo.add_undo_method(self, "outside_canvas", true) + Global.undo_redo.commit_action() + update() + func _draw() -> void: if has_focus: @@ -58,5 +64,23 @@ func _draw() -> void: draw_set_transform(Vector2(points[0].x + font.get_height() * zoom.y, Global.camera.offset.y - (viewport_size.y / 2.25) * zoom.y), rotation, zoom * 2) draw_string(font, Vector2.ZERO, "%spx" % str(round(mouse_pos.x))) +func outside_canvas(undo := false) -> bool: + if undo: + Global.undos -= 1 + Global.notification_label("Move Guide") + if Global.control.redone: + if Global.undos < Global.undo_redo.get_version(): #If we did undo and then redo + Global.undos = Global.undo_redo.get_version() + Global.notification_label("Move Guide") + if type == TYPE.HORIZONTAL: + if points[0].y < 0 || points[0].y > Global.canvas.size.y: + queue_free() + return true + else: + if points[0].x < 0 || points[0].x > Global.canvas.size.x: + queue_free() + return true + return false + func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool: return p.x > coord1.x && p.y > coord1.y && p.x < coord2.x && p.y < coord2.y \ No newline at end of file diff --git a/icon.png b/icon.png index 62e85a40e918596f977dc0b9bf341cdb71a63d20..f1b37a2a8e969ef5adc57e5e56a68307393be088 100644 GIT binary patch literal 2342 zcma)6dpy&7AO9_9CeuQgBP8Tf!l*3w%dkDt1vw;<9cCuOT&B!5SuvL|$~6>`dK4y3 zF7-&cHZdjURx3v1kVUj-o##BSSAUe}`MzG?*Z2MUe81n%`*Xj1{HXmlaRqSz0JdS! zC?@~_2_Xm&6BQn(Lo59NKxE*&i(8n}*+`Y(P@*3`&{riaD%e-Wmy8!)l1Cop;;&XC zB`*qwwK-x{duuwG3J9aT>0{#hZ2vcnUZzw!%01iMAPMCx;Eh`eCM44?-GMSSdD~$5 zfmc)Q4sdH(fpbo0VC=4DS>>@;Q(ky;t4Sz1OL01Y>mrWB3m{?XCx9 zvjc~;3NPU{KIFt%%;09_hN~3`rQO(7NMQrA8M`5u6Li^aCG#Eq8GJ|2d`Q{2{QflN za78z3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