Implemented ordering and command setting

This commit is contained in:
2024-11-01 22:54:51 +03:00
parent f1d5b75ca1
commit e3f37cdcdc
10 changed files with 704 additions and 149 deletions

View File

@@ -1,176 +1,543 @@
[layouts]
entries=[ {
"children": [ 2 ],
"children": [ 3 ],
"command": -1,
"index": 0,
"name": "v2",
"order": 0,
"type": "layout"
}, {
"children": [ 3, 4, 5 ],
"children": [ 4, 5, 6 ],
"command": -1,
"floor_index": 0,
"index": 1,
"name": "v1",
"order": 0,
"type": "layout"
}, {
"children": [ 6 ],
"children": [ 7, 8, 9, 10, 11 ],
"command": -1,
"floor_index": 0,
"index": 2,
"name": "v3",
"order": 0,
"type": "layout"
}, {
"children": [ 12 ],
"command": -1,
"index": 3,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 7, 8, 9 ],
"index": 3,
"children": [ 13, 14, 15, 16 ],
"command": -1,
"index": 4,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 17, 18, 19 ],
"command": -1,
"index": 5,
"name": "zone_0",
"order": 1,
"type": "zone",
"zone_type": 0
}, {
"children": [ 10, 11, 12, 13 ],
"index": 4,
"name": "zone_1",
"children": [ 20, 21 ],
"command": -1,
"index": 6,
"name": "unit_0",
"order": 3,
"type": "unit"
}, {
"children": [ 22, 23 ],
"command": -1,
"index": 7,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 14, 15 ],
"index": 5,
"children": [ 24, 25 ],
"command": -1,
"index": 8,
"name": "unit_0",
"order": 0,
"type": "unit"
}, {
"children": [ 16 ],
"index": 6,
"children": [ 26, 27 ],
"command": -1,
"index": 9,
"name": "unit_1",
"order": 0,
"type": "unit"
}, {
"children": [ 28, 29 ],
"command": -1,
"index": 10,
"name": "unit_2",
"order": 0,
"type": "unit"
}, {
"children": [ 30, 31 ],
"command": -1,
"index": 11,
"name": "unit_3",
"order": 0,
"type": "unit"
}, {
"children": [ 32 ],
"command": -1,
"index": 12,
"name": "stair_0",
"order": 0,
"room_area": 0.0,
"room_type": 305,
"type": "room",
"window": true
}, {
"children": [ ],
"index": 7,
"name": "wc_0",
"room_area": 16.0,
"room_type": 200,
"type": "room",
"window": false
}, {
"children": [ ],
"index": 8,
"name": "bathroom_0",
"room_area": 16.0,
"room_type": 201,
"type": "room",
"window": false
}, {
"children": [ ],
"index": 9,
"name": "bedroom_0",
"room_area": 64.0,
"room_type": 202,
"type": "room",
"window": true
}, {
"children": [ ],
"index": 10,
"command": 1,
"index": 13,
"name": "living_room_0",
"order": 0,
"room_area": 144.0,
"room_type": 300,
"type": "room",
"window": true
}, {
"children": [ ],
"index": 11,
"command": 1,
"index": 14,
"name": "kitchen_0",
"order": 1,
"room_area": 64.0,
"room_type": 302,
"type": "room",
"window": true
}, {
"children": [ ],
"index": 12,
"command": 1,
"index": 15,
"name": "storage_room_0",
"order": 2,
"room_area": 16.0,
"room_type": 307,
"type": "room",
"window": true
}, {
"children": [ ],
"index": 13,
"command": 1,
"index": 16,
"name": "enterance_0",
"order": 3,
"room_area": 16.0,
"room_type": 304,
"type": "room",
"window": true
}, {
"children": [ 17, 18, 19 ],
"index": 14,
"name": "zone_0",
"type": "zone",
"zone_type": 0
}, {
"children": [ 20, 21 ],
"index": 15,
"name": "zone_1",
"type": "zone",
"zone_type": 1
}, {
"children": [ 22 ],
"floor_index": 0,
"index": 16,
"name": "floor_0",
"type": "floor"
}, {
"children": [ ],
"command": 1,
"index": 17,
"name": "bedroom_0",
"room_area": 36.0,
"room_type": 202,
"name": "wc_0",
"order": 0,
"room_area": 16.0,
"room_type": 200,
"type": "room",
"window": true
"window": false
}, {
"children": [ ],
"command": 1,
"index": 18,
"name": "bathroom_0",
"order": 1,
"room_area": 16.0,
"room_type": 201,
"type": "room",
"window": false
}, {
"children": [ ],
"command": 1,
"index": 19,
"name": "bedroom_0",
"order": 2,
"room_area": 64.0,
"room_type": 202,
"type": "room",
"window": true
}, {
"children": [ 33, 34, 35 ],
"command": -1,
"index": 20,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 36, 37 ],
"command": -1,
"index": 21,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ ],
"command": -1,
"index": 22,
"name": "enterance_0",
"order": 0,
"room_area": 64.0,
"room_type": 304,
"type": "room",
"window": true
}, {
"children": [ 38 ],
"command": -1,
"index": 23,
"name": "stair_0",
"order": 0,
"room_area": 16.0,
"room_type": 305,
"type": "room",
"window": true
}, {
"children": [ 39, 40, 41 ],
"command": -1,
"index": 24,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 42, 43 ],
"command": -1,
"index": 25,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 44 ],
"command": -1,
"index": 26,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 45, 46 ],
"command": -1,
"index": 27,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 47 ],
"command": -1,
"index": 28,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 48 ],
"command": -1,
"index": 29,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 49 ],
"command": -1,
"index": 30,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 50 ],
"command": -1,
"index": 31,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 51 ],
"command": -1,
"floor_index": 0,
"index": 32,
"name": "floor_0",
"order": 0,
"type": "floor"
}, {
"children": [ ],
"command": 1,
"index": 33,
"name": "bathroom_0",
"order": 0,
"room_area": 16.0,
"room_type": 201,
"type": "room",
"window": false
}, {
"children": [ ],
"command": 1,
"index": 34,
"name": "wc_0",
"order": 1,
"room_area": 4.0,
"room_type": 200,
"type": "room",
"window": false
}, {
"children": [ ],
"index": 20,
"command": 1,
"index": 35,
"name": "bedroom_0",
"order": 2,
"room_area": 36.0,
"room_type": 202,
"type": "room",
"window": true
}, {
"children": [ ],
"command": 1,
"index": 36,
"name": "living_room_0",
"order": 0,
"room_area": 36.0,
"room_type": 300,
"type": "room",
"window": true
}, {
"children": [ ],
"index": 21,
"command": 1,
"index": 37,
"name": "kitchen_0",
"order": 1,
"room_area": 16.0,
"room_type": 302,
"type": "room",
"window": true
}, {
"children": [ 23, 24 ],
"index": 22,
"children": [ 52, 53 ],
"command": -1,
"floor_index": 1,
"index": 38,
"name": "floor_0",
"order": 0,
"type": "floor"
}, {
"children": [ ],
"command": -1,
"index": 39,
"name": "bathroom_0",
"order": 0,
"room_area": 16.0,
"room_type": 201,
"type": "room",
"window": false
}, {
"children": [ ],
"command": -1,
"index": 40,
"name": "bedroom_0",
"order": 0,
"room_area": 64.0,
"room_type": 202,
"type": "room",
"window": true
}, {
"children": [ ],
"command": -1,
"index": 41,
"name": "wc_0",
"order": 0,
"room_area": 16.0,
"room_type": 200,
"type": "room",
"window": false
}, {
"children": [ ],
"command": -1,
"index": 42,
"name": "kitchen_0",
"order": 0,
"room_area": 16.0,
"room_type": 302,
"type": "room",
"window": true
}, {
"children": [ ],
"command": -1,
"index": 43,
"name": "living_room_0",
"order": 0,
"room_area": 144.0,
"room_type": 300,
"type": "room",
"window": true
}, {
"children": [ ],
"command": -1,
"index": 44,
"name": "bathroom_0",
"order": 0,
"room_area": 16.0,
"room_type": 201,
"type": "room",
"window": false
}, {
"children": [ ],
"command": -1,
"index": 45,
"name": "kitchen_0",
"order": 0,
"room_area": 64.0,
"room_type": 302,
"type": "room",
"window": true
}, {
"children": [ ],
"command": -1,
"index": 46,
"name": "living_room_0",
"order": 0,
"room_area": 64.0,
"room_type": 300,
"type": "room",
"window": true
}, {
"children": [ ],
"command": -1,
"index": 47,
"name": "wc_0",
"order": 0,
"room_area": 16.0,
"room_type": 200,
"type": "room",
"window": false
}, {
"children": [ ],
"command": -1,
"index": 48,
"name": "living_room_0",
"order": 0,
"room_area": 64.0,
"room_type": 300,
"type": "room",
"window": true
}, {
"children": [ ],
"command": -1,
"index": 49,
"name": "bathroom_0",
"order": 0,
"room_area": 16.0,
"room_type": 201,
"type": "room",
"window": false
}, {
"children": [ ],
"command": -1,
"index": 50,
"name": "living_room_0",
"order": 0,
"room_area": 64.0,
"room_type": 300,
"type": "room",
"window": true
}, {
"children": [ 54, 55 ],
"command": -1,
"index": 51,
"name": "unit_0",
"order": 0,
"type": "unit"
}, {
"children": [ 56 ],
"command": -1,
"index": 52,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ 57, 58 ],
"command": -1,
"index": 53,
"name": "unit_0",
"order": 0,
"type": "unit"
}, {
"children": [ ],
"index": 23,
"command": -1,
"index": 54,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ ],
"index": 24,
"command": -1,
"index": 55,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ ],
"command": -1,
"index": 56,
"name": "storage_room_0",
"order": 0,
"room_area": 64.0,
"room_type": 307,
"type": "room",
"window": true
}, {
"children": [ 59 ],
"command": -1,
"index": 57,
"name": "zone_0",
"order": 0,
"type": "zone",
"zone_type": 0
}, {
"children": [ 60 ],
"command": -1,
"index": 58,
"name": "zone_1",
"order": 0,
"type": "zone",
"zone_type": 1
}, {
"children": [ ],
"command": -1,
"index": 59,
"name": "wc_0",
"order": 0,
"room_area": 0.0,
"room_type": 200,
"type": "room",
"window": false
}, {
"children": [ ],
"command": -1,
"index": 60,
"name": "living_room_0",
"order": 0,
"room_area": 0.0,
"room_type": 300,
"type": "room",
"window": true
} ]

