Worked on debugging and metadata stuff

This commit is contained in:
2024-09-18 23:00:52 +03:00
parent a9190fcc09
commit 43c312e371
13 changed files with 431 additions and 110 deletions

View File

@@ -16,6 +16,7 @@
#include <core/os/time.h>
#include <core/io/json.h>
#include <modules/regex/regex.h>
#include "editor_event.h"
#include "world_editor.h"
#include "from_string.h"
#include "road_lines_data.h"
@@ -157,6 +158,8 @@ protected:
}
};
static String current_line = "";
class HandlePointSelection : public Object {
GDCLASS(HandlePointSelection, Object)
RoadLinesEditor *editor;
@@ -286,6 +289,8 @@ public:
protected:
void update_metadata_editor()
{
if (current_line == "")
return;
TextEdit *metadata_edit = editor->get_as_node<TextEdit>(
"%road_lines_metadata_edit");
String text = editor->get_current_line_metadata();
@@ -313,6 +318,10 @@ protected:
break;
case 23:
/* edit line metadata */
if (current_line == "") {
print_error("No current line set");
return;
}
editor->get_as_node<Control>("%road_lines_base")->hide();
editor->get_as_node<Control>(
"%road_lines_edit_metadata_dlg")
@@ -340,6 +349,58 @@ protected:
case 101:
editor->save_data();
break;
case 201:
case 210:
case 211:
case 212: {
print_line("selected item 201");
int i, j;
Node *menu_block = editor->get_as_node<Node>(
"%road_lines_menu_block");
for (i = 0; i < menu_block->get_child_count(); i++) {
Node *menu_button_node =
menu_block->get_child(i);
MenuButton *menu_button =
Object::cast_to<MenuButton>(
menu_button_node);
if (!menu_button)
continue;
PopupMenu *popup = menu_button->get_popup();
for (j = 0; j < popup->get_item_count(); j++) {
int nid = popup->get_item_id(j);
if (nid == id) {
bool checked =
popup->is_item_checked(
j);
if (checked)
print_line("checked");
else
print_line("unchecked");
checked = !checked;
popup->set_item_checked(
j, checked);
switch (id) {
case 201:
editor->set_update_roads(
checked);
break;
case 210:
editor->set_debug_road_nodes(
checked);
break;
case 211:
editor->set_debug_road_edges(
checked);
break;
case 212:
editor->set_debug_road_wedges(
checked);
break;
}
}
}
}
} break;
default:
print_line("menu option pressed: " + itos(id));
}
@@ -467,6 +528,10 @@ RoadLinesEditor::RoadLinesEditor(WorldEditor *editor)
, cursor_enabled(false)
, filter_text("")
, camera_moved(false)
, update_roads(false)
, debug_road_nodes(false)
, debug_road_edges(false)
, debug_road_wedges(false)
{
}
@@ -483,7 +548,6 @@ Node *RoadLinesEditor::scene()
return editor->get_tree()->get_current_scene();
}
static String current_line = "";
void RoadLinesEditor::update_line_geometry()
{
RoadLinesData *rld = RoadLinesData::get_singleton();
@@ -553,6 +617,9 @@ void RoadLinesEditor::select_line(const String &line_name)
set_line_index(0);
update_line_geometry();
}
Array args;
args.push_back(current_line);
EditorEvent::get_singleton()->event.emit("lines_select_line", args);
update_ui();
}
@@ -572,6 +639,9 @@ void RoadLinesEditor::line_create_point()
int index = get_line_index();
rld->lines[current_line].points.insert(
rld->lines[current_line].points.begin() + index + 1, xform);
Array args;
args.push_back(current_line);
EditorEvent::get_singleton()->event.emit("lines_changed_line", args);
update_line_geometry();
update_line_index_ui();
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
@@ -589,6 +659,9 @@ void RoadLinesEditor::line_delete_point()
return;
rld->lines[current_line].points.erase(
rld->lines[current_line].points.begin() + index);
Array args;
args.push_back(current_line);
EditorEvent::get_singleton()->event.emit("lines_changed_line", args);
update_line_geometry();
update_line_index_ui();
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
@@ -607,6 +680,9 @@ void RoadLinesEditor::set_point_to_cursor()
Transform xform = cursor->get_global_transform();
int index = get_line_index();
rld->lines[current_line].points[index].origin = xform.origin;
Array args;
args.push_back(current_line);
EditorEvent::get_singleton()->event.emit("lines_changed_line", args);
update_line_geometry();
set_ui_point_position(rld->lines[current_line].points[index].origin);
}
@@ -798,6 +874,9 @@ void RoadLinesEditor::set_point_position(const Vector3 &position)
RoadLinesData *rld = RoadLinesData::get_singleton();
int index = get_line_index();
rld->lines[current_line].points[index].origin = position;
Array args;
args.push_back(current_line);
EditorEvent::get_singleton()->event.emit("lines_changed_line", args);
update_line_geometry();
}
void RoadLinesEditor::set_ui_cursor_position(const Vector3 &cursor_position)
@@ -869,12 +948,16 @@ void RoadLinesEditor::activate()
new_line_handler = memnew(HandleCreateNewLine(this));
if (!point_selection_handler)
point_selection_handler = memnew(HandlePointSelection(this));
EditorEvent::get_singleton()->event.add_listener(
this, &RoadLinesEditor::event_handler);
active = true;
}
void RoadLinesEditor::deactivate()
{
EditorEvent::get_singleton()->event.remove_listener(
this, &RoadLinesEditor::event_handler);
Node *lines_list_node =
editor->get_tree()->get_current_scene()->get_node(
NodePath("%lines_list"));
@@ -913,6 +996,15 @@ void RoadLinesEditor::place_generated_objects()
void RoadLinesEditor::rebuild_roads()
{
Array args;
int debug_flags = 0;
if (debug_road_nodes)
debug_flags |= (1 << 0);
if (debug_road_edges)
debug_flags |= (1 << 1);
if (debug_road_wedges)
debug_flags |= (1 << 2);
print_line("rebuild_roads: debug: " + itos(debug_flags));
args.push_back(debug_flags);
editor->editor_command("rebuild_roads", args);
}
void RoadLinesEditor::remove_road_meshes()
@@ -925,6 +1017,22 @@ void RoadLinesEditor::handle_input()
if (editor->get_camera_mode() != 3)
return;
}
void RoadLinesEditor::set_update_roads(bool checked)
{
update_roads = checked;
}
void RoadLinesEditor::set_debug_road_nodes(bool checked)
{
debug_road_nodes = checked;
}
void RoadLinesEditor::set_debug_road_edges(bool checked)
{
debug_road_edges = checked;
}
void RoadLinesEditor::set_debug_road_wedges(bool checked)
{
debug_road_wedges = checked;
}
void RoadLinesEditor::place_zebras()
{
Array args;
@@ -1053,3 +1161,21 @@ template <class T> T *RoadLinesEditor::get_as_node(const String &path)
assert(ret);
return ret;
}
void RoadLinesEditor::event_handler(const String &event, const Array &args)
{
if (event == "lines_get_current_line" && current_line != "") {
Array nargs;
nargs.push_back(current_line);
EditorEvent::get_singleton()->event.emit("lines_select_line",
nargs);
}
if (event == "lines_changed_line") {
if (!update_roads)
print_line("road update disabled");
if (current_line.ends_with("_road"))
print_line("the line is a road");
if (current_line.ends_with("_road") && update_roads)
rebuild_roads();
}
}