The stadium as a card model with a camera

The ground, its stands, facilities and periphery are built as bodies from the stadium
overview, seen through an axonometric camera, sorted by depth and drawn as a vector
picture. A click chooses the bowl, a stand, the floodlights or a house; the camera
flies there in 0.6 seconds (reduced motion jumps) and a card shows what stands there
and leads to the builder's offer. Stands are as deep as they have places, seats take
the club's colour, a roof and scaffolding show, and what may still be built is a
dashed footprint.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-15 00:14:06 +01:00
1 parent d75617052f
commit b9d8b2db96
7 files changed
+524 -20

No files matched your search

+32
View File
@@ -171,3 +171,35 @@ body.midnight .stadium-plan-total,body.matchday .stadium-plan-total {color:#d5dd
.stadium-block-bar span {display:block;height:8dp;border-radius:4dp;background-color:#9a7a3a;}
.stadium-block-copy strong {font-family:Display;font-size:34dp;font-weight:bold;}
.stadium-plan-total {right:auto;left:24dp;top:16dp;text-align:left;width:380dp;}
/* the card model */
.stadium-model {position:absolute;left:0;top:134dp;width:1790dp;height:1600dp;border:2dp var(--paper-edge);border-radius:8dp;overflow:hidden;}
#stadium-model-art {position:absolute;left:0;top:0;width:1790dp;height:1600dp;}
.stadium-model-back,.stadium-model-back:hover {position:absolute;padding:0;border:0dp;border-radius:0dp;background-color:transparent;decorator:none;}
.stadium-model-hit {position:absolute;padding:0;border:3dp transparent;border-radius:12dp;background-color:transparent;decorator:none;}
.stadium-model-hit:hover,.stadium-model-hit:focus-visible {border-color:#25617a;background-color:#25617a1c;}
.stadium-model-hit.chosen {border-color:transparent;background-color:transparent;}
.stadium-model-hit.bowl {display:flex;align-items:flex-start;justify-content:center;font-family:Display;font-size:44dp;color:#25617a;border:3dp #25617a55;}
.stadium-model-tag {position:absolute;width:0;height:0;pointer-events:none;}
.stadium-model-tag>span {display:block;position:absolute;left:-150dp;top:-22dp;width:300dp;height:44dp;line-height:44dp;text-align:center;font-size:26dp;color:#3d362a;white-space:nowrap;}
.stadium-model-tag.letter>span {left:-30dp;top:-30dp;width:60dp;height:60dp;line-height:54dp;border:3dp #3d362a;border-radius:30dp;background-color:#fdfaf2;font-family:Display;font-size:38dp;font-weight:bold;}
.stadium-model-path {position:absolute;left:20dp;top:18dp;height:64dp;display:flex;gap:12dp;}
.stadium-model-crumb {height:60dp;padding:0 28dp;border:2dp var(--rule);border-radius:30dp;background-color:#fdfaf2e0;decorator:none;font-size:30dp;color:#3d362a;display:flex;align-items:center;}
.stadium-model-crumb.here {background-color:#9a7a3a;border-color:#9a7a3a;color:#ffffff;}
.stadium-model-crumb span {display:block;}
.stadium-card {position:absolute;left:1822dp;top:134dp;width:790dp;height:1600dp;border:2dp var(--rule);border-radius:10dp;background-color:var(--panel);padding:36dp;}
.stadium-card h3 {display:block;margin:0 0 20dp 0;font-family:Display;font-size:60dp;line-height:72dp;font-weight:bold;}
.stadium-card .bank-fact {height:84dp;font-size:36dp;}
.stadium-card .bank-fact strong {font-size:42dp;}
.stadium-card .bank-part-track {margin:6dp 0 14dp 0;}
.stadium-card-pips {display:flex;gap:12dp;margin:16dp 0;}
.stadium-card-pips .pip {width:44dp;height:44dp;border:3dp var(--rule);border-radius:8dp;}
.stadium-card-pips .pip.on {background-color:#9a7a3a;border-color:#9a7a3a;}
.stadium-card-note {margin:30dp 0;font-size:32dp;line-height:44dp;color:var(--muted);}
.stadium-card-build {display:flex;align-items:center;justify-content:center;width:100%;height:110dp;font-size:42dp;margin-bottom:20dp;}
.stadium-card-back {display:flex;align-items:center;justify-content:center;width:100%;height:84dp;font-size:34dp;}
.stadium-model-tag>span {left:-160dp;top:-20dp;width:320dp;height:40dp;line-height:40dp;}
.stadium-model-hit,.stadium-model-hit:focus-visible {border-radius:40dp;}
.stadium-model-hit:focus-visible {border-color:transparent;background-color:transparent;}
.stadium-model-tag.letter>span {left:-30dp;top:-30dp;width:60dp;height:60dp;line-height:54dp;}
.stadium-model-tag>span {font-size:28dp;font-weight:bold;}
+1
View File
@@ -223,6 +223,7 @@ bool App::engine_stadium_action(const std::string &action, Rml::Element *target)
if (menu_ != "stadium" || engine_busy_ || !engine_fresh_ || !engine_stadium_value_.is_object() ||
amount_ || !popup_.empty())
return true;
if (stadium_focus_action(action, target)) return true;
stadium_view_defaults(stadium_view_);
const auto value = target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
const auto index = stadium_integer(value, 255);
+39
View File
@@ -25,10 +25,49 @@ void App::sync_stadium_draft() {
if(stadium_view_.at("dialog")=="block")if(auto *button=element("stadium-place-number"))button->SetInnerRML("<span class=\"control-label\">"+std::to_string(stadium_view_.at("draft").at("places").get<int64_t>())+"</span>");
dirty_=true;
}
// The camera of the card model: a new focus starts a flight of 0.6 seconds, during which
// only the picture is drawn anew; reduced motion jumps.
bool App::stadium_focus_action(const std::string &action,Rml::Element *target) {
if(action!="stadium-focus"||!target)return false;
if(stadium_flying_)return true;
const auto next=std::string(target->GetAttribute<Rml::String>("data-id",""));
if(next==stadium_focus_)return true;
stadium_view_defaults(stadium_view_);
const auto overview=stadium_overview(stadium_view_.at("future").get<bool>());
if(!overview.value("ok",false))return true;
const auto scene=stadium3d::build(overview,"#3d6f8f",theme_=="silver");
if(!next.empty()&&next!="stadium"&&!scene.centres.contains(next))return true;
stadium_camera_from_=stadium_camera_;stadium_camera_to_=stadium3d::camera_for(scene,next);
stadium_focus_=next;
const bool calm=ui_preferences_.is_object()&&ui_preferences_.contains("display")&&ui_preferences_.at("display").value("motion","full")=="reduced";
stadium_flying_=!calm&&config_.commands.empty();
stadium_flight_start_=SDL_GetTicks64();
focus_after_render_=next.find(':')!=std::string::npos?"stadium-card-build":"";
refresh();
return true;
}
void App::stadium_camera_tick() {
if(!stadium_flying_)return;
if(menu_!="stadium"||!world_){stadium_flying_=false;return;}
const double t=std::min(1.0,double(SDL_GetTicks64()-stadium_flight_start_)/600.0);
stadium_camera_=stadium3d::mix(stadium_camera_from_,stadium_camera_to_,t);
if(t>=1){stadium_flying_=false;refresh();return;}
stadium_view_defaults(stadium_view_);
const auto overview=stadium_overview(stadium_view_.at("future").get<bool>());
auto *art=element("stadium-model-art");
if(!overview.value("ok",false)||!art){stadium_flying_=false;refresh();return;}
std::string seat_colour;
if(const auto *own=world_->find("clubs",overview.value("club",std::string()));own&&!own->value("crest","").empty())seat_colour=renderer_.crest_colour(own->value("crest",""));
if(seat_colour.empty())seat_colour="#3d6f8f";
const auto drawing=stadium3d::draw(stadium3d::build(overview,seat_colour,theme_=="silver"),stadium_camera_,1790,1600);
art->SetInnerRML(picture(renderer_.diagram("stadium-model",drawing.svg,1790),1790,1600));
dirty_=true;
}
bool App::stadium_action(const std::string &action,Rml::Element *target) {
if(engine_mode_)return engine_stadium_action(action,target);
if(!action.starts_with("stadium-"))return false;
if(menu_!="stadium"||!source_||!world_||amount_||!popup_.empty()||!report_detail_kind_.empty())return true;
if(stadium_focus_action(action,target))return true;
stadium_view_defaults(stadium_view_);const auto s=snap();const auto club=stadium_managed(s);
if(club.empty()||!s.world)return true;
const auto overview=demo_stadium_view(s.state,*s.world,stadium_view_.at("future").get<bool>(),club);if(!overview.value("ok",false))return true;
+339
View File
@@ -0,0 +1,339 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// The stadium and its surroundings as a card model: bodies built from the blocks,
// facilities and periphery of the stadium overview, seen through a camera, sorted by depth
// and drawn as a vector picture. No renderer is involved: the same picture comes out on
// every platform, and the same input always gives the same picture.
//
// World: x east, y north, z up, the centre spot at the origin; lengths roughly in metres.
// Camera: an axonometric view (no perspective) turned by `yaw` around the vertical axis and
// raised by `pitch` above the ground, both in degrees.
#include "modern/ui/catalog.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include <map>
#include <sstream>
#include <string>
#include <vector>
namespace bmh::modern_ui::stadium3d {
struct Vec { double x = 0, y = 0, z = 0; };
struct Camera { double yaw = 28, pitch = 40, zoom = 1, tx = 0, ty = 0; };
struct Face {
std::vector<Vec> points;
std::string fill; // "#rrggbb"; empty for an outline
std::string part; // the selectable part it belongs to, e.g. "block:3"
bool dashed = false, open = false, flat = false; // flat: keep the fill as it is (no shading)
double stroke = 2, opacity = 1;
std::string ink; // stroke colour; empty: the scene's ink
std::vector<std::vector<Vec>> lines; // drawn on the face, in its ink at 40 %
double bias = 0; // moves the face towards the viewer in the depth order
};
struct Part { std::string id; Vec centre; double x0 = 0, y0 = 0, x1 = 0, y1 = 0, cx = 0, cy = 0; bool seen = false; };
struct Anchor { std::string id; double x = 0, y = 0; };
// centres: where a part's name stands and the camera flies to; anchors: every spot a click
// may choose the part at (the four masts of the floodlights are four anchors of one part)
struct Scene { std::vector<Face> faces; std::map<std::string, Vec> centres; std::vector<std::pair<std::string, Vec>> anchors; std::string ink = "#3d362a", accent = "#25617a"; };
struct Drawing { std::string svg; std::vector<Part> parts; std::vector<Anchor> anchors; };
inline std::string num(double value) {
std::ostringstream out;
out.imbue(std::locale::classic());
out << std::round(value * 10) / 10;
return out.str();
}
inline std::string shade(const std::string &colour, double factor) {
if (colour.size() != 7 || colour[0] != '#') return colour;
std::string out = "#";
for (size_t at = 1; at < 7; at += 2) {
const int value = std::clamp(int(std::lround(std::stoi(colour.substr(at, 2), nullptr, 16) * factor)), 0, 255);
static constexpr char digits[] = "0123456789abcdef";
out += digits[value / 16];
out += digits[value % 16];
}
return out;
}
inline Camera mix(const Camera &a, const Camera &b, double t) {
const double s = t * t * (3 - 2 * t); // ease in and out
double turn = std::fmod(b.yaw - a.yaw, 360.0);
if (turn > 180) turn -= 360;
if (turn < -180) turn += 360;
return {a.yaw + turn * s, a.pitch + (b.pitch - a.pitch) * s, a.zoom + (b.zoom - a.zoom) * s, a.tx + (b.tx - a.tx) * s, a.ty + (b.ty - a.ty) * s};
}
// The eight stands lie on a ring around the pitch; angles in degrees, counted from the east
// towards the south (as on the plan: A north-west, B north, ... H west).
constexpr std::array<std::array<double, 2>, 8> spans{{{{205, 245}}, {{245, 295}}, {{295, 335}}, {{-25, 25}}, {{25, 65}}, {{65, 115}}, {{115, 155}}, {{155, 205}}}};
inline Vec ring(double degrees, double offset, double z) {
const double a = degrees * 3.14159265358979 / 180;
return {(74 + offset) * std::cos(a), -(52 + offset) * std::sin(a), z};
}
inline double stand_depth(int64_t places, int64_t greatest) { return 12 + 44.0 * double(std::max<int64_t>(0, places)) / double(std::max<int64_t>(1, greatest)); }
inline void box(Scene &scene, const std::string &part, double x, double y, double w, double d, double h, const std::string &fill, bool planned = false, double z = 0) {
const Vec a{x - w / 2, y - d / 2, z}, b{x + w / 2, y - d / 2, z}, c{x + w / 2, y + d / 2, z}, e{x - w / 2, y + d / 2, z};
if (planned) { // not built: its footprint only
scene.faces.push_back({{a, b, c, e}, "", part, true, false, false, 2.5, .8, "", {}, 2});
return;
}
const auto up = [&](Vec v) { v.z = z + h; return v; };
for (const auto &[p, q] : std::array<std::pair<Vec, Vec>, 4>{{{a, b}, {b, c}, {c, e}, {e, a}}})
scene.faces.push_back({{p, q, up(q), up(p)}, fill, part});
scene.faces.push_back({{up(a), up(b), up(c), up(e)}, fill, part});
}
// Builds the model. `seats` is the club's colour; `paper` selects the light skin's tones.
inline Scene build(const Json &overview, const std::string &seats, bool paper) {
Scene scene;
scene.ink = paper ? "#3d362a" : "#d5dde3";
scene.accent = paper ? "#25617a" : "#9ac7d8";
const std::string plate = paper ? "#efe4c8" : "#27323c", wall = paper ? "#f6efdc" : "#55616c", terrace = paper ? "#d6ccb4" : "#6a7680",
roof = paper ? "#5a646e" : "#161d24", glass = "#9fc4d6", gold = "#c9962e", lamp = "#f3d778";
const auto level_of = [](const Json &row) { return row.value("display_level", row.value("level", 0)); };
const auto building = [](const Json &row) { return row.value("building", false); };
// the plate everything stands on
scene.faces.push_back({{{-350, -262, 0}, {350, -262, 0}, {350, 262, 0}, {-350, 262, 0}}, plate, "", false, false, true, 3, 1, "", {}, -1000});
// the pitch: its colour tells the state of the turf (facility 4)
const auto &facilities = overview.value("facilities", Json::array());
const auto facility = [&](size_t index) -> const Json & { static const Json none = Json::object(); return index < facilities.size() ? facilities[index] : none; };
const int turf = facilities.size() > 4 ? level_of(facility(4)) : 3;
const std::array<std::array<const char *, 2>, 5> greens{{{"#a39a5c", "#b3a868"}, {"#8f9e58", "#9dab62"}, {"#6fa25c", "#7bae66"}, {"#4f9a5c", "#57a765"}, {"#3f9456", "#49a260"}}};
const auto &green = greens[size_t(std::clamp(turf, 0, 4))];
{
std::vector<Vec> oval;
for (int a = 0; a < 360; a += 10) oval.push_back(ring(a, -4, 0));
scene.faces.push_back({oval, paper ? "#e2d6b8" : "#323e49", "", false, false, true, 2.5, 1, "", {}, -900});
for (int stripe = 0; stripe < 10; ++stripe) {
const double x0 = -52.5 + stripe * 10.5;
Face f{{{x0, -34, 0}, {x0 + 10.5, -34, 0}, {x0 + 10.5, 34, 0}, {x0, 34, 0}}, green[size_t(stripe % 2)], "facility:4", false, false, true, 0, 1, "", {}, -800};
scene.faces.push_back(f);
}
Face lines{{{-52.5, -34, 0}, {52.5, -34, 0}, {52.5, 34, 0}, {-52.5, 34, 0}}, "", "facility:4", false, false, true, 3, 1, "#f4f7ef", {}, -700};
scene.faces.push_back(lines);
scene.faces.push_back({{{0, -34, 0}, {0, 34, 0}}, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700});
std::vector<Vec> circle;
for (int a = 0; a <= 360; a += 20) circle.push_back({9.15 * std::cos(a * 3.14159265 / 180), 9.15 * std::sin(a * 3.14159265 / 180), 0});
scene.faces.push_back({circle, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700});
for (const double side : {-1.0, 1.0})
scene.faces.push_back({{{side * 52.5, -20, 0}, {side * 36, -20, 0}, {side * 36, 20, 0}, {side * 52.5, 20, 0}}, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700});
// turf heating (facility 2): pipes under the grass show through
if (facilities.size() > 2 && level_of(facility(2)) > 1)
for (double y = -28; y <= 28; y += 8)
scene.faces.push_back({{{-48, y, 0}, {48, y, 0}}, "", "facility:2", true, true, true, 2.5, .7, "#c8553d", {}, -650});
scene.centres["facility:4"] = {0, 0, 0};
}
// the stands
const auto &blocks = overview.at("blocks");
int64_t greatest = 1;
for (const auto &b : blocks) greatest = std::max(greatest, b.at("max_places").get<int64_t>());
double deepest = 0;
for (size_t i = 0; i < 8 && i < blocks.size(); ++i) {
const auto &b = blocks[i];
const std::string part = "block:" + std::to_string(i);
const double from = spans[i][0] + 1.6, to = spans[i][1] - 1.6, inner = 5;
const double depth = stand_depth(b.at("display_places").get<int64_t>(), greatest), most = stand_depth(b.at("max_places").get<int64_t>(), greatest);
const double top = 3 + depth * .58, outer = inner + depth;
deepest = std::max(deepest, inner + most);
const bool seated = b.at("display_seats").get<bool>(), roofed = b.at("display_roof").get<bool>();
const std::string tread = seated ? seats : terrace;
const int steps = 4;
for (int s = 0; s < steps; ++s) {
const double a0 = from + (to - from) * s / steps, a1 = from + (to - from) * (s + 1) / steps;
Face slope{{ring(a0, inner, 2), ring(a1, inner, 2), ring(a1, outer, top), ring(a0, outer, top)}, tread, part};
for (int row = 1; row < 5; ++row) { // rows of seats, or the steps of a terrace
const double t = row / 5.0;
slope.lines.push_back({ring(a0, inner + depth * t, 2 + (top - 2) * t), ring(a1, inner + depth * t, 2 + (top - 2) * t)});
}
scene.faces.push_back(slope);
scene.faces.push_back({{ring(a0, outer, 0), ring(a1, outer, 0), ring(a1, outer, top), ring(a0, outer, top)}, wall, part});
scene.faces.push_back({{ring(a0, inner, 0), ring(a1, inner, 0), ring(a1, inner, 2), ring(a0, inner, 2)}, wall, part});
if (roofed) {
const double edge = inner + depth * .45, height = top + 7;
Face slab{{ring(a0, edge, height + 2), ring(a1, edge, height + 2), ring(a1, outer + 3, height), ring(a0, outer + 3, height)}, roof, part};
slab.bias = 6;
slab.lines.push_back({ring(a0, outer, top), ring(a0, outer + 1, height)}); // a post
scene.faces.push_back(slab);
}
}
for (const double a : {from, to})
scene.faces.push_back({{ring(a, inner, 0), ring(a, inner, 2), ring(a, outer, top), ring(a, outer, 0)}, wall, part});
// how far the stand may grow: its footprint as a dashed line
std::vector<Vec> limit;
for (int s = 0; s <= steps; ++s) limit.push_back(ring(from + (to - from) * s / steps, inner + most, 0));
limit.push_back(ring(to, outer, 0));
limit.insert(limit.begin(), ring(from, outer, 0));
scene.faces.push_back({limit, "", part, true, true, true, 2.5, .55, "", {}, 0});
if (building(b)) { // a frame of scaffolding at the size being built
const double target = inner + stand_depth(b.at("job").value("places", b.at("display_places").get<int64_t>()), greatest);
const double height = 3 + (target - inner) * .58;
for (int s = 0; s < steps; ++s) {
const double a0 = from + (to - from) * s / steps, a1 = from + (to - from) * (s + 1) / steps;
Face frame{{ring(a0, target + 2, 0), ring(a1, target + 2, 0), ring(a1, target + 2, height + 9), ring(a0, target + 2, height + 9)}, gold, part, true, false, true, 3, .28, gold, {}, 4};
scene.faces.push_back(frame);
}
}
scene.centres[part] = ring((from + to) / 2, inner + depth / 2, top / 2);
}
// facility 0: four floodlight masts, taller and brighter with every level
if (!facilities.empty()) {
const int level = level_of(facility(0));
for (const double a : {45.0, 135.0, 225.0, 315.0}) {
const Vec foot = ring(a, deepest + 16, 0);
const double height = 34 + 9 * level;
if (level <= 0) { box(scene, "facility:0", foot.x, foot.y, 8, 8, 1, wall, true); continue; }
scene.faces.push_back({{foot, {foot.x, foot.y, height}}, "", "facility:0", false, true, true, 5, 1, "", {}, 3});
const double w = 7 + 2 * level, h = 4 + 1.5 * level;
const double nx = -foot.y / std::hypot(foot.x, foot.y), ny = foot.x / std::hypot(foot.x, foot.y);
Face panel{{{foot.x - nx * w, foot.y - ny * w, height - h}, {foot.x + nx * w, foot.y + ny * w, height - h}, {foot.x + nx * w, foot.y + ny * w, height + h}, {foot.x - nx * w, foot.y - ny * w, height + h}},
lamp, "facility:0", false, false, true, 2.5, 1, "", {}, 5};
for (int row = 1; row <= level; ++row) panel.lines.push_back({{foot.x - nx * w, foot.y - ny * w, height - h + 2 * h * row / (level + 1)}, {foot.x + nx * w, foot.y + ny * w, height - h + 2 * h * row / (level + 1)}});
scene.faces.push_back(panel);
scene.anchors.push_back({"facility:0", {foot.x, foot.y, height}});
}
scene.centres["facility:0"] = ring(45, deepest + 16, 30);
}
// facility 1: the score board behind the east curve
if (facilities.size() > 1) {
const int level = level_of(facility(1));
const Vec at = ring(0, deepest + 14, 0);
if (level <= 0) box(scene, "facility:1", at.x, at.y, 6, 30, 1, wall, true);
else {
box(scene, "facility:1", at.x, at.y - 12, 2, 2, 14, wall);
box(scene, "facility:1", at.x, at.y + 12, 2, 2, 14, wall);
box(scene, "facility:1", at.x, at.y, 4, 26 + 4 * level, 8 + 3 * level, "#2c3640", false, 14);
}
scene.centres["facility:1"] = {at.x, at.y, 16};
}
// facility 3: the lounge, a glass box on the south stand
if (facilities.size() > 3 && blocks.size() > 5) {
const int level = level_of(facility(3)) - 1;
const Vec at = ring(90, 5 + stand_depth(blocks[5].at("display_places").get<int64_t>(), greatest) + 9, 0);
if (level <= 0) box(scene, "facility:3", at.x, at.y, 40, 10, 1, wall, true);
else box(scene, "facility:3", at.x, at.y, 34 + 8 * level, 10, 6 + 4 * level, glass);
scene.centres["facility:3"] = {at.x, at.y, 8};
}
// facilities 2, 5, 6, 7 as small houses beside the ground: boiler, kiosks, workshop, gate
const std::array<std::tuple<size_t, double, double, const char *>, 4> houses{{{2, -150, -150, "#c8a58a"}, {5, 150, -150, "#d9c38a"}, {6, -150, 150, "#b9b3a2"}, {7, 150, 150, "#a9b7a0"}}};
for (const auto &[index, x, y, colour] : houses) {
if (index >= facilities.size()) continue;
const std::string part = "facility:" + std::to_string(index);
const int level = level_of(facility(index)) - (index == 2 || index == 5 ? 1 : 0);
if (level <= 0) box(scene, part, x, y, 26, 18, 1, wall, true);
else
for (int n = 0; n < std::min(level, 4); ++n) box(scene, part, x + (n - (std::min(level, 4) - 1) / 2.0) * 20, y, 16, 16, 7 + 2 * level, colour);
scene.centres[part] = {x, y, 6};
}
// the periphery on an outer ring: a house per object, growing with its level
const auto &periphery = overview.value("periphery", Json::array());
for (size_t i = 0; i < periphery.size(); ++i) {
const std::string part = "periphery:" + std::to_string(i);
const double a = (360.0 * double(i) / double(std::max<size_t>(1, periphery.size())) + 20) * 3.14159265358979 / 180;
const double x = 292 * std::cos(a), y = 214 * std::sin(a);
const int level = periphery[i].value("level", 0);
static constexpr std::array<const char *, 6> tones{"#c9b48c", "#b7c4a8", "#c8a79a", "#a9bccb", "#d2c08f", "#bfb2c4"};
if (level <= 0) box(scene, part, x, y, 44, 30, 1, wall, true);
else {
box(scene, part, x, y, 30 + 6 * level, 22 + 3 * level, 6 + 5 * level, tones[i % tones.size()]);
if (building(periphery[i])) box(scene, part, x, y, 40 + 6 * level, 30 + 3 * level, 1, gold, true);
}
scene.centres[part] = {x, y, 6};
}
scene.centres["stadium"] = {0, 0, 0};
for (const auto &[id, centre] : scene.centres)
if (id != "stadium" && id != "facility:0") scene.anchors.push_back({id, centre});
return scene;
}
// Draws the scene. Faces of `highlight` get an accented outline; `parts` lists where every
// selectable part lies in the picture (in its own units, 0..width and 0..height).
inline Drawing draw(const Scene &scene, const Camera &camera, double width, double height, const std::string &highlight = {}) {
const double yaw = camera.yaw * 3.14159265358979 / 180, pitch = camera.pitch * 3.14159265358979 / 180;
const double cs = std::cos(yaw), sn = std::sin(yaw), sp = std::sin(pitch), cp = std::cos(pitch);
const double scale = camera.zoom * height / 620.0;
struct Flat { double x, y, depth; };
const auto project = [&](const Vec &v) {
const double x = (v.x - camera.tx) * cs - (v.y - camera.ty) * sn, y = (v.x - camera.tx) * sn + (v.y - camera.ty) * cs;
return Flat{width / 2 + x * scale, height / 2 - (y * sp + v.z * cp) * scale, y * cp - v.z * sp};
};
struct Item { const Face *face; double depth; };
std::vector<Item> order;
order.reserve(scene.faces.size());
for (const auto &face : scene.faces) {
double depth = 0;
for (const auto &p : face.points) depth += project(p).depth;
order.push_back({&face, depth / double(std::max<size_t>(1, face.points.size())) - face.bias});
}
std::stable_sort(order.begin(), order.end(), [](const Item &a, const Item &b) { return a.depth > b.depth; });
std::map<std::string, Part> parts;
Drawing out;
out.svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 " + num(width) + " " + num(height) + "\">";
const Vec light{-0.42, -0.5, 0.76};
for (const auto &item : order) {
const auto &face = *item.face;
std::string path;
for (size_t i = 0; i < face.points.size(); ++i) {
const auto p = project(face.points[i]);
path += (i ? "L" : "M") + num(p.x) + " " + num(p.y);
if (!face.part.empty()) {
auto &part = parts[face.part];
if (!part.seen) { part.id = face.part; part.x0 = part.x1 = p.x; part.y0 = part.y1 = p.y; part.seen = true; }
part.x0 = std::min(part.x0, p.x); part.x1 = std::max(part.x1, p.x); part.y0 = std::min(part.y0, p.y); part.y1 = std::max(part.y1, p.y);
}
}
if (!face.open) path += "Z";
std::string fill = "none";
if (!face.fill.empty()) {
double factor = 1;
if (!face.flat && face.points.size() >= 3) {
const Vec &a = face.points[0], &b = face.points[1], &c = face.points[2];
Vec n{(b.y - a.y) * (c.z - a.z) - (b.z - a.z) * (c.y - a.y), (b.z - a.z) * (c.x - a.x) - (b.x - a.x) * (c.z - a.z), (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)};
const double length = std::sqrt(n.x * n.x + n.y * n.y + n.z * n.z);
if (length > 0) factor = .74 + .26 * std::abs((n.x * light.x + n.y * light.y + n.z * light.z) / length);
}
fill = shade(face.fill, factor);
}
const bool lit = !highlight.empty() && face.part == highlight;
const std::string ink = lit ? scene.accent : face.ink.empty() ? scene.ink : face.ink;
out.svg += "<path d=\"" + path + "\" fill=\"" + fill + "\" fill-opacity=\"" + (face.fill.empty() ? std::string("1") : num(face.opacity)) + "\"" +
(face.stroke > 0 || lit ? " stroke=\"" + ink + "\" stroke-width=\"" + num((lit ? std::max(face.stroke, 2.0) + 2 : face.stroke) * std::sqrt(camera.zoom)) + "\" stroke-linejoin=\"round\" stroke-linecap=\"round\"" : std::string()) +
(face.dashed ? " stroke-dasharray=\"" + num(9 * std::sqrt(camera.zoom)) + " " + num(7 * std::sqrt(camera.zoom)) + "\"" : std::string()) +
(face.fill.empty() && face.opacity < 1 ? " stroke-opacity=\"" + num(face.opacity) + "\"" : std::string()) + "/>";
for (const auto &line : face.lines) {
std::string d;
for (size_t i = 0; i < line.size(); ++i) { const auto p = project(line[i]); d += (i ? "L" : "M") + num(p.x) + " " + num(p.y); }
out.svg += "<path d=\"" + d + "\" fill=\"none\" stroke=\"" + (face.fill == "" ? ink : std::string("#ffffff")) + "\" stroke-opacity=\".45\" stroke-width=\"" + num(1.6 * std::sqrt(camera.zoom)) + "\"/>";
}
}
out.svg += "</svg>";
for (auto &[id, part] : parts) {
if (const auto found = scene.centres.find(id); found != scene.centres.end()) {
part.centre = found->second;
const auto p = project(found->second);
part.cx = p.x; part.cy = p.y;
} else { part.cx = (part.x0 + part.x1) / 2; part.cy = (part.y0 + part.y1) / 2; }
out.parts.push_back(part);
}
for (const auto &[id, at] : scene.anchors) {
const auto p = project(at);
out.anchors.push_back({id, p.x, p.y});
}
return out;
}
// Where the camera stands for a focus: "" the whole ground with its surroundings, "stadium"
// the bowl, a part id that part, turned so that it lies in front.
inline Camera camera_for(const Scene &scene, const std::string &focus) {
if (focus.empty()) return {28, 42, 1.32, 0, 0};
if (focus == "stadium") return {28, 44, 2.0, 0, 0};
if (focus == "periphery") return {28, 52, 1.15, 0, 0};
const auto found = scene.centres.find(focus);
if (found == scene.centres.end()) return {28, 44, 2.0, 0, 0};
const Vec c = found->second;
if (std::hypot(c.x, c.y) < 1) return {28, 50, 3.0, 0, 0};
// turn the part to the near side, a little off the axis so that its flank shows
const double towards = std::atan2(c.y, c.x) * 180 / 3.14159265358979;
const bool outer = focus.starts_with("periphery:");
return {-90 - towards + 22, 38, outer ? 2.6 : focus.starts_with("block:") ? 3.0 : 3.2, c.x * .82, c.y * .82};
}
} // namespace bmh::modern_ui::stadium3d
+76 -19
View File
@@ -140,26 +140,87 @@ std::string App::render_stadium() {
return "<span class=\"stadium-art-overlay\" style=\""+rect(0,0,w,viewport_h)+"\">"+picture(renderer_.diagram("stadium-card-overlay-"+std::to_string(i)+"-"+std::to_string(level)+"-"+theme_,stadium_svg(body,w,viewport_h),1564),w,viewport_h)+"</span>";
};
std::string out="<div class=\"stadium-screen"+std::string(view=="panorama"?" periphery":"")+"\" id=\"stadium-underlay\">";
if(view!="panorama")out+="<header class=\"stadium-heading\"><div class=\"stadium-heading-copy\"><h2>"+esc(overview.at("name").get<std::string>())+"</h2><p>"+(view=="inside"?"Innenansicht":"Stadiondaten")+"</p></div><div class=\"stadium-summary\"><div><span>"+(future?"Geplante Kapazität":"Verfügbare Kapazität")+std::string("</span><strong>")+number(overview.at("capacity").get<int64_t>())+" <small>Plätze</small></strong></div><div><span>"+std::string(engine_mode_?"Vereinskasse":"Ausbaubudget")+"</span><strong class=\""+std::string(engine_mode_?money_classes(overview.at("budget").get<int64_t>()):"")+"\">"+esc(stadium_cash(overview.at("budget")))+"</strong></div></div></header>";
if(view!="panorama")out+="<header class=\"stadium-heading\"><div class=\"stadium-heading-copy\"><h2>"+esc(overview.at("name").get<std::string>())+"</h2><p>"+(view=="inside"?"Modell · ein Bauteil anklicken":"Stadiondaten")+"</p></div><div class=\"stadium-summary\"><div><span>"+(future?"Geplante Kapazität":"Verfügbare Kapazität")+std::string("</span><strong>")+number(overview.at("capacity").get<int64_t>())+" <small>Plätze</small></strong></div><div><span>"+std::string(engine_mode_?"Vereinskasse":"Ausbaubudget")+"</span><strong class=\""+std::string(engine_mode_?money_classes(overview.at("budget").get<int64_t>()):"")+"\">"+esc(stadium_cash(overview.at("budget")))+"</strong></div></div></header>";
if(view=="inside") {
constexpr double bowl_h=1430.0*1045/1505;
// the plan is drawn from the blocks; the manager's club gives the seats their colour
// the ground as a card model: the camera stands where the focus is, parts are chosen in the picture
std::string seat_colour;
if(const auto *own=world_->find("clubs",club);own&&!own->value("crest","").empty())seat_colour=renderer_.crest_colour(own->value("crest",""));
if(seat_colour.empty())seat_colour="#3d6f8f";
std::string plan_key=seat_colour+theme_+(future?"f":"n");
int64_t greatest=1,built_sum=0,most_sum=0;
for(const auto &b:overview.at("blocks")){greatest=std::max(greatest,b.at("max_places").get<int64_t>());built_sum+=b.at("display_places").get<int64_t>();most_sum+=b.at("max_places").get<int64_t>();
plan_key+="-"+std::to_string(b.at("display_places").get<int64_t>())+(b.at("display_seats").get<bool>()?"s":"t")+(b.at("display_roof").get<bool>()?"r":"o")+(b.at("building").get<bool>()?"b"+std::to_string(b.at("job").value("places",int64_t(0))):"");}
out+="<div class=\"stadium-bowl stadium-plan\">"+picture(renderer_.diagram("stadium-plan-"+plan_key,stadium_plan_svg(overview.at("blocks"),seat_colour,theme_),2852),1426,bowl_h-4);
for(size_t i=0;i<8;++i) {
const auto &b=overview.at("blocks")[i];const bool building=b.at("building").get<bool>();
const double depth=48+stadium_plan_depth(b.at("display_places").get<int64_t>(),greatest)/2;
const auto at=stadium_plan_point((stadium_plan_spans[i][0]+stadium_plan_spans[i][1])/2,depth);
out+=btn("stadium-block",b.at("letter").get<std::string>(),std::string("stadium-letter ")+(building?"building":""),"id=\"stadium-letter-"+std::to_string(i)+"\" data-id=\""+std::to_string(i)+"\" style=\""+rect(at[0]*1426/stadium_plan_w-38,at[1]*(bowl_h-4)/stadium_plan_h-38,76,76)+"\" aria-label=\"Block "+b.at("letter").get<std::string>()+", "+esc(b.at("name").get<std::string>())+"\" "+(building?"disabled=\"disabled\"":""));
const auto scene=stadium3d::build(overview,seat_colour,theme_=="silver");
if(stadium_focus_!=""&&stadium_focus_!="stadium"&&!scene.centres.contains(stadium_focus_))stadium_focus_="stadium";
if(!stadium_flying_)stadium_camera_=stadium3d::camera_for(scene,stadium_focus_);
constexpr double mw=1790,mh=1600;
const bool part_focus=stadium_focus_.find(':')!=std::string::npos;
const auto drawing=stadium3d::draw(scene,stadium_camera_,mw,mh,part_focus?stadium_focus_:std::string());
out+="<div class=\"stadium-model\" id=\"stadium-model\"><div id=\"stadium-model-art\">"+picture(renderer_.diagram("stadium-model",drawing.svg,stadium_flying_?1790:3580),mw,mh)+"</div>";
const auto name_of=[&](const std::string &id)->std::string {
const auto index=size_t(std::stoul(id.substr(id.find(':')+1)));
if(id.starts_with("block:"))return "Block "+overview.at("blocks")[index].at("letter").get<std::string>();
if(id.starts_with("facility:"))return overview.at("facilities")[index].at("name").get<std::string>();
return overview.at("periphery")[index].at("name").get<std::string>();
};
if(!stadium_flying_) {
// a click beside every part leads one level back
if(!stadium_focus_.empty())out+=btn("stadium-focus","","stadium-model-back","id=\"stadium-model-ground\" data-id=\""+std::string(part_focus&&!stadium_focus_.starts_with("periphery:")?"stadium":"")+"\" aria-label=\"Zurück\" style=\""+rect(0,0,mw,mh)+"\"");
double sx0=mw,sy0=mh,sx1=0,sy1=0;
for(const auto &part:drawing.parts)if(part.id.starts_with("block:")){sx0=std::min(sx0,part.x0);sy0=std::min(sy0,part.y0);sx1=std::max(sx1,part.x1);sy1=std::max(sy1,part.y1);}
// every part is chosen at its anchors: a spot of a size that follows the zoom
const double reach=std::clamp(30*stadium_camera_.zoom,44.0,110.0);
std::map<std::string,int> spots;
// stands last: where spots overlap, the stand is the one that is hit
auto anchors=drawing.anchors;
std::stable_sort(anchors.begin(),anchors.end(),[](const auto &a,const auto &b){return !a.id.starts_with("block:")&&b.id.starts_with("block:");});
for(const auto &anchor:anchors) {
const bool outer=anchor.id.starts_with("periphery:");
// the whole ground: the bowl as one part, and the houses around it; inside the bowl: its parts
if(stadium_focus_.empty()&&!outer)continue;
if(part_focus&&anchor.id==stadium_focus_)continue;
if(anchor.x<reach||anchor.y<reach||anchor.x>mw-reach||anchor.y>mh-reach)continue;
const auto name=name_of(anchor.id);const int spot=spots[anchor.id]++;
out+=btn("stadium-focus","","stadium-model-hit","id=\"stadium-part-"+esc(anchor.id.substr(0,anchor.id.find(':'))+"-"+anchor.id.substr(anchor.id.find(':')+1))+(spot?"-"+std::to_string(spot):std::string())+"\" data-id=\""+esc(anchor.id)+"\" data-stadium-hint=\""+esc(name)+"\" aria-label=\""+esc(name)+"\" style=\""+rect(anchor.x-reach,anchor.y-reach*.8,2*reach,1.6*reach)+"\"");
}
for(const auto &part:drawing.parts) {
if(stadium_focus_.empty()&&!part.id.starts_with("periphery:"))continue;
if(part.cx<60||part.cy<60||part.cx>mw-60||part.cy>mh-60)continue;
const bool letter=part.id.starts_with("block:");
out+="<span class=\"stadium-model-tag"+std::string(letter?" letter":"")+"\" style=\"left:"+scalar(part.cx)+"dp;top:"+scalar(part.cy+(letter?0:reach*.55))+"dp;\"><span>"+esc(letter?overview.at("blocks")[size_t(std::stoul(part.id.substr(6)))].at("letter").get<std::string>():name_of(part.id))+"</span></span>";
}
if(stadium_focus_.empty()&&sx1>sx0)out+=btn("stadium-focus","<span>Stadion</span>","stadium-model-hit bowl","id=\"stadium-part-stadium\" data-id=\"stadium\" aria-label=\"Stadion ansehen\" style=\""+rect(sx0-10,sy0-10,sx1-sx0+20,sy1-sy0+20)+"\"");
}
out+="<div class=\"stadium-plan-legend\"><span class=\"key seats\" style=\"background-color:"+seat_colour+";\"></span><span>Sitzplätze</span><span class=\"key terrace\"></span><span>Stehplätze</span><span class=\"key roof\"></span><span>Dach</span><span class=\"key most\"></span><span>Ausbaugrenze</span><span class=\"key building\"></span><span>Im Bau</span></div>"
"<div class=\"stadium-plan-total\"><strong>"+number(built_sum)+"</strong><span>von "+number(most_sum)+" Plätzen ausgebaut</span><div class=\"bank-part-track\"><div style=\"width:"+scalar(most_sum>0?built_sum*100.0/most_sum:0)+"%;\"></div></div></div></div>";
out+="<div class=\"stadium-model-path\">"+btn("stadium-focus","Gelände","stadium-model-crumb"+std::string(stadium_focus_.empty()?" here":""),"id=\"stadium-crumb-all\" data-id=\"\"")+
btn("stadium-focus","Stadion","stadium-model-crumb"+std::string(stadium_focus_=="stadium"?" here":""),"id=\"stadium-crumb-stadium\" data-id=\"stadium\"")+
(part_focus?"<span class=\"stadium-model-crumb here\"><span>"+esc(name_of(stadium_focus_))+"</span></span>":std::string())+"</div></div>";
if(part_focus) {
// the part's card: what stands there today, and the way to build on
const auto index=size_t(std::stoul(stadium_focus_.substr(stadium_focus_.find(':')+1)));
std::string facts,action,label="Ausbauen";bool busy=false,full=false;
const auto fact=[](const std::string &k,const std::string &v){return "<div class=\"bank-fact\"><span>"+k+"</span><strong>"+v+"</strong></div>";};
if(stadium_focus_.starts_with("block:")) {
const auto &b=overview.at("blocks")[index];busy=b.at("building").get<bool>();action="stadium-block";
const int64_t places=b.at("display_places").get<int64_t>(),most=b.at("max_places").get<int64_t>();
facts=fact("Plätze",number(places)+" von "+number(most))+"<div class=\"bank-part-track\"><div style=\"width:"+scalar(std::clamp(places*100.0/double(std::max<int64_t>(1,most)),0.0,100.0))+"%;\"></div></div>"+
fact("Sitzplätze",b.at("display_seats").get<bool>()?"ja":"nein, Stehplätze")+fact("Dach",b.at("display_roof").get<bool>()?"ja":"nein");
if(busy)facts+=fact("Im Bau",number(b.at("job").at("places").get<int64_t>())+" Plätze · noch "+std::to_string(b.at("job").at("weeks").get<int>())+" Wochen");
full=places>=most&&b.at("display_seats").get<bool>()&&b.at("display_roof").get<bool>();
} else if(stadium_focus_.starts_with("facility:")) {
const auto &f=overview.at("facilities")[index];busy=f.at("building").get<bool>();action="stadium-facility";
facts=fact("Zustand",esc(f.at("display_label").get<std::string>()));
if(busy)facts+=fact("Im Bau","noch "+std::to_string(f.at("job").at("weeks").get<int>())+" Wochen");
full=f.value("available",true)!=true;label=index>=4?"Erneuern":"Ausbauen";
} else {
const auto &p=overview.at("periphery")[index];busy=p.at("building").get<bool>();action="stadium-periphery";
const int level=p.at("level").get<int>(),most=p.at("max_level").get<int>();
facts=fact("Ausbaustufe",std::to_string(level)+" von "+std::to_string(most));
std::string pips="<div class=\"stadium-card-pips\">";for(int k=0;k<most;++k)pips+=k<level?"<div class=\"pip on\"></div>":"<div class=\"pip\"></div>";
facts+=pips+"</div>";
if(busy)facts+=fact("Im Bau","noch "+std::to_string(p.at("job").at("weeks").get<int>())+" Wochen");
full=level>=most;
}
out+="<aside class=\"stadium-card\" id=\"stadium-card\"><h3>"+esc(name_of(stadium_focus_))+"</h3>"+facts+
"<p class=\"stadium-card-note\">"+std::string(busy?"Hier wird gebaut.":full?"Hier ist alles ausgebaut.":"Preis und Bauzeit nennt das Angebot der Baufirma.")+"</p>"+
btn(action,label,"primary stadium-card-build","id=\"stadium-card-build\" data-id=\""+std::to_string(index)+"\" "+(busy||full?"disabled=\"disabled\"":""))+
btn("stadium-focus","Zurück","stadium-card-back","id=\"stadium-card-back\" data-id=\""+std::string(stadium_focus_.starts_with("periphery:")?"":"stadium")+"\"")+"</aside>";
} else {
for(size_t i=0;i<8;++i) {
const auto &b=overview.at("blocks")[i];const bool building=b.at("building").get<bool>();
const auto &j=b.at("job");const auto detail=future?(building?"Im Bau: "+number(j.at("places").get<int64_t>())+" Plätze":"kein Bau"):number(b.at("display_places").get<int64_t>())+" Plätze";
@@ -167,10 +228,6 @@ std::string App::render_stadium() {
const double top=note.empty()?48.625:34.625;
out+=btn("stadium-block","<span class=\"stadium-block-copy\" style=\"top:"+scalar(top)+"dp;\"><strong>Block "+b.at("letter").get<std::string>()+"</strong><span>"+esc(detail)+"</span><small>"+esc(note)+"</small></span><span class=\"stadium-block-bar\"><span style=\"width:"+scalar(std::clamp(b.at("display_places").get<int64_t>()*100.0/double(std::max<int64_t>(1,b.at("max_places").get<int64_t>())),0.0,100.0))+"%;\"></span></span><span class=\"stadium-block-icons\">"+feature("seats",b.at("display_seats").get<bool>(),76)+feature("roof",b.at("display_roof").get<bool>(),76)+"</span>","stadium-block "+std::string(building?"building":""),"id=\"stadium-block-"+std::to_string(i)+"\" data-id=\""+std::to_string(i)+"\" style=\""+rect(1822,134+i*201.25,790,189.25)+"\" "+(building?"disabled=\"disabled\"":""));
}
for(size_t i=0;i<8;++i) {
const auto &f=overview.at("facilities")[i];const int level=f.at("display_level").get<int>();const auto art=renderer_.image("stadium.facility."+std::to_string(i)+".level."+std::to_string(level),false,2048);const double h=art.width?391.0*art.height/art.width:215;
const auto caption=f.at("display_label").get<std::string>()+(f.at("building").get<bool>()?" · "+std::to_string(f.at("job").at("weeks").get<int>())+" W.":"");
out+=btn("stadium-facility","<span class=\"stadium-facility-picture\">"+picture(art,391,125,true)+art_overlay(int(i),level,391,h)+"</span><strong>"+esc(f.at("name").get<std::string>())+"</strong><span class=\"stadium-facility-caption\">"+esc(caption)+"</span>","stadium-facility","id=\"stadium-facility-"+std::to_string(i)+"\" data-id=\""+std::to_string(i)+"\" style=\""+rect((i%4)*411,1148+(i/4)*214,395,198)+"\" aria-label=\""+esc(f.at("name").get<std::string>()+", "+caption)+"\" "+(f.at("building").get<bool>()?"disabled=\"disabled\"":""));
}
} else if(view=="panorama") {
constexpr double scale=2612.0/1920;
+11 -1
View File
@@ -39,6 +39,7 @@
#include "modern/ui/settings_presentation.hpp"
#include "modern/ui/ui_preferences.hpp"
#include "modern/ui/desktop.hpp"
#include "modern/ui/stadium_model.hpp"
#include "modern/ui/demo_widgets.hpp"
#include "modern/ui/demo_files.hpp"
#include "modern/ui/gui_assets.hpp"
@@ -488,6 +489,14 @@ class App final : public Rml::EventListener {
std::shared_ptr<const Catalog> transfer_world_;
Json career_view_ = Json::object(), rankings_view_ = Json::object();
Json stadium_view_ = Json::object();
// the stadium's card model: what the camera looks at ("" the whole ground, "stadium", or a
// part such as "block:3"), and its flight from one focus to the next
std::string stadium_focus_;
stadium3d::Camera stadium_camera_, stadium_camera_from_, stadium_camera_to_;
bool stadium_flying_ = false;
uint64_t stadium_flight_start_ = 0;
bool stadium_focus_action(const std::string &, Rml::Element *);
void stadium_camera_tick();
uint64_t stadium_revision_ = 0;
std::shared_ptr<const Catalog> stadium_world_;
const DataSource *stadium_source_ = nullptr;
@@ -768,7 +777,7 @@ class App final : public Rml::EventListener {
statistics_view_ = Json::object(); statistics_trophy_ = Json::object();
statistics_scrolls_ = Json::object();
reset_news();
stadium_view_ = Json::object(); stadium_revision_ = 0;
stadium_view_ = Json::object(); stadium_revision_ = 0; stadium_focus_.clear(); stadium_flying_ = false;
stadium_world_.reset(); stadium_source_ = nullptr;
advertising_selected_ = -1; advertising_offer_ = 0; advertising_revision_ = 0; advertising_world_.reset();
toto_column_ = 0; toto_dialog_.clear();
@@ -1240,6 +1249,7 @@ class App final : public Rml::EventListener {
void frame() {
engine_create_poll();
engine_files_poll();
stadium_camera_tick();
if (engine_mode_) { engine_frame(); return; }
front_poll();
flush_selects();
+26
View File
@@ -4,6 +4,7 @@
#include "modern/ui/demo_reports.hpp"
#include "modern/ui/demo_finance.hpp"
#include "modern/ui/desktop.hpp"
#include "modern/ui/stadium_model.hpp"
#include "modern/ui/gui_assets.hpp"
#include "modern/ui/model.hpp"
#include "modern/ui/crest_contrast.hpp"
@@ -539,6 +540,31 @@ int main(int argc, char **argv) try {
require(fit_desktop(tall) && valid_desktop(tall) && tall["objects"]["app-almanac"]["y"].get<int>() + 224 <= 2160,
"Object below the shown desk was not brought back into sight");
}
// the stadium's card model: drawn from the overview alone, the same picture for the same input
{
Json overview = {{"blocks", Json::array()}, {"facilities", Json::array()}, {"periphery", Json::array()}};
for (int i = 0; i < 8; ++i)
overview["blocks"].push_back({{"letter", std::string(1, char('A' + i))}, {"display_places", 3000 + 1000 * i}, {"max_places", 18000},
{"display_seats", i % 2 == 0}, {"display_roof", i == 3}, {"building", i == 5}, {"job", {{"places", 9000}, {"weeks", 12}}}});
for (int i = 0; i < 8; ++i) overview["facilities"].push_back({{"name", "Anlage"}, {"display_level", 2}, {"building", false}});
for (int i = 0; i < 14; ++i) overview["periphery"].push_back({{"name", "Haus"}, {"level", i % 3}, {"max_level", 3}, {"building", false}});
const auto scene = stadium3d::build(overview, "#aa2233", true);
require(scene.centres.contains("block:7") && scene.centres.contains("facility:0") && scene.centres.contains("periphery:13"),
"Stadium model misses a selectable part");
const auto whole = stadium3d::draw(scene, stadium3d::camera_for(scene, ""), 1790, 1600);
const auto again = stadium3d::draw(stadium3d::build(overview, "#aa2233", true), stadium3d::camera_for(scene, ""), 1790, 1600);
require(whole.svg == again.svg && whole.svg.size() > 4000,
"Stadium model is not drawn the same way twice");
require(std::count_if(whole.anchors.begin(), whole.anchors.end(), [](const auto &a) { return a.id == "facility:0"; }) == 4,
"Each floodlight mast should choose the floodlights");
const auto near = stadium3d::camera_for(scene, "block:5"), far = stadium3d::camera_for(scene, "stadium");
require(near.zoom > far.zoom && stadium3d::mix(far, near, 0).zoom == far.zoom && stadium3d::mix(far, near, 1).zoom == near.zoom,
"Camera flight does not start and end at its stations");
const auto close = stadium3d::draw(scene, near, 1790, 1600, "block:5");
const auto chosen = std::find_if(close.parts.begin(), close.parts.end(), [](const auto &p) { return p.id == "block:5"; });
require(chosen != close.parts.end() && chosen->cx > 300 && chosen->cx < 1490 && chosen->cy > 300 && chosen->cy < 1300,
"The chosen stand does not lie in the middle of the picture");
}
auto corrupt = layout;
corrupt["objects"]["calendar"]["x"] = 999999;
require(!valid_desktop(corrupt), "Out of bounds desktop accepted");