Bind stadium construction and historical data to scoped engine offers (by Codex)
This commit is contained in:
1 parent
dfb972abbd
commit
0edf208405
22 files changed
+1037
-40
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_statistics.cpp engine_toto.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp career_files.cpp demo_opening.cpp)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_statistics.cpp engine_toto.cpp engine_stadium.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp career_files.cpp demo_opening.cpp)
|
||||
target_include_directories(bmh_modern_ui_core PUBLIC ../..)
|
||||
target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io)
|
||||
add_library(bmh_modern_ui_mods STATIC mod_library.cpp)
|
||||
@@ -49,7 +49,7 @@ foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss report
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
foreach(component career_reports rankings career_files statistics_projection toto_projection)
|
||||
foreach(component career_reports rankings career_files statistics_projection toto_projection stadium_projection)
|
||||
add_executable(modern_${component}_tests ../../../tests/modern_${component}_tests.cpp)
|
||||
target_link_libraries(modern_${component}_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -62,6 +62,11 @@ Json engine_other_projection(const Json &bundle,const Json &index,const Json &re
|
||||
Json engine_rankings_projection(const Json &bundle,const Json &index,const Json &read,const std::string &league,int scope);
|
||||
Json engine_fairplay_projection(const Json &bundle,const Json &index,const Json &read);
|
||||
|
||||
Json engine_stadium_projection(const Json &bundle,bool future);
|
||||
Json engine_stadium_quote(const Json &bundle,const Json &draft);
|
||||
Json engine_stadium_request(const Json &bundle,const Json &draft,const std::string &request_id,bool update=false);
|
||||
Json engine_stadium_commit(const Json &bundle,bool accept,const std::string &request_id);
|
||||
|
||||
Json engine_toto_projection(const Json &bundle);
|
||||
Json engine_toto_command(const Json &bundle,const Json "e,const std::string &request_id);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ void App::engine_accept(EngineReply result) {
|
||||
engine_almanac_sync();
|
||||
engine_ticket_bind();
|
||||
engine_toto_poll();
|
||||
engine_stadium_poll();
|
||||
engine_contracts_poll();
|
||||
engine_calendar_sync();
|
||||
engine_friendly_sync();
|
||||
@@ -133,6 +134,7 @@ void App::engine_save() {
|
||||
engine_start("Spielstand wird gespeichert …", [link, output] { auto response = link->save_copy(output); return EngineReply{link, link->snapshot(), response, nullptr}; });
|
||||
}
|
||||
void App::engine_quit() {
|
||||
if(!engine_busy_&&engine_data_.value("stadium",Json()).is_object()&&engine_data_.at("stadium").value("messageType","")=="snapshot"&&engine_data_.at("stadium").at("data").at("quote").is_object()){engine_stadium_exit_=true;engine_stadium_send(engine_stadium_commit(engine_data_,false,editor::new_id("request:ui-")),"cancel");return;}
|
||||
if (engine_busy_ || engine_files_busy_) { engine_notice_ = "Bitte den laufenden Vorgang abwarten."; dirty_ = true; return; }
|
||||
if (engine_dirty_) {
|
||||
confirmation("Die Partie enthält ungespeicherte Änderungen. Vor dem Beenden speichern?",[this]{closed_=true;});
|
||||
@@ -163,6 +165,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (engine_reports_event(event)) return;
|
||||
if(menu_=="statistics"&&statistics_event(event))return;
|
||||
if(menu_=="toto"&&toto_event(event))return;
|
||||
if(menu_=="stadium"&&stadium_event(event))return;
|
||||
if(!engine_busy_&&popup_.empty()&&rankings_event(event))return;
|
||||
if (!engine_busy_ && popup_.empty() && engine_friendly_event(event)) return;
|
||||
if (!engine_busy_ && planning_dialog_.empty() && popup_.empty() && (menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="statistics") && report_picker_event(event)) return;
|
||||
@@ -256,6 +259,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (engine_reports_action(action,node)) return;
|
||||
if(menu_=="statistics"&&statistics_action(action,node))return;
|
||||
if(menu_=="toto"&&toto_action(action,node))return;
|
||||
if(menu_=="stadium"&&stadium_action(action,node))return;
|
||||
if (almanac_action(action,node)) return;
|
||||
if (engine_friendly_action(action, node)) return;
|
||||
if ((menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="statistics") && report_picker_action(action,node)) return;
|
||||
@@ -272,6 +276,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
ticket_->open(node, device_ratio_, price.at("min"), price.at("max")); dirty_ = true;
|
||||
}
|
||||
else if (action == "engine-open" && (id == "environment" || id == "advertising")) { menu_ = id; advertising_selected_ = -1; advertising_offer_ = 0; refresh(); }
|
||||
else if(action=="engine-open"&&id=="stadium"){menu_=id;stadium_view_=Json::object();stadium_view_defaults(stadium_view_);engine_stadium_sync();refresh();}
|
||||
else if(action=="engine-open"&&id=="toto"){menu_=id;engine_toto_sync();refresh();}
|
||||
else if(action=="engine-open"&&id=="statistics"){menu_=id;engine_reports_sync();engine_statistics_load();}
|
||||
else if(action=="engine-open"&&id=="load"){engine_files_begin("load");}
|
||||
@@ -305,5 +310,5 @@ void App::engine_event(Rml::Event &event) {
|
||||
}
|
||||
Json App::engine_snapshot() const {
|
||||
return {{"mode", engine_mode_}, {"creation_busy",engine_creation_busy_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
|
||||
{"response", engine_response_}, {"toto_value",engine_toto_value_},{"toto_draft",engine_toto_edit_},{"toto_quote",engine_toto_quote_},{"toto_feedback",engine_toto_feedback_},{"statistics_read",engine_statistics_read_},{"statistics_value",engine_statistics_value_},{"statistics_query",engine_statistics_query_},{"files_native",files_native_},{"files_busy",engine_files_busy_},{"files_current",engine_files_metadata_},{"opening_read",engine_opening_read_},{"opening_state",engine_opening_state_},{"rankings_read",engine_rankings_read_},{"rankings_state",engine_rankings_state_},{"fairplay_read",engine_fairplay_read_},{"other_index",engine_other_index_},{"other_read",engine_other_read_},{"fixtures_read",engine_fixtures_read_},{"reports_state",engine_reports_state_},{"reports_index",engine_reports_index_},{"reports_read",engine_reports_read_},{"reports_roster",engine_reports_roster_},{"almanac_cache",engine_almanac_cache_}, {"almanac_context",engine_almanac_context_}, {"friendly_quote", engine_friendly_read_}, {"friendly_league", engine_friendly_league_}, {"friendly_opponent", engine_friendly_opponent_}, {"friendly_date", engine_friendly_date_}, {"friendly_home", engine_friendly_home_}, {"friendly_stage", engine_friendly_stage_}, {"friendly_month", engine_friendly_month_}, {"calendar_day", engine_calendar_day_}, {"move_id", engine_move_id_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
{"response", engine_response_}, {"stadium_view",stadium_view_},{"stadium_value",engine_stadium_value_},{"toto_value",engine_toto_value_},{"toto_draft",engine_toto_edit_},{"toto_quote",engine_toto_quote_},{"toto_feedback",engine_toto_feedback_},{"statistics_read",engine_statistics_read_},{"statistics_value",engine_statistics_value_},{"statistics_query",engine_statistics_query_},{"files_native",files_native_},{"files_busy",engine_files_busy_},{"files_current",engine_files_metadata_},{"opening_read",engine_opening_read_},{"opening_state",engine_opening_state_},{"rankings_read",engine_rankings_read_},{"rankings_state",engine_rankings_state_},{"fairplay_read",engine_fairplay_read_},{"other_index",engine_other_index_},{"other_read",engine_other_read_},{"fixtures_read",engine_fixtures_read_},{"reports_state",engine_reports_state_},{"reports_index",engine_reports_index_},{"reports_read",engine_reports_read_},{"reports_roster",engine_reports_roster_},{"almanac_cache",engine_almanac_cache_}, {"almanac_context",engine_almanac_context_}, {"friendly_quote", engine_friendly_read_}, {"friendly_league", engine_friendly_league_}, {"friendly_opponent", engine_friendly_opponent_}, {"friendly_date", engine_friendly_date_}, {"friendly_home", engine_friendly_home_}, {"friendly_stage", engine_friendly_stage_}, {"friendly_month", engine_friendly_month_}, {"calendar_day", engine_calendar_day_}, {"move_id", engine_move_id_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
}
|
||||
@@ -21,7 +21,7 @@ void App::engine_files_poll() {
|
||||
try {
|
||||
auto result=engine_files_job_.get();
|
||||
if(result.operation=="loaded") {
|
||||
engine_toto_context_=Json();engine_toto_quote_=Json();engine_reports_context_=Json();engine_almanac_context_=Json();engine_friendly_read_=Json();engine_friendly_stage_=0;engine_calendar_season_.clear();engine_calendar_day_=-1;engine_move_id_.clear();report_detail_kind_.clear();engine_player_.clear();lineup_selected_.clear();engine_opening_state_=Json();engine_opening_read_=Json();
|
||||
stadium_view_=Json::object();engine_stadium_context_=Json();engine_toto_context_=Json();engine_toto_quote_=Json();engine_reports_context_=Json();engine_almanac_context_=Json();engine_friendly_read_=Json();engine_friendly_stage_=0;engine_calendar_season_.clear();engine_calendar_day_=-1;engine_move_id_.clear();report_detail_kind_.clear();engine_player_.clear();lineup_selected_.clear();engine_opening_state_=Json();engine_opening_read_=Json();
|
||||
engine_mode_=true;engine_dirty_=engine_base_dirty_=false;engine_accept(std::move(*result.engine));source_.reset();entry_catalog_.reset();engine_files_current_id_=result.selected;engine_files_pending_load_.reset();scene_="engine";menu_.clear();reset_files();refresh();return;
|
||||
}
|
||||
files_rows_=std::move(result.rows);if(result.metadata.is_object())engine_files_metadata_=std::move(result.metadata);
|
||||
|
||||
@@ -120,7 +120,7 @@ void App::engine_render() {
|
||||
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=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&engine_fresh_) || route == "save" || route == "load" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
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=="stadium"&&engine_fresh_&&engine_stadium_value_.is_object()) || (route=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&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_);
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,7 @@ void App::engine_render() {
|
||||
if(menu_=="scorers")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Spielerstatistiken",engine_rankings_value_.is_object()?render_scorers():"<div class=\"fill center\">"+esc(engine_busy_?"Spielerstatistiken werden geladen …":engine_notice_)+"</div>")+"</div>";
|
||||
if(menu_=="fairplay")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Fairplay",engine_fairplay_value_.is_object()?render_fairplay():"<div class=\"fill center\">"+esc(engine_busy_?"Fairplay wird geladen …":engine_notice_)+"</div>")+"</div>";
|
||||
if(menu_=="other")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Übrige Spiele",engine_other_value_.is_object()?render_reports("other"):"<div class=\"fill center\">"+esc(engine_busy_?"Wettbewerbe werden geladen …":engine_other_index_.is_object()?"Keine aktiven Wettbewerbe.":engine_notice_)+"</div>")+"</div>";
|
||||
if(menu_=="stadium")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Stadion",render_stadium())+"</div>";
|
||||
if(menu_=="toto")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Toto",render_toto())+"</div>";
|
||||
if(menu_=="statistics")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Statistiken",engine_statistics_value_.is_object()?render_statistics():"<div class=\"fill center\">"+esc(engine_busy_?"Statistik wird geladen …":engine_notice_)+"</div>")+"</div>";
|
||||
if(menu_=="league")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Ligaspiele",engine_fixtures_value_.is_object()?render_reports("league"):"<div class=\"fill center\">"+esc(engine_busy_?"Ligaspiele werden geladen …":engine_notice_)+"</div>")+"</div>";
|
||||
@@ -146,7 +147,7 @@ void App::engine_render() {
|
||||
if (menu_ == "lineup") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Aufstellung", render_lineup()) + "</div>";
|
||||
if (menu_ == "camp") out += "<div class=\"fill\" style=\"z-index:100;\">" + window("Trainingslager", render_camp()) + "</div>";
|
||||
}
|
||||
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 += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
|
||||
if ((menu_ == "stadium" || 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 += "<div class=\"panel\" style=\"position:absolute;bottom:12dp;left:700dp;right:700dp;padding:9dp;font-size:25dp;z-index:110;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
|
||||
if (menu_.empty() || engine_data_.empty()) out += "<div class=\"panel\" style=\"position:absolute;left:850dp;bottom:24dp;right:100dp;padding:18dp;font-size:27dp;\" id=\"engine-status\">" + esc(engine_busy_ ? engine_operation_ : engine_notice_) + "</div>";
|
||||
if(menu_=="statistics")out+=render_statistics_trophy();
|
||||
element("canvas")->SetProperty("overflow",statistics_trophy_.contains("asset")?"visible":"hidden");
|
||||
@@ -172,6 +173,7 @@ void App::engine_render() {
|
||||
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"||menu_=="statistics")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#report-underlay button,.rankings-scorers button,.rankings-fairplay button,.statistics-native button,#window-close");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}}
|
||||
if(menu_=="stadium"&&stadium_view_.value("dialog",std::string())!=""){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#stadium-underlay button,.window>.titlebar button");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}}
|
||||
if(!toto_dialog_.empty()){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,"#toto-underlay button,.window>.titlebar button");for(auto *n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}}
|
||||
if(statistics_trophy_.contains("asset")){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,".window button,.window input");for(auto *n:nodes)n->SetAttribute("disabled",true);}
|
||||
if (engine_busy_) {
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
void check(bool yes, const char *message) {
|
||||
if (!yes)
|
||||
throw editor::Error(message);
|
||||
}
|
||||
const Json &read(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &r = bundle.at("stadium");
|
||||
check(r.value("messageType", "") == "snapshot" && r.at("data").value("kind", "") == "stadium",
|
||||
"Stadion ist derzeit nicht verfügbar.");
|
||||
for (const auto *key : {"careerId", "worldId", "worldRevision", "stateRevision", "scope"})
|
||||
check(r.at("meta").at(key) == bundle.at("desktop").at("meta").at(key),
|
||||
"Der Stadionkontext hat sich geändert.");
|
||||
return r.at("data");
|
||||
}
|
||||
Json command(const Json &b, const std::string &kind, const Json &payload, const std::string &id) {
|
||||
const auto &m = b.at("desktop").at("meta");
|
||||
const auto &allowed = m.at("scope").at("allowedCommands");
|
||||
check(std::find(allowed.begin(), allowed.end(), Json(kind)) != allowed.end(),
|
||||
"Diese Stadionaktion ist derzeit gesperrt.");
|
||||
return {{"messageType", "command"},
|
||||
{"contractVersion", m.at("contractVersion")},
|
||||
{"careerId", m.at("careerId")},
|
||||
{"requestId", id},
|
||||
{"expectedRevision", m.at("stateRevision")},
|
||||
{"owner", {{"managerId", m.at("scope").at("managerId")}}},
|
||||
{"kind", kind},
|
||||
{"payload", payload}};
|
||||
}
|
||||
} // namespace
|
||||
Json engine_stadium_projection(const Json &bundle, bool future) {
|
||||
const auto &d = read(bundle);
|
||||
check(d.at("blocks").size() == 8 && d.at("facilities").size() == 8 &&
|
||||
d.at("periphery").size() == 14,
|
||||
"Unvollständiges Stadion.");
|
||||
Json blocks = Json::array(), facilities = Json::array(), periphery = Json::array();
|
||||
int64_t available = 0, planned = 0, physical = 0;
|
||||
bool super = true;
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
const auto &b = d.at("blocks")[i];
|
||||
const int weeks = b.at("constructionWeeks");
|
||||
const bool busy = weeks > 0;
|
||||
const int64_t current = b.at("places"),
|
||||
target = busy ? b.at("placesAfterConstruction").get<int64_t>() : current;
|
||||
const bool seats = future && busy ? b.at("seatsAfterConstruction").get<bool>()
|
||||
: b.at("seats").get<bool>(),
|
||||
roof = future && busy ? b.at("roofAfterConstruction").get<bool>()
|
||||
: b.at("roof").get<bool>();
|
||||
const int64_t display = busy && !future ? 0 : future ? target : current;
|
||||
blocks.push_back({{"id", b.at("id")},
|
||||
{"index", i},
|
||||
{"letter", std::string(1, char('A' + i))},
|
||||
{"name", b.at("name")},
|
||||
{"places", current},
|
||||
{"max_places", b.at("maxPlaces")},
|
||||
{"seats", b.at("seats")},
|
||||
{"roof", b.at("roof")},
|
||||
{"building", busy},
|
||||
{"display_places", display},
|
||||
{"display_seats", seats},
|
||||
{"display_roof", roof},
|
||||
{"weeks", 0},
|
||||
{"job", busy ? Json{{"places", target},
|
||||
{"seats", b.at("seatsAfterConstruction")},
|
||||
{"roof", b.at("roofAfterConstruction")},
|
||||
{"weeks", weeks}}
|
||||
: Json()}});
|
||||
available += busy ? 0 : current;
|
||||
physical += current;
|
||||
planned += target;
|
||||
super =
|
||||
super && (future ? target : current) == b.at("maxPlaces").get<int64_t>() && seats && roof;
|
||||
}
|
||||
for (size_t i = 0; i < 8; ++i) {
|
||||
const auto &f = d.at("facilities")[i];
|
||||
const int level = f.at("level"), weeks = f.at("constructionWeeks"),
|
||||
target = f.value("plannedLevel", level), shown = future && weeks > 0 ? target : level;
|
||||
Json labels = i == 2 || i == 3 ? Json({"—", "nicht vorhanden", "vorhanden"})
|
||||
: i < 2 ? Json({"—", "klein", "mittel", "groß", "mega"})
|
||||
: Json({"—", "schlecht", "ausreichend", "gut", "sehr gut"});
|
||||
check(shown >= 0 && shown < int(labels.size()), "Ungültige Ausstattungsstufe.");
|
||||
facilities.push_back({{"id", f.at("id")},
|
||||
{"index", i},
|
||||
{"name", f.at("name")},
|
||||
{"level", level},
|
||||
{"max_level", f.at("maxLevel")},
|
||||
{"display_level", shown},
|
||||
{"display_label", labels[size_t(shown)]},
|
||||
{"levels", labels},
|
||||
{"weeks", 0},
|
||||
{"rate", nullptr},
|
||||
{"building", weeks > 0},
|
||||
{"available", f.at("upgradeAvailable")},
|
||||
{"job", weeks > 0 ? Json{{"level", target}, {"weeks", weeks}} : Json()}});
|
||||
}
|
||||
for (size_t i = 0; i < 14; ++i) {
|
||||
const auto &p = d.at("periphery")[i];
|
||||
const int level = i == 0 ? p.at("stage").get<int>()
|
||||
: p.at("built") == true ? 1
|
||||
: 0,
|
||||
max = i == 0 ? p.at("maxStage").get<int>() : 1, days = p.at("constructionDays");
|
||||
const bool busy = days > 0;
|
||||
const int target = std::min(max, level + 1);
|
||||
periphery.push_back({{"id", p.at("id")},
|
||||
{"index", i},
|
||||
{"name", p.at("name")},
|
||||
{"level", level},
|
||||
{"max_level", max},
|
||||
{"display_level", future && busy ? target : level},
|
||||
{"building", busy},
|
||||
{"job", busy ? Json{{"level", target}, {"weeks", days}} : Json()}});
|
||||
}
|
||||
return {{"ok", true},
|
||||
{"club", d.at("teamId")},
|
||||
{"name", d.value("name", std::string("Stadion"))},
|
||||
{"budget", engine_money_minor(bundle.at("desktop").at("data").at("accounts").at("cash"))},
|
||||
{"blocks", blocks},
|
||||
{"facilities", facilities},
|
||||
{"periphery", periphery},
|
||||
{"available_capacity", available},
|
||||
{"planned_capacity", planned},
|
||||
{"physical_capacity", future ? planned : physical},
|
||||
{"capacity", future ? planned : available},
|
||||
{"super_stadium", super}};
|
||||
}
|
||||
Json engine_stadium_quote(const Json &bundle, const Json &draft) {
|
||||
const auto &d = read(bundle);
|
||||
const auto &q = d.at("quote");
|
||||
if (!q.is_object())
|
||||
return {{"ok", false}, {"can_build", false}};
|
||||
const auto kind = draft.at("kind").get<std::string>();
|
||||
check(q.at("kind") == kind, "Das Angebot gehört zu einer anderen Ausbauart.");
|
||||
const int index = draft.at("index");
|
||||
const auto &row = d.at(kind == "block" ? "blocks"
|
||||
: kind == "facility" ? "facilities"
|
||||
: "periphery")
|
||||
.at(size_t(index));
|
||||
check(q.at(kind == "block" ? "blockId"
|
||||
: kind == "facility" ? "facilityId"
|
||||
: "objectId") == row.at("id"),
|
||||
"Das Angebot gehört zu einem anderen Objekt.");
|
||||
const int64_t cost = engine_money_minor(q.at("price"));
|
||||
Json result = {{"ok", true},
|
||||
{"can_build", cost > 0},
|
||||
{"cost", cost},
|
||||
{"company_percent", q.value("pricePercent", 100)},
|
||||
{"weeks", q.value("weeks", 0)},
|
||||
{"options", Json::array()}};
|
||||
if (kind == "block") {
|
||||
check(q.at("places") == draft.at("places") && q.at("seats") == draft.at("seats") &&
|
||||
q.at("roof") == draft.at("roof"),
|
||||
"Das Blockangebot passt nicht zum Entwurf.");
|
||||
for (const auto &part : q.at("breakdown")) {
|
||||
const auto code = part.at("code").get<std::string>();
|
||||
result[code == "places" ? "placesCost"
|
||||
: code == "seats" ? "seatsCost"
|
||||
: "roofCost"] = engine_money_minor(part.at("amount"));
|
||||
}
|
||||
}
|
||||
if (kind == "facility") {
|
||||
check(q.at("toLevel") == draft.at("level"), "Die Angebotsstufe hat sich geändert.");
|
||||
for (const auto &option : q.at("options"))
|
||||
result["options"].push_back(
|
||||
{{"level", option.at("toLevel")}, {"cost", engine_money_minor(option.at("price"))}});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Json engine_stadium_request(const Json &bundle, const Json &draft, const std::string &id,
|
||||
bool update) {
|
||||
const auto &d = read(bundle);
|
||||
const auto kind = draft.at("kind").get<std::string>();
|
||||
check(kind == "block" || kind == "facility" || kind == "periphery", "Unbekannte Ausbauart.");
|
||||
const int index = draft.at("index");
|
||||
const auto &rows = d.at(kind == "block" ? "blocks"
|
||||
: kind == "facility" ? "facilities"
|
||||
: "periphery");
|
||||
check(index >= 0 && size_t(index) < rows.size(), "Unbekanntes Stadionobjekt.");
|
||||
const auto &row = rows[size_t(index)];
|
||||
Json payload = {{"kind", kind}};
|
||||
if (kind == "block") {
|
||||
payload["blockId"] = row.at("id");
|
||||
payload["places"] = draft.at("places");
|
||||
payload["seats"] = draft.at("seats");
|
||||
payload["roof"] = draft.at("roof");
|
||||
} else if (kind == "facility") {
|
||||
payload["facilityId"] = row.at("id");
|
||||
payload["increment"] = draft.at("level").get<int>() - row.at("level").get<int>();
|
||||
} else
|
||||
payload["objectId"] = row.at("id");
|
||||
if (update) {
|
||||
check(kind != "periphery" && d.at("quote").is_object(),
|
||||
"Kein bearbeitbares Angebot vorhanden.");
|
||||
payload["quoteId"] = d.at("quote").at("id");
|
||||
}
|
||||
return command(bundle, "quote.request", payload, id);
|
||||
}
|
||||
Json engine_stadium_commit(const Json &bundle, bool accept, const std::string &id) {
|
||||
const auto &d = read(bundle);
|
||||
check(d.at("quote").is_object(), "Kein Stadionangebot vorhanden.");
|
||||
return command(bundle, "stadium.commit",
|
||||
{{"quoteId", d.at("quote").at("id")}, {"accept", accept}, {"tip", false}}, id);
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,491 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
Json App::stadium_overview(bool future) const {
|
||||
if (!engine_mode_) {
|
||||
const auto s = snap();
|
||||
return demo_stadium_view(s.state, *s.world, future, stadium_managed(s));
|
||||
}
|
||||
auto value = engine_stadium_projection(engine_data_, future);
|
||||
const auto club = value.at("club").get<std::string>();
|
||||
const auto *team = world_->find("clubs", club);
|
||||
const Json *stadium = nullptr;
|
||||
if (team && team->value("stadium", Json()).is_string())
|
||||
stadium = world_->find("stadiums", team->at("stadium"));
|
||||
if (!stadium)
|
||||
for (const auto &row : world_->rows("stadiums"))
|
||||
if (row.value("owner", Json()) == club) {
|
||||
stadium = &row;
|
||||
break;
|
||||
}
|
||||
if (stadium)
|
||||
value["name"] = world_->name(*stadium);
|
||||
return value;
|
||||
}
|
||||
Json App::stadium_quote_value() const {
|
||||
if (engine_mode_) {
|
||||
try {
|
||||
return engine_stadium_quote(engine_data_, stadium_view_.at("draft"));
|
||||
} catch (const std::exception &) {
|
||||
return {{"ok", false}, {"can_build", false}};
|
||||
}
|
||||
}
|
||||
const auto s = snap();
|
||||
return demo_stadium_quote(s.state, stadium_view_.at("draft"), *s.world, stadium_managed(s));
|
||||
}
|
||||
std::string App::stadium_cash(const Json &value) const {
|
||||
return engine_mode_ ? (value.is_number_integer()
|
||||
? money(value.get<int64_t>(), {{"code", "EUR"}, {"minor_units", 2}})
|
||||
: "—")
|
||||
: stadium_money(value, *world_);
|
||||
}
|
||||
std::string App::stadium_offer_feedback(const Json "e, bool invalid) const {
|
||||
if (!engine_mode_)
|
||||
return stadium_feedback(quote, invalid);
|
||||
if (invalid)
|
||||
return "Bitte die Anzahl der Plätze prüfen.";
|
||||
if (!quote.value("ok", false))
|
||||
return "Angebot wird aktualisiert …";
|
||||
if (!quote.value("can_build", false))
|
||||
return "Bitte einen Ausbau auswählen.";
|
||||
const int percent = quote.value("company_percent", 100);
|
||||
return percent != 100 ? "Firmenangebot: " + std::to_string(percent) +
|
||||
" % des Grundpreises. Bauauftrag erst nach Bestätigung."
|
||||
: "Bauauftrag erst nach Bestätigung des Gesamtbetrags.";
|
||||
}
|
||||
void App::engine_stadium_sync() {
|
||||
stadium_view_defaults(stadium_view_);
|
||||
engine_stadium_value_ = Json();
|
||||
try {
|
||||
engine_stadium_value_ = stadium_overview(stadium_view_.at("future"));
|
||||
} catch (const std::exception &) {
|
||||
}
|
||||
engine_stadium_context_ = engine_data_.at("desktop").at("meta");
|
||||
}
|
||||
void App::engine_stadium_poll() {
|
||||
engine_stadium_sync();
|
||||
if (engine_stadium_operation_.empty())
|
||||
return;
|
||||
const auto operation = std::exchange(engine_stadium_operation_, std::string());
|
||||
const bool success = engine_response_.value("messageType", "") == "command_result";
|
||||
if (!success) {
|
||||
engine_stadium_exit_ = false;
|
||||
if (engine_stadium_confirmed_.is_object())
|
||||
stadium_view_["draft"] = engine_stadium_confirmed_;
|
||||
stadium_view_["feedback"] = engine_notice_;
|
||||
return;
|
||||
}
|
||||
if (operation == "quote" || operation == "update") {
|
||||
engine_stadium_confirmed_ = stadium_view_.at("draft");
|
||||
stadium_view_["feedback"] = "";
|
||||
focus_after_render_ =
|
||||
stadium_view_.at("dialog") == "block" ? "stadium-place-range" : "stadium-build";
|
||||
return;
|
||||
}
|
||||
if (operation == "build" || operation == "cancel") {
|
||||
const auto focus = stadium_view_.value("return_focus", std::string("stadium-data"));
|
||||
bool built = true;
|
||||
if (operation == "build") {
|
||||
const auto &d = stadium_view_.at("draft");
|
||||
const auto now = stadium_overview(false);
|
||||
built = now.at(d.at("kind") == "block" ? "blocks"
|
||||
: d.at("kind") == "facility" ? "facilities"
|
||||
: "periphery")
|
||||
.at(d.at("index").get<size_t>())
|
||||
.at("building");
|
||||
if (!built) {
|
||||
auto reason = engine_text(engine_response_.at("feedback"));
|
||||
if (reason.empty() || reason == "Der Bau beginnt." || reason == "—")
|
||||
reason = "Der Ausbau wurde nicht begonnen.";
|
||||
engine_notice_ = reason;
|
||||
message(reason);
|
||||
}
|
||||
if (built && d.at("kind") != "periphery")
|
||||
stadium_view_["future"] = true;
|
||||
}
|
||||
stadium_view_["dialog"] = "";
|
||||
stadium_view_["draft"] = Json();
|
||||
stadium_view_["feedback"] = "";
|
||||
stadium_view_["invalid_places"] = false;
|
||||
stadium_view_["hint"] = "";
|
||||
engine_stadium_confirmed_ = Json();
|
||||
focus_after_render_ = focus;
|
||||
if (engine_stadium_exit_) {
|
||||
engine_stadium_exit_ = false;
|
||||
engine_quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
void App::engine_stadium_send(const Json &request, const std::string &operation) {
|
||||
if (engine_busy_ || !engine_fresh_)
|
||||
return;
|
||||
engine_stadium_operation_ = operation;
|
||||
auto link = engine_link_;
|
||||
engine_start(operation == "build" ? "Stadionbau wird beauftragt …"
|
||||
: operation == "cancel" ? "Angebot wird geschlossen …"
|
||||
: "Stadionangebot wird berechnet …",
|
||||
[link, request] {
|
||||
const auto response = link->command(request);
|
||||
return EngineReply{link, link->snapshot(), response, nullptr};
|
||||
});
|
||||
}
|
||||
std::string App::engine_stadium_data() {
|
||||
const auto &data = engine_data_.at("stadium").at("data");
|
||||
std::string svg = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2560 456'><path d='M20 "
|
||||
"10V436H2540' fill='none' stroke='" +
|
||||
std::string(theme_ == "silver" ? "#627c8f" : "#7d9aae") +
|
||||
"' stroke-width='2'/>";
|
||||
constexpr std::array<const char *, 6> colors{"#8fbaa6", "#8cacc9", "#adb7c1",
|
||||
"#cf9088", "#c5b384", "#729aae"},
|
||||
names{"Zuschauer", "Eintritt", "Stadionwert", "Zus. Stadion-Einnahmen",
|
||||
"Einnahmen", "Stadionkosten"};
|
||||
for (size_t curve = 0; curve < 6; ++curve)
|
||||
if (stadium_view_.at("curves")[curve] == true) {
|
||||
svg += "<polyline fill='none' stroke='" + std::string(colors[curve]) +
|
||||
"' stroke-width='4' points='";
|
||||
for (const auto &point : data.at("history")[curve].at(
|
||||
stadium_view_.at("relative") == true ? "relative" : "absolute"))
|
||||
svg += scalar(20. + (point[0].get<double>() - 13.) * 2520. / 298.) + "," +
|
||||
scalar(20. + (point[1].get<double>() - 18.) * 416. / 83.) + " ";
|
||||
svg += "'/>";
|
||||
const auto &points = data.at("history")[curve].at(
|
||||
stadium_view_.at("relative") == true ? "relative" : "absolute");
|
||||
if (points.size() == 1)
|
||||
svg += "<circle cx='" + scalar(20. + (points[0][0].get<double>() - 13.) * 2520. / 298.) +
|
||||
"' cy='" + scalar(20. + (points[0][1].get<double>() - 18.) * 416. / 83.) +
|
||||
"' r='3' fill='" + std::string(colors[curve]) + "'/>";
|
||||
}
|
||||
svg += "</svg>";
|
||||
std::string out = "<div class=\"stadium-graph\"><div class=\"stadium-graph-art\">" +
|
||||
picture(renderer_.diagram("stadium-engine-graph", svg, 5120), 2560, 456) +
|
||||
"</div></div>";
|
||||
for (size_t i = 0; i < 6; ++i)
|
||||
out += btn("stadium-curve",
|
||||
"<span class=\"stadium-curve-color\" style=\"background-color:" +
|
||||
std::string(colors[i]) + ";\"></span><span class=\"stadium-curve-label\">" +
|
||||
esc(data.at("history")[i].value("name", std::string(names[i]))) + "</span>",
|
||||
"stadium-curve",
|
||||
"id=\"stadium-curve-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) +
|
||||
"\" aria-pressed=\"" +
|
||||
(stadium_view_.at("curves")[i] == true ? "true" : "false") + "\" style=\"" +
|
||||
rect((i % 3) * 754.666666667, 660 + (i / 3) * 90, 732.666666667, 74) + "\"");
|
||||
for (int i = 0; i < 2; ++i)
|
||||
out += btn("stadium-scale", i ? "Relativ" : "Absolut", "stadium-scale",
|
||||
"id=\"stadium-scale-" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) +
|
||||
"\" aria-pressed=\"" +
|
||||
(stadium_view_.at("relative") == bool(i) ? "true" : "false") + "\" style=\"" +
|
||||
rect(2282, 660 + i * 90, 330, 74) + "\"");
|
||||
const std::array<const char *, 6> labels{"", "Max. Zuschauer", "Max. Einnahmen (€)",
|
||||
"Heimspiele", "Ø Zuschauer", "Ges. Einnahmen (€)"};
|
||||
out += "<div class=\"stadium-data-table\">";
|
||||
for (size_t row = 0; row < 6; ++row) {
|
||||
out += "<div class=\"stadium-data-row " +
|
||||
std::string(row == 0 ? "head"
|
||||
: row % 2 ? "striped"
|
||||
: "") +
|
||||
"\">";
|
||||
for (size_t col = 0; col < 4; ++col) {
|
||||
std::string value;
|
||||
if (!col)
|
||||
value = labels[row];
|
||||
else if (!row)
|
||||
value = col == 1 ? "Liga" : col == 2 ? "DFB-Pokal" : "Europapokal";
|
||||
else {
|
||||
const size_t source = row == 1 ? 0 : row == 2 ? 2 : row + 1;
|
||||
value = data.at("table")[source][col - 1];
|
||||
if (row <= 2) {
|
||||
const auto other = data.at("table")[source + 1][col - 1].get<std::string>();
|
||||
if (!other.empty())
|
||||
value += " · " + other;
|
||||
}
|
||||
}
|
||||
out += "<div class=\"stadium-data-cell " + std::string(col ? "" : "first") + "\"><span>" +
|
||||
esc(value) + "</span></div>";
|
||||
}
|
||||
out += "</div>";
|
||||
}
|
||||
out += "</div>";
|
||||
const int ticket = int(engine_money_minor(data.at("ticketPrice")) / 100);
|
||||
out += "<p class=\"stadium-required\"><span>Benötigter Zuschauerschnitt bei " +
|
||||
std::to_string(ticket) + " € Eintritt: </span><span class=\"stadium-required-value\">" +
|
||||
esc(data.at("requiredAttendanceText").get<std::string>()) +
|
||||
"</span></p><div class=\"stadium-ticket\"><strong>Eintritt:</strong>";
|
||||
const int low = int(engine_money_minor(data.at("ticketPriceRange").at("min")) / 100),
|
||||
high = int(engine_money_minor(data.at("ticketPriceRange").at("max")) / 100);
|
||||
for (int price = low; price <= high; ++price)
|
||||
out += btn(
|
||||
"stadium-ticket", (price < 10 ? "0" : "") + std::to_string(price), "stadium-ticket-price",
|
||||
"id=\"stadium-ticket-" + std::to_string(price) + "\" data-id=\"" + std::to_string(price) +
|
||||
"\" aria-pressed=\"" + (ticket == price ? "true" : "false") + "\"");
|
||||
return out + "</div>";
|
||||
}
|
||||
bool App::engine_stadium_action(const std::string &action, Rml::Element *target) {
|
||||
if (!action.starts_with("stadium-"))
|
||||
return false;
|
||||
if (menu_ != "stadium" || engine_busy_ || !engine_fresh_ || !engine_stadium_value_.is_object() ||
|
||||
amount_ || !popup_.empty())
|
||||
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);
|
||||
if (action == "stadium-cancel") {
|
||||
if (engine_data_.at("stadium").at("data").at("quote").is_object())
|
||||
engine_stadium_send(engine_stadium_commit(engine_data_, false, editor::new_id("request:ui-")),
|
||||
"cancel");
|
||||
else {
|
||||
stadium_view_["dialog"] = "";
|
||||
stadium_view_["draft"] = Json();
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-build") {
|
||||
const auto q = stadium_quote_value();
|
||||
if (!q.value("can_build", false))
|
||||
return true;
|
||||
const auto request = engine_stadium_commit(engine_data_, true, editor::new_id("request:ui-")),
|
||||
context = engine_data_.at("desktop").at("meta");
|
||||
confirmation("Diesen Ausbau für " + stadium_cash(q.at("cost")) + " beauftragen?",
|
||||
[this, request, context] {
|
||||
if (engine_data_.at("desktop").at("meta") != context) {
|
||||
message("Das Angebot hat sich geändert. Bitte erneut öffnen.");
|
||||
return;
|
||||
}
|
||||
engine_stadium_send(request, "build");
|
||||
});
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-option" && stadium_view_.at("dialog") == "facility" && index) {
|
||||
auto d = stadium_view_.at("draft");
|
||||
d["level"] = *index;
|
||||
stadium_view_["draft"] = d;
|
||||
engine_stadium_send(
|
||||
engine_stadium_request(engine_data_, d, editor::new_id("request:ui-"), true), "update");
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-places-editor" && stadium_view_.at("dialog") == "block") {
|
||||
const auto overview = stadium_overview(false);
|
||||
const auto row = overview.at("blocks").at(stadium_view_.at("draft").at("index").get<size_t>());
|
||||
const auto context = engine_data_.at("desktop").at("meta");
|
||||
AmountRequest r;
|
||||
r.title = "Neue Gesamtplätze";
|
||||
r.unit = "Plätze";
|
||||
r.value = stadium_view_.at("draft").at("places");
|
||||
r.min = row.at("places");
|
||||
r.max = row.at("max_places");
|
||||
r.step = 1000;
|
||||
r.suggestion_step = 1000;
|
||||
r.return_focus = "stadium-place-number";
|
||||
r.review = false;
|
||||
r.accept = [this, context](int64_t places) {
|
||||
if (engine_data_.at("desktop").at("meta") != context || places % 1000)
|
||||
return false;
|
||||
stadium_view_["draft"]["places"] = places;
|
||||
engine_stadium_send(engine_stadium_request(engine_data_, stadium_view_.at("draft"),
|
||||
editor::new_id("request:ui-"), true),
|
||||
"update");
|
||||
return true;
|
||||
};
|
||||
open_amount(std::move(r));
|
||||
return true;
|
||||
}
|
||||
if (stadium_view_.at("dialog") != "")
|
||||
return true;
|
||||
if (action == "stadium-view") {
|
||||
stadium_view_["view"] = "panorama";
|
||||
stadium_view_["hint"] = "";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-back") {
|
||||
stadium_view_["view"] = "inside";
|
||||
stadium_view_["hint"] = "";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-future") {
|
||||
stadium_view_["future"] = !stadium_view_.at("future").get<bool>();
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-data") {
|
||||
stadium_view_["view"] = "data";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-curve" && index && *index < 6) {
|
||||
stadium_view_["curves"][size_t(*index)] =
|
||||
!stadium_view_.at("curves")[size_t(*index)].get<bool>();
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-scale" && index && *index < 2) {
|
||||
stadium_view_["relative"] = bool(*index);
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "stadium-ticket" && index) {
|
||||
const auto request = engine_ticket_command(engine_data_, *index, editor::new_id("request:ui-"));
|
||||
confirmation("Eintritt auf " + std::to_string(*index) + " € ändern?",
|
||||
[this, request] { engine_stadium_send(request, "ticket"); });
|
||||
return true;
|
||||
}
|
||||
const bool block = action == "stadium-block", facility = action == "stadium-facility",
|
||||
periphery = action == "stadium-periphery";
|
||||
if (!block && !facility && !periphery)
|
||||
return true;
|
||||
if (!index || *index >= (periphery ? 14 : 8))
|
||||
return true;
|
||||
const auto overview = stadium_overview(false);
|
||||
const auto &row = overview.at(block ? "blocks"
|
||||
: facility ? "facilities"
|
||||
: "periphery")[size_t(*index)];
|
||||
if (row.at("building") == true)
|
||||
return true;
|
||||
if (facility && row.at("available") != true)
|
||||
return true;
|
||||
if (periphery && row.at("level").get<int>() >= row.at("max_level").get<int>())
|
||||
return true;
|
||||
Json d = {{"kind", block ? "block" : facility ? "facility" : "periphery"}, {"index", *index}};
|
||||
if (block) {
|
||||
d["places"] = row.at("places");
|
||||
d["seats"] = row.at("seats");
|
||||
d["roof"] = row.at("roof");
|
||||
} else
|
||||
d["level"] = row.at("level").get<int>() + 1;
|
||||
stadium_view_["draft"] = d;
|
||||
stadium_view_["dialog"] = d.at("kind");
|
||||
stadium_view_["feedback"] = "";
|
||||
stadium_view_["return_focus"] = target->GetId();
|
||||
engine_stadium_confirmed_ = Json();
|
||||
engine_stadium_send(engine_stadium_request(engine_data_, d, editor::new_id("request:ui-")),
|
||||
"quote");
|
||||
return true;
|
||||
}
|
||||
bool App::engine_stadium_event(Rml::Event &event) {
|
||||
if (menu_ != "stadium" || amount_ || !popup_.empty())
|
||||
return false;
|
||||
stadium_view_defaults(stadium_view_);
|
||||
const auto type = event.GetType();
|
||||
auto *target = event.GetTargetElement();
|
||||
const bool key_event = type == "keydown";
|
||||
const auto key = key_event
|
||||
? Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0))
|
||||
: Rml::Input::KI_UNKNOWN;
|
||||
const bool dialog = stadium_view_.at("dialog") != "";
|
||||
if (engine_busy_) {
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if ((key_event && key == Rml::Input::KI_ESCAPE) ||
|
||||
(dialog && type == "mouseup" && event.GetParameter<int>("button", 0) == 1)) {
|
||||
if (dialog)
|
||||
engine_stadium_action("stadium-cancel", nullptr);
|
||||
else if (stadium_view_.at("view") != "inside")
|
||||
engine_stadium_action("stadium-back", nullptr);
|
||||
else
|
||||
return false;
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (!dialog && stadium_view_.at("view") == "panorama" &&
|
||||
(type == "mousemove" || type == "focus" || type == "blur")) {
|
||||
std::string hint;
|
||||
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
||||
if (n->HasAttribute("data-stadium-hint")) {
|
||||
hint = n->GetAttribute<Rml::String>("data-stadium-hint", "");
|
||||
break;
|
||||
}
|
||||
if (type == "blur")
|
||||
hint.clear();
|
||||
if (stadium_view_.at("hint") != hint) {
|
||||
stadium_view_["hint"] = hint;
|
||||
if (auto *n = element("stadium-interaction-hint"))
|
||||
n->SetInnerRML("<span>" +
|
||||
esc(hint.empty() ? "Ein Element im Stadionumfeld auswählen." : hint) +
|
||||
"</span>");
|
||||
dirty_ = true;
|
||||
}
|
||||
}
|
||||
Rml::Element *range = nullptr;
|
||||
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
||||
if (n->GetId() == "stadium-place-range") {
|
||||
range = n;
|
||||
break;
|
||||
}
|
||||
const auto update = [&] {
|
||||
engine_stadium_send(engine_stadium_request(engine_data_, stadium_view_.at("draft"),
|
||||
editor::new_id("request:ui-"), true),
|
||||
"update");
|
||||
};
|
||||
if (dialog && stadium_view_.at("dialog") == "block") {
|
||||
if (range && (type == "input" || type == "change")) {
|
||||
if (auto *control = dynamic_cast<Rml::ElementFormControl *>(range)) {
|
||||
const auto places = stadium_integer(control->GetValue(), 255000);
|
||||
if (places) {
|
||||
stadium_view_["draft"]["places"] = *places;
|
||||
sync_stadium_draft();
|
||||
}
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (range && type == "mouseup") {
|
||||
if (stadium_view_.at("draft") != engine_stadium_confirmed_)
|
||||
update();
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (range && key_event &&
|
||||
(key == Rml::Input::KI_HOME || key == Rml::Input::KI_END || key == Rml::Input::KI_LEFT ||
|
||||
key == Rml::Input::KI_RIGHT || key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN)) {
|
||||
const auto row = stadium_overview(false).at("blocks").at(
|
||||
stadium_view_.at("draft").at("index").get<size_t>());
|
||||
int places = stadium_view_.at("draft").at("places");
|
||||
places = key == Rml::Input::KI_HOME ? row.at("places").get<int>()
|
||||
: key == Rml::Input::KI_END
|
||||
? row.at("max_places").get<int>()
|
||||
: places + ((key == Rml::Input::KI_LEFT || key == Rml::Input::KI_DOWN) ? -1000
|
||||
: 1000);
|
||||
stadium_view_["draft"]["places"] =
|
||||
std::clamp(places, row.at("places").get<int>(), row.at("max_places").get<int>());
|
||||
update();
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (type == "change" && target && target->HasAttribute("data-stadium-feature")) {
|
||||
const auto field = target->GetAttribute<Rml::String>("data-stadium-feature", "");
|
||||
if (field == "seats" || field == "roof") {
|
||||
stadium_view_["draft"][field] = target->HasAttribute("checked");
|
||||
update();
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dialog && key_event && key == Rml::Input::KI_TAB) {
|
||||
Rml::ElementList nodes;
|
||||
if (auto *root = element("stadium-draft"))
|
||||
root->QuerySelectorAll(nodes, "button,input");
|
||||
std::erase_if(nodes,
|
||||
[](auto *n) { return n->HasAttribute("disabled") || !n->IsVisible(true); });
|
||||
if (!nodes.empty()) {
|
||||
const auto at = std::find(nodes.begin(), nodes.end(), context_->GetFocusElement());
|
||||
const int current = at == nodes.end() ? -1 : int(at - nodes.begin()),
|
||||
count = int(nodes.size());
|
||||
nodes[size_t((current + count + (event.GetParameter<int>("shift_key", 0) ? -1 : 1)) % count)]
|
||||
->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (dialog) {
|
||||
bool inside = false;
|
||||
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
||||
if (n->GetId() == "stadium-modal")
|
||||
inside = true;
|
||||
if (!inside && (type == "click" || type == "mousedown" || type == "mouseup" || key_event)) {
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -112,3 +112,17 @@
|
||||
Json toto_value() const;
|
||||
Json toto_summary() const;
|
||||
Json toto_programme() const;
|
||||
|
||||
Json engine_stadium_context_,engine_stadium_value_,engine_stadium_confirmed_;
|
||||
std::string engine_stadium_operation_;
|
||||
bool engine_stadium_exit_=false;
|
||||
Json stadium_overview(bool) const;
|
||||
Json stadium_quote_value() const;
|
||||
std::string stadium_cash(const Json &) const;
|
||||
std::string stadium_offer_feedback(const Json &,bool) const;
|
||||
std::string engine_stadium_data();
|
||||
void engine_stadium_sync();
|
||||
void engine_stadium_poll();
|
||||
void engine_stadium_send(const Json &,const std::string &);
|
||||
bool engine_stadium_action(const std::string &,Rml::Element *);
|
||||
bool engine_stadium_event(Rml::Event &);
|
||||
@@ -8,6 +8,7 @@ std::optional<int> stadium_integer(const std::string &text,int maximum) {
|
||||
}
|
||||
} // namespace
|
||||
void App::sync_stadium_draft() {
|
||||
if(engine_mode_){if(auto *button=element("stadium-build"))button->SetAttribute("disabled",true);for(const auto *id:{"stadium-quote-total","stadium-cost-placesCost","stadium-cost-seatsCost","stadium-cost-roofCost"})if(auto *n=element(id))n->SetInnerRML("—");if(auto *n=element("stadium-draft-feedback"))n->SetInnerRML("Angebot für die geänderte Auswahl wird aktualisiert.");if(auto *n=element("stadium-place-number"))n->SetInnerRML("<span class=\"control-label\">"+std::to_string(stadium_view_.at("draft").at("places").get<int64_t>())+"</span>");dirty_=true;return;}
|
||||
stadium_view_defaults(stadium_view_);if(stadium_view_.at("dialog")==""||!stadium_view_.at("draft").is_object())return;
|
||||
const auto s=snap();const bool fresh=s.world==stadium_world_&&source_.get()==stadium_source_&&s.revision==stadium_revision_&&stadium_managed(s)==stadium_view_.value("bound_club",std::string());
|
||||
const auto q=fresh?demo_stadium_quote(s.state,stadium_view_.at("draft"),*s.world,stadium_managed(s)):Json{{"ok",false}};
|
||||
@@ -25,6 +26,7 @@ void App::sync_stadium_draft() {
|
||||
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;
|
||||
stadium_view_defaults(stadium_view_);const auto s=snap();const auto club=stadium_managed(s);
|
||||
@@ -101,6 +103,7 @@ bool App::stadium_action(const std::string &action,Rml::Element *target) {
|
||||
refresh();return true;
|
||||
}
|
||||
bool App::stadium_event(Rml::Event &event) {
|
||||
if(engine_mode_)return engine_stadium_event(event);
|
||||
if(menu_!="stadium"||!source_||!report_detail_kind_.empty())return false;
|
||||
stadium_view_defaults(stadium_view_);const auto type=event.GetType();auto *target=event.GetTargetElement();
|
||||
const auto key=type=="keydown"?Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0)):Rml::Input::KI_UNKNOWN;
|
||||
|
||||
@@ -59,11 +59,11 @@ std::string stadium_graph_svg(const Json &curves,bool relative,const std::string
|
||||
} // namespace
|
||||
|
||||
std::string App::render_stadium() {
|
||||
stadium_view_defaults(stadium_view_);const auto snapshot=snap();const auto club=stadium_managed(snapshot);
|
||||
if(!snapshot.world||club.empty())return "<p class=\"stadium-empty\">Die Stadionvorschau ist derzeit nicht verfügbar.</p>";
|
||||
stadium_view_defaults(stadium_view_);if(!world_)return "";
|
||||
const bool future=stadium_view_.at("future").get<bool>();
|
||||
const auto overview=demo_stadium_view(snapshot.state,*snapshot.world,future,club);
|
||||
const auto overview=stadium_overview(future);const auto club=overview.value("club",std::string());
|
||||
if(!overview.value("ok",false))return "<p class=\"stadium-empty\">Die Stadionvorschau ist derzeit nicht verfügbar.</p>";
|
||||
if(engine_mode_)engine_stadium_value_=overview;
|
||||
const auto view=stadium_view_.at("view").get<std::string>();
|
||||
const auto feature=[&](const std::string &kind,bool built,double size) {return picture(renderer_.diagram("stadium-feature-"+kind+(built?"-built-":"-empty-")+theme_,stadium_feature_svg(kind,built,theme_),232),size,size);};
|
||||
const auto art_overlay=[&](int i,int level,double w,double natural_h) {
|
||||
@@ -87,7 +87,7 @@ 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>Ausbaubudget</span><strong>"+esc(stadium_money(overview.at("budget"),*snapshot.world))+"</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"?"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=="inside") {
|
||||
constexpr double bowl_h=1430.0*1045/1505;
|
||||
out+="<div class=\"stadium-bowl\">"+img("art.stadium-interior-v1.png",1426,bowl_h-4,false,false,2048);
|
||||
@@ -126,6 +126,8 @@ std::string App::render_stadium() {
|
||||
} catch(const std::exception &) {out+="<p class=\"stadium-empty\">Die Stadionumfeld-Grafiken sind unvollständig.</p>";}
|
||||
out+="</div><p id=\"stadium-interaction-hint\" role=\"status\" aria-live=\"polite\"><span>"+esc(stadium_view_.at("hint").get<std::string>().empty()?"Ein Element im Stadionumfeld auswählen.":stadium_view_.at("hint").get<std::string>())+"</span></p>";
|
||||
} else {
|
||||
if(engine_mode_)out+=engine_stadium_data();
|
||||
else {const auto snapshot=snap();
|
||||
const auto graph=stadium_graph_svg(stadium_view_.at("curves"),stadium_view_.at("relative").get<bool>(),theme_);
|
||||
out+="<div class=\"stadium-graph\"><div class=\"stadium-graph-art\">"+picture(renderer_.diagram("stadium-graph",graph,7200),2560,456)+"</div></div>";
|
||||
constexpr std::array<const char*,6> colors{"#8fbaa6","#8cacc9","#adb7c1","#cf9088","#c5b384","#729aae"},names{"Zuschauer","Eintritt","Stadionwert","Zus. Stadion-Einnahmen","Einnahmen","Stadionkosten"};
|
||||
@@ -140,6 +142,7 @@ std::string App::render_stadium() {
|
||||
out+="<p class=\"stadium-required\"><span>Benötigter Zuschauerschnitt bei "+esc(cash(ticket))+" Eintritt: </span><span class=\"stadium-required-value\">"+(ticket?number((94000+ticket-1)/ticket):"–")+"</span></p><div class=\"stadium-ticket\"><strong>Eintritt:</strong>";
|
||||
for(int price=0;price<=25;++price)out+=btn("stadium-ticket",(price<10?"0":"")+std::to_string(price),"stadium-ticket-price","id=\"stadium-ticket-"+std::to_string(price)+"\" data-id=\""+std::to_string(price)+"\" aria-pressed=\""+(price==ticket?"true":"false")+"\" aria-label=\"Eintritt "+std::to_string(price)+" "+esc(money_unit())+"\"");
|
||||
out+="</div>";
|
||||
}
|
||||
}
|
||||
out+="<nav class=\"stadium-nav\">";
|
||||
if(view=="panorama") {
|
||||
@@ -157,11 +160,12 @@ std::string App::render_stadium() {
|
||||
|
||||
std::string App::render_stadium_dialog() {
|
||||
stadium_view_defaults(stadium_view_);if(stadium_view_.at("dialog")=="")return "";
|
||||
const auto s=snap();if(!s.world||!stadium_view_.at("draft").is_object())return "";
|
||||
if(!world_||!stadium_view_.at("draft").is_object())return "";
|
||||
const auto &d=stadium_view_.at("draft");const bool block=d.at("kind")=="block";const int index=d.at("index").get<int>();
|
||||
const auto overview=demo_stadium_view(s.state,*s.world,false,stadium_managed(s));if(!overview.value("ok",false))return "";
|
||||
const auto overview=stadium_overview(false);if(!overview.value("ok",false))return "";
|
||||
const bool periphery=d.at("kind")=="periphery";
|
||||
const auto &row=overview.at(block?"blocks":periphery?"periphery":"facilities")[size_t(index)];const auto q=demo_stadium_quote(s.state,d,*s.world,stadium_managed(s));
|
||||
const auto &row=overview.at(block?"blocks":periphery?"periphery":"facilities")[size_t(index)];const auto q=stadium_quote_value();
|
||||
if(engine_mode_&&!q.value("ok",false))return "<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" style=\""+rect(226,650,2160,480)+"\"><h2>"+esc(row.at("name").get<std::string>())+" ausbauen</h2><p>"+esc(engine_busy_?"Angebot wird geladen …":stadium_view_.value("feedback",std::string("Kein gültiges Angebot verfügbar.")))+"</p><nav class=\"stadium-draft-actions\" style=\"top:300dp;\">"+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
|
||||
if(periphery) {
|
||||
const int level=d.at("level").get<int>();std::string preview;
|
||||
if(gui_.contains("stadium.scene"))try {
|
||||
@@ -172,20 +176,20 @@ std::string App::render_stadium_dialog() {
|
||||
preview="<span class=\"stadium-periphery-preview\" style=\""+rect(680,174,800,height)+"\">"+img("stadium.scene."+asset,800,height,false,false,1600)+"</span>";
|
||||
} catch(const std::exception &) {}
|
||||
const auto title=row.at("name").get<std::string>();
|
||||
return "<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,377,2160,1110)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>"+(row.at("level")==0?"Neubau":"Erweiterung")+" · Stufe "+std::to_string(level)+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",0))+" Wochen</span></div>"+preview+"<div class=\"stadium-draft-total\" style=\"top:758dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_money(stadium_field(q,"cost"),*s.world))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:850dp;\">"+esc(stadium_feedback(q,false))+"</p><nav class=\"stadium-draft-actions\" style=\"top:946dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(q.value("can_build",false)?"":"disabled=\"disabled\""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
|
||||
return "<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,377,2160,1110)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>"+(row.at("level")==0?"Neubau":"Erweiterung")+" · Stufe "+std::to_string(level)+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",0))+" Wochen</span></div>"+preview+"<div class=\"stadium-draft-total\" style=\"top:758dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_cash(stadium_field(q,"cost")))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:850dp;\">"+esc(stadium_offer_feedback(q,false))+"</p><nav class=\"stadium-draft-actions\" style=\"top:946dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(q.value("can_build",false)?"":"disabled=\"disabled\""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
|
||||
}
|
||||
struct Option {int level;Picture art;double height;};std::vector<Option> options;double option_h=0;
|
||||
if(!block)for(int level=row.at("level").get<int>()+1;level<=row.at("max_level").get<int>();++level){const auto a=renderer_.image("stadium.facility."+std::to_string(index)+".level."+std::to_string(level),false,2048);const double h=a.width?592.0*a.height/a.width:325;options.push_back({level,a,h});option_h=std::max(option_h,h+159);}
|
||||
if(!block)for(int level=row.at("level").get<int>()+1;level<=row.at("max_level").get<int>();++level){if(engine_mode_&&std::none_of(q.at("options").begin(),q.at("options").end(),[&](const auto &option){return option.at("level")==level;}))continue;const auto a=renderer_.image("stadium.facility."+std::to_string(index)+".level."+std::to_string(level),false,2048);const double h=a.width?592.0*a.height/a.width:325;options.push_back({level,a,h});option_h=std::max(option_h,h+159);}
|
||||
const double height=block?982.5:option_h+499,total_top=block?687.5:option_h+204,feedback_top=block?776.5:option_h+293,actions_top=block?854.5:option_h+371;
|
||||
const auto title=block?"Block "+row.at("letter").get<std::string>()+" · "+row.at("name").get<std::string>():row.at("name").get<std::string>();
|
||||
std::string out="<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,(1864-height)/2,2160,height)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>POC-Budget: "+esc(stadium_money(overview.at("budget"),*s.world))+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",row.at("weeks").get<int>()))+" Wochen</span></div>";
|
||||
std::string out="<div class=\"stadium-modal\" id=\"stadium-modal\"><section class=\"stadium-draft\" id=\"stadium-draft\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"stadium-draft-title\" style=\""+rect(226,(1864-height)/2,2160,height)+"\"><h2 id=\"stadium-draft-title\">"+esc(title)+" ausbauen</h2><div class=\"stadium-draft-summary\"><span>"+std::string(engine_mode_?"Vereinskasse: ":"POC-Budget: ")+esc(stadium_cash(overview.at("budget")))+"</span><span>Bauzeit: "+std::to_string(q.value("weeks",row.at("weeks").get<int>()))+" Wochen</span></div>";
|
||||
if(block) {
|
||||
out+="<section class=\"stadium-place-field\"><strong>Block "+row.at("letter").get<std::string>()+"</strong><p>Aktuell: "+number(row.at("places").get<int64_t>())+" Plätze</p><span class=\"stadium-place-label\"><span>Neue Gesamtplätze</span></span>"+btn("stadium-places-editor",std::to_string(d.at("places").get<int64_t>()),"stadium-place-number amount-trigger","id=\"stadium-place-number\"")+"<input type=\"range\" id=\"stadium-place-range\" min=\""+std::to_string(row.at("places").get<int>())+"\" max=\""+std::to_string(row.at("max_places").get<int>())+"\" step=\"1000\" value=\""+std::to_string(d.at("places").get<int>())+"\" aria-label=\"Neue Gesamtplätze\"/></section><div class=\"stadium-features\">";
|
||||
const std::array<const char*,2> features{"seats","roof"},labels{"Sitzplätze","Überdachung"};
|
||||
for(size_t i=0;i<2;++i){const bool built=row.at(features[i]).get<bool>();const bool checked=d.at(features[i]).get<bool>();out+="<label class=\"stadium-feature-row\"><input type=\"checkbox\" id=\"stadium-feature-"+std::string(features[i])+"\" data-stadium-feature=\""+features[i]+"\" "+(checked?"checked=\"checked\" ":"")+(built?"disabled=\"disabled\" ":"")+"/><span class=\"stadium-feature-image\" id=\"stadium-feature-image-"+std::string(features[i])+"\">"+picture(renderer_.diagram("stadium-feature-"+std::string(features[i])+(checked?"-built-":"-empty-")+theme_,stadium_feature_svg(features[i],checked,theme_),232),116,116)+"</span><span>"+labels[i]+"</span></label>";}
|
||||
out+="</div><dl class=\"stadium-costs\">";
|
||||
const std::array<const char*,3> keys{"placesCost","seatsCost","roofCost"},names{"Neue Plätze","Sitzplätze","Überdachung"};
|
||||
for(size_t i=0;i<3;++i)out+="<div class=\"stadium-cost-row\" style=\"top:"+scalar(i*51.5)+"dp;\"><dt>"+std::string(names[i])+"</dt><dd id=\"stadium-cost-"+keys[i]+"\">"+esc(stadium_money(stadium_field(q,keys[i]),*s.world))+"</dd></div>";
|
||||
for(size_t i=0;i<3;++i)out+="<div class=\"stadium-cost-row\" style=\"top:"+scalar(i*51.5)+"dp;\"><dt>"+std::string(names[i])+"</dt><dd id=\"stadium-cost-"+keys[i]+"\">"+esc(stadium_cash(stadium_field(q,keys[i])))+"</dd></div>";
|
||||
out+="</dl>";
|
||||
} else {
|
||||
const double total=options.size()*640+(options.size()-1)*28,left=52+(2052-total)/2;
|
||||
@@ -200,10 +204,10 @@ std::string App::render_stadium_dialog() {
|
||||
art+="<span class=\"stadium-art-overlay\" style=\""+rect(592*x,o.height*y,592*rw,o.height*rh)+"\">"+picture(renderer_.diagram("stadium-option-score-"+std::to_string(o.level)+"-"+theme_,svg,1536),592*rw,o.height*rh)+"</span>";
|
||||
}
|
||||
if(index==5){const std::string color=theme_=="silver"?"#805b18":theme_=="matchday"?"#e1c68b":"#e0c99b";const auto svg=stadium_svg("<path d=\"m24 3 6 13 15 2-11 11 3 15-13-7-13 7 3-15L3 18l15-2Z\" fill=\""+color+"\"/>",48,48);const int n=o.level-1;for(int j=0;j<n;++j)art+="<span class=\"stadium-art-overlay\" style=\""+rect((592-(n*52+(n-1)*8))/2+j*60,(o.height-52)/2,52,52)+"\">"+picture(renderer_.diagram("stadium-option-star-"+theme_,svg,104),52,52)+"</span>";}
|
||||
out+=btn("stadium-option","<span class=\"stadium-option-art\" style=\"height:"+scalar(o.height)+"dp;top:"+scalar(22+group_offset)+"dp;\">"+art+"</span><strong style=\"top:"+scalar(22+o.height+20+group_offset)+"dp;\">"+esc(row.at("levels")[size_t(o.level)].get<std::string>())+"</strong><span class=\"stadium-option-price\" style=\"top:"+scalar(22+o.height+20+37+20+group_offset)+"dp;\">"+esc(stadium_money(Json(int64_t(o.level-row.at("level").get<int>())*row.at("rate").get<int64_t>()),*s.world))+"</span>","stadium-option","id=\"stadium-option-"+std::to_string(o.level)+"\" data-id=\""+std::to_string(o.level)+"\" aria-pressed=\""+(selected?"true":"false")+"\" style=\""+rect(left+i*668,174,640,option_h)+"\"");
|
||||
out+=btn("stadium-option","<span class=\"stadium-option-art\" style=\"height:"+scalar(o.height)+"dp;top:"+scalar(22+group_offset)+"dp;\">"+art+"</span><strong style=\"top:"+scalar(22+o.height+20+group_offset)+"dp;\">"+esc(row.at("levels")[size_t(o.level)].get<std::string>())+"</strong><span class=\"stadium-option-price\" style=\"top:"+scalar(22+o.height+20+37+20+group_offset)+"dp;\">"+esc(stadium_cash(engine_mode_?[&]()->Json{for(const auto &option:q.at("options"))if(option.at("level")==o.level)return option.at("cost");return Json();}():Json(int64_t(o.level-row.at("level").get<int>())*row.at("rate").get<int64_t>())))+"</span>","stadium-option","id=\"stadium-option-"+std::to_string(o.level)+"\" data-id=\""+std::to_string(o.level)+"\" aria-pressed=\""+(selected?"true":"false")+"\" style=\""+rect(left+i*668,174,640,option_h)+"\"");
|
||||
}
|
||||
}
|
||||
const auto custom=stadium_view_.at("feedback").get<std::string>();const auto feedback=custom.empty()?stadium_feedback(q,stadium_view_.at("invalid_places").get<bool>()):custom;
|
||||
out+="<div class=\"stadium-draft-total\" style=\"top:"+scalar(total_top)+"dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_money(stadium_field(q,"cost"),*s.world))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:"+scalar(feedback_top)+"dp;\">"+esc(feedback)+"</p><nav class=\"stadium-draft-actions\" style=\"top:"+scalar(actions_top)+"dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(!q.value("can_build",false)||stadium_view_.at("invalid_places").get<bool>()?"disabled=\"disabled\"":""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
|
||||
const auto custom=stadium_view_.at("feedback").get<std::string>();const auto feedback=custom.empty()?stadium_offer_feedback(q,stadium_view_.at("invalid_places").get<bool>()):custom;
|
||||
out+="<div class=\"stadium-draft-total\" style=\"top:"+scalar(total_top)+"dp;\"><span>Gesamtbetrag:</span><span id=\"stadium-quote-total\">"+esc(stadium_cash(stadium_field(q,"cost")))+"</span></div><p id=\"stadium-draft-feedback\" style=\"top:"+scalar(feedback_top)+"dp;\">"+esc(feedback)+"</p><nav class=\"stadium-draft-actions\" style=\"top:"+scalar(actions_top)+"dp;\">"+btn("stadium-build","Bauen","stadium-dialog-action primary","id=\"stadium-build\" "+std::string(!q.value("can_build",false)||stadium_view_.at("invalid_places").get<bool>()?"disabled=\"disabled\"":""))+btn("stadium-cancel","Abbrechen","stadium-dialog-action","id=\"stadium-cancel\"")+"</nav></section></div>";
|
||||
return out;
|
||||
}
|
||||
@@ -1543,6 +1543,7 @@ public:
|
||||
#include "modern/ui/engine_files.inc"
|
||||
#include "modern/ui/engine_statistics.inc"
|
||||
#include "modern/ui/engine_toto.inc"
|
||||
#include "modern/ui/engine_stadium.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user