View File

@@ -106,21 +106,6 @@ void BuildingLayoutGraph::get_layout_list(List<String> *keys) const
});
}
void BuildingLayoutGraph::create_new_layout(const String &layout_name)
{
flecs::world ecs = BaseData::get_singleton()->get();
flecs::entity base = get_layout_base();
flecs::entity e = base.lookup(layout_name.ascii().ptr());
if (e.is_valid())
return;
e = ecs.entity(layout_name.ascii().ptr()).child_of(base);
if (e.is_valid()) {
e.add<WorldEditor::components::buildings_layout_graph>();
e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
e.set<WorldEditor::components::buildings_layout_area>({ 0 });
}
}
flecs::entity BuildingLayoutGraph::get_layout(const String &layout_name) const
{
assert(layout_name.length() > 0);
@@ -378,6 +363,18 @@ void BuildingLayoutGraph::save_layouts()
entry["name"] = String(e.name());
entry["index"] = index;
entry["children"] = children;
int order = 0;
if (e.has<WorldEditor::components::buildings_layout_order>())
order = e.get<WorldEditor::components::
buildings_layout_order>()
->index;
entry["order"] = order;
int command = -1;
if (e.has<WorldEditor::components::buildings_layout_command>())
command = e.get<WorldEditor::components::
buildings_layout_command>()
->command;
entry["command"] = command;
if (e.has<WorldEditor::components::buildings_layout_graph>()) {
entry["type"] = "layout";
/* remember it has floor component too */
@@ -472,6 +469,8 @@ void BuildingLayoutGraph::load_layouts()
const Dictionary &entry = entities[index];
String name = entry["name"];
String type = entry["type"];
int order = entry.get("order", 0);
int command = entry.get("command", -1);
print_line("name: " + name + " type: " + type);
int parent = entry.get("parent", -1);
flecs::entity parent_e = base;
@@ -482,6 +481,10 @@ void BuildingLayoutGraph::load_layouts()
ecs.entity(name.ascii().ptr()).child_of(parent_e);
assert(e.is_valid());
print_line(String(e.path()));
e.set<WorldEditor::components::buildings_layout_order>(
{ order });
e.set<WorldEditor::components::buildings_layout_command>(
{ command });
if (type == "layout") {
e.add<WorldEditor::components::buildings_layout_graph>();
if (entry.has("floor_index")) {
@@ -578,6 +581,11 @@ void BuildingLayoutGraph::create_interior_tilemap(const String &layout_name)
int BuildingLayoutGraph::get_layout_count() const
{
flecs::entity base_e = get_layout_base();
return get_children_count(base_e);
}
int BuildingLayoutGraph::get_children_count(flecs::entity base_e) const
{
int count = 0;
base_e.children([&count](flecs::entity e) { count++; });
return count;

View File

@@ -48,6 +48,7 @@ public:
void load_layouts();
void create_interior_tilemap(const String &layout_name);
int get_layout_count() const;
int get_children_count(flecs::entity base_e) const;
struct graph_module {
graph_module(flecs::world &ecs);
};

View File

@@ -1,4 +1,5 @@
#include <scene/gui/spin_box.h>
#include <scene/gui/option_button.h>
#include "building_layout_graph_ui.h"
void BuildingLayoutGraphUI::menu_pressed(int id, Control *button,
@@ -13,7 +14,6 @@ void BuildingLayoutGraphUI::menu_pressed(int id, Control *button,
case 102:
case 103:
case 104: {
int count = 0;
switch (id) {
case 100:
BuildingLayoutGraph::get_singleton()->create_unit(path);
@@ -50,11 +50,9 @@ void BuildingLayoutGraphUI::update_buttons(ColorRect *canvas)
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::
@@ -69,8 +67,8 @@ void BuildingLayoutGraphUI::update_buttons(ColorRect *canvas)
->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) {
if (pt.x + 100.0f >= canvas->get_size().x ||
pt.y + 40.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));
@@ -141,15 +139,41 @@ void BuildingLayoutGraphUI::update_buttons(ColorRect *canvas)
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);
SpinBox *sb = Object::cast_to<SpinBox>(
save_data["floor_index"]);
sb->set_min(-2000);
sb->set_max(2000);
sb->set_value(floor_index);
save_data["floor_index"]->connect(
"value_changed", this,
"floor_index_entered",
varray(save_data["floor_index"],
String(e.path())));
}
/* order input form */
if (e.has<WorldEditor::components::
buildings_layout_order>()) {
std::vector<Variant> args = { "Order: ",
"order" };
HashMap<String, Object *> save_data;
int order =
e.get<WorldEditor::components::
buildings_layout_order>()
->index;
ui_field::ui_field_builder(
canvas, box, "p{h{lx#$}}", args.data(),
args.size(), &save_data);
assert(save_data.has("order"));
SpinBox *sb = Object::cast_to<SpinBox>(
save_data["order"]);
sb->set_min(-1000);
sb->set_max(1000);
sb->set_value(order);
save_data["order"]->connect(
"value_changed", this, "order_entered",
varray(save_data["order"],
String(e.path())));
}
/* area input form */
if (e.has<WorldEditor::components::
buildings_layout_room>() &&
@@ -166,9 +190,11 @@ void BuildingLayoutGraphUI::update_buttons(ColorRect *canvas)
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);
SpinBox *sb = Object::cast_to<SpinBox>(
save_data["area_value"]);
sb->set_min(16);
sb->set_max(200000);
sb->set_value(area);
save_data["area_value"]->connect(
"value_changed", this,
"room_size_entered",
@@ -218,13 +244,151 @@ void BuildingLayoutGraphUI::update_buttons(ColorRect *canvas)
args.data(),
args.size());
}
if (e.has<WorldEditor::components::
buildings_layout_command>()) {
std::vector<Variant> args = {
/* clang-format off */
"Command:",
"None", 3,
-1, "None",
1, "Arrach1",
2, "Attach2",
"command",
/* clang-format on */
};
HashMap<String, Object *> save_data;
ui_field::ui_field_builder(
canvas, box, "p{h{lo#$}}", args.data(),
args.size(), &save_data);
assert(!save_data.empty());
List<String> keys;
save_data.get_key_list(&keys);
print_line(keys.front()->get());
assert(save_data["command"]);
OptionButton *ob =
Object::cast_to<OptionButton>(
save_data["command"]);
int command =
e.get<WorldEditor::components::
buildings_layout_command>()
->command;
int selected = -1;
selected = ob->get_popup()->get_item_index(
command);
print_line("selected: " + itos(command) + " " +
itos(selected));
ob->select(selected);
ob->connect("item_selected", this,
"command_entered",
varray(save_data["command"],
String(e.path())));
}
button->get_popup()->connect(
"id_pressed", this, "menu_pressed",
varray(button, String(e.path())));
}
e.children([&queue](flecs::entity fe) { queue.push_back(fe); });
flecs::query<
const WorldEditor::components::buildings_layout_order>
q = e.world()
.query_builder<
const WorldEditor::components::
buildings_layout_order>()
.with(flecs::ChildOf, e)
.order_by<WorldEditor::components::
buildings_layout_order>(
[](flecs::entity_t e1,
const WorldEditor::components::
buildings_layout_order
*o1,
flecs::entity_t e2,
const WorldEditor::components::
buildings_layout_order
*o2) {
return (o1->index >
o2->index) -
(o1->index <
o2->index);
})
.build();
q.each([&queue](flecs::entity fe,
const WorldEditor::components::
buildings_layout_order &order) {
queue.push_back(fe);
});
}
}
void BuildingLayoutGraphUI::update_graph()
{
int i;
assert(dlg->get_node(NodePath("%buildings_layout_graph")));
Control *base = Object::cast_to<Control>(
dlg->get_node(NodePath("%buildings_layout_graph")));
base->set_custom_minimum_size(Vector2(2048, 1600));
base->set_anchor(MARGIN_RIGHT, 1.0f);
base->set_anchor(MARGIN_BOTTOM, 1.0f);
base->set_v_size_flags(Control::SIZE_EXPAND_FILL);
base->set_h_size_flags(Control::SIZE_EXPAND_FILL);
ScrollContainer *p =
Object::cast_to<ScrollContainer>(base->get_parent());
p->set_v_size_flags(Control::SIZE_EXPAND_FILL);
p->set_h_size_flags(Control::SIZE_EXPAND_FILL);
// p->set_anchor(MARGIN_RIGHT, 1.0f);
// p->set_anchor(MARGIN_BOTTOM, 1.0f);
LocalVector<Node *> data;
for (i = 0; i < base->get_child_count(); i++)
data.push_back(base->get_child(i));
for (i = 0; i < (int)data.size(); i++) {
base->remove_child(data[i]);
data[i]->queue_delete();
}
data.clear();
ColorRect *canvas = memnew(ColorRect);
base->add_child(canvas);
canvas->set_frame_color(Color(0.2, 0.2, 0.25, 1.0));
canvas_item = canvas;
canvas->connect("draw", this, "draw_graph");
if (current_layout.length() > 0)
update_buttons(canvas);
dlg->update();
}
void BuildingLayoutGraphUI::floor_index_entered(float value, Control *item,
const String &path)
{
print_line(String::num(value));
flecs::world ecs = BaseData::get_singleton()->get();
flecs::entity e = ecs.lookup(path.ascii().ptr());
assert(e.is_valid());
e.get_mut<WorldEditor::components::buildings_layout_floor_index>()
->index = (int)value;
e.modified<WorldEditor::components::buildings_layout_floor_index>();
print_line("data set floor");
}
void BuildingLayoutGraphUI::order_entered(float value, Control *item,
const String &path)
{
print_line(String::num(value));
flecs::world ecs = BaseData::get_singleton()->get();
flecs::entity e = ecs.lookup(path.ascii().ptr());
assert(e.is_valid());
e.get_mut<WorldEditor::components::buildings_layout_order>()->index =
(int)value;
e.modified<WorldEditor::components::buildings_layout_order>();
print_line("data set order");
}
void BuildingLayoutGraphUI::command_entered(int index, Control *item,
const String &path)
{
print_line(itos(index));
flecs::world ecs = BaseData::get_singleton()->get();
flecs::entity e = ecs.lookup(path.ascii().ptr());
assert(e.is_valid());
e.get_mut<WorldEditor::components::buildings_layout_command>()->command =
index;
e.modified<WorldEditor::components::buildings_layout_command>();
print_line("data set command");
}
void BuildingLayoutGraphUI::_bind_methods()
{
ClassDB::bind_method(D_METHOD("menu_pressed", "id", "button", "path"),
@@ -243,4 +407,12 @@ void BuildingLayoutGraphUI::_bind_methods()
"item"
"path"),
&BuildingLayoutGraphUI::floor_index_entered);
ClassDB::bind_method(D_METHOD("order_entered", "value",
"item"
"path"),
&BuildingLayoutGraphUI::order_entered);
ClassDB::bind_method(D_METHOD("command_entered", "index",
"item"
"path"),
&BuildingLayoutGraphUI::command_entered);
}

View File

@@ -161,58 +161,15 @@ public:
{ MAX(16.0f, area_final) });
print_line("data set room_size");
}
void floor_index_entered(float value, Control *item, const String &path)
{
print_line(String::num(value));
flecs::world ecs = BaseData::get_singleton()->get();
flecs::entity e = ecs.lookup(path.ascii().ptr());
assert(e.is_valid());
e.get_mut<WorldEditor::components::buildings_layout_floor_index>()
->index = (int)value;
e.modified<
WorldEditor::components::buildings_layout_floor_index>();
print_line("data set floor");
}
void floor_index_entered(float value, Control *item,
const String &path);
void order_entered(float value, Control *item, const String &path);
void command_entered(int index, Control *item, const String &path);
Vector<Vector2> buttons;
#define DEPTH_MUL 160
#define Y_MUL 130
#define Y_MUL 220
void update_buttons(ColorRect *canvas);
void update_graph()
{
int i;
assert(dlg->get_node(NodePath("%buildings_layout_graph")));
Control *base = Object::cast_to<Control>(
dlg->get_node(NodePath("%buildings_layout_graph")));
base->set_custom_minimum_size(Vector2(2048, 1600));
base->set_anchor(MARGIN_RIGHT, 1.0f);
base->set_anchor(MARGIN_BOTTOM, 1.0f);
base->set_v_size_flags(Control::SIZE_EXPAND_FILL);
base->set_h_size_flags(Control::SIZE_EXPAND_FILL);
ScrollContainer *p =
Object::cast_to<ScrollContainer>(base->get_parent());
p->set_v_size_flags(Control::SIZE_EXPAND_FILL);
p->set_h_size_flags(Control::SIZE_EXPAND_FILL);
// p->set_anchor(MARGIN_RIGHT, 1.0f);
// p->set_anchor(MARGIN_BOTTOM, 1.0f);
LocalVector<Node *> data;
for (i = 0; i < base->get_child_count(); i++)
data.push_back(base->get_child(i));
for (i = 0; i < (int)data.size(); i++) {
base->remove_child(data[i]);
data[i]->queue_delete();
}
data.clear();
ColorRect *canvas = memnew(ColorRect);
base->add_child(canvas);
canvas->set_frame_color(Color(0.2, 0.2, 0.25, 1.0));
canvas_item = canvas;
canvas->connect("draw", this, "draw_graph");
if (current_layout.length() > 0)
update_buttons(canvas);
dlg->update();
}
void update_graph();
void draw_graph()
{
List<flecs::entity> queue;
@@ -296,11 +253,12 @@ public:
"building_layouts_save", varray(),
"Build", "building_layouts_create_grid",
"building_layouts_create_grid", varray(),
Color(0.6f, 0.8f, 1.0f, 1.0f), "building_gen_display", Vector2(120, 180),
/* clang-format on */
};
ui_field::ui_field_builder(gui, tab,
"l_p{v{li.#!lh{e#+!b#!Q}b#!Qb#!Q}}",
args_data.data(), args_data.size());
ui_field::ui_field_builder(
gui, tab, "l_p{v{li.#!lh{e#+!b#!Q}b#!Qb#!Qc#.}}",
args_data.data(), args_data.size());
}
static void _bind_methods();
};

