Removed script from editor

This commit is contained in:
2024-09-20 16:06:27 +03:00
parent 43c312e371
commit 9ad8bb2620
8 changed files with 336 additions and 97 deletions

View File

@@ -51,6 +51,7 @@ WorldEditor::WorldEditor()
InputMap::get_singleton()->add_action("mouse1");
EditorEvent::get_singleton()->event.add_listener(
this, &WorldEditor::event_signal_handler);
print_line("constructed");
}
WorldEditor::~WorldEditor()
@@ -65,6 +66,7 @@ WorldEditor::~WorldEditor()
memdelete(buildings_editor);
buildings_editor = nullptr;
}
print_line("destructed");
}
void WorldEditor::set_camera_mode(int mode)
@@ -159,6 +161,13 @@ static std::unordered_map<String, int, StringHasher> modes = {
{ "select_road_lines", WorldEditor::MODE_ROAD_LINES },
{ "select_npc", WorldEditor::MODE_NPC }
};
static std::unordered_map<int, String> vmode = { { 2, "%v_buildings" },
{ 3, "%v_navigation" },
{ 5, "%v_poi" },
{ 6, "%v_road_lines" },
{ 7, "%v_npc" } };
void WorldEditor::tools_button(const String &button)
{
Array change;
@@ -166,8 +175,11 @@ void WorldEditor::tools_button(const String &button)
print_line("tools_button: " + button);
if (modes.find(button) == modes.end())
goto end;
assert(modes[button] >= 0);
if (current_mode == modes[button])
goto end;
print_line("mode change: " + itos(current_mode) + " " +
itos(modes[button]));
change[0] = current_mode;
change[1] = modes[button];
EditorEvent::get_singleton()->event.emit("mode_change_pre", change);
@@ -197,7 +209,9 @@ void WorldEditor::tools_button(const String &button)
break;
}
EditorEvent::get_singleton()->event.emit("mode_change_post", change);
assert(modes[button] >= 0);
current_mode = modes[button];
assert(current_mode >= 0);
end:;
}
@@ -269,6 +283,50 @@ int WorldEditor::get_current_mode() const
void WorldEditor::event_signal_handler(const String &event, const Array &args)
{
if (event == "mode_change_pre") {
int prev_mode = args[0];
if (prev_mode == -1) {
auto pt = vmode.begin();
while (pt != vmode.end()) {
auto data = *pt;
Control *p = Object::cast_to<Control>(
get_node(NodePath(data.second)));
assert(p);
p->hide();
pt++;
}
} else {
Control *p = Object::cast_to<Control>(
get_node(NodePath(vmode[prev_mode])));
assert(p);
p->hide();
}
} else if (event == "mode_change_post") {
int mode_next = args[1];
Control *p = Object::cast_to<Control>(
get_node(NodePath(vmode[mode_next])));
assert(p);
p->show();
switch (mode_next) {
case 2:
editor_command("get_building_types", Array());
break;
case 6:
editor_command("get_lines_list", Array());
break;
}
} else if (event == "editor_camera_moved") {
Camera *cam = get_viewport()->get_camera();
Spatial *area = Object::cast_to<Spatial>(
get_node(NodePath("%selection_area")));
assert(cam);
assert(area);
Transform area_transform = area->get_global_transform();
const Transform &cam_transform = cam->get_global_transform();
area_transform.origin.x = cam_transform.origin.x;
area_transform.origin.z = cam_transform.origin.z;
area->set_global_transform(area_transform);
}
emit_signal("editor_event", event, args);
}
@@ -287,6 +345,9 @@ void WorldEditor::_notification(int which)
{
switch (which) {
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
Node *base = get_parent();
int count = base->get_child_count();
int i;
@@ -303,6 +364,24 @@ void WorldEditor::_notification(int which)
"world_command_result");
}
}
auto pt = vmode.begin();
while (pt != vmode.end()) {
auto data = *pt;
Control *p = Object::cast_to<Control>(
get_node(NodePath(data.second)));
assert(p);
p->hide();
pt++;
}
Spatial *building_cursor = Object::cast_to<Spatial>(
get_node(NodePath("%building_cursor")));
assert(building_cursor);
building_cursor->hide();
Spatial *line_cursor = Object::cast_to<Spatial>(
get_node(NodePath("%line_cursor")));
assert(line_cursor);
line_cursor->hide();
set_process_unhandled_input(true);
set_physics_process(true);
Spatial *cursor = Object::cast_to<Spatial>(
@@ -319,6 +398,9 @@ void WorldEditor::_notification(int which)
set_process_unhandled_input(false);
break;
case NOTIFICATION_PHYSICS_PROCESS: {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
if (!is_inside_tree())
return;
Camera *cam = get_viewport()->get_camera();
@@ -359,7 +441,6 @@ void WorldEditor::_notification(int which)
buildings_editor->update(delta);
break;
case MODE_ROAD_LINES:
// print_line("current_mode: " + itos(current_mode));
road_lines_editor->update(delta);
break;
}