Getting room types from file

This commit is contained in:
2024-10-27 00:32:04 +03:00
parent 0356746749
commit 6eb584f73c
3 changed files with 111 additions and 52 deletions

View File

@@ -0,0 +1,23 @@
[rooms]
private = [
[200, "WC", { "window": false }],
[201, "Bathroom", { "window": false }],
[202, "Bedroom", { "window": true }],
[203, "Holding Cell", { "window": true }],
[204, "Torture Room", { "window": false }]
]
public = [
[300, "Living Room", { "window": true }],
[301, "Family Room", { "window": true }],
[302, "Kitchen", { "window": true }],
[303, "Dining Room", { "window": true }],
[304, "Enterance", { "window": true }],
[305, "Stair", { "window": true }],
[306, "Elevator", { "window": true }],
[307, "Storage Room", { "window": true }],
[308, "Cellar", { "window": true }],
[309, "Office", { "window": true }],
[310, "Server Room", { "window": true }],
[311, "Room", { "window": true }]
]

View File

@@ -23,6 +23,9 @@ class BuildingLayoutGraphUI : public Object {
Control *canvas_item;
Button *button;
String current_layout;
ConfigFile config;
Array public_rooms;
Array private_rooms;
public:
BuildingLayoutGraphUI(MainTabs *gui, WindowDialog *dlg)
@@ -33,6 +36,10 @@ public:
, button(nullptr)
{
dlg->connect("tree_entered", this, "tree_entered");
Error err = config.load("res://astream/building_layout.conf");
assert(err == OK);
public_rooms = config.get_value("rooms", "public", Array());
private_rooms = config.get_value("rooms", "private", Array());
}
void menu_pressed(int id, Control *button, const String &path)
{
@@ -79,6 +86,39 @@ public:
buildings_layout_zone>({ 1 });
}
} break;
default: {
int i;
int count = 0;
Array rooms;
rooms.append_array(private_rooms);
rooms.append_array(public_rooms);
int index = -1;
for (i = 0; i < rooms.size(); i++) {
Array room_data = rooms[i];
int room_id = room_data[0];
if (room_id == id) {
index = i;
break;
}
}
Array room = rooms[index];
String type_name = room[1];
Dictionary room_options = room[2];
bool window = room_options.get("window", false);
type_name = type_name.replace(" ", "_").to_lower();
base_e.children([type_name, &count](flecs::entity e) {
String name(e.name());
if (name.begins_with(type_name + "_" +
itos(count)))
count++;
});
String ename = type_name + "_" + itos(count);
flecs::entity new_e =
ecs.entity(ename.ascii().ptr()).child_of(base_e);
new_e.set<WorldEditor::components::buildings_layout_room>(
{ id, window });
} break;
}
update_graph();
}
@@ -325,65 +365,41 @@ public:
buildings_layout_zone>()
->type;
if (zone_type == 0) {
int i;
button->set_text(
button->get_text() +
"Private Zone\n");
for (i = 0;
i < private_rooms.size();
i++) {
Array room_data =
private_rooms[i];
int id = room_data[0];
String room_name =
room_data[1];
button->get_popup()->add_item(
"Create WC", 200);
button->get_popup()->add_item(
"Create Bathroom", 201);
button->get_popup()->add_item(
"Create Bedroom", 202);
button->get_popup()->add_item(
"Create Holding Cell",
203);
button->get_popup()->add_item(
"Create Torture Room",
203);
"Create " +
room_name,
id);
}
} else if (zone_type == 1) {
int i;
button->set_text(
button->get_text() +
"Public Zone\n");
for (i = 0;
i < public_rooms.size();
i++) {
Array room_data =
public_rooms[i];
int id = room_data[0];
String room_name =
room_data[1];
button->get_popup()->add_item(
"Create Living Room",
300);
button->get_popup()->add_item(
"Create Family Room",
301);
button->get_popup()->add_item(
"Create Kitchen", 302);
button->get_popup()->add_item(
"Create Dinging Room",
303);
button->get_popup()->add_item(
"Create Enterance",
304);
button->get_popup()->add_item(
"Create Stair", 305);
button->get_popup()->add_item(
"Create Elevator", 306);
button->get_popup()->add_item(
"Create Storage Room",
307);
button->get_popup()->add_item(
"Create Cellar", 308);
button->get_popup()->add_item(
"Create Office", 309);
button->get_popup()->add_item(
"Create Server Room",
310);
button->get_popup()->add_item(
"Create Room", 311);
PopupMenu *mp =
memnew(PopupMenu);
mp->add_child(memnew(LineEdit));
button->get_popup()->add_child(
mp);
mp->set_name("subedit");
button->get_popup()
->add_submenu_item(
"SubEdit Moo",
"subedit", 400);
"Create " +
room_name,
id);
}
}
button->set_text(button->get_text() +
String(e.name()));
@@ -398,6 +414,22 @@ public:
"Create hallway", 103);
#endif
}
if (e.has<WorldEditor::components::
buildings_layout_room>()) {
int room_type =
e.get<WorldEditor::components::
buildings_layout_room>()
->room_type;
button->set_text(button->get_text() +
"Room\n" +
String(e.name()));
PopupMenu *mp = memnew(PopupMenu);
mp->add_child(memnew(LineEdit));
button->get_popup()->add_child(mp);
mp->set_name("subedit");
button->get_popup()->add_submenu_item(
"SubEdit Moo", "subedit", 400);
}
#if 0
button->set_text(
button->get_text() + "size: \n" +

View File

@@ -82,6 +82,10 @@ public:
struct buildings_layout_floor {
int flags;
};
struct buildings_layout_room {
int room_type;
bool window;
};
};
};