+
+RecordsPanel::RecordsPanel(world::Simulation &sim)
+: sim(sim)
+, records()
+, holders()
+, panel()
+, shown(true) {
+ Label *rank_label = new Label(sim.Assets().fonts.medium);
+ rank_label->Text("Rank");
+
+ Panel *rank_panel = new Panel;
+ rank_panel
+ ->Direction(Panel::VERTICAL)
+ ->Add(rank_label);
+
+ for (int i = 0; i < world::Record::MAX; ++i) {
+ rank_label = new Label(sim.Assets().fonts.medium);
+ rank_label->Text(std::to_string(i + 1));
+ rank_panel->Add(rank_label);
+ }
+
+ panel
+ .Direction(Panel::HORIZONTAL)
+ ->Padding(glm::vec2(10.0f))
+ ->Spacing(45.0f)
+ ->Background(glm::vec4(1.0f, 1.0f, 1.0f, 0.7f))
+ ->Add(rank_panel);
+
+ records.reserve(sim.Records().size() * (world::Record::MAX + 1));
+ holders.reserve(sim.Records().size() * (world::Record::MAX + 1));
+ int ri = 0;
+ for (const auto &r : sim.Records()) {
+ Panel *by_panel = new Panel;
+ by_panel
+ ->Direction(Panel::VERTICAL);
+ Panel *val_panel = new Panel;
+ val_panel
+ ->Direction(Panel::VERTICAL);
+ Panel *tab_panel = new Panel;
+ tab_panel
+ ->Direction(Panel::HORIZONTAL)
+ ->Spacing(10.0f)
+ ->Add(by_panel)
+ ->Add(val_panel);
+ Label *rec_label = new Label(sim.Assets().fonts.medium);
+ rec_label->Text(r.name);
+ Panel *rec_panel = new Panel;
+ rec_panel
+ ->Direction(Panel::VERTICAL)
+ ->Add(rec_label)
+ ->Add(tab_panel);
+ for (int i = 0; i < world::Record::MAX; ++i) {
+ Label *val_label = new Label(sim.Assets().fonts.medium);
+ val_panel->Add(val_label);
+ records.push_back(val_label);
+ Label *holder_label = new Label(sim.Assets().fonts.medium);
+ by_panel->Add(holder_label);
+ holders.push_back(holder_label);
+ }
+ Panel *group_panel = new Panel;
+ group_panel
+ ->Direction(Panel::HORIZONTAL)
+ ->Spacing(10.0f)
+ ->Add(rec_panel);
+ panel.Add(group_panel);
+ ++ri;
+ }
+}
+
+RecordsPanel::~RecordsPanel() {
+}
+
+void RecordsPanel::Draw(graphics::Viewport &viewport) noexcept {
+ if (!shown) return;
+
+ int ri = 0;
+ for (const auto &r : sim.Records()) {
+ for (int i = 0; i < world::Record::MAX; ++i) {
+ if (!r.rank[i]) {
+ break;
+ }
+ records[ri * world::Record::MAX + i]->Text(r.ValueString(i));
+ holders[ri * world::Record::MAX + i]->Text(r.rank[i].holder->Name());
+ }
+ ++ri;
+ }
+
+ const glm::vec2 margin(20.0f);
+ panel.Position(glm::vec2(margin.x, margin.y));
+ panel.Layout();
+ panel.Draw(sim.Assets(), viewport);
+}
+
+
+TimePanel::TimePanel(world::Simulation &sim)
+: sim(sim)
+, body(nullptr)
+, live(new Label(sim.Assets().fonts.medium))
+, time(new Label(sim.Assets().fonts.medium))
+, clock(new Label(sim.Assets().fonts.medium))
+, panel() {
+ Label *live_label = new Label(sim.Assets().fonts.medium);
+ live_label->Text("Alive");
+ Label *time_label = new Label(sim.Assets().fonts.medium);
+ time_label->Text("Time");
+ Label *clock_label = new Label(sim.Assets().fonts.medium);
+ clock_label->Text("Clock");
+
+ Panel *label_panel = new Panel;
+ label_panel
+ ->Direction(Panel::VERTICAL)
+ ->Add(live_label)
+ ->Add(time_label)
+ ->Add(clock_label);
+
+ Panel *value_panel = new Panel;
+ value_panel
+ ->Direction(Panel::VERTICAL)
+ ->Add(live)
+ ->Add(time)
+ ->Add(clock);
+
+ panel
+ .Direction(Panel::HORIZONTAL)
+ ->Padding(glm::vec2(10.0f))
+ ->Spacing(10.0f)
+ ->Background(glm::vec4(1.0f, 1.0f, 1.0f, 0.7f))
+ ->Add(label_panel)
+ ->Add(value_panel);
+}
+
+TimePanel::~TimePanel() {
+}
+
+void TimePanel::Draw(graphics::Viewport &viewport) noexcept {
+ live->Text(NumberString(sim.LiveCreatures().size()));
+ time->Text(TimeString(sim.Time()));
+ if (body) {
+ clock->Text(TimeString(std::fmod(sim.Time(), body->DayLength())) + " / " + TimeString(body->DayLength()));
+ } else {
+ clock->Text("no reference");
+ }
+
+ const glm::vec2 margin(20.0f);
+ panel.Position(glm::vec2(margin.x, viewport.Height() - margin.y - panel.Size().y));
+ panel.Layout();
+ panel.Draw(sim.Assets(), viewport);
+}
+
+
+namespace {
+std::ostream &custom_fixed(std::ostream &out, double n, int d) {
+ double f = n;
+ int p = d;
+ while (f > 1.0 && p > 0) {
+ --p;
+ f *= 0.1;
+ }
+ if (p > 0) {
+ out << std::fixed << std::setprecision(p) << n;
+ } else {
+ out.unsetf(std::ios_base::floatfield);
+ out << std::setprecision(d) << n;
+ }
+ return out;
+}
+}
+
+std::string AngleString(double a) {
+ std::stringstream s;
+ s << std::fixed << std::setprecision(2) << std::fmod(a * 180.0 * PI_inv, 360.0) << "°";
+ return s.str();
+}
+
+std::string DecimalString(double n, int p) {
+ std::stringstream s;
+ s << std::fixed << std::setprecision(p) << n;
+ return s.str();
+}
+
+std::string LengthString(double m) {
+ std::stringstream s;
+ if (m > 1.5e9) {
+ custom_fixed(s, m * 1.0e-9, 4) << "Gm";
+ } else if (m > 1.5e6) {
+ custom_fixed(s, m * 1.0e-6, 4) << "Mm";
+ } else if (m > 1.5e3) {
+ custom_fixed(s, m * 1.0e-3, 4) << "km";
+ } else if (m < 1.5e-3) {
+ custom_fixed(s, m * 1.0e3, 4) << "mm";
+ } else if (m < 1.5) {
+ custom_fixed(s, m * 1.0e2, 4) << "cm";
+ } else {
+ custom_fixed(s, m, 4) << "m";
+ }
+ return s.str();
+}
+
+std::string MassString(double kg) {
+ std::stringstream s;
+ if (kg > 1.5e12) {
+ custom_fixed(s, kg * 1.0e-12, 4) << "Gt";
+ } else if (kg > 1.5e9) {
+ custom_fixed(s, kg * 1.0e-9, 4) << "Mt";
+ } else if (kg > 1.5e6) {
+ custom_fixed(s, kg * 1.0e-6, 4) << "kt";
+ } else if (kg > 1.5e3) {
+ custom_fixed(s, kg * 1.0e-3, 4) << "t";
+ } else if (kg < 1.0e-3) {
+ custom_fixed(s, kg * 1.0e6, 4) << "mg";
+ } else if (kg < 1.0) {
+ custom_fixed(s, kg * 1.0e3, 4) << "g";
+ } else {
+ custom_fixed(s, kg, 4) << "kg";
+ }
+ return s.str();
+}
+
+std::string NumberString(int n) {
+ return std::to_string(n);
+}
+
+std::string PercentageString(double n) {
+ std::stringstream s;
+ s << std::fixed << std::setprecision(1) << (n * 100.0) << '%';
+ return s.str();
+}
+
+std::string TimeString(double s) {
+ int is = int(s);
+ int md = 1;
+ int sd = 1;
+ std::stringstream ss;
+ ss << std::setfill('0');
+ if (is >= 3600) {
+ ss << (is / 3600) << "h ";
+ is %= 3600;
+ md = 2;
+ }
+ if (is >= 60) {
+ ss << std::setw(md) << (is / 60) << "m ";
+ is %= 60;
+ sd = 2;
+ }
+ ss << std::setw(sd) << is << 's';
+ return ss.str();
+}
+
+std::string VectorString(const glm::dvec3 &v, int p) {
+ std::stringstream ss;
+ ss << std::fixed << std::setprecision(p)
+ << "<" << v.x << ", " << v.y << ", " << v.z << ">";
+ return ss.str();
+}
+
+std::string VectorString(const glm::ivec2 &v) {
+ std::stringstream ss;
+ ss << "<" << v.x << ", " << v.y << ">";
+ return ss.str();
+}
+