Started buildings undo system implementation

This commit is contained in:
2024-07-26 13:44:03 +03:00
parent 42ac0f19ca
commit e30e1ed2d8
4 changed files with 39 additions and 12 deletions

View File

@@ -17,6 +17,7 @@ func _ready():
$"%select_poi", $"%select_poi",
$"%select_road_lines", $"%select_road_lines",
$"%select_npc", $"%select_npc",
$"%buildings_save",
]: ]:
b.connect("pressed", $WorldEditor, "editor_command", [b.name, []]) b.connect("pressed", $WorldEditor, "editor_command", [b.name, []])
$WorldEditor.connect("editor_event", self, "editor_event") $WorldEditor.connect("editor_event", self, "editor_event")
@@ -120,8 +121,9 @@ func check_edit_building():
print("get closest building") print("get closest building")
$WorldEditor.editor_command("get_closest_building", [Transform(Basis(), proj)]) $WorldEditor.editor_command("get_closest_building", [Transform(Basis(), proj)])
elif Input.is_action_pressed("mouse1"): elif Input.is_action_pressed("mouse1"):
# Moving buildings
if $"%buildings_edit_mode".selected == 1: if $"%buildings_edit_mode".selected == 1:
if drag_delay < 0.0: if drag_delay < 0.0 && !dragging:
dragging = true dragging = true
var position = get_viewport().get_mouse_position() var position = get_viewport().get_mouse_position()
var camera = get_viewport().get_camera() var camera = get_viewport().get_camera()
@@ -132,8 +134,8 @@ func check_edit_building():
var result = space_state.intersect_ray(start, end, [], 1 << 15, false, true) var result = space_state.intersect_ray(start, end, [], 1 << 15, false, true)
if result.has("collider"): if result.has("collider"):
var proj = result.position var proj = result.position
if $"%buildings_edit_mode".selected == 1: drag_start = proj
drag_start = proj $WorldEditor.editor_command("buildings_checkpoint", [])
else: else:
drag_delay -= get_process_delta_time() drag_delay -= get_process_delta_time()
else: else:

View File

@@ -110,7 +110,7 @@ text = "NPC Mode"
unique_name_in_owner = true unique_name_in_owner = true
margin_top = 154.0 margin_top = 154.0
margin_right = 160.0 margin_right = 160.0
margin_bottom = 224.0 margin_bottom = 248.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_buildings"] [node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_buildings"]
margin_right = 160.0 margin_right = 160.0
@@ -138,11 +138,18 @@ margin_right = 160.0
margin_bottom = 70.0 margin_bottom = 70.0
text = "Building Type" text = "Building Type"
[node name="buildings_save" type="Button" parent="VBoxContainer/v_buildings"]
unique_name_in_owner = true
margin_top = 74.0
margin_right = 160.0
margin_bottom = 94.0
text = "Save Buildings"
[node name="v_navigation" type="VBoxContainer" parent="VBoxContainer"] [node name="v_navigation" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_top = 228.0 margin_top = 252.0
margin_right = 160.0 margin_right = 160.0
margin_bottom = 250.0 margin_bottom = 274.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_navigation"] [node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_navigation"]
margin_right = 160.0 margin_right = 160.0
@@ -156,9 +163,9 @@ text = "Navigation mode"
[node name="v_poi" type="VBoxContainer" parent="VBoxContainer"] [node name="v_poi" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_top = 254.0 margin_top = 278.0
margin_right = 160.0 margin_right = 160.0
margin_bottom = 276.0 margin_bottom = 300.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_poi"] [node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_poi"]
margin_right = 160.0 margin_right = 160.0
@@ -172,9 +179,9 @@ text = "POI mode"
[node name="v_road_lines" type="VBoxContainer" parent="VBoxContainer"] [node name="v_road_lines" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_top = 280.0 margin_top = 304.0
margin_right = 160.0 margin_right = 160.0
margin_bottom = 302.0 margin_bottom = 326.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_road_lines"] [node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_road_lines"]
margin_right = 160.0 margin_right = 160.0
@@ -188,9 +195,9 @@ text = "Road Lines mode"
[node name="v_npc" type="VBoxContainer" parent="VBoxContainer"] [node name="v_npc" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true unique_name_in_owner = true
margin_top = 306.0 margin_top = 330.0
margin_right = 160.0 margin_right = 160.0
margin_bottom = 328.0 margin_bottom = 352.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_npc"] [node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_npc"]
margin_right = 160.0 margin_right = 160.0

View File

@@ -337,6 +337,12 @@ void StreamWorld::run_command(const String &command, const Array &args)
bnode->set_global_transform(args[1]); bnode->set_global_transform(args[1]);
VariantWriter::write_to_string(buildings[id].xform, key); VariantWriter::write_to_string(buildings[id].xform, key);
buildings[id].key = key; buildings[id].key = key;
} else if (command == "buildings_checkpoint") {
/* TODO */
} else if (command == "buildings_undo") {
/* TODO */
} else if (command == "buildings_save") {
/* TODO */
} else } else
print_error("No command " + command); print_error("No command " + command);
} }

View File

@@ -120,6 +120,18 @@ void WorldEditor::editor_command(const String &command, const Array &args)
if (stream_world) { if (stream_world) {
stream_world->run_command(command, args); stream_world->run_command(command, args);
} }
} else if (command == "buildings_checkpoint") {
if (stream_world) {
stream_world->run_command(command, args);
}
} else if (command == "buildings_undo") {
if (stream_world) {
stream_world->run_command(command, args);
}
} else if (command == "buildings_save") {
if (stream_world) {
stream_world->run_command(command, args);
}
} }
} }