Forgot to add a file
This commit is contained in:
246
src/modules/stream/ui/building_layout_graph_ui.cpp
Normal file
246
src/modules/stream/ui/building_layout_graph_ui.cpp
Normal file
@@ -0,0 +1,246 @@
|
|||||||
|
#include <scene/gui/spin_box.h>
|
||||||
|
#include "building_layout_graph_ui.h"
|
||||||
|
|
||||||
|
void BuildingLayoutGraphUI::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 BuildingLayoutGraphUI::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();
|
||||||
|
}
|
||||||
|
|
||||||
|
String title = "";
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>())
|
||||||
|
title = "Floor";
|
||||||
|
else if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_unit>())
|
||||||
|
title = "Unit";
|
||||||
|
else if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_zone>()) {
|
||||||
|
int zone_type =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_zone>()
|
||||||
|
->type;
|
||||||
|
if (zone_type == 0)
|
||||||
|
title = "Private Zone";
|
||||||
|
else if (zone_type == 1)
|
||||||
|
title = "Public Zone";
|
||||||
|
} else if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_room>())
|
||||||
|
title = "Room";
|
||||||
|
button->set_text(button->get_text() + title + "\n" +
|
||||||
|
String(e.name()));
|
||||||
|
|
||||||
|
/* index input form */
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor>() &&
|
||||||
|
e.has<WorldEditor::components::
|
||||||
|
buildings_layout_floor_index>()) {
|
||||||
|
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())));
|
||||||
|
}
|
||||||
|
/* area input form */
|
||||||
|
if (e.has<WorldEditor::components::
|
||||||
|
buildings_layout_room>() &&
|
||||||
|
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_room>()) {
|
||||||
|
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_floor>() &&
|
||||||
|
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>()) {
|
||||||
|
int grid_size =
|
||||||
|
e.get<WorldEditor::components::
|
||||||
|
buildings_layout_floor_data>()
|
||||||
|
->grid_size;
|
||||||
|
std::vector<Variant> args = { "Grid size: " +
|
||||||
|
itos(grid_size) };
|
||||||
|
ui_field::ui_field_builder(canvas, box, "l",
|
||||||
|
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 BuildingLayoutGraphUI::_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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user