View File

@@ -1015,6 +1015,8 @@ void BuildingLayoutGraph::create_zone(const String &base_path, int zone_type)
{ zone_type });
new_e.set<WorldEditor::components::buildings_layout_graph_node>(
{ 0, 0, 0 });
int count = get_children_count(new_e.parent());
new_e.set<WorldEditor::components::buildings_layout_order>({ count });
}
void BuildingLayoutGraph::create_unit(const String &base_path)
@@ -1023,6 +1025,8 @@ void BuildingLayoutGraph::create_unit(const String &base_path)
new_e.set<WorldEditor::components::buildings_layout_unit>({ 0 });
new_e.set<WorldEditor::components::buildings_layout_graph_node>(
{ 0, 0, 0 });
int count = get_children_count(new_e.parent());
new_e.set<WorldEditor::components::buildings_layout_order>({ count });
}
void BuildingLayoutGraph::create_floor(const String &base_path)
@@ -1031,6 +1035,8 @@ void BuildingLayoutGraph::create_floor(const String &base_path)
new_e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
new_e.set<WorldEditor::components::buildings_layout_graph_node>(
{ 0, 0, 0 });
int count = get_children_count(new_e.parent());
new_e.set<WorldEditor::components::buildings_layout_order>({ count });
}
void BuildingLayoutGraph::create_room(const String &base_path, int id)
@@ -1049,4 +1055,29 @@ void BuildingLayoutGraph::create_room(const String &base_path, int id)
{ 0, 0, 0 });
new_e.set<WorldEditor::components::buildings_layout_area>({ 0.0f });
assert(new_e.has<WorldEditor::components::buildings_layout_graph_node>());
int count = get_children_count(new_e.parent());
new_e.set<WorldEditor::components::buildings_layout_order>({ count });
new_e.set<WorldEditor::components::buildings_layout_command>({ -1 });
}
void BuildingLayoutGraph::create_new_layout(const String &layout_name)
{
flecs::world ecs = BaseData::get_singleton()->get();
flecs::entity base = get_layout_base();
flecs::entity e = base.lookup(layout_name.ascii().ptr());
if (e.is_valid())
return;
e = ecs.entity(layout_name.ascii().ptr()).child_of(base);
if (e.is_valid()) {
e.add<WorldEditor::components::buildings_layout_graph>();
e.set<WorldEditor::components::buildings_layout_floor>({ 0 });
e.set<WorldEditor::components::buildings_layout_graph_node>(
{ 0, 0, 0 });
e.set<WorldEditor::components::buildings_layout_floor_index>(
{ 0 });
e.set<WorldEditor::components::buildings_layout_area>({ 0 });
int count = get_children_count(base);
e.set<WorldEditor::components::buildings_layout_order>(
{ count });
}
}

