From b3e5ef4b4ddffca6f87705c429fb8723490b0fa6 Mon Sep 17 00:00:00 2001 From: Weyoune Date: Sat, 14 Nov 2026 20:47:31 +0100 Subject: [PATCH] The desk is as high as the screen shows of it On a screen taller than 16:9 the career's desk offers its lower rows for widgets and icons (up to 4:3). A stored layout may use the greatest height; objects a shorter screen cannot show are moved back into sight. Property names read as nouns throughout the bank. Co-Authored-By: Claude Fable 5.2 --- assets/modern/bank.rcss | 3 ++- src/modern/ui/controls.inc | 2 +- src/modern/ui/desktop.cpp | 28 ++++++++++++++++++++++++---- src/modern/ui/desktop.hpp | 5 +++++ src/modern/ui/engine_dto.cpp | 18 ++++++++++++++++++ src/modern/ui/view.cpp | 16 ++++++++++++++++ tests/modern_ui_core_tests.cpp | 16 ++++++++++++++++ 7 files changed, 82 insertions(+), 6 deletions(-) diff --git a/assets/modern/bank.rcss b/assets/modern/bank.rcss index 87fcc07..80d4dec 100644 --- a/assets/modern/bank.rcss +++ b/assets/modern/bank.rcss @@ -142,7 +142,8 @@ body.silver {--bank-gold:#9a7a3a;--bank-panel:#ffffff8c;} .stock-chart,body.silver .stock-chart,body.matchday .stock-chart {position:relative;left:0;top:0;width:920dp;height:500dp;margin-top:10dp;border:2dp var(--rule);border-radius:8dp;background-color:var(--bank-panel);} .stock-legend {display:flex;align-items:center;height:56dp;margin:0;font-size:26dp;color:var(--muted);} .stock-legend .key {display:block;width:36dp;height:8dp;border-radius:4dp;margin:0 12dp 0 26dp;} -.stock-legend .key.course {margin-left:0;background-color:#25617a;} +.stock-legend .key.course {margin-left:0;background-color:#9ac7d8;} +body.silver .stock-legend .key.course {background-color:#25617a;} .stock-legend .key.average {background-color:var(--bank-gold);} .stock-legend .key.high {width:16dp;height:16dp;border-radius:8dp;background-color:var(--win);} .stock-legend .key.low {width:16dp;height:16dp;border-radius:8dp;background-color:var(--loss);} diff --git a/src/modern/ui/controls.inc b/src/modern/ui/controls.inc index b78f78f..6b0d0ce 100644 --- a/src/modern/ui/controls.inc +++ b/src/modern/ui/controls.inc @@ -92,7 +92,7 @@ void App::drag_event(Rml::Event &event) { const double left = std::clamp(drag_.left + (x - drag_.x) / scale_, 0.0, 3840.0 - o.value("w", 224)); const double top = std::clamp(drag_.top + (y - drag_.y) / scale_, 224.0, - 2160.0 - o.value("h", 224)); + double(desktop_height()) - o.value("h", 224)); o["x"] = left; o["y"] = top; if (auto *n = element("object-" + drag_.id)) { diff --git a/src/modern/ui/desktop.cpp b/src/modern/ui/desktop.cpp index 7329f9e..8c99beb 100644 --- a/src/modern/ui/desktop.cpp +++ b/src/modern/ui/desktop.cpp @@ -8,6 +8,11 @@ namespace bmh::modern_ui { namespace { constexpr int pitch = 248, gap = 24, cell = 224, left = 64, top = 224; +// The desk is 3840 wide and as high as the screen shows of it: 2160 on a 16:9 screen, more +// on a taller one. A stored layout may use the greatest height; what a screen cannot show +// is moved up by fit_desktop. +constexpr int tallest_desk = 2880; +int desk_height = 2160; bool overlaps(const Json &a, const Json &b, int spacing) { const int x = a.at("x"), y = a.at("y"), bx = b.at("x"), by = b.at("y"); return x < bx + b.at("w").get() + spacing && @@ -23,7 +28,7 @@ bool find_space(Json &layout, const std::string &id, int near_x, int near_y, const int step = grid ? pitch : 32; double best = std::numeric_limits::max(); int found_x = -1, found_y = -1; - for (int y = top; y + height <= 2160 - gap; y += step) { + for (int y = top; y + height <= desk_height - gap; y += step) { for (int x = left; x + width <= 3840 - gap; x += step) { Json candidate = object; candidate["x"] = x; @@ -181,7 +186,7 @@ bool valid_desktop(const Json &layout) { return false; const int x = o.at("x"), y = o.at("y"), w = o.at("w"), h = o.at("h"); return w > 0 && h > 0 && w <= 3840 && h <= 2160 - top && x >= 0 && - y >= top && x <= 3840 - w && y <= 2160 - h && + y >= top && x <= 3840 - w && y <= tallest_desk - h && (widget || (w == cell && h == cell && o.at("visible") == true)); }; for (const auto &d : widget_definitions()) { @@ -202,6 +207,21 @@ bool valid_desktop(const Json &layout) { return false; } } +void set_desktop_height(int height) { desk_height = std::clamp(height, 2160, tallest_desk); } +int desktop_height() { return desk_height; } +bool fit_desktop(Json &layout) { + if (!valid_desktop(layout)) return false; + auto next = layout; + bool moved = false; + for (auto &[id, o] : next["objects"].items()) { + if (!o.value("visible", false) || o.at("y").get() + o.at("h").get() <= desk_height) continue; + const int x = o.at("x"), y = desk_height - o.at("h").get(); + if (find_space(next, id, x, y, true)) moved = true; + else { o["y"] = std::max(top, y); moved = true; } // a full desk: at least within sight + } + if (moved && valid_desktop(next)) layout = std::move(next); + return moved; +} bool migrate_desktop(Json &layout) { try { if (layout.at("objects").contains("app-almanac")) @@ -227,7 +247,7 @@ bool place_desktop_object(Json &layout, const std::string &id, int x, int y, return false; if (!next.at("grid").get()) { o["x"] = std::clamp(x, 0, 3840 - o.at("w").get()); - o["y"] = std::clamp(y, top, 2160 - o.at("h").get()); + o["y"] = std::clamp(y, top, desk_height - o.at("h").get()); } else if (!find_space(next, id, x, y, nearest)) return false; o["visible"] = true; @@ -318,7 +338,7 @@ bool add_desktop_widget(Json &layout, const std::string &id, int columns, if (next.at("grid") == true) return false; o["x"] = (3840 - o.at("w").get()) / 2; - o["y"] = (2160 - o.at("h").get()) / 2; + o["y"] = (desk_height - o.at("h").get()) / 2; } o["visible"] = true; if (!valid_desktop(next)) diff --git a/src/modern/ui/desktop.hpp b/src/modern/ui/desktop.hpp index df2d567..fd343cc 100644 --- a/src/modern/ui/desktop.hpp +++ b/src/modern/ui/desktop.hpp @@ -16,6 +16,11 @@ Json default_desktop(); bool valid_desktop(const Json &); // Add new applications to a valid older view without moving existing objects. bool migrate_desktop(Json &); +// The height of the desk the screen shows (2160 to 2880); placement keeps within it. +void set_desktop_height(int); +int desktop_height(); +// Move visible objects that lie below the shown height back into sight. True when one moved. +bool fit_desktop(Json &); bool place_desktop_object(Json &, const std::string &, int x, int y, bool nearest = true); bool resize_desktop_widget(Json &, const std::string &, int columns, int rows); diff --git a/src/modern/ui/engine_dto.cpp b/src/modern/ui/engine_dto.cpp index b7a1c2f..d35222d 100644 --- a/src/modern/ui/engine_dto.cpp +++ b/src/modern/ui/engine_dto.cpp @@ -2,6 +2,7 @@ #include "modern/ui/engine_bridge.hpp" #include #include +#include #include #include #include @@ -286,6 +287,22 @@ Json engine_training_command(const Json &bundle, const Json &draft, const std::s return sports_command(bundle, "training.commit", {{"types", draft.at("types")}, {"areas", draft.at("areas")}, {"players", changed}}, id); } +namespace { +// The game writes a property's name in capitals; the interface reads it as a noun. +std::string noun_case(std::string text) { + bool first = true; + for (size_t i = 0; i < text.size(); ++i) { + const unsigned char c = static_cast(text[i]); + if (c == 0xc3 && i + 1 < text.size()) { // Ä Ö Ü + const unsigned char next = static_cast(text[i + 1]); + if (!first && (next == 0x84 || next == 0x96 || next == 0x9c)) text[i + 1] = static_cast(next + 0x20); + ++i; first = false; + } else if (std::isalpha(c)) { if (!first) text[i] = static_cast(std::tolower(c)); first = false; } + else if (c == ' ' || c == '-') first = true; + } + return text; +} +} Json engine_bank_projection(const Json &bundle) { validate_engine_desk(bundle); const auto &data = lineup_read(bundle, "bank"); @@ -314,6 +331,7 @@ Json engine_bank_projection(const Json &bundle) { std::string name = row.at("name").is_string() ? row.at("name").get() : row.at("name").value("text", ""); // A missing backend label is identified, never filled from a demo company. if (name.empty() || name.starts_with("%%")) name = std::string(stock ? "Aktie · " : "Immobilie · ") + id; + if (!stock) name = noun_case(name); Json item = {{"id", id}, {"name", name}, {"price", price}, {"owned", owned}, {"maxToBuy", max}}; if (stock) { item["previous"] = engine_money_minor(row.at("previousPrice")); diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp index 4445ba5..3c7e5e3 100644 --- a/src/modern/ui/view.cpp +++ b/src/modern/ui/view.cpp @@ -960,6 +960,22 @@ class App final : public Rml::EventListener { canvas_left_ = (pw - 3840 * scale_) / 2; canvas_top_ = (ph - 2160 * scale_) / 2; if (desk_top_ && canvas_top_ > 0) canvas_top_ = 0; + // a career's desk is as high as the screen shows of it; menus keep their 16:9 stage + const bool desk_scene = scene_ == "engine" || scene_ == "desktop"; + const double fitted = std::min(double(pw) / 3840, double(ph) / 2160); + const int stage_height = desk_scene ? std::clamp(int(ph / fitted), 2160, 2880) : 2160; + if (stage_height != desktop_height()) { + set_desktop_height(stage_height); + needs_render_ = true; + } + element("canvas")->SetProperty("height", std::to_string(stage_height) + "dp"); + if (desk_scene && desktop_.is_object() && desktop_.contains("objects")) { + const bool clean = desktop_ == saved_desktop_; + if (fit_desktop(desktop_)) { + if (clean) saved_desktop_ = desktop_; + needs_render_ = true; + } + } device_ratio_ = float(pw) / w; renderer_.SetViewport(pw, ph); context_->SetDimensions({pw, ph}); diff --git a/tests/modern_ui_core_tests.cpp b/tests/modern_ui_core_tests.cpp index bd2efdd..6f8b99d 100644 --- a/tests/modern_ui_core_tests.cpp +++ b/tests/modern_ui_core_tests.cpp @@ -523,6 +523,22 @@ int main(int argc, char **argv) try { const auto resized = moved; require(!resize_desktop_widget(moved, "account", 3, 7) && moved == resized, "Invalid widget size mutated layout"); + // a taller screen shows more of the desk; a shorter one brings what lies below back into sight + { + auto tall = layout; + tall["objects"]["app-almanac"]["pinned"] = false; + set_desktop_height(2400); + require(place_desktop_object(tall, "app-almanac", 1800, 2150) && valid_desktop(tall) && + tall["objects"]["app-almanac"]["y"].get() + 224 > 2160 && + tall["objects"]["app-almanac"]["y"].get() + 224 <= 2400, + "Taller desk did not offer its lower rows"); + auto unchanged = tall; + require(!fit_desktop(unchanged) && unchanged == tall, "Fit moved an object that is in sight"); + set_desktop_height(2160); + require(valid_desktop(tall), "Layout of a taller screen is invalid on a shorter one"); + require(fit_desktop(tall) && valid_desktop(tall) && tall["objects"]["app-almanac"]["y"].get() + 224 <= 2160, + "Object below the shown desk was not brought back into sight"); + } auto corrupt = layout; corrupt["objects"]["calendar"]["x"] = 999999; require(!valid_desktop(corrupt), "Out of bounds desktop accepted");