All editor is in c++ now
This commit is contained in:
@@ -27,17 +27,17 @@ extends Spatial
|
||||
# get_viewport().get_camera().global_transform.origin.x += event.relative.x
|
||||
# get_viewport().get_camera().global_transform.origin.z -= event.relative.y
|
||||
|
||||
func _ready():
|
||||
for b in [
|
||||
$"%select_buildings",
|
||||
$"%select_navigation",
|
||||
$"%select_poi",
|
||||
$"%select_road_lines",
|
||||
$"%select_npc",
|
||||
$"%buildings_save",
|
||||
]:
|
||||
b.connect("pressed", $WorldEditor, "editor_command", [b.name, []])
|
||||
$WorldEditor.connect("editor_event", self, "editor_event")
|
||||
#func _ready():
|
||||
# for b in [
|
||||
# $"%select_buildings",
|
||||
# $"%select_navigation",
|
||||
# $"%select_poi",
|
||||
# $"%select_road_lines",
|
||||
# $"%select_npc",
|
||||
# $"%buildings_save",
|
||||
# ]:
|
||||
# b.connect("pressed", $WorldEditor, "editor_command", [b.name, []])
|
||||
# $WorldEditor.connect("editor_event", self, "editor_event")
|
||||
# for k in vmode.keys():
|
||||
# vmode[k].hide()
|
||||
# $"%building_cursor".hide()
|
||||
|
||||
@@ -16,6 +16,53 @@
|
||||
#include "editor_event.h"
|
||||
#include "buildings_editor.h"
|
||||
|
||||
class HandleCommandButton : public Object {
|
||||
GDCLASS(HandleCommandButton, Object)
|
||||
WorldEditor *editor;
|
||||
String button_path;
|
||||
String command;
|
||||
Array command_args;
|
||||
Button *get_button()
|
||||
{
|
||||
Button *button = Object::cast_to<Button>(
|
||||
editor->get_node(NodePath(button_path)));
|
||||
assert(button);
|
||||
return button;
|
||||
}
|
||||
void button_handler()
|
||||
{
|
||||
editor->editor_command(command, command_args);
|
||||
}
|
||||
|
||||
public:
|
||||
HandleCommandButton(WorldEditor *editor, const String &button_path,
|
||||
const String &command,
|
||||
const Array &command_args = Array())
|
||||
: Object()
|
||||
, editor(editor)
|
||||
, button_path(button_path)
|
||||
, command(command)
|
||||
, command_args(command_args)
|
||||
{
|
||||
if (!get_button()->is_connected("pressed", this,
|
||||
"button_handler"))
|
||||
get_button()->connect("pressed", this,
|
||||
"button_handler");
|
||||
}
|
||||
virtual ~HandleCommandButton()
|
||||
{
|
||||
if (get_button()->is_connected("pressed", this,
|
||||
"button_handler"))
|
||||
get_button()->disconnect("pressed", this,
|
||||
"button_handler");
|
||||
}
|
||||
static void _bind_methods()
|
||||
{
|
||||
ClassDB::bind_method(D_METHOD("button_handler"),
|
||||
&HandleCommandButton::button_handler);
|
||||
}
|
||||
};
|
||||
|
||||
WorldEditor::WorldEditor()
|
||||
: Spatial()
|
||||
, stream_world(nullptr)
|
||||
@@ -341,6 +388,15 @@ void WorldEditor::world_command_result(const String &what, const Array &data)
|
||||
EditorEvent::get_singleton()->event.emit("result:" + what, data);
|
||||
}
|
||||
|
||||
static std::vector<String> tool_buttons = {
|
||||
"%select_buildings"
|
||||
"%select_navigation",
|
||||
"%select_poi",
|
||||
"%select_road_lines",
|
||||
"%select_npc",
|
||||
"%buildings_save",
|
||||
};
|
||||
std::vector<HandleCommandButton *> tool_handlers;
|
||||
void WorldEditor::_notification(int which)
|
||||
{
|
||||
switch (which) {
|
||||
@@ -351,6 +407,12 @@ void WorldEditor::_notification(int which)
|
||||
Node *base = get_parent();
|
||||
int count = base->get_child_count();
|
||||
int i;
|
||||
for (i = 0; i < (int)tool_buttons.size(); i++) {
|
||||
String bname =
|
||||
get_node(NodePath(tool_buttons[i]))->get_name();
|
||||
tool_handlers.push_back(memnew(HandleCommandButton(
|
||||
this, tool_buttons[i], bname)));
|
||||
}
|
||||
for (i = 0; i < count; i++) {
|
||||
Node *node = base->get_child(i);
|
||||
StreamWorld *sw = Object::cast_to<StreamWorld>(node);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <cassert>
|
||||
#include <list>
|
||||
#include <scene/3d/spatial.h>
|
||||
#include "editor_mixin.h"
|
||||
#include "stream.h"
|
||||
class RoadLinesEditor;
|
||||
class BuildingsEditor;
|
||||
@@ -52,4 +53,5 @@ public:
|
||||
int get_current_mode() const;
|
||||
void event_signal_handler(const String &event, const Array &args);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user