Almost separated the buildings editor
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <scene/scene_string_names.h>
|
||||
#include "road_lines_editor.h"
|
||||
#include "world_editor.h"
|
||||
#include "buildings_editor.h"
|
||||
|
||||
WorldEditor::WorldEditor()
|
||||
: Spatial()
|
||||
@@ -25,7 +26,7 @@ WorldEditor::WorldEditor()
|
||||
, dragging(false)
|
||||
, drag_delay(0.2f)
|
||||
, road_lines_editor(memnew(RoadLinesEditor(this)))
|
||||
, selected_building(-1)
|
||||
, buildings_editor(memnew(BuildingsEditor(this)))
|
||||
{
|
||||
if (!InputMap::get_singleton()->has_action("left"))
|
||||
InputMap::get_singleton()->add_action("left");
|
||||
@@ -47,11 +48,20 @@ WorldEditor::WorldEditor()
|
||||
InputMap::get_singleton()->add_action("editor_cam3");
|
||||
if (!InputMap::get_singleton()->has_action("mouse1"))
|
||||
InputMap::get_singleton()->add_action("mouse1");
|
||||
event.add_listener(this, &WorldEditor::event_signal_handler);
|
||||
}
|
||||
|
||||
WorldEditor::~WorldEditor()
|
||||
{
|
||||
memdelete(road_lines_editor);
|
||||
event.remove_listener(this, &WorldEditor::event_signal_handler);
|
||||
if (road_lines_editor) {
|
||||
memdelete(road_lines_editor);
|
||||
road_lines_editor = nullptr;
|
||||
}
|
||||
if (buildings_editor) {
|
||||
memdelete(buildings_editor);
|
||||
buildings_editor = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void WorldEditor::set_camera_mode(int mode)
|
||||
@@ -100,16 +110,6 @@ int WorldEditor::get_camera_mode() const
|
||||
return current_camera_mode;
|
||||
}
|
||||
|
||||
int WorldEditor::get_selected_building() const
|
||||
{
|
||||
return selected_building;
|
||||
}
|
||||
|
||||
Transform WorldEditor::get_selected_building_xform() const
|
||||
{
|
||||
return selected_building_xform;
|
||||
}
|
||||
|
||||
void WorldEditor::disable_all()
|
||||
{
|
||||
}
|
||||
@@ -143,13 +143,6 @@ void WorldEditor::mode_npc()
|
||||
disable_all();
|
||||
print_line("NPC");
|
||||
}
|
||||
enum {
|
||||
MODE_BUILDINGS = 2,
|
||||
MODE_NAVIGATION = 3,
|
||||
MODE_POI = 5,
|
||||
MODE_ROAD_LINES = 6,
|
||||
MODE_NPC = 7,
|
||||
};
|
||||
struct StringHasher {
|
||||
std::size_t operator()(const String &s) const
|
||||
{
|
||||
@@ -157,11 +150,11 @@ struct StringHasher {
|
||||
}
|
||||
};
|
||||
static std::unordered_map<String, int, StringHasher> modes = {
|
||||
{ "select_buildings", MODE_BUILDINGS },
|
||||
{ "select_navigation", MODE_NAVIGATION },
|
||||
{ "select_poi", MODE_POI },
|
||||
{ "select_road_lines", MODE_ROAD_LINES },
|
||||
{ "select_npc", MODE_NPC }
|
||||
{ "select_buildings", WorldEditor::MODE_BUILDINGS },
|
||||
{ "select_navigation", WorldEditor::MODE_NAVIGATION },
|
||||
{ "select_poi", WorldEditor::MODE_POI },
|
||||
{ "select_road_lines", WorldEditor::MODE_ROAD_LINES },
|
||||
{ "select_npc", WorldEditor::MODE_NPC }
|
||||
};
|
||||
void WorldEditor::tools_button(const String &button)
|
||||
{
|
||||
@@ -174,7 +167,7 @@ void WorldEditor::tools_button(const String &button)
|
||||
goto end;
|
||||
change[0] = current_mode;
|
||||
change[1] = modes[button];
|
||||
emit_signal("editor_event", "mode_change_pre", change);
|
||||
event.emit("mode_change_pre", change);
|
||||
switch (current_mode) {
|
||||
case MODE_ROAD_LINES:
|
||||
road_lines_editor->exit();
|
||||
@@ -197,7 +190,7 @@ void WorldEditor::tools_button(const String &button)
|
||||
mode_npc();
|
||||
break;
|
||||
}
|
||||
emit_signal("editor_event", "mode_change_post", change);
|
||||
event.emit("mode_change_post", change);
|
||||
current_mode = modes[button];
|
||||
end:;
|
||||
}
|
||||
@@ -237,8 +230,6 @@ void WorldEditor::editor_command(const String &command, const Array &args)
|
||||
if (stream_world) {
|
||||
stream_world->run_command(command, args);
|
||||
}
|
||||
} else if (command == "select_building") {
|
||||
select_building(args[0], args[1], args[2]);
|
||||
} else if (command == "remove_generated_stuff") {
|
||||
if (stream_world)
|
||||
stream_world->run_command(command, args);
|
||||
@@ -248,37 +239,17 @@ void WorldEditor::editor_command(const String &command, const Array &args)
|
||||
} else if (command == "remove_road_meshes") {
|
||||
if (stream_world)
|
||||
stream_world->run_command(command, args);
|
||||
} else if (road_lines_editor) {
|
||||
road_lines_editor->editor_command(command, args);
|
||||
}
|
||||
}
|
||||
|
||||
void WorldEditor::select_building(const Transform &xform, int id,
|
||||
const String &mid)
|
||||
{
|
||||
int i;
|
||||
selected_building_xform = xform;
|
||||
selected_building = id;
|
||||
print_line("selected id: " + itos(id));
|
||||
OptionButton *building_type = Object::cast_to<OptionButton>(
|
||||
get_node(NodePath("%building_type")));
|
||||
assert(building_type);
|
||||
for (i = 0; i < building_type->get_item_count(); i++) {
|
||||
const String &item = building_type->get_item_text(i);
|
||||
if (item == mid) {
|
||||
building_type->select(i);
|
||||
break;
|
||||
}
|
||||
/* TODO: set building cursor position to xform */
|
||||
Button *delete_button = Object::cast_to<Button>(
|
||||
get_node(NodePath("%buildings_delete_building")));
|
||||
assert(delete_button);
|
||||
delete_button->show();
|
||||
/* FIXME */
|
||||
if (!delete_button->is_connected("pressed", this,
|
||||
"delete_building_handler"))
|
||||
delete_button->connect("pressed", this,
|
||||
"delete_building_handler");
|
||||
} else if (command == "remove_building") {
|
||||
if (stream_world)
|
||||
stream_world->run_command(command, args);
|
||||
} else if (command == "remove_buildings_by_prefix") {
|
||||
if (stream_world)
|
||||
stream_world->run_command(command, args);
|
||||
} else {
|
||||
if (road_lines_editor)
|
||||
road_lines_editor->editor_command(command, args);
|
||||
if (buildings_editor)
|
||||
buildings_editor->editor_command(command, args);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,6 +258,11 @@ int WorldEditor::get_current_mode() const
|
||||
return current_mode;
|
||||
}
|
||||
|
||||
void WorldEditor::event_signal_handler(const String &event, const Array &args)
|
||||
{
|
||||
emit_signal("editor_event", event, args);
|
||||
}
|
||||
|
||||
StreamWorld *WorldEditor::get_stream_world()
|
||||
{
|
||||
return stream_world;
|
||||
@@ -295,7 +271,7 @@ StreamWorld *WorldEditor::get_stream_world()
|
||||
void WorldEditor::world_command_result(const String &what, const Array &data)
|
||||
{
|
||||
print_line("what: " + what);
|
||||
emit_signal("editor_event", "result:" + what, data);
|
||||
event.emit("result:" + what, data);
|
||||
}
|
||||
|
||||
void WorldEditor::_notification(int which)
|
||||
@@ -320,6 +296,14 @@ void WorldEditor::_notification(int which)
|
||||
}
|
||||
set_process_unhandled_input(true);
|
||||
set_physics_process(true);
|
||||
Spatial *cursor = Object::cast_to<Spatial>(
|
||||
get_node(NodePath("%building_cursor")));
|
||||
assert(cursor);
|
||||
cursor->hide();
|
||||
Spatial *rot_cursor = Object::cast_to<Spatial>(
|
||||
get_node(NodePath("%building_rot_cursor")));
|
||||
assert(rot_cursor);
|
||||
rot_cursor->hide();
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE:
|
||||
set_physics_process(false);
|
||||
@@ -342,8 +326,7 @@ void WorldEditor::_notification(int which)
|
||||
Vector2 position =
|
||||
get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
emit_signal("editor_event", "mouse_drag_off",
|
||||
args);
|
||||
event.emit("mouse_drag_off", args);
|
||||
}
|
||||
}
|
||||
Transform cam_xform = cam->get_global_transform();
|
||||
@@ -382,13 +365,15 @@ void WorldEditor::_notification(int which)
|
||||
cam->set_global_transform(cam_xform);
|
||||
Array move_args;
|
||||
move_args.push_back(cam_xform);
|
||||
emit_signal("editor_event",
|
||||
"editor_camera_moved", move_args);
|
||||
event.emit("editor_camera_moved", move_args);
|
||||
}
|
||||
}
|
||||
if (!dragging && drag_delay >= 0.0f)
|
||||
drag_delay -= delta;
|
||||
switch (current_mode) {
|
||||
case MODE_BUILDINGS:
|
||||
buildings_editor->update(delta);
|
||||
break;
|
||||
case MODE_ROAD_LINES:
|
||||
// print_line("current_mode: " + itos(current_mode));
|
||||
road_lines_editor->update(delta);
|
||||
@@ -415,13 +400,13 @@ void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
|
||||
Array args;
|
||||
Vector2 position = get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
emit_signal("editor_event", "mouse_press", args);
|
||||
this->event.emit("mouse_press", args);
|
||||
} else if (Input::get_singleton()->is_action_pressed("mouse1")) {
|
||||
if (dragging) {
|
||||
Array args;
|
||||
Vector2 position = get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
emit_signal("editor_event", "mouse_drag", args);
|
||||
this->event.emit("mouse_drag", args);
|
||||
} else {
|
||||
if (drag_delay < 0.0f && !dragging) {
|
||||
dragging = true;
|
||||
@@ -429,8 +414,7 @@ void WorldEditor::_unhandled_input(const Ref<InputEvent> &event)
|
||||
Vector2 position =
|
||||
get_viewport()->get_mouse_position();
|
||||
args.push_back(position);
|
||||
emit_signal("editor_event", "mouse_drag_on",
|
||||
args);
|
||||
this->event.emit("mouse_drag_on", args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,22 +427,6 @@ void WorldEditor::world_exited()
|
||||
stream_world = nullptr;
|
||||
}
|
||||
|
||||
void WorldEditor::delete_building_handler()
|
||||
{
|
||||
Array args, args2;
|
||||
args.push_back(selected_building);
|
||||
stream_world->run_command("remove_building", args);
|
||||
args2.push_back(selected_building_xform);
|
||||
stream_world->run_command("get_closest_building", args2);
|
||||
}
|
||||
|
||||
void WorldEditor::remove_buildings_by_prefix(const String &prefix)
|
||||
{
|
||||
Array args;
|
||||
args.push_back(prefix);
|
||||
stream_world->run_command("remove_buildings_by_prefix", args);
|
||||
}
|
||||
|
||||
void WorldEditor::_bind_methods()
|
||||
{
|
||||
ClassDB::bind_method(D_METHOD("editor_command", "command", "args"),
|
||||
@@ -475,16 +443,8 @@ void WorldEditor::_bind_methods()
|
||||
&WorldEditor::set_camera_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_camera_mode"),
|
||||
&WorldEditor::get_camera_mode);
|
||||
ClassDB::bind_method(D_METHOD("select_building", "xform", "id", "mid"),
|
||||
&WorldEditor::select_building);
|
||||
ClassDB::bind_method(D_METHOD("get_selected_building"),
|
||||
&WorldEditor::get_selected_building);
|
||||
ClassDB::bind_method(D_METHOD("get_selected_building_xform"),
|
||||
&WorldEditor::get_selected_building_xform);
|
||||
ClassDB::bind_method(D_METHOD("_unhandled_input", "event"),
|
||||
&WorldEditor::_unhandled_input);
|
||||
ClassDB::bind_method(D_METHOD("delete_building_handler"),
|
||||
&WorldEditor::delete_building_handler);
|
||||
ADD_SIGNAL(MethodInfo("editor_event",
|
||||
PropertyInfo(Variant::STRING, "event_name"),
|
||||
PropertyInfo(Variant::ARRAY, "args")));
|
||||
|
||||
Reference in New Issue
Block a user