Bind the transfer market to world-relative Modern data (by Codex)
This commit is contained in:
1 parent
e559e84a69
commit
1e88304019
23 files changed
+1230
-76
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 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)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_statistics.cpp engine_toto.cpp engine_stadium.cpp engine_transfer.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 stadium_projection)
|
||||
foreach(component career_reports rankings career_files statistics_projection toto_projection stadium_projection transfer_projection)
|
||||
add_executable(modern_${component}_tests ../../../tests/modern_${component}_tests.cpp)
|
||||
target_link_libraries(modern_${component}_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -17,7 +17,7 @@ Json from_engine(const cli::Json &v) { return Json::parse(cli::dump_json(v)); }
|
||||
namespace {
|
||||
Json session_snapshot(modern::app::ModernSession &session,uint64_t revision) {
|
||||
Json bundle=Json::object();
|
||||
for(const auto *kind:{"session","desktop","camps","squad","lineup","tactics","training","bank","stadium","credit","environment","advertising","contracts","friendly-plan","toto"})bundle[kind]=from_engine(session.ui_read(cli::Json::Object{{"kind",kind}},revision));
|
||||
for(const auto *kind:{"session","desktop","camps","squad","lineup","tactics","training","bank","stadium","credit","environment","advertising","contracts","friendly-plan","toto","transfer"})bundle[kind]=from_engine(session.ui_read(cli::Json::Object{{"kind",kind}},revision));
|
||||
validate_engine_desk(bundle);const auto &season=bundle.at("desktop").at("meta").at("season");
|
||||
bundle["calendar"]=from_engine(session.ui_read(cli::Json::Object{{"kind","calendar"},{"from",season.at("startDate").get<std::string>()},{"until",season.at("endDate").get<std::string>()}},revision));
|
||||
bundle["scheduling"]=from_engine(session.ui_read(cli::Json::Object{{"kind","scheduling"}},revision));return bundle;
|
||||
|
||||
@@ -72,6 +72,10 @@ Json engine_toto_command(const Json &bundle,const Json "e,const std::string
|
||||
|
||||
Json engine_statistics_projection(const Json &bundle,const Json &read);
|
||||
|
||||
Json engine_transfer_filters();
|
||||
Json engine_transfer_projection(const Json &,const Json &);
|
||||
Json engine_transfer_command(const Json &,const Json &,const std::string &);
|
||||
|
||||
Json engine_opening_projection(const Json &bundle,const Json &read);
|
||||
|
||||
// Single-session facade. Its owner serializes all calls on a background worker.
|
||||
|
||||
@@ -31,6 +31,7 @@ void App::engine_accept(EngineReply result) {
|
||||
engine_ticket_bind();
|
||||
engine_toto_poll();
|
||||
engine_stadium_poll();
|
||||
engine_transfer_sync();
|
||||
engine_contracts_poll();
|
||||
engine_calendar_sync();
|
||||
engine_friendly_sync();
|
||||
@@ -91,6 +92,7 @@ void App::engine_frame() {
|
||||
}
|
||||
if(rendered&&(menu_=="scorers"||menu_=="fairplay")){rankings_restore_scroll();context_->Update();}
|
||||
if(menu_=="statistics")statistics_restore_scroll();
|
||||
if(menu_=="transfer")transfer_restore_scroll();
|
||||
if(rendered&&files_native_){files_after_render();context_->Update();}
|
||||
if (center_selects(*doc_)) context_->Update();
|
||||
if (menu_ == "lineup" && lineup_roster_scroll_) {
|
||||
@@ -166,6 +168,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
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(!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;
|
||||
@@ -260,6 +263,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
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 (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;
|
||||
@@ -276,6 +280,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=="transfer"){menu_=id;transfer_view_=Json::object();transfer_dialog_.clear();engine_transfer_sync();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();}
|
||||
@@ -310,5 +315,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_}, {"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_}};
|
||||
{"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_}};
|
||||
}
|
||||
@@ -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=="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());
|
||||
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=="transfer"&&engine_fresh_&&engine_transfer_value_.is_object()) || (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_=="transfer")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Transfers",render_transfer())+"</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>";
|
||||
@@ -176,6 +177,7 @@ void App::engine_render() {
|
||||
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(menu_=="transfer"&&!transfer_dialog_.empty()){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,".transfer-overview button,.transfer-overview input,#window-close");for(auto*n:nodes){n->SetAttribute("disabled",true);n->SetProperty("pointer-events","none");}if(transfer_dialog_=="search"){for(auto*id:{"transfer-criterion-foot","transfer-criterion-type","transfer-search-trait-0","transfer-search-trait-1","transfer-search-trait-2"})if(auto*n=element(id))n->SetAttribute("disabled",true);}}
|
||||
if (engine_busy_) {
|
||||
Rml::ElementList controls; doc_->QuerySelectorAll(controls, "#canvas button,#canvas input");
|
||||
for (auto *node : controls) node->SetAttribute("disabled", true);
|
||||
|
||||
@@ -126,3 +126,10 @@
|
||||
void engine_stadium_send(const Json &,const std::string &);
|
||||
bool engine_stadium_action(const std::string &,Rml::Element *);
|
||||
bool engine_stadium_event(Rml::Event &);
|
||||
|
||||
Json engine_transfer_context_,engine_transfer_value_,engine_transfer_filters_=engine_transfer_filters();
|
||||
bool engine_transfer_submitting_=false;
|
||||
void engine_transfer_sync();
|
||||
Json transfer_data() const;
|
||||
std::string transfer_money(const Json &) const;
|
||||
bool engine_transfer_action(const std::string &,Rml::Element *);
|
||||
@@ -0,0 +1,235 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
void check(bool yes, const char *message) {
|
||||
if (!yes)
|
||||
throw editor::Error(message);
|
||||
}
|
||||
const Json &read(const Json &b) {
|
||||
validate_engine_desk(b);
|
||||
const auto &r = b.at("transfer"), &m = b.at("desktop").at("meta");
|
||||
check(r.value("messageType", "") == "snapshot" &&
|
||||
r.at("data").value("kind", "") == "transfer",
|
||||
"Transfermarkt nicht verfügbar.");
|
||||
for (const auto *key : {"contractVersion", "careerId", "worldId",
|
||||
"worldRevision", "stateRevision", "scope"})
|
||||
check(r.at("meta").at(key) == m.at(key),
|
||||
"Der Transferkontext hat sich geändert.");
|
||||
check(m.at("scope").at("role") == "club" &&
|
||||
r.at("data").at("teamId") == m.at("scope").at("teamId"),
|
||||
"Transfers gehören einer anderen Mannschaft.");
|
||||
return r.at("data");
|
||||
}
|
||||
Json row(const Json &p, const Json &club, bool own) {
|
||||
const auto &d = p.at("details");
|
||||
Json r = {{"id", p.at("playerId")},
|
||||
{"name", d.at("name")},
|
||||
{"club", club.is_string() ? club : Json("")},
|
||||
{"own", own},
|
||||
{"age", p.at("age")},
|
||||
{"position", p.at("position")},
|
||||
{"strength", p.at("strength")},
|
||||
{"nation", d.at("nationId")},
|
||||
{"photo", d.at("photoAssetId")},
|
||||
{"skills", d.at("skills")},
|
||||
{"condition", d.at("condition")},
|
||||
{"technique", d.at("technique")},
|
||||
{"form", d.at("form")},
|
||||
{"fee", nullptr},
|
||||
{"salary", nullptr},
|
||||
{"foot", nullptr},
|
||||
{"type", nullptr},
|
||||
{"nation_name", ""},
|
||||
{"games", nullptr},
|
||||
{"goals", nullptr},
|
||||
{"assists", nullptr},
|
||||
{"league_games", nullptr},
|
||||
{"cup_games", nullptr},
|
||||
{"europe_games", nullptr}};
|
||||
return r;
|
||||
}
|
||||
std::string folded(std::string s) {
|
||||
for (size_t i = 0; i < s.size(); ++i) {
|
||||
auto &c = s[i];
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c = char(c - 'A' + 'a');
|
||||
else if (static_cast<unsigned char>(c) == 0xc3 && i + 1 < s.size()) {
|
||||
auto &next = s[++i];
|
||||
const auto n = static_cast<unsigned char>(next);
|
||||
if (n >= 0x80 && n <= 0x9e && n != 0x97)
|
||||
next = char(n + 0x20);
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
} // namespace
|
||||
Json engine_transfer_filters() {
|
||||
return {{"query", ""},
|
||||
{"positions", 15},
|
||||
{"criteria",
|
||||
{{"age_min", 16},
|
||||
{"age_max", 47},
|
||||
{"strength_min", 0},
|
||||
{"strength_max", 100},
|
||||
{"traits", 7},
|
||||
{"foot", 0},
|
||||
{"type", 0},
|
||||
{"price_max", 9999999900LL}}}};
|
||||
}
|
||||
Json engine_transfer_projection(const Json &b, const Json &filters) {
|
||||
const auto &d = read(b);
|
||||
check(filters.is_object() && filters.at("query").is_string() &&
|
||||
filters.at("positions").is_number_integer(),
|
||||
"Ungültiger Suchfilter.");
|
||||
const int positions = filters.at("positions");
|
||||
check(positions > 0 && positions <= 15, "Ungültiger Positionsfilter.");
|
||||
Json own = Json::array(), market = Json::array(), orders = Json::array(),
|
||||
listed = Json::array();
|
||||
std::set<std::string> ids, listing_ids;
|
||||
for (const auto &p : d.at("squad")) {
|
||||
check(ids.insert(p.at("playerId").get<std::string>()).second,
|
||||
"Doppelter Kaderspieler.");
|
||||
auto r = row(p, d.at("teamId"), true);
|
||||
if (p.at("listed") == true)
|
||||
listed.push_back(p.at("playerId"));
|
||||
own.push_back(std::move(r));
|
||||
}
|
||||
const auto &c = filters.at("criteria");
|
||||
for (const auto &p : d.at("listings")) {
|
||||
check(listing_ids.insert(p.at("id").get<std::string>()).second,
|
||||
"Doppelter Listenplatz.");
|
||||
auto r = row(p, p.at("sellerId"), p.at("ownListing"));
|
||||
r["listing"] = p.at("id");
|
||||
r["fee"] = engine_money_minor(p.at("askingFee"));
|
||||
r["offers"] = p.at("offers");
|
||||
r["bid"] = p.at("ownBid");
|
||||
r["salary_reference"] = engine_money_minor(p.at("salaryReference"));
|
||||
r["salary_percent"] = p.at("salaryDemandPercent");
|
||||
r["seller_name"] = p.at("seller");
|
||||
r["loan_allowed"] = p.at("loanAvailable");
|
||||
r["terms"] = p.at("offerTerms");
|
||||
if (r.at("own") == true)
|
||||
for (auto &member : own)
|
||||
if (member.at("id") == r.at("id")) {
|
||||
member["fee"] = r.at("fee");
|
||||
member["listing"] = r.at("listing");
|
||||
}
|
||||
if (p.at("ownBid").is_object()) {
|
||||
const auto &bid = p.at("ownBid");
|
||||
orders.push_back({{"player", r.at("id")},
|
||||
{"name", r.at("name")},
|
||||
{"kind", bid.value("loan", false) ? "loan" : "buy"},
|
||||
{"poached", false},
|
||||
{"fee", engine_money_minor(bid.at("fee"))},
|
||||
{"months", bid.at("years").get<int>() * 12},
|
||||
{"listing", p.at("id")}});
|
||||
}
|
||||
const std::array<const char *, 4> roles{"gk", "def", "mid", "fwd"};
|
||||
const auto pos = std::find(roles.begin(), roles.end(),
|
||||
r.at("position").get<std::string>());
|
||||
check(pos != roles.end(), "Unbekannte Transferposition.");
|
||||
if (!(positions & (1 << int(pos - roles.begin()))) ||
|
||||
r.at("age") < c.at("age_min") || r.at("age") > c.at("age_max") ||
|
||||
r.at("strength") < c.at("strength_min") ||
|
||||
r.at("strength") > c.at("strength_max") ||
|
||||
r.at("fee") > c.at("price_max"))
|
||||
continue;
|
||||
if (folded(r.at("name")).find(folded(filters.at("query"))) ==
|
||||
std::string::npos)
|
||||
continue;
|
||||
market.push_back(std::move(r));
|
||||
}
|
||||
const auto &a = d.at("activeStrengths"), &t = d.at("teamStrengths");
|
||||
check(a.size() == 5 && t.size() == 5, "Unvollständige Mannschaftsstärken.");
|
||||
return {{"ok", true},
|
||||
{"own", own},
|
||||
{"market", market},
|
||||
{"orders", orders},
|
||||
{"listed", listed},
|
||||
{"query", filters.at("query")},
|
||||
{"positions", positions},
|
||||
{"cash", engine_money_minor(d.at("cash"))},
|
||||
{"credit", engine_money_minor(d.at("creditLine"))},
|
||||
{"strengths",
|
||||
{{"active", Json::array({a[0], a[1], a[2], a[3]})},
|
||||
{"team", Json::array({t[0], t[1], t[2], t[3]})},
|
||||
{"active_average", a[4]},
|
||||
{"team_average", t[4]}}}};
|
||||
}
|
||||
Json engine_transfer_command(const Json &b, const Json &draft,
|
||||
const std::string &id) {
|
||||
const auto &d = read(b), &m = b.at("desktop").at("meta");
|
||||
check(!id.empty(), "Anfrage-ID fehlt.");
|
||||
const auto &commands = m.at("scope").at("allowedCommands");
|
||||
check(std::find(commands.begin(), commands.end(), Json("transfer.submit")) !=
|
||||
commands.end(),
|
||||
"Transfers sind derzeit gesperrt.");
|
||||
const auto kind = draft.at("kind").get<std::string>(),
|
||||
player = draft.at("player").get<std::string>();
|
||||
Json payload;
|
||||
if (kind == "sell" || kind == "lend") {
|
||||
const auto it =
|
||||
std::find_if(d.at("squad").begin(), d.at("squad").end(),
|
||||
[&](const auto &p) { return p.at("playerId") == player; });
|
||||
check(it != d.at("squad").end() && it->at("listed") == false,
|
||||
"Der Spieler ist nicht verfügbar oder bereits gelistet.");
|
||||
payload = {
|
||||
{"action", "list"}, {"playerId", player}, {"loan", kind == "lend"}};
|
||||
} else {
|
||||
check(kind == "buy" || kind == "loan", "Unbekannte Transferart.");
|
||||
const auto listing = draft.at("listing").get<std::string>();
|
||||
const auto it = std::find_if(
|
||||
d.at("listings").begin(), d.at("listings").end(), [&](const auto &p) {
|
||||
return p.at("id") == listing && p.at("playerId") == player;
|
||||
});
|
||||
check(it != d.at("listings").end() && it->at("ownListing") == false,
|
||||
"Das Angebot gehört einem anderen Spieler.");
|
||||
if (kind == "loan")
|
||||
check(it->at("loanAvailable") == true,
|
||||
"Vereinslose Spieler können nicht ausgeliehen werden.");
|
||||
if (it->at("ownBid").is_object())
|
||||
check(it->at("ownBid").value("loan", false) == (kind == "loan"),
|
||||
"Die Leihart eines laufenden Angebots kann hier noch nicht "
|
||||
"geändert werden.");
|
||||
const auto integer = [&](const Json &v, int64_t maximum) {
|
||||
check(v.is_number_integer() && v.get<int64_t>() >= 0 &&
|
||||
v.get<int64_t>() <= maximum,
|
||||
"Ungültiger Angebotswert.");
|
||||
return v.get<int64_t>();
|
||||
};
|
||||
const auto fee = integer(draft.at("fee"), 99999999),
|
||||
salary = integer(draft.at("salary"), 200000),
|
||||
months = integer(draft.at("months"), 48);
|
||||
check(months >= 12 && months % 12 == 0 && (kind != "loan" || months <= 24),
|
||||
"Ungültige Vertragsdauer.");
|
||||
check(draft.at("bonuses").is_array() && draft.at("bonuses").size() == 7,
|
||||
"Sieben Prämien benötigt.");
|
||||
for (size_t i = 0; i < 7; ++i)
|
||||
integer(draft.at("bonuses")[i], i < 3 ? 20 : 200);
|
||||
const auto money = [](int64_t euros) {
|
||||
return Json{{"currency", "EUR"},
|
||||
{"minorUnits", 2},
|
||||
{"minor", std::to_string(euros * 100)}};
|
||||
};
|
||||
payload = {{"action", "bid"},
|
||||
{"listingId", listing},
|
||||
{"fee", money(fee)},
|
||||
{"monthlySalary", money(salary)},
|
||||
{"years", months / 12},
|
||||
{"loan", kind == "loan"},
|
||||
{"bonuses", draft.at("bonuses")}};
|
||||
}
|
||||
return {{"messageType", "command"},
|
||||
{"requestId", id},
|
||||
{"careerId", m.at("careerId")},
|
||||
{"expectedRevision", m.at("stateRevision")},
|
||||
{"owner", {{"managerId", m.at("scope").at("managerId")}}},
|
||||
{"kind", "transfer.submit"},
|
||||
{"payload", payload}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,365 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
Json App::transfer_data() const {
|
||||
return engine_mode_ ? engine_transfer_projection(engine_data_,
|
||||
engine_transfer_filters_)
|
||||
: demo_transfer_view(snap().state, *world_,
|
||||
transfer_ui_club(snap()));
|
||||
}
|
||||
std::string App::transfer_money(const Json &minor) const {
|
||||
if (!minor.is_number_integer())
|
||||
return "—";
|
||||
if (!engine_mode_)
|
||||
return cash(minor.get<int64_t>());
|
||||
return engine_price({{"currency", "EUR"},
|
||||
{"minorUnits", 2},
|
||||
{"minor", std::to_string(minor.get<int64_t>())}});
|
||||
}
|
||||
void App::engine_transfer_sync() {
|
||||
const auto &meta = engine_data_.at("desktop").at("meta");
|
||||
if (!engine_transfer_context_.is_object() ||
|
||||
engine_transfer_context_.value("careerId", Json()) !=
|
||||
meta.at("careerId") ||
|
||||
engine_transfer_context_.at("scope").at("managerId") !=
|
||||
meta.at("scope").at("managerId") ||
|
||||
engine_transfer_context_.at("scope").at("teamId") !=
|
||||
meta.at("scope").at("teamId") ||
|
||||
engine_transfer_context_.at("scope").at("role") !=
|
||||
meta.at("scope").at("role")) {
|
||||
engine_transfer_filters_ = engine_transfer_filters();
|
||||
transfer_view_ = Json::object();
|
||||
transfer_dialog_.clear();
|
||||
}
|
||||
engine_transfer_context_ = meta;
|
||||
engine_transfer_value_ = Json();
|
||||
try {
|
||||
engine_transfer_value_ =
|
||||
engine_transfer_projection(engine_data_, engine_transfer_filters_);
|
||||
} catch (const std::exception &) {
|
||||
}
|
||||
if (engine_transfer_submitting_) {
|
||||
engine_transfer_submitting_ = false;
|
||||
transfer_dialog_ = "booked";
|
||||
transfer_notice_ = engine_notice_;
|
||||
transfer_draft_ = Json();
|
||||
transfer_world_.reset();
|
||||
focus_after_render_ = "transfer-close";
|
||||
}
|
||||
}
|
||||
bool App::engine_transfer_action(const std::string &action,
|
||||
Rml::Element *target) {
|
||||
if (!action.starts_with("transfer-"))
|
||||
return false;
|
||||
if (menu_ != "transfer" || engine_busy_ || !engine_fresh_ ||
|
||||
!engine_transfer_value_.is_object())
|
||||
return true;
|
||||
transfer_remember_scroll();
|
||||
const auto index = target ? target->GetAttribute<int>("data-index", -1) : -1;
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-player", "") : "";
|
||||
const auto context = engine_transfer_context_;
|
||||
const auto update = [&] {
|
||||
engine_transfer_value_ =
|
||||
engine_transfer_projection(engine_data_, engine_transfer_filters_);
|
||||
transfer_view_["page"] = 0;
|
||||
transfer_view_["market"] = "";
|
||||
transfer_view_["hover"] = "";
|
||||
refresh();
|
||||
};
|
||||
const auto send = [this, context](const Json &draft) {
|
||||
if (!engine_fresh_ || engine_busy_ || engine_transfer_context_ != context) {
|
||||
message("Die Partie hat sich geändert. Bitte das Angebot erneut öffnen.");
|
||||
return;
|
||||
}
|
||||
const auto request = engine_transfer_command(engine_data_, draft,
|
||||
editor::new_id("request:ui-"));
|
||||
engine_transfer_submitting_ = true;
|
||||
auto link = engine_link_;
|
||||
engine_start(
|
||||
"Transferauftrag wird bearbeitet …",
|
||||
[link, request] {
|
||||
const auto reply = link->command(request);
|
||||
return EngineReply{link, link->snapshot(), reply, nullptr};
|
||||
},
|
||||
true);
|
||||
};
|
||||
if (action == "transfer-close") {
|
||||
close_transfer();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-offer-back") {
|
||||
transfer_dialog_ = "offer";
|
||||
focus_after_render_ = "transfer-fee";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-own" || action == "transfer-market") {
|
||||
auto row = transfer_ui_find(engine_transfer_value_.at("own"), id);
|
||||
if (row.is_null())
|
||||
row = transfer_ui_find(engine_transfer_value_.at("market"), id);
|
||||
if (row.is_null())
|
||||
return true;
|
||||
const bool own = row.at("own");
|
||||
transfer_view_[own ? "own" : "market"] = id;
|
||||
transfer_view_["side"] = own ? "own" : "market";
|
||||
transfer_view_["hover"] = "";
|
||||
focus_after_render_ = target->GetId();
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-data" || action == "transfer-all" ||
|
||||
action == "transfer-scope") {
|
||||
if (action == "transfer-data")
|
||||
transfer_view_["tab"] = 1 - transfer_view_.value("tab", 0);
|
||||
else if (action == "transfer-all") {
|
||||
transfer_view_["complete"] = !transfer_view_.value("complete", false);
|
||||
transfer_view_["roster_left"] = 0;
|
||||
} else {
|
||||
const auto scope = target->GetAttribute<Rml::String>("data-scope", "");
|
||||
if (scope == "team" || scope == "active")
|
||||
transfer_view_["scope"] = scope;
|
||||
}
|
||||
focus_after_render_ = target->GetId();
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-filter") {
|
||||
if (index < 0 || index > 4)
|
||||
return true;
|
||||
const int mask = index == 0
|
||||
? 15
|
||||
: engine_transfer_filters_.at("positions").get<int>() ^
|
||||
(1 << (index - 1));
|
||||
if (mask) {
|
||||
engine_transfer_filters_["positions"] = mask;
|
||||
update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-search") {
|
||||
engine_transfer_filters_["query"] =
|
||||
transfer_view_.value("query", std::string());
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-page") {
|
||||
const int step = target->GetAttribute<int>("data-step", 0);
|
||||
if (step == -1 || step == 1) {
|
||||
transfer_view_["page"] = std::clamp(
|
||||
transfer_view_.value("page", 0) + step, 0,
|
||||
std::max(0,
|
||||
int((engine_transfer_value_.at("market").size() + 5) / 6) -
|
||||
1));
|
||||
transfer_view_["hover"] = "";
|
||||
focus_after_render_ = target->GetId();
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-offer") {
|
||||
const auto kind = target->GetAttribute<Rml::String>("data-kind", "");
|
||||
const bool own = kind == "sell" || kind == "lend";
|
||||
auto row = transfer_ui_find(
|
||||
engine_transfer_value_.at(own ? "own" : "market"),
|
||||
transfer_view_.value(own ? "own" : "market", std::string()));
|
||||
if (row.is_null())
|
||||
return true;
|
||||
if (own) {
|
||||
if (std::find(engine_transfer_value_.at("listed").begin(),
|
||||
engine_transfer_value_.at("listed").end(),
|
||||
row.at("id")) != engine_transfer_value_.at("listed").end())
|
||||
return true;
|
||||
const Json draft = {{"kind", kind}, {"player", row.at("id")}};
|
||||
confirmation(row.at("name").get<std::string>() +
|
||||
(kind == "lend" ? " zum Verleih anbieten?"
|
||||
: " auf die Transferliste setzen?"),
|
||||
[send, draft] { send(draft); });
|
||||
popup_accept_ = "Anbieten";
|
||||
return true;
|
||||
}
|
||||
const auto *club = row.at("club").is_string()
|
||||
? world_->find("clubs", row.at("club"))
|
||||
: nullptr;
|
||||
row["club_name"] =
|
||||
club ? world_->name(*club) : row.value("seller_name", std::string("—"));
|
||||
row["nation_name"] = row.at("nation").is_string()
|
||||
? world_->nation_name(row.at("nation"))
|
||||
: "";
|
||||
const auto &bid = row.at("bid");
|
||||
Json bonuses = Json::array({0, 0, 0, 0, 0, 0, 0});
|
||||
if (bid.is_object())
|
||||
bonuses = bid.at("bonuses");
|
||||
transfer_draft_ = {
|
||||
{"kind", kind},
|
||||
{"player", row.at("id")},
|
||||
{"listing", row.at("listing")},
|
||||
{"row", row},
|
||||
{"poached", false},
|
||||
{"fee", bid.is_object() ? engine_money_minor(bid.at("fee")) / 100
|
||||
: engine_money_minor(
|
||||
row.at("terms")
|
||||
.at(kind == "loan" ? "loan" : "buy")
|
||||
.at("fee")) /
|
||||
100},
|
||||
{"salary", bid.is_object()
|
||||
? engine_money_minor(bid.at("monthlySalary")) / 100
|
||||
: row.at("salary_reference").get<int64_t>() / 100},
|
||||
{"months", bid.is_object() ? bid.at("years").get<int>() * 12 : 24},
|
||||
{"bonuses", bonuses},
|
||||
{"demand_fee",
|
||||
engine_money_minor(
|
||||
row.at("terms").at(kind == "loan" ? "loan" : "buy").at("fee"))},
|
||||
{"demand_salary", row.at("salary_reference")}};
|
||||
transfer_revision_ =
|
||||
std::stoull(context.at("stateRevision").get<std::string>());
|
||||
transfer_world_ = world_;
|
||||
transfer_return_focus_ = target->GetId();
|
||||
transfer_dialog_ = "offer";
|
||||
focus_after_render_ = "transfer-fee";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-player-info" || action == "transfer-team-info") {
|
||||
if (transfer_dialog_ == "offer") {
|
||||
transfer_dialog_ =
|
||||
action == "transfer-player-info" ? "player-info" : "team-info";
|
||||
focus_after_render_ = "transfer-offer-back";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-submit") {
|
||||
if (transfer_dialog_ != "offer" || transfer_world_ != world_)
|
||||
return true;
|
||||
const auto draft = transfer_draft_;
|
||||
const auto request = engine_transfer_command(
|
||||
engine_data_, draft, editor::new_id("request:review-"));
|
||||
(void)request;
|
||||
confirmation(draft.at("row").at("name").get<std::string>() + ": " +
|
||||
(draft.at("kind") == "loan" ? std::string("Leihgebühr ")
|
||||
: std::string("Ablöse ")) +
|
||||
transfer_money(draft.at("fee").get<int64_t>() * 100) +
|
||||
", Monatsgehalt " +
|
||||
transfer_money(draft.at("salary").get<int64_t>() * 100) +
|
||||
", " + std::to_string(draft.at("months").get<int>()) +
|
||||
" Monate. Angebot mit den angezeigten Prämien abgeben?",
|
||||
[send, draft] { send(draft); });
|
||||
popup_accept_ = "Angebot abgeben";
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-amount" || action == "transfer-bonus" ||
|
||||
action == "transfer-search-budget") {
|
||||
const bool search = action == "transfer-search-budget",
|
||||
bonus = action == "transfer-bonus";
|
||||
if (search ? transfer_dialog_ != "search" : transfer_dialog_ != "offer")
|
||||
return true;
|
||||
const auto field =
|
||||
search ? std::string("price_max")
|
||||
: bonus ? std::string("bonuses")
|
||||
: target->GetAttribute<Rml::String>("data-field", "");
|
||||
if ((bonus && (index < 0 || index > 6)) ||
|
||||
(!search && !bonus && field != "fee" && field != "salary"))
|
||||
return true;
|
||||
AmountRequest a;
|
||||
a.title = search ? "Maximale Ablösesumme"
|
||||
: bonus ? transfer_ui_bonuses[size_t(index)]
|
||||
: field == "fee" ? "Ablöse / Leihgebühr"
|
||||
: "Monatsgehalt";
|
||||
a.unit = bonus ? "" : "€";
|
||||
a.return_focus = target->GetId();
|
||||
a.min = 0;
|
||||
a.max = bonus ? (index < 3 ? 20 : 1000)
|
||||
: field == "salary" ? 200000
|
||||
: 99999999;
|
||||
a.step = bonus && index >= 3 ? 5 : 1;
|
||||
if (!search && !bonus) {
|
||||
const auto &terms = transfer_draft_.at("row").at("terms");
|
||||
a.max = std::min<int64_t>(
|
||||
a.max, engine_money_minor(
|
||||
field == "fee"
|
||||
? terms
|
||||
.at(transfer_draft_.at("kind") == "loan" ? "loan"
|
||||
: "buy")
|
||||
.at("maximumFee")
|
||||
: terms.at("maximumMonthlySalary")) /
|
||||
100);
|
||||
}
|
||||
a.suggestion_step = bonus ? 1 : field == "salary" ? 5000 : 100000;
|
||||
a.review = false;
|
||||
a.value = search ? transfer_search_draft_.at(field).get<int64_t>()
|
||||
: bonus ? transfer_draft_.at(field)[size_t(index)].get<int64_t>()
|
||||
: transfer_draft_.at(field).get<int64_t>();
|
||||
if (bonus && index >= 3)
|
||||
a.value *= 5;
|
||||
a.accept = [this, context, field, index, search, bonus](int64_t value) {
|
||||
if (menu_ != "transfer" || engine_transfer_context_ != context ||
|
||||
transfer_dialog_ != (search ? "search" : "offer"))
|
||||
return false;
|
||||
if (search)
|
||||
transfer_search_draft_[field] = value;
|
||||
else if (bonus)
|
||||
transfer_draft_[field][size_t(index)] = index < 3 ? value : value / 5;
|
||||
else
|
||||
transfer_draft_[field] = value;
|
||||
refresh();
|
||||
return true;
|
||||
};
|
||||
open_amount(std::move(a));
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-criteria" || action == "transfer-suggest" ||
|
||||
action == "transfer-search-reset") {
|
||||
transfer_search_draft_ = action == "transfer-search-reset"
|
||||
? engine_transfer_filters().at("criteria")
|
||||
: engine_transfer_filters_.at("criteria");
|
||||
transfer_search_draft_["price_max"] =
|
||||
transfer_search_draft_.at("price_max").get<int64_t>() / 100;
|
||||
transfer_search_draft_["positions"] =
|
||||
action == "transfer-search-reset"
|
||||
? 15
|
||||
: engine_transfer_filters_.at("positions").get<int>();
|
||||
if (action == "transfer-suggest") {
|
||||
const auto &strengths =
|
||||
engine_transfer_value_.at("strengths").at("active");
|
||||
const auto it = std::min_element(strengths.begin(), strengths.end());
|
||||
transfer_search_draft_["positions"] = 1 << int(it - strengths.begin());
|
||||
}
|
||||
transfer_world_ = world_;
|
||||
transfer_dialog_ = "search";
|
||||
transfer_return_focus_ = target->GetId();
|
||||
focus_after_render_ = "transfer-search-position-0";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-search-position") {
|
||||
if (transfer_dialog_ == "search" && index >= 0 && index < 4) {
|
||||
const int mask =
|
||||
transfer_search_draft_.at("positions").get<int>() ^ (1 << index);
|
||||
if (mask)
|
||||
transfer_search_draft_["positions"] = mask;
|
||||
focus_after_render_ = target->GetId();
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-search-apply") {
|
||||
if (transfer_dialog_ != "search")
|
||||
return true;
|
||||
auto criteria = transfer_search_draft_;
|
||||
engine_transfer_filters_["positions"] = criteria.at("positions");
|
||||
criteria.erase("positions");
|
||||
criteria["price_max"] = criteria.at("price_max").get<int64_t>() * 100;
|
||||
engine_transfer_filters_["criteria"] = criteria;
|
||||
engine_transfer_filters_["query"] = "";
|
||||
update();
|
||||
close_transfer();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-orders") {
|
||||
transfer_dialog_ = "orders";
|
||||
transfer_return_focus_ = target->GetId();
|
||||
focus_after_render_ = "transfer-close";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ void App::close_transfer(bool restore) {
|
||||
refresh();
|
||||
}
|
||||
bool App::transfer_action(const std::string &action, Rml::Element *target) {
|
||||
if (engine_mode_) return engine_transfer_action(action,target);
|
||||
if (!action.starts_with("transfer-"))
|
||||
return false;
|
||||
if (menu_ != "transfer" || !world_ || !source_)
|
||||
@@ -392,7 +393,7 @@ bool App::transfer_action(const std::string &action, Rml::Element *target) {
|
||||
return true;
|
||||
}
|
||||
bool App::transfer_event(Rml::Event &event) {
|
||||
if (menu_ != "transfer" || !source_ || amount_ || !popup_.empty() ||
|
||||
if (menu_ != "transfer" || (!engine_mode_ && !source_) || amount_ || !popup_.empty() ||
|
||||
!report_detail_kind_.empty())
|
||||
return false;
|
||||
const auto type = event.GetType();
|
||||
@@ -458,7 +459,7 @@ bool App::transfer_event(Rml::Event &event) {
|
||||
target->HasAttribute("data-criterion")) {
|
||||
const auto field =
|
||||
target->GetAttribute<Rml::String>("data-criterion", "");
|
||||
const int maximum = (field == "age_min" || field == "age_max") ? 40
|
||||
const int maximum = (field == "age_min" || field == "age_max") ? (engine_mode_?47:40)
|
||||
: (field == "foot" || field == "type") ? 3
|
||||
: 100;
|
||||
const int minimum = (field == "age_min" || field == "age_max") ? 16 : 0;
|
||||
@@ -549,7 +550,7 @@ bool App::transfer_event(Rml::Event &event) {
|
||||
offers = true;
|
||||
if (offers) {
|
||||
const auto pool =
|
||||
demo_transfer_view(snap().state, *world_, transfer_ui_club(snap()))
|
||||
transfer_data()
|
||||
.at("market");
|
||||
const int pages = std::max(1, int((pool.size() + 5) / 6));
|
||||
transfer_view_["page"] = (transfer_view_.value("page", 0) + 1) % pages;
|
||||
@@ -576,9 +577,8 @@ bool App::transfer_event(Rml::Event &event) {
|
||||
return false;
|
||||
if (transfer_view_.value("hover", std::string()) != hover) {
|
||||
transfer_view_["hover"] = hover;
|
||||
const auto snapshot = snap();
|
||||
const auto rows = demo_transfer_view(snapshot.state, *world_,
|
||||
transfer_ui_club(snapshot));
|
||||
const auto snapshot = engine_mode_ ? Snapshot{} : snap();
|
||||
const auto rows = transfer_data();
|
||||
auto row = transfer_ui_find(rows.at("market"), hover);
|
||||
if (row.is_null())
|
||||
row = transfer_view_.value("side", std::string()) == "own"
|
||||
@@ -589,19 +589,19 @@ bool App::transfer_event(Rml::Event &event) {
|
||||
transfer_view_.value("market", std::string()));
|
||||
std::string body = "<p>Wähle einen angebotenen Spieler.</p>";
|
||||
if (row.is_object()) {
|
||||
const auto fee = row.at("fee").get<int64_t>(),
|
||||
remaining = snapshot.state.at("cash").get<int64_t>() +
|
||||
const auto fee = row.at("fee").is_number_integer() ? row.at("fee").get<int64_t>() : 0,
|
||||
remaining = (engine_mode_ ? engine_transfer_value_.at("cash").get<int64_t>() : snapshot.state.at("cash").get<int64_t>()) +
|
||||
(row.at("own") == true ? fee : -fee);
|
||||
body = "<p>" + label(world_->find("clubs", row.at("club")), 32) +
|
||||
body = "<p>" + (world_->find("clubs",row.at("club"))?label(world_->find("clubs",row.at("club")),32):esc(row.value("seller_name",std::string("—")))) +
|
||||
"</p><div><section><span>" +
|
||||
std::string(row.at("own") == true ? "Marktwert"
|
||||
: "Geforderte Ablöse") +
|
||||
"</span><strong>" + esc(cash(fee)) +
|
||||
"</span><strong>" + esc(row.at("fee").is_null()?std::string("—"):transfer_money(fee)) +
|
||||
"</strong></section><section><span>Restkapital nach " +
|
||||
std::string(row.at("own") == true ? "Verkauf" : "Kauf") +
|
||||
"</span><strong class=\"" +
|
||||
std::string(remaining < 0 ? "transfer-negative" : "") + "\">" +
|
||||
esc(cash(remaining)) + "</strong></section></div>";
|
||||
money_classes(remaining) + "\">" +
|
||||
esc(row.at("fee").is_null()?std::string("—"):transfer_money(remaining)) + "</strong></section></div>";
|
||||
}
|
||||
if (auto *preview = element("transfer-preview"))
|
||||
preview->SetInnerRML(body);
|
||||
|
||||
@@ -110,9 +110,9 @@ void App::transfer_restore_scroll() {
|
||||
}
|
||||
std::string App::render_transfer() {
|
||||
transfer_remember_scroll();
|
||||
const auto snapshot = snap();
|
||||
const auto own = transfer_ui_club(snapshot);
|
||||
const auto data = demo_transfer_view(snapshot.state, *world_, own);
|
||||
const auto snapshot = engine_mode_ ? Snapshot{} : snap();
|
||||
const auto own = engine_mode_ ? engine_data_.at("desktop").at("meta").at("scope").at("teamId").get<std::string>() : transfer_ui_club(snapshot);
|
||||
const auto data = transfer_data();
|
||||
if (!data.value("ok", false))
|
||||
return {};
|
||||
if (!transfer_view_.is_object() || !transfer_view_.contains("tab"))
|
||||
@@ -159,7 +159,7 @@ std::string App::render_transfer() {
|
||||
if (preview.is_null())
|
||||
preview = chosen;
|
||||
const auto listed = [&](const std::string &id) {
|
||||
const auto &ls = snapshot.state.at("transfer").at("listed");
|
||||
const auto &ls = engine_mode_ ? engine_transfer_value_.at("listed") : snapshot.state.at("transfer").at("listed");
|
||||
return std::find(ls.begin(), ls.end(), id) != ls.end();
|
||||
};
|
||||
const auto trait = [&](const Json &v, bool foot) {
|
||||
@@ -204,8 +204,8 @@ std::string App::render_transfer() {
|
||||
"<section class=\"transfer-overview " +
|
||||
std::string(complete ? "transfer-complete" : "") +
|
||||
"\"><header class=\"transfer-heading\"><h2>Kader und "
|
||||
"Transfermarkt</h2><div><span>Verfügbares Kapital</span><strong>" +
|
||||
esc(cash(snapshot.state.at("cash").get<int64_t>())) +
|
||||
"Transfermarkt</h2>" + (engine_mode_?"<p id=\"transfer-engine-feedback\" style=\"position:absolute;left:0;right:650dp;bottom:0;font-size:23dp;line-height:27dp;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;\">"+esc(engine_busy_?engine_operation_:engine_notice_)+"</p>":"") + "<div><span>Verfügbares Kapital</span><strong class=\"" + money_classes(engine_mode_?engine_transfer_value_.at("cash").get<int64_t>():snapshot.state.at("cash").get<int64_t>()) + "\">" +
|
||||
esc(transfer_money((engine_mode_ ? engine_transfer_value_.at("cash").get<int64_t>() : snapshot.state.at("cash").get<int64_t>()))) +
|
||||
"</strong></div></header><div class=\"transfer-columns\"><section "
|
||||
"class=\"transfer-roster\"><header><h2>Dein Kader</h2><span>" +
|
||||
std::to_string(ours.size()) + " Spieler · Daten " + (b ? "B" : "A") +
|
||||
@@ -368,18 +368,18 @@ std::string App::render_transfer() {
|
||||
"</div><section id=\"transfer-preview\" class=\"transfer-preview\">";
|
||||
if (preview.is_object()) {
|
||||
const auto *source = world_->find("clubs", preview.at("club"));
|
||||
const auto fee = preview.at("fee").get<int64_t>();
|
||||
const auto remaining = snapshot.state.at("cash").get<int64_t>() +
|
||||
const auto fee = preview.at("fee").is_number_integer() ? preview.at("fee").get<int64_t>() : 0;
|
||||
const auto remaining = (engine_mode_ ? engine_transfer_value_.at("cash").get<int64_t>() : snapshot.state.at("cash").get<int64_t>()) +
|
||||
(preview.at("own") == true ? fee : -fee);
|
||||
out += "<p>" + label(source, 32) + "</p><div><section><span>" +
|
||||
out += "<p>" + (source?label(source,32):esc(preview.value("seller_name",std::string("—")))) + "</p><div><section><span>" +
|
||||
std::string(preview.at("own") == true ? "Marktwert"
|
||||
: "Geforderte Ablöse") +
|
||||
"</span><strong>" + esc(cash(fee)) +
|
||||
"</span><strong>" + esc(preview.at("fee").is_null()?std::string("—"):transfer_money(fee)) +
|
||||
"</strong></section><section><span>Restkapital nach " +
|
||||
std::string(preview.at("own") == true ? "Verkauf" : "Kauf") +
|
||||
"</span><strong class=\"" +
|
||||
std::string(remaining < 0 ? "transfer-negative" : "") + "\">" +
|
||||
esc(cash(remaining)) + "</strong></section></div>";
|
||||
money_classes(remaining) + "\">" +
|
||||
esc(preview.at("fee").is_null()?std::string("—"):transfer_money(remaining)) + "</strong></section></div>";
|
||||
} else
|
||||
out += "<p>Wähle einen angebotenen Spieler.</p>";
|
||||
out += "</section><nav class=\"transfer-filters\">";
|
||||
@@ -397,7 +397,7 @@ std::string App::render_transfer() {
|
||||
: "false") +
|
||||
"\"");
|
||||
out += "</nav>";
|
||||
const auto strengths = demo_transfer_strengths(
|
||||
const auto strengths = engine_mode_ ? engine_transfer_value_.at("strengths") : demo_transfer_strengths(
|
||||
snapshot.state, *world_, own, demo_lineup_active(snapshot.state));
|
||||
const auto scope = transfer_view_.value("scope", std::string("active"));
|
||||
out +=
|
||||
@@ -428,17 +428,19 @@ std::string App::render_transfer() {
|
||||
: "Kein Marktspieler ausgewählt") +
|
||||
"</p><div>";
|
||||
const bool mine = chosen.is_object() && chosen.at("own") == true;
|
||||
const bool pending = engine_mode_ && !mine && chosen.is_object() && chosen.value("bid",Json()).is_object();
|
||||
const bool pending_loan = pending && chosen.at("bid").value("loan",false);
|
||||
out +=
|
||||
btn("transfer-offer",
|
||||
mine && listed(chosen.at("id")) ? "Vom Markt nehmen" : "Ver-kaufen",
|
||||
"",
|
||||
"id=\"transfer-offer-buy-sell\" data-kind=\"" +
|
||||
std::string(mine ? "sell" : "buy") + "\" " +
|
||||
std::string(chosen.is_object() ? "" : "disabled")) +
|
||||
std::string(chosen.is_object() && (!engine_mode_ || !mine || !listed(chosen.at("id"))) && (!pending || !pending_loan) ? "" : "disabled")) +
|
||||
btn("transfer-offer", "Ver-leihen", "",
|
||||
"id=\"transfer-offer-loan-lend\" data-kind=\"" +
|
||||
std::string(mine ? "lend" : "loan") + "\" " +
|
||||
std::string(chosen.is_object() ? "" : "disabled")) +
|
||||
std::string(chosen.is_object() && (!engine_mode_ || !mine || !listed(chosen.at("id"))) && (!pending || pending_loan) && (!engine_mode_ || mine || chosen.value("loan_allowed",false)) ? "" : "disabled")) +
|
||||
"</div></div></div></section>";
|
||||
}
|
||||
out += "</div><nav class=\"transfer-actions\">" +
|
||||
@@ -451,7 +453,7 @@ std::string App::render_transfer() {
|
||||
out += btn("transfer-criteria", "Spieler suchen", "",
|
||||
"id=\"transfer-criteria\"") +
|
||||
btn("transfer-suggest", "Vorschlag", "", "id=\"transfer-suggest\"") +
|
||||
btn("transfer-poach", "Abwerben", "", "id=\"transfer-poach\"") +
|
||||
btn("transfer-poach", "Abwerben", "", "id=\"transfer-poach\" " + std::string(engine_mode_?"disabled title=\"Noch nicht angebunden\"":"")) +
|
||||
btn("transfer-orders",
|
||||
"Aufträge (" + std::to_string(data.at("orders").size()) + ")",
|
||||
"", "id=\"transfer-orders\"");
|
||||
@@ -462,8 +464,8 @@ std::string App::render_transfer() {
|
||||
std::string App::render_transfer_dialog() {
|
||||
if (transfer_dialog_.empty())
|
||||
return {};
|
||||
const auto snapshot = snap();
|
||||
const auto actor = transfer_ui_club(snapshot);
|
||||
const auto snapshot = engine_mode_ ? Snapshot{} : snap();
|
||||
const auto actor = engine_mode_ ? engine_data_.at("desktop").at("meta").at("scope").at("teamId").get<std::string>() : transfer_ui_club(snapshot);
|
||||
std::string title, body, actions;
|
||||
double height = 500;
|
||||
const auto button = [&](const char *action, const std::string &caption,
|
||||
@@ -500,15 +502,15 @@ std::string App::render_transfer_dialog() {
|
||||
transfer_ui_number(r.at("age")) + " Jahre · Stärke " +
|
||||
transfer_ui_number(r.at("strength")) +
|
||||
"</span></div><div class=\"transfer-offer-club\">" +
|
||||
label(world_->find("clubs", r.at("club")), 58) +
|
||||
(world_->find("clubs",r.at("club"))?label(world_->find("clubs",r.at("club")),58):esc(r.value("club_name",std::string("—")))) +
|
||||
"</div></header><div class=\"transfer-demands\"><section><span>" +
|
||||
std::string(loan ? "Fiktive Leihgebühr" : "Ungefährer Marktwert") +
|
||||
"</span><strong>" + esc(cash(d.at("demand_fee").get<int64_t>())) +
|
||||
std::string(engine_mode_ ? "Ablöseforderung" : loan ? "Fiktive Leihgebühr" : "Ungefährer Marktwert") +
|
||||
"</span><strong>" + esc(transfer_money(d.at("demand_fee").get<int64_t>())) +
|
||||
"</strong></section><section><span>" +
|
||||
std::string(mine ? "Aktuelles Monatsgehalt" : "Gehaltswunsch") +
|
||||
std::string(engine_mode_ ? "Gehaltsreferenz / Monat" : mine ? "Aktuelles Monatsgehalt" : "Gehaltswunsch") +
|
||||
"</span><strong>" +
|
||||
(d.at("demand_salary").is_number_integer()
|
||||
? esc(cash(d.at("demand_salary").get<int64_t>()))
|
||||
? esc(transfer_money(d.at("demand_salary").get<int64_t>()))
|
||||
: "—") +
|
||||
"</strong></section></div><h3 class=\"transfer-offer-your\">Dein "
|
||||
"Angebot</h3><div class=\"transfer-offer-inputs\">";
|
||||
@@ -544,13 +546,13 @@ std::string App::render_transfer_dialog() {
|
||||
"<div class=\"transfer-premium-row\" style=\"" +
|
||||
rect((i % 2) * 1063, 48 + (i / 2) * 82, 1029, 82) + "\"><span>" +
|
||||
std::string(transfer_ui_bonuses[size_t(i)]) + "</span>" +
|
||||
btn("transfer-bonus", transfer_ui_number(d.at("bonuses")[size_t(i)]),
|
||||
btn("transfer-bonus", transfer_ui_number(engine_mode_&&i>=3?Json(d.at("bonuses")[size_t(i)].get<int>()*5):d.at("bonuses")[size_t(i)]),
|
||||
"amount-trigger",
|
||||
"id=\"transfer-bonus-" + std::to_string(i) + "\" data-index=\"" +
|
||||
std::to_string(i) + "\"") +
|
||||
"</div>";
|
||||
body += "</div></section><p class=\"transfer-offer-note\">" +
|
||||
std::string(mine ? "Der Spieler wird zum " +
|
||||
std::string(engine_mode_ ? "Die Engine entscheidet nach Bestätigung über dieses Angebot. Die Konditionen werden erst beim Absenden verbindlich." : mine ? "Der Spieler wird zum " +
|
||||
std::string(loan ? "Verleihen" : "Verkauf") +
|
||||
" auf dem Markt vorgemerkt."
|
||||
: "Das Angebot wird vorgemerkt; die Entscheidung "
|
||||
@@ -594,7 +596,7 @@ std::string App::render_transfer_dialog() {
|
||||
"</span><input type=\"range\" id=\"transfer-range-" + key +
|
||||
"\" data-criterion=\"" + key + "\" min=\"" +
|
||||
std::to_string(i < 2 ? 16 : 0) + "\" max=\"" +
|
||||
std::to_string(i < 2 ? 40 : 100) + "\" step=\"1\" value=\"" +
|
||||
std::to_string(i < 2 ? (engine_mode_?47:40) : 100) + "\" step=\"1\" value=\"" +
|
||||
transfer_ui_number(d.at(key)) +
|
||||
"\"/><output id=\"transfer-range-value-" + key + "\">" +
|
||||
transfer_ui_number(d.at(key)) + "</output></div>";
|
||||
@@ -652,7 +654,7 @@ std::string App::render_transfer_dialog() {
|
||||
"class=\"transfer-info-photo\">" +
|
||||
(r.at("photo").is_string()
|
||||
? img(r.at("photo"), 440, 550, true, true, 650)
|
||||
: "<span>—</span>") +
|
||||
: engine_mode_ ? img("asset:player/generic/photo",440,550,true,false,650) : "<span>—</span>") +
|
||||
"</div><div class=\"transfer-info-facts\">";
|
||||
const std::vector<std::pair<std::string, std::string>> facts{
|
||||
{"Verein", r.at("club_name")},
|
||||
@@ -683,7 +685,7 @@ std::string App::render_transfer_dialog() {
|
||||
} else if (transfer_dialog_ == "team-info") {
|
||||
height = 800;
|
||||
title = "Team-Info";
|
||||
const auto values = demo_transfer_strengths(
|
||||
const auto values = engine_mode_ ? engine_transfer_value_.at("strengths") : demo_transfer_strengths(
|
||||
snapshot.state, *world_, actor, demo_lineup_active(snapshot.state));
|
||||
body = "<div class=\"transfer-team-info\"><h3>" +
|
||||
label(world_->find("clubs", actor), 58) +
|
||||
@@ -766,7 +768,7 @@ std::string App::render_transfer_dialog() {
|
||||
"<span>" + transfer_ui_role(r.at("position")) + "</span><span>" +
|
||||
transfer_ui_number(r.at("age")) + "</span><span>" +
|
||||
transfer_ui_number(r.at("strength")) + "</span><span>" +
|
||||
esc(cash((r.at("fee").get<int64_t>() * 3 + 1) / 2)) +
|
||||
esc(transfer_money((r.at("fee").get<int64_t>() * 3 + 1) / 2)) +
|
||||
"</span></div>";
|
||||
body += "</div>";
|
||||
actions = button("transfer-poach-back", "Zurück zu Vereinen",
|
||||
@@ -775,7 +777,7 @@ std::string App::render_transfer_dialog() {
|
||||
} else if (transfer_dialog_ == "orders") {
|
||||
title = "Vorgemerkte Transferaufträge";
|
||||
const auto rows =
|
||||
demo_transfer_view(snapshot.state, *world_, actor).at("orders");
|
||||
transfer_data().at("orders");
|
||||
height = rows.empty() ? 430 : std::min(1450., 352. + rows.size() * 74.);
|
||||
body = "<div id=\"transfer-orders-scroll\" class=\"transfer-order-list\">";
|
||||
if (rows.empty())
|
||||
@@ -793,21 +795,21 @@ std::string App::render_transfer_dialog() {
|
||||
body +=
|
||||
"<div class=\"transfer-order-row\"><span>" +
|
||||
esc(o.at("name").get<std::string>()) + "</span><span>" +
|
||||
esc(o.at("poached") == true ? "Abwerben" : kinds.at(o.at("kind"))) +
|
||||
"</span><span>" + esc(cash(o.at("fee").get<int64_t>())) +
|
||||
esc(engine_mode_ ? "Gebot" : o.at("poached") == true ? "Abwerben" : kinds.at(o.at("kind"))) +
|
||||
"</span><span>" + esc(transfer_money(o.at("fee").get<int64_t>())) +
|
||||
"</span><span>" + std::to_string(o.at("months").get<int>()) +
|
||||
" Monate</span>" +
|
||||
btn("transfer-order-delete", "×", "",
|
||||
"id=\"transfer-order-delete-" + std::to_string(i) +
|
||||
"\" data-index=\"" + std::to_string(i) +
|
||||
"\" aria-label=\"Auftrag zurücknehmen\"") +
|
||||
"\" aria-label=\"Auftrag zurücknehmen\" " + std::string(engine_mode_?"disabled title=\"Noch nicht angebunden\"":"")) +
|
||||
"</div>";
|
||||
}
|
||||
}
|
||||
body += "</div>";
|
||||
actions = close("Zurück");
|
||||
} else {
|
||||
title = transfer_dialog_ == "booked" ? "Auftrag vorgemerkt"
|
||||
title = transfer_dialog_ == "booked" ? (engine_mode_ ? "Transferauftrag" : "Auftrag vorgemerkt")
|
||||
: "Transferliste voll";
|
||||
body = "<p class=\"transfer-notice\">" + esc(transfer_notice_) + "</p>";
|
||||
actions = close("Verstanden");
|
||||
|
||||
@@ -1546,6 +1546,7 @@ public:
|
||||
#include "modern/ui/engine_statistics.inc"
|
||||
#include "modern/ui/engine_toto.inc"
|
||||
#include "modern/ui/engine_stadium.inc"
|
||||
#include "modern/ui/engine_transfer.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user