View File

@@ -25,7 +25,6 @@ public:
}
void update_ui()
{
RoadLinesData *rld = RoadLinesData::get_singleton();
ItemList *lines_list =
gui->get_as_node<ItemList>("%lines_list");
assert(lines_list);

View File

@@ -82,7 +82,6 @@ void MainTabs::_notification(int which)
return (std::size_t)s.hash64();
}
};
int j;
switch (which) {
case NOTIFICATION_ENTER_TREE:
connect("tab_changed", this, "tab_changed");
@@ -112,10 +111,12 @@ void MainTabs::_notification(int which)
WorldEditor::components::buildings_editor_node>());
assert(world_editor_e.has<
WorldEditor::components::road_lines_editor_node>());
#if 0
WorldEditor *we =
world_editor_e
.get<WorldEditor::components::world_editor_node>()
->node;
#endif
BuildingsEditor *editor =
world_editor_e
.get<WorldEditor::components::

View File

@@ -11,6 +11,7 @@
#include <scene/gui/menu_button.h>
#include <scene/gui/spin_box.h>
#include <scene/gui/separator.h>
#include <scene/gui/color_rect.h>
#include "base_data.h"
#include "world_editor.h"
#include "handle_cmd_button.h"
@@ -126,6 +127,7 @@ void ui_field::ui_field_builder(Node *owner, Node *parent, const String format,
{
Label *l = memnew(Label);
l->set_text(args[argp++]);
// printf("set_text: %s\n", l->get_text().ascii().ptr());
parent->add_child(l);
l->set_owner(owner);
last_created = l;
@@ -163,10 +165,12 @@ void ui_field::ui_field_builder(Node *owner, Node *parent, const String format,
OptionButton *b = memnew(OptionButton);
assert(argp < args_size);
b->set_text(args[argp++]);
// printf("set_text: %s\n", b->get_text().ascii().ptr());
parent->add_child(b);
b->set_owner(owner);
assert(argp < args_size);
count = args[argp++];
// printf("count: %d\n", count);
for (j = 0; j < count; j++) {
assert(argp < args_size);
int id = args[argp++];
@@ -237,6 +241,14 @@ void ui_field::ui_field_builder(Node *owner, Node *parent, const String format,
sp->set_owner(owner);
last_created = sp;
} break;
case 'c': {
assert(argp < args_size);
ColorRect *cr = memnew(ColorRect);
parent->add_child(cr);
cr->set_owner(owner);
cr->set_frame_color(args[argp++]);
last_created = cr;
} break;
case '_': {
HSeparator *hs = memnew(HSeparator);
parent->add_child(hs);

View File

@@ -101,6 +101,12 @@ public:
struct buildings_layout_floor_index {
int index;
};
struct buildings_layout_order {
int index;
};
struct buildings_layout_command {
int command;
};
};
};