Visualize grid in 2D: multiple floors support

This commit is contained in:
2024-11-11 03:03:43 +03:00
parent 8381e37fbe
commit 124a080840
3 changed files with 55 additions and 6 deletions

View File

@@ -695,7 +695,7 @@ void BuildingLayoutGraphUI::tree_entered()
MARGIN_RIGHT, 1.0f, MARGIN_BOTTOM, 1.0f,
"buildings_layout_graph",
MARGIN_RIGHT, 1.0f, MARGIN_BOTTOM, 1.0f,
"Interior", Control::SIZE_EXPAND_FILL, Color(1, 0, 0, 1),
"Interior", "", 0, "select_grid_level", Control::SIZE_EXPAND_FILL, Color(1, 0, 0, 1),
MARGIN_RIGHT, 1.0f, MARGIN_BOTTOM, 1.0f,
"color_view_grid",
"Exterior",
@@ -705,13 +705,24 @@ void BuildingLayoutGraphUI::tree_entered()
ui_field::ui_field_builder(
dlg, dlg,
// "p+={t+={v#{s#!+={}}v#{}v#{}}}",
"t**{v#{s**{p#!**}}v#{p={c**#$}}v#{}}",
"t**{v#{s**{p#!**}}v#{o#$p={c**#$}}v#{}}",
args_data2.data(), args_data2.size(), &save_obj);
assert(save_obj.has("color_view_grid"));
assert(save_obj.has("select_grid_level"));
ColorRect *grid_view =
Object::cast_to<ColorRect>(save_obj["color_view_grid"]);
grid_view->connect("draw", this, "draw_2d_grid_view",
varray(grid_view));
OptionButton *select_grid_floor_ob =
Object::cast_to<OptionButton>(
save_obj["select_grid_level"]);
assert(select_grid_floor_ob);
select_grid_floor_ob->get_popup()->connect(
"about_to_show", this, "update_select_grid_floor_ob",
varray(select_grid_floor_ob));
select_grid_floor_ob->get_popup()->connect(
"id_pressed", this, "select_grid_floor_ob",
varray(select_grid_floor_ob, grid_view));
dlg->update();
update_layout_item_list();
if (BuildingLayoutGraph::get_singleton()->get_layout_count() >
@@ -815,14 +826,15 @@ void BuildingLayoutGraphUI::draw_2d_grid_view(Control *draw)
int pos = 0;
draw->draw_rect(Rect2(0, 0, disp_size, disp_size), Color(1, 1, 0, 1));
int cur_floor = current_floor;
const String &cur_floor = current_grid_floor;
floor_q.each([count, disp_size, grid_size, &pos, &draw,
cur_floor](flecs::entity fe,
const WorldEditor::components::
buildings_layout_grid_floor) {
print_line(String(fe.path()));
if (pos == cur_floor) {
if (String(fe.name()) == cur_floor ||
(cur_floor == "" && pos == 0)) {
draw->draw_rect(Rect2(0, 0, disp_size, disp_size),
Color(0, 1, 1, 1), false);
// TODO: display children cells
@@ -858,6 +870,33 @@ void BuildingLayoutGraphUI::draw_2d_grid_view(Control *draw)
pos++;
});
}
void BuildingLayoutGraphUI::update_select_grid_floor_ob(Control *button)
{
flecs::entity grid_e = get_current_grid_layout();
OptionButton *ob = Object::cast_to<OptionButton>(button);
flecs::query<const WorldEditor::components::buildings_layout_grid_floor>
q = grid_e.world()
.query_builder<const WorldEditor::components::
buildings_layout_grid_floor>()
.with(flecs::ChildOf, grid_e)
.build();
ob->get_popup()->clear();
q.each([&ob](flecs::entity ec,
const WorldEditor::components::buildings_layout_grid_floor
&fl) {
String pname(ec.name());
ob->get_popup()->add_item(pname);
});
}
void BuildingLayoutGraphUI::select_grid_floor_ob(int id, Control *button,
Control *draw)
{
OptionButton *ob = Object::cast_to<OptionButton>(button);
int index = ob->get_item_index(id);
current_grid_floor = ob->get_item_text(index);
print_line("selected: " + current_grid_floor);
draw->update();
}
void BuildingLayoutGraphUI::_bind_methods()
{
ClassDB::bind_method(D_METHOD("menu_pressed", "id", "button", "path"),
@@ -893,4 +932,10 @@ void BuildingLayoutGraphUI::_bind_methods()
&BuildingLayoutGraphUI::draw_building_gen_display);
ClassDB::bind_method(D_METHOD("draw_2d_grid_view", "draw"),
&BuildingLayoutGraphUI::draw_2d_grid_view);
ClassDB::bind_method(
D_METHOD("update_select_grid_floor_ob", "button"),
&BuildingLayoutGraphUI::update_select_grid_floor_ob);
ClassDB::bind_method(D_METHOD("select_grid_floor_ob", "id", "button",
"draw"),
&BuildingLayoutGraphUI::select_grid_floor_ob);
}

View File

@@ -24,7 +24,7 @@ class BuildingLayoutGraphUI : public Object {
Control *canvas_item;
Button *button;
String current_layout;
int current_floor;
String current_grid_floor;
public:
BuildingLayoutGraphUI(MainTabs *gui, WindowDialog *dlg)
@@ -33,7 +33,7 @@ public:
, dlg(dlg)
, canvas_item(nullptr)
, button(nullptr)
, current_floor(0)
, current_grid_floor("")
{
dlg->connect("tree_entered", this, "tree_entered");
}
@@ -171,6 +171,8 @@ public:
void setup_layout_tab(Control *tab, const String &header);
void draw_building_gen_display(Control *draw);
void draw_2d_grid_view(Control *draw);
void update_select_grid_floor_ob(Control *button);
void select_grid_floor_ob(int id, Control *button, Control *draw);
static void _bind_methods();
};

View File

@@ -910,6 +910,8 @@ BuildingLayoutGraph::graph_module::graph_module(flecs::world &ecs)
floor_e.add<
WorldEditor::components::
buildings_layout_grid_floor>();
floor_e.add<WorldEditor::components::belongs>(
base_floor_e);
flecs::log::warn("created floor: %s::%s",
grid_e.path().c_str(),
floor_name.ascii().ptr());