// SPDX-License-Identifier: GPL-3.0-only namespace { std::string engine_text(const Json &v) { return v.is_string() ? v.get() : v.is_object() ? v.value("text", "") : "—"; } std::string engine_price(const Json &v) { return money(engine_money_minor(v), {{"code", "EUR"}, {"minor_units", 2}}); } } Json App::engine_camp_view() const { const auto art = Json::parse(editor::read_file(gui_.root() / "gui-assets.json")).at("demo"); const auto &data = engine_data_.at("camps").at("data"); Json camps = Json::array(), maps = Json::array(); for (const auto &map : data.at("maps")) maps.push_back({{"id", map.at("id")}, {"name", engine_text(map.at("name"))}}); for (const auto &item : data.at("camps")) { const auto &q = item.at("quality"); Json camp = {{"id", item.at("id")}, {"map", item.at("mapId")}, {"name", engine_text(item.at("name"))}, {"place", item.at("place")}, {"quality", {q.at("pitch"), q.at("fitness"), q.at("catering"), q.at("lodging")}}, {"price", nullptr}, {"gui_image", ""}, {"positioned", false}}; // GUI placement is presentation metadata only. Never copy prices, quality, // focus or booking rules from the GUI resource catalogue into a real career. for (const auto &ref : art.at("training_camps")) if (ref.at("id") == item.at("id") && ref.at("map") == item.at("mapId")) { camp["x"] = ref.at("x"); camp["y"] = ref.at("y"); camp["positioned"] = true; } if (item.at("position").is_object()) { camp["x"] = item.at("position").at("x"); camp["y"] = item.at("position").at("y"); camp["positioned"] = true; } auto image = item.value("guiImageKey", ""); if (image.starts_with("gui:camp/")) camp["gui_image"] = "camp." + image.substr(9); if (item.at("quote").is_object()) camp["price"] = engine_money_minor(item.at("quote").at("total")); camps.push_back(std::move(camp)); } return {{"maps", maps}, {"training_camps", camps}}; } void App::engine_render() { if(menu_=="save"||menu_=="load"||!files_mode_.empty())files_before_render(); if (ticket_) ticket_->close(false); if(menu_=="scorers"||menu_=="fairplay")rankings_remember_scroll(); fixture_half_width_=-1.f; almanac_list_width_=-1.f; if (menu_ == "friendlies") if (auto *list = element("friendly-opponents")) engine_friendly_scroll_ = list->GetScrollTop(); if (menu_ == "contracts") if (auto *roster = element("contracts-roster-scroll")) engine_contract_scroll_ = roster->GetScrollTop(); if (menu_ == "lineup") { if (auto *roster = element("lineup-roster-scroll")) lineup_roster_scroll_ = lineup_reset_scroll_ ? 0.f : roster->GetScrollTop(); lineup_reset_scroll_ = false; } doc_->SetClassNames(theme_); std::string out; if (engine_data_.empty()) { out = "

OpenBMH

" + esc(engine_busy_ ? "Spielstand wird geladen …" : engine_notice_) + "

