Added initial implementation of world editor
This commit is contained in:
5
godot/main/editor.tscn
Normal file
5
godot/main/editor.tscn
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[gd_scene format=2]
|
||||||
|
|
||||||
|
[node name="editor" type="Spatial"]
|
||||||
|
|
||||||
|
[node name="WorldEditor" type="WorldEditor" parent="."]
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include "road_debug.h"
|
#include "road_debug.h"
|
||||||
|
#include "world_editor.h"
|
||||||
|
|
||||||
void register_stream_types()
|
void register_stream_types()
|
||||||
{
|
{
|
||||||
ClassDB::register_class<StreamWorld>();
|
ClassDB::register_class<StreamWorld>();
|
||||||
ClassDB::register_class<RoadDebug>();
|
ClassDB::register_class<RoadDebug>();
|
||||||
|
ClassDB::register_class<WorldEditor>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void unregister_stream_types()
|
void unregister_stream_types()
|
||||||
|
|||||||
171
src/modules/stream/world_editor.cpp
Normal file
171
src/modules/stream/world_editor.cpp
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
#include <core/object.h>
|
||||||
|
#include <scene/gui/control.h>
|
||||||
|
#include <scene/gui/box_container.h>
|
||||||
|
#include <scene/gui/button.h>
|
||||||
|
#include "world_editor.h"
|
||||||
|
|
||||||
|
WorldEditor::WorldEditor()
|
||||||
|
: Spatial()
|
||||||
|
, stream_world(nullptr)
|
||||||
|
, editor_menu(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldEditor::~WorldEditor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldEditor::disable_all()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldEditor::mode_buildings()
|
||||||
|
{
|
||||||
|
disable_all();
|
||||||
|
print_line("BUILDINGS");
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldEditor::mode_navigation()
|
||||||
|
{
|
||||||
|
disable_all();
|
||||||
|
print_line("NAVIGATION");
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldEditor::mode_poi()
|
||||||
|
{
|
||||||
|
disable_all();
|
||||||
|
print_line("POI");
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldEditor::mode_road_lines()
|
||||||
|
{
|
||||||
|
disable_all();
|
||||||
|
print_line("ROAD_LINES");
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
return (std::size_t)s.hash64();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
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 }
|
||||||
|
};
|
||||||
|
void WorldEditor::tools_button(const String &button)
|
||||||
|
{
|
||||||
|
print_line("tools_button: " + button);
|
||||||
|
if (modes.find(button) == modes.end())
|
||||||
|
goto end;
|
||||||
|
switch (modes[button]) {
|
||||||
|
case MODE_BUILDINGS:
|
||||||
|
mode_buildings();
|
||||||
|
break;
|
||||||
|
case MODE_NAVIGATION:
|
||||||
|
mode_navigation();
|
||||||
|
break;
|
||||||
|
case MODE_POI:
|
||||||
|
mode_poi();
|
||||||
|
break;
|
||||||
|
case MODE_ROAD_LINES:
|
||||||
|
mode_road_lines();
|
||||||
|
break;
|
||||||
|
case MODE_NPC:
|
||||||
|
mode_npc();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
end:;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CREATE_TOOLS_BUTTON(bname, btext) \
|
||||||
|
{ \
|
||||||
|
Vector<Variant> binds; \
|
||||||
|
binds.push_back(#bname); \
|
||||||
|
Button *bname = memnew(Button); \
|
||||||
|
bname->set_name(#bname); \
|
||||||
|
bname->set_text(btext); \
|
||||||
|
bname->set_custom_minimum_size(Vector2(188, 16)); \
|
||||||
|
bname->connect("pressed", this, "tools_button", binds); \
|
||||||
|
tools->add_child(bname); \
|
||||||
|
bname->update(); \
|
||||||
|
tools->update(); \
|
||||||
|
}
|
||||||
|
void WorldEditor::create_menu()
|
||||||
|
{
|
||||||
|
editor_menu = memnew(Control);
|
||||||
|
editor_menu->set_name("menu");
|
||||||
|
editor_menu->set_anchor(MARGIN_LEFT, 1.0f);
|
||||||
|
editor_menu->set_anchor(MARGIN_RIGHT, 1.0f);
|
||||||
|
editor_menu->set_anchor(MARGIN_BOTTOM, 1.0f);
|
||||||
|
editor_menu->set_anchor(MARGIN_TOP, 0.0f);
|
||||||
|
editor_menu->update();
|
||||||
|
VBoxContainer *tools = memnew(VBoxContainer);
|
||||||
|
Vector2 min_size = tools->get_minimum_size();
|
||||||
|
min_size.x = 200.0f;
|
||||||
|
min_size.y = 400.0f;
|
||||||
|
tools->set_custom_minimum_size(min_size);
|
||||||
|
tools->set_name("tools");
|
||||||
|
tools->set_anchor_and_margin(MARGIN_LEFT, 1.0f, -210.0f);
|
||||||
|
tools->set_anchor_and_margin(MARGIN_RIGHT, 1.0f, 0.0f);
|
||||||
|
tools->set_anchor_and_margin(MARGIN_BOTTOM, 1.0f, 0.0f);
|
||||||
|
tools->set_anchor_and_margin(MARGIN_TOP, 0.0f, 0.0f);
|
||||||
|
tools->set_mouse_filter(Control::MOUSE_FILTER_STOP);
|
||||||
|
editor_menu->add_child(tools);
|
||||||
|
|
||||||
|
CREATE_TOOLS_BUTTON(select_buildings, "Select Buildings");
|
||||||
|
CREATE_TOOLS_BUTTON(select_navigation, "Select Navigation");
|
||||||
|
CREATE_TOOLS_BUTTON(select_poi, "Select POI");
|
||||||
|
CREATE_TOOLS_BUTTON(select_road_lines, "Select Road Lines");
|
||||||
|
CREATE_TOOLS_BUTTON(select_npc, "Select NPC");
|
||||||
|
editor_menu->update();
|
||||||
|
tools->update();
|
||||||
|
editor_menu->update();
|
||||||
|
tools->update();
|
||||||
|
print_line("Created menu");
|
||||||
|
}
|
||||||
|
|
||||||
|
Control *WorldEditor::get_editor_menu()
|
||||||
|
{
|
||||||
|
if (!is_inside_tree())
|
||||||
|
return nullptr;
|
||||||
|
if (!editor_menu)
|
||||||
|
create_menu();
|
||||||
|
return editor_menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldEditor::_notification(int which)
|
||||||
|
{
|
||||||
|
switch (which) {
|
||||||
|
case NOTIFICATION_ENTER_TREE: {
|
||||||
|
Control *c = get_editor_menu();
|
||||||
|
if (c)
|
||||||
|
add_child(c);
|
||||||
|
} break;
|
||||||
|
case NOTIFICATION_EXIT_TREE:
|
||||||
|
if (editor_menu)
|
||||||
|
editor_menu->queue_delete();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldEditor::_bind_methods()
|
||||||
|
{
|
||||||
|
ClassDB::bind_method(D_METHOD("tools_button", "button"),
|
||||||
|
&WorldEditor::tools_button);
|
||||||
|
}
|
||||||
26
src/modules/stream/world_editor.h
Normal file
26
src/modules/stream/world_editor.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef WORLD_EDITOR_H
|
||||||
|
#define WORLD_EDITOR_H
|
||||||
|
#include <scene/3d/spatial.h>
|
||||||
|
#include "stream.h"
|
||||||
|
class WorldEditor : public Spatial {
|
||||||
|
GDCLASS(WorldEditor, Spatial)
|
||||||
|
protected:
|
||||||
|
StreamWorld *stream_world;
|
||||||
|
Control *editor_menu;
|
||||||
|
void disable_all();
|
||||||
|
void mode_buildings();
|
||||||
|
void mode_navigation();
|
||||||
|
void mode_poi();
|
||||||
|
void mode_road_lines();
|
||||||
|
void mode_npc();
|
||||||
|
void tools_button(const String &which);
|
||||||
|
void create_menu();
|
||||||
|
Control *get_editor_menu();
|
||||||
|
void _notification(int which);
|
||||||
|
static void _bind_methods();
|
||||||
|
|
||||||
|
public:
|
||||||
|
WorldEditor();
|
||||||
|
~WorldEditor();
|
||||||
|
};
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user