Updated systems handling
This commit is contained in:
@@ -78,27 +78,32 @@ public:
|
||||
: Object()
|
||||
, editor(editor)
|
||||
{
|
||||
#if 0
|
||||
LineEdit *filter =
|
||||
editor->get_as_node<LineEdit>("%road_lines_filter");
|
||||
filter->connect("text_changed", this, "filter_handler");
|
||||
filter->connect("text_entered", this, "filter_handler");
|
||||
#endif
|
||||
#if 0
|
||||
ItemList *lines_list =
|
||||
editor->get_as_node<ItemList>("%lines_list");
|
||||
lines_list->connect("item_selected", this, "handler");
|
||||
Button *cursor_set = editor->get_as_node<Button>(
|
||||
"%road_lines_set_cursor_position");
|
||||
Button *cursor_set = editor->cursor_set;
|
||||
assert(cursor_set);
|
||||
cursor_set->connect("pressed", this, "set_cursor_handler");
|
||||
Button *point_set = editor->get_as_node<Button>(
|
||||
"%road_lines_set_point_position");
|
||||
Button *point_set = editor->cursor_set;
|
||||
assert(point_set);
|
||||
point_set->connect("pressed", this, "set_point_handler");
|
||||
#endif
|
||||
}
|
||||
virtual ~HandleSelection()
|
||||
{
|
||||
Button *cursor_set = editor->get_as_node<Button>(
|
||||
"%road_lines_set_cursor_position");
|
||||
#if 0
|
||||
Button *cursor_set = editor->cursor_set;
|
||||
assert(cursor_set);
|
||||
cursor_set->disconnect("pressed", this, "set_cursor_handler");
|
||||
Button *point_set = editor->get_as_node<Button>(
|
||||
"%road_lines_set_point_position");
|
||||
Button *point_set = editor->cursor_set;
|
||||
assert(point_set);
|
||||
point_set->disconnect("pressed", this, "set_point_handler");
|
||||
ItemList *lines_list =
|
||||
editor->get_as_node<ItemList>("%lines_list");
|
||||
@@ -107,6 +112,7 @@ public:
|
||||
editor->get_as_node<LineEdit>("%road_lines_filter");
|
||||
filter->disconnect("text_entered", this, "filter_handler");
|
||||
filter->disconnect("text_changed", this, "filter_handler");
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -122,12 +128,12 @@ protected:
|
||||
{
|
||||
editor->line_list_filter_changed(text);
|
||||
}
|
||||
#if 0
|
||||
void set_cursor_handler()
|
||||
{
|
||||
LineEdit *cursor_x = editor->get_as_node<LineEdit>("%cursor_x");
|
||||
LineEdit *cursor_y = editor->get_as_node<LineEdit>("%cursor_y");
|
||||
LineEdit *cursor_z = editor->get_as_node<LineEdit>("%cursor_z");
|
||||
LineEdit *cursor[] = { cursor_x, cursor_y, cursor_z };
|
||||
LineEdit *cursor_x = editor->cursor_pos[0];
|
||||
LineEdit *cursor_y = editor->cursor_pos[1];
|
||||
LineEdit *cursor_z = editor->cursor_pos[2];
|
||||
Vector3 position;
|
||||
position.x = cursor_x->get_text().to_float();
|
||||
position.y = cursor_y->get_text().to_float();
|
||||
@@ -136,26 +142,28 @@ protected:
|
||||
}
|
||||
void set_point_handler()
|
||||
{
|
||||
LineEdit *point_x = editor->get_as_node<LineEdit>("%point_x");
|
||||
LineEdit *point_y = editor->get_as_node<LineEdit>("%point_y");
|
||||
LineEdit *point_z = editor->get_as_node<LineEdit>("%point_z");
|
||||
LineEdit *point[] = { point_x, point_y, point_z };
|
||||
LineEdit *point_x = editor->point_pos[0];
|
||||
LineEdit *point_y = editor->point_pos[1];
|
||||
LineEdit *point_z = editor->point_pos[2];
|
||||
Vector3 position;
|
||||
position.x = point_x->get_text().to_float();
|
||||
position.y = point_y->get_text().to_float();
|
||||
position.z = point_z->get_text().to_float();
|
||||
editor->set_point_position(position);
|
||||
}
|
||||
#endif
|
||||
static void _bind_methods()
|
||||
{
|
||||
ClassDB::bind_method(D_METHOD("handler", "index"),
|
||||
&HandleSelection::handler);
|
||||
ClassDB::bind_method(D_METHOD("filter_handler", "text"),
|
||||
&HandleSelection::filter_handler);
|
||||
#if 0
|
||||
ClassDB::bind_method(D_METHOD("set_cursor_handler"),
|
||||
&HandleSelection::set_cursor_handler);
|
||||
ClassDB::bind_method(D_METHOD("set_point_handler"),
|
||||
&HandleSelection::set_point_handler);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@@ -170,17 +178,21 @@ public:
|
||||
: Object()
|
||||
, editor(editor)
|
||||
{
|
||||
#if 0
|
||||
SpinBox *sp_line_point =
|
||||
editor->get_as_node<SpinBox>("%line_index");
|
||||
sp_line_point->connect("value_changed", this,
|
||||
"handle_value_change");
|
||||
#endif
|
||||
}
|
||||
virtual ~HandlePointSelection()
|
||||
{
|
||||
#if 0
|
||||
SpinBox *sp_line_point =
|
||||
editor->get_as_node<SpinBox>("%line_index");
|
||||
sp_line_point->disconnect("value_changed", this,
|
||||
"handle_value_change");
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -218,10 +230,6 @@ public:
|
||||
: Object()
|
||||
, editor(editor)
|
||||
{
|
||||
Button *cancel_button = editor->get_as_node<Button>(
|
||||
"%road_lines_create_new_cancel");
|
||||
LineEdit *line_name = editor->get_as_node<LineEdit>(
|
||||
"%road_lines_create_new_line_name");
|
||||
Button *cancel_metadata_button = editor->get_as_node<Button>(
|
||||
"%road_lines_metadata_cancel");
|
||||
Button *update_metadata_button = editor->get_as_node<Button>(
|
||||
@@ -230,9 +238,6 @@ public:
|
||||
"%road_lines_metadata_edit");
|
||||
Button *line_buildings_close =
|
||||
editor->get_as_node<Button>("%line_buildings_close");
|
||||
cancel_button->connect("pressed", this, "cancel_handler");
|
||||
line_name->connect("text_entered", this, "entered_handler");
|
||||
line_name->connect("text_changed", this, "changed_handler");
|
||||
cancel_metadata_button->connect("pressed", this,
|
||||
"cancel_metadata_handler");
|
||||
update_metadata_button->connect("pressed", this,
|
||||
@@ -252,10 +257,6 @@ public:
|
||||
"%road_lines_metadata_update");
|
||||
Button *cancel_metadata_button = editor->get_as_node<Button>(
|
||||
"%road_lines_metadata_cancel");
|
||||
Button *cancel_button = editor->get_as_node<Button>(
|
||||
"%road_lines_create_new_cancel");
|
||||
LineEdit *line_name = editor->get_as_node<LineEdit>(
|
||||
"%road_lines_create_new_line_name");
|
||||
line_buildings_close->disconnect(
|
||||
"pressed", this, "line_buildings_close_handler");
|
||||
metadata_edit->disconnect("text_changed", this,
|
||||
@@ -264,9 +265,6 @@ public:
|
||||
"update_metadata_handler");
|
||||
cancel_metadata_button->disconnect("pressed", this,
|
||||
"cancel_metadata_handler");
|
||||
line_name->disconnect("text_changed", this, "changed_handler");
|
||||
line_name->disconnect("text_entered", this, "entered_handler");
|
||||
cancel_button->disconnect("pressed", this, "cancel_handler");
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -298,53 +296,6 @@ protected:
|
||||
items->add_item(key);
|
||||
}
|
||||
}
|
||||
void cancel_handler()
|
||||
{
|
||||
LineEdit *line_name = editor->get_as_node<LineEdit>(
|
||||
"%road_lines_create_new_line_name");
|
||||
editor->get_as_node<Control>("%road_lines_base")->show();
|
||||
editor->get_as_node<Control>("%road_lines_create_new_line_dlg")
|
||||
->hide();
|
||||
line_name->set_text("");
|
||||
}
|
||||
bool check_line_name(const String &line_name)
|
||||
{
|
||||
String text = line_name.strip_edges();
|
||||
if (editor->line_exists(text) || text.length() < 5 ||
|
||||
text.find("_") < 0 || text.ends_with("_"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
void entered_handler(const String &new_text)
|
||||
{
|
||||
String text = new_text.strip_edges();
|
||||
LineEdit *line_name = editor->get_as_node<LineEdit>(
|
||||
"%road_lines_create_new_line_name");
|
||||
if (!check_line_name(text)) {
|
||||
line_name->add_color_override(
|
||||
"font_color", Color(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
return;
|
||||
} else
|
||||
line_name->remove_color_override("font_color");
|
||||
editor->create_new_line_at_cursor(text);
|
||||
/* clean text */
|
||||
line_name->set_text("");
|
||||
editor->get_as_node<Control>("%road_lines_base")->show();
|
||||
editor->get_as_node<Control>("%road_lines_create_new_line_dlg")
|
||||
->hide();
|
||||
}
|
||||
void changed_handler(const String &new_text)
|
||||
{
|
||||
LineEdit *line_name = editor->get_as_node<LineEdit>(
|
||||
"%road_lines_create_new_line_name");
|
||||
String text = new_text.strip_edges();
|
||||
if (!check_line_name(text)) {
|
||||
line_name->add_color_override(
|
||||
"font_color", Color(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
return;
|
||||
} else
|
||||
line_name->remove_color_override("font_color");
|
||||
}
|
||||
void cancel_metadata_handler()
|
||||
{
|
||||
TextEdit *metadata_text = editor->get_as_node<TextEdit>(
|
||||
@@ -404,12 +355,6 @@ protected:
|
||||
}
|
||||
static void _bind_methods()
|
||||
{
|
||||
ClassDB::bind_method(D_METHOD("cancel_handler"),
|
||||
&HandleCreateNewLine::cancel_handler);
|
||||
ClassDB::bind_method(D_METHOD("entered_handler", "new_text"),
|
||||
&HandleCreateNewLine::entered_handler);
|
||||
ClassDB::bind_method(D_METHOD("changed_handler", "new_text"),
|
||||
&HandleCreateNewLine::changed_handler);
|
||||
ClassDB::bind_method(
|
||||
D_METHOD("cancel_metadata_handler"),
|
||||
&HandleCreateNewLine::cancel_metadata_handler);
|
||||
@@ -442,6 +387,12 @@ RoadLinesEditor::RoadLinesEditor(WorldEditor *editor)
|
||||
, filter_text("")
|
||||
, camera_moved(false)
|
||||
, update_roads(false)
|
||||
#if 0
|
||||
, cursor_pos{ 0, 0, 0 }
|
||||
, cursor_set(nullptr)
|
||||
, point_pos{ 0, 0, 0 }
|
||||
, point_set(nullptr)
|
||||
#endif
|
||||
, debug_road_nodes(false)
|
||||
, debug_road_edges(false)
|
||||
, debug_road_wedges(false)
|
||||
@@ -533,10 +484,8 @@ void RoadLinesEditor::update_line_geometry()
|
||||
}
|
||||
void RoadLinesEditor::update_line_index_ui()
|
||||
{
|
||||
RoadLinesData *rld = RoadLinesData::get_singleton();
|
||||
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
|
||||
sp_line_index->set_max(rld->lines(current_line).points.size() - 1);
|
||||
sp_line_index->set_min(0);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"road_lines_editor_update_line_index_ui", varray(current_line));
|
||||
}
|
||||
void RoadLinesEditor::select_line(const String &line_name)
|
||||
{
|
||||
@@ -546,8 +495,8 @@ void RoadLinesEditor::select_line(const String &line_name)
|
||||
if (current_line != line_name) {
|
||||
current_line = line_name;
|
||||
update_line_index_ui();
|
||||
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
|
||||
sp_line_index->set_value(0);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"road_lines_editor_clear_selected_line_ui", varray());
|
||||
/* as actual index of SpinBox might not change
|
||||
call point selection explicitly */
|
||||
set_line_index(0);
|
||||
@@ -577,9 +526,8 @@ void RoadLinesEditor::line_create_point()
|
||||
varray(current_line));
|
||||
update_line_geometry();
|
||||
update_line_index_ui();
|
||||
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
|
||||
sp_line_index->set_value(index + 1);
|
||||
// move_cursor_to_point();
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"road_lines_editor_set_line_index_ui", varray(line_index + 1));
|
||||
}
|
||||
|
||||
void RoadLinesEditor::line_delete_point()
|
||||
@@ -595,10 +543,11 @@ void RoadLinesEditor::line_delete_point()
|
||||
varray(current_line));
|
||||
update_line_geometry();
|
||||
update_line_index_ui();
|
||||
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
|
||||
sp_line_index->set_value(0);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"road_lines_editor_update_line_index_ui", varray(current_line));
|
||||
index = MAX(0, index - 1);
|
||||
sp_line_index->set_value(index);
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"road_lines_editor_set_line_index_ui", varray(index));
|
||||
}
|
||||
|
||||
static const String cursor_name = "%line_cursor";
|
||||
@@ -619,10 +568,7 @@ void RoadLinesEditor::set_point_to_cursor()
|
||||
|
||||
int RoadLinesEditor::get_line_index()
|
||||
{
|
||||
print_line("get_line_index");
|
||||
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
|
||||
int index = (int)sp_line_index->get_value();
|
||||
return index;
|
||||
return line_index;
|
||||
}
|
||||
|
||||
void RoadLinesEditor::move_cursor_to_point()
|
||||
@@ -739,14 +685,12 @@ void RoadLinesEditor::update_ui()
|
||||
{
|
||||
RoadLinesData *rld = RoadLinesData::get_singleton();
|
||||
get_as_node<Control>("%road_lines_base")->show();
|
||||
get_as_node<Control>("%road_lines_create_new_line_dlg")->hide();
|
||||
get_as_node<Control>("%road_lines_edit_metadata_dlg")->hide();
|
||||
get_as_node<Control>("%road_lines_buildings")->hide();
|
||||
ItemList *lines_list = get_as_node<ItemList>("%lines_list");
|
||||
PoolVector<String> elements;
|
||||
List<String> line_keys;
|
||||
rld->get_lines_key_list(&line_keys);
|
||||
List<String>::Element *e = line_keys.front();
|
||||
lines_list->clear();
|
||||
if (!re.is_valid())
|
||||
re.instance();
|
||||
re->compile(filter_text);
|
||||
@@ -763,14 +707,19 @@ void RoadLinesEditor::update_ui()
|
||||
}
|
||||
if (key == current_line)
|
||||
selected_index = index;
|
||||
lines_list->add_item(key);
|
||||
elements.push_back(key);
|
||||
e = e->next();
|
||||
index++;
|
||||
}
|
||||
#if 0
|
||||
if (selected_index >= 0)
|
||||
lines_list->set_current(selected_index);
|
||||
else
|
||||
lines_list->set_current(0);
|
||||
#endif
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"road_lines_editor_update_lines_list",
|
||||
varray(elements, selected_index));
|
||||
}
|
||||
|
||||
void RoadLinesEditor::create_new_line_at_cursor(const String &line_name)
|
||||
@@ -788,6 +737,7 @@ void RoadLinesEditor::create_new_line_at_cursor(const String &line_name)
|
||||
Transform cursor_position(Basis(), get_cursor_position());
|
||||
rline.points.push_back(cursor_position);
|
||||
rld->set_line(line_name, rline);
|
||||
assert(rld->has_line(line_name));
|
||||
update_line_index_ui();
|
||||
update_ui();
|
||||
}
|
||||
@@ -827,21 +777,31 @@ void RoadLinesEditor::set_point_position(const Vector3 &position)
|
||||
}
|
||||
void RoadLinesEditor::set_ui_cursor_position(const Vector3 &cursor_position)
|
||||
{
|
||||
LineEdit *cursor_x = get_as_node<LineEdit>("%cursor_x");
|
||||
LineEdit *cursor_y = get_as_node<LineEdit>("%cursor_y");
|
||||
LineEdit *cursor_z = get_as_node<LineEdit>("%cursor_z");
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"road_lines_editor_set_ui_cursor_position",
|
||||
varray(cursor_position));
|
||||
#if 0
|
||||
LineEdit *cursor_x = cursor_pos[0];
|
||||
LineEdit *cursor_y = cursor_pos[1];
|
||||
LineEdit *cursor_z = cursor_pos[2];
|
||||
cursor_x->set_text(String::num(cursor_position.x));
|
||||
cursor_y->set_text(String::num(cursor_position.y));
|
||||
cursor_z->set_text(String::num(cursor_position.z));
|
||||
#endif
|
||||
}
|
||||
void RoadLinesEditor::set_ui_point_position(const Vector3 &point_position)
|
||||
{
|
||||
LineEdit *point_x = get_as_node<LineEdit>("%point_x");
|
||||
LineEdit *point_y = get_as_node<LineEdit>("%point_y");
|
||||
LineEdit *point_z = get_as_node<LineEdit>("%point_z");
|
||||
EditorEvent::get_singleton()->event.emit(
|
||||
"road_lines_editor_set_ui_point_position",
|
||||
varray(point_position));
|
||||
#if 0
|
||||
LineEdit *point_x = point_pos[0];
|
||||
LineEdit *point_y = point_pos[1];
|
||||
LineEdit *point_z = point_pos[2];
|
||||
point_x->set_text(String::num(point_position.x));
|
||||
point_y->set_text(String::num(point_position.y));
|
||||
point_z->set_text(String::num(point_position.z));
|
||||
#endif
|
||||
}
|
||||
|
||||
void RoadLinesEditor::set_line_index(int index)
|
||||
@@ -851,6 +811,7 @@ void RoadLinesEditor::set_line_index(int index)
|
||||
assert(index < (int)rld->lines(current_line).points.size());
|
||||
Vector3 point_position = rld->lines(current_line).points[index].origin;
|
||||
Vector3 cursor_position = point_position;
|
||||
line_index = index;
|
||||
set_cursor_position(cursor_position);
|
||||
set_ui_cursor_position(cursor_position);
|
||||
set_ui_point_position(point_position);
|
||||
@@ -1150,5 +1111,55 @@ void RoadLinesEditor::event_handler(const String &event,
|
||||
rebuild_roads();
|
||||
} else if (event == "result:get_building_types") {
|
||||
/* TODO:: implement */
|
||||
#if 0
|
||||
} else if (event == "road_lines_setup_cursor_ui") {
|
||||
cursor_pos[0] = Object::cast_to<LineEdit>(args[0]);
|
||||
cursor_pos[1] = Object::cast_to<LineEdit>(args[1]);
|
||||
cursor_pos[2] = Object::cast_to<LineEdit>(args[2]);
|
||||
cursor_set = Object::cast_to<Button>(args[3]);
|
||||
assert(cursor_set);
|
||||
} else if (event == "road_lines_setup_point_ui") {
|
||||
point_pos[0] = Object::cast_to<LineEdit>(args[0]);
|
||||
point_pos[1] = Object::cast_to<LineEdit>(args[1]);
|
||||
point_pos[2] = Object::cast_to<LineEdit>(args[2]);
|
||||
point_set = Object::cast_to<Button>(args[3]);
|
||||
assert(cursor_set);
|
||||
#endif
|
||||
} else if (event == "road_lines_editor_set_cursor_position") {
|
||||
Vector3 position = args[0];
|
||||
set_cursor_position(position);
|
||||
} else if (event == "road_lines_editor_set_point_position") {
|
||||
Vector3 position = args[0];
|
||||
set_point_position(position);
|
||||
} else if (event == "road_lines_filter") {
|
||||
String text = args[1];
|
||||
line_list_filter_changed(text);
|
||||
} else if (event == "road_lines_editor_set_line_index") {
|
||||
int index = (int)args[1];
|
||||
set_line_index(index);
|
||||
} else if (event == "road_lines_create_new_line_name:entered") {
|
||||
String new_text = args[1];
|
||||
String text = new_text.strip_edges();
|
||||
LineEdit *le = Object::cast_to<LineEdit>(args[0]);
|
||||
if (line_exists(text) || text.length() < 5 ||
|
||||
text.find("_") < 0 || text.ends_with("_")) {
|
||||
le->add_color_override("font_color",
|
||||
Color(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
return;
|
||||
} else {
|
||||
le->remove_color_override("font_color");
|
||||
create_new_line_at_cursor(text);
|
||||
}
|
||||
} else if (event == "road_lines_create_new_line_name:changed") {
|
||||
String new_text = args[1];
|
||||
String text = new_text.strip_edges();
|
||||
LineEdit *le = Object::cast_to<LineEdit>(args[0]);
|
||||
if (line_exists(text) || text.length() < 5 ||
|
||||
text.find("_") < 0 || text.ends_with("_")) {
|
||||
le->add_color_override("font_color",
|
||||
Color(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
return;
|
||||
} else
|
||||
le->remove_color_override("font_color");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user