"; } else if(engine_opening_active()&&menu_.empty()) { out=main_menu()+"
"+render_opening()+"
"; } else { const auto &desk = engine_data_.at("desktop").at("data"), &meta = engine_data_.at("desktop").at("meta"); const auto &team = desk.at("team"), &person = desk.at("manager"); const auto *club = world_->find("clubs", team.at("id").get()); out = "
" + crest(club, 82) + "" + esc(engine_text(team.at("name"))) + "" + esc(engine_text(person.at("name"))) + "
" + esc(meta.at("date").get()) + "" + esc(meta.at("season").at("label").get()) + "
Guthaben" + esc(engine_price(desk.at("accounts").at("cash"))) + "
"; bool lineup_available = false; try { (void)engine_lineup_projection(engine_data_); lineup_available = true; } catch (const std::exception &) {} bool training_available = false, tactics_available = false; try { (void)engine_training_projection(engine_data_); training_available = true; } catch (const std::exception &) {} try { (void)engine_tactics_projection(engine_data_); tactics_available = true; } catch (const std::exception &) {} bool bank_available = false, ticket_available = false; try { (void)engine_bank_projection(engine_data_); bank_available = true; } catch (const std::exception &) {} try { (void)engine_ticket_projection(engine_data_); ticket_available = true; } catch (const std::exception &) {} const auto allowed = meta.at("scope").value("allowedCommands", Json::array()); bank_available = bank_available && std::find(allowed.begin(), allowed.end(), Json("bank.commit")) != allowed.end(); ticket_available = ticket_available && std::find(allowed.begin(), allowed.end(), Json("ticket.commit")) != allowed.end(); bool environment_available = false, advertising_available = false; try { (void)engine_environment_projection(engine_data_); environment_available = true; } catch (const std::exception &) {} try { (void)engine_advertising_projection(engine_data_); advertising_available = true; } catch (const std::exception &) {} environment_available = environment_available && std::find(allowed.begin(), allowed.end(), Json("environment.commit")) != allowed.end(); advertising_available = advertising_available && (std::find(allowed.begin(), allowed.end(), Json("advertising.accept")) != allowed.end() || std::find(allowed.begin(), allowed.end(), Json("budget.commit")) != allowed.end()); bool contracts_available = false; try { (void)engine_contracts_projection(engine_data_); contracts_available = true; } catch (const std::exception &) {} bool calendar_available = false, scheduling_available = false; try { (void)engine_calendar_projection(engine_data_); calendar_available = true; } catch (const std::exception &) {} try { scheduling_available = engine_scheduling_projection(engine_data_).at("allowed"); } catch (const std::exception &) {} bool friendlies_available = false; try { (void)engine_friendly_plan(engine_data_); friendlies_available = true; } catch (const std::exception &) {} init_desktop(); for (const auto &[id, o] : desktop_.at("objects").items()) { if (!o.value("visible", false)) continue; const auto style = rect(o.at("x"), o.at("y"), o.at("w"), o.at("h")); if (o.value("widget", false)) { std::string body; if (id == "portrait") { auto portrait = person.value("portraitGuiKey", ""); if (portrait.starts_with("gui:manager/photo/")) body = img("manager." + portrait.substr(18), o.at("w"), o.at("h"), false, false, 768); else if(portrait.starts_with("gui:manager/painted/"))body=img("manager-painted."+portrait.substr(20),o.at("w"),o.at("h"),false,false,768); body += "
Manager" + esc(person.at("name").get()) + "
"; } else if (id == "calendar") { const auto date = meta.at("date").get(); const int y = std::stoi(date.substr(0, 4)), m = std::stoi(date.substr(5, 2)), d = std::stoi(date.substr(8, 2)); const auto ymd = std::chrono::year_month_day{std::chrono::year(y), std::chrono::month(unsigned(m)), std::chrono::day(unsigned(d))}; if (!ymd.ok()) throw editor::Error("Ungültiges Engine-Datum."); const std::array months{"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"}; const std::array weekdays{"Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"}; body = "
" + std::string(months[size_t(m - 1)]) + " " + std::to_string(y) + "
" + weekdays[std::chrono::weekday{std::chrono::sys_days(ymd)}.c_encoding()] + "" + std::to_string(d) + "" + esc(meta.at("season").at("label").get()) + "
"; } else if (id == "account") { const auto savings = bank_available ? engine_data_.at("bank").at("data").at("accounts").at("deposit") : desk.at("accounts").at("savings"); body = widget_heading("Vereinskasse", false) + ""; } else if (id == "opponent-crest" && desk.at("nextFixture").is_object()) { const auto &next = desk.at("nextFixture"); const auto &other = next.at(next.at("home").at("id") == team.at("id") ? "away" : "home"); body = widget_heading("Nächster Gegner", false) + "
" + crest(world_->find("clubs", other.at("id").get()), 220) + "

" + esc(engine_text(other.at("name"))) + "

