Refactoring; Started GUI for interior layout graph

This commit is contained in:
2024-10-25 22:16:35 +03:00
parent 2cc591706f
commit 3b4006e02d
19 changed files with 1713 additions and 1148 deletions

View File

@@ -219,19 +219,6 @@ public:
, editor(editor)
{
int i;
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();
popup->connect("id_pressed", this, "main_handler");
// popup->connect("mouse_exited", popup, "hide");
popup->connect("focus_exited", popup, "hide");
}
Button *cancel_button = editor->get_as_node<Button>(
"%road_lines_create_new_cancel");
LineEdit *line_name = editor->get_as_node<LineEdit>(
@@ -282,17 +269,6 @@ public:
line_name->disconnect("text_changed", this, "changed_handler");
line_name->disconnect("text_entered", this, "entered_handler");
cancel_button->disconnect("pressed", this, "cancel_handler");
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();
popup->disconnect("id_pressed", this, "main_handler");
}
}
protected:
@@ -324,129 +300,6 @@ protected:
items->add_item(key);
}
}
void main_handler(int id)
{
switch (id) {
case 11:
editor->line_create_point();
break;
case 12:
editor->line_delete_point();
break;
case 21:
/* Create line */
editor->get_as_node<Control>("%road_lines_base")->hide();
editor->get_as_node<Control>(
"%road_lines_create_new_line_dlg")
->show();
break;
case 22:
/* delete line */
editor->delete_current_line();
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")
->show();
update_metadata_editor();
break;
case 30:
editor->remove_generated_stuff();
break;
case 31:
editor->place_generated_objects();
break;
case 32:
editor->rebuild_roads();
break;
case 33:
editor->remove_road_meshes();
break;
case 34: {
RoadLinesData::get_singleton()->assign_close_buildings(
current_line);
editor->update_line_geometry();
} break;
case 36:
editor->get_as_node<Control>("%road_lines_base")->hide();
editor->get_as_node<Control>("%road_lines_buildings")
->show();
update_line_buildings_editor();
break;
case 51:
editor->set_point_to_cursor();
break;
case 52:
editor->move_cursor_to_point();
break;
case 53:
editor->move_cursor_to_closest_building();
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));
assert(false);
}
}
void cancel_handler()
{
LineEdit *line_name = editor->get_as_node<LineEdit>(
@@ -553,8 +406,6 @@ protected:
}
static void _bind_methods()
{
ClassDB::bind_method(D_METHOD("main_handler", "id"),
&HandleCreateNewLine::main_handler);
ClassDB::bind_method(D_METHOD("cancel_handler"),
&HandleCreateNewLine::cancel_handler);
ClassDB::bind_method(D_METHOD("entered_handler", "new_text"),
@@ -1127,6 +978,38 @@ void RoadLinesEditor::set_debug_road_wedges(bool checked)
{
debug_road_wedges = checked;
}
const String &RoadLinesEditor::get_current_line() const
{
return current_line;
}
const String &RoadLinesEditor::get_filter_text() const
{
return filter_text;
}
void RoadLinesEditor::get_matching_lines(List<String> *lines)
{
if (!re.is_valid())
re.instance();
re->compile(filter_text);
if (filter_text.length() > 0 && !re->is_valid())
return;
List<String> line_keys;
RoadLinesData *rld = RoadLinesData::get_singleton();
rld->get_lines_key_list(&line_keys);
assert(!line_keys.empty());
lines->clear();
List<String>::Element *e = line_keys.front();
while (e) {
Array matches = re->search_all(e->get());
if (filter_text.length() > 0 && matches.size() == 0) {
e = e->next();
continue;
}
lines->push_back(e->get());
e = e->next();
}
assert(!lines->empty());
}
void RoadLinesEditor::place_zebras()
{
editor->editor_command("remove_buildings_by_prefix", varray("zebra"));