Fixed lots of problems
This commit is contained in:
@@ -1,39 +1,58 @@
|
|||||||
[layouts]
|
[layouts]
|
||||||
|
|
||||||
entries=[ {
|
entries=[ {
|
||||||
"children": [ 1, 2, 3 ],
|
"children": [ 2 ],
|
||||||
"floor_index": 0,
|
|
||||||
"index": 0,
|
"index": 0,
|
||||||
|
"name": "v2",
|
||||||
|
"type": "layout"
|
||||||
|
}, {
|
||||||
|
"children": [ 3, 4, 5 ],
|
||||||
|
"floor_index": 0,
|
||||||
|
"index": 1,
|
||||||
"name": "v1",
|
"name": "v1",
|
||||||
"type": "layout"
|
"type": "layout"
|
||||||
}, {
|
}, {
|
||||||
"children": [ 4, 5, 6 ],
|
"children": [ 6 ],
|
||||||
"index": 1,
|
"index": 2,
|
||||||
|
"name": "zone_0",
|
||||||
|
"type": "zone",
|
||||||
|
"zone_type": 1
|
||||||
|
}, {
|
||||||
|
"children": [ 7, 8, 9 ],
|
||||||
|
"index": 3,
|
||||||
"name": "zone_0",
|
"name": "zone_0",
|
||||||
"type": "zone",
|
"type": "zone",
|
||||||
"zone_type": 0
|
"zone_type": 0
|
||||||
}, {
|
}, {
|
||||||
"children": [ 7, 8, 9, 10 ],
|
"children": [ 10, 11, 12, 13 ],
|
||||||
"index": 2,
|
"index": 4,
|
||||||
"name": "zone_1",
|
"name": "zone_1",
|
||||||
"type": "zone",
|
"type": "zone",
|
||||||
"zone_type": 1
|
"zone_type": 1
|
||||||
}, {
|
}, {
|
||||||
"children": [ 11, 12 ],
|
"children": [ 14, 15 ],
|
||||||
"index": 3,
|
"index": 5,
|
||||||
"name": "unit_0",
|
"name": "unit_0",
|
||||||
"type": "unit"
|
"type": "unit"
|
||||||
}, {
|
}, {
|
||||||
|
"children": [ 16 ],
|
||||||
|
"index": 6,
|
||||||
|
"name": "stair_0",
|
||||||
|
"room_area": 0.0,
|
||||||
|
"room_type": 305,
|
||||||
|
"type": "room",
|
||||||
|
"window": true
|
||||||
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 4,
|
"index": 7,
|
||||||
"name": "wc_0",
|
"name": "wc_0",
|
||||||
"room_area": 4.0,
|
"room_area": 16.0,
|
||||||
"room_type": 200,
|
"room_type": 200,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": false
|
"window": false
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 5,
|
"index": 8,
|
||||||
"name": "bathroom_0",
|
"name": "bathroom_0",
|
||||||
"room_area": 16.0,
|
"room_area": 16.0,
|
||||||
"room_type": 201,
|
"room_type": 201,
|
||||||
@@ -41,31 +60,31 @@ entries=[ {
|
|||||||
"window": false
|
"window": false
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 6,
|
"index": 9,
|
||||||
"name": "bedroom_0",
|
"name": "bedroom_0",
|
||||||
"room_area": 36.0,
|
"room_area": 64.0,
|
||||||
"room_type": 202,
|
"room_type": 202,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 7,
|
"index": 10,
|
||||||
"name": "living_room_0",
|
"name": "living_room_0",
|
||||||
"room_area": 36.0,
|
"room_area": 144.0,
|
||||||
"room_type": 300,
|
"room_type": 300,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 8,
|
"index": 11,
|
||||||
"name": "kitchen_0",
|
"name": "kitchen_0",
|
||||||
"room_area": 16.0,
|
"room_area": 64.0,
|
||||||
"room_type": 302,
|
"room_type": 302,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 9,
|
"index": 12,
|
||||||
"name": "storage_room_0",
|
"name": "storage_room_0",
|
||||||
"room_area": 16.0,
|
"room_area": 16.0,
|
||||||
"room_type": 307,
|
"room_type": 307,
|
||||||
@@ -73,27 +92,33 @@ entries=[ {
|
|||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 10,
|
"index": 13,
|
||||||
"name": "enterance_0",
|
"name": "enterance_0",
|
||||||
"room_area": 16.0,
|
"room_area": 16.0,
|
||||||
"room_type": 304,
|
"room_type": 304,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ 13, 14, 15 ],
|
"children": [ 17, 18, 19 ],
|
||||||
"index": 11,
|
"index": 14,
|
||||||
"name": "zone_0",
|
"name": "zone_0",
|
||||||
"type": "zone",
|
"type": "zone",
|
||||||
"zone_type": 0
|
"zone_type": 0
|
||||||
}, {
|
}, {
|
||||||
"children": [ 16, 17 ],
|
"children": [ 20, 21 ],
|
||||||
"index": 12,
|
"index": 15,
|
||||||
"name": "zone_1",
|
"name": "zone_1",
|
||||||
"type": "zone",
|
"type": "zone",
|
||||||
"zone_type": 1
|
"zone_type": 1
|
||||||
}, {
|
}, {
|
||||||
|
"children": [ 22 ],
|
||||||
|
"floor_index": 0,
|
||||||
|
"index": 16,
|
||||||
|
"name": "floor_0",
|
||||||
|
"type": "floor"
|
||||||
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 13,
|
"index": 17,
|
||||||
"name": "bedroom_0",
|
"name": "bedroom_0",
|
||||||
"room_area": 36.0,
|
"room_area": 36.0,
|
||||||
"room_type": 202,
|
"room_type": 202,
|
||||||
@@ -101,7 +126,7 @@ entries=[ {
|
|||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 14,
|
"index": 18,
|
||||||
"name": "bathroom_0",
|
"name": "bathroom_0",
|
||||||
"room_area": 16.0,
|
"room_area": 16.0,
|
||||||
"room_type": 201,
|
"room_type": 201,
|
||||||
@@ -109,7 +134,7 @@ entries=[ {
|
|||||||
"window": false
|
"window": false
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 15,
|
"index": 19,
|
||||||
"name": "wc_0",
|
"name": "wc_0",
|
||||||
"room_area": 4.0,
|
"room_area": 4.0,
|
||||||
"room_type": 200,
|
"room_type": 200,
|
||||||
@@ -117,7 +142,7 @@ entries=[ {
|
|||||||
"window": false
|
"window": false
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 16,
|
"index": 20,
|
||||||
"name": "living_room_0",
|
"name": "living_room_0",
|
||||||
"room_area": 36.0,
|
"room_area": 36.0,
|
||||||
"room_type": 300,
|
"room_type": 300,
|
||||||
@@ -125,10 +150,27 @@ entries=[ {
|
|||||||
"window": true
|
"window": true
|
||||||
}, {
|
}, {
|
||||||
"children": [ ],
|
"children": [ ],
|
||||||
"index": 17,
|
"index": 21,
|
||||||
"name": "kitchen_0",
|
"name": "kitchen_0",
|
||||||
"room_area": 16.0,
|
"room_area": 16.0,
|
||||||
"room_type": 302,
|
"room_type": 302,
|
||||||
"type": "room",
|
"type": "room",
|
||||||
"window": true
|
"window": true
|
||||||
|
}, {
|
||||||
|
"children": [ 23, 24 ],
|
||||||
|
"index": 22,
|
||||||
|
"name": "unit_0",
|
||||||
|
"type": "unit"
|
||||||
|
}, {
|
||||||
|
"children": [ ],
|
||||||
|
"index": 23,
|
||||||
|
"name": "zone_0",
|
||||||
|
"type": "zone",
|
||||||
|
"zone_type": 0
|
||||||
|
}, {
|
||||||
|
"children": [ ],
|
||||||
|
"index": 24,
|
||||||
|
"name": "zone_1",
|
||||||
|
"type": "zone",
|
||||||
|
"zone_type": 1
|
||||||
} ]
|
} ]
|
||||||
|
|||||||
@@ -51,58 +51,6 @@ const Array &BuildingLayoutGraph::get_public_rooms() const
|
|||||||
return public_rooms;
|
return public_rooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
flecs::entity
|
|
||||||
BuildingLayoutGraph::create_graph_entity(const String &base_path,
|
|
||||||
const String &entity_type)
|
|
||||||
{
|
|
||||||
flecs::world ecs = BaseData::get_singleton()->get();
|
|
||||||
flecs::entity base_e = ecs.lookup(base_path.ascii().ptr());
|
|
||||||
int count = 0;
|
|
||||||
const String &type_name = entity_type;
|
|
||||||
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);
|
|
||||||
return new_e;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingLayoutGraph::create_zone(const String &base_path, int zone_type)
|
|
||||||
{
|
|
||||||
flecs::entity new_e = create_graph_entity(base_path, "zone");
|
|
||||||
new_e.set<WorldEditor::components::buildings_layout_zone>(
|
|
||||||
{ zone_type });
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingLayoutGraph::create_unit(const String &base_path)
|
|
||||||
{
|
|
||||||
flecs::entity new_e = create_graph_entity(base_path, "unit");
|
|
||||||
new_e.set<WorldEditor::components::buildings_layout_unit>({ 0 });
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingLayoutGraph::create_floor(const String &base_path)
|
|
||||||
{
|
|
||||||
flecs::entity new_e = create_graph_entity(base_path, "floor");
|
|
||||||
new_e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingLayoutGraph::create_room(const String &base_path, int id)
|
|
||||||
{
|
|
||||||
Array room;
|
|
||||||
BuildingLayoutGraph::get_singleton()->get_room_data(id, room);
|
|
||||||
assert(!room.empty());
|
|
||||||
String type_name = room[1];
|
|
||||||
Dictionary room_options = room[2];
|
|
||||||
bool window = room_options.get("window", false);
|
|
||||||
type_name = type_name.replace(" ", "_").to_lower();
|
|
||||||
flecs::entity new_e = create_graph_entity(base_path, type_name);
|
|
||||||
new_e.set<WorldEditor::components::buildings_layout_room>(
|
|
||||||
{ id, window });
|
|
||||||
new_e.set<WorldEditor::components::buildings_layout_area>({ 0.0f });
|
|
||||||
}
|
|
||||||
|
|
||||||
void BuildingLayoutGraph::destroy_graph_entity(const String &path)
|
void BuildingLayoutGraph::destroy_graph_entity(const String &path)
|
||||||
{
|
{
|
||||||
flecs::world ecs = BaseData::get_singleton()->get();
|
flecs::world ecs = BaseData::get_singleton()->get();
|
||||||
@@ -202,32 +150,60 @@ void BuildingLayoutGraph::recalculate_size(const String &layout_name)
|
|||||||
while (!queue.empty()) {
|
while (!queue.empty()) {
|
||||||
flecs::entity e = queue.front()->get();
|
flecs::entity e = queue.front()->get();
|
||||||
queue.pop_front();
|
queue.pop_front();
|
||||||
int size = 1;
|
|
||||||
bool readd = false;
|
bool readd = false;
|
||||||
|
int size = 1;
|
||||||
e.children([&readd, &size, &queue](flecs::entity fe) {
|
e.children([&readd, &size, &queue](flecs::entity fe) {
|
||||||
|
print_line(String(fe.path()));
|
||||||
if (!fe.has<WorldEditor::components::
|
if (!fe.has<WorldEditor::components::
|
||||||
buildings_layout_graph_node>()) {
|
buildings_layout_graph_node>()) {
|
||||||
fe.set<WorldEditor::components::
|
|
||||||
buildings_layout_graph_node>(
|
|
||||||
{ 0, 0, 0 });
|
|
||||||
readd = true;
|
readd = true;
|
||||||
|
} else {
|
||||||
|
assert(fe.is_valid());
|
||||||
|
assert(fe.has<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>());
|
||||||
|
assert(fe.get<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>());
|
||||||
|
size += fe.get<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>()
|
||||||
|
->size;
|
||||||
|
queue.push_back(fe);
|
||||||
}
|
}
|
||||||
size += fe.get<WorldEditor::components::
|
|
||||||
buildings_layout_graph_node>()
|
|
||||||
->size;
|
|
||||||
queue.push_back(fe);
|
|
||||||
});
|
});
|
||||||
if (readd)
|
if (readd)
|
||||||
queue.push_back(e);
|
queue.push_back(e);
|
||||||
if (e.get<WorldEditor::components::buildings_layout_graph_node>()
|
if (!e.has<WorldEditor::components::
|
||||||
->size != size) {
|
buildings_layout_graph_node>()) {
|
||||||
e.get_mut<WorldEditor::components::
|
bool is_r = e.has<
|
||||||
|
WorldEditor::components::buildings_layout_room>();
|
||||||
|
bool is_z = e.has<
|
||||||
|
WorldEditor::components::buildings_layout_zone>();
|
||||||
|
bool is_u = e.has<
|
||||||
|
WorldEditor::components::buildings_layout_unit>();
|
||||||
|
bool is_f = e.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>();
|
||||||
|
if (is_r || is_z || is_u || is_f)
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>(
|
||||||
|
{ 0, 0, 0 });
|
||||||
|
queue.push_back(e);
|
||||||
|
} else {
|
||||||
|
assert(e.has<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>());
|
||||||
|
if (e.get<WorldEditor::components::
|
||||||
buildings_layout_graph_node>()
|
buildings_layout_graph_node>()
|
||||||
->size = size;
|
->size != size) {
|
||||||
if (e.parent()
|
e.get_mut<WorldEditor::components::
|
||||||
.has<WorldEditor::components::
|
buildings_layout_graph_node>()
|
||||||
buildings_layout_graph_node>())
|
->size = size;
|
||||||
queue.push_back(e);
|
e.modified<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>();
|
||||||
|
if (e.parent()
|
||||||
|
.has<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>())
|
||||||
|
queue.push_back(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,6 +232,8 @@ void BuildingLayoutGraph::update_button_positions(const String &layout_name)
|
|||||||
->y_pos = y;
|
->y_pos = y;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int offset = y;
|
int offset = y;
|
||||||
|
e.modified<
|
||||||
|
WorldEditor::components::buildings_layout_graph_node>();
|
||||||
e.children([depth, y, &count, &queue,
|
e.children([depth, y, &count, &queue,
|
||||||
&offset](flecs::entity fe) {
|
&offset](flecs::entity fe) {
|
||||||
int size = fe.get<WorldEditor::components::
|
int size = fe.get<WorldEditor::components::
|
||||||
@@ -412,14 +390,18 @@ void BuildingLayoutGraph::save_layouts()
|
|||||||
entry["floor_index"] = floor_index;
|
entry["floor_index"] = floor_index;
|
||||||
}
|
}
|
||||||
} else if (e.has<WorldEditor::components::
|
} else if (e.has<WorldEditor::components::
|
||||||
buildings_layout_floor_index>()) {
|
buildings_layout_floor>()) {
|
||||||
/* non-root floor */
|
/* non-root floor */
|
||||||
entry["type"] = "floor";
|
entry["type"] = "floor";
|
||||||
int floor_index =
|
if (e.has<WorldEditor::components::
|
||||||
e.get<WorldEditor::components::
|
buildings_layout_floor_index>()) {
|
||||||
buildings_layout_floor_index>()
|
int floor_index =
|
||||||
->index;
|
e.get<WorldEditor::components::
|
||||||
entry["floor_index"] = floor_index;
|
buildings_layout_floor_index>()
|
||||||
|
->index;
|
||||||
|
print_line("floor_index: " + itos(floor_index));
|
||||||
|
entry["floor_index"] = floor_index;
|
||||||
|
}
|
||||||
} else if (e.has<WorldEditor::components::
|
} else if (e.has<WorldEditor::components::
|
||||||
buildings_layout_zone>()) {
|
buildings_layout_zone>()) {
|
||||||
entry["type"] = "zone";
|
entry["type"] = "zone";
|
||||||
@@ -512,6 +494,8 @@ void BuildingLayoutGraph::load_layouts()
|
|||||||
} else
|
} else
|
||||||
e.set<WorldEditor::components::
|
e.set<WorldEditor::components::
|
||||||
buildings_layout_floor>({ 0 });
|
buildings_layout_floor>({ 0 });
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>({ 0, 0, 0 });
|
||||||
} else if (type == "floor") {
|
} else if (type == "floor") {
|
||||||
if (entry.has("floor_index")) {
|
if (entry.has("floor_index")) {
|
||||||
int floor_index = entry["floor_index"];
|
int floor_index = entry["floor_index"];
|
||||||
@@ -527,15 +511,21 @@ void BuildingLayoutGraph::load_layouts()
|
|||||||
buildings_layout_floor_index>(
|
buildings_layout_floor_index>(
|
||||||
{ 0 });
|
{ 0 });
|
||||||
}
|
}
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>({ 0, 0, 0 });
|
||||||
} else if (type == "zone") {
|
} else if (type == "zone") {
|
||||||
int zone_type = entry["zone_type"];
|
int zone_type = entry["zone_type"];
|
||||||
e.set<WorldEditor::components::buildings_layout_zone>(
|
e.set<WorldEditor::components::buildings_layout_zone>(
|
||||||
{ zone_type });
|
{ zone_type });
|
||||||
e.add<WorldEditor::components::buildings_layout_dirty>();
|
e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>({ 0, 0, 0 });
|
||||||
} else if (type == "unit") {
|
} else if (type == "unit") {
|
||||||
e.set<WorldEditor::components::buildings_layout_unit>(
|
e.set<WorldEditor::components::buildings_layout_unit>(
|
||||||
{ 0 });
|
{ 0 });
|
||||||
e.add<WorldEditor::components::buildings_layout_dirty>();
|
e.add<WorldEditor::components::buildings_layout_dirty>();
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>({ 0, 0, 0 });
|
||||||
} else if (type == "room") {
|
} else if (type == "room") {
|
||||||
int room_type = entry["room_type"];
|
int room_type = entry["room_type"];
|
||||||
bool window = entry["window"];
|
bool window = entry["window"];
|
||||||
@@ -550,6 +540,8 @@ void BuildingLayoutGraph::load_layouts()
|
|||||||
} else
|
} else
|
||||||
e.set<WorldEditor::components::
|
e.set<WorldEditor::components::
|
||||||
buildings_layout_area>({ 0.0f });
|
buildings_layout_area>({ 0.0f });
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_graph_node>({ 0, 0, 0 });
|
||||||
} else
|
} else
|
||||||
assert(false);
|
assert(false);
|
||||||
entity_index[index] = e;
|
entity_index[index] = e;
|
||||||
|
|||||||
@@ -49,6 +49,6 @@ public:
|
|||||||
void create_interior_tilemap(const String &layout_name);
|
void create_interior_tilemap(const String &layout_name);
|
||||||
int get_layout_count() const;
|
int get_layout_count() const;
|
||||||
struct graph_module {
|
struct graph_module {
|
||||||
graph_module(flecs::world ecs);
|
graph_module(flecs::world &ecs);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -35,48 +35,7 @@ public:
|
|||||||
{
|
{
|
||||||
dlg->connect("tree_entered", this, "tree_entered");
|
dlg->connect("tree_entered", this, "tree_entered");
|
||||||
}
|
}
|
||||||
void menu_pressed(int id, Control *button, const String &path)
|
void menu_pressed(int id, Control *button, const String &path);
|
||||||
{
|
|
||||||
assert(button);
|
|
||||||
print_line(itos(id));
|
|
||||||
print_line(path);
|
|
||||||
switch (id) {
|
|
||||||
case 100:
|
|
||||||
case 101:
|
|
||||||
case 102:
|
|
||||||
case 103:
|
|
||||||
case 104: {
|
|
||||||
int count = 0;
|
|
||||||
switch (id) {
|
|
||||||
case 100:
|
|
||||||
BuildingLayoutGraph::get_singleton()
|
|
||||||
->create_unit(path);
|
|
||||||
break;
|
|
||||||
case 101:
|
|
||||||
BuildingLayoutGraph::get_singleton()
|
|
||||||
->create_zone(path, 0);
|
|
||||||
break;
|
|
||||||
case 102:
|
|
||||||
BuildingLayoutGraph::get_singleton()
|
|
||||||
->create_zone(path, 1);
|
|
||||||
break;
|
|
||||||
case 104:
|
|
||||||
BuildingLayoutGraph::get_singleton()
|
|
||||||
->create_floor(path);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case 1000:
|
|
||||||
BuildingLayoutGraph::get_singleton()
|
|
||||||
->destroy_graph_entity(path);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
BuildingLayoutGraph::get_singleton()->create_room(path,
|
|
||||||
id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
update_graph();
|
|
||||||
}
|
|
||||||
void update_layout_item_list()
|
void update_layout_item_list()
|
||||||
{
|
{
|
||||||
ItemList *item_list =
|
ItemList *item_list =
|
||||||
@@ -104,6 +63,7 @@ public:
|
|||||||
EditorEvent::get_singleton()->event.emit(
|
EditorEvent::get_singleton()->event.emit(
|
||||||
"building_layouts_layout_selected",
|
"building_layouts_layout_selected",
|
||||||
varray(current_layout));
|
varray(current_layout));
|
||||||
|
print_line("select_layout: " + itos(id));
|
||||||
}
|
}
|
||||||
void handle_event(const String &event, const Vector<Variant> &args)
|
void handle_event(const String &event, const Vector<Variant> &args)
|
||||||
{
|
{
|
||||||
@@ -177,6 +137,12 @@ public:
|
|||||||
update_graph();
|
update_graph();
|
||||||
EditorEvent::get_singleton()->event.add_listener(
|
EditorEvent::get_singleton()->event.add_listener(
|
||||||
this, &BuildingLayoutGraphUI::handle_event);
|
this, &BuildingLayoutGraphUI::handle_event);
|
||||||
|
ItemList *item_list = gui->get_as_node<ItemList>(
|
||||||
|
"%building_layout_list");
|
||||||
|
if (!item_list->is_connected("item_selected", this,
|
||||||
|
"select_layout"))
|
||||||
|
item_list->connect("item_selected", this,
|
||||||
|
"select_layout");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void room_size_entered(float value, Control *item, const String &path)
|
void room_size_entered(float value, Control *item, const String &path)
|
||||||
@@ -184,12 +150,15 @@ public:
|
|||||||
print_line(String::num(value));
|
print_line(String::num(value));
|
||||||
flecs::world ecs = BaseData::get_singleton()->get();
|
flecs::world ecs = BaseData::get_singleton()->get();
|
||||||
flecs::entity e = ecs.lookup(path.ascii().ptr());
|
flecs::entity e = ecs.lookup(path.ascii().ptr());
|
||||||
float value_r = Math::ceil(Math::sqrt(Math::abs(value)));
|
int value_r = (int)Math::ceil(Math::sqrt(Math::abs(value)));
|
||||||
float value_div = Math::ceil(value_r / 2);
|
int pdiv = value_r % 4;
|
||||||
float area_final = (value_div * 2) * (value_div * 2);
|
int value_div = value_r / 4;
|
||||||
|
if (pdiv > 0)
|
||||||
|
value_div++;
|
||||||
|
float area_final = (value_div * 4) * (value_div * 4);
|
||||||
assert(e.is_valid());
|
assert(e.is_valid());
|
||||||
e.set<WorldEditor::components::buildings_layout_area>(
|
e.set<WorldEditor::components::buildings_layout_area>(
|
||||||
{ area_final });
|
{ MAX(16.0f, area_final) });
|
||||||
print_line("data set room_size");
|
print_line("data set room_size");
|
||||||
}
|
}
|
||||||
void floor_index_entered(float value, Control *item, const String &path)
|
void floor_index_entered(float value, Control *item, const String &path)
|
||||||
@@ -207,233 +176,7 @@ public:
|
|||||||
Vector<Vector2> buttons;
|
Vector<Vector2> buttons;
|
||||||
#define DEPTH_MUL 160
|
#define DEPTH_MUL 160
|
||||||
#define Y_MUL 130
|
#define Y_MUL 130
|
||||||
void update_buttons(ColorRect *canvas)
|
void update_buttons(ColorRect *canvas);
|
||||||
{
|
|
||||||
assert(current_layout.length() > 0);
|
|
||||||
BuildingLayoutGraph::get_singleton()->recalculate_size(
|
|
||||||
current_layout);
|
|
||||||
BuildingLayoutGraph::get_singleton()->update_button_positions(
|
|
||||||
current_layout);
|
|
||||||
flecs::entity layout_e = get_current_layout();
|
|
||||||
List<flecs::entity> queue;
|
|
||||||
bool layout_empty = true;
|
|
||||||
queue.push_back(layout_e);
|
|
||||||
while (!queue.empty()) {
|
|
||||||
buttons.clear();
|
|
||||||
layout_empty = false;
|
|
||||||
flecs::entity e = queue.front()->get();
|
|
||||||
queue.pop_front();
|
|
||||||
if (!e.has<WorldEditor::components::
|
|
||||||
buildings_layout_graph_node>()) {
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
int depth = e.get<WorldEditor::components::
|
|
||||||
buildings_layout_graph_node>()
|
|
||||||
->depth;
|
|
||||||
int y = e.get<WorldEditor::components::
|
|
||||||
buildings_layout_graph_node>()
|
|
||||||
->y_pos;
|
|
||||||
/* make button here */
|
|
||||||
Vector2 pt(depth * DEPTH_MUL + 40, y * Y_MUL + 40);
|
|
||||||
if (pt.x + 16.0f >= canvas->get_size().x ||
|
|
||||||
pt.y + 16.0f >= canvas->get_size().y) {
|
|
||||||
Vector2 old_size = canvas->get_size();
|
|
||||||
Vector2 new_size(MAX(pt.x + 200.0f, old_size.x),
|
|
||||||
MAX(pt.y + 200.0f,
|
|
||||||
old_size.y));
|
|
||||||
Object::cast_to<Control>(canvas->get_parent())
|
|
||||||
->set_custom_minimum_size(new_size);
|
|
||||||
canvas->set_size(new_size);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
VBoxContainer *box = memnew(VBoxContainer);
|
|
||||||
MenuButton *button = memnew(MenuButton);
|
|
||||||
button->set_text("");
|
|
||||||
box->add_child(button);
|
|
||||||
canvas->add_child(box);
|
|
||||||
button->set_size(Vector2(80, 40));
|
|
||||||
box->set_position(pt);
|
|
||||||
box->update();
|
|
||||||
List<Pair<int, String> > menu_options;
|
|
||||||
List<Pair<int, String> >::Element *pe;
|
|
||||||
BuildingLayoutGraph::get_singleton()
|
|
||||||
->get_menu_entries(e, &menu_options);
|
|
||||||
pe = menu_options.front();
|
|
||||||
while (pe) {
|
|
||||||
if (pe->get().first < 0)
|
|
||||||
button->get_popup()
|
|
||||||
->add_separator();
|
|
||||||
else
|
|
||||||
button->get_popup()->add_item(
|
|
||||||
pe->get().second,
|
|
||||||
pe->get().first);
|
|
||||||
pe = pe->next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.has<WorldEditor::components::
|
|
||||||
buildings_layout_floor>()) {
|
|
||||||
button->set_text(button->get_text() +
|
|
||||||
"Floor\n" +
|
|
||||||
String(e.name()));
|
|
||||||
std::vector<Variant> args = {
|
|
||||||
"Floor: ", "floor_index"
|
|
||||||
};
|
|
||||||
HashMap<String, Object *> save_data;
|
|
||||||
int floor_index =
|
|
||||||
e.get<WorldEditor::components::
|
|
||||||
buildings_layout_floor_index>()
|
|
||||||
->index;
|
|
||||||
ui_field::ui_field_builder(canvas, box,
|
|
||||||
"p{h{lx#$}}",
|
|
||||||
args.data(),
|
|
||||||
args.size(),
|
|
||||||
&save_data);
|
|
||||||
assert(save_data.has("floor_index"));
|
|
||||||
Object::cast_to<SpinBox>(
|
|
||||||
save_data["floor_index"])
|
|
||||||
->set_value(floor_index);
|
|
||||||
save_data["floor_index"]->connect(
|
|
||||||
"value_changed", this,
|
|
||||||
"floor_index_entered",
|
|
||||||
varray(save_data["floor_index"],
|
|
||||||
String(e.path())));
|
|
||||||
}
|
|
||||||
if (e.has<WorldEditor::components::
|
|
||||||
buildings_layout_unit>()) {
|
|
||||||
button->set_text(button->get_text() +
|
|
||||||
"Unit\n" +
|
|
||||||
String(e.name()));
|
|
||||||
if (e.has<WorldEditor::components::
|
|
||||||
buildings_layout_area>()) {
|
|
||||||
float area =
|
|
||||||
e.get<WorldEditor::components::
|
|
||||||
buildings_layout_area>()
|
|
||||||
->area;
|
|
||||||
std::vector<Variant> args = {
|
|
||||||
"Area: " + itos(area)
|
|
||||||
};
|
|
||||||
ui_field::ui_field_builder(
|
|
||||||
canvas, box, "l",
|
|
||||||
args.data(),
|
|
||||||
args.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e.has<WorldEditor::components::
|
|
||||||
buildings_layout_zone>()) {
|
|
||||||
int zone_type =
|
|
||||||
e.get<WorldEditor::components::
|
|
||||||
buildings_layout_zone>()
|
|
||||||
->type;
|
|
||||||
if (zone_type == 0) {
|
|
||||||
int i;
|
|
||||||
button->set_text(
|
|
||||||
button->get_text() +
|
|
||||||
"Private Zone\n");
|
|
||||||
} else if (zone_type == 1) {
|
|
||||||
int i;
|
|
||||||
button->set_text(
|
|
||||||
button->get_text() +
|
|
||||||
"Public Zone\n");
|
|
||||||
}
|
|
||||||
button->set_text(button->get_text() +
|
|
||||||
String(e.name()));
|
|
||||||
if (e.has<WorldEditor::components::
|
|
||||||
buildings_layout_area>()) {
|
|
||||||
float area =
|
|
||||||
e.get<WorldEditor::components::
|
|
||||||
buildings_layout_area>()
|
|
||||||
->area;
|
|
||||||
std::vector<Variant> args = {
|
|
||||||
"Area: " +
|
|
||||||
String::num(area)
|
|
||||||
};
|
|
||||||
ui_field::ui_field_builder(
|
|
||||||
canvas, box, "l",
|
|
||||||
args.data(),
|
|
||||||
args.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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() + " " +
|
|
||||||
itos(room_type)));
|
|
||||||
if (e.has<WorldEditor::components::
|
|
||||||
buildings_layout_area>()) {
|
|
||||||
std::vector<Variant> args = {
|
|
||||||
"Area: ", "area_value"
|
|
||||||
};
|
|
||||||
HashMap<String, Object *>
|
|
||||||
save_data;
|
|
||||||
float area =
|
|
||||||
e.get<WorldEditor::components::
|
|
||||||
buildings_layout_area>()
|
|
||||||
->area;
|
|
||||||
ui_field::ui_field_builder(
|
|
||||||
canvas, box,
|
|
||||||
"p{h{lx#$}}",
|
|
||||||
args.data(),
|
|
||||||
args.size(),
|
|
||||||
&save_data);
|
|
||||||
assert(save_data.has(
|
|
||||||
"area_value"));
|
|
||||||
Object::cast_to<SpinBox>(
|
|
||||||
save_data["area_value"])
|
|
||||||
->set_value(area);
|
|
||||||
save_data["area_value"]->connect(
|
|
||||||
"value_changed", this,
|
|
||||||
"room_size_entered",
|
|
||||||
varray(save_data["area_value"],
|
|
||||||
String(e.path())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (e.has<WorldEditor::components::
|
|
||||||
buildings_layout_floor_index>()) {
|
|
||||||
int index =
|
|
||||||
e.get<WorldEditor::components::
|
|
||||||
buildings_layout_floor_index>()
|
|
||||||
->index;
|
|
||||||
std::vector<Variant> args = {
|
|
||||||
"Floor index: " + itos(index)
|
|
||||||
};
|
|
||||||
ui_field::ui_field_builder(canvas, box,
|
|
||||||
"l",
|
|
||||||
args.data(),
|
|
||||||
args.size());
|
|
||||||
}
|
|
||||||
if (e.has<WorldEditor::components::
|
|
||||||
buildings_layout_floor_data>()) {
|
|
||||||
float area =
|
|
||||||
e.get<WorldEditor::components::
|
|
||||||
buildings_layout_area>()
|
|
||||||
->area;
|
|
||||||
int grid_size =
|
|
||||||
e.get<WorldEditor::components::
|
|
||||||
buildings_layout_floor_data>()
|
|
||||||
->grid_size;
|
|
||||||
std::vector<Variant> args = {
|
|
||||||
"Area: " + String::num(area),
|
|
||||||
"Grid size: " + itos(grid_size)
|
|
||||||
};
|
|
||||||
ui_field::ui_field_builder(canvas, box,
|
|
||||||
"ll",
|
|
||||||
args.data(),
|
|
||||||
args.size());
|
|
||||||
}
|
|
||||||
button->get_popup()->connect(
|
|
||||||
"id_pressed", this, "menu_pressed",
|
|
||||||
varray(button, String(e.path())));
|
|
||||||
}
|
|
||||||
e.children([&queue](flecs::entity fe) {
|
|
||||||
queue.push_back(fe);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void update_graph()
|
void update_graph()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -559,27 +302,7 @@ public:
|
|||||||
"l_p{v{li.#!lh{e#+!b#!Q}b#!Qb#!Q}}",
|
"l_p{v{li.#!lh{e#+!b#!Q}b#!Qb#!Q}}",
|
||||||
args_data.data(), args_data.size());
|
args_data.data(), args_data.size());
|
||||||
}
|
}
|
||||||
static void _bind_methods()
|
static void _bind_methods();
|
||||||
{
|
|
||||||
ClassDB::bind_method(D_METHOD("menu_pressed", "id", "button",
|
|
||||||
"path"),
|
|
||||||
&BuildingLayoutGraphUI::menu_pressed);
|
|
||||||
ClassDB::bind_method(D_METHOD("tree_entered"),
|
|
||||||
&BuildingLayoutGraphUI::tree_entered);
|
|
||||||
ClassDB::bind_method(D_METHOD("draw_graph"),
|
|
||||||
&BuildingLayoutGraphUI::draw_graph);
|
|
||||||
ClassDB::bind_method(D_METHOD("select_layout", "id"),
|
|
||||||
&BuildingLayoutGraphUI::select_layout);
|
|
||||||
ClassDB::bind_method(D_METHOD("room_size_entered", "value",
|
|
||||||
"item"
|
|
||||||
"path"),
|
|
||||||
&BuildingLayoutGraphUI::room_size_entered);
|
|
||||||
ClassDB::bind_method(
|
|
||||||
D_METHOD("floor_index_entered", "value",
|
|
||||||
"item"
|
|
||||||
"path"),
|
|
||||||
&BuildingLayoutGraphUI::floor_index_entered);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,10 +4,306 @@
|
|||||||
#include "editor_event.h"
|
#include "editor_event.h"
|
||||||
#include "building_layout_graph.h"
|
#include "building_layout_graph.h"
|
||||||
|
|
||||||
BuildingLayoutGraph::graph_module::graph_module(flecs::world ecs)
|
#define MIN_ROOM_SIZE 16 /* 4 * 4 tiles */
|
||||||
|
|
||||||
|
BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
|
||||||
{
|
{
|
||||||
|
ecs.module<BuildingLayoutGraph::graph_module>();
|
||||||
ecs.component<WorldEditor::components::buildings_layout_graph>();
|
ecs.component<WorldEditor::components::buildings_layout_graph>();
|
||||||
|
ecs.component<WorldEditor::components::buildings_layout_graph_node>();
|
||||||
ecs.component<WorldEditor::components::buildings_layout_base>();
|
ecs.component<WorldEditor::components::buildings_layout_base>();
|
||||||
|
ecs.component<WorldEditor::components::buildings_layout_room>();
|
||||||
|
ecs.component<WorldEditor::components::buildings_layout_zone>();
|
||||||
|
ecs.component<WorldEditor::components::buildings_layout_unit>();
|
||||||
|
ecs.component<WorldEditor::components::buildings_layout_floor>();
|
||||||
|
ecs.component<WorldEditor::components::buildings_layout_floor_index>();
|
||||||
|
const String &module_name = "::BuildingLayoutGraph::graph_module";
|
||||||
|
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_floor_index,
|
||||||
|
const WorldEditor::components::buildings_layout_floor>(
|
||||||
|
"FloorIndex")
|
||||||
|
.kind(0)
|
||||||
|
.write<WorldEditor::components::buildings_layout_floor_index>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_floor_index
|
||||||
|
&index,
|
||||||
|
const WorldEditor::components::buildings_layout_floor
|
||||||
|
&f) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
List<flecs::entity> queue;
|
||||||
|
e.children([&queue](flecs::entity ec) {
|
||||||
|
if (!ec.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>())
|
||||||
|
queue.push_back(ec);
|
||||||
|
});
|
||||||
|
while (!queue.empty()) {
|
||||||
|
flecs::entity qe = queue.front()->get();
|
||||||
|
queue.pop_front();
|
||||||
|
if (!qe.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>()) {
|
||||||
|
qe.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>(
|
||||||
|
{ index.index });
|
||||||
|
print_line(String(qe.path()) +
|
||||||
|
" index set");
|
||||||
|
qe.children([&queue](flecs::entity ec) {
|
||||||
|
queue.push_back(ec);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print_line("floor index done");
|
||||||
|
});
|
||||||
|
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_room>("RoomArea")
|
||||||
|
.kind(0)
|
||||||
|
.without<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_room &f) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
floor_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ MIN_ROOM_SIZE });
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_zone>("ZoneArea")
|
||||||
|
.kind(0)
|
||||||
|
.without<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_zone &f) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
floor_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ 0.0f });
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_unit>("UnitArea")
|
||||||
|
.kind(0)
|
||||||
|
.without<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_unit &f) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
floor_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ 0.0f });
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_floor>("FloorArea")
|
||||||
|
.kind(0)
|
||||||
|
.without<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_floor &f) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
floor_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ 0.0f });
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_zone,
|
||||||
|
WorldEditor::components::buildings_layout_area,
|
||||||
|
WorldEditor::components::buildings_layout_floor_index>(
|
||||||
|
"ZoneAreaSum")
|
||||||
|
.kind(0)
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_zone &f,
|
||||||
|
WorldEditor::components::buildings_layout_area &area,
|
||||||
|
WorldEditor::components::buildings_layout_floor_index
|
||||||
|
&index) {
|
||||||
|
flecs::entity zone_e = it.entity(count);
|
||||||
|
flecs::query<
|
||||||
|
WorldEditor::components::buildings_layout_room,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_area,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>
|
||||||
|
q = zone_e.world()
|
||||||
|
.query_builder<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_room,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_area,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
.with(flecs::ChildOf, zone_e)
|
||||||
|
.build();
|
||||||
|
float sum = 0.0f;
|
||||||
|
q.each([&sum,
|
||||||
|
index](flecs::entity e,
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_room &r,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_area &rarea,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index
|
||||||
|
&rindex) {
|
||||||
|
if (index.index == rindex.index)
|
||||||
|
sum += MAX(rarea.area, MIN_ROOM_SIZE);
|
||||||
|
});
|
||||||
|
zone_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ sum });
|
||||||
|
print_line("area: " + String(zone_e.path()) + ": " +
|
||||||
|
String::num(sum));
|
||||||
|
});
|
||||||
|
ecs.system<const WorldEditor::components::buildings_layout_unit,
|
||||||
|
WorldEditor::components::buildings_layout_area,
|
||||||
|
WorldEditor::components::buildings_layout_floor_index>(
|
||||||
|
"UnitAreaSum")
|
||||||
|
.kind(0)
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_unit &f,
|
||||||
|
WorldEditor::components::buildings_layout_area &area,
|
||||||
|
WorldEditor::components::buildings_layout_floor_index
|
||||||
|
&index) {
|
||||||
|
flecs::entity unit_e = it.entity(count);
|
||||||
|
flecs::query<
|
||||||
|
WorldEditor::components::buildings_layout_zone,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_area,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>
|
||||||
|
q = unit_e.world()
|
||||||
|
.query_builder<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_zone,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_area,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
.with(flecs::ChildOf, unit_e)
|
||||||
|
.build();
|
||||||
|
float sum = 0.0f;
|
||||||
|
q.each([&sum,
|
||||||
|
index](flecs::entity e,
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_zone &r,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_area &rarea,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index
|
||||||
|
&rindex) {
|
||||||
|
if (index.index == rindex.index)
|
||||||
|
sum += rarea.area;
|
||||||
|
});
|
||||||
|
unit_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ sum });
|
||||||
|
print_line("area: " + String(unit_e.path()) + ": " +
|
||||||
|
String::num(sum));
|
||||||
|
});
|
||||||
|
ecs.system<const WorldEditor::components::buildings_layout_floor,
|
||||||
|
WorldEditor::components::buildings_layout_area,
|
||||||
|
WorldEditor::components::buildings_layout_floor_index>(
|
||||||
|
"FloorAreaSum")
|
||||||
|
.kind(0)
|
||||||
|
.write<WorldEditor::components::buildings_layout_area>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_floor
|
||||||
|
&f,
|
||||||
|
WorldEditor::components::buildings_layout_area &area,
|
||||||
|
WorldEditor::components::buildings_layout_floor_index
|
||||||
|
&index) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
flecs::query<const WorldEditor::components::
|
||||||
|
buildings_layout_area,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>
|
||||||
|
q = floor_e.world()
|
||||||
|
.query_builder<
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_area,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()
|
||||||
|
.scope_open()
|
||||||
|
.with<WorldEditor::components::
|
||||||
|
buildings_layout_zone>()
|
||||||
|
.or_()
|
||||||
|
.with<WorldEditor::components::
|
||||||
|
buildings_layout_unit>()
|
||||||
|
.scope_close()
|
||||||
|
.with(flecs::ChildOf, floor_e)
|
||||||
|
.build();
|
||||||
|
float sum = 0.0f;
|
||||||
|
q.each([&sum,
|
||||||
|
index](flecs::entity e,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_area &rarea,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index
|
||||||
|
&rindex) {
|
||||||
|
if (index.index == rindex.index)
|
||||||
|
sum += rarea.area;
|
||||||
|
});
|
||||||
|
floor_e.set<
|
||||||
|
WorldEditor::components::buildings_layout_area>(
|
||||||
|
{ sum });
|
||||||
|
print_line("area: " + String(floor_e.path()) + ": " +
|
||||||
|
String::num(sum));
|
||||||
|
});
|
||||||
|
ecs.system<const WorldEditor::components::buildings_layout_graph,
|
||||||
|
const WorldEditor::components::buildings_layout_floor_index,
|
||||||
|
const WorldEditor::components::buildings_layout_area>(
|
||||||
|
"CreateFloorData")
|
||||||
|
.kind(0)
|
||||||
|
.write<WorldEditor::components::buildings_layout_floor_data>()
|
||||||
|
.each([](flecs::iter &it, size_t count,
|
||||||
|
const WorldEditor::components::buildings_layout_graph
|
||||||
|
&p,
|
||||||
|
const WorldEditor::components::
|
||||||
|
buildings_layout_floor_index &idx,
|
||||||
|
const WorldEditor::components::buildings_layout_area
|
||||||
|
&area) {
|
||||||
|
flecs::entity e = it.entity(count);
|
||||||
|
flecs::query<WorldEditor::components::buildings_layout_area> q =
|
||||||
|
e.world()
|
||||||
|
.query_builder<
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_area>()
|
||||||
|
.with<WorldEditor::components::
|
||||||
|
buildings_layout_floor>()
|
||||||
|
.with(flecs::ChildOf, e)
|
||||||
|
.build();
|
||||||
|
float max_area = area.area;
|
||||||
|
q.each([&max_area](flecs::entity ec,
|
||||||
|
WorldEditor::components::
|
||||||
|
buildings_layout_area &r) {
|
||||||
|
if (max_area < r.area)
|
||||||
|
max_area = r.area;
|
||||||
|
});
|
||||||
|
float grid_size = Math::ceil(
|
||||||
|
Math::ceil(Math::sqrt(max_area)) / 4.0f);
|
||||||
|
e.set<WorldEditor::components::
|
||||||
|
buildings_layout_floor_data>(
|
||||||
|
{ (int)Math::ceil(grid_size) });
|
||||||
|
print_line("grid size: " +
|
||||||
|
itos((int)Math::ceil(grid_size)));
|
||||||
|
});
|
||||||
|
ecs.system<WorldEditor::components::buildings_layout_floor>(
|
||||||
|
"FloorCompleteArea")
|
||||||
|
.kind(0)
|
||||||
|
.each([module_name](
|
||||||
|
flecs::iter &it, size_t count,
|
||||||
|
WorldEditor::components::buildings_layout_floor
|
||||||
|
&f) {
|
||||||
|
flecs::entity floor_e = it.entity(count);
|
||||||
|
flecs::world w = floor_e.world();
|
||||||
|
std::vector<String> systems = {
|
||||||
|
"RoomArea", "ZoneArea", "UnitArea",
|
||||||
|
"FloorArea", "ZoneAreaSum", "UnitAreaSum",
|
||||||
|
"FloorAreaSum", "CreateFloorData"
|
||||||
|
};
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < (int)systems.size(); i++) {
|
||||||
|
w.system(w.lookup((module_name +
|
||||||
|
"::" + systems[i])
|
||||||
|
.ascii()
|
||||||
|
.ptr()))
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
print_line("floor complete");
|
||||||
|
});
|
||||||
|
#if 0
|
||||||
ecs.system<WorldEditor::components::buildings_layout_floor>("FloorArea")
|
ecs.system<WorldEditor::components::buildings_layout_floor>("FloorArea")
|
||||||
.kind(flecs::OnUpdate)
|
.kind(flecs::OnUpdate)
|
||||||
.without<WorldEditor::components::buildings_layout_area>()
|
.without<WorldEditor::components::buildings_layout_area>()
|
||||||
@@ -595,14 +891,29 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world ecs)
|
|||||||
e.remove<WorldEditor::components::
|
e.remove<WorldEditor::components::
|
||||||
buildings_layout_dirty>();
|
buildings_layout_dirty>();
|
||||||
});
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
ecs.observer<const WorldEditor::components::buildings_layout_area>()
|
ecs.observer<const WorldEditor::components::buildings_layout_area>()
|
||||||
.event(flecs::OnSet)
|
.event(flecs::OnSet)
|
||||||
.with<WorldEditor::components::buildings_layout_room>()
|
.with<WorldEditor::components::buildings_layout_room>()
|
||||||
.write<WorldEditor::components::buildings_layout_dirty>()
|
.write<WorldEditor::components::buildings_layout_dirty>()
|
||||||
.each([](flecs::entity e,
|
.each([module_name](
|
||||||
const WorldEditor::components::buildings_layout_area
|
flecs::entity e,
|
||||||
&r) {
|
const WorldEditor::components::buildings_layout_area
|
||||||
|
&r) {
|
||||||
|
flecs::world w = e.world();
|
||||||
|
// create indices
|
||||||
|
w.system(w.lookup((module_name + "::FloorIndex")
|
||||||
|
.ascii()
|
||||||
|
.ptr()))
|
||||||
|
.run();
|
||||||
|
w.system(w.lookup((module_name + "::FloorCompleteArea")
|
||||||
|
.ascii()
|
||||||
|
.ptr()))
|
||||||
|
.run();
|
||||||
|
EditorEvent::get_singleton()->event.emit(
|
||||||
|
"update_layout_view", varray());
|
||||||
|
#if 0
|
||||||
/* if set for room make zone dirty */
|
/* if set for room make zone dirty */
|
||||||
flecs::entity parent_e = e.parent();
|
flecs::entity parent_e = e.parent();
|
||||||
while (parent_e.is_valid()) {
|
while (parent_e.is_valid()) {
|
||||||
@@ -617,6 +928,7 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world ecs)
|
|||||||
}
|
}
|
||||||
parent_e = parent_e.parent();
|
parent_e = parent_e.parent();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
if (parent_e.has<WorldEditor::components::
|
if (parent_e.has<WorldEditor::components::
|
||||||
buildings_layout_zone>())
|
buildings_layout_zone>())
|
||||||
@@ -639,38 +951,22 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world ecs)
|
|||||||
ecs.observer<WorldEditor::components::buildings_layout_floor_index>()
|
ecs.observer<WorldEditor::components::buildings_layout_floor_index>()
|
||||||
.event(flecs::OnSet)
|
.event(flecs::OnSet)
|
||||||
.with<WorldEditor::components::buildings_layout_floor>()
|
.with<WorldEditor::components::buildings_layout_floor>()
|
||||||
.each([](flecs::entity e,
|
.each([module_name](flecs::entity e,
|
||||||
const WorldEditor::components::
|
const WorldEditor::components::
|
||||||
buildings_layout_floor_index &r) {
|
buildings_layout_floor_index &r) {
|
||||||
// e.add<WorldEditor::components::buildings_layout_dirty>();
|
flecs::world w = e.world();
|
||||||
if (e.has<WorldEditor::components::
|
// create indices
|
||||||
buildings_layout_floor>()) {
|
w.system(w.lookup((module_name + "::FloorIndex")
|
||||||
List<flecs::entity> queue;
|
.ascii()
|
||||||
e.children([&queue](flecs::entity ec) {
|
.ptr()))
|
||||||
queue.push_back(ec);
|
.run();
|
||||||
});
|
w.system(w.lookup((module_name + "::FloorCompleteArea")
|
||||||
while (!queue.empty()) {
|
.ascii()
|
||||||
flecs::entity qe = queue.front()->get();
|
.ptr()))
|
||||||
queue.pop_front();
|
.run();
|
||||||
if (!qe.has<WorldEditor::components::
|
|
||||||
buildings_layout_floor>()) {
|
|
||||||
qe.set<WorldEditor::components::
|
|
||||||
buildings_layout_floor_index>(
|
|
||||||
{ r.index });
|
|
||||||
print_line(String(qe.path()) +
|
|
||||||
" index set");
|
|
||||||
qe.children(
|
|
||||||
[&queue](flecs::entity
|
|
||||||
ec) {
|
|
||||||
queue.push_back(
|
|
||||||
ec);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EditorEvent::get_singleton()->event.emit(
|
EditorEvent::get_singleton()->event.emit(
|
||||||
"update_layout_view", varray());
|
"update_layout_view", varray());
|
||||||
print_line("floor set");
|
print_line(String(e.path()) + ": set floor");
|
||||||
#if 0
|
#if 0
|
||||||
List<flecs::entity> queue;
|
List<flecs::entity> queue;
|
||||||
queue.push_back(e);
|
queue.push_back(e);
|
||||||
@@ -691,3 +987,66 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world ecs)
|
|||||||
#endif
|
#endif
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* These functions are used from GUI */
|
||||||
|
|
||||||
|
flecs::entity
|
||||||
|
BuildingLayoutGraph::create_graph_entity(const String &base_path,
|
||||||
|
const String &entity_type)
|
||||||
|
{
|
||||||
|
flecs::world ecs = BaseData::get_singleton()->get();
|
||||||
|
flecs::entity base_e = ecs.lookup(base_path.ascii().ptr());
|
||||||
|
int count = 0;
|
||||||
|
const String &type_name = entity_type;
|
||||||
|
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);
|
||||||
|
return new_e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildingLayoutGraph::create_zone(const String &base_path, int zone_type)
|
||||||
|
{
|
||||||
|
flecs::entity new_e = create_graph_entity(base_path, "zone");
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_zone>(
|
||||||
|
{ zone_type });
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_graph_node>(
|
||||||
|
{ 0, 0, 0 });
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildingLayoutGraph::create_unit(const String &base_path)
|
||||||
|
{
|
||||||
|
flecs::entity new_e = create_graph_entity(base_path, "unit");
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_unit>({ 0 });
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_graph_node>(
|
||||||
|
{ 0, 0, 0 });
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildingLayoutGraph::create_floor(const String &base_path)
|
||||||
|
{
|
||||||
|
flecs::entity new_e = create_graph_entity(base_path, "floor");
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_graph_node>(
|
||||||
|
{ 0, 0, 0 });
|
||||||
|
}
|
||||||
|
|
||||||
|
void BuildingLayoutGraph::create_room(const String &base_path, int id)
|
||||||
|
{
|
||||||
|
Array room;
|
||||||
|
BuildingLayoutGraph::get_singleton()->get_room_data(id, room);
|
||||||
|
assert(!room.empty());
|
||||||
|
String type_name = room[1];
|
||||||
|
Dictionary room_options = room[2];
|
||||||
|
bool window = room_options.get("window", false);
|
||||||
|
type_name = type_name.replace(" ", "_").to_lower();
|
||||||
|
flecs::entity new_e = create_graph_entity(base_path, type_name);
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_room>(
|
||||||
|
{ id, window });
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_graph_node>(
|
||||||
|
{ 0, 0, 0 });
|
||||||
|
new_e.set<WorldEditor::components::buildings_layout_area>({ 0.0f });
|
||||||
|
assert(new_e.has<WorldEditor::components::buildings_layout_graph_node>());
|
||||||
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void ui_field::ui_field_builder(Node *owner, Node *parent, const String format,
|
|||||||
for (i = 0; i < format.length(); i++) {
|
for (i = 0; i < format.length(); i++) {
|
||||||
const char *fmt = format.ascii().ptr();
|
const char *fmt = format.ascii().ptr();
|
||||||
int c = fmt[i];
|
int c = fmt[i];
|
||||||
printf("character: %c : argp: %d\n", (char)c, argp);
|
// printf("character: %c : argp: %d\n", (char)c, argp);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '{':
|
case '{':
|
||||||
stack.push_front(parent);
|
stack.push_front(parent);
|
||||||
@@ -57,7 +57,7 @@ void ui_field::ui_field_builder(Node *owner, Node *parent, const String format,
|
|||||||
String name = args[argp++];
|
String name = args[argp++];
|
||||||
assert(name.length() > 0);
|
assert(name.length() > 0);
|
||||||
last_created->set_name(name);
|
last_created->set_name(name);
|
||||||
printf("set name: %s\n", name.ascii().ptr());
|
// printf("set name: %s\n", name.ascii().ptr());
|
||||||
} break;
|
} break;
|
||||||
case '$': {
|
case '$': {
|
||||||
if (saved_nodes)
|
if (saved_nodes)
|
||||||
|
|||||||
Reference in New Issue
Block a user