"; } if (!body.empty()) out += "
" + body + "
"; } else { const auto route = id.substr(4); const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available"; const auto commands = meta.at("scope").value("allowedCommands", Json::array()); const bool supported = ((route=="tables"||route=="strengths"||route=="league"||route=="other"||route=="scorers"||route=="fairplay")&&engine_fresh_&&meta.at("scope").at("role")=="club") || (route == "almanac" && engine_fresh_) || (route == "friendlies" && friendlies_available && engine_fresh_) || (route == "calendar" && calendar_available && engine_fresh_) || (route == "postpone" && scheduling_available && engine_fresh_) || (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || route == "save" || route == "load" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end()); out += desktop_button(id, o, "engine-open", supported && !engine_busy_); } } out += "
"; if(menu_=="save"||menu_=="load")out+="
"+window(menu_=="save"?"Spiel speichern":"Spiel laden",render_files(false,menu_=="save"))+"
"; if(menu_=="scorers")out+="
"+window("Spielerstatistiken",engine_rankings_value_.is_object()?render_scorers():"
"+esc(engine_busy_?"Spielerstatistiken werden geladen …":engine_notice_)+"
")+"
"; if(menu_=="fairplay")out+="
"+window("Fairplay",engine_fairplay_value_.is_object()?render_fairplay():"
"+esc(engine_busy_?"Fairplay wird geladen …":engine_notice_)+"
")+"
"; if(menu_=="other")out+="
"+window("Übrige Spiele",engine_other_value_.is_object()?render_reports("other"):"
"+esc(engine_busy_?"Wettbewerbe werden geladen …":engine_other_index_.is_object()?"Keine aktiven Wettbewerbe.":engine_notice_)+"
")+"
"; if(menu_=="league")out+="
"+window("Ligaspiele",engine_fixtures_value_.is_object()?render_reports("league"):"
"+esc(engine_busy_?"Ligaspiele werden geladen …":engine_notice_)+"
")+"
"; if(menu_=="tables"||menu_=="strengths")out+="
"+window(menu_=="tables"?"Tabelle":"Stärken",engine_reports_read_.is_object()?render_reports(menu_):"
"+esc(engine_busy_?"Ligabericht wird geladen …":engine_notice_)+"
")+"
"; if(menu_=="almanac") out+="
"+window("Almanach",engine_almanac_cache_.contains("index")?render_almanac():"
"+esc(engine_busy_?"Spielarchiv wird geladen …":engine_notice_)+"
")+"
"; if (menu_ == "friendlies") out += "
" + window("Freundschaftsspiel", friendlies_available ? render_friendlies() : "
Freundschaftsplanung ist derzeit nicht verfügbar.
") + "
"; if (menu_ == "calendar") out += "
" + window("Kalender", calendar_available ? render_calendar() : "
Der Saisonkalender ist derzeit nicht verfügbar.
") + "
"; if (menu_ == "postpone") out += "
" + window("Verlegen", scheduling_available ? render_postpone() : "
Die Spielverlegung ist derzeit nicht verfügbar.
") + "
"; if (menu_ == "contracts") out += "
" + window("Verträge", render_contracts()) + "
"; if (menu_ == "environment") out += "
" + window("Umfeld", render_environment()) + "
"; if (menu_ == "advertising") out += "
" + window("Werbung", render_advertising()) + "
"; if (menu_ == "bank") out += "
" + window("Bank", render_bank()) + "
"; if (menu_ == "training") out += "
" + window("Training", render_training()) + "
"; if (menu_ == "tactics") out += "
" + window("Taktik", render_tactics()) + "
"; if (menu_ == "lineup") out += "
" + window("Aufstellung", render_lineup()) + "
"; if (menu_ == "camp") out += "
" + window("Trainingslager", render_camp()) + "
"; } if ((menu_ == "bank" || menu_ == "environment" || menu_ == "advertising" || menu_ == "contracts" || menu_ == "calendar" || menu_ == "postpone" || menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="fairplay") && !amount_ && contracts_dialog_.empty() && planning_dialog_.empty()) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; if (menu_.empty() || engine_data_.empty()) out += "
" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "
"; element("canvas")->SetInnerRML(out); ++document_generation_; scale_chalk_shadow(); if (!engine_player_.empty()) { Rml::ElementList underlay; doc_->QuerySelectorAll(underlay, "#lineup-underlay button,#window-close"); for (auto *node : underlay) { node->SetAttribute("disabled", true); node->SetProperty("pointer-events", "none"); } } const auto size = context_->GetDimensions(); element("background")->SetInnerRML(img("background", size.x / scale_, size.y / scale_, false, true, 2048)); element("background")->SetProperty("filter", theme_ == "silver" ? "saturate(0.2) brightness(0.9)" : theme_ == "matchday" ? "saturate(0.13) brightness(0.56)" : "saturate(0.34) brightness(0.70)"); if (!contracts_dialog_.empty()) { Rml::ElementList underlay; doc_->QuerySelectorAll(underlay, "#contracts-underlay button,.contracts-actions button,#window-close"); for (auto *node : underlay) { node->SetAttribute("disabled", true); node->SetProperty("pointer-events", "none"); } } if (!planning_dialog_.empty() && menu_ == "friendlies") { Rml::ElementList underlay; doc_->QuerySelectorAll(underlay,"#report-underlay button,#report-underlay select,#window-close"); for (auto *node : underlay) { node->SetAttribute("disabled",true); node->SetProperty("pointer-events","none"); } } if (amount_) { Rml::ElementList underlay; doc_->QuerySelectorAll(underlay, ".window>.content,.window>.titlebar"); for (auto *node : underlay) { node->SetProperty("pointer-events", "none"); node->SetProperty("filter", "blur(10dp)"); } } if(!report_detail_kind_.empty()&&(menu_=="tables"||menu_=="strengths"||menu_=="league"||menu_=="other"||menu_=="scorers"||menu_=="fairplay")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#report-underlay button,.rankings-scorers button,.rankings-fairplay button,#window-close");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}} if (engine_busy_) { Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#canvas button,#canvas input"); for (auto *node : controls) node->SetAttribute("disabled", true); } needs_render_ = false; dirty_ = true; }