diff --git a/godot/main/building_layout_editor.tscn b/godot/main/building_layout_editor.tscn index 5ce85f7..917e7de 100644 --- a/godot/main/building_layout_editor.tscn +++ b/godot/main/building_layout_editor.tscn @@ -87,8 +87,8 @@ scroll_horizontal_enabled = false [node name="layout_mesh_buttons" type="VBoxContainer" parent="VBoxContainer/ScrollContainer"] unique_name_in_owner = true -margin_right = 302.0 -margin_bottom = 168.0 +margin_right = 314.0 +margin_bottom = 100.0 rect_min_size = Vector2( 100, 0 ) size_flags_horizontal = 3 size_flags_vertical = 3 diff --git a/src/modules/stream/buildings/building_layout_editor.cpp b/src/modules/stream/buildings/building_layout_editor.cpp index d38c027..9379e03 100644 --- a/src/modules/stream/buildings/building_layout_editor.cpp +++ b/src/modules/stream/buildings/building_layout_editor.cpp @@ -1,5 +1,6 @@ #undef NDEBUG #include +#include #include
#include #include @@ -13,17 +14,6 @@ #include #include "building_layout_editor.h" -/* Taken from Godot code editor/editor_plugin.cpp */ - -BuildingLayoutEditor::BuildingLayoutEditor() - : meshes_ready(false) - , current_mode(-1) - , current_element_type("") - , current_element("") - , current_socket(-1) -{ -} - template T *get_as_node(const String &path) { Node *scene; @@ -43,6 +33,289 @@ template T *get_as_node(const String &path) return ret; } +class ElementData { +public: + static ElementData *singleton; + static ElementData *get_singleton() + { + if (!singleton) + singleton = memnew(ElementData); + return singleton; + } + static void cleanup() + { + if (singleton) + memdelete(singleton); + } + struct grid_element_type { + String name; + Transform sockets[ELEMENT_SOCKETS]; + }; + +protected: + HashMap element_type; + +public: + void get_key_list(List *keys) + { + element_type.get_key_list(keys); + } + void create_element_type(const String &key) + { + assert(!element_type.has(key)); + struct grid_element_type g; + g.name = key; + element_type[key] = g; + } + void set_element_type_socket(const String &key, int socket, + const Transform &xform) + { + assert(element_type.has(key)); + assert(socket >= 0 && socket < ELEMENT_SOCKETS); + element_type[key].sockets[socket] = xform; + } + void set_element_type_name(const String &key, const String &name) + { + assert(element_type.has(key)); + element_type[key].name = name; + } + bool has(const String &key) + { + return element_type.has(key); + } + Transform get_element_type_socket(const String &key, int socket) + { + assert(element_type.has(key)); + assert(socket >= 0 && socket < ELEMENT_SOCKETS); + return element_type[key].sockets[socket]; + } + int get_element_type_size() + { + return element_type.size(); + } +}; +ElementData *ElementData::singleton = nullptr; + +class ElementTypeEditor : public Object { + GDCLASS(ElementTypeEditor, Object) + BuildingLayoutEditor *editor; + String current_element_type; + int current_socket; + +public: + ElementTypeEditor(BuildingLayoutEditor *editor) + : Object() + , editor(editor) + , current_element_type("") + , current_socket(-1) + { + get_as_node("%element_type_list") + ->connect("item_selected", this, "select_element_type"); + get_as_node("%socket_list") + ->connect("item_selected", this, "select_socket"); + get_as_node