Line filter is implemented

This commit is contained in:
2024-09-01 06:13:06 +03:00
parent 0e819d6e7e
commit 818c21ecac
3 changed files with 348 additions and 132 deletions

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=2]
[gd_scene load_steps=16 format=2]
[ext_resource path="res://main/editor.gd" type="Script" id=1]
[ext_resource path="res://terrain/terrain_draw.png" type="Image" id=2]
@@ -44,6 +44,9 @@ extents = Vector3( 50, 1, 50 )
[sub_resource type="CubeMesh" id=13]
size = Vector3( 4, 4, 120 )
[sub_resource type="CubeMesh" id=14]
size = Vector3( 3, 60, 3 )
[node name="editor" type="Spatial"]
script = ExtResource( 1 )
@@ -53,10 +56,10 @@ script = ExtResource( 1 )
anchor_left = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -160.0
margin_left = -232.0
[node name="ColorRect" type="ColorRect" parent="VBoxContainer"]
margin_right = 162.0
margin_right = 232.0
margin_bottom = 30.0
rect_min_size = Vector2( 160, 30 )
size_flags_horizontal = 3
@@ -77,58 +80,58 @@ valign = 1
[node name="select_buildings" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 34.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 54.0
text = "Buildings Mode"
[node name="select_navigation" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 58.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 78.0
text = "Navigation Mode"
[node name="select_poi" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 82.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 102.0
text = "POI Mode"
[node name="select_road_lines" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 106.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 126.0
text = "Road Lines Mode"
[node name="select_npc" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 130.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 150.0
text = "NPC Mode"
[node name="v_buildings" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 154.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 274.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_buildings"]
margin_right = 162.0
margin_right = 232.0
margin_bottom = 4.0
[node name="Label" type="Label" parent="VBoxContainer/v_buildings"]
margin_top = 8.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 22.0
text = "Buildings mode"
[node name="buildings_edit_mode" type="OptionButton" parent="VBoxContainer/v_buildings"]
unique_name_in_owner = true
margin_top = 26.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 46.0
text = "Select"
items = [ "Select", null, false, 0, null, "Move", null, false, 1, null, "Rotate", null, false, 2, null ]
@@ -136,193 +139,300 @@ selected = 0
[node name="Label2" type="Label" parent="VBoxContainer/v_buildings"]
margin_top = 50.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 64.0
text = "Building type"
[node name="building_type" type="OptionButton" parent="VBoxContainer/v_buildings"]
unique_name_in_owner = true
margin_top = 68.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 88.0
text = "Building Type"
[node name="HSeparator2" type="HSeparator" parent="VBoxContainer/v_buildings"]
margin_top = 92.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 96.0
[node name="buildings_save" type="Button" parent="VBoxContainer/v_buildings"]
unique_name_in_owner = true
margin_top = 100.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 120.0
text = "Save Buildings"
[node name="v_navigation" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 278.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 300.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_navigation"]
margin_right = 162.0
margin_right = 232.0
margin_bottom = 4.0
[node name="Label" type="Label" parent="VBoxContainer/v_navigation"]
margin_top = 8.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 22.0
text = "Navigation mode"
[node name="v_poi" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 304.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 326.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_poi"]
margin_right = 162.0
margin_right = 232.0
margin_bottom = 4.0
[node name="Label" type="Label" parent="VBoxContainer/v_poi"]
margin_top = 8.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 22.0
text = "POI mode"
[node name="v_road_lines" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 330.0
margin_right = 162.0
margin_bottom = 724.0
margin_right = 232.0
margin_bottom = 712.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_road_lines"]
margin_right = 162.0
margin_right = 232.0
margin_bottom = 4.0
[node name="road_lines_base" type="PanelContainer" parent="VBoxContainer/v_road_lines"]
unique_name_in_owner = true
margin_top = 8.0
margin_right = 162.0
margin_bottom = 328.0
margin_right = 232.0
margin_bottom = 316.0
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/v_road_lines/road_lines_base"]
margin_left = 7.0
margin_top = 7.0
margin_right = 155.0
margin_bottom = 313.0
margin_right = 225.0
margin_bottom = 301.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="road_lines_menu_block" type="HBoxContainer" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
unique_name_in_owner = true
margin_right = 218.0
margin_bottom = 20.0
[node name="road_lines_file_menu" type="MenuButton" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_menu_block"]
unique_name_in_owner = true
margin_right = 35.0
margin_bottom = 20.0
focus_mode = 2
text = "File"
items = [ "Save Lines", null, 0, false, false, 101, 0, null, "", false ]
[node name="road_lines_edit_menu" type="MenuButton" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_menu_block"]
unique_name_in_owner = true
margin_left = 39.0
margin_right = 75.0
margin_bottom = 20.0
focus_mode = 2
text = "Edit"
items = [ "Undo", null, 0, false, false, 201, 0, null, "", false ]
[node name="road_lines_point_menu" type="MenuButton" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_menu_block"]
unique_name_in_owner = true
margin_left = 79.0
margin_right = 124.0
margin_bottom = 20.0
text = "Point"
items = [ "", null, 0, false, false, 0, 0, null, "", true, "Create", null, 0, false, false, 11, 0, null, "", false, "Remove", null, 0, false, false, 12, 0, null, "", false, "", null, 0, false, false, 3, 0, null, "", true, "Point To Cursor", null, 0, false, false, 51, 0, null, "", false, "Cursor To Point", null, 0, false, false, 52, 0, null, "", false, "Item 6", null, 0, false, false, 6, 0, null, "", false, "Item 7", null, 0, false, false, 7, 0, null, "", false ]
[node name="road_lines_line_menu" type="MenuButton" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_menu_block"]
unique_name_in_owner = true
margin_left = 128.0
margin_right = 167.0
margin_bottom = 20.0
focus_mode = 2
text = "Line"
items = [ "Create", null, 0, false, false, 21, 0, null, "", false, "Delete", null, 0, false, false, 22, 0, null, "", false ]
[node name="HSeparator3" type="HSeparator" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
margin_top = 24.0
margin_right = 218.0
margin_bottom = 28.0
[node name="Label" type="Label" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
margin_right = 148.0
margin_bottom = 14.0
margin_top = 32.0
margin_right = 218.0
margin_bottom = 46.0
text = "Road Lines mode"
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
margin_top = 50.0
margin_right = 218.0
margin_bottom = 74.0
[node name="Label" type="Label" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/HBoxContainer"]
margin_top = 5.0
margin_right = 41.0
margin_bottom = 19.0
text = "Filter: "
[node name="road_lines_filter" type="LineEdit" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
margin_left = 45.0
margin_right = 218.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="lines_list" type="ItemList" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
unique_name_in_owner = true
margin_top = 18.0
margin_right = 148.0
margin_bottom = 118.0
rect_min_size = Vector2( 0, 100 )
margin_top = 78.0
margin_right = 218.0
margin_bottom = 158.0
rect_min_size = Vector2( 0, 80 )
size_flags_horizontal = 3
[node name="line_index" type="SpinBox" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
unique_name_in_owner = true
margin_top = 122.0
margin_right = 148.0
margin_bottom = 146.0
[node name="road_lines_set_point" type="Button" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
unique_name_in_owner = true
margin_top = 150.0
margin_right = 148.0
margin_bottom = 170.0
text = "Set Point To Cursor"
[node name="road_lines_move_cursor" type="Button" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
unique_name_in_owner = true
margin_top = 174.0
margin_right = 148.0
margin_bottom = 194.0
text = "Move Cursor To Point"
margin_top = 162.0
margin_right = 218.0
margin_bottom = 186.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
margin_top = 190.0
margin_right = 218.0
margin_bottom = 194.0
[node name="Label2" type="Label" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
margin_top = 198.0
margin_right = 148.0
margin_bottom = 202.0
margin_right = 218.0
margin_bottom = 212.0
text = "Cursor position"
[node name="road_lines_create_point" type="Button" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
[node name="road_lines_cursor_position" type="VBoxContainer" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
unique_name_in_owner = true
margin_top = 206.0
margin_right = 148.0
margin_bottom = 226.0
text = "Create Point"
margin_top = 216.0
margin_right = 218.0
margin_bottom = 240.0
[node name="road_lines_remove_point" type="Button" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_cursor_position"]
margin_right = 218.0
margin_bottom = 24.0
[node name="cursor_x" type="LineEdit" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_cursor_position/HBoxContainer"]
unique_name_in_owner = true
margin_top = 230.0
margin_right = 148.0
margin_bottom = 250.0
text = "Remove Point"
margin_right = 58.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="HSeparator2" type="HSeparator" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
margin_top = 254.0
margin_right = 148.0
margin_bottom = 258.0
[node name="road_lines_create_new_line" type="Button" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
[node name="cursor_y" type="LineEdit" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_cursor_position/HBoxContainer"]
unique_name_in_owner = true
margin_top = 262.0
margin_right = 148.0
margin_bottom = 282.0
text = "Creeate New Line"
margin_left = 62.0
margin_right = 120.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="road_lines_delete_line" type="Button" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
[node name="cursor_z" type="LineEdit" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_cursor_position/HBoxContainer"]
unique_name_in_owner = true
margin_top = 286.0
margin_right = 148.0
margin_bottom = 306.0
text = "Delete Line"
margin_left = 124.0
margin_right = 182.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="road_lines_set_cursor_position" type="Button" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_cursor_position/HBoxContainer"]
unique_name_in_owner = true
margin_left = 186.0
margin_right = 218.0
margin_bottom = 24.0
text = "Set"
[node name="HSeparator4" type="HSeparator" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
margin_top = 244.0
margin_right = 218.0
margin_bottom = 248.0
[node name="Label3" type="Label" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
margin_top = 252.0
margin_right = 218.0
margin_bottom = 266.0
text = "Point position"
[node name="road_lines_point_position" type="VBoxContainer" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer"]
unique_name_in_owner = true
margin_top = 270.0
margin_right = 218.0
margin_bottom = 294.0
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_point_position"]
margin_right = 218.0
margin_bottom = 24.0
[node name="point_x" type="LineEdit" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_point_position/HBoxContainer2"]
unique_name_in_owner = true
margin_right = 58.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="point_y" type="LineEdit" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_point_position/HBoxContainer2"]
unique_name_in_owner = true
margin_left = 62.0
margin_right = 120.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="point_z" type="LineEdit" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_point_position/HBoxContainer2"]
unique_name_in_owner = true
margin_left = 124.0
margin_right = 182.0
margin_bottom = 24.0
size_flags_horizontal = 3
[node name="road_lines_set_point_position" type="Button" parent="VBoxContainer/v_road_lines/road_lines_base/VBoxContainer/road_lines_point_position/HBoxContainer2"]
unique_name_in_owner = true
margin_left = 186.0
margin_right = 218.0
margin_bottom = 24.0
text = "Set"
[node name="road_lines_create_new_line_dlg" type="PanelContainer" parent="VBoxContainer/v_road_lines"]
unique_name_in_owner = true
margin_top = 332.0
margin_right = 162.0
margin_bottom = 394.0
margin_top = 320.0
margin_right = 232.0
margin_bottom = 382.0
[node name="v" type="VBoxContainer" parent="VBoxContainer/v_road_lines/road_lines_create_new_line_dlg"]
margin_left = 7.0
margin_top = 7.0
margin_right = 155.0
margin_right = 225.0
margin_bottom = 55.0
[node name="road_lines_create_new_line_name" type="LineEdit" parent="VBoxContainer/v_road_lines/road_lines_create_new_line_dlg/v"]
unique_name_in_owner = true
margin_right = 148.0
margin_right = 218.0
margin_bottom = 24.0
[node name="road_lines_create_new_cancel" type="Button" parent="VBoxContainer/v_road_lines/road_lines_create_new_line_dlg/v"]
unique_name_in_owner = true
margin_top = 28.0
margin_right = 148.0
margin_right = 218.0
margin_bottom = 48.0
text = "Cancel"
[node name="v_npc" type="VBoxContainer" parent="VBoxContainer"]
unique_name_in_owner = true
margin_top = 728.0
margin_right = 162.0
margin_bottom = 750.0
margin_top = 716.0
margin_right = 232.0
margin_bottom = 738.0
[node name="HSeparator" type="HSeparator" parent="VBoxContainer/v_npc"]
margin_right = 162.0
margin_right = 232.0
margin_bottom = 4.0
[node name="Label" type="Label" parent="VBoxContainer/v_npc"]
margin_top = 8.0
margin_right = 162.0
margin_right = 232.0
margin_bottom = 22.0
text = "NPC mode"
@@ -367,20 +477,6 @@ monitoring = false
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
shape = SubResource( 12 )
[node name="line_cursor" type="MeshInstance" parent="."]
unique_name_in_owner = true
mesh = SubResource( 10 )
material/0 = SubResource( 11 )
[node name="Area" type="Area" parent="line_cursor"]
collision_layer = 32768
collision_mask = 32768
monitoring = false
[node name="CollisionShape" type="CollisionShape" parent="line_cursor/Area"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
shape = SubResource( 12 )
[node name="building_rot_cursor" type="Spatial" parent="."]
[node name="building_rot_cursor" type="MeshInstance" parent="building_rot_cursor"]
@@ -397,3 +493,20 @@ monitoring = false
[node name="CollisionShape" type="CollisionShape" parent="building_rot_cursor/building_rot_cursor/Area"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
shape = SubResource( 12 )
[node name="line_cursor" type="Spatial" parent="."]
unique_name_in_owner = true
[node name="Area" type="Area" parent="line_cursor"]
collision_layer = 32768
collision_mask = 32768
monitoring = false
[node name="CollisionShape" type="CollisionShape" parent="line_cursor/Area"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0 )
shape = SubResource( 12 )
[node name="mi" type="MeshInstance" parent="line_cursor"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 30, 0 )
mesh = SubResource( 14 )
material/0 = SubResource( 11 )

View File

@@ -5,11 +5,13 @@
#include <scene/gui/button.h>
#include <scene/gui/line_edit.h>
#include <scene/gui/spin_box.h>
#include <scene/gui/menu_button.h>
#include <scene/3d/immediate_geometry.h>
#include <scene/3d/camera.h>
#include <core/io/config_file.h>
#include <core/os/file_access.h>
#include <core/io/json.h>
#include <modules/regex/regex.h>
#include "world_editor.h"
#include "from_string.h"
#include "road_lines_editor.h"
@@ -75,19 +77,23 @@ public:
: Object()
, editor(editor)
{
Node *lines_list_node =
editor->scene()->get_node(NodePath("%lines_list"));
LineEdit *filter =
editor->get_as_node<LineEdit>("%road_lines_filter");
filter->connect("text_changed", this, "filter_handler");
filter->connect("text_entered", this, "filter_handler");
ItemList *lines_list =
Object::cast_to<ItemList>(lines_list_node);
editor->get_as_node<ItemList>("%lines_list");
lines_list->connect("item_selected", this, "handler");
}
virtual ~HandleSelection()
{
Node *lines_list_node =
editor->scene()->get_node(NodePath("%lines_list"));
ItemList *lines_list =
Object::cast_to<ItemList>(lines_list_node);
editor->get_as_node<ItemList>("%lines_list");
lines_list->disconnect("item_selected", this, "handler");
LineEdit *filter =
editor->get_as_node<LineEdit>("%road_lines_filter");
filter->disconnect("text_entered", this, "filter_handler");
filter->disconnect("text_changed", this, "filter_handler");
}
protected:
@@ -95,16 +101,20 @@ protected:
{
if (index < 0)
return;
Node *lines_list_node =
editor->scene()->get_node(NodePath("%lines_list"));
ItemList *lines_list =
Object::cast_to<ItemList>(lines_list_node);
editor->get_as_node<ItemList>("%lines_list");
editor->select_line(lines_list->get_item_text(index));
}
void filter_handler(const String &text)
{
editor->line_list_filter_changed(text);
}
static void _bind_methods()
{
ClassDB::bind_method(D_METHOD("handler", "index"),
&HandleSelection::handler);
ClassDB::bind_method(D_METHOD("filter_handler", "text"),
&HandleSelection::filter_handler);
}
};
@@ -121,16 +131,9 @@ public:
editor->get_as_node<SpinBox>("%line_index");
sp_line_point->connect("value_changed", this,
"handle_value_change");
Button *bt_line_set_point =
editor->get_as_node<Button>("%road_lines_set_point");
bt_line_set_point->connect("pressed", this, "handle_set_point");
}
virtual ~HandlePointSelection()
{
Button *bt_line_set_point =
editor->get_as_node<Button>("%road_lines_set_point");
bt_line_set_point->disconnect("pressed", this,
"handle_set_point");
SpinBox *sp_line_point =
editor->get_as_node<SpinBox>("%line_index");
sp_line_point->disconnect("value_changed", this,
@@ -147,6 +150,10 @@ protected:
{
editor->set_point_to_cursor();
}
void handle_move_cursor()
{
editor->move_cursor_to_point();
}
static void _bind_methods()
{
ClassDB::bind_method(
@@ -154,6 +161,8 @@ protected:
&HandlePointSelection::handle_value_change);
ClassDB::bind_method(D_METHOD("handle_set_point"),
&HandlePointSelection::handle_set_point);
ClassDB::bind_method(D_METHOD("handle_move_cursor"),
&HandlePointSelection::handle_move_cursor);
}
};
@@ -166,21 +175,31 @@ public:
: Object()
, editor(editor)
{
Button *main_button = editor->get_as_node<Button>(
"%road_lines_create_new_line");
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>(
"%road_lines_create_new_line_name");
main_button->connect("pressed", this, "main_handler");
cancel_button->connect("pressed", this, "cancel_handler");
line_name->connect("text_entered", this, "entered_handler");
line_name->connect("text_changed", this, "changed_handler");
}
virtual ~HandleCreateNewLine()
{
Button *main_button = editor->get_as_node<Button>(
"%road_lines_create_new_line");
int i;
Button *cancel_button = editor->get_as_node<Button>(
"%road_lines_create_new_cancel");
LineEdit *line_name = editor->get_as_node<LineEdit>(
@@ -188,15 +207,50 @@ public:
line_name->disconnect("text_changed", this, "changed_handler");
line_name->disconnect("text_entered", this, "entered_handler");
cancel_button->disconnect("pressed", this, "cancel_handler");
main_button->disconnect("pressed", this, "main_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:
void main_handler()
void main_handler(int id)
{
switch (id) {
case 11:
/* TODO: create point */
break;
case 12:
/* TODO: 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")
editor->get_as_node<Control>(
"%road_lines_create_new_line_dlg")
->show();
break;
case 22:
/* TODO: delete line */
break;
case 51:
/* TODO: point to cursor */
editor->set_point_to_cursor();
break;
case 52:
/* TODO: cursor to point */
editor->move_cursor_to_point();
break;
default:
print_line("menu option pressed: " + itos(id));
}
}
void cancel_handler()
{
@@ -248,7 +302,7 @@ protected:
}
static void _bind_methods()
{
ClassDB::bind_method(D_METHOD("main_handler"),
ClassDB::bind_method(D_METHOD("main_handler", "id"),
&HandleCreateNewLine::main_handler);
ClassDB::bind_method(D_METHOD("cancel_handler"),
&HandleCreateNewLine::cancel_handler);
@@ -267,6 +321,7 @@ RoadLinesEditor::RoadLinesEditor(WorldEditor *editor)
: active(false)
, editor(editor)
, cursor_enabled(false)
, filter_text("")
{
}
@@ -274,6 +329,8 @@ RoadLinesEditor::~RoadLinesEditor()
{
if (active && editor->is_inside_tree())
deactivate();
if (re.is_valid())
re.unref();
}
Node *RoadLinesEditor::scene()
@@ -359,6 +416,16 @@ void RoadLinesEditor::set_point_to_cursor()
update_line_geometry();
}
void RoadLinesEditor::move_cursor_to_point()
{
print_line("move_cursor_to_point");
Spatial *cursor = get_as_node<Spatial>("%line_cursor");
SpinBox *sp_line_index = get_as_node<SpinBox>("%line_index");
int index = (int)sp_line_index->get_value();
Transform xform(Basis(), lines[current_line].points[index].origin);
cursor->set_global_transform(xform);
}
void RoadLinesEditor::update(float delta)
{
if (!active)
@@ -387,7 +454,7 @@ void RoadLinesEditor::editor_command(const String &command, const Array &args)
void RoadLinesEditor::editor_event(const String &event, const Array &args)
{
print_line("RoadLinesEditor::event: " + event);
if (event == "mouse_press") {
if (event == "mouse_press" || event == "mouse_drag") {
if (cursor_enabled) {
/* Raycasting outside physics process */
Spatial *cursor = get_as_node<Spatial>("%line_cursor");
@@ -400,6 +467,17 @@ void RoadLinesEditor::editor_event(const String &event, const Array &args)
editor->get_world()->get_direct_space_state();
PhysicsDirectSpaceState::RayResult result;
Set<RID> exclude;
space_state->intersect_ray(start, end, result, exclude,
(1 << 15) | (1 << 0), true,
true);
Vector3 result_pre;
if (result.rid == RID())
goto end;
result_pre = result.position;
result_pre.x = Math::stepify(result_pre.x, 2.0f);
result_pre.z = Math::stepify(result_pre.z, 2.0f);
start = result_pre + Vector3(0.0f, 200.0f, 0.0f);
end = result_pre - Vector3(0.0f, 200.0f, 0.0f);
space_state->intersect_ray(start, end, result, exclude,
(1 << 15) | (1 << 0), true,
true);
@@ -412,6 +490,7 @@ void RoadLinesEditor::editor_event(const String &event, const Array &args)
"line_cursor_motion",
pargs);
}
end:;
}
}
}
@@ -429,10 +508,20 @@ void RoadLinesEditor::update_ui()
lines.get_key_list(&line_keys);
List<String>::Element *e = line_keys.front();
lines_list->clear();
if (!re.is_valid())
re.instance();
re->compile(filter_text);
if (filter_text.length() > 0 && !re->is_valid())
return;
int selected_index = -1;
int index = 0;
while (e) {
String key = e->get();
Array matches = re->search_all(key);
if (filter_text.length() > 0 && matches.size() == 0) {
e = e->next();
continue;
}
if (key == current_line)
selected_index = index;
lines_list->add_item(key);
@@ -441,6 +530,8 @@ void RoadLinesEditor::update_ui()
}
if (selected_index >= 0)
lines_list->set_current(selected_index);
else
lines_list->set_current(0);
}
void RoadLinesEditor::create_new_line_at_cursor(const String &line_name)
@@ -460,6 +551,13 @@ void RoadLinesEditor::set_line_index(int index)
editor->emit_signal("editor_event", "line_cursor_motion", pargs);
}
void RoadLinesEditor::line_list_filter_changed(const String &text)
{
print_line("lines filter update: " + text);
filter_text = text.strip_edges();
update_ui();
}
void RoadLinesEditor::activate()
{
assert(!active);

View File

@@ -2,10 +2,13 @@
#define ROAD_LINES_EDITOR_H
#include "world_editor.h"
class ItemList;
class RegEx;
class RoadLinesEditor {
bool active;
WorldEditor *editor;
bool cursor_enabled;
String filter_text;
Ref<RegEx> re;
public:
RoadLinesEditor(WorldEditor *editor);
@@ -15,6 +18,7 @@ public:
void select_line(const String &line_name);
bool line_exists(const String &line_name);
void set_point_to_cursor();
void move_cursor_to_point();
void update(float delta);
void exit();
void editor_command(const String &command, const Array &args);
@@ -23,6 +27,7 @@ public:
void update_ui();
void create_new_line_at_cursor(const String &line_name);
void set_line_index(int index);
void line_list_filter_changed(const String &text);
template <class T> T *get_as_node(const String &path);
protected: