The scene under the pointer is framed and lit, the others step back, and under the picture stands what the scene does. The picture is the project's own; the page is left by any other marker of the book. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
528 lines
38 KiB
C++
528 lines
38 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
void App::engine_start(std::string label, std::function<EngineReply()> job, bool mutating) {
|
|
if (engine_busy_) return;
|
|
engine_base_dirty_ = engine_dirty_;
|
|
if (mutating) { engine_dirty_ = true; engine_fresh_ = false; }
|
|
engine_operation_ = std::move(label); engine_busy_ = true;
|
|
engine_job_ = std::async(std::launch::async, std::move(job)); refresh();
|
|
}
|
|
// Plays the next kickoff with the line-up and tactics of the desk; the ticker then shows
|
|
// the engine's recording of it. Answers to questions of the run travel in the payload.
|
|
void App::engine_kickoff() {
|
|
if (engine_busy_ || !engine_link_) return;
|
|
// A rehearsal first: a question of the run (a contract running out) is asked before the
|
|
// kickoff, never after a match the manager has watched and steered.
|
|
Json rehearsal = engine_advance_payload_, live = engine_advance_payload_;
|
|
rehearsal["dryRun"] = true; live["live"] = true;
|
|
const auto probe = engine_advance_command(engine_data_, editor::new_id("request:ui-"), rehearsal);
|
|
const auto command = engine_advance_command(engine_data_, editor::new_id("request:ui-"), live);
|
|
auto link = engine_link_;
|
|
const Json desk = engine_data_;
|
|
// The desk as it stands is kept beside the careers before every kickoff.
|
|
fs::path safety;
|
|
try { safety = engine_files_directory() / "Sicherung vor dem Anstoss.obs"; } catch (const std::exception &) {}
|
|
engine_start("Anstoß …", [link, probe, command, desk, safety] {
|
|
if (!safety.empty()) try {
|
|
std::error_code ignored;
|
|
fs::create_directories(safety.parent_path(), ignored);
|
|
const auto fresh = safety.parent_path() / "Sicherung vor dem Anstoss.neu.obs";
|
|
fs::remove(fresh, ignored);
|
|
link->save_copy(fresh);
|
|
fs::remove(safety, ignored);
|
|
fs::rename(fresh, safety, ignored);
|
|
} catch (const std::exception &) {} // a failed safety copy never stops the kickoff
|
|
auto response = link->command(probe);
|
|
if (response.value("messageType", "") != "command_result") {
|
|
response["advanceRefused"] = true;
|
|
return EngineReply{link, link->snapshot(), response, nullptr};
|
|
}
|
|
response = link->command(command);
|
|
if (response.value("messageType", "") != "command_result") {
|
|
response["advanceRefused"] = true;
|
|
return EngineReply{link, link->snapshot(), response, nullptr};
|
|
}
|
|
const auto state = link->read_live({{"kind", "fixture"}});
|
|
if (state.value("ok", false) && state.value("live", false)) {
|
|
// the kickoff stands after its first minute; the desk snapshot stays the one before it
|
|
response["liveState"] = state;
|
|
return EngineReply{link, desk, response, nullptr};
|
|
}
|
|
response["liveRecording"] = state;
|
|
response["postmatch"] = link->read({{"kind", "postmatch"}});
|
|
auto after = link->snapshot();
|
|
engine_attach_opening(*link, engine_season_id(desk), after, response);
|
|
return EngineReply{link, std::move(after), response, nullptr};
|
|
}, true);
|
|
}
|
|
// A contract runs out on the way to the next desk: the manager extends at the player's
|
|
// demand, lets him go, or returns to the desk to deal with it there.
|
|
void App::engine_expiry_ask(const Json &args) {
|
|
const std::string id = args.value("playerId", std::string());
|
|
if (id.empty()) return;
|
|
std::string name = id;
|
|
try {
|
|
for (const auto &p : engine_data_.at("squad").at("data").at("players"))
|
|
if (p.at("player").at("id") == id) name = p.at("player").at("name").get<std::string>();
|
|
} catch (const std::exception &) {}
|
|
int years = 0; Json salary;
|
|
const auto demands = args.value("demands", Json::array());
|
|
for (int option : {1, 0, 2, 3})
|
|
if (!years && demands.is_array() && size_t(option) < demands.size() && demands[size_t(option)].is_object()) { years = option + 1; salary = demands[size_t(option)]; }
|
|
engine_expiry_player_ = id;
|
|
if (years) {
|
|
confirmation("Der Vertrag von " + name + " läuft aus. Er fordert " + engine_price(salary) + " monatlich für " +
|
|
std::to_string(years) + (years == 1 ? " Jahr." : " Jahre.") + " Verlängern oder freigeben?",
|
|
[this, id, years, salary] {
|
|
engine_advance_payload_["contractExpiry"][id] = {{"action", "renew"}, {"years", years}, {"monthlySalary", salary}};
|
|
engine_kickoff();
|
|
});
|
|
popup_accept_ = "Verlängern";
|
|
} else {
|
|
confirmation("Der Vertrag von " + name + " läuft aus und der Spieler verlängert nicht. Freigeben und weiter?",
|
|
[this, id] { engine_advance_payload_["contractExpiry"][id] = {{"action", "release"}}; engine_kickoff(); });
|
|
popup_accept_ = "Freigeben";
|
|
return;
|
|
}
|
|
popup_extra_ = btn("engine-expiry-release", "Freigeben");
|
|
}
|
|
void App::engine_accept(EngineReply result) {
|
|
engine_fresh_ = true;
|
|
if (result.catalog) { world_ = std::move(result.catalog); bind_world(world_); }
|
|
engine_link_ = std::move(result.connection); engine_data_ = std::move(result.bundle);
|
|
engine_response_ = std::move(result.response);
|
|
if (engine_response_.value("messageType", "") == "command_result") {
|
|
engine_dirty_ = engine_base_dirty_ || engine_response_.at("newRevision") != engine_response_.at("previousRevision");
|
|
engine_notice_ = engine_text(engine_response_.at("feedback")) + (engine_dirty_ ? " · Änderungen noch nicht gespeichert." : "");
|
|
} else if (engine_response_.value("messageType", "") == "error") {
|
|
engine_dirty_ = engine_base_dirty_;
|
|
auto reason = engine_text(engine_response_.value("message", Json()));
|
|
if (reason.empty() || reason == "—") reason = engine_response_.value("code", "unknown_error");
|
|
engine_notice_ = "Änderung abgewiesen: " + reason;
|
|
} else if (engine_response_.value("messageType", "") == "saved") {
|
|
engine_dirty_ = false; engine_notice_ = "Spielstand als neue OBS-Datei gespeichert.";
|
|
if(engine_exit_after_save_){engine_exit_after_save_=false;closed_=true;}
|
|
} else if(engine_response_.value("messageType","")=="created"){engine_dirty_=true;engine_notice_="Neue Partie · Noch nicht gespeichert.";}
|
|
else if(engine_response_.value("messageType","")=="live_finished"){engine_dirty_=true;engine_notice_="Abpfiff · Änderungen noch nicht gespeichert.";}
|
|
else engine_notice_ = "Spielstand geladen.";
|
|
if (engine_response_.value("messageType", "") == "command_result") { advertising_selected_ = -1; advertising_offer_ = 0; }
|
|
engine_credit_ = engine_data_.value("credit", Json()); engine_credit_edits_ = Json::array();
|
|
engine_reports_sync();
|
|
engine_almanac_sync();
|
|
engine_ticket_bind();
|
|
engine_toto_poll();
|
|
engine_stadium_poll();
|
|
engine_transfer_sync();
|
|
engine_news_sync();
|
|
engine_balance_sync();
|
|
engine_indoor_sync();
|
|
engine_settings_sync();
|
|
engine_manager_sync();
|
|
engine_contracts_poll();
|
|
engine_calendar_sync();
|
|
engine_friendly_sync();
|
|
engine_sports_reset();
|
|
const auto &f = engine_data_.at("camps").at("data").at("focus");
|
|
engine_focus_ = {{"condition", f.at("condition")}, {"technique", f.at("technique")}, {"play", f.at("play")}};
|
|
if (engine_camp_.empty() && !engine_data_.at("camps").at("data").at("camps").empty())
|
|
engine_camp_ = engine_data_.at("camps").at("data").at("camps").front().at("id");
|
|
if (engine_response_.value("advanceRefused", false)) {
|
|
engine_response_.erase("advanceRefused");
|
|
Json args;
|
|
try { args = engine_response_.at("message").at("args"); } catch (const std::exception &) {}
|
|
if (engine_response_.value("code", "") == "decision_pending" && args.is_object() && args.value("decision", "") == "contract_expiry")
|
|
engine_expiry_ask(args);
|
|
}
|
|
if (engine_response_.contains("seasonOpening")) {
|
|
// a new season began: its draw is shown once the ticker is closed
|
|
const Json opening = engine_response_.at("seasonOpening");
|
|
engine_response_.erase("seasonOpening");
|
|
try {
|
|
auto state = engine_opening_projection(engine_data_, opening);
|
|
engine_opening_read_ = opening; engine_opening_state_ = std::move(state);
|
|
opening_due_ = 0; opening_io_blocked_ = false;
|
|
} catch (const std::exception &) {} // without a showable draw the desk simply continues
|
|
}
|
|
if (engine_response_.contains("liveState")) {
|
|
const Json state = engine_response_.at("liveState");
|
|
engine_response_.erase("liveState");
|
|
engine_advance_payload_ = Json::object();
|
|
engine_live_begin(state, engine_response_.value("newRevision", std::string()));
|
|
}
|
|
if (engine_response_.contains("liveRecording")) {
|
|
engine_postmatch_read_ = engine_response_.value("postmatch", Json());
|
|
engine_response_.erase("postmatch");
|
|
const Json recording = engine_response_.at("liveRecording");
|
|
engine_response_.erase("liveRecording");
|
|
engine_advance_payload_ = Json::object();
|
|
if (recording.value("ok", false)) engine_live_open(recording);
|
|
else engine_notice_ = "Weiter zum nächsten Termin · an diesem Tag gab es kein eigenes Spiel.";
|
|
}
|
|
}
|
|
void App::engine_poll() {
|
|
if (!engine_busy_ || engine_job_.wait_for(std::chrono::milliseconds(0)) != std::future_status::ready) return;
|
|
engine_busy_ = false;
|
|
try {
|
|
auto result = engine_job_.get();
|
|
validate_engine_desk(result.bundle);
|
|
if(result.response.value("messageType","")=="balance_preview"){engine_balance_preview(result);refresh();return;}
|
|
if(result.response.value("messageType","")=="toto_preview"){engine_toto_preview(result);refresh();return;}
|
|
if(result.response.value("messageType","")=="reports_preview"){engine_reports_poll(result);refresh();return;}
|
|
if(result.response.value("messageType","")=="almanac_preview"){engine_almanac_poll(result);refresh();return;}
|
|
if (result.response.value("messageType", "") == "friendly_preview") {
|
|
const auto &read = result.response.at("read");
|
|
if (read.value("messageType", "") == "error") {
|
|
planning_notice_ = engine_text(read.value("message", Json()));
|
|
if (planning_notice_.empty() || planning_notice_ == "—") planning_notice_ = "Dieses Freundschaftsspiel ist derzeit nicht verfügbar.";
|
|
planning_dialog_ = "friendly-error"; focus_after_render_ = "planning-close";
|
|
} else {
|
|
const auto quote = engine_friendly_projection(result.bundle,read,result.response.at("opponent"),result.response.at("home"));
|
|
engine_friendly_read_ = read; planning_dialog_ = "quote";
|
|
focus_after_render_ = quote.at("days").empty() ? "planning-close" : "friendly-quote-accept";
|
|
}
|
|
refresh(); return;
|
|
}
|
|
if (result.response.value("messageType", "") == "credit_preview") {
|
|
const auto &read = result.response.at("read");
|
|
if (read.value("messageType", "") == "error") engine_notice_ = "Kreditvorschau abgewiesen: " + read.value("code", "unknown_error");
|
|
else {
|
|
(void)engine_credit_projection(result.bundle, read);
|
|
engine_credit_ = read; engine_credit_edits_ = result.response.at("edits");
|
|
engine_notice_ = "Kreditvorschau berechnet · Noch keine Buchung.";
|
|
}
|
|
refresh(); return;
|
|
}
|
|
engine_accept(std::move(result));
|
|
} catch (const std::exception &e) { engine_notice_ = e.what(); if(engine_exit_after_save_){engine_exit_after_save_=false;message("Der Spielstand konnte nicht gespeichert werden: "+std::string(e.what()));} }
|
|
refresh();
|
|
}
|
|
void App::engine_frame() {
|
|
engine_poll();
|
|
const bool rendered = needs_render_;
|
|
if(needs_render_&&menu_=="news"){last_rendered_menu_=menu_;news_before_render();}
|
|
if (needs_render_) engine_render();
|
|
engine_sports_update();
|
|
if (ticket_) ticket_->update();
|
|
render_popup(); context_->Update();
|
|
if (scene_ == "live" && live_.available()) {
|
|
if (rendered) { live_after_render(); context_->Update(); }
|
|
live_update_parts();
|
|
}
|
|
if(center_fixture_columns())context_->Update();
|
|
if (menu_ == "settings") { settings_after_render(); context_->Update(); }
|
|
if (rendered && menu_ == "friendlies") if (auto *list = element("friendly-opponents")) list->SetScrollTop(engine_friendly_scroll_);
|
|
if (menu_ == "contracts" && engine_contract_scroll_) {
|
|
if (auto *roster = element("contracts-roster-scroll")) roster->SetScrollTop(*engine_contract_scroll_);
|
|
engine_contract_scroll_.reset();
|
|
}
|
|
if(rendered&&(menu_=="scorers"||menu_=="fairplay")){rankings_restore_scroll();context_->Update();}
|
|
if(menu_=="statistics")statistics_restore_scroll();
|
|
if(menu_=="transfer")transfer_restore_scroll();
|
|
if(menu_=="news")news_after_render();
|
|
if(rendered&&files_native_){files_after_render();context_->Update();}
|
|
if (center_selects(*doc_)) context_->Update();
|
|
if (menu_ == "lineup" && lineup_roster_scroll_) {
|
|
if (auto *roster = element("lineup-roster-scroll")) roster->SetScrollTop(*lineup_roster_scroll_);
|
|
lineup_roster_scroll_.reset();
|
|
}
|
|
if (!engine_busy_ && popup_.empty() && !focus_after_render_.empty()) {
|
|
if (auto *node = element(focus_after_render_)) {
|
|
node->Focus(keyboard_navigation_);
|
|
if(node->GetId().starts_with("report-club-")||node->GetId().starts_with("report-option-"))node->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
|
if(menu_=="almanac"&&node->GetId().starts_with("alm-match-")) {
|
|
node->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
|
if(auto *list=element("alm-day-list"))list->SetScrollLeft(0);
|
|
}
|
|
}
|
|
focus_after_render_.clear();
|
|
}
|
|
if (amount_select_all_) {
|
|
if (auto *input = dynamic_cast<Rml::ElementFormControlInput *>(element("calculator-value"))) input->Select();
|
|
amount_select_all_ = false;
|
|
}
|
|
if (amount_caret_end_) {
|
|
if (auto *input = dynamic_cast<Rml::ElementFormControlInput *>(element("calculator-value"))) input->SetSelectionRange(int(input->GetValue().size()), int(input->GetValue().size()));
|
|
amount_caret_end_ = false;
|
|
}
|
|
renderer_.Clear(); renderer_.BeginFrame(); context_->Render(); renderer_.EndFrame(); video_.present(); dirty_ = false;
|
|
}
|
|
void App::engine_save() {
|
|
if(menu_=="balance"&&!engine_balance_edits_.empty()){engine_balance_close("save");return;}
|
|
if (engine_busy_ || engine_files_busy_ || !engine_link_) return;
|
|
if(config_.file_export.empty()){engine_files_begin("save");return;}
|
|
auto output = config_.file_export;
|
|
if (output.empty()) {
|
|
NFD::Guard guard; NFD::UniquePath chosen;
|
|
const nfdfilteritem_t filters[] = {{"Dreierpack-Spielstand", "obs"}};
|
|
const auto result = NFD::SaveDialog(chosen, filters, 1, nullptr, "openbmh-career.obs");
|
|
if (result == NFD_CANCEL) {engine_exit_after_save_=false;return;}
|
|
if (result != NFD_OKAY) throw editor::Error("Die Dateiauswahl konnte nicht geöffnet werden.");
|
|
output = editor::path(chosen.get());
|
|
}
|
|
auto link = engine_link_;
|
|
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(menu_=="balance"&&!engine_balance_edits_.empty()){engine_balance_close("quit");return;}
|
|
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;});
|
|
popup_accept_="Ohne Speichern beenden";
|
|
popup_extra_=btn("engine-save-exit","Speichern und beenden","primary","id=\"engine-save-exit\"");
|
|
}
|
|
else closed_ = true;
|
|
}
|
|
void App::engine_event(Rml::Event &event) {
|
|
const auto type = event.GetType(); auto *target = event.GetTargetElement();
|
|
if (type == "keydown") keyboard_navigation_ = true;
|
|
if (type == "mousedown") keyboard_navigation_ = false;
|
|
if (balance_simulation_event(event)) return;
|
|
// the right mouse button leaves an opened month of the calendar
|
|
if (menu_ == "calendar" && calendar_month_ >= 0 && popup_.empty() &&
|
|
(type == "contextmenu" || (type == "mousedown" && event.GetParameter<int>("button", 0) == 1))) {
|
|
if (type == "mousedown") calendar_open_month(-1);
|
|
return;
|
|
}
|
|
if (scene_ == "live" && live_.available()) {
|
|
// The ticker of a played kickoff: only its own controls, nothing of the desk beneath.
|
|
if (live_event(event)) return;
|
|
if (type == "click")
|
|
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
|
if (n->HasAttribute("data-action") && !n->HasAttribute("disabled")) {
|
|
live_action(n->GetAttribute<Rml::String>("data-action", ""), n); break;
|
|
}
|
|
event.StopImmediatePropagation(); return;
|
|
}
|
|
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
|
|
if (node->GetId() == "native-ticket-layer") return; // owned by the compact control
|
|
if (ticket_ && ticket_->is_open()) return;
|
|
if (amount_event(event)) return;
|
|
// the manager's page is left by any other control of the notebook
|
|
if(menu_=="newplayer"&&scene_=="managerhub"&&popup_.empty()&&type=="click"&&!engine_busy_&&!career_resign_open_&&!career_game_end_&&engine_manager_value_.is_object()&&engine_manager_value_.value("ended",false)!=true)
|
|
for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->HasAttribute("data-action")&&!n->HasAttribute("disabled")) {
|
|
const auto action=n->GetAttribute<Rml::String>("data-action","");
|
|
if(!action.starts_with("career-")&&action!="close"){scene_="engine";menu_.clear();}
|
|
break;
|
|
}
|
|
if(menu_=="newplayer"&&popup_.empty()) {
|
|
if(engine_busy_){event.StopImmediatePropagation();return;}
|
|
if(scene_=="manager") {
|
|
if(entry_event(event))return;
|
|
if(type=="change"&&(entry_change(target)||entry_input(target)))return;
|
|
if(type=="input"&&entry_input(target))return;
|
|
} else if(career_event(event))return;
|
|
if(type=="keydown") {
|
|
const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
|
|
if(key==Rml::Input::KI_RETURN||key==Rml::Input::KI_SPACE)for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->GetTagName()=="button"&&!n->HasAttribute("disabled")){n->DispatchEvent("click",{});event.StopImmediatePropagation();return;}
|
|
}
|
|
if(type=="click")for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->HasAttribute("data-action")&&!n->HasAttribute("disabled")){const auto action=n->GetAttribute<Rml::String>("data-action","");if(scene_=="manager")entry_action(action,n);else career_action(action,n);event.StopImmediatePropagation();return;}
|
|
return;
|
|
}
|
|
if (menu_ == "settings") {
|
|
if (engine_busy_) { event.StopImmediatePropagation(); return; }
|
|
if (settings_event(event)) return;
|
|
}
|
|
if (!engine_busy_ && bank_event(event)) return;
|
|
if (!engine_busy_ && advertising_event(event)) return;
|
|
if (!engine_busy_ && popup_.empty() && contracts_event(event)) return;
|
|
if(engine_opening_active()&&menu_.empty()&&popup_.empty()) {
|
|
if(type=="keydown") {const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
|
|
if(key==Rml::Input::KI_TAB){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,".opening-actions button");std::erase_if(nodes,[](auto *n){return n->HasAttribute("disabled");});if(!nodes.empty()){const auto it=std::find(nodes.begin(),nodes.end(),context_->GetFocusElement());const int i=it==nodes.end()?-1:int(it-nodes.begin()),n=int(nodes.size());nodes[size_t((i+n+(event.GetParameter<int>("shift_key",0)?-1:1))%n)]->Focus(true);}event.StopImmediatePropagation();return;}
|
|
if(key==Rml::Input::KI_RETURN||key==Rml::Input::KI_SPACE){for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->GetTagName()=="button"&&!n->HasAttribute("disabled")){n->DispatchEvent("click",{});break;}}}
|
|
if(type=="click")for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->HasAttribute("data-action")){opening_action(n->GetAttribute<Rml::String>("data-action",""),n);break;}
|
|
event.StopImmediatePropagation();return;
|
|
}
|
|
if(files_native_&&files_event(event))return;
|
|
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(menu_=="transfer"&&transfer_event(event))return;
|
|
if(menu_=="achievements"&&career_report_event(event))return;
|
|
if(menu_=="news"&&news_event(event))return;
|
|
if(menu_=="balance"&&!engine_busy_&&popup_.empty()&&finance_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;
|
|
if (engine_sports_event(event)) return;
|
|
Rml::ElementFormControl *range = nullptr;
|
|
for (auto *node = target; node && node != doc_; node = node->GetParentNode())
|
|
if (node->GetId().starts_with("camp-focus-") && !node->HasAttribute("disabled")) {
|
|
range = dynamic_cast<Rml::ElementFormControl *>(node); break;
|
|
}
|
|
if (popup_.empty() && !engine_busy_ && range && type == "mouseup") {
|
|
focus_after_render_ = range->GetId(); dirty_ = true;
|
|
}
|
|
if (popup_.empty() && !engine_busy_ && range && type == "keydown") {
|
|
const auto key = Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0));
|
|
if (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 int index = range->GetAttribute<int>("data-id", -1);
|
|
if (index >= 0 && index < 3) {
|
|
const int value = key == Rml::Input::KI_HOME ? 0 : key == Rml::Input::KI_END ? 15 : std::clamp(std::stoi(range->GetValue()) + (key == Rml::Input::KI_LEFT || key == Rml::Input::KI_DOWN ? -1 : 1), 0, 15);
|
|
range->SetValue(std::to_string(value));
|
|
engine_focus_[std::array<const char *, 3>{"condition", "technique", "play"}[size_t(index)]] = value;
|
|
element("camp-value-" + std::to_string(index))->SetInnerRML(std::to_string(value) + " / 15");
|
|
element("camp-value-3")->SetInnerRML("—"); element("camp-focus-3")->SetProperty("visibility", "hidden");
|
|
dirty_ = true; event.StopImmediatePropagation(); return;
|
|
}
|
|
}
|
|
}
|
|
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) {
|
|
if (menu_ == "almanac" && engine_busy_) { event.StopImmediatePropagation(); return; }
|
|
if (!popup_.empty()) { popup_.clear(); reset_popup(); engine_files_pending_load_.reset(); engine_exit_after_save_=false; dirty_ = true; }
|
|
else if (!engine_busy_ && !engine_player_.empty()) { focus_after_render_ = "lineup-detail-" + engine_player_ + "-0"; engine_player_.clear(); refresh(); }
|
|
else if (!engine_busy_ && menu_ == "almanac") engine_almanac_action("alm-back",nullptr);
|
|
else if(!engine_busy_&&menu_=="balance"){engine_balance_close("menu");}
|
|
else if (!engine_busy_ && !menu_.empty()) { if (menu_ == "training" || menu_ == "tactics") engine_sports_reset(); if(menu_=="scorers"||menu_=="fairplay")rankings_remember_scroll(); menu_.clear(); refresh(); }
|
|
else engine_quit();
|
|
event.StopImmediatePropagation(); return;
|
|
}
|
|
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_TAB) {
|
|
auto *root = !popup_.empty() ? element("popup") : !engine_player_.empty() ? element("engine-player-dialog") : !menu_.empty() ? doc_->QuerySelector(".window") : element("canvas"); Rml::ElementList controls;
|
|
if (!root) return;
|
|
root->QuerySelectorAll(controls, "button,input,[data-engine-route]");
|
|
controls.erase(std::remove_if(controls.begin(), controls.end(), [](auto *node) { return !node->IsVisible(true) || node->HasAttribute("disabled"); }), controls.end());
|
|
if (!controls.empty()) {
|
|
const auto found = std::find(controls.begin(), controls.end(), context_->GetFocusElement());
|
|
const int index = found == controls.end() ? -1 : int(found - controls.begin());
|
|
auto *next=controls[size_t((index + int(controls.size()) + (event.GetParameter<int>("shift_key", 0) ? -1 : 1)) % int(controls.size()))];
|
|
next->Focus(true);
|
|
if(next->GetId().starts_with("report-club-"))next->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
|
if(menu_=="almanac"&&next->GetId().starts_with("alm-match-")) {
|
|
next->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
|
if(auto *list=element("alm-day-list"))list->SetScrollLeft(0);
|
|
}
|
|
}
|
|
event.StopImmediatePropagation(); return;
|
|
}
|
|
if(type=="keydown"&&popup_.empty()&&(menu_.empty()||menu_=="balance")&&!engine_busy_&&!engine_files_busy_) {
|
|
const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
|
|
if(event.GetParameter<int>("ctrl_key",0)&&(key==Rml::Input::KI_S||key==Rml::Input::KI_O)){engine_files_begin(key==Rml::Input::KI_S?"save":"load");event.StopImmediatePropagation();return;}
|
|
}
|
|
if (engine_busy_) return;
|
|
if ((type == "input" || type == "change") && menu_ == "camp" && popup_.empty() && target->GetId().starts_with("camp-focus-")) {
|
|
const int index = target->GetAttribute<int>("data-id", -1);
|
|
if (index < 0 || index > 2) return;
|
|
const int value = std::stoi(dynamic_cast<Rml::ElementFormControl *>(target)->GetValue());
|
|
if (value < 0 || value > 15) return;
|
|
engine_focus_[std::array<const char *, 3>{"condition", "technique", "play"}[size_t(index)]] = value;
|
|
element("camp-value-" + std::to_string(index))->SetInnerRML(std::to_string(value) + " / 15");
|
|
element("camp-value-3")->SetInnerRML("—");
|
|
element("camp-focus-3")->SetProperty("visibility", "hidden"); dirty_ = true; return;
|
|
}
|
|
if(type=="keydown") {
|
|
const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
|
|
if(key==Rml::Input::KI_RETURN||key==Rml::Input::KI_SPACE) {
|
|
for(auto *node=target;node&&node!=doc_;node=node->GetParentNode())if(node->GetTagName()=="button"||node->HasAttribute("data-engine-route")) {
|
|
if(!node->HasAttribute("disabled"))node->DispatchEvent("click",{});
|
|
event.StopImmediatePropagation();return;
|
|
}
|
|
}
|
|
}
|
|
if (type != "click") return;
|
|
for (auto *node = target; node && node != doc_; node = node->GetParentNode()) {
|
|
if (!node->HasAttribute("data-action") || node->HasAttribute("disabled")) continue;
|
|
const auto action = node->GetAttribute<Rml::String>("data-action", ""), id = node->GetAttribute<Rml::String>("data-id", "");
|
|
if (!popup_.empty()) {
|
|
if(action=="balance-discard"){engine_balance_action(action,node);return;}
|
|
if (action == "engine-expiry-release") {
|
|
const auto player = engine_expiry_player_;
|
|
popup_.clear(); reset_popup(); confirm_ = {}; dirty_ = true;
|
|
if (!player.empty()) { engine_advance_payload_["contractExpiry"][player] = {{"action", "release"}}; engine_kickoff(); }
|
|
return;
|
|
}
|
|
if (action == "popup-close") { popup_.clear(); reset_popup(); engine_files_pending_load_.reset(); engine_exit_after_save_=false; dirty_ = true; }
|
|
if(action=="files-save-before-load"){const auto pending=engine_files_pending_load_;reset_popup();popup_.clear();engine_files_begin("save");engine_files_pending_load_=pending;return;}
|
|
if(action=="engine-save-exit"){reset_popup();popup_.clear();engine_exit_after_save_=true;try{engine_save();}catch(const std::exception &e){engine_exit_after_save_=false;message(e.what());}return;}
|
|
if (action == "popup-confirm") { auto callback=std::move(confirm_);auto text_callback=std::move(text_accept_);const auto text=field("popup-text");popup_.clear();reset_popup();dirty_=true;if(text_callback)text_callback(text);else if(callback)callback(); }
|
|
return;
|
|
}
|
|
if (action == "engine-widget-warning" && menu_.empty() && !engine_busy_) {
|
|
const auto rows = engine_widgets_projection(engine_data_).at("warnings");
|
|
std::string text;
|
|
for (size_t i = 0; i < rows.size(); ++i) {
|
|
if (id != std::to_string(i) && id != "3,4" && id != "5,6") continue;
|
|
if ((id == "3,4" && i != 3 && i != 4) || (id == "5,6" && i != 5 && i != 6)) continue;
|
|
const auto &row = rows[i];
|
|
if (!text.empty()) text += "\n";
|
|
text += row.at("name").get<std::string>() + ": ";
|
|
text += row.at("attention").is_null() ? "Nicht bekannt." : row.at("attention") == true
|
|
? row.at("description").get<std::string>() : "Kein Hinweis.";
|
|
}
|
|
if (!text.empty()) message(text);
|
|
return;
|
|
}
|
|
if(files_native_&&files_action(action,node))return;
|
|
if(action.starts_with("rankings-")&&menu_=="scorers"){rankings_action(action,node);return;}
|
|
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(menu_=="transfer"&&transfer_action(action,node))return;
|
|
if(menu_=="achievements"&&career_report_action(action,node))return;
|
|
if(menu_=="news"&&dispatch_news(action,node))return;
|
|
if(menu_=="balance"&&engine_balance_action(action,node))return;
|
|
if(menu_=="indoor"&&indoor_action(action,node))return;
|
|
if(menu_=="settings"&&settings_action(action,node))return;
|
|
if(menu_=="settings"&&action=="close"){reset_settings();menu_.clear();refresh();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;
|
|
if (engine_calendar_action(action, node)) return;
|
|
if (contracts_action(action, node)) return;
|
|
if (environment_action(action, node)) return;
|
|
if (advertising_action(action, node)) return;
|
|
if (bank_action(action, node)) return;
|
|
if (engine_sports_action(action, id, node)) return;
|
|
if (engine_lineup_action(action, id, node)) return;
|
|
if (action == "close") { if(menu_=="scorers"||menu_=="fairplay")rankings_remember_scroll(); menu_.clear(); refresh(); }
|
|
else if (action == "engine-ticket" && engine_fresh_) {
|
|
const auto price = engine_ticket_projection(engine_data_);
|
|
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=="newplayer"){menu_=id;scene_="managerhub";career_resign_open_=career_game_end_=false;engine_manager_context_=engine_data_.at("desktop").at("meta");focus_after_render_="career-add";refresh();}
|
|
else if(action=="engine-open"&&id=="settings"){reset_settings();menu_=id;refresh();}
|
|
else if(action=="engine-open"&&id=="indoor"){menu_=id;engine_reports_sync();refresh();}
|
|
else if(action=="engine-open"&&id=="balance"){menu_=id;balance_future_=false;engine_balance_feedback_="Gebuchte Saisonwerte.";refresh();}
|
|
else if(action=="engine-open"&&id=="news"){menu_=id;news_dialog_.clear();refresh();}
|
|
else if(action=="engine-open"&&id=="achievements"){menu_=id;career_view_=Json::object();refresh();}
|
|
else if(action=="engine-open"&&id=="transfer"){menu_=id;transfer_view_=Json::object();transfer_dialog_.clear();engine_transfer_sync();refresh();}
|
|
else if(action=="engine-open"&&(id=="stadium"||id=="periphery")){menu_="stadium";stadium_view_=Json::object();stadium_view_defaults(stadium_view_);if(id=="periphery")stadium_view_["view"]="panorama";stadium_focus_.clear();engine_stadium_sync();refresh();}
|
|
else if(action=="engine-open"&&id=="toto"){menu_=id;engine_toto_sync();refresh();}
|
|
else if(action=="engine-open"&&(id=="statistics"||id.starts_with("stat-"))){statistics_open(id);}
|
|
else if(action=="engine-open"&&id=="load"){engine_files_begin("load");}
|
|
else if(action=="engine-open"&&id=="scorers"){menu_=id;engine_reports_sync();engine_rankings_load(engine_rankings_state_.at("league"),engine_rankings_state_.at("scope"));}
|
|
else if(action=="engine-open"&&id=="fairplay"){menu_=id;engine_reports_sync();engine_fairplay_load();}
|
|
else if(action=="engine-open"&&id=="other"){menu_=id;engine_reports_sync();engine_other_load(engine_other_value_.is_object()?engine_other_value_.at("viewId").get<std::string>():"",engine_other_value_.is_object()?engine_other_value_.at("round").get<int>():0);}
|
|
else if(action=="engine-open"&&id=="league"){menu_=id;engine_reports_sync();const auto league=engine_reports_state_.at("league").get<std::string>();engine_fixtures_load(league,engine_fixtures_value_.is_object()&&engine_fixtures_value_.at("leagueId")==league?engine_fixtures_value_.at("round").get<int>():0);}
|
|
else if(action=="engine-open"&&(id=="tables"||id=="strengths")){menu_=id;engine_reports_sync();engine_reports_load(engine_reports_state_.at("league"),engine_reports_state_.at("filter"));}
|
|
else if (action == "engine-open" && id == "almanac") { menu_=id;engine_almanac_sync();engine_almanac_load({{"kind","index"}}); }
|
|
else if (action == "engine-open" && id == "friendlies") { menu_ = id; planning_dialog_.clear(); engine_friendly_sync(); refresh(); }
|
|
else if (action == "engine-open" && (id == "calendar" || id == "postpone")) { menu_ = id; engine_move_id_.clear(); calendar_month_ = -1; calendar_anim_.clear(); engine_calendar_sync(); refresh(); }
|
|
else if (action == "engine-open" && id == "contracts") { menu_ = id; engine_contracts_clear(false); contracts_player_.clear(); engine_contract_scroll_ = 0.f; refresh(); }
|
|
else if (action == "engine-open" && id == "bank") { bank_view_ = "entrance"; bank_hint_.clear(); menu_ = "bank"; refresh(); }
|
|
else if (action == "engine-open" && id == "save") engine_save();
|
|
else if (action == "engine-open" && (id == "training" || id == "tactics")) { engine_sports_reset(); menu_ = id; refresh(); }
|
|
else if (action == "engine-open" && id == "lineup") { menu_ = "lineup"; lineup_selected_.clear(); lineup_reset_scroll_ = true; refresh(); }
|
|
else if (action == "engine-open" && id == "kickoff" && engine_fresh_) engine_kickoff();
|
|
else if (action == "engine-open" && id == "camp") { menu_ = "camp"; refresh(); }
|
|
else if (action == "camp-region") { selections_["camp-region"] = id; refresh(); }
|
|
else if (action == "camp-select") { engine_camp_ = id; refresh(); }
|
|
else if (action == "camp-remember" && engine_fresh_) {
|
|
const auto command = engine_camp_command(engine_data_, engine_camp_, engine_focus_, editor::new_id("request:ui-"));
|
|
const auto &camps = engine_data_.at("camps").at("data").at("camps");
|
|
const auto chosen = std::find_if(camps.begin(), camps.end(), [&](const auto &camp) { return camp.at("id") == engine_camp_; });
|
|
confirmation(engine_text(chosen->at("name")) + " für " + engine_price(chosen->at("quote").at("total")) + " verbindlich buchen?", [this, command] {
|
|
auto link = engine_link_;
|
|
engine_start("Trainingslager wird gebucht …", [link, command] { auto response = link->command(command); return EngineReply{link, link->snapshot(), response, nullptr}; }, true);
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
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_},
|
|
{"manager_value",engine_manager_value_},{"manager_context",engine_manager_context_},{"manager_operation",engine_manager_operation_},{"settings_value",engine_settings_value_},{"settings_context",engine_settings_context_},{"indoor_value",engine_indoor_value_},{"balance_future",engine_balance_future_},{"balance_edits",engine_balance_edits_},{"balance_view_future",balance_future_},{"news_error",engine_news_error_},{"news_value",engine_news_value_},{"news_view",news_view_},{"news_undo",engine_news_undo_},{"achievements_value",engine_mode_&&engine_data_.value("achievements",Json()).value("messageType","")=="snapshot"?achievements_data(career_view_.value("page",0)):Json()},{"career_view",career_view_},{"transfer_value",engine_transfer_value_},{"transfer_filters",engine_transfer_filters_},{"transfer_draft",transfer_draft_},{"transfer_view",transfer_view_},{"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_}};
|
|
}
|