Bind native desk and training camps to Modern OBS careers (by Codex)

This commit is contained in:
Codex committed 2026-10-27 22:00:10 +01:00
1 parent 1fb6499b15
commit 85a1fe5a95
19 files changed
+733 -46

No files matched your search

+48 -33
View File
@@ -13,6 +13,33 @@ void App::init_desktop() {
}
}
std::string App::desktop_button(const std::string &id, const Json &o, const std::string &action, bool enabled) {
const auto route = id.substr(4);
const auto style = rect(o.value("x", 0), o.value("y", 0), o.value("w", 224), o.value("h", 224)) + "z-index:" + std::to_string(o.value("z", 1)) + ";";
const std::array<std::string, 32> colors = {
"#3d789b", "#375a83", "#477c73", "#42846b", "#a58a49", "#586ba0",
"#517d71", "#668a98", "#af6860", "#6b809c", "#657cb3", "#507b9c",
"#559b76", "#a7474e", "#967d50", "#648f91", "#54856b", "#558f93",
"#6379a3", "#788598", "#8d7856", "#a66d64", "#748474", "#6887a2",
"#6b9270", "#7c8b9c", "#ac8b52", "#7783a4", "#648f83", "#927d9d",
"#ac5e63", "#806c98"};
const auto i = std::find(routes.begin(), routes.end(), route);
const auto color = colors[size_t(i - routes.begin())];
const auto top = theme_ == "matchday" ? mixed_color(color, "#27282e", .55)
: mixed_color(color, "#c5ddf1", .1);
const auto bottom =
theme_ == "matchday" ? "#272a30" : mixed_color(color, "#07111e", .38);
return "<button id=\"object-" + esc(id) + "\" data-object=\"" + esc(id) +
"\" data-action=\"" + action +
"\" data-id=\"" + route + "\" class=\"desktop-app\" style=\"" + style +
"\" " + std::string(enabled ? "" : "disabled ") + "><div class=\"app-tile\" "
"style=\"decorator:linear-gradient(140deg," +
top + "," + bottom + ");\">" +
img("button." + route, 146, 146, false, false, 256) +
"</div><span class=\"app-name\">" + esc(route=="newplayer"?"Manager":route=="transfer"?"Transfer":title(route)) + "</span>" +
(o.value("pinned", true) ? "<div class=\"pin-dot\"></div>" : "") +
"</button>";
}
std::string App::render_desktop() {
init_desktop();
const auto s = snap();
@@ -46,29 +73,7 @@ std::string App::render_desktop() {
"</div>";
} else {
const auto route = id.substr(4);
const std::array<std::string, 32> colors = {
"#3d789b", "#375a83", "#477c73", "#42846b", "#a58a49", "#586ba0",
"#517d71", "#668a98", "#af6860", "#6b809c", "#657cb3", "#507b9c",
"#559b76", "#a7474e", "#967d50", "#648f91", "#54856b", "#558f93",
"#6379a3", "#788598", "#8d7856", "#a66d64", "#748474", "#6887a2",
"#6b9270", "#7c8b9c", "#ac8b52", "#7783a4", "#648f83", "#927d9d",
"#ac5e63", "#806c98"};
const auto i = std::find(routes.begin(), routes.end(), route);
const auto color = colors[size_t(i - routes.begin())];
const auto top = theme_ == "matchday" ? mixed_color(color, "#27282e", .55)
: mixed_color(color, "#c5ddf1", .1);
const auto bottom =
theme_ == "matchday" ? "#272a30" : mixed_color(color, "#07111e", .38);
out += "<button id=\"object-" + esc(id) + "\" data-object=\"" + esc(id) +
"\" data-action=\"open:" + route +
"\" class=\"desktop-app\" style=\"" + style +
"\"><div class=\"app-tile\" "
"style=\"decorator:linear-gradient(140deg," +
top + "," + bottom + ");\">" +
img("button." + route, 146, 146, false, false, 256) +
"</div><span class=\"app-name\">" + esc(route=="newplayer"?"Manager":route=="transfer"?"Transfer":title(route)) + "</span>" +
(o.value("pinned", true) ? "<div class=\"pin-dot\"></div>" : "") +
"</button>";
out += desktop_button(id, o, "open:" + route);
}
}
return out + "</div>";
@@ -76,9 +81,9 @@ std::string App::render_desktop() {
std::string App::render_camp() {
const auto index_file =
Json::parse(editor::read_file(gui_.root() / "gui-assets.json"));
const auto demo = index_file.at("demo"), camps = demo.at("training_camps");
const auto s = snap();
const auto id = s.state.at("camp").value("selected", std::string("resort:4"));
const auto demo = engine_mode_ ? engine_camp_view() : index_file.at("demo"), camps = demo.at("training_camps");
const auto state = engine_mode_ ? Json{{"camp", {{"selected", engine_camp_}, {"focus", {engine_focus_.at("condition"), engine_focus_.at("technique"), engine_focus_.at("play")}}}}} : snap().state;
const auto id = state.at("camp").value("selected", std::string("resort:4"));
const Json *chosen = nullptr;
for (const auto &c : camps)
if (c.value("id", "") == id)
@@ -100,7 +105,7 @@ std::string App::render_camp() {
"2dp;overflow:hidden;border-radius:22dp;\">" +
img("map." + region.substr(4), 1440, 1603.2, false, false, 1600);
for (const auto &c : camps)
if (c.value("map", "") == region) {
if (c.value("map", "") == region && c.value("positioned", true)) {
const double x = c.value("x", 0) * 1.2, y = c.value("y", 0) * 1.2;
body += btn("camp-select",
"<span "
@@ -135,30 +140,40 @@ std::string App::render_camp() {
}
body += "<div class=\"field-row\"><strong>Preis</strong><strong "
"class=\"accent\">" +
cash(chosen->value("price", int64_t(0))) + "</strong></div>";
(chosen->at("price").is_null() ? std::string("—") : (engine_mode_ ? money(chosen->at("price").get<int64_t>(), {{"code", "EUR"}, {"minor_units", 2}}) : cash(chosen->at("price").get<int64_t>()))) + "</strong></div>";
const std::array<const char *, 4> focus = {"Kondition", "Technik", "Spiel",
"Erholung"};
const auto values = s.state.at("camp").at("focus");
const auto values = state.at("camp").at("focus");
int sum = 0;
for (const auto &v : values)
sum += v.get<int>();
const bool focus_changed = engine_mode_ && (engine_focus_.at("condition") != engine_data_.at("camps").at("data").at("focus").at("condition") || engine_focus_.at("technique") != engine_data_.at("camps").at("data").at("focus").at("technique") || engine_focus_.at("play") != engine_data_.at("camps").at("data").at("focus").at("play"));
for (int i = 0; i < 4; ++i) {
const int value = i == 3 ? 15 - sum / 3 : values[size_t(i)].get<int>();
const int recovery = engine_mode_ ? engine_data_.at("camps").at("data").at("focus").value("recovery", 0) : 15 - sum / 3;
const int value = i == 3 ? recovery : values[size_t(i)].get<int>();
body += "<div class=\"field-row\" style=\"min-height:100dp;padding:8dp "
"0;\"><label>" +
std::string(focus[size_t(i)]) +
"</label><input type=\"range\" id=\"camp-focus-" +
std::to_string(i) + "\" data-input=\"camp-focus\" data-id=\"" +
std::to_string(i) + "\" min=\"0\" max=\"15\" step=\"1\" value=\"" +
std::to_string(value) + "\" style=\"width:400dp;\" " +
std::to_string(value) + "\" style=\"width:400dp;" + std::string(i == 3 && focus_changed ? "visibility:hidden;" : "") + "\" " +
(i == 3 ? "disabled" : "") + "/><span id=\"camp-value-" +
std::to_string(i) +
"\" style=\"width:145dp;flex-shrink:0;text-align:right;\">" +
std::to_string(value) + " / 15</span></div>";
(i == 3 && focus_changed ? std::string("—") : std::to_string(value) + " / 15") + "</span></div>";
}
std::string booking_note;
if (engine_mode_) for (const auto &camp : engine_data_.at("camps").at("data").at("camps")) if (camp.at("id") == id && camp.at("quote").is_object()) {
const auto &quote = camp.at("quote");
const auto reason = quote.at("reasonCode");
if (reason == "booked_this_week") booking_note = "Diese Woche wurde bereits ein Trainingslager gebucht.";
else if (reason == "visit_limit") booking_note = "Das Trainingslagerlimit dieser Saison ist erreicht.";
else if (quote.value("exceedsCash", false)) booking_note = "Der Preis übersteigt das aktuelle Guthaben.";
}
body += "<div class=\"row\" "
"style=\"margin-top:26dp;justify-content:flex-end;\">" +
btn("camp-remember", "Vormerken", "primary") + "</div></div>";
btn("camp-remember", engine_mode_ ? "Verbindlich buchen" : "Vormerken", "primary", "id=\"camp-book\" " + std::string(engine_mode_ && ![&]() { for (const auto &camp : engine_data_.at("camps").at("data").at("camps")) if (camp.at("id") == id) return engine_fresh_ && camp.at("quote").is_object() && camp.at("quote").value("allowed", false); return false; }() ? "disabled" : "")) + "</div>" + (engine_mode_ ? "<p class=\"small muted\" style=\"margin-top:22dp;\">" + esc(engine_busy_ ? engine_operation_ : (booking_note.empty() ? engine_notice_ : booking_note)) + "</p>" : "") + "</div>";
return body;
}
std::string App::render_menu(const std::string &key) {