2023-02-12 13:20:53 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
var axes: Node2D
|
|
|
|
var do_pool = [] # A pool that stores data of points removed by undo
|
|
|
|
var delete_pool = [] # A pool that containg deleted data and their index
|
|
|
|
var vanishing_point_res := preload("res://src/UI/PerspectiveEditor/VanishingPoint.tscn")
|
2023-02-18 00:33:46 +00:00
|
|
|
var tracker_disabled := false
|
2023-02-12 13:20:53 +00:00
|
|
|
onready var vanishing_point_container = $"%VanishingPointContainer"
|
|
|
|
|
|
|
|
|
|
|
|
func _on_AddPoint_pressed() -> void:
|
2023-02-18 00:33:46 +00:00
|
|
|
do_pool.clear() # Reset (clears Redo history of vanishing points)
|
2023-02-12 13:20:53 +00:00
|
|
|
var project = Global.current_project
|
|
|
|
project.undos += 1
|
|
|
|
project.undo_redo.create_action("Add Vanishing Point")
|
|
|
|
project.undo_redo.add_do_method(self, "add_vanishing_point", true)
|
|
|
|
project.undo_redo.add_undo_method(self, "undo_add_vanishing_point")
|
|
|
|
project.undo_redo.commit_action()
|
|
|
|
|
|
|
|
|
2023-02-18 00:33:46 +00:00
|
|
|
func _on_TrackerLines_toggled(button_pressed):
|
|
|
|
for point in vanishing_point_container.get_children():
|
|
|
|
tracker_disabled = !button_pressed
|
2023-02-12 13:20:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
func add_vanishing_point(is_redo := false):
|
|
|
|
var vanishing_point := vanishing_point_res.instance()
|
|
|
|
vanishing_point_container.add_child(vanishing_point)
|
|
|
|
if is_redo and !do_pool.empty():
|
2023-02-18 00:33:46 +00:00
|
|
|
# if it's a redo then initialize it with the redo data
|
2023-02-12 13:20:53 +00:00
|
|
|
vanishing_point.initiate(do_pool.pop_back())
|
|
|
|
vanishing_point.update_data_to_project()
|
|
|
|
else:
|
|
|
|
vanishing_point.initiate()
|
|
|
|
|
|
|
|
|
|
|
|
func undo_add_vanishing_point():
|
|
|
|
var point = vanishing_point_container.get_child(vanishing_point_container.get_child_count() - 1)
|
|
|
|
point.queue_free()
|
2023-02-18 00:33:46 +00:00
|
|
|
do_pool.append(point.serialize())
|
2023-02-12 13:20:53 +00:00
|
|
|
point.update_data_to_project(true)
|
|
|
|
|
|
|
|
|
|
|
|
func delete_point(idx):
|
|
|
|
var project = Global.current_project
|
|
|
|
project.undos += 1
|
|
|
|
project.undo_redo.create_action("Delete Vanishing Point")
|
|
|
|
project.undo_redo.add_do_method(self, "do_delete_point", idx)
|
|
|
|
project.undo_redo.add_undo_method(self, "undo_delete_point", idx)
|
|
|
|
project.undo_redo.commit_action()
|
|
|
|
|
|
|
|
|
|
|
|
func do_delete_point(idx):
|
|
|
|
var point = vanishing_point_container.get_child(idx)
|
2023-02-18 00:33:46 +00:00
|
|
|
delete_pool.append(point.serialize())
|
2023-02-12 13:20:53 +00:00
|
|
|
point.queue_free()
|
|
|
|
point.update_data_to_project(true)
|
|
|
|
|
|
|
|
|
|
|
|
func undo_delete_point(idx):
|
|
|
|
var point = delete_pool.pop_back()
|
|
|
|
Global.current_project.vanishing_points.insert(idx, point)
|
2023-02-18 00:33:46 +00:00
|
|
|
update_points()
|
|
|
|
|
|
|
|
|
|
|
|
func update_points():
|
|
|
|
# Delete old vanishing points
|
|
|
|
for c in vanishing_point_container.get_children():
|
|
|
|
c.queue_free()
|
|
|
|
# Add the "updated" vanising points from the current_project
|
|
|
|
for idx in Global.current_project.vanishing_points.size():
|
|
|
|
# Create the point
|
|
|
|
var vanishing_point := vanishing_point_res.instance()
|
|
|
|
vanishing_point_container.add_child(vanishing_point)
|
|
|
|
# Initialize it
|
|
|
|
var point_data = Global.current_project.vanishing_points[idx]
|
|
|
|
vanishing_point.initiate(point_data, idx)
|