Working on building removal
This commit is contained in:
@@ -146,11 +146,12 @@ func select_building(xform, id, mid):
|
||||
selected_building = id
|
||||
selected_building_xform = xform
|
||||
print("selected id: ", id)
|
||||
for h in range($"%building_type".get_item_count()):
|
||||
var item = $"%building_type".get_item_text(h)
|
||||
if item == mid:
|
||||
$"%building_type".select(h)
|
||||
break
|
||||
$WorldEditor.select_building(xform, id, mid)
|
||||
# for h in range($"%building_type".get_item_count()):
|
||||
# var item = $"%building_type".get_item_text(h)
|
||||
# if item == mid:
|
||||
# $"%building_type".select(h)
|
||||
# break
|
||||
if !$building_cursor.visible:
|
||||
$building_cursor.show()
|
||||
$building_cursor.global_transform.origin = xform.origin
|
||||
|
||||
@@ -493,6 +493,14 @@ void StreamWorld::run_command(const String &command, const Array &args)
|
||||
" from: " + old_type + " to: " + new_type);
|
||||
} else if (command == "remove_building") {
|
||||
/* TODO: implement */
|
||||
if (args.size() == 0) {
|
||||
print_error("bad command: not enough args: " + command);
|
||||
return;
|
||||
}
|
||||
int id = args[0];
|
||||
unload_building(id);
|
||||
buildings.erase(buildings.begin() + id);
|
||||
update_items();
|
||||
} else if (command == "remove_generated_stuff") {
|
||||
remove_generated_stuff();
|
||||
update_items();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#undef NDEBUG
|
||||
#include <cassert>
|
||||
#include <core/object.h>
|
||||
#include <core/engine.h>
|
||||
#include <core/os/input.h>
|
||||
@@ -5,6 +7,7 @@
|
||||
#include <scene/gui/control.h>
|
||||
#include <scene/gui/box_container.h>
|
||||
#include <scene/gui/button.h>
|
||||
#include <scene/gui/option_button.h>
|
||||
#include <scene/main/viewport.h>
|
||||
#include <scene/3d/camera.h>
|
||||
#include <scene/scene_string_names.h>
|
||||
@@ -22,6 +25,7 @@ WorldEditor::WorldEditor()
|
||||
, dragging(false)
|
||||
, drag_delay(0.2f)
|
||||
, road_lines_editor(memnew(RoadLinesEditor(this)))
|
||||
, selected_building(-1)
|
||||
{
|
||||
if (!InputMap::get_singleton()->has_action("left"))
|
||||
InputMap::get_singleton()->add_action("left");
|
||||
@@ -96,6 +100,16 @@ 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()
|
||||
{
|
||||
}
|
||||
@@ -223,11 +237,42 @@ 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 (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");
|
||||
}
|
||||
}
|
||||
|
||||
int WorldEditor::get_current_mode() const
|
||||
{
|
||||
return current_mode;
|
||||
@@ -387,6 +432,15 @@ 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::_bind_methods()
|
||||
{
|
||||
ClassDB::bind_method(D_METHOD("editor_command", "command", "args"),
|
||||
@@ -403,8 +457,16 @@ 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")));
|
||||
|
||||
@@ -32,11 +32,17 @@ private:
|
||||
bool dragging;
|
||||
float drag_delay;
|
||||
RoadLinesEditor *road_lines_editor;
|
||||
int selected_building;
|
||||
Transform selected_building_xform;
|
||||
void delete_building_handler();
|
||||
|
||||
public:
|
||||
WorldEditor();
|
||||
virtual ~WorldEditor();
|
||||
void editor_command(const String &command, const Array &args);
|
||||
int get_camera_mode() const;
|
||||
int get_selected_building() const;
|
||||
Transform get_selected_building_xform() const;
|
||||
void select_building(const Transform &xform, int id, const String &mid);
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user