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 <noreply@anthropic.com>
This commit is contained in:
1 parent
e3edd2f9ed
commit
b3e5ef4b4d
7 files changed
+82
-6
No files matched your search
@@ -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)) {
|
||||
|
||||
@@ -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<int>() + 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<double>::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<int>() + o.at("h").get<int>() <= desk_height) continue;
|
||||
const int x = o.at("x"), y = desk_height - o.at("h").get<int>();
|
||||
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<bool>()) {
|
||||
o["x"] = std::clamp(x, 0, 3840 - o.at("w").get<int>());
|
||||
o["y"] = std::clamp(y, top, 2160 - o.at("h").get<int>());
|
||||
o["y"] = std::clamp(y, top, desk_height - o.at("h").get<int>());
|
||||
} 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<int>()) / 2;
|
||||
o["y"] = (2160 - o.at("h").get<int>()) / 2;
|
||||
o["y"] = (desk_height - o.at("h").get<int>()) / 2;
|
||||
}
|
||||
o["visible"] = true;
|
||||
if (!valid_desktop(next))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cctype>
|
||||
#include <charconv>
|
||||
#include <set>
|
||||
#include <limits>
|
||||
@@ -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<unsigned char>(text[i]);
|
||||
if (c == 0xc3 && i + 1 < text.size()) { // Ä Ö Ü
|
||||
const unsigned char next = static_cast<unsigned char>(text[i + 1]);
|
||||
if (!first && (next == 0x84 || next == 0x96 || next == 0x9c)) text[i + 1] = static_cast<char>(next + 0x20);
|
||||
++i; first = false;
|
||||
} else if (std::isalpha(c)) { if (!first) text[i] = static_cast<char>(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<std::string>() : 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"));
|
||||
|
||||
@@ -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});
|
||||
|
||||
Reference in new issue
Block a user