Port lineup and transfer market to the native Modern UI (by Codex)
This commit is contained in:
1 parent
ec1d804d08
commit
bf3f910437
33 files changed
+3339
-29
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 model.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)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp model.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_transfer.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 STATIC view.cpp ticket_popover.cpp)
|
||||
@@ -14,7 +14,7 @@ endif()
|
||||
set(modern_assets "${CMAKE_BINARY_DIR}/assets/modern")
|
||||
FetchContent_GetProperties(rmlui)
|
||||
file(MAKE_DIRECTORY "${modern_assets}")
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss)
|
||||
foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss reports.rcss report_details.rcss report_pickers.rcss indoor.rcss planning.rcss almanac.rcss finance.rcss bank.rcss contracts.rcss amount.rcss environment.rcss advertising.rcss toto.rcss lineup.rcss transfer.rcss)
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
file(GLOB modern_icons CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/assets/modern/icons/*.svg")
|
||||
@@ -80,7 +80,7 @@ if(MSVC)
|
||||
endif()
|
||||
add_test(NAME modern_control_layout_tests COMMAND modern_control_layout_tests "${modern_assets}")
|
||||
|
||||
foreach(component environment advertising toto)
|
||||
foreach(component environment advertising toto lineup transfer)
|
||||
add_executable(modern_${component}_ui_tests ../../../tests/modern_${component}_ui_tests.cpp)
|
||||
target_link_libraries(modern_${component}_ui_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -131,6 +131,10 @@ void App::drag_event(Rml::Event &event) {
|
||||
}
|
||||
void App::ProcessEvent(Rml::Event &event) try {
|
||||
const auto type = event.GetType();
|
||||
// Native widgets can emit intermediate selected values while their options
|
||||
// are being constructed. Opening a squad menu must stay read-only.
|
||||
if (setting_menu_markup_ && (menu_ == "lineup" || menu_ == "transfer") &&
|
||||
(type == "change" || type == "input")) return;
|
||||
if (type == "keydown")
|
||||
keyboard_navigation_ = true;
|
||||
else if (type == "mousedown")
|
||||
@@ -150,7 +154,16 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
if (n->GetId() == "native-ticket-layer")
|
||||
return;
|
||||
if (amount_event(event)) return;
|
||||
if ((menu_ == "lineup" || menu_ == "transfer") && (type == "change" || type == "input")) {
|
||||
if (auto *select = dynamic_cast<Rml::ElementFormControlSelect *>(event.GetTargetElement());
|
||||
select && select->IsSelectBoxVisible()) {
|
||||
pending_selects_.insert(select->GetId());
|
||||
dirty_ = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (popup_.empty() && amount_trigger_event(event)) return;
|
||||
if (popup_.empty() && report_detail_kind_.empty() && (lineup_event(event) || transfer_event(event))) return;
|
||||
if (popup_.empty() && contracts_event(event)) return;
|
||||
if (popup_.empty() && (advertising_event(event) || toto_event(event))) return;
|
||||
if (popup_.empty() && (bank_event(event) || finance_event(event))) return;
|
||||
@@ -396,7 +409,10 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
controls[size_t(next)]->GetId().starts_with("report-club-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("friendly-opponent-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("alm-match-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("contract-player-"))
|
||||
controls[size_t(next)]->GetId().starts_with("contract-player-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("lineup-name-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("lineup-detail-") ||
|
||||
controls[size_t(next)]->GetId().starts_with("lineup-bench-"))
|
||||
controls[size_t(next)]->ScrollIntoView(
|
||||
Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
||||
event.StopImmediatePropagation();
|
||||
@@ -436,6 +452,7 @@ void App::ProcessEvent(Rml::Event &event) try {
|
||||
void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-id", "") : std::string();
|
||||
if (lineup_action(action, target) || transfer_action(action, target)) return;
|
||||
if (environment_action(action, target) || advertising_action(action, target) || toto_action(action, target)) return;
|
||||
if (amount_action(action, target) || bank_action(action, target) || finance_action(action, target) || contracts_action(action, target)) return;
|
||||
if (almanac_action(action, target) || planning_action(action, target) || indoor_action(action, target)) return;
|
||||
@@ -1049,7 +1066,7 @@ void App::dispatch(const std::string &action, Rml::Element *target) {
|
||||
}
|
||||
static const std::set<std::string> available = {
|
||||
"tables", "strengths", "camp", "settings",
|
||||
"save", "load", "training", "tactics", "calendar", "league", "other", "postpone", "friendlies", "indoor", "almanac", "bank", "balance", "contracts", "environment", "advertising", "toto"};
|
||||
"save", "load", "training", "tactics", "calendar", "league", "other", "postpone", "friendlies", "indoor", "almanac", "bank", "balance", "contracts", "environment", "advertising", "toto", "lineup", "transfer"};
|
||||
if (!available.contains(route)) {
|
||||
message("Diese native Ansicht wird im nächsten Menüpaket übertragen.");
|
||||
return;
|
||||
@@ -1438,6 +1455,8 @@ void App::script() {
|
||||
{"balance_future", balance_future_},
|
||||
{"advertising_view", {{"selected", advertising_selected_}, {"offer", advertising_offer_}}},
|
||||
{"toto_view", {{"column", toto_column_}, {"dialog", toto_dialog_}}},
|
||||
{"lineup_view", {{"pitch", lineup_pitch_}, {"data", lineup_data_}, {"page", lineup_page_}, {"side", lineup_side_}, {"selected", lineup_selected_}, {"drag", lineup_drag_}}},
|
||||
{"transfer_view", transfer_view_}, {"transfer_dialog", transfer_dialog_}, {"transfer_draft", transfer_draft_},
|
||||
{"contracts_view", {{"dialog", contracts_dialog_}, {"player", contracts_player_}, {"tab", contracts_tab_}, {"draft", contract_draft_}}},
|
||||
{"amount_editor", amount_ ? Json{{"title", amount_->request.title}, {"raw", amount_->raw}, {"review", amount_->review}, {"error", amount_error()}} : Json()},
|
||||
{"source_revision", source_ ? Json(snap().revision) : Json()},
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
bool keys(const Json &v, std::initializer_list<const char *> list) {
|
||||
return v.is_object() && v.size() == list.size() && std::all_of(list.begin(), list.end(),
|
||||
[&](auto key) { return v.contains(key); });
|
||||
}
|
||||
bool integer(const Json &v, int lo, int hi) {
|
||||
if (v.is_number_unsigned()) return v.get<uint64_t>() <= uint64_t(hi) &&
|
||||
(lo <= 0 || v.get<uint64_t>() >= uint64_t(lo));
|
||||
return v.is_number_integer() && v.get<int64_t>() >= lo && v.get<int64_t>() <= hi;
|
||||
}
|
||||
bool integers(const Json &v, size_t count, int lo, int hi) {
|
||||
return v.is_array() && v.size() == count && std::all_of(v.begin(), v.end(),
|
||||
[&](const auto &n) { return integer(n, lo, hi); });
|
||||
}
|
||||
bool points(const Json &v) {
|
||||
if (!v.is_array() || v.size() != 11) return false;
|
||||
std::set<std::pair<int,int>> seen;
|
||||
for (const auto &p : v) {
|
||||
if (!p.is_array() || p.size() != 2 || !integer(p[0], 0, 18) || !integer(p[1], 0, 8) ||
|
||||
!seen.emplace(p[0].get<int>(), p[1].get<int>()).second) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::string own(const Catalog &world, const std::string &club, const Json *state = nullptr) {
|
||||
if (!club.empty()) return world.manageable(club) ? club : std::string();
|
||||
if (state && state->is_object() && state->contains("managers")) {
|
||||
const auto &m = state->at("managers");
|
||||
if (!m.is_array() || m.empty() || !m[0].is_object() || !m[0].contains("club") ||
|
||||
!m[0]["club"].is_string()) return {};
|
||||
const auto id = m[0]["club"].get<std::string>();
|
||||
return world.manageable(id) ? id : std::string();
|
||||
}
|
||||
for (auto *c : world.clubs()) if (world.manageable(c->value("id", ""))) return c->value("id", "");
|
||||
return {};
|
||||
}
|
||||
std::string position(const Json &p) {
|
||||
if (!p.contains("positions") || !p.at("positions").is_array()) return {};
|
||||
const auto &pos = p.at("positions");
|
||||
if (std::find(pos.begin(), pos.end(), "gk") != pos.end()) return "gk";
|
||||
for (const auto &v : pos) if (v.is_string()) return v.get<std::string>();
|
||||
return {};
|
||||
}
|
||||
Json attribute(const Json &p, const char *key) {
|
||||
if (!p.contains("attributes") || !p.at("attributes").is_object()) return nullptr;
|
||||
const auto found = p.at("attributes").find(key);
|
||||
return found != p.at("attributes").end() && found->is_number() &&
|
||||
std::isfinite(found->get<double>()) ? *found : Json(nullptr);
|
||||
}
|
||||
bool date(const Json &v) {
|
||||
if (!v.is_string()) return false;
|
||||
const auto &s = v.get_ref<const std::string &>();
|
||||
if (s.size() != 10 || s[4] != '-' || s[7] != '-') return false;
|
||||
for (size_t i = 0; i < s.size(); ++i) if (i != 4 && i != 7 && (s[i] < '0' || s[i] > '9')) return false;
|
||||
return std::chrono::year_month_day{std::chrono::year{std::stoi(s.substr(0,4))},
|
||||
std::chrono::month{unsigned(std::stoi(s.substr(5,2)))},
|
||||
std::chrono::day{unsigned(std::stoi(s.substr(8,2)))}}.ok();
|
||||
}
|
||||
Json age(const Json &p, const Json &reference) {
|
||||
const Json born = p.value("born", p.value("birth_date", Json()));
|
||||
if (date(born) && date(reference)) {
|
||||
const auto b = born.get<std::string>(), r = reference.get<std::string>();
|
||||
const int n = std::stoi(r.substr(0,4)) - std::stoi(b.substr(0,4)) - int(r.substr(5) < b.substr(5));
|
||||
return n >= 0 && n <= 100 ? Json(n) : Json(nullptr);
|
||||
}
|
||||
const auto initial = p.value("age_at_start", Json());
|
||||
return integer(initial, 0, 100) ? initial : Json(nullptr);
|
||||
}
|
||||
void clean_takers(Json &lineup) {
|
||||
const auto &order = lineup.at("order");
|
||||
for (auto &taker : lineup["takers"]) {
|
||||
bool active = false;
|
||||
for (size_t i = 0; i < std::min(size_t(11), order.size()); ++i) if (order[i] == taker) active = true;
|
||||
if (!active) taker = "";
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
Json demo_lineup_formations() {
|
||||
return Json::array({
|
||||
{{0,4},{5,1},{5,3},{5,5},{5,7},{10,1},{10,3},{10,5},{10,7},{16,3},{16,5}},
|
||||
{{0,4},{5,1},{5,3},{5,5},{5,7},{10,2},{10,4},{10,6},{16,1},{16,4},{16,7}},
|
||||
{{0,4},{5,2},{5,4},{5,6},{10,0},{10,2},{10,4},{10,6},{10,8},{16,3},{16,5}},
|
||||
{{0,4},{4,0},{4,2},{4,4},{4,6},{4,8},{10,2},{10,4},{10,6},{16,3},{16,5}}
|
||||
});
|
||||
}
|
||||
Json demo_lineup(const Catalog &world, const std::string &managed) {
|
||||
const auto club = own(world, managed);
|
||||
Json order = Json::array(), orders = Json::object();
|
||||
const auto squad = world.squad(club);
|
||||
std::set<std::string> used;
|
||||
for (const auto &[role, count] : std::array<std::pair<const char *, int>,4>{{{"gk",1},{"def",4},{"mid",4},{"fwd",2}}}) {
|
||||
int n = 0;
|
||||
for (auto *p : squad) if (position(*p) == role && n < count && used.insert(p->at("id").get<std::string>()).second) {
|
||||
order.push_back(p->at("id")); ++n;
|
||||
}
|
||||
}
|
||||
for (auto *p : squad) if (used.insert(p->at("id").get<std::string>()).second) order.push_back(p->at("id"));
|
||||
for (auto *p : squad) orders[p->at("id").get<std::string>()] = {20,20,20,20};
|
||||
return {{"club", club}, {"order", order}, {"points", demo_lineup_formations()[0]},
|
||||
{"formation", 0}, {"custom", {nullptr,nullptr,nullptr,nullptr}},
|
||||
{"weights", {1,2,2}}, {"takers", {"","",""}}, {"orders", orders}};
|
||||
}
|
||||
Json demo_lineup_active(const Json &state) {
|
||||
Json active = Json::array();
|
||||
if (!state.is_object() || !state.contains("lineup") || !state.at("lineup").is_object() ||
|
||||
!state.at("lineup").contains("order") || !state.at("lineup").at("order").is_array()) return active;
|
||||
const auto &order = state.at("lineup").at("order");
|
||||
for (size_t i = 0; i < std::min(size_t(11), order.size()); ++i) {
|
||||
if (!order[i].is_string()) return Json::array();
|
||||
active.push_back(order[i]);
|
||||
}
|
||||
return active;
|
||||
}
|
||||
bool valid_demo_lineup(const Json &state, const Catalog &world, const std::string &managed) {
|
||||
try {
|
||||
if (!state.is_object() || !state.contains("lineup")) return false;
|
||||
const auto &l = state.at("lineup");
|
||||
const auto club = own(world, managed, &state);
|
||||
if (club.empty() || !keys(l, {"club","order","points","formation","custom","weights","takers","orders"}) ||
|
||||
l.at("club") != club || !l.at("order").is_array() || !points(l.at("points")) ||
|
||||
!integer(l.at("formation"), -1, 7) || !l.at("custom").is_array() || l.at("custom").size() != 4 ||
|
||||
!integers(l.at("weights"), 3, 0, 3) || !l.at("takers").is_array() || l.at("takers").size() != 3 ||
|
||||
!l.at("orders").is_object()) return false;
|
||||
for (const auto &p : l.at("custom")) if (!p.is_null() && !points(p)) return false;
|
||||
const int formation = l.at("formation").get<int>();
|
||||
if (formation >= 0 && l.at("points") != (formation < 4 ? demo_lineup_formations()[size_t(formation)] : l.at("custom")[size_t(formation-4)])) return false;
|
||||
std::set<std::string> expected, actual;
|
||||
for (auto *p : world.squad(club)) expected.insert(p->at("id").get<std::string>());
|
||||
if (l.at("order").size() != expected.size() || l.at("orders").size() != expected.size()) return false;
|
||||
for (const auto &id : l.at("order")) if (!id.is_string() || !actual.insert(id.get<std::string>()).second) return false;
|
||||
if (actual != expected) return false;
|
||||
for (const auto &id : expected) if (!l.at("orders").contains(id) || !integers(l.at("orders").at(id), 4, 2, 40)) return false;
|
||||
const auto active = demo_lineup_active(state);
|
||||
for (const auto &id : l.at("takers")) if (!id.is_string() || (id != "" && std::find(active.begin(), active.end(), id) == active.end())) return false;
|
||||
return true;
|
||||
} catch (const std::exception &) { return false; }
|
||||
}
|
||||
bool migrate_demo_lineup(Json &state, const Catalog &world, const std::string &managed) {
|
||||
if (!state.is_object()) return false;
|
||||
auto next = state;
|
||||
if (!next.contains("lineup")) next["lineup"] = demo_lineup(world, own(world, managed, &state));
|
||||
if (!valid_demo_lineup(next, world, managed)) return false;
|
||||
state = std::move(next);
|
||||
return true;
|
||||
}
|
||||
std::string edit_demo_lineup(Json &state, const Json &action, const Catalog &world, const std::string &managed) {
|
||||
if (!valid_demo_lineup(state, world, managed)) return "invalid_lineup_state";
|
||||
if (!action.is_object() || !action.contains("kind") || !action.at("kind").is_string()) return "invalid_lineup_action";
|
||||
auto next = state;
|
||||
auto &l = next["lineup"];
|
||||
const auto kind = action.at("kind").get<std::string>();
|
||||
const auto slot = [&](const Json &id) -> int {
|
||||
if (!id.is_string()) return -1;
|
||||
const auto it = std::find(l.at("order").begin(), l.at("order").end(), id);
|
||||
return it == l.at("order").end() ? -1 : int(it - l.at("order").begin());
|
||||
};
|
||||
if (kind == "swap") {
|
||||
if (!keys(action, {"kind","a","b"})) return "invalid_lineup_action";
|
||||
const int a = slot(action.at("a")), b = slot(action.at("b"));
|
||||
if (a < 0 || b < 0) return "invalid_lineup_player";
|
||||
std::swap(l["order"][size_t(a)], l["order"][size_t(b)]);
|
||||
clean_takers(l);
|
||||
} else if (kind == "move") {
|
||||
if (!keys(action, {"kind","player","point"})) return "invalid_lineup_action";
|
||||
const int from = slot(action.at("player"));
|
||||
const auto &p = action.at("point");
|
||||
if (from < 0 || from >= 11 || !p.is_array() || p.size() != 2 || !integer(p[0],0,18) || !integer(p[1],0,8)) return "invalid_lineup_point";
|
||||
const auto it = std::find(l.at("points").begin(), l.at("points").end(), p);
|
||||
const int hit = int(it - l.at("points").begin());
|
||||
if (hit != from && hit < int(std::min(size_t(11), l.at("order").size()))) {
|
||||
std::swap(l["order"][size_t(from)], l["order"][size_t(hit)]);
|
||||
clean_takers(l);
|
||||
} else if (hit < 11 && hit != from) { std::swap(l["points"][size_t(from)],l["points"][size_t(hit)]); l["formation"]=-1; }
|
||||
else { l["points"][size_t(from)] = p; l["formation"] = -1; }
|
||||
} else if (kind == "formation") {
|
||||
if (!keys(action, {"kind","value"}) || !integer(action.at("value"),0,7)) return "invalid_lineup_formation";
|
||||
const int i = action.at("value").get<int>();
|
||||
const auto p = i < 4 ? demo_lineup_formations()[size_t(i)] : l.at("custom")[size_t(i-4)];
|
||||
if (p.is_null()) return "missing_lineup_formation";
|
||||
l["points"] = p; l["formation"] = i;
|
||||
} else if (kind == "custom-save") {
|
||||
if (!keys(action, {"kind","index"}) || !integer(action.at("index"),0,3)) return "invalid_lineup_formation";
|
||||
const int i = action.at("index").get<int>();
|
||||
l["custom"][size_t(i)] = l.at("points"); l["formation"] = i + 4;
|
||||
} else if (kind == "weight") {
|
||||
if (!keys(action, {"kind","index"}) || !integer(action.at("index"),0,2)) return "invalid_lineup_weight";
|
||||
const size_t i = action.at("index").get<size_t>();
|
||||
l["weights"][i] = (l.at("weights")[i].get<int>()+1)%4;
|
||||
} else if (kind == "order") {
|
||||
if (!keys(action, {"kind","player","index","value"}) || slot(action.at("player")) < 0 || slot(action.at("player")) >= 11 ||
|
||||
!integer(action.at("index"),0,3) || !integer(action.at("value"),2,40)) return "invalid_lineup_order";
|
||||
l["orders"][action.at("player").get<std::string>()][action.at("index").get<size_t>()] = action.at("value");
|
||||
} else if (kind == "taker") {
|
||||
if (!keys(action, {"kind","index","player"}) || !integer(action.at("index"),0,2) || !action.at("player").is_string()) return "invalid_lineup_taker";
|
||||
const int n = slot(action.at("player"));
|
||||
if (action.at("player") != "" && (n < 0 || n >= 11)) return "invalid_lineup_taker";
|
||||
l["takers"][action.at("index").get<size_t>()] = action.at("player");
|
||||
} else if (kind == "takers-auto") {
|
||||
if (!keys(action, {"kind"})) return "invalid_lineup_action";
|
||||
l["takers"] = {"","",""};
|
||||
} else return "unknown_lineup_action";
|
||||
if (!valid_demo_lineup(next, world, managed)) return "invalid_lineup_state";
|
||||
state = std::move(next);
|
||||
return {};
|
||||
}
|
||||
Json demo_lineup_rows(const Json &state, const Catalog &world, const std::string &managed) {
|
||||
if (!valid_demo_lineup(state, world, managed)) return {{"ok",false},{"error","invalid_lineup_state"}};
|
||||
Json rows = Json::array();
|
||||
const auto reference = state.value("date", world.manifest().value("start_date",Json()));
|
||||
const auto &l = state.at("lineup");
|
||||
size_t slot = 0;
|
||||
for (const auto &id : l.at("order")) {
|
||||
const auto *p = world.find("players", id.get<std::string>());
|
||||
if (!p) return {{"ok",false},{"error","missing_lineup_player"}};
|
||||
Json row = {{"id",id},{"name",world.name(*p)},{"position",position(*p)},
|
||||
{"slot",slot},{"starter",slot < 11},{"age",age(*p,reference)},
|
||||
{"nation",p->value("nationalities",Json::array()).is_array() && !p->value("nationalities",Json::array()).empty() ? p->at("nationalities")[0] : p->value("nation",Json())}, {"positions",p->value("positions",Json::array())}};
|
||||
for (const auto *key : {"condition","technique","form","strength","motivation","goals","assists",
|
||||
"corner","free_kick","tackling","passing","shooting","speed","teamplay","games","grade"})
|
||||
row[key] = attribute(*p,key);
|
||||
rows.push_back(std::move(row)); ++slot;
|
||||
}
|
||||
return {{"ok",true},{"club",l.at("club")},{"rows",rows}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,17 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
// Presentation-only lineup. Stable catalogue IDs, all real squad members, no
|
||||
// squad-size cap or world/engine mutation. FULL state is used by all editors.
|
||||
Json demo_lineup(const Catalog &, const std::string &club = {});
|
||||
Json demo_lineup_formations();
|
||||
bool migrate_demo_lineup(Json &, const Catalog &, const std::string &club = {});
|
||||
bool valid_demo_lineup(const Json &, const Catalog &, const std::string &club = {});
|
||||
std::string edit_demo_lineup(Json &, const Json &, const Catalog &, const std::string &club = {});
|
||||
// Shared read-side starting eleven; missing/empty lineups yield an empty array.
|
||||
Json demo_lineup_active(const Json &);
|
||||
// {ok,club,rows:[{id,name,position,...actual nullable catalogue attributes}]}.
|
||||
Json demo_lineup_rows(const Json &, const Catalog &, const std::string &club = {});
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include <array>
|
||||
#include <numeric>
|
||||
#include <sstream>
|
||||
@@ -179,7 +180,8 @@ std::string edit_demo_tactics(Json &state, const Json &action) {
|
||||
return "unknown_tactic_action";
|
||||
return {};
|
||||
}
|
||||
std::string tactics_diagram(const Json &state, const std::string &theme) {
|
||||
std::string tactics_diagram(const Json &state, const std::string &theme,
|
||||
const Json &lineup_points) {
|
||||
const auto values = state.at("values").get<std::array<int, 8>>();
|
||||
const std::string line = theme == "silver" ? "#536f66" : "#dfe8bf";
|
||||
const auto field_line = theme == "silver" ? "#536f66" : "#d7edbf",
|
||||
@@ -217,7 +219,7 @@ std::string tactics_diagram(const Json &state, const std::string &theme) {
|
||||
field(19, 82, 104, 62);
|
||||
field(137, 10, 58, 37);
|
||||
field(205, 10, 58, 37);
|
||||
const std::array<std::pair<int, int>, 10> formation = {{{5, 1},
|
||||
std::array<std::pair<int, int>, 10> formation = {{{5, 1},
|
||||
{5, 3},
|
||||
{5, 5},
|
||||
{5, 7},
|
||||
@@ -227,6 +229,20 @@ std::string tactics_diagram(const Json &state, const std::string &theme) {
|
||||
{10, 7},
|
||||
{16, 3},
|
||||
{16, 5}}};
|
||||
if (!lineup_points.is_null()) {
|
||||
if (!lineup_points.is_array() || lineup_points.size() != 11)
|
||||
throw editor::Error("invalid_lineup_points");
|
||||
std::set<std::pair<int, int>> occupied;
|
||||
for (size_t i = 0; i < lineup_points.size(); ++i) {
|
||||
const auto &p = lineup_points[i];
|
||||
if (!p.is_array() || p.size() != 2 || !p[0].is_number_integer() ||
|
||||
!p[1].is_number_integer() || p[0] < 0 || p[0] > 18 || p[1] < 0 || p[1] > 8)
|
||||
throw editor::Error("invalid_lineup_points");
|
||||
const std::pair point{p[0].get<int>(), p[1].get<int>()};
|
||||
if (!occupied.insert(point).second) throw editor::Error("invalid_lineup_points");
|
||||
if (i) formation[i - 1] = point;
|
||||
}
|
||||
}
|
||||
for (const auto &[x, y] : formation) {
|
||||
const double px = 25 + x / 18.0 * 82, py = 16 + y / 8.0 * 49;
|
||||
arrow(px, py, std::array<int, 4>{-16, -7, 7, 16}[size_t(values[0])], 0);
|
||||
|
||||
@@ -11,5 +11,6 @@ std::string edit_demo_training(Json &, const Json &action);
|
||||
Json demo_tactics();
|
||||
bool valid_demo_tactics(const Json &);
|
||||
std::string edit_demo_tactics(Json &, const Json &action);
|
||||
std::string tactics_diagram(const Json &, const std::string &theme);
|
||||
std::string tactics_diagram(const Json &, const std::string &theme,
|
||||
const Json &lineup_points = Json());
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,307 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include "modern/ui/demo_finance.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <set>
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
constexpr int64_t cap = 99999999, salary_cap = 200000;
|
||||
constexpr std::array<const char *,4> positions{"gk","def","mid","fwd"};
|
||||
constexpr std::array<const char *,7> skills{"corner","free_kick","tackling","passing","shooting","speed","teamplay"};
|
||||
bool keys(const Json &v, std::initializer_list<const char *> expected) {
|
||||
return v.is_object() && v.size() == expected.size() && std::all_of(expected.begin(),expected.end(),[&](auto *k){return v.contains(k);});
|
||||
}
|
||||
bool integer(const Json &v, int64_t lo, int64_t hi) {
|
||||
if (v.is_number_unsigned()) return hi >= 0 && v.get<uint64_t>() <= uint64_t(hi) && (lo <= 0 || v.get<uint64_t>() >= uint64_t(lo));
|
||||
return v.is_number_integer() && v.get<int64_t>() >= lo && v.get<int64_t>() <= hi;
|
||||
}
|
||||
Json error(const char *code) { return {{"ok",false},{"error",code}}; }
|
||||
std::string own(const Catalog &world, const std::string &club) {
|
||||
if (!club.empty()) {
|
||||
if (!world.manageable(club)) throw editor::Error("invalid_transfer_club");
|
||||
return club;
|
||||
}
|
||||
for (auto *c : world.clubs()) if (world.manageable(c->value("id",""))) return c->value("id","");
|
||||
return "";
|
||||
}
|
||||
std::string position(const Json &p) {
|
||||
const auto found = p.find("positions");
|
||||
if (found == p.end() || !found->is_array()) return "";
|
||||
for (auto *role : positions) if (std::find(found->begin(),found->end(),role) != found->end()) return role;
|
||||
return "";
|
||||
}
|
||||
int role_index(const std::string &p) {
|
||||
const auto it = std::find(positions.begin(),positions.end(),p);
|
||||
return int(it - positions.begin());
|
||||
}
|
||||
bool iso(const Json &v) {
|
||||
if (!v.is_string()) return false;
|
||||
const auto s = v.get<std::string>();
|
||||
if (s.size()!=10 || s[4]!='-' || s[7]!='-') return false;
|
||||
for (size_t i=0;i<10;++i) if(i!=4 && i!=7 && (s[i]<'0'||s[i]>'9')) return false;
|
||||
return std::stoi(s.substr(0,4))>0 && std::chrono::year_month_day{std::chrono::year{std::stoi(s.substr(0,4))},std::chrono::month{unsigned(std::stoi(s.substr(5,2)))},std::chrono::day{unsigned(std::stoi(s.substr(8,2)))}}.ok();
|
||||
}
|
||||
Json age(const Json &p, const Json &state, const Catalog &world) {
|
||||
const auto when = state.value("date",world.manifest().value("start_date",Json()));
|
||||
if (p.contains("born") && iso(p.at("born")) && iso(when)) {
|
||||
const auto born=p.at("born").get<std::string>(), day=when.get<std::string>();
|
||||
const int years=std::stoi(day.substr(0,4))-std::stoi(born.substr(0,4))-(day.substr(5)<born.substr(5)?1:0);
|
||||
return years>=0 && years<=100 ? Json(years):Json();
|
||||
}
|
||||
const auto initial=p.value("age_at_start",Json());
|
||||
if(integer(initial,0,100)) return initial;
|
||||
if(initial.is_object() && initial.contains("years") && integer(initial.at("years"),0,100) && initial.value("on",Json())==when) return initial.at("years");
|
||||
return nullptr;
|
||||
}
|
||||
Json attribute(const Json &p, const char *key) {
|
||||
const auto a=p.find("attributes");
|
||||
if(a==p.end()||!a->is_object()) return nullptr;
|
||||
const auto v=a->find(key);
|
||||
return v!=a->end() && v->is_number() && std::isfinite(v->get<double>()) && *v>=0 && *v<=100 ? *v:Json();
|
||||
}
|
||||
Json criteria(int64_t factor) {
|
||||
return {{"age_min",16},{"age_max",40},{"strength_min",0},{"strength_max",100},{"traits",7},{"foot",0},{"type",0},{"price_max",cap*factor}};
|
||||
}
|
||||
bool valid_criteria(const Json &c, int64_t factor) {
|
||||
return keys(c,{"age_min","age_max","strength_min","strength_max","traits","foot","type","price_max"}) &&
|
||||
integer(c.at("age_min"),16,40) && integer(c.at("age_max"),16,40) && c.at("age_min")<=c.at("age_max") &&
|
||||
integer(c.at("strength_min"),0,100) && integer(c.at("strength_max"),0,100) && c.at("strength_min")<=c.at("strength_max") &&
|
||||
integer(c.at("traits"),1,7) && integer(c.at("foot"),0,3) && integer(c.at("type"),0,3) && integer(c.at("price_max"),0,cap*factor);
|
||||
}
|
||||
bool query_text(const Json &v) {
|
||||
if(!v.is_string()) return false;
|
||||
const auto &s=v.get_ref<const std::string&>(); size_t chars=0;
|
||||
for(size_t i=0;i<s.size();) {
|
||||
const auto c=static_cast<unsigned char>(s[i]); size_t n= c<128?1:c>=194&&c<=223?2:c>=224&&c<=239?3:c>=240&&c<=244?4:0;
|
||||
if(!n || i+n>s.size() || c<32) return false;
|
||||
for(size_t k=1;k<n;++k) if((static_cast<unsigned char>(s[i+k])&192)!=128) return false;
|
||||
if((c==224 && static_cast<unsigned char>(s[i+1])<160)||(c==237 && static_cast<unsigned char>(s[i+1])>=160)||(c==240 && static_cast<unsigned char>(s[i+1])<144)||(c==244 && static_cast<unsigned char>(s[i+1])>=144)) return false;
|
||||
i+=n; if(++chars>40) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::string fold(std::string s) {
|
||||
for(const auto &[a,b]:std::initializer_list<std::pair<std::string,std::string>>{
|
||||
{"Ä","a"},{"ä","a"},{"Ö","o"},{"ö","o"},{"Ü","u"},{"ü","u"},{"ẞ","ss"},{"ß","ss"},
|
||||
{"É","e"},{"é","e"},{"È","e"},{"è","e"},{"Ê","e"},{"ê","e"},{"Ë","e"},{"ë","e"},
|
||||
{"Á","a"},{"á","a"},{"À","a"},{"à","a"},{"Â","a"},{"â","a"},{"Ã","a"},{"ã","a"},{"Å","a"},{"å","a"},
|
||||
{"Í","i"},{"í","i"},{"Ì","i"},{"ì","i"},{"Î","i"},{"î","i"},{"İ","i"},
|
||||
{"Ñ","n"},{"ñ","n"},{"Ç","c"},{"ç","c"},{"Ł","l"},{"ł","l"},
|
||||
{"Ó","o"},{"ó","o"},{"Ò","o"},{"ò","o"},{"Ô","o"},{"ô","o"},{"Õ","o"},{"õ","o"},{"Ø","o"},{"ø","o"},
|
||||
{"Ú","u"},{"ú","u"},{"Ù","u"},{"ù","u"},{"Û","u"},{"û","u"},{"Æ","ae"},{"æ","ae"},{"Œ","oe"},{"œ","oe"},
|
||||
{"Ś","s"},{"ś","s"},{"Ć","c"},{"ć","c"},{"Ź","z"},{"ź","z"},{"Ż","z"},{"ż","z"}}) {
|
||||
size_t at=0;while((at=s.find(a,at))!=std::string::npos){s.replace(at,a.size(),b);at+=b.size();}
|
||||
}
|
||||
for(auto &c:s) if(c>='A'&&c<='Z') c=char(c-'A'+'a');
|
||||
return s;
|
||||
}
|
||||
std::vector<const Json*> market_players(const Catalog &world, const std::string &club) {
|
||||
if(club.empty()) return {};
|
||||
std::vector<const Json*> clubs;
|
||||
for(auto *c:world.clubs()) {
|
||||
auto *l=world.find("competitions",c->value("competition",""));
|
||||
if(c->at("id")!=club && l && l->value("type","")=="league") clubs.push_back(c);
|
||||
}
|
||||
std::vector<const Json*> out;std::set<std::string> used;
|
||||
for(int slot=0;slot<12 && !clubs.empty();++slot) {
|
||||
const Json *chosen=nullptr;
|
||||
for(size_t offset=0;offset<clubs.size()&&!chosen;++offset) {
|
||||
const auto squad=world.squad(clubs[(size_t(slot)+offset)%clubs.size()]->at("id"));
|
||||
for(auto *p:squad) if(!used.contains(p->at("id")) && position(*p)==positions[size_t(slot)%4]) {chosen=p;break;}
|
||||
if(!chosen) for(auto *p:squad) if(!used.contains(p->at("id"))) {chosen=p;break;}
|
||||
}
|
||||
if(!chosen) break;
|
||||
used.insert(chosen->at("id").get<std::string>());out.push_back(chosen);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
bool available(const Catalog &world, const Json *p) {
|
||||
if(!p) return false;
|
||||
auto *c=world.find("clubs",p->value("team",""));
|
||||
auto *l=c?world.find("competitions",c->value("competition","")):nullptr;
|
||||
return c && c->value("type","club")=="club" && l && l->value("type","")=="league";
|
||||
}
|
||||
Json row(const Json &state, const Catalog &world, const std::string &club, const Json &p, const std::vector<const Json*> *cached_market = nullptr) {
|
||||
const auto factor=finance_currency_factor(world);
|
||||
const auto id=p.at("id").get<std::string>(), team=p.value("team","");
|
||||
const bool is_own=team==club;
|
||||
auto squad=world.squad(team);auto at=std::find(squad.begin(),squad.end(),&p);
|
||||
size_t ordinal=at==squad.end()?0:size_t(at-squad.begin());
|
||||
const auto market=cached_market?*cached_market:market_players(world,club);auto candidate=std::find(market.begin(),market.end(),&p);
|
||||
if(candidate!=market.end()) ordinal=size_t(candidate-market.begin());
|
||||
const int64_t fee=std::min<int64_t>(cap,(is_own?600000:450000)+int64_t(std::min<size_t>(ordinal,500))* (is_own?95000:170000))*factor;
|
||||
Json strength=attribute(p,"strength");
|
||||
const auto cond=attribute(p,"condition"),tech=attribute(p,"technique"),form=attribute(p,"form");
|
||||
if(strength.is_null()&&!cond.is_null()&&!tech.is_null()&&!form.is_null()) strength=int(std::floor((cond.get<double>()+tech.get<double>()+form.get<double>())/3));
|
||||
Json salary=nullptr;
|
||||
if(is_own&&state.contains("contracts")&&state.at("contracts").is_object()) {
|
||||
const auto players=state.at("contracts").find("players");
|
||||
if(players!=state.at("contracts").end()&&players->is_object()&&players->contains(id)) {
|
||||
const auto &c=players->at(id);if(c.is_object()&&c.contains("salary")&&integer(c.at("salary"),0,salary_cap*factor)) salary=c.at("salary");
|
||||
}
|
||||
}
|
||||
const auto *c=world.find("clubs",team);
|
||||
Json nation=nullptr; const auto ns=p.find("nationalities");
|
||||
if(ns!=p.end()&&ns->is_array()&&!ns->empty()&&(*ns)[0].is_string()&&world.find("nations",(*ns)[0])) nation=(*ns)[0];
|
||||
Json skill=Json::array();for(auto *key:skills)skill.push_back(attribute(p,key));
|
||||
Json foot=attribute(p,"foot"),type=attribute(p,"type");
|
||||
if(!integer(foot,1,3))foot=nullptr;
|
||||
if(!integer(type,1,3))type=nullptr;
|
||||
return {{"id",id},{"name",world.name(p)},{"club",team},{"club_name",c?world.name(*c):""},{"crest",c?c->value("crest",Json()):Json()},
|
||||
{"photo",p.value("photo",Json())},{"position",position(p).empty()?Json():Json(position(p))},{"age",age(p,state,world)},
|
||||
{"condition",cond},{"technique",tech},{"form",form},{"strength",strength},{"foot",foot},{"type",type},
|
||||
{"nation",nation},{"nation_name",nation.is_string()?world.nation_name(nation.get<std::string>()):""},{"skills",skill},
|
||||
{"games",attribute(p,"games")},{"goals",attribute(p,"goals")},{"assists",attribute(p,"assists")},
|
||||
{"league_games",attribute(p,"league_games")},{"cup_games",attribute(p,"cup_games")},{"europe_games",attribute(p,"europe_games")},
|
||||
{"fee",fee},{"salary",salary},{"own",is_own}};
|
||||
}
|
||||
bool valid_order(const Json &o, const Catalog &world, const std::string &club, int64_t factor) {
|
||||
if(!keys(o,{"kind","player","source_club","fee","salary","months","bonuses","poached"}) ||!o.at("kind").is_string()||!o.at("player").is_string()||!o.at("source_club").is_string()||!o.at("poached").is_boolean())return false;
|
||||
const auto kind=o.at("kind").get<std::string>();const bool is_own=kind=="sell"||kind=="lend",loan=kind=="loan"||kind=="lend";
|
||||
const auto *p=world.find("players",o.at("player"));
|
||||
if(!(is_own||kind=="buy"||kind=="loan")||!available(world,p)||p->value("team","")!=o.at("source_club").get<std::string>()||is_own!=(p->value("team","")==club))return false;
|
||||
if(is_own&&o.at("poached")!=false)return false;
|
||||
if(!is_own&&o.at("poached")==false) {
|
||||
const auto market=market_players(world,club);if(std::find(market.begin(),market.end(),p)==market.end())return false;
|
||||
}
|
||||
if(!integer(o.at("fee"),0,cap*factor)||!integer(o.at("salary"),0,salary_cap*factor)||!integer(o.at("months"),12,48)||
|
||||
!(o.at("months")==12||o.at("months")==24||(!loan&&(o.at("months")==36||o.at("months")==48)))||!o.at("bonuses").is_array()||o.at("bonuses").size()!=7)return false;
|
||||
return std::all_of(o.at("bonuses").begin(),o.at("bonuses").end(),[&](const auto &v){return integer(v,0,100*factor);});
|
||||
}
|
||||
bool same_order_target(const Json &a,const Json &b) {
|
||||
const bool own=a.at("kind")=="sell"||a.at("kind")=="lend";
|
||||
return a.at("player")==b.at("player")&&a.at("source_club")==b.at("source_club")&&
|
||||
(own?(b.at("kind")=="sell"||b.at("kind")=="lend"):a.at("kind")==b.at("kind"));
|
||||
}
|
||||
} // namespace
|
||||
Json demo_transfer(const Catalog &world,const std::string &requested) {
|
||||
const auto club=own(world,requested);return {{"club",club},{"query",""},{"positions",15},{"criteria",criteria(finance_currency_factor(world))},{"listed",Json::array()},{"orders",Json::array()}};
|
||||
}
|
||||
bool valid_demo_transfer(const Json &state,const Catalog &world,const std::string &requested) {
|
||||
try {
|
||||
const auto club=own(world,requested);
|
||||
const auto factor=finance_currency_factor(world);const auto &t=state.at("transfer");
|
||||
if(!keys(t,{"club","query","positions","criteria","listed","orders"})||t.at("club")!=club||!query_text(t.at("query"))||!integer(t.at("positions"),1,15)||!valid_criteria(t.at("criteria"),factor)||!t.at("listed").is_array()||t.at("listed").size()>3||!t.at("orders").is_array()||t.at("orders").size()>50)return false;
|
||||
std::set<std::string> listed,required;
|
||||
for(const auto &p:t.at("listed")){if(!p.is_string()||!listed.insert(p.get<std::string>()).second)return false;const auto *r=world.find("players",p);if(!r||r->value("team","")!=club)return false;}
|
||||
std::vector<Json> accepted;
|
||||
for(const auto &o:t.at("orders")) {
|
||||
if(!valid_order(o,world,club,factor)||std::any_of(accepted.begin(),accepted.end(),[&](const auto&a){return same_order_target(a,o);}))return false;
|
||||
if(o.at("kind")=="sell"||o.at("kind")=="lend")required.insert(o.at("player").get<std::string>());
|
||||
accepted.push_back(o);
|
||||
}
|
||||
return listed==required;
|
||||
}catch(const std::exception&){return false;}
|
||||
}
|
||||
bool migrate_demo_transfer(Json &state,const Catalog &world,const std::string &club) {
|
||||
try{if(!state.is_object())return false;if(state.contains("transfer"))return valid_demo_transfer(state,world,club);auto next=state;next["transfer"]=demo_transfer(world,club);if(!valid_demo_transfer(next,world,club))return false;state=std::move(next);return true;}catch(const std::exception&){return false;}
|
||||
}
|
||||
std::string edit_demo_transfer(Json &state,const Json &action,const Catalog &world,const std::string &requested) {
|
||||
if(!valid_demo_transfer(state,world,requested))return "invalid_transfer_state";
|
||||
try {
|
||||
if(!action.is_object()||!action.contains("kind")||!action.at("kind").is_string())return "invalid_transfer_action";
|
||||
auto next=state;auto &t=next["transfer"];const auto club=own(world,requested);const auto factor=finance_currency_factor(world);const auto kind=action.at("kind").get<std::string>();
|
||||
if(kind=="search") {if(!keys(action,{"kind","query"})||!query_text(action.at("query")))return "invalid_transfer_query";
|
||||
t["query"]=action.at("query");}
|
||||
else if(kind=="criteria") {
|
||||
if(!keys(action,{"kind","value","positions"})||!integer(action.at("positions"),1,15))return "invalid_transfer_criteria";
|
||||
auto c=action.at("value");if(!c.is_object()||!c.contains("price_max")||!integer(c.at("price_max"),0,cap))return "invalid_transfer_criteria";
|
||||
c["price_max"]=c.at("price_max").get<int64_t>()*factor;if(!valid_criteria(c,factor))return "invalid_transfer_criteria";
|
||||
t["criteria"]=c;t["positions"]=action.at("positions");t["query"]="";
|
||||
} else if(kind=="positions") {if(!keys(action,{"kind","value"})||!integer(action.at("value"),1,15))return "invalid_transfer_criteria";
|
||||
t["positions"]=action.at("value");}
|
||||
else if(kind=="unlist") {
|
||||
if(!keys(action,{"kind","player"})||!action.at("player").is_string())return "invalid_transfer_player";
|
||||
const auto id=action.at("player").get<std::string>();auto &ls=t["listed"];auto it=std::find(ls.begin(),ls.end(),id);if(it==ls.end())return "transfer_not_listed";
|
||||
ls.erase(it);auto &os=t["orders"];os.erase(std::remove_if(os.begin(),os.end(),[&](const auto&o){return o.at("player")==id&&(o.at("kind")=="sell"||o.at("kind")=="lend");}),os.end());
|
||||
} else if(kind=="remove") {
|
||||
if(!keys(action,{"kind","index"})||!integer(action.at("index"),0,int64_t(t["orders"].size())-1))return "invalid_transfer_order";
|
||||
const auto index=action.at("index").get<size_t>();const auto removed=t["orders"][index];t["orders"].erase(t["orders"].begin()+ptrdiff_t(index));if(removed.at("kind")=="sell"||removed.at("kind")=="lend"){auto &ls=t["listed"];auto it=std::find(ls.begin(),ls.end(),removed.at("player"));if(it!=ls.end())ls.erase(it);}
|
||||
} else if(kind=="submit") {
|
||||
if(!keys(action,{"kind","order"}))return "invalid_transfer_order";
|
||||
auto o=action.at("order");
|
||||
if(!keys(o,{"kind","player","source_club","fee","salary","months","bonuses","poached"})||!integer(o.at("fee"),0,cap)||!integer(o.at("salary"),0,salary_cap)||!o.at("bonuses").is_array()||o.at("bonuses").size()!=7)return "invalid_transfer_order";
|
||||
for(auto &b:o["bonuses"]){if(!integer(b,0,100))return "invalid_transfer_order";
|
||||
b=b.get<int64_t>()*factor;}
|
||||
o["fee"]=o.at("fee").get<int64_t>()*factor;o["salary"]=o.at("salary").get<int64_t>()*factor;if(!valid_order(o,world,club,factor))return "invalid_transfer_order";
|
||||
const bool is_own=o.at("kind")=="sell"||o.at("kind")=="lend";auto &os=t["orders"];auto it=std::find_if(os.begin(),os.end(),[&](const auto&a){return same_order_target(a,o);});
|
||||
if(it==os.end()){if(os.size()>=50)return "transfer_orders_full";
|
||||
os.push_back(o);}else *it=o;
|
||||
if(is_own&&std::find(t["listed"].begin(),t["listed"].end(),o.at("player"))==t["listed"].end()){if(t["listed"].size()>=3)return "transfer_list_full";
|
||||
t["listed"].push_back(o.at("player"));}
|
||||
}else return "unknown_transfer_action";
|
||||
if(!valid_demo_transfer(next,world,requested))return "invalid_transfer_state";
|
||||
state=std::move(next);return {};
|
||||
}catch(const std::exception&){return "invalid_transfer_action";}
|
||||
}
|
||||
Json demo_transfer_player(const Json &state,const Catalog &world,const std::string &requested,const std::string &id) {
|
||||
if(!valid_demo_transfer(state,world,requested))return error("invalid_transfer_state");
|
||||
const auto *p=world.find("players",id);if(!available(world,p))return error("invalid_transfer_player");
|
||||
return {{"ok",true},{"row",row(state,world,own(world,requested),*p)}};
|
||||
}
|
||||
Json demo_transfer_view(const Json &state,const Catalog &world,const std::string &requested) {
|
||||
if(!valid_demo_transfer(state,world,requested))return error("invalid_transfer_state");
|
||||
const auto club=own(world,requested);const auto &t=state.at("transfer"),&c=t.at("criteria");Json ours=Json::array(),market=Json::array(),orders=Json::array();
|
||||
const auto candidates=market_players(world,club);
|
||||
if(!club.empty())for(auto *p:world.squad(club))ours.push_back(row(state,world,club,*p,&candidates));
|
||||
std::vector<Json> pool;for(auto *p:candidates)pool.push_back(row(state,world,club,*p,&candidates));for(const auto &id:t.at("listed"))pool.push_back(row(state,world,club,*world.find("players",id),&candidates));
|
||||
const auto inrange=[](const Json&v,int low,int high,int defaultlow,int defaulthigh){return v.is_null()?(low==defaultlow&&high==defaulthigh):v>=low&&v<=high;};
|
||||
std::erase_if(pool,[&](const auto&p){
|
||||
const int index=role_index(p.at("position").is_string()?p.at("position").template get<std::string>():"");const int mask=t.at("positions");if(index==4?mask!=15:!(mask&(1<<index)))return true;
|
||||
if(fold(p.at("name").template get<std::string>()).find(fold(t.at("query").template get<std::string>()))==std::string::npos)return true;
|
||||
if(!inrange(p.at("age"),c.at("age_min"),c.at("age_max"),16,40))return true;
|
||||
Json strength=nullptr;double sum=0;int count=0;bool known=true;int bit=0;
|
||||
for(auto *field:{"condition","technique","form"}){if(c.at("traits").template get<int>()&(1<<bit)){if(p.at(field).is_null())known=false;else{sum+=p.at(field).template get<double>();++count;}}++bit;}
|
||||
if(known&&count)strength=int(std::floor(sum/count));
|
||||
if(!inrange(strength,c.at("strength_min"),c.at("strength_max"),0,100))return true;
|
||||
return (c.at("foot")!=0&&c.at("foot")!=p.at("foot"))||(c.at("type")!=0&&c.at("type")!=p.at("type"))||p.at("fee")>c.at("price_max");
|
||||
});
|
||||
std::stable_sort(pool.begin(),pool.end(),[](const auto&a,const auto&b){const int pa=role_index(a.at("position").is_string()?a.at("position").template get<std::string>():""),pb=role_index(b.at("position").is_string()?b.at("position").template get<std::string>():"");if(pa!=pb)return pa<pb;if(a.at("strength").is_null()!=b.at("strength").is_null())return !a.at("strength").is_null();if(a.at("strength")!=b.at("strength"))return a.at("strength")>b.at("strength");return a.at("own")==false&&b.at("own")==true;});
|
||||
for(const auto &p:pool)market.push_back(p);
|
||||
for(const auto &o:t.at("orders")){auto display=o;auto *p=world.find("players",o.at("player"));display["name"]=world.name(*p);orders.push_back(display);}
|
||||
return {{"ok",true},{"club",club},{"own",ours},{"market",market},{"orders",orders},{"criteria",c},{"positions",t.at("positions")},{"query",t.at("query")}};
|
||||
}
|
||||
Json demo_transfer_roster(const Json &state,const Catalog &world,const std::string &requested,const std::string &team) {
|
||||
if(!valid_demo_transfer(state,world,requested))return error("invalid_transfer_state");
|
||||
const auto *c=world.find("clubs",team);
|
||||
if(!c||c->value("type","club")!="club")return error("invalid_transfer_club");
|
||||
const auto club=own(world,requested);const auto candidates=market_players(world,club);Json rows=Json::array();
|
||||
for(auto *p:world.squad(team))if(available(world,p))rows.push_back(row(state,world,club,*p,&candidates));
|
||||
return {{"ok",true},{"club",team},{"rows",rows}};
|
||||
}
|
||||
Json demo_transfer_quote(const Json &state,const Json &request,const Catalog &world,const std::string &requested) {
|
||||
if(!valid_demo_transfer(state,world,requested))return error("invalid_transfer_state");
|
||||
try {
|
||||
if(!keys(request,{"kind","player","poached"})||!request.at("kind").is_string()||!request.at("player").is_string()||!request.at("poached").is_boolean())return error("invalid_transfer_quote");
|
||||
const auto club=own(world,requested),kind=request.at("kind").get<std::string>();const auto factor=finance_currency_factor(world);const bool is_own=kind=="sell"||kind=="lend",loan=kind=="loan"||kind=="lend";auto *p=world.find("players",request.at("player"));if(!available(world,p))return error("invalid_transfer_player");
|
||||
auto r=row(state,world,club,*p);
|
||||
Json order={{"kind",kind},{"player",request.at("player")},{"source_club",p->at("team")},{"fee",0},{"salary",0},{"months",12},{"bonuses",{0,0,0,0,0,0,0}},{"poached",request.at("poached")}};
|
||||
if(!valid_order(order,world,club,factor))return error("invalid_transfer_player");
|
||||
if(is_own&&std::find(state.at("transfer").at("listed").begin(),state.at("transfer").at("listed").end(),request.at("player"))==state.at("transfer").at("listed").end()&&state.at("transfer").at("listed").size()>=3)return error("transfer_list_full");
|
||||
const auto value=r.at("fee").get<int64_t>();const int64_t price=request.at("poached")==true?std::min(cap*factor,((value/factor*3+1)/2)*factor):value;
|
||||
const Json salary=is_own?r.at("salary"):Json(25000*factor);order["fee"]=loan?50000*factor:price;order["salary"]=salary.is_null()?Json(0):salary;order["months"]=loan?12:24;
|
||||
for(const auto&o:state.at("transfer").at("orders"))if(o.at("kind")==kind&&o.at("player")==request.at("player")&&o.at("source_club")==p->at("team")){order=o;break;}
|
||||
const auto &orders=state.at("transfer").at("orders");
|
||||
const bool can_submit=orders.size()<50||std::any_of(orders.begin(),orders.end(),[&](const auto &saved){return same_order_target(saved,order);});
|
||||
return {{"ok",true},{"can_submit",can_submit},{"row",r},{"kind",kind},{"source_club",p->at("team")},{"poached",request.at("poached")},
|
||||
{"demand_fee",loan?Json(50000*factor):Json(price)},{"demand_salary",salary},{"fee",order.at("fee")},{"salary",order.at("salary")},{"months",order.at("months")},{"bonuses",order.at("bonuses")}};
|
||||
}catch(const std::exception&){return error("invalid_transfer_quote");}
|
||||
}
|
||||
Json demo_transfer_strengths(const Json &state,const Catalog &world,const std::string &requested,const Json &active) {
|
||||
if(!valid_demo_transfer(state,world,requested))return error("invalid_transfer_state");
|
||||
const auto club=own(world,requested);std::set<std::string> selected;if(active.is_array())for(const auto&id:active)if(id.is_string())selected.insert(id.get<std::string>());
|
||||
std::array<double,5> sa{},st{};std::array<int,5> ca{},ct{};const auto candidates=market_players(world,club);
|
||||
if(!club.empty())for(auto *p:world.squad(club)){const auto r=row(state,world,club,*p,&candidates);if(r.at("strength").is_null())continue;const auto strength=r.at("strength").get<double>();const auto pos=role_index(position(*p));st[4]+=strength;++ct[4];if(pos<4){st[size_t(pos)]+=strength;++ct[size_t(pos)];}if(selected.contains(p->at("id"))){sa[4]+=strength;++ca[4];if(pos<4){sa[size_t(pos)]+=strength;++ca[size_t(pos)];}}}
|
||||
Json a=Json::array(),t=Json::array();for(size_t i=0;i<4;++i){a.push_back(ca[i]?Json(int(std::floor(sa[i]/ca[i]))):Json());t.push_back(ct[i]?Json(int(std::floor(st[i]/ct[i]))):Json());}
|
||||
return {{"ok",true},{"active",a},{"team",t},{"active_average",ca[4]?Json(int(std::floor(sa[4]/ca[4]))):Json()},{"team_average",ct[4]?Json(int(std::floor(st[4]/ct[4]))):Json()}};
|
||||
}
|
||||
Json demo_transfer_suggestion(const Json &state,const Catalog &world,const std::string &club,const Json &active) {
|
||||
const auto values=demo_transfer_strengths(state,world,club,active);if(!values.value("ok",false))return values;int weakest=0;int score=101;for(int i=0;i<4;++i)if(values.at("active")[size_t(i)].is_number_integer()&&values.at("active")[size_t(i)].get<int>()<score){score=values.at("active")[size_t(i)];weakest=i;}
|
||||
const auto factor=finance_currency_factor(world);auto c=criteria(factor);c["age_min"]=18;c["age_max"]=28;c["strength_min"]=values.at("active_average").is_number_integer()?values.at("active_average"):Json(0);const auto cash=state.value("cash",Json());c["price_max"]=integer(cash,0,cap*factor)?Json(std::min<int64_t>(cash.get<int64_t>(),3000000*factor)):Json(0);return {{"ok",true},{"criteria",c},{"positions",1<<weakest}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,20 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
#include "modern/ui/catalog.hpp"
|
||||
|
||||
namespace bmh::modern_ui {
|
||||
// Presentation-only search, listings and provisional orders. No player, cash,
|
||||
// contract, session or RNG is changed. Model money is minor units; submit and
|
||||
// criteria editor actions use whole displayed units (including seven bonuses).
|
||||
Json demo_transfer(const Catalog &, const std::string &club);
|
||||
bool migrate_demo_transfer(Json &full_state, const Catalog &, const std::string &club);
|
||||
bool valid_demo_transfer(const Json &full_state, const Catalog &, const std::string &club);
|
||||
std::string edit_demo_transfer(Json &full_state, const Json &action, const Catalog &, const std::string &club);
|
||||
Json demo_transfer_view(const Json &full_state, const Catalog &, const std::string &club);
|
||||
Json demo_transfer_player(const Json &full_state, const Catalog &, const std::string &club, const std::string &player);
|
||||
Json demo_transfer_roster(const Json &full_state, const Catalog &, const std::string &club, const std::string &source_club);
|
||||
Json demo_transfer_quote(const Json &full_state, const Json &request, const Catalog &, const std::string &club);
|
||||
// Active IDs come from the lineup source; the transfer module never creates XI.
|
||||
Json demo_transfer_strengths(const Json &full_state, const Catalog &, const std::string &club, const Json &active_ids);
|
||||
Json demo_transfer_suggestion(const Json &full_state, const Catalog &, const std::string &club, const Json &active_ids);
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,193 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::cancel_lineup_drag(bool refresh_view) {
|
||||
lineup_drag_=Json(); lineup_drag_world_.reset(); lineup_drag_revision_=0;
|
||||
if (auto *ghost=element("lineup-ghost")) ghost->SetProperty("display","none");
|
||||
if (refresh_view) refresh();
|
||||
}
|
||||
bool App::lineup_action(const std::string &action,Rml::Element *target) {
|
||||
if (!action.starts_with("lineup-") || menu_!="lineup") return false;
|
||||
if (!source_ || !target || !popup_.empty() || amount_ || !report_detail_kind_.empty()) return true;
|
||||
if (lineup_ignore_click_ && action=="lineup-player") {lineup_ignore_click_=false;return true;}
|
||||
const auto id=target->GetAttribute<Rml::String>("data-id","");
|
||||
const auto s=snap();
|
||||
if (!s.world || !valid_demo_lineup(s.state,*s.world,lineup_managed(s))) return true;
|
||||
const auto &l=s.state.at("lineup");
|
||||
const auto small=[&](int max)->int {return id.size()==1 && id[0]>='0' && id[0]<='0'+max ? id[0]-'0':-1;};
|
||||
const auto commit=[&](const Json &payload,const std::string &focus) {
|
||||
const auto result=source_->apply({s.revision,"lineup",payload});
|
||||
if (!result.ok) {message("Die Aufstellung konnte nicht übernommen werden. Bitte die Ansicht erneut öffnen.");return false;}
|
||||
focus_after_render_=focus; refresh(); return true;
|
||||
};
|
||||
const auto player_focus=[&](const std::string &p) {
|
||||
const int slot=lineup_slot(l,p);
|
||||
return std::string(lineup_pitch_?(slot<11?"lineup-player-":"lineup-bench-"):"lineup-name-")+p;
|
||||
};
|
||||
if (action=="lineup-player") {
|
||||
if (lineup_slot(l,id)<0) return true;
|
||||
if (lineup_selected_==id) lineup_selected_.clear();
|
||||
else if (!lineup_selected_.empty()) {
|
||||
const auto selected=lineup_selected_; lineup_selected_.clear();
|
||||
const int destination=lineup_slot(l,selected);
|
||||
const auto focus=std::string(lineup_pitch_?(destination<11?"lineup-player-":"lineup-bench-"):"lineup-name-")+id;
|
||||
commit({{"kind","swap"},{"a",selected},{"b",id}},focus); return true;
|
||||
} else lineup_selected_=id;
|
||||
focus_after_render_=player_focus(id); refresh(); return true;
|
||||
}
|
||||
if (action=="lineup-data") {lineup_data_=1-lineup_data_;focus_after_render_="lineup-data";refresh();return true;}
|
||||
if (action=="lineup-view") {cancel_lineup_drag(false);lineup_pitch_=!lineup_pitch_;lineup_reset_scroll_=true;focus_after_render_="lineup-view";refresh();return true;}
|
||||
if (action=="lineup-side") {
|
||||
if (id=="formations" || id=="orders" || id=="takers") {lineup_side_=id;focus_after_render_="lineup-side-"+id;refresh();}
|
||||
return true;
|
||||
}
|
||||
if (action=="lineup-page") {const int n=small(1);if(n>=0) {lineup_page_=n;focus_after_render_=n?"lineup-page-prev":"lineup-page-next";refresh();}return true;}
|
||||
if (action=="lineup-formation") {const int n=small(7);if(n>=0) {lineup_selected_.clear();commit({{"kind","formation"},{"value",n}},"lineup-formation-"+id);}return true;}
|
||||
if (action=="lineup-save") {const int n=small(3);if(n>=0)commit({{"kind","custom-save"},{"index",n}},"lineup-save-"+id);return true;}
|
||||
if (action=="lineup-weight") {const int n=small(2);if(n>=0)commit({{"kind","weight"},{"index",n}},"lineup-weight-"+id);return true;}
|
||||
if (action=="lineup-auto") {commit({{"kind","takers-auto"}},"lineup-auto");return true;}
|
||||
return true;
|
||||
}
|
||||
bool App::lineup_event(Rml::Event &event) {
|
||||
if (menu_!="lineup" || !source_ || !popup_.empty() || amount_ || !report_detail_kind_.empty()) return false;
|
||||
const auto type=event.GetType();
|
||||
auto *target=event.GetTargetElement();
|
||||
const auto ancestor=[&](const std::string &attribute)->Rml::Element* {
|
||||
for(auto *n=target;n && n!=doc_;n=n->GetParentNode()) if(n->HasAttribute(attribute))return n;
|
||||
return nullptr;
|
||||
};
|
||||
auto *player_node=ancestor("data-squad-player");
|
||||
auto *pitch=element("lineup-pitch");
|
||||
const auto s=snap();
|
||||
if (!s.world || !valid_demo_lineup(s.state,*s.world,lineup_managed(s))) {cancel_lineup_drag(false);return false;}
|
||||
const auto &l=s.state.at("lineup");
|
||||
const auto stop=[&]() {event.StopImmediatePropagation();};
|
||||
const auto commit=[&](const Json &payload,uint64_t revision) {
|
||||
const auto result=source_->apply({revision,"lineup",payload});
|
||||
if(!result.ok)message("Die Aufstellung hat sich geändert. Bitte den Spieler erneut auswählen.");
|
||||
return result.ok;
|
||||
};
|
||||
const auto point=[&](float x,float y)->Json {
|
||||
if(!pitch)return Json();
|
||||
const auto origin=pitch->GetAbsoluteOffset(Rml::BoxArea::Border), size=pitch->GetBox().GetSize(Rml::BoxArea::Border);
|
||||
if(size.x<=0 || size.y<=0)return Json();
|
||||
return Json::array({std::clamp(int(std::round(((x-origin.x)/size.x*100-8)/84*18)),0,18),std::clamp(int(std::round(((y-origin.y)/size.y*100-10)/80*8)),0,8)});
|
||||
};
|
||||
const auto in_pitch=[&](float x,float y) {
|
||||
if(!pitch)return false;
|
||||
const auto origin=pitch->GetAbsoluteOffset(Rml::BoxArea::Border), size=pitch->GetBox().GetSize(Rml::BoxArea::Border);
|
||||
return x>=origin.x && y>=origin.y && x<=origin.x+size.x && y<=origin.y+size.y;
|
||||
};
|
||||
const float mx=event.GetParameter<float>("mouse_x",0),my=event.GetParameter<float>("mouse_y",0);
|
||||
if(type=="keydown") {
|
||||
lineup_ignore_click_=false;
|
||||
const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
|
||||
if(key==Rml::Input::KI_ESCAPE) {
|
||||
for(auto *n=target;n && n!=doc_;n=n->GetParentNode())
|
||||
if(auto *select=dynamic_cast<Rml::ElementFormControlSelect*>(n);select && select->IsSelectBoxVisible())return false;
|
||||
if(!lineup_drag_.is_null()) {cancel_lineup_drag(true);stop();return true;}
|
||||
if(!lineup_selected_.empty()) {lineup_selected_.clear();refresh();stop();return true;}
|
||||
return false;
|
||||
}
|
||||
if(pitch && player_node && player_node->IsClassSet("lineup-player") && (key==Rml::Input::KI_LEFT || key==Rml::Input::KI_RIGHT || key==Rml::Input::KI_UP || key==Rml::Input::KI_DOWN)) {
|
||||
const auto id=player_node->GetAttribute<Rml::String>("data-squad-player","");
|
||||
const int slot=lineup_slot(l,id);
|
||||
if(slot>=0 && slot<11) {
|
||||
auto p=l.at("points")[size_t(slot)];
|
||||
p[0]=std::clamp(p[0].get<int>()+(key==Rml::Input::KI_RIGHT?1:key==Rml::Input::KI_LEFT?-1:0),0,18);
|
||||
p[1]=std::clamp(p[1].get<int>()+(key==Rml::Input::KI_DOWN?1:key==Rml::Input::KI_UP?-1:0),0,8);
|
||||
lineup_selected_=id;commit({{"kind","move"},{"player",id},{"point",p}},s.revision);
|
||||
focus_after_render_="lineup-player-"+id;refresh();stop();return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if((type=="change" || type=="input") && target) {
|
||||
if(auto *control=dynamic_cast<Rml::ElementFormControl*>(target)) {
|
||||
if(target->HasAttribute("data-lineup-taker")) {
|
||||
const auto index=target->GetAttribute<Rml::String>("data-lineup-taker","");
|
||||
if(index.size()!=1 || index[0]<'0' || index[0]>'2')return true;
|
||||
const auto value=control->GetValue(); const int i=index[0]-'0';
|
||||
if(l.at("takers")[size_t(i)]!=value) {commit({{"kind","taker"},{"index",i},{"player",value}},s.revision);focus_after_render_=target->GetId();refresh();}
|
||||
stop();return true;
|
||||
}
|
||||
if(target->HasAttribute("data-lineup-order")) {
|
||||
const auto index=target->GetAttribute<Rml::String>("data-lineup-order","");
|
||||
const auto id=target->GetAttribute<Rml::String>("data-player","");
|
||||
const auto text=control->GetValue();
|
||||
if(index.size()!=1 || index[0]<'0' || index[0]>'3' || text.empty() || text.size()>2 || std::any_of(text.begin(),text.end(),[](char c){return c<'0'||c>'9';}))return true;
|
||||
const int value=std::stoi(text),i=index[0]-'0';
|
||||
if(value<2 || value>40 || lineup_slot(l,id)<0 || lineup_slot(l,id)>=11)return true;
|
||||
if(l.at("orders").at(id)[size_t(i)]!=value && commit({{"kind","order"},{"player",id},{"index",i},{"value",value}},s.revision)) {
|
||||
if(auto *output=element("lineup-order-value-"+index))output->SetInnerRML(std::to_string(value));
|
||||
if(auto *zone=element("lineup-zone")) {
|
||||
const auto now=snap();
|
||||
zone->SetInnerRML(picture(renderer_.diagram("lineup-zone",lineup_zone(now.state.at("lineup"),id),1600),1486,885.4375));
|
||||
}
|
||||
dirty_=true;
|
||||
}
|
||||
stop();return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(type=="mousedown" && event.GetParameter<int>("button",0)==0) {
|
||||
lineup_ignore_click_=false;
|
||||
if(pitch && player_node) {
|
||||
const auto id=player_node->GetAttribute<Rml::String>("data-squad-player","");const int slot=lineup_slot(l,id);
|
||||
if(slot>=0) {lineup_drag_={{"player",id},{"club",lineup_managed(s)},{"source_slot",slot},{"start_x",mx},{"start_y",my},{"ghost",point(mx,my)},{"moved",false}};lineup_drag_revision_=s.revision;lineup_drag_world_=s.world;}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if(type=="mousemove" && lineup_drag_.is_object()) {
|
||||
if(!lineup_drag_.value("moved",false) && std::hypot(mx-lineup_drag_.at("start_x").get<float>(),my-lineup_drag_.at("start_y").get<float>())<5)return false;
|
||||
lineup_drag_["moved"]=true;
|
||||
const auto p=point(mx,my);lineup_drag_["ghost"]=p;
|
||||
if(p.is_array())if(auto *ghost=element("lineup-ghost")) {
|
||||
ghost->SetProperty("display","block");
|
||||
ghost->SetProperty("left",scalar((8+p[0].get<int>()/18.0*84)*14.86-63)+"dp");
|
||||
ghost->SetProperty("top",scalar((10+p[1].get<int>()/8.0*80)*8.854375-76.86)+"dp");
|
||||
dirty_=true;
|
||||
}
|
||||
stop();return true;
|
||||
}
|
||||
if(type=="mouseup" && lineup_drag_.is_object()) {
|
||||
const auto drag=lineup_drag_; const auto revision=lineup_drag_revision_;const auto world=lineup_drag_world_;
|
||||
const bool moved=drag.value("moved",false);cancel_lineup_drag(false);
|
||||
if(!moved)return false;
|
||||
lineup_ignore_click_=true;
|
||||
const auto id=drag.at("player").get<std::string>();
|
||||
if(s.world!=world || s.revision!=revision || lineup_managed(s)!=drag.at("club").get<std::string>() || lineup_slot(l,id)!=drag.at("source_slot").get<int>()) {
|
||||
message("Die Aufstellung hat sich geändert. Bitte den Spieler erneut auswählen.");stop();return true;
|
||||
}
|
||||
// Resolve the physical drop target independently of the active mouse
|
||||
// element: Rml may continue dispatching mouseup to the drag origin.
|
||||
std::string drop;
|
||||
for(auto *n=context_->GetElementAtPoint({mx,my});n && n!=doc_;n=n->GetParentNode()) {
|
||||
if(n->HasAttribute("data-squad-player")) {drop=n->GetAttribute<Rml::String>("data-squad-player","");break;}
|
||||
}
|
||||
const int drop_slot=lineup_slot(l,drop);
|
||||
if(drop_slot>=0 && drop!=id) {
|
||||
commit({{"kind","swap"},{"a",id},{"b",drop}},revision);
|
||||
lineup_selected_.clear();
|
||||
focus_after_render_=std::string(drop_slot<11?"lineup-player-":"lineup-bench-")+id;
|
||||
} else if(drop_slot<0 && in_pitch(mx,my)) {
|
||||
const int slot=lineup_slot(l,id); const auto p=point(mx,my);
|
||||
if(slot<11) {lineup_selected_=id;commit({{"kind","move"},{"player",id},{"point",p}},revision);}
|
||||
else {
|
||||
const auto &points=l.at("points");const auto hit=std::find(points.begin(),points.end(),p);const int n=int(hit-points.begin());
|
||||
if(n<int(std::min(size_t(11),l.at("order").size()))) {commit({{"kind","swap"},{"a",id},{"b",l.at("order")[size_t(n)]}},revision);lineup_selected_.clear();}
|
||||
else lineup_selected_=id;
|
||||
}
|
||||
focus_after_render_="lineup-player-"+id;
|
||||
}
|
||||
refresh();stop();return true;
|
||||
}
|
||||
if(type=="click" && lineup_ignore_click_) {lineup_ignore_click_=false;stop();return true;}
|
||||
if(type=="click" && pitch && !player_node && !lineup_selected_.empty()) {
|
||||
bool inside=false;for(auto *n=target;n && n!=doc_;n=n->GetParentNode())if(n==pitch)inside=true;
|
||||
if(inside) {
|
||||
const int slot=lineup_slot(l,lineup_selected_);
|
||||
if(slot>=0 && slot<11) {const auto id=lineup_selected_;commit({{"kind","move"},{"player",id},{"point",point(mx,my)}},s.revision);focus_after_render_="lineup-player-"+id;refresh();}
|
||||
else message("Einen Ersatzspieler auf einen Spieler der Startelf ziehen oder beide nacheinander anklicken.");
|
||||
stop();return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
namespace {
|
||||
std::string lineup_managed(const Snapshot &s) {
|
||||
const auto m = s.state.value("managers",Json::array());
|
||||
return m.is_array() && !m.empty() && m[0].is_object() ? m[0].value("club","") : "";
|
||||
}
|
||||
std::string lineup_position(const Json &v) {
|
||||
if (!v.is_string()) return "—";
|
||||
const auto code = v.get<std::string>();
|
||||
return code == "gk" ? "TW" : code == "def" ? "ABW" : code == "mid" ? "MIT" : code == "fwd" ? "STU" : code.empty() ? "—" : code;
|
||||
}
|
||||
std::string lineup_value(const Json &v) {
|
||||
if (!v.is_number()) return "—";
|
||||
if (v.is_number_integer()) return number(v.get<int64_t>());
|
||||
if (!std::isfinite(v.get<double>())) return "—";
|
||||
std::ostringstream out; out << std::setprecision(5) << v.get<double>();
|
||||
auto text = out.str(); std::replace(text.begin(),text.end(),'.',','); return text;
|
||||
}
|
||||
int lineup_slot(const Json &l, const std::string &id) {
|
||||
if (!l.is_object() || !l.contains("order") || !l.at("order").is_array()) return -1;
|
||||
const auto &a = l.at("order"); const auto p = std::find(a.begin(),a.end(),id);
|
||||
return p == a.end() ? -1 : int(p-a.begin());
|
||||
}
|
||||
std::string lineup_svg(const std::string &body, const std::string &box="0 0 120 72") {
|
||||
return "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\""+box+"\">"+body+"</svg>";
|
||||
}
|
||||
std::string lineup_mini(const Json &points, const std::string &theme) {
|
||||
const auto line = theme == "silver" ? "#536f66" : "#c3e8cb";
|
||||
std::string body = "<g stroke=\""+std::string(line)+"\" stroke-width=\"1\" fill=\"none\"><path d=\"M2 2H118V70H2Z M60 2V70 M2 20H19V52H2 M118 20H101V52H118\"/><circle cx=\"60\" cy=\"36\" r=\"9\"/></g>";
|
||||
if (points.is_array()) for (const auto &p : points) {
|
||||
const int depth=p[0].get<int>(), lane=p[1].get<int>();
|
||||
const auto color = theme == "silver" ? (depth<7?"#85600c":depth<13?"#a46914":"#b44931") : (depth<7?"#ffdc69":depth<13?"#ecac4b":"#f07852");
|
||||
body += "<circle cx=\""+scalar(8+depth/18.0*104)+"\" cy=\""+scalar(8+lane/8.0*56)+"\" r=\"2.6\" fill=\""+color+"\"/>";
|
||||
}
|
||||
return lineup_svg(body);
|
||||
}
|
||||
std::string lineup_field() {
|
||||
std::string body;
|
||||
for (int x=0;x<196;x+=15) body += "<rect x=\""+std::to_string(x)+"\" width=\"15\" height=\"117\" fill=\""+(x%30?"#306b4c":"#2d6447")+"\"/>";
|
||||
body += "<svg viewBox=\"0 0 120 72\" width=\"196\" height=\"117\"><g fill=\"none\" stroke=\"#cfdfd2\" stroke-width=\".45\">"
|
||||
"<path d=\"M7 2H113V70H7Z M60 2V70 M7 15.84H23.5V56.16H7 M113 15.84H96.5V56.16H113 M7 26.84H12.5V45.16H7 M113 26.84H107.5V45.16H113 M7 32.34H5V39.66H7 M113 32.34H115V39.66H113 M23.5 28.8Q30 36 23.5 43.2 M96.5 28.8Q90 36 96.5 43.2 M8 2A1 1 0 0 1 7 3 M112 2A1 1 0 0 0 113 3 M7 69A1 1 0 0 1 8 70 M112 70A1 1 0 0 1 113 69\"/>"
|
||||
"<circle cx=\"60\" cy=\"36\" r=\"9.15\"/></g><g fill=\"#cfdfd2\"><circle cx=\"60\" cy=\"36\" r=\".4\"/><circle cx=\"18\" cy=\"36\" r=\".3\"/><circle cx=\"102\" cy=\"36\" r=\".3\"/></g></svg>";
|
||||
return lineup_svg(body,"0 0 196 117");
|
||||
}
|
||||
std::string lineup_zone(const Json &l, const std::string &id) {
|
||||
const int row = lineup_slot(l,id);
|
||||
if (row<0 || row>=11) return "";
|
||||
const auto &point = l.at("points")[size_t(row)], &orders = l.at("orders").at(id);
|
||||
const double forward=orders[0].get<int>(), width=orders[1].get<int>(), coverage=orders[2].get<int>();
|
||||
const double x=(8+point[0].get<int>()/18.0*84)*1.96, y=(10+point[1].get<int>()/8.0*80)*1.17;
|
||||
double x0=x-(width/2+46-forward), x1=x+width/2+forward+8;
|
||||
std::string body="<g fill=\"#ed5b61\" fill-opacity=\".46\">";
|
||||
for (int n=0;n<=int(coverage/2);++n) {
|
||||
if (n) { const int bend=(n==8?3:0)+(n==6?2:0)+(n==3?1:0); if (x0<x1-(1+bend)*2-20) {x0+=1+bend;x1-=1+bend;} }
|
||||
const double lo=std::max(3.0,x0),hi=std::min(192.0,x1);
|
||||
if (hi>lo) for (const auto yy : {std::max(2.0,y-n-1),std::min(114.0,y+n+1)})
|
||||
body += "<rect x=\""+scalar(lo)+"\" y=\""+scalar(yy)+"\" width=\""+scalar(hi-lo)+"\" height=\"1\"/>";
|
||||
}
|
||||
return lineup_svg(body+"</g>","0 0 196 117");
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string App::render_lineup() {
|
||||
const auto s=snap();
|
||||
if (!s.world) return "<p class=\"lineup-empty\">Die Aufstellung ist derzeit nicht verfügbar.</p>";
|
||||
const auto projection=demo_lineup_rows(s.state,*s.world,lineup_managed(s));
|
||||
if (!projection.value("ok",false)) return "<p class=\"lineup-empty\">Die Aufstellung ist derzeit nicht verfügbar.</p>";
|
||||
const auto &l=s.state.at("lineup"), &rows=projection.at("rows");
|
||||
if (lineup_slot(l,lineup_selected_)<0) lineup_selected_.clear();
|
||||
lineup_data_=lineup_data_==1?1:0; lineup_page_=lineup_page_==1?1:0;
|
||||
if (lineup_side_!="orders" && lineup_side_!="takers") lineup_side_="formations";
|
||||
const auto attr=[](const std::string &key,const std::string &value) {return " "+key+"=\""+esc(value)+"\"";};
|
||||
const auto player_attrs=[&](const Json &row,const std::string &prefix) {
|
||||
const auto id=row.at("id").get<std::string>();
|
||||
return attr("id",prefix+id)+attr("data-id",id)+attr("data-squad-player",id)+
|
||||
attr("data-slot",std::to_string(row.at("slot").get<size_t>()))+attr("aria-pressed",lineup_selected_==id?"true":"false")+
|
||||
attr("aria-label",row.at("name").get<std::string>()+", "+lineup_position(row.at("position")));
|
||||
};
|
||||
std::string out="<div id=\"lineup-underlay\" class=\"lineup-screen "+std::string(lineup_pitch_?"pitch-view":"team-view")+"\"><div class=\"lineup-roster\"><div class=\"lineup-row lineup-head\" role=\"row\">";
|
||||
const std::array<std::array<const char*,12>,2> headings{{
|
||||
{{"Nr.","Name","Pos.","Ko","Te","Fo","Stärke","Status","Land","Mot.","Tore","Ass."}},
|
||||
{{"Nr.","Name","Alter","Eck.","Frei.","Zwei.","Pass","Schuss","Schn.","Team","Spiele","Note"}}}};
|
||||
for (int c=0;c<12;++c) out+="<span class=\"lineup-cell lineup-col-"+std::to_string(c)+"\"><span>"+headings[size_t(lineup_data_)][size_t(c)]+"</span></span>";
|
||||
out+="</div><div id=\"lineup-roster-scroll\" class=\"lineup-roster-scroll\" tabindex=\"0\" aria-label=\"Kaderliste, scrollbar\" role=\"table\">";
|
||||
for (const auto &row:rows) {
|
||||
const auto slot=row.at("slot").get<int>(); const auto id=row.at("id").get<std::string>();
|
||||
out+="<div class=\"lineup-row "+std::string(slot%2?"even ":"")+(slot==11?"reserve-start ":"")+(lineup_selected_==id?"selected":"")+"\" role=\"row\">";
|
||||
out+="<span class=\"lineup-cell lineup-col-0\"><span>"+(slot<11?std::to_string(slot+1):"–")+"</span></span>";
|
||||
out+=btn("lineup-player",esc(row.at("name").get<std::string>()),"lineup-cell lineup-col-1 lineup-name",player_attrs(row,"lineup-name-"));
|
||||
std::vector<std::string> fields;
|
||||
if (!lineup_data_) fields={lineup_position(row.at("position")),lineup_value(row.at("condition")),lineup_value(row.at("technique")),lineup_value(row.at("form")),lineup_value(row.at("strength")),slot<11?"STARTELF":"BANK",row.at("nation").is_string()?row.at("nation").get<std::string>():"—",lineup_value(row.at("motivation")),lineup_value(row.at("goals")),lineup_value(row.at("assists"))};
|
||||
else for (const auto *key:{"age","corner","free_kick","tackling","passing","shooting","speed","teamplay","games","grade"}) fields.push_back(lineup_value(row.at(key)));
|
||||
for (size_t f=0;f<fields.size();++f) {
|
||||
std::string value=esc(fields[f]);
|
||||
if (!lineup_data_ && f==6 && row.at("nation").is_string()) {
|
||||
auto code=row.at("nation").get<std::string>();
|
||||
if (code.starts_with("nation:")) code=code.substr(7);
|
||||
if (code=="de") value=picture(renderer_.diagram("lineup-flag-de",lineup_svg("<path fill=\"#111111\" d=\"M0 0H40V8H0Z\"/><path fill=\"#bc302e\" d=\"M0 8H40V16H0Z\"/><path fill=\"#edc758\" d=\"M0 16H40V24H0Z\"/>","0 0 40 24"),80),40,24);
|
||||
else {
|
||||
const auto flag=ui_nation_flag_svg(code);
|
||||
if (!flag.empty()) value=picture(renderer_.diagram("lineup-flag-"+code,flag,80),40,24);
|
||||
else { std::transform(code.begin(),code.end(),code.begin(),[](unsigned char c){return char(std::toupper(c));}); value=esc(code); }
|
||||
}
|
||||
}
|
||||
if (!lineup_data_ && f==5) value="<span class=\"lineup-status\">"+value+"</span>";
|
||||
out+=btn("player-detail",value,"lineup-cell lineup-col-"+std::to_string(f+2)+" lineup-detail",
|
||||
attr("id","lineup-detail-"+id+"-"+std::to_string(f))+attr("data-id",id)+attr("aria-label",row.at("name").get<std::string>()+", Spielerinformationen"));
|
||||
}
|
||||
out+="</div>";
|
||||
}
|
||||
if (rows.empty()) out+="<p class=\"lineup-empty\">Für diesen Verein sind keine Spieler überliefert.</p>";
|
||||
out+="</div></div>";
|
||||
const auto data_btn=[&]() {return btn("lineup-data",lineup_data_?"Daten A":"Daten B","lineup-tab","id=\"lineup-data\"");};
|
||||
const auto view_btn=[&]() {return btn("lineup-view",lineup_pitch_?"Team":"Spielfeld","lineup-tab","id=\"lineup-view\"");};
|
||||
if (lineup_pitch_) {
|
||||
out+="<div id=\"lineup-pitch\" class=\"lineup-pitch\" role=\"group\" aria-label=\"Spielfeld, Spieler auswählen oder ziehen\"><div class=\"lineup-field-art\">"+picture(renderer_.diagram("lineup-field",lineup_field(),1600),1486,885.4375)+"</div>";
|
||||
if (lineup_side_=="orders" && !lineup_selected_.empty()) {
|
||||
const auto zone=lineup_zone(l,lineup_selected_);
|
||||
if (!zone.empty()) out+="<div id=\"lineup-zone\" class=\"lineup-order-zone\">"+picture(renderer_.diagram("lineup-zone",zone,1600),1486,885.4375)+"</div>";
|
||||
}
|
||||
for (size_t i=0;i<std::min(size_t(11),rows.size());++i) {
|
||||
const auto &row=rows[i], &point=l.at("points")[i];
|
||||
const bool selected=lineup_selected_==row.at("id").get<std::string>();
|
||||
const auto x=(8+point[0].get<int>()/18.0*84)*14.86-63;
|
||||
const auto y=(10+point[1].get<int>()/8.0*80)*8.854375-76.86;
|
||||
out+=btn("lineup-player",img(selected?"lineup.player.selected":"lineup.player.normal",126,126)+"<span class=\"lineup-jersey\">"+std::to_string(i+1)+"</span>","lineup-player",player_attrs(row,"lineup-player-")+attr("style",rect(x,y,126,126)));
|
||||
}
|
||||
out+="<div id=\"lineup-ghost\" class=\"lineup-ghost\">"+img("lineup.player.ghost",126,126)+"</div></div><aside class=\"lineup-controls\"><nav class=\"lineup-tabs\" aria-label=\"Aufstellungsansichten\">"+data_btn()+view_btn();
|
||||
for (const auto &[side,label]:std::array<std::pair<const char*,const char*>,3>{{{"formations","Aufst."},{"orders","Anweis."},{"takers","Schütze"}}})
|
||||
out+=btn("lineup-side",label,"lineup-tab",attr("id","lineup-side-"+std::string(side))+attr("data-id",side)+attr("aria-pressed",lineup_side_==side?"true":"false"));
|
||||
out+="</nav><div class=\"lineup-side\" id=\"lineup-side\">";
|
||||
if (lineup_side_=="formations") {
|
||||
for (int slot=0;slot<4;++slot) {
|
||||
const int i=slot+lineup_page_*4;
|
||||
const auto point=i<4?demo_lineup_formations()[size_t(i)]:l.at("custom")[size_t(i-4)];
|
||||
const auto mini=lineup_mini(point,theme_);
|
||||
const std::string label=i<4?"Aufstellung "+std::to_string(i+1):"Eigene "+std::to_string(i-3);
|
||||
const auto art=picture(renderer_.diagram("lineup-mini-"+std::to_string(i)+"-"+theme_,mini,520),260,156);
|
||||
out+="<div class=\"lineup-formation-cell "+std::string(i>=4?"custom":"")+"\" style=\""+rect((slot%2)*546,(slot/2)*230,528,218)+"\">";
|
||||
out+=btn("lineup-formation","<span class=\"lineup-mini\">"+art+"</span><span class=\"lineup-formation-label\">"+label+"</span>","lineup-formation",
|
||||
attr("id","lineup-formation-"+std::to_string(i))+attr("data-id",std::to_string(i))+attr("aria-pressed",l.at("formation")==i?"true":"false")+(point.is_null()?" disabled=\"disabled\"":""));
|
||||
if (i>=4) out+=btn("lineup-save","Merken","lineup-save",attr("id","lineup-save-"+std::to_string(i-4))+attr("data-id",std::to_string(i-4)));
|
||||
out+="</div>";
|
||||
}
|
||||
const auto arrow=[&](bool next) {return picture(renderer_.diagram(next?"lineup-next":"lineup-prev",lineup_svg("<path d=\""+std::string(next?"M8 3L17 12L8 21":"M16 3L7 12L16 21")+"\" fill=\"none\" stroke=\""+std::string(theme_=="silver"?"#233443":"#dce5ee")+"\" stroke-width=\"2\"/>","0 0 24 24"),48),32,32);};
|
||||
out+="<nav class=\"lineup-pages\" aria-label=\"Aufstellungsseiten\">"+btn("lineup-page",arrow(false),"lineup-page","id=\"lineup-page-prev\" data-id=\"0\" aria-label=\"Vorgegebene Aufstellungen\" "+std::string(lineup_page_==0?"disabled=\"disabled\"":""))+"<span>"+(lineup_page_?"Eigene Aufstellungen":"Vorgegebene Aufstellungen")+"</span>"+btn("lineup-page",arrow(true),"lineup-page","id=\"lineup-page-next\" data-id=\"1\" aria-label=\"Eigene Aufstellungen\" "+std::string(lineup_page_==1?"disabled=\"disabled\"":""))+"</nav><div class=\"lineup-weights\">";
|
||||
const std::array<const char*,3> names{"Position","Seite / Rolle","Frische"};
|
||||
for (int i=0;i<3;++i) {
|
||||
const int weight=l.at("weights")[size_t(i)].get<int>();
|
||||
std::string bars="<span class=\"lineup-weight-bars\">";
|
||||
for (int n=0;n<3;++n) bars+="<span class=\"lineup-weight-bar "+std::string(n<weight?"active":"")+"\"></span>";
|
||||
out+=btn("lineup-weight","<span class=\"lineup-weight-label\">"+std::string(names[size_t(i)])+"</span>"+bars+"</span>","lineup-weight",attr("id","lineup-weight-"+std::to_string(i))+attr("data-id",std::to_string(i))+attr("aria-label",std::string(names[size_t(i)])+" Gewichtung "+std::to_string(weight)+" von 3"));
|
||||
}
|
||||
out+="</div>";
|
||||
} else if (lineup_side_=="orders") {
|
||||
const int slot=lineup_slot(l,lineup_selected_);
|
||||
out+="<section class=\"lineup-orders\"><h2>Anweisungen</h2><p class=\"lineup-order-name\">"+esc(slot>=0?rows[size_t(slot)].at("name").get<std::string>():"Einen Feldspieler auswählen.")+"</p>";
|
||||
if (slot>=0 && slot<11) {
|
||||
const std::array<const char*,4> paths{"M8 34L34 8M14 8H34V28","M8 34L34 8M8 14V34H28","M4 22H40M13 13L4 22L13 31M31 13L40 22L31 31","M22 4V40M13 13L22 4L31 13M13 31L22 40L31 31"};
|
||||
for (int i=0;i<4;++i) {
|
||||
const auto value=l.at("orders").at(lineup_selected_)[size_t(i)].get<int>();
|
||||
const auto icon=lineup_svg("<path d=\""+std::string(paths[size_t(i)])+"\" fill=\"none\" stroke=\""+std::string(theme_=="silver"?"#25617a":theme_=="matchday"?"#efb2aa":"#a9dccb")+"\" stroke-width=\"3\"/>","0 0 44 44");
|
||||
out+="<label class=\"lineup-order-row\" style=\"top:"+std::to_string(135+i*83)+"dp;\"><span class=\"lineup-order-icon\">"+picture(renderer_.diagram("lineup-order-icon-"+std::to_string(i)+"-"+theme_,icon,88),44,44)+"</span><input type=\"range\" min=\"2\" max=\"40\" step=\"1\" value=\""+std::to_string(value)+"\" id=\"lineup-order-"+std::to_string(i)+"\" data-lineup-order=\""+std::to_string(i)+"\" data-player=\""+esc(lineup_selected_)+"\" aria-label=\"Anweisung "+std::to_string(i+1)+"\"/><span class=\"lineup-order-value\" id=\"lineup-order-value-"+std::to_string(i)+"\">"+std::to_string(value)+"</span></label>";
|
||||
}
|
||||
} else out+="<p class=\"lineup-hint\">Die vier Vorschauwerte gelten für Spieler in der Startelf.</p>";
|
||||
out+="</section>";
|
||||
} else {
|
||||
out+="<section class=\"lineup-takers\"><h2>Schützen</h2>";
|
||||
const std::array<const char*,3> labels{"Freistoß","Elfmeter","Eckball"};
|
||||
const auto option_text=[](const std::string &name) {
|
||||
return "<span class=\"lineup-option-mark\" aria-hidden=\"true\"><span class=\"lineup-option-check\"></span></span><span class=\"lineup-option-text\">"+esc(name)+"</span>";
|
||||
};
|
||||
for (int i=0;i<3;++i) {
|
||||
out+="<label class=\"lineup-taker-label\"><span>"+std::string(labels[size_t(i)])+"</span><select class=\"lineup-taker\" id=\"lineup-taker-"+std::to_string(i)+"\" data-lineup-taker=\""+std::to_string(i)+"\" aria-label=\""+std::string(labels[size_t(i)])+"schütze\"><option value=\"\" "+std::string(l.at("takers")[size_t(i)]==""?"selected=\"selected\"":"")+">"+option_text("AUTO")+"</option>";
|
||||
for (size_t r=0;r<std::min(size_t(11),rows.size());++r) {
|
||||
const auto id=rows[r].at("id").get<std::string>();
|
||||
out+="<option value=\""+esc(id)+"\" "+std::string(l.at("takers")[size_t(i)]==id?"selected=\"selected\"":"")+">"+option_text(rows[r].at("name").get<std::string>())+"</option>";
|
||||
}
|
||||
out+="</select></label>";
|
||||
}
|
||||
out+=btn("lineup-auto","Automatisch","lineup-auto","id=\"lineup-auto\"")+"</section>";
|
||||
}
|
||||
out+="</div><section class=\"lineup-bench\"><h2>Ersatzbank</h2><div id=\"lineup-bench-scroll\" class=\"lineup-bench-scroll\">";
|
||||
for (size_t r=11;r<rows.size();++r) {
|
||||
const auto &row=rows[r];
|
||||
out+=btn("lineup-player","<span class=\"lineup-bench-position\">"+esc(lineup_position(row.at("position")))+"</span><span class=\"lineup-bench-name\">"+esc(row.at("name").get<std::string>())+"</span>","lineup-bench-player",player_attrs(row,"lineup-bench-"));
|
||||
}
|
||||
if (rows.size()<=11) out+="<span class=\"lineup-bench-empty\">Keine Ersatzspieler überliefert.</span>";
|
||||
out+="</div></section></aside>";
|
||||
} else {
|
||||
out+="<footer class=\"lineup-team-actions\">"+data_btn()+view_btn()+"<span>"+std::to_string(std::min(size_t(11),rows.size()))+" Spieler auf dem Feld · "+std::to_string(rows.size()>11?rows.size()-11:0)+" Kaderplätze auf der Bank</span></footer>";
|
||||
}
|
||||
out+="</div>";
|
||||
return out+render_report_detail();
|
||||
}
|
||||
@@ -8,6 +8,8 @@
|
||||
#include "modern/ui/demo_calendar.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
@@ -92,6 +94,8 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
|
||||
throw editor::Error("invalid_demo_finance");
|
||||
if (!migrate_demo_environment(state_, *catalog_) || !migrate_demo_advertising(state_, *catalog_) || !migrate_demo_toto(state_, *catalog_))
|
||||
throw editor::Error("invalid_demo_club");
|
||||
if (!migrate_demo_lineup(state_, *catalog_, club) || !migrate_demo_transfer(state_, *catalog_, club))
|
||||
throw editor::Error("invalid_demo_squad");
|
||||
saved_ = state_;
|
||||
}
|
||||
Snapshot DemoSource::snapshot() const { return {revision_, catalog_, state_}; }
|
||||
@@ -131,6 +135,8 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
next["training"] = demo_training(*catalog_, first);
|
||||
next["tactics"] = demo_tactics();
|
||||
next["contracts"] = demo_contracts(*catalog_, first);
|
||||
next["lineup"] = demo_lineup(*catalog_, first);
|
||||
next["transfer"] = demo_transfer(*catalog_, first);
|
||||
next["calendar"] = demo_calendar(*catalog_, next.at("date"), first);
|
||||
const auto error = edit_demo_reports(next["reports"],
|
||||
{{"kind", "league"}, {"value", next["calendar"]["league"]}}, *catalog_);
|
||||
@@ -141,6 +147,11 @@ ActionResult DemoSource::apply(const Action &action) {
|
||||
: action.kind == "advertising" ? edit_demo_advertising(next, action.value, *catalog_)
|
||||
: edit_demo_toto(next, action.value, *catalog_);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
} else if (action.kind == "lineup" || action.kind == "transfer") {
|
||||
const auto club = next["managers"][0]["club"].get<std::string>();
|
||||
const auto error = action.kind == "lineup" ? edit_demo_lineup(next, action.value, *catalog_, club)
|
||||
: edit_demo_transfer(next, action.value, *catalog_, club);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
} else if (action.kind == "finance") {
|
||||
const auto error = edit_demo_finance(next, action.value, *catalog_, next["managers"][0]["club"]);
|
||||
if (!error.empty()) return {false, revision_, error};
|
||||
@@ -267,6 +278,8 @@ Json DemoSource::load(const fs::path &file) {
|
||||
throw editor::Error("invalid_demo_finance");
|
||||
if (!migrate_demo_environment(data, *catalog_) || !migrate_demo_advertising(data, *catalog_) || !migrate_demo_toto(data, *catalog_))
|
||||
throw editor::Error("invalid_demo_club");
|
||||
if (!migrate_demo_lineup(data, *catalog_, club) || !migrate_demo_transfer(data, *catalog_, club))
|
||||
throw editor::Error("invalid_demo_squad");
|
||||
auto next = data;
|
||||
auto desktop = next.value("desktop", Json::object());
|
||||
if (!migrate_desktop(desktop))
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
namespace {
|
||||
// Small UI flags, sharing the muted palette of the HTML reference. Unknown
|
||||
// identifiers deliberately return no image; callers retain a neutral label.
|
||||
std::string ui_nation_flag_svg(const std::string &value) {
|
||||
std::string code=value.starts_with("nation:")?value.substr(7):value;
|
||||
for(auto &c:code)if(c>='A'&&c<='Z')c=char(c-'A'+'a');
|
||||
const std::map<std::string,std::string> aliases{{"x-eng","en"},{"eng","en"},{"ger","de"},{"deu","de"},{"fra","fr"},{"ita","it"},{"esp","es"},{"ned","nl"},{"nld","nl"},{"jpn","jp"},{"swe","se"},{"den","dk"},{"dnk","dk"},{"nga","ng"},{"bra","br"},{"mar","ma"},{"alg","dz"},{"dza","dz"}};
|
||||
if(auto it=aliases.find(code);it!=aliases.end())code=it->second;
|
||||
const auto rect=[](double x,double y,double w,double h,const char*fill){return "<rect x=\""+scalar(x)+"\" y=\""+scalar(y)+"\" width=\""+scalar(w)+"\" height=\""+scalar(h)+"\" fill=\""+fill+"\"/>";};
|
||||
std::string body;
|
||||
const std::map<std::string,std::array<const char*,3>> bars{
|
||||
{"de",{"#262b30","#c85a52","#d9bf65"}},{"fr",{"#5685b6","#e6ebee","#c7625b"}},
|
||||
{"it",{"#679b83","#e6ebee","#c7625b"}},{"es",{"#c75b50","#e3c66b","#c75b50"}},
|
||||
{"nl",{"#bf5c56","#e6ebee","#5b83b1"}},{"be",{"#262b30","#e3c66b","#c7625b"}},
|
||||
{"ie",{"#679b83","#e6ebee","#d69455"}},{"ro",{"#5685b6","#e3c66b","#c7625b"}},
|
||||
{"ng",{"#38865d","#e6ebee","#38865d"}},{"at",{"#c7625b","#e6ebee","#c7625b"}},
|
||||
{"ru",{"#e6ebee","#5685b6","#c7625b"}},{"hu",{"#c7625b","#e6ebee","#679b83"}}};
|
||||
if(auto it=bars.find(code);it!=bars.end()){
|
||||
const bool vertical=code=="fr"||code=="it"||code=="be"||code=="ie"||code=="ro"||code=="ng";
|
||||
for(int i=0;i<3;++i)body+=rect(vertical?i*10.:0,vertical?0:i*20./3,vertical?10:30,vertical?20:20./3,it->second[size_t(i)]);
|
||||
}else if(code=="pl"||code=="ua")body=rect(0,0,30,10,code=="pl"?"#e6ebee":"#5685b6")+rect(0,10,30,10,code=="pl"?"#c7625b":"#e3c66b");
|
||||
else if(code=="jp")body=rect(0,0,30,20,"#e6ebee")+"<circle cx=\"15\" cy=\"10\" r=\"6\" fill=\"#c7625b\"/>";
|
||||
else if(code=="en"||code=="dk"||code=="se"||code=="fi"){
|
||||
const auto bg=code=="dk"?"#c7625b":code=="se"?"#5685b6":"#e6ebee";
|
||||
const auto cross=code=="en"?"#c7625b":code=="se"?"#e3c66b":code=="fi"?"#5685b6":"#e6ebee";
|
||||
body=rect(0,0,30,20,bg)+rect(code=="en"?13:8,0,4,20,cross)+rect(0,8,30,4,cross);
|
||||
}else if(code=="ch")body=rect(0,0,30,20,"#c7625b")+rect(13,4,4,12,"#e6ebee")+rect(9,8,12,4,"#e6ebee");
|
||||
else if(code=="ma")body=rect(0,0,30,20,"#c7625b")+"<path d=\"M15 4L18.5 15L9.3 8.2H20.7L11.5 15Z\" fill=\"none\" stroke=\"#266747\" stroke-width=\"1\"/>";
|
||||
else if(code=="dz")body=rect(0,0,15,20,"#38865d")+rect(15,0,15,20,"#e6ebee")+"<defs><mask id=\"crescent\"><rect width=\"30\" height=\"20\" fill=\"white\"/><circle cx=\"17\" cy=\"10\" r=\"5\" fill=\"black\"/></mask></defs><circle cx=\"15\" cy=\"10\" r=\"6\" fill=\"#c7625b\" mask=\"url(#crescent)\"/><path d=\"M18 7L18.7 9.1L21 9.1L19.2 10.5L19.9 12.7L18 11.3L16.1 12.7L16.8 10.5L15 9.1H17.3Z\" fill=\"#c7625b\"/>";
|
||||
else if(code=="br")body=rect(0,0,30,20,"#38865d")+"<path d=\"M15 1.6L28 10L15 18.4L2 10Z\" fill=\"#e3c66b\"/><circle cx=\"15\" cy=\"10\" r=\"5.5\" fill=\"#40658d\"/><path d=\"M10 8Q15 6.5 20 11\" stroke=\"#e6ebee\" stroke-width=\"1\" fill=\"none\"/><g fill=\"#e6ebee\"><circle cx=\"12\" cy=\"11\" r=\".3\"/><circle cx=\"15\" cy=\"13\" r=\".3\"/><circle cx=\"18\" cy=\"12\" r=\".3\"/><circle cx=\"14\" cy=\"10\" r=\".3\"/></g>";
|
||||
else return {};
|
||||
return "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"30\" height=\"20\" viewBox=\"0 0 30 20\">"+body+"</svg>";
|
||||
}
|
||||
} // namespace
|
||||
@@ -883,6 +883,10 @@ std::string App::render_menu(const std::string &key) {
|
||||
body = render_friendlies();
|
||||
else if (key == "indoor")
|
||||
body = render_indoor();
|
||||
else if (key == "lineup")
|
||||
body = render_lineup();
|
||||
else if (key == "transfer")
|
||||
body = render_transfer();
|
||||
else if (key == "environment")
|
||||
body = render_environment();
|
||||
else if (key == "advertising")
|
||||
|
||||
@@ -154,7 +154,7 @@ std::string App::render_tactics() {
|
||||
{205, 10, 58, 37}}};
|
||||
std::string body =
|
||||
"<div class=\"tactics-board\"><div class=\"tactics-surface\"></div>" +
|
||||
picture(renderer_.diagram("tactics", tactics_diagram(t, theme_)), 2300,
|
||||
picture(renderer_.diagram("tactics", tactics_diagram(t, theme_, snap().state.value("lineup", Json::object()).value("points", Json()))), 2300,
|
||||
1864);
|
||||
for (size_t i = 0; i < 7; ++i) {
|
||||
const auto a = areas[i];
|
||||
|
||||
@@ -0,0 +1,612 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::close_transfer(bool restore) {
|
||||
transfer_remember_scroll();
|
||||
transfer_dialog_.clear();
|
||||
transfer_draft_ = Json();
|
||||
transfer_search_draft_ = Json();
|
||||
transfer_picker_.clear();
|
||||
transfer_world_.reset();
|
||||
if (restore)
|
||||
focus_after_render_ = transfer_return_focus_;
|
||||
refresh();
|
||||
}
|
||||
bool App::transfer_action(const std::string &action, Rml::Element *target) {
|
||||
if (!action.starts_with("transfer-"))
|
||||
return false;
|
||||
if (menu_ != "transfer" || !world_ || !source_)
|
||||
return true;
|
||||
transfer_remember_scroll();
|
||||
const auto snapshot = snap();
|
||||
const auto actor = transfer_ui_club(snapshot);
|
||||
const auto world = world_;
|
||||
const auto factor = finance_currency_factor(*world_);
|
||||
const auto id =
|
||||
target ? target->GetAttribute<Rml::String>("data-player", "") : "";
|
||||
const auto index = target ? target->GetAttribute<int>("data-index", -1) : -1;
|
||||
const auto change = [&](const Json &value, uint64_t revision) {
|
||||
const auto r = source_->apply({revision, "transfer", value});
|
||||
if (!r.ok) {
|
||||
message("Die Eingabe konnte nicht übernommen werden. Bitte den aktuellen "
|
||||
"Stand erneut auswählen. (" +
|
||||
r.error + ")");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const auto begin_offer = [&](const std::string &kind,
|
||||
const std::string &player, bool poached) {
|
||||
const auto q = demo_transfer_quote(
|
||||
snapshot.state,
|
||||
{{"kind", kind}, {"player", player}, {"poached", poached}}, *world_,
|
||||
actor);
|
||||
if (!q.value("ok", false)) {
|
||||
transfer_dialog_ = "notice";
|
||||
transfer_notice_ = q.value("error", std::string()) == "transfer_list_full"
|
||||
? "Es können höchstens drei eigene Spieler "
|
||||
"gleichzeitig auf dem Markt stehen."
|
||||
: "Für diese Auswahl ist kein Angebot verfügbar.";
|
||||
transfer_return_focus_ =
|
||||
target ? target->GetId() : "transfer-offer-buy-sell";
|
||||
focus_after_render_ = "transfer-close";
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
transfer_draft_ = q;
|
||||
transfer_draft_["player"] = player;
|
||||
transfer_draft_["fee"] = q.at("fee").get<int64_t>() / factor;
|
||||
transfer_draft_["salary"] = q.at("salary").get<int64_t>() / factor;
|
||||
for (auto &b : transfer_draft_["bonuses"])
|
||||
b = b.get<int64_t>() / factor;
|
||||
transfer_dialog_ = "offer";
|
||||
transfer_revision_ = snapshot.revision;
|
||||
transfer_world_ = world_;
|
||||
transfer_return_focus_ = (kind == "loan" || kind == "lend")
|
||||
? "transfer-offer-loan-lend"
|
||||
: "transfer-offer-buy-sell";
|
||||
focus_after_render_ = "transfer-fee";
|
||||
refresh();
|
||||
};
|
||||
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") {
|
||||
const auto p = demo_transfer_player(snapshot.state, *world_, actor, id);
|
||||
if (!p.value("ok", false))
|
||||
return true;
|
||||
const bool mine = p.at("row").at("own");
|
||||
transfer_view_[mine ? "own" : "market"] = id;
|
||||
transfer_view_["side"] = mine ? "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 ? target->GetAttribute<Rml::String>("data-scope", "") : "";
|
||||
if (scope != "active" && scope != "team")
|
||||
return true;
|
||||
transfer_view_["scope"] = scope;
|
||||
}
|
||||
focus_after_render_ = target ? target->GetId() : "transfer-data";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-filter") {
|
||||
if (index < 0 || index > 4)
|
||||
return true;
|
||||
const int old = snapshot.state.at("transfer").at("positions"),
|
||||
mask = index == 0 ? 15 : old ^ (1 << (index - 1));
|
||||
if (!mask)
|
||||
return true;
|
||||
if (change({{"kind", "positions"}, {"value", mask}}, snapshot.revision)) {
|
||||
transfer_view_["page"] = 0;
|
||||
transfer_view_["market"] = "";
|
||||
transfer_view_["hover"] = "";
|
||||
focus_after_render_ = target->GetId();
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-page") {
|
||||
const int step = target ? target->GetAttribute<int>("data-step", 0) : 0;
|
||||
if (step != -1 && step != 1)
|
||||
return true;
|
||||
const auto pool =
|
||||
demo_transfer_view(snapshot.state, *world_, actor).at("market");
|
||||
const int page = std::clamp(transfer_view_.value("page", 0) + step, 0,
|
||||
std::max(0, int((pool.size() + 5) / 6) - 1));
|
||||
transfer_view_["page"] = page;
|
||||
if (size_t(page) * 6 < pool.size()) {
|
||||
const auto &r = pool[size_t(page) * 6];
|
||||
const bool mine = r.at("own");
|
||||
transfer_view_[mine ? "own" : "market"] = r.at("id");
|
||||
transfer_view_["side"] = mine ? "own" : "market";
|
||||
}
|
||||
transfer_view_["hover"] = "";
|
||||
focus_after_render_ = target ? target->GetId() : "transfer-page-next";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-search") {
|
||||
const auto query = transfer_view_.value("query", std::string());
|
||||
if (change({{"kind", "search"}, {"query", query}}, snapshot.revision)) {
|
||||
transfer_view_["page"] = 0;
|
||||
transfer_view_["market"] = "";
|
||||
transfer_view_["hover"] = "";
|
||||
focus_after_render_ = "transfer-search";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-offer") {
|
||||
const auto kind =
|
||||
target ? target->GetAttribute<Rml::String>("data-kind", "") : "";
|
||||
const bool mine = kind == "sell" || kind == "lend";
|
||||
const auto player =
|
||||
transfer_view_.value(mine ? "own" : "market", std::string());
|
||||
if (player.empty())
|
||||
return true;
|
||||
const auto &listed = snapshot.state.at("transfer").at("listed");
|
||||
if (kind == "sell" &&
|
||||
std::find(listed.begin(), listed.end(), player) != listed.end()) {
|
||||
if (change({{"kind", "unlist"}, {"player", player}}, snapshot.revision)) {
|
||||
focus_after_render_ = "transfer-own-" + player;
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
begin_offer(kind, player, false);
|
||||
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") ||
|
||||
(!search && transfer_dialog_ != "offer") || transfer_world_ != world_)
|
||||
return true;
|
||||
const auto field =
|
||||
search ? std::string("price_max")
|
||||
: bonus ? std::string("bonuses")
|
||||
: target->GetAttribute<Rml::String>("data-field", "");
|
||||
if (!search && !bonus && field != "fee" && field != "salary")
|
||||
return true;
|
||||
if (bonus && (index < 0 || index > 6))
|
||||
return true;
|
||||
if (snapshot.revision != transfer_revision_) {
|
||||
message("Die Daten haben sich geändert. Bitte das Angebot schließen und "
|
||||
"erneut öffnen.");
|
||||
return true;
|
||||
}
|
||||
const auto revision = transfer_revision_;
|
||||
const auto *source = source_.get();
|
||||
const auto player = search
|
||||
? std::string()
|
||||
: transfer_draft_.at("player").get<std::string>();
|
||||
AmountRequest request;
|
||||
request.title = search ? "Maximale Ablösesumme"
|
||||
: bonus ? transfer_ui_bonuses[size_t(index)]
|
||||
: field == "fee" ? ((transfer_draft_.at("kind") == "loan" ||
|
||||
transfer_draft_.at("kind") == "lend")
|
||||
? "Leihgebühr"
|
||||
: "Ablöse")
|
||||
: "Monatsgehalt";
|
||||
request.unit = money_unit();
|
||||
request.return_focus = target->GetId();
|
||||
request.min = 0;
|
||||
request.max = bonus ? 100 : field == "salary" ? 200000 : 99999999;
|
||||
request.step = 1;
|
||||
request.suggestion_step = search ? 500000
|
||||
: bonus ? 1
|
||||
: field == "salary" ? 5000
|
||||
: 100000;
|
||||
request.review = true;
|
||||
request.value =
|
||||
search ? transfer_search_draft_.at(field).get<int64_t>()
|
||||
: bonus ? transfer_draft_.at("bonuses")[size_t(index)].get<int64_t>()
|
||||
: transfer_draft_.at(field).get<int64_t>();
|
||||
request.accept = [this, world, source, revision, player, field, index,
|
||||
search, bonus](int64_t value) {
|
||||
if (world_ != world || source_.get() != source || menu_ != "transfer" ||
|
||||
transfer_world_ != world || transfer_revision_ != revision ||
|
||||
snap().revision != revision)
|
||||
return false;
|
||||
if (search) {
|
||||
if (transfer_dialog_ != "search")
|
||||
return false;
|
||||
transfer_search_draft_[field] = value;
|
||||
} else {
|
||||
if (transfer_dialog_ != "offer" ||
|
||||
transfer_draft_.at("player") != player)
|
||||
return false;
|
||||
if (bonus)
|
||||
transfer_draft_["bonuses"][size_t(index)] = value;
|
||||
else
|
||||
transfer_draft_[field] = value;
|
||||
}
|
||||
refresh();
|
||||
return true;
|
||||
};
|
||||
open_amount(std::move(request));
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-submit") {
|
||||
if (transfer_dialog_ != "offer" || transfer_world_ != world_)
|
||||
return true;
|
||||
Json order = Json::object();
|
||||
for (auto *key : {"kind", "player", "source_club", "fee", "salary",
|
||||
"months", "bonuses", "poached"})
|
||||
order[key] = transfer_draft_.at(key);
|
||||
if (change({{"kind", "submit"}, {"order", order}}, transfer_revision_)) {
|
||||
transfer_dialog_ = "booked";
|
||||
transfer_notice_ =
|
||||
"Der fiktive Transferauftrag liegt in der Auftragsliste.";
|
||||
transfer_draft_ = Json();
|
||||
transfer_world_.reset();
|
||||
focus_after_render_ = "transfer-close";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-player-info" || action == "transfer-team-info") {
|
||||
if (transfer_dialog_ != "offer")
|
||||
return true;
|
||||
transfer_dialog_ =
|
||||
action == "transfer-player-info" ? "player-info" : "team-info";
|
||||
focus_after_render_ = "transfer-offer-back";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-criteria" || action == "transfer-suggest" ||
|
||||
action == "transfer-search-reset") {
|
||||
if (action == "transfer-search-reset" && transfer_dialog_ != "search")
|
||||
return true;
|
||||
Json criteria = snapshot.state.at("transfer").at("criteria");
|
||||
int mask = snapshot.state.at("transfer").at("positions");
|
||||
if (action == "transfer-suggest") {
|
||||
const auto suggestion = demo_transfer_suggestion(
|
||||
snapshot.state, *world_, actor, demo_lineup_active(snapshot.state));
|
||||
criteria = suggestion.at("criteria");
|
||||
mask = suggestion.at("positions");
|
||||
}
|
||||
if (action == "transfer-search-reset") {
|
||||
const auto defaults = demo_transfer(*world_, actor);
|
||||
criteria = defaults.at("criteria");
|
||||
mask = 15;
|
||||
}
|
||||
criteria["price_max"] = criteria.at("price_max").get<int64_t>() / factor;
|
||||
transfer_search_draft_ = criteria;
|
||||
transfer_search_draft_["positions"] = mask;
|
||||
transfer_dialog_ = "search";
|
||||
transfer_revision_ = snapshot.revision;
|
||||
transfer_world_ = world_;
|
||||
if (target && action != "transfer-search-reset")
|
||||
transfer_return_focus_ = target->GetId();
|
||||
focus_after_render_ = "transfer-search-position-0";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-search-position" ||
|
||||
action == "transfer-search-trait") {
|
||||
if (transfer_dialog_ != "search" || index < 0 ||
|
||||
index > (action == "transfer-search-position" ? 3 : 2))
|
||||
return true;
|
||||
const auto key =
|
||||
action == "transfer-search-position" ? "positions" : "traits";
|
||||
const int mask = transfer_search_draft_.at(key).get<int>() ^ (1 << index);
|
||||
if (mask)
|
||||
transfer_search_draft_[key] = mask;
|
||||
focus_after_render_ = target->GetId();
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-search-apply") {
|
||||
if (transfer_dialog_ != "search" || transfer_world_ != world_)
|
||||
return true;
|
||||
auto criteria = transfer_search_draft_;
|
||||
const auto mask = criteria.at("positions");
|
||||
criteria.erase("positions");
|
||||
if (change({{"kind", "criteria"}, {"value", criteria}, {"positions", mask}},
|
||||
transfer_revision_)) {
|
||||
transfer_view_["query"] = "";
|
||||
transfer_view_["page"] = 0;
|
||||
transfer_view_["market"] = "";
|
||||
transfer_view_["hover"] = "";
|
||||
close_transfer();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-orders") {
|
||||
transfer_dialog_ = "orders";
|
||||
transfer_revision_ = snapshot.revision;
|
||||
transfer_world_ = world_;
|
||||
transfer_return_focus_ = target ? target->GetId() : "transfer-orders";
|
||||
focus_after_render_ = "transfer-close";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-order-delete") {
|
||||
if (transfer_dialog_ != "orders" || transfer_world_ != world_ || index < 0)
|
||||
return true;
|
||||
if (change({{"kind", "remove"}, {"index", index}}, transfer_revision_)) {
|
||||
transfer_revision_ = snap().revision;
|
||||
focus_after_render_ = "transfer-close";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach") {
|
||||
transfer_dialog_ = "poach-clubs";
|
||||
const auto *c = world_->find("clubs", actor);
|
||||
transfer_poach_league_ = c ? c->value("competition", "") : "";
|
||||
transfer_poach_club_.clear();
|
||||
transfer_view_["poach_top"] = 0;
|
||||
transfer_revision_ = snapshot.revision;
|
||||
transfer_world_ = world_;
|
||||
transfer_return_focus_ = target ? target->GetId() : "transfer-poach";
|
||||
focus_after_render_ = "transfer-poach-country";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-club" && target) {
|
||||
const auto club = target->GetAttribute<Rml::String>("data-club", "");
|
||||
if (club == actor || !world_->find("clubs", club))
|
||||
return true;
|
||||
transfer_poach_club_ = club;
|
||||
transfer_dialog_ = "poach-roster";
|
||||
transfer_view_["poach_top"] = 0;
|
||||
focus_after_render_ = "transfer-poach-back";
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-back") {
|
||||
transfer_dialog_ = "poach-clubs";
|
||||
focus_after_render_ = "transfer-poach-club-" + transfer_poach_club_;
|
||||
refresh();
|
||||
return true;
|
||||
}
|
||||
if (action == "transfer-poach-player") {
|
||||
if (transfer_dialog_ != "poach-roster" || transfer_world_ != world_)
|
||||
return true;
|
||||
const auto p = demo_transfer_player(snapshot.state, *world_, actor, id);
|
||||
if (!p.value("ok", false) || p.at("row").at("club") != transfer_poach_club_)
|
||||
return true;
|
||||
begin_offer("buy", id, true);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool App::transfer_event(Rml::Event &event) {
|
||||
if (menu_ != "transfer" || !source_ || amount_ || !popup_.empty() ||
|
||||
!report_detail_kind_.empty())
|
||||
return false;
|
||||
const auto type = event.GetType();
|
||||
auto *target = event.GetTargetElement();
|
||||
const bool keyboard = type == "keydown";
|
||||
const auto key = keyboard ? Rml::Input::KeyIdentifier(
|
||||
event.GetParameter<int>("key_identifier", 0))
|
||||
: Rml::Input::KI_UNKNOWN;
|
||||
if ((type == "input" || type == "change") &&
|
||||
target->GetId() == "transfer-search") {
|
||||
auto *p = dynamic_cast<Rml::ElementFormControl *>(target);
|
||||
if (p)
|
||||
transfer_view_["query"] = p->GetValue();
|
||||
return true;
|
||||
}
|
||||
if (keyboard && key == Rml::Input::KI_RETURN &&
|
||||
target->GetId() == "transfer-search") {
|
||||
transfer_action("transfer-search", target);
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if ((type == "input" || type == "change") && (!transfer_dialog_.empty())) {
|
||||
auto *p = dynamic_cast<Rml::ElementFormControl *>(target);
|
||||
if (!p)
|
||||
return false;
|
||||
const auto raw = p->GetValue();
|
||||
if (target->GetId() == "transfer-poach-country") {
|
||||
const auto leagues = world_->leagues(raw);
|
||||
if (leagues.empty())
|
||||
return true;
|
||||
const auto next = leagues[0]->at("id").get<std::string>();
|
||||
if (next != transfer_poach_league_) {
|
||||
transfer_poach_league_ = next;
|
||||
transfer_view_["poach_top"] = 0;
|
||||
focus_after_render_ = "transfer-poach-country";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (target->GetId() == "transfer-poach-league") {
|
||||
const auto *league = world_->find("competitions", raw);
|
||||
if (league && league->value("type", "") == "league" &&
|
||||
raw != transfer_poach_league_) {
|
||||
transfer_poach_league_ = raw;
|
||||
transfer_view_["poach_top"] = 0;
|
||||
focus_after_render_ = "transfer-poach-league";
|
||||
refresh();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (raw.empty() || raw.size() > 3 ||
|
||||
raw.find_first_not_of("0123456789") != raw.npos)
|
||||
return true;
|
||||
const int value = std::stoi(raw);
|
||||
if (target->GetId() == "transfer-months" && transfer_dialog_ == "offer") {
|
||||
const bool loan = transfer_draft_.at("kind") == "loan" ||
|
||||
transfer_draft_.at("kind") == "lend";
|
||||
if (value == 12 || value == 24 || (!loan && (value == 36 || value == 48)))
|
||||
transfer_draft_["months"] = value;
|
||||
return true;
|
||||
}
|
||||
if (transfer_dialog_ == "search" &&
|
||||
target->HasAttribute("data-criterion")) {
|
||||
const auto field =
|
||||
target->GetAttribute<Rml::String>("data-criterion", "");
|
||||
const int maximum = (field == "age_min" || field == "age_max") ? 40
|
||||
: (field == "foot" || field == "type") ? 3
|
||||
: 100;
|
||||
const int minimum = (field == "age_min" || field == "age_max") ? 16 : 0;
|
||||
if (value < minimum || value > maximum ||
|
||||
!transfer_search_draft_.contains(field))
|
||||
return true;
|
||||
int next = value;
|
||||
if (field.ends_with("_min"))
|
||||
next =
|
||||
std::min(next, transfer_search_draft_
|
||||
.at(field.substr(0, field.size() - 4) + "_max")
|
||||
.get<int>());
|
||||
if (field.ends_with("_max"))
|
||||
next =
|
||||
std::max(next, transfer_search_draft_
|
||||
.at(field.substr(0, field.size() - 4) + "_min")
|
||||
.get<int>());
|
||||
transfer_search_draft_[field] = next;
|
||||
if (next != value)
|
||||
p->SetValue(std::to_string(next));
|
||||
if (auto *out = element("transfer-range-value-" + field))
|
||||
out->SetInnerRML("<span>" + std::to_string(next) + "</span>");
|
||||
dirty_ = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!transfer_dialog_.empty()) {
|
||||
if ((keyboard && key == Rml::Input::KI_ESCAPE) ||
|
||||
(type == "mouseup" && event.GetParameter<int>("button", 0) == 1)) {
|
||||
if (keyboard) {
|
||||
Rml::ElementList selects;
|
||||
if (auto *d = element("transfer-dialog"))
|
||||
d->QuerySelectorAll(selects, "select");
|
||||
for (auto *n : selects)
|
||||
if (auto *s = dynamic_cast<Rml::ElementFormControlSelect *>(n);
|
||||
s && s->IsSelectBoxVisible()) {
|
||||
s->CancelSelectBox();
|
||||
s->Focus(true);
|
||||
event.StopImmediatePropagation();
|
||||
dirty_ = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (transfer_dialog_ == "player-info" || transfer_dialog_ == "team-info")
|
||||
transfer_action("transfer-offer-back", nullptr);
|
||||
else if (transfer_dialog_ == "poach-roster")
|
||||
transfer_action("transfer-poach-back", nullptr);
|
||||
else
|
||||
close_transfer();
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
if (keyboard && key == Rml::Input::KI_TAB) {
|
||||
Rml::ElementList fields;
|
||||
if (auto *d = element("transfer-dialog"))
|
||||
d->QuerySelectorAll(fields, "button,input,select");
|
||||
std::erase_if(fields, [](auto *n) {
|
||||
return !n->IsVisible(true) || n->HasAttribute("disabled");
|
||||
});
|
||||
if (!fields.empty()) {
|
||||
const auto at = std::find(fields.begin(), fields.end(),
|
||||
context_->GetFocusElement());
|
||||
const int old = at == fields.end() ? -1 : int(at - fields.begin()),
|
||||
count = int(fields.size());
|
||||
const bool back = event.GetParameter<int>("shift_key", 0) != 0;
|
||||
fields[size_t(old < 0 ? (back ? count - 1 : 0)
|
||||
: (old + (back ? -1 : 1) + count) % count)]
|
||||
->Focus(true);
|
||||
}
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
bool inside = false;
|
||||
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
||||
if (n->GetId() == "transfer-dialog")
|
||||
inside = true;
|
||||
if (!inside && (type == "click" || type == "mousedown" ||
|
||||
type == "mouseup" || type == "dblclick" || keyboard)) {
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (type == "mouseup" && event.GetParameter<int>("button", 0) == 1) {
|
||||
bool offers = false;
|
||||
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
||||
if (n->GetId() == "transfer-offers")
|
||||
offers = true;
|
||||
if (offers) {
|
||||
const auto pool =
|
||||
demo_transfer_view(snap().state, *world_, transfer_ui_club(snap()))
|
||||
.at("market");
|
||||
const int pages = std::max(1, int((pool.size() + 5) / 6));
|
||||
transfer_view_["page"] = (transfer_view_.value("page", 0) + 1) % pages;
|
||||
if (!pool.empty()) {
|
||||
const auto &r = pool[size_t(transfer_view_.at("page").get<int>()) * 6];
|
||||
const bool own = r.at("own");
|
||||
transfer_view_[own ? "own" : "market"] = r.at("id");
|
||||
transfer_view_["side"] = own ? "own" : "market";
|
||||
}
|
||||
transfer_view_["hover"] = "";
|
||||
refresh();
|
||||
event.StopImmediatePropagation();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (type == "mousemove" || type == "focus") {
|
||||
std::string hover;
|
||||
for (auto *n = target; n && n != doc_; n = n->GetParentNode())
|
||||
if (n->HasAttribute("data-preview")) {
|
||||
hover = n->GetAttribute<Rml::String>("data-preview", "");
|
||||
break;
|
||||
}
|
||||
if (type == "focus" && hover.empty())
|
||||
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));
|
||||
auto row = transfer_ui_find(rows.at("market"), hover);
|
||||
if (row.is_null())
|
||||
row = transfer_view_.value("side", std::string()) == "own"
|
||||
? transfer_ui_find(rows.at("own"),
|
||||
transfer_view_.value("own", std::string()))
|
||||
: transfer_ui_find(
|
||||
rows.at("market"),
|
||||
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>() +
|
||||
(row.at("own") == true ? fee : -fee);
|
||||
body = "<p>" + label(world_->find("clubs", row.at("club")), 32) +
|
||||
"</p><div><section><span>" +
|
||||
std::string(row.at("own") == true ? "Marktwert"
|
||||
: "Geforderte Ablöse") +
|
||||
"</span><strong>" + esc(cash(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>";
|
||||
}
|
||||
if (auto *preview = element("transfer-preview"))
|
||||
preview->SetInnerRML(body);
|
||||
dirty_ = true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,827 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
namespace {
|
||||
const Json &transfer_ui_field(const Json &v, const char *key) {
|
||||
static const Json empty;
|
||||
if (v.is_object()) {
|
||||
auto i = v.find(key);
|
||||
if (i != v.end())
|
||||
return *i;
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
std::string transfer_ui_text(const Json &v, const std::string &fallback = "—") {
|
||||
return v.is_string() && !v.get_ref<const std::string &>().empty()
|
||||
? v.get<std::string>()
|
||||
: fallback;
|
||||
}
|
||||
std::string transfer_ui_number(const Json &v) {
|
||||
if (v.is_number_integer())
|
||||
return number(v.get<int64_t>());
|
||||
if (!v.is_number())
|
||||
return "—";
|
||||
std::ostringstream s;
|
||||
s.imbue(std::locale::classic());
|
||||
s << std::setprecision(4) << v.get<double>();
|
||||
auto out = s.str();
|
||||
std::replace(out.begin(), out.end(), '.', ',');
|
||||
return out;
|
||||
}
|
||||
std::string transfer_ui_role(const Json &v) {
|
||||
const auto p = transfer_ui_text(v, "");
|
||||
return p == "gk" ? "TW"
|
||||
: p == "def" ? "ABW"
|
||||
: p == "mid" ? "MIT"
|
||||
: p == "fwd" ? "STU"
|
||||
: "—";
|
||||
}
|
||||
std::string transfer_ui_club(const Snapshot &s) {
|
||||
return s.state.at("managers")[0].at("club").get<std::string>();
|
||||
}
|
||||
Json transfer_ui_find(const Json &rows, const std::string &id) {
|
||||
if (rows.is_array())
|
||||
for (const auto &r : rows)
|
||||
if (r.at("id") == id)
|
||||
return r;
|
||||
return nullptr;
|
||||
}
|
||||
const std::array<const char *, 7> transfer_ui_bonuses{
|
||||
"Torprämie", "Punktprämie", "Auflaufprämie", "Meisterprämie",
|
||||
"Prämie Pl. 2–5", "Prämie Pl. 6–10", "Nichtabstiegsprämie"};
|
||||
} // namespace
|
||||
|
||||
void App::transfer_remember_scroll() {
|
||||
if (!transfer_view_.is_object())
|
||||
return;
|
||||
for (const auto &[id, key] :
|
||||
std::array<std::pair<const char *, const char *>, 4>{
|
||||
{{"transfer-roster-scroll", "roster_top"},
|
||||
{"transfer-market-scroll", "market_top"},
|
||||
{"transfer-poach-scroll", "poach_top"},
|
||||
{"transfer-orders-scroll", "orders_top"}}})
|
||||
if (auto *node = element(id)) {
|
||||
transfer_view_[key] = node->GetScrollTop();
|
||||
if (std::string(id) == "transfer-roster-scroll")
|
||||
transfer_view_["roster_left"] = node->GetScrollLeft();
|
||||
}
|
||||
if (auto *node = element("transfer-poach-scroll")) {
|
||||
const auto key = node->GetAttribute<Rml::String>("data-scope", "");
|
||||
if (!key.empty())
|
||||
transfer_view_["poach_scrolls"][key] = node->GetScrollTop();
|
||||
}
|
||||
if (auto *node = element("transfer-dialog-scroll")) {
|
||||
const auto kind = node->GetAttribute<Rml::String>("data-dialog", "");
|
||||
if (!kind.empty())
|
||||
transfer_view_["dialog_scrolls"][kind] = node->GetScrollTop();
|
||||
}
|
||||
}
|
||||
void App::transfer_restore_scroll() {
|
||||
if (menu_ != "transfer" || !transfer_view_.is_object() ||
|
||||
!transfer_view_.value("restore_scroll", false))
|
||||
return;
|
||||
transfer_view_["restore_scroll"] = false;
|
||||
for (const auto &[id, key] :
|
||||
std::array<std::pair<const char *, const char *>, 4>{
|
||||
{{"transfer-roster-scroll", "roster_top"},
|
||||
{"transfer-market-scroll", "market_top"},
|
||||
{"transfer-poach-scroll", "poach_top"},
|
||||
{"transfer-orders-scroll", "orders_top"}}})
|
||||
if (auto *node = element(id)) {
|
||||
const auto &v = transfer_ui_field(transfer_view_, key);
|
||||
if (v.is_number())
|
||||
node->SetScrollTop(v.get<float>());
|
||||
if (std::string(id) == "transfer-roster-scroll" &&
|
||||
transfer_view_.contains("roster_left"))
|
||||
node->SetScrollLeft(transfer_view_.at("roster_left").get<float>());
|
||||
}
|
||||
if (auto *node = element("transfer-poach-scroll")) {
|
||||
const auto key = node->GetAttribute<Rml::String>("data-scope", "");
|
||||
const auto &v = transfer_ui_field(
|
||||
transfer_ui_field(transfer_view_, "poach_scrolls"), key.c_str());
|
||||
if (v.is_number())
|
||||
node->SetScrollTop(v.get<float>());
|
||||
}
|
||||
if (auto *node = element("transfer-dialog-scroll")) {
|
||||
const auto kind = node->GetAttribute<Rml::String>("data-dialog", "");
|
||||
const auto &v = transfer_ui_field(
|
||||
transfer_ui_field(transfer_view_, "dialog_scrolls"), kind.c_str());
|
||||
if (v.is_number())
|
||||
node->SetScrollTop(v.get<float>());
|
||||
}
|
||||
}
|
||||
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);
|
||||
if (!data.value("ok", false))
|
||||
return {};
|
||||
if (!transfer_view_.is_object() || !transfer_view_.contains("tab"))
|
||||
transfer_view_ = {{"tab", 0},
|
||||
{"complete", false},
|
||||
{"scope", "active"},
|
||||
{"page", 0},
|
||||
{"side", "market"},
|
||||
{"own", ""},
|
||||
{"market", ""},
|
||||
{"hover", ""},
|
||||
{"query", data.at("query")},
|
||||
{"dialog_scrolls", Json::object()}};
|
||||
if (transfer_view_.value("applied_query", std::string()) !=
|
||||
data.at("query").get<std::string>()) {
|
||||
transfer_view_["query"] = data.at("query");
|
||||
transfer_view_["applied_query"] = data.at("query");
|
||||
}
|
||||
const auto &ours = data.at("own"), &pool = data.at("market");
|
||||
if (transfer_ui_find(ours, transfer_view_.value("own", std::string()))
|
||||
.is_null())
|
||||
transfer_view_["own"] = ours.empty() ? Json("") : ours[0].at("id");
|
||||
if (transfer_ui_find(pool, transfer_view_.value("market", std::string()))
|
||||
.is_null()) {
|
||||
transfer_view_["market"] = "";
|
||||
for (const auto &r : pool)
|
||||
if (r.at("own") == false) {
|
||||
transfer_view_["market"] = r.at("id");
|
||||
break;
|
||||
}
|
||||
}
|
||||
const bool complete = transfer_view_.value("complete", false),
|
||||
b = transfer_view_.value("tab", 0) == 1;
|
||||
const int pages = std::max(1, int((pool.size() + 5) / 6)),
|
||||
page = std::clamp(transfer_view_.value("page", 0), 0, pages - 1);
|
||||
transfer_view_["page"] = page;
|
||||
Json chosen =
|
||||
transfer_view_.value("side", std::string("market")) == "own"
|
||||
? transfer_ui_find(ours, transfer_view_.value("own", std::string()))
|
||||
: transfer_ui_find(pool,
|
||||
transfer_view_.value("market", std::string()));
|
||||
const auto hovered = transfer_view_.value("hover", std::string());
|
||||
auto preview = transfer_ui_find(pool, hovered);
|
||||
if (preview.is_null())
|
||||
preview = chosen;
|
||||
const auto listed = [&](const std::string &id) {
|
||||
const auto &ls = snapshot.state.at("transfer").at("listed");
|
||||
return std::find(ls.begin(), ls.end(), id) != ls.end();
|
||||
};
|
||||
const auto trait = [&](const Json &v, bool foot) {
|
||||
if (!v.is_number_integer())
|
||||
return std::string("<span class=\"transfer-trait\">—</span>");
|
||||
const int n = v.get<int>();
|
||||
const std::array<const char *, 4> fl{"", "Links", "Beidfüßig", "Rechts"},
|
||||
ty{"", "Defensiv", "Ausgeglichen", "Offensiv"};
|
||||
const std::string path = n == 2 ? "M16 4L28 16L16 28L4 16Z"
|
||||
: foot
|
||||
? (n == 1 ? "M28 16H4M4 16L14 6M4 16L14 26"
|
||||
: "M4 16H28M28 16L18 6M28 16L18 26")
|
||||
: (n == 1 ? "M16 4V28M16 28L6 18M16 28L26 18"
|
||||
: "M16 28V4M16 4L6 14M16 4L26 14");
|
||||
const auto svg =
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"32\" "
|
||||
"height=\"32\"><path d=\"" +
|
||||
path + "\" stroke=\"#9db7c9\" fill=\"none\" stroke-width=\"2\"/></svg>";
|
||||
return "<span class=\"transfer-trait\" title=\"" +
|
||||
std::string(foot ? fl[size_t(n)] : ty[size_t(n)]) + "\">" +
|
||||
picture(renderer_.diagram("transfer-trait-" +
|
||||
std::to_string(int(foot)) + "-" +
|
||||
std::to_string(n),
|
||||
svg, 64),
|
||||
32, 32) +
|
||||
"</span>";
|
||||
};
|
||||
const auto nation = [&](const Json &r) {
|
||||
const auto code = transfer_ui_text(r.at("nation"), "");
|
||||
const auto svg = ui_nation_flag_svg(code);
|
||||
return "<span class=\"transfer-nation\" title=\"" +
|
||||
esc(transfer_ui_text(transfer_ui_field(r, "nation_name"))) + "\">" +
|
||||
(svg.empty() ? std::string("—")
|
||||
: picture(renderer_.diagram(
|
||||
"transfer-flag-" +
|
||||
content::sha256(svg).substr(0, 12),
|
||||
svg, 120),
|
||||
36, 24)) +
|
||||
"</span>";
|
||||
};
|
||||
std::string out =
|
||||
"<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>())) +
|
||||
"</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") +
|
||||
"</span></header><div id=\"transfer-roster-scroll\" "
|
||||
"class=\"transfer-roster-scroll\"><div class=\"transfer-roster-table " +
|
||||
std::string(b ? "data-b" : "data-a") + "\">";
|
||||
std::vector<std::string> headers =
|
||||
b ? std::vector<std::string>{"Spieler", "Alter", "Ecke",
|
||||
"Frei", "Zwei", "Pass",
|
||||
"Schuss", "Schnell", "Team"}
|
||||
: std::vector<std::string>{"Spieler", "Pos.", "Fuß", "Typ",
|
||||
"Kond.", "Tech.", "Form", "Stärke"};
|
||||
if (complete) {
|
||||
const std::vector<std::string> extras =
|
||||
b ? std::vector<std::string>{"Liga", "Pokal", "Europa", "Tore",
|
||||
"Vorlagen"}
|
||||
: std::vector<std::string>{"Alter", "Land", "Spiele", "Tore",
|
||||
"Vorlagen"};
|
||||
headers.insert(headers.end(), extras.begin(), extras.end());
|
||||
}
|
||||
const double namewidth = complete ? 22. : 33.,
|
||||
width = (100 - namewidth) / (headers.size() - 1);
|
||||
out += "<div class=\"transfer-roster-row head\">";
|
||||
for (size_t i = 0; i < headers.size(); ++i)
|
||||
out += "<div style=\"width:" + scalar(i ? width : namewidth) +
|
||||
"%;\"><span>" + headers[i] + "</span></div>";
|
||||
out += "</div>";
|
||||
for (size_t i = 0; i < ours.size(); ++i) {
|
||||
const auto &r = ours[i];
|
||||
const auto id = r.at("id").get<std::string>();
|
||||
std::vector<std::string> values;
|
||||
if (b) {
|
||||
values.push_back(transfer_ui_number(r.at("age")));
|
||||
for (const auto &v : r.at("skills"))
|
||||
values.push_back(transfer_ui_number(v));
|
||||
} else
|
||||
values = {transfer_ui_role(r.at("position")),
|
||||
trait(r.at("foot"), true),
|
||||
trait(r.at("type"), false),
|
||||
transfer_ui_number(r.at("condition")),
|
||||
transfer_ui_number(r.at("technique")),
|
||||
transfer_ui_number(r.at("form")),
|
||||
transfer_ui_number(r.at("strength"))};
|
||||
if (complete) {
|
||||
if (b) {
|
||||
for (auto *key :
|
||||
{"league_games", "cup_games", "europe_games", "goals", "assists"})
|
||||
values.push_back(transfer_ui_number(r.at(key)));
|
||||
} else {
|
||||
values.push_back(transfer_ui_number(r.at("age")));
|
||||
values.push_back(nation(r));
|
||||
for (auto *key : {"games", "goals", "assists"})
|
||||
values.push_back(transfer_ui_number(r.at(key)));
|
||||
}
|
||||
}
|
||||
out += "<div class=\"transfer-roster-row " +
|
||||
std::string(i % 2 == 0 ? "striped " : "") +
|
||||
(transfer_view_.value("side", std::string()) == "own" &&
|
||||
transfer_view_.at("own") == id
|
||||
? "selected"
|
||||
: "") +
|
||||
"\"><div class=\"transfer-name-cell\" style=\"width:" +
|
||||
scalar(namewidth) + "%;\">" +
|
||||
btn("transfer-own",
|
||||
"<span class=\"transfer-player-rank\">" + std::to_string(i + 1) +
|
||||
".</span><span class=\"transfer-player-name\">" +
|
||||
esc(r.at("name").get<std::string>()) + "</span>" +
|
||||
(listed(id) ? "<span class=\"transfer-list-marker\">●</span>"
|
||||
: ""),
|
||||
listed(id) ? "transfer-listed" : "",
|
||||
"id=\"transfer-own-" + esc(id) + "\" data-player=\"" + esc(id) +
|
||||
"\" aria-pressed=\"" +
|
||||
(transfer_view_.value("side", std::string()) == "own" &&
|
||||
transfer_view_.at("own") == id
|
||||
? "true"
|
||||
: "false") +
|
||||
"\"") +
|
||||
"</div>";
|
||||
for (const auto &v : values)
|
||||
out += "<div style=\"width:" + scalar(width) + "%;\"><span>" + v +
|
||||
"</span></div>";
|
||||
out += "</div>";
|
||||
}
|
||||
if (ours.empty())
|
||||
out += "<p class=\"transfer-empty\">Keine Kaderspieler vorhanden.</p>";
|
||||
out += "</div></div><p class=\"transfer-roster-note\">" +
|
||||
std::string(
|
||||
complete
|
||||
? "Vollständige Kaderdaten"
|
||||
: "Spieler links wählen, um zu verkaufen oder zu verleihen") +
|
||||
"</p></section>";
|
||||
if (!complete) {
|
||||
out +=
|
||||
"<section id=\"transfer-market-scroll\" class=\"transfer-market\"><div "
|
||||
"class=\"transfer-market-content\"><header><h2>Angebote</"
|
||||
"h2><span>Kondition · Technik · Form (Stärke)</span></header><div "
|
||||
"class=\"transfer-name-search\"><input id=\"transfer-search\" "
|
||||
"maxlength=\"40\" value=\"" +
|
||||
esc(transfer_view_.value("query",
|
||||
data.at("query").get<std::string>())) +
|
||||
"\" aria-label=\"Spielername suchen\" placeholder=\"Spielername "
|
||||
"suchen\"/>" +
|
||||
btn("transfer-search", "Finden", "", "id=\"transfer-find\"") +
|
||||
"</div><div id=\"transfer-offers\" class=\"transfer-offers\">";
|
||||
for (size_t i = size_t(page) * 6;
|
||||
i < std::min(pool.size(), size_t(page + 1) * 6); ++i) {
|
||||
const auto &r = pool[i];
|
||||
const auto id = r.at("id").get<std::string>();
|
||||
const bool mine = r.at("own");
|
||||
out += btn(
|
||||
mine ? "transfer-own" : "transfer-market",
|
||||
"<span class=\"transfer-market-name\">" + nation(r) + "<strong>" +
|
||||
esc(r.at("name").get<std::string>()) + "</strong><span>" +
|
||||
transfer_ui_role(r.at("position")) + "</span>" +
|
||||
trait(r.at("foot"), true) + trait(r.at("type"), false) +
|
||||
"</span><span class=\"transfer-market-attributes\"><span>" +
|
||||
transfer_ui_number(r.at("condition")) + " · " +
|
||||
transfer_ui_number(r.at("technique")) + " · " +
|
||||
transfer_ui_number(r.at("form")) + " <strong>(" +
|
||||
transfer_ui_number(r.at("strength")) + ")</strong></span><span>" +
|
||||
transfer_ui_number(r.at("age")) + " Jahre</span></span>",
|
||||
"transfer-market-player " +
|
||||
std::string(mine ? "transfer-own-listing " : "") +
|
||||
((mine ? transfer_view_.at("own")
|
||||
: transfer_view_.at("market")) == id &&
|
||||
transfer_view_.value("side", std::string()) ==
|
||||
(mine ? "own" : "market")
|
||||
? "selected"
|
||||
: ""),
|
||||
"id=\"transfer-market-" + esc(id) + "\" data-player=\"" + esc(id) +
|
||||
"\" data-preview=\"" + esc(id) + "\" aria-pressed=\"" +
|
||||
(((mine ? transfer_view_.at("own")
|
||||
: transfer_view_.at("market")) == id)
|
||||
? "true"
|
||||
: "false") +
|
||||
"\" style=\"" +
|
||||
rect(0, (i - size_t(page) * 6) * 128.7864583, 1087.03125,
|
||||
120.7864583) +
|
||||
"\"");
|
||||
}
|
||||
if (pool.empty())
|
||||
out +=
|
||||
"<p class=\"transfer-empty\">Keine Spieler für diese "
|
||||
"Auswahl.<small>Name, Positionen oder Suchprofil ändern.</small></p>";
|
||||
out +=
|
||||
"</div><div class=\"transfer-market-pages\">" +
|
||||
btn("transfer-page", "‹", "",
|
||||
"id=\"transfer-page-previous\" data-step=\"-1\" " +
|
||||
std::string(page == 0 ? "disabled" : "")) +
|
||||
"<span>" +
|
||||
(pool.empty()
|
||||
? std::string("Keine Angebote")
|
||||
: std::to_string(page * 6 + 1) + "–" +
|
||||
std::to_string(std::min(pool.size(), size_t(page + 1) * 6)) +
|
||||
" von " + std::to_string(pool.size())) +
|
||||
"</span>" +
|
||||
btn("transfer-page", "›", "",
|
||||
"id=\"transfer-page-next\" data-step=\"1\" " +
|
||||
std::string(page + 1 >= pages ? "disabled" : "")) +
|
||||
"</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>() +
|
||||
(preview.at("own") == true ? fee : -fee);
|
||||
out += "<p>" + label(source, 32) + "</p><div><section><span>" +
|
||||
std::string(preview.at("own") == true ? "Marktwert"
|
||||
: "Geforderte Ablöse") +
|
||||
"</span><strong>" + esc(cash(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>";
|
||||
} else
|
||||
out += "<p>Wähle einen angebotenen Spieler.</p>";
|
||||
out += "</section><nav class=\"transfer-filters\">";
|
||||
const std::array<const char *, 5> filters{"Alle", "Tor", "ABW", "MIT",
|
||||
"STU"};
|
||||
for (int i = 0; i < 5; ++i)
|
||||
out +=
|
||||
btn("transfer-filter", filters[size_t(i)], "",
|
||||
"id=\"transfer-filter-" + std::to_string(i) + "\" data-index=\"" +
|
||||
std::to_string(i) + "\" aria-pressed=\"" +
|
||||
std::string((i == 0 ? data.at("positions") == 15
|
||||
: bool(data.at("positions").get<int>() &
|
||||
(1 << (i - 1))))
|
||||
? "true"
|
||||
: "false") +
|
||||
"\"");
|
||||
out += "</nav>";
|
||||
const auto strengths = demo_transfer_strengths(
|
||||
snapshot.state, *world_, own, demo_lineup_active(snapshot.state));
|
||||
const auto scope = transfer_view_.value("scope", std::string("active"));
|
||||
out +=
|
||||
"<section class=\"transfer-strengths\"><header><nav>" +
|
||||
btn("transfer-scope", "Aktive", "",
|
||||
"id=\"transfer-scope-active\" data-scope=\"active\" "
|
||||
"aria-pressed=\"" +
|
||||
std::string(scope == "active" ? "true" : "false") + "\"") +
|
||||
btn("transfer-scope", "Team", "",
|
||||
"id=\"transfer-scope-team\" data-scope=\"team\" aria-pressed=\"" +
|
||||
std::string(scope == "team" ? "true" : "false") + "\"") +
|
||||
"</nav><p>Durchschnitt <strong>" +
|
||||
transfer_ui_number(
|
||||
strengths.at(scope == "team" ? "team_average" : "active_average")) +
|
||||
"</strong></p></header><div>";
|
||||
for (int i = 0; i < 4; ++i)
|
||||
out += "<section><span>" +
|
||||
std::string(std::array<const char *, 4>{
|
||||
"Tor", "Abwehr", "Mittelfeld", "Sturm"}[size_t(i)]) +
|
||||
"</span><strong>" +
|
||||
transfer_ui_number(strengths.at(scope)[size_t(i)]) +
|
||||
"</strong></section>";
|
||||
out += "</div></section><div class=\"transfer-business\"><p>" +
|
||||
(chosen.is_object()
|
||||
? std::string(chosen.at("own") == true ? "Eigener Spieler: "
|
||||
: "Marktspieler: ") +
|
||||
esc(chosen.at("name").get<std::string>())
|
||||
: "Kein Marktspieler ausgewählt") +
|
||||
"</p><div>";
|
||||
const bool mine = chosen.is_object() && chosen.at("own") == true;
|
||||
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")) +
|
||||
btn("transfer-offer", "Ver-leihen", "",
|
||||
"id=\"transfer-offer-loan-lend\" data-kind=\"" +
|
||||
std::string(mine ? "lend" : "loan") + "\" " +
|
||||
std::string(chosen.is_object() ? "" : "disabled")) +
|
||||
"</div></div></div></section>";
|
||||
}
|
||||
out += "</div><nav class=\"transfer-actions\">" +
|
||||
btn("transfer-data", b ? "Daten A" : "Daten B", "",
|
||||
"id=\"transfer-data\"") +
|
||||
btn("transfer-all", complete ? "Angebote" : "Komplett", "",
|
||||
"id=\"transfer-all\" aria-pressed=\"" +
|
||||
std::string(complete ? "true" : "false") + "\"");
|
||||
if (!complete)
|
||||
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-orders",
|
||||
"Aufträge (" + std::to_string(data.at("orders").size()) + ")",
|
||||
"", "id=\"transfer-orders\"");
|
||||
transfer_view_["restore_scroll"] = true;
|
||||
return out + "</nav></section>" + render_transfer_dialog();
|
||||
}
|
||||
|
||||
std::string App::render_transfer_dialog() {
|
||||
if (transfer_dialog_.empty())
|
||||
return {};
|
||||
const auto snapshot = snap();
|
||||
const auto actor = transfer_ui_club(snapshot);
|
||||
std::string title, body, actions;
|
||||
double height = 500;
|
||||
const auto button = [&](const char *action, const std::string &caption,
|
||||
const std::string &attrs = "") {
|
||||
return btn(action, esc(caption), "transfer-dialog-button", attrs);
|
||||
};
|
||||
const auto close = [&](const std::string &caption = "Abbruch") {
|
||||
return button("transfer-close", caption, "id=\"transfer-close\"");
|
||||
};
|
||||
if (transfer_dialog_ == "offer") {
|
||||
height = 1210.5;
|
||||
const auto &d = transfer_draft_;
|
||||
const auto &r = d.at("row");
|
||||
const auto kind = d.at("kind").get<std::string>();
|
||||
const bool loan = kind == "loan" || kind == "lend", mine = r.at("own");
|
||||
const std::map<std::string, std::string> kinds{{"buy", "Kaufen"},
|
||||
{"loan", "Ausleihen"},
|
||||
{"sell", "Verkaufen"},
|
||||
{"lend", "Verleihen"}};
|
||||
title =
|
||||
(d.at("poached") == true ? std::string("Abwerben") : kinds.at(kind)) +
|
||||
" · " + r.at("name").get<std::string>();
|
||||
const auto flag = ui_nation_flag_svg(transfer_ui_text(r.at("nation"), ""));
|
||||
const auto flag_image =
|
||||
flag.empty()
|
||||
? std::string("<span>—</span>")
|
||||
: picture(renderer_.diagram("transfer-offer-flag", flag, 180), 60,
|
||||
40);
|
||||
body = "<section class=\"transfer-offer-layout\"><header><div "
|
||||
"class=\"transfer-offer-flag\">" +
|
||||
flag_image + "</div><div class=\"transfer-offer-person\"><strong>" +
|
||||
esc(r.at("name").get<std::string>()) + "</strong><span>" +
|
||||
transfer_ui_role(r.at("position")) + " · " +
|
||||
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) +
|
||||
"</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>())) +
|
||||
"</strong></section><section><span>" +
|
||||
std::string(mine ? "Aktuelles Monatsgehalt" : "Gehaltswunsch") +
|
||||
"</span><strong>" +
|
||||
(d.at("demand_salary").is_number_integer()
|
||||
? esc(cash(d.at("demand_salary").get<int64_t>()))
|
||||
: "—") +
|
||||
"</strong></section></div><h3 class=\"transfer-offer-your\">Dein "
|
||||
"Angebot</h3><div class=\"transfer-offer-inputs\">";
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
const auto field = i == 0 ? "fee" : i == 1 ? "salary" : "months";
|
||||
const std::string caption = i == 0 ? (loan ? "Leihgebühr" : "Ablöse")
|
||||
: i == 1 ? "Monatsgehalt"
|
||||
: "Vertragsdauer";
|
||||
body += "<div><span>" + caption + "</span>";
|
||||
if (i < 2)
|
||||
body += btn("transfer-amount",
|
||||
esc(std::to_string(d.at(field).get<int64_t>())),
|
||||
"transfer-amount-input amount-trigger",
|
||||
"id=\"transfer-" + std::string(field) + "\" data-field=\"" +
|
||||
field + "\" aria-label=\"" + caption + "\"");
|
||||
else {
|
||||
body += "<select id=\"transfer-months\" aria-label=\"Vertragsdauer in "
|
||||
"Monaten\">";
|
||||
for (int months : {12, 24, 36, 48})
|
||||
if (!loan || months <= 24)
|
||||
body += "<option value=\"" + std::to_string(months) + "\" " +
|
||||
std::string(d.at("months") == months ? "selected" : "") +
|
||||
">" + std::to_string(months) + " Monate</option>";
|
||||
body += "</select>";
|
||||
}
|
||||
body += "</div>";
|
||||
}
|
||||
body += "</div><section "
|
||||
"class=\"transfer-offer-premiums\"><h3>Mannschaftsprämien für "
|
||||
"diesen Vertrag</h3><div>";
|
||||
for (int i = 0; i < 7; ++i)
|
||||
body +=
|
||||
"<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)]),
|
||||
"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(loan ? "Verleihen" : "Verkauf") +
|
||||
" auf dem Markt vorgemerkt."
|
||||
: "Das Angebot wird vorgemerkt; die Entscheidung "
|
||||
"des Spielers folgt später.") +
|
||||
"</p></section>";
|
||||
actions =
|
||||
button("transfer-team-info", "Team-Info", "id=\"transfer-team-info\"") +
|
||||
button("transfer-player-info", "Spieler-Info",
|
||||
"id=\"transfer-player-info\"") +
|
||||
close() +
|
||||
button("transfer-submit", "Angebot",
|
||||
"id=\"transfer-submit\" " +
|
||||
std::string(d.value("can_submit", true) ? "" : "disabled"));
|
||||
} else if (transfer_dialog_ == "search") {
|
||||
height = 899;
|
||||
title = "Spieler suchen";
|
||||
const auto &d = transfer_search_draft_;
|
||||
body = "<section class=\"transfer-search-editor\"><section "
|
||||
"class=\"transfer-search-kind\"><h3>Art</h3><nav>";
|
||||
for (int i = 0; i < 4; ++i)
|
||||
body += btn(
|
||||
"transfer-search-position",
|
||||
std::array<const char *, 4>{"Tor", "ABW", "MIT", "STU"}[size_t(i)],
|
||||
"",
|
||||
"id=\"transfer-search-position-" + std::to_string(i) +
|
||||
"\" data-index=\"" + std::to_string(i) + "\" aria-pressed=\"" +
|
||||
std::string(d.at("positions").get<int>() & (1 << i) ? "true"
|
||||
: "false") +
|
||||
"\"");
|
||||
body += "</nav></section><section class=\"transfer-search-ranges\">";
|
||||
const std::array<std::pair<const char *, const char *>, 4> ranges{
|
||||
{{"age_min", "Alter von"},
|
||||
{"age_max", "Alter bis"},
|
||||
{"strength_min", "Stärke von"},
|
||||
{"strength_max", "Stärke bis"}}};
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
const auto [key, caption] = ranges[size_t(i)];
|
||||
body += "<div style=\"" +
|
||||
rect((i % 2) * 1068.5, 20 + (i / 2) * 57, 1023.5, 31) +
|
||||
"\"><span>" + caption +
|
||||
"</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=\"" +
|
||||
transfer_ui_number(d.at(key)) +
|
||||
"\"/><output id=\"transfer-range-value-" + key + "\">" +
|
||||
transfer_ui_number(d.at(key)) + "</output></div>";
|
||||
}
|
||||
body += "</section><section class=\"transfer-search-traits\"><h3>Typ · "
|
||||
"darauf achten</h3><nav>";
|
||||
for (int i = 0; i < 3; ++i)
|
||||
body += btn(
|
||||
"transfer-search-trait",
|
||||
std::array<const char *, 3>{"Kondition", "Technik",
|
||||
"Form"}[size_t(i)],
|
||||
"",
|
||||
"id=\"transfer-search-trait-" + std::to_string(i) +
|
||||
"\" data-index=\"" + std::to_string(i) + "\" aria-pressed=\"" +
|
||||
std::string(d.at("traits").get<int>() & (1 << i) ? "true"
|
||||
: "false") +
|
||||
"\"");
|
||||
body += "</nav></section><section class=\"transfer-search-space\">";
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
const auto field = i ? "foot" : "type";
|
||||
const std::array<const char *, 4> names =
|
||||
i ? std::array<const char *, 4>{"Beliebig", "Links", "Beidfüßig",
|
||||
"Rechts"}
|
||||
: std::array<const char *, 4>{"Beliebig", "Defensiv",
|
||||
"Ausgeglichen", "Offensiv"};
|
||||
body += "<div><span>" + std::string(i ? "Spielseite" : "Spielweise") +
|
||||
"</span><select id=\"transfer-criterion-" + field +
|
||||
"\" data-criterion=\"" + field + "\" aria-label=\"" +
|
||||
std::string(i ? "Spielseite" : "Spielweise") + "\">";
|
||||
for (int n = 0; n < 4; ++n)
|
||||
body += "<option value=\"" + std::to_string(n) + "\" " +
|
||||
std::string(d.at(field) == n ? "selected" : "") + ">" +
|
||||
names[size_t(n)] + "</option>";
|
||||
body += "</select></div>";
|
||||
}
|
||||
body +=
|
||||
"</section><section "
|
||||
"class=\"transfer-search-budget\"><span>Preisvorstellung bis</span>" +
|
||||
btn("transfer-search-budget",
|
||||
esc(std::to_string(d.at("price_max").get<int64_t>())),
|
||||
"amount-trigger",
|
||||
"id=\"transfer-search-budget\" aria-label=\"Maximale "
|
||||
"Ablösesumme\"") +
|
||||
"</section></section>";
|
||||
actions = close() +
|
||||
button("transfer-search-reset", "Zurücksetzen",
|
||||
"id=\"transfer-search-reset\"") +
|
||||
button("transfer-search-apply", "Suchen",
|
||||
"id=\"transfer-search-apply\"");
|
||||
} else if (transfer_dialog_ == "player-info") {
|
||||
height = 822;
|
||||
const auto &r = transfer_draft_.at("row");
|
||||
title = r.at("name").get<std::string>();
|
||||
body = "<div class=\"transfer-player-info\"><div "
|
||||
"class=\"transfer-info-photo\">" +
|
||||
(r.at("photo").is_string()
|
||||
? img(r.at("photo"), 440, 550, true, true, 650)
|
||||
: "<span>—</span>") +
|
||||
"</div><div class=\"transfer-info-facts\">";
|
||||
const std::vector<std::pair<std::string, std::string>> facts{
|
||||
{"Verein", r.at("club_name")},
|
||||
{"Position", transfer_ui_role(r.at("position"))},
|
||||
{"Alter", transfer_ui_number(r.at("age")) + " Jahre"},
|
||||
{"Kondition", transfer_ui_number(r.at("condition"))},
|
||||
{"Technik", transfer_ui_number(r.at("technique"))},
|
||||
{"Form", transfer_ui_number(r.at("form"))},
|
||||
{"Stärke", transfer_ui_number(r.at("strength"))},
|
||||
{"Fuß", r.at("foot").is_number_integer()
|
||||
? std::array<const char *, 4>{"—", "Links", "Beidfüßig",
|
||||
"Rechts"}[size_t(
|
||||
r.at("foot").get<int>())]
|
||||
: "—"},
|
||||
{"Typ", r.at("type").is_number_integer()
|
||||
? std::array<const char *,
|
||||
4>{"—", "Defensiv", "Ausgeglichen",
|
||||
"Offensiv"}[size_t(r.at("type").get<int>())]
|
||||
: "—"}};
|
||||
for (size_t i = 0; i < facts.size(); ++i)
|
||||
body += "<div style=\"" +
|
||||
rect((i % 2) * 823.5, (i / 2) * 115, 783.5, 91) + "\"><span>" +
|
||||
esc(facts[i].first) + "</span><strong>" + esc(facts[i].second) +
|
||||
"</strong></div>";
|
||||
body += "</div></div>";
|
||||
actions = button("transfer-offer-back", "Zurück zum Angebot",
|
||||
"id=\"transfer-offer-back\"");
|
||||
} else if (transfer_dialog_ == "team-info") {
|
||||
height = 800;
|
||||
title = "Team-Info";
|
||||
const auto values = 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) +
|
||||
"</h3><div class=\"transfer-info-table\"><div "
|
||||
"class=\"transfer-info-table-row "
|
||||
"head\"><span>Mannschaftsteil</span><span>Aktive</span><span>Team</"
|
||||
"span></div>";
|
||||
for (int i = 0; i < 4; ++i)
|
||||
body +=
|
||||
"<div class=\"transfer-info-table-row\"><span>" +
|
||||
std::string(std::array<const char *, 4>{"Tor", "Abwehr", "Mittelfeld",
|
||||
"Sturm"}[size_t(i)]) +
|
||||
"</span><span>" + transfer_ui_number(values.at("active")[size_t(i)]) +
|
||||
"</span><span>" + transfer_ui_number(values.at("team")[size_t(i)]) +
|
||||
"</span></div>";
|
||||
body += "</div></div>";
|
||||
actions = button("transfer-offer-back", "Zurück zum Angebot",
|
||||
"id=\"transfer-offer-back\"");
|
||||
} else if (transfer_dialog_ == "poach-clubs") {
|
||||
height = 1141;
|
||||
title = "Spieler abwerben";
|
||||
const auto leagues = world_->leagues();
|
||||
if (transfer_poach_league_.empty() && !leagues.empty())
|
||||
transfer_poach_league_ = leagues[0]->at("id").get<std::string>();
|
||||
const auto *league = world_->find("competitions", transfer_poach_league_);
|
||||
const auto country = league ? league->value("nation", "") : "";
|
||||
body = "<section class=\"transfer-poach\"><p>Verein wählen, danach einen "
|
||||
"Spieler aus dessen Beispielkader.</p><nav "
|
||||
"class=\"transfer-poach-pickers\"><select "
|
||||
"id=\"transfer-poach-country\" aria-label=\"Land\">";
|
||||
for (const auto &nation : world_->rows("nations")) {
|
||||
const auto id = nation.at("id").get<std::string>();
|
||||
if (world_->leagues(id).empty())
|
||||
continue;
|
||||
body += "<option value=\"" + esc(id) + "\" " +
|
||||
std::string(country == id ? "selected" : "") + ">" +
|
||||
esc(world_->name(nation)) + "</option>";
|
||||
}
|
||||
body +=
|
||||
"</select><select id=\"transfer-poach-league\" aria-label=\"Liga\">";
|
||||
for (const auto *l : world_->leagues(country))
|
||||
body +=
|
||||
"<option value=\"" + esc(l->at("id").get<std::string>()) + "\" " +
|
||||
std::string(l->at("id") == transfer_poach_league_ ? "selected" : "") +
|
||||
">" + esc(world_->name(*l)) + "</option>";
|
||||
body +=
|
||||
"</select></nav><div id=\"transfer-poach-scroll\" data-scope=\"clubs-" +
|
||||
esc(transfer_poach_league_) + "\" class=\"transfer-poach-clubs\">";
|
||||
const auto clubs = world_->clubs(transfer_poach_league_);
|
||||
for (size_t i = 0; i < clubs.size(); ++i)
|
||||
body += btn(
|
||||
"transfer-poach-club", label(clubs[i], 52), "",
|
||||
"id=\"transfer-poach-club-" +
|
||||
esc(clubs[i]->at("id").get<std::string>()) + "\" data-club=\"" +
|
||||
esc(clubs[i]->at("id").get<std::string>()) + "\" style=\"" +
|
||||
rect((i % 4) * 527, (i / 4) * 140, 511, 124) + "\" " +
|
||||
std::string(clubs[i]->at("id") == actor ? "disabled" : ""));
|
||||
body += "</div></section>";
|
||||
actions = close();
|
||||
} else if (transfer_dialog_ == "poach-roster") {
|
||||
height = 1400;
|
||||
const auto *club = world_->find("clubs", transfer_poach_club_);
|
||||
title = "Abwerben · " + std::string(club ? world_->name(*club) : "—");
|
||||
const auto rows = demo_transfer_roster(snapshot.state, *world_, actor,
|
||||
transfer_poach_club_);
|
||||
body = "<div id=\"transfer-poach-scroll\" data-scope=\"roster-" +
|
||||
esc(transfer_poach_club_) +
|
||||
"\" class=\"transfer-poach-roster\"><div class=\"transfer-poach-row "
|
||||
"head\"><span>Spieler</span><span>Pos.</span><span>Alter</"
|
||||
"span><span>Stärke</span><span>Marktwert</span></div>";
|
||||
if (rows.value("ok", false))
|
||||
for (const auto &r : rows.at("rows"))
|
||||
body +=
|
||||
"<div class=\"transfer-poach-row\">" +
|
||||
btn("transfer-poach-player", esc(r.at("name").get<std::string>()),
|
||||
"",
|
||||
"id=\"transfer-poach-player-" +
|
||||
esc(r.at("id").get<std::string>()) + "\" data-player=\"" +
|
||||
esc(r.at("id").get<std::string>()) + "\"") +
|
||||
"<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)) +
|
||||
"</span></div>";
|
||||
body += "</div>";
|
||||
actions = button("transfer-poach-back", "Zurück zu Vereinen",
|
||||
"id=\"transfer-poach-back\"") +
|
||||
close();
|
||||
} else if (transfer_dialog_ == "orders") {
|
||||
title = "Vorgemerkte Transferaufträge";
|
||||
const auto rows =
|
||||
demo_transfer_view(snapshot.state, *world_, actor).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())
|
||||
body += "<p>Noch keine Transferaufträge vorgemerkt.</p>";
|
||||
else {
|
||||
body += "<div class=\"transfer-order-row "
|
||||
"head\"><span>Spieler</span><span>Art</span><span>Betrag</"
|
||||
"span><span>Laufzeit</span><span></span></div>";
|
||||
const std::map<std::string, std::string> kinds{{"buy", "Kaufen"},
|
||||
{"loan", "Ausleihen"},
|
||||
{"sell", "Verkaufen"},
|
||||
{"lend", "Verleihen"}};
|
||||
for (size_t i = 0; i < rows.size(); ++i) {
|
||||
const auto &o = rows[i];
|
||||
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>())) +
|
||||
"</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\"") +
|
||||
"</div>";
|
||||
}
|
||||
}
|
||||
body += "</div>";
|
||||
actions = close("Zurück");
|
||||
} else {
|
||||
title = transfer_dialog_ == "booked" ? "Auftrag vorgemerkt"
|
||||
: "Transferliste voll";
|
||||
body = "<p class=\"transfer-notice\">" + esc(transfer_notice_) + "</p>";
|
||||
actions = close("Verstanden");
|
||||
}
|
||||
return "<div id=\"transfer-layer\" class=\"transfer-layer\"><section "
|
||||
"id=\"transfer-dialog\" class=\"transfer-dialog " +
|
||||
esc(transfer_dialog_) +
|
||||
"\" role=\"dialog\" aria-modal=\"true\" "
|
||||
"aria-labelledby=\"transfer-dialog-title\" style=\"height:" +
|
||||
scalar(height) + "dp;\"><h2 id=\"transfer-dialog-title\">" +
|
||||
esc(title) +
|
||||
"</h2><div id=\"transfer-dialog-scroll\" "
|
||||
"class=\"transfer-dialog-scroll\" data-dialog=\"" +
|
||||
esc(transfer_dialog_) + "\">" + body +
|
||||
"</div><nav class=\"transfer-dialog-actions\">" + actions +
|
||||
"</nav></section></div>";
|
||||
}
|
||||
+72
-6
@@ -12,6 +12,8 @@
|
||||
#include "modern/ui/demo_toto.hpp"
|
||||
#include "modern/ui/demo_reports.hpp"
|
||||
#include "modern/ui/demo_sports.hpp"
|
||||
#include "modern/ui/demo_lineup.hpp"
|
||||
#include "modern/ui/demo_transfer.hpp"
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include "modern/ui/gui_assets.hpp"
|
||||
#include "modern/ui/model.hpp"
|
||||
@@ -324,7 +326,7 @@ class App final : public Rml::EventListener {
|
||||
bool focus_ticket_ = false;
|
||||
std::set<std::string> pending_selects_;
|
||||
std::string focus_after_render_;
|
||||
bool keyboard_navigation_ = false;
|
||||
bool keyboard_navigation_ = false, setting_menu_markup_ = false;
|
||||
std::string last_rendered_menu_;
|
||||
std::optional<float> training_scroll_;
|
||||
std::optional<float> report_scroll_;
|
||||
@@ -352,6 +354,18 @@ class App final : public Rml::EventListener {
|
||||
int toto_column_ = 0;
|
||||
std::array<std::pair<int, int>, 6> toto_focus_{{{0,1},{0,1},{0,1},{0,1},{0,1},{0,1}}};
|
||||
std::string toto_dialog_, toto_return_focus_;
|
||||
bool lineup_pitch_ = true;
|
||||
int lineup_data_ = 0, lineup_page_ = 0;
|
||||
std::string lineup_side_ = "formations", lineup_selected_;
|
||||
Json lineup_drag_;
|
||||
uint64_t lineup_drag_revision_ = 0;
|
||||
std::shared_ptr<const Catalog> lineup_drag_world_;
|
||||
bool lineup_ignore_click_ = false, lineup_reset_scroll_ = false;
|
||||
std::optional<float> lineup_roster_scroll_, lineup_bench_scroll_;
|
||||
Json transfer_view_ = Json::object(), transfer_draft_, transfer_search_draft_;
|
||||
std::string transfer_dialog_, transfer_return_focus_, transfer_notice_, transfer_poach_league_, transfer_poach_club_, transfer_picker_;
|
||||
uint64_t transfer_revision_ = 0;
|
||||
std::shared_ptr<const Catalog> transfer_world_;
|
||||
float device_ratio_ = 1.f;
|
||||
Json desktop_ = Json::object(), saved_desktop_ = Json::object(),
|
||||
options_ = Json::object();
|
||||
@@ -565,6 +579,11 @@ class App final : public Rml::EventListener {
|
||||
renderer_.world(next);
|
||||
world_ = std::move(next);
|
||||
source_ = std::move(demo);
|
||||
lineup_drag_ = Json(); lineup_drag_world_.reset(); lineup_selected_.clear(); lineup_ignore_click_ = false;
|
||||
lineup_pitch_ = true; lineup_data_ = lineup_page_ = 0; lineup_side_ = "formations";
|
||||
transfer_view_ = Json::object(); transfer_draft_ = transfer_search_draft_ = Json();
|
||||
transfer_dialog_.clear(); transfer_picker_.clear(); transfer_notice_.clear(); transfer_return_focus_.clear();
|
||||
transfer_poach_league_.clear(); transfer_poach_club_.clear(); transfer_world_.reset(); transfer_revision_ = 0;
|
||||
advertising_selected_ = -1; advertising_offer_ = 0; advertising_revision_ = 0; advertising_world_.reset();
|
||||
toto_column_ = 0; toto_dialog_.clear();
|
||||
for (auto &focus : toto_focus_) focus = {0, 1};
|
||||
@@ -714,6 +733,17 @@ class App final : public Rml::EventListener {
|
||||
std::string render_toto();
|
||||
bool toto_action(const std::string &, Rml::Element *);
|
||||
bool toto_event(Rml::Event &);
|
||||
std::string render_lineup();
|
||||
bool lineup_action(const std::string &, Rml::Element *);
|
||||
bool lineup_event(Rml::Event &);
|
||||
void cancel_lineup_drag(bool refresh_view = true);
|
||||
std::string render_transfer();
|
||||
std::string render_transfer_dialog();
|
||||
bool transfer_action(const std::string &, Rml::Element *);
|
||||
bool transfer_event(Rml::Event &);
|
||||
void close_transfer(bool restore = true);
|
||||
void transfer_remember_scroll();
|
||||
void transfer_restore_scroll();
|
||||
std::string render_almanac();
|
||||
bool almanac_action(const std::string &, Rml::Element *);
|
||||
std::string render_indoor();
|
||||
@@ -742,8 +772,13 @@ class App final : public Rml::EventListener {
|
||||
}
|
||||
for (const auto &id : ready) {
|
||||
pending_selects_.erase(id);
|
||||
if (auto *select = element(id))
|
||||
change(select);
|
||||
if (auto *select = element(id)) {
|
||||
// Menu-local select handlers receive only a committed/cancelled value.
|
||||
if ((menu_ == "lineup" && id.starts_with("lineup-")) ||
|
||||
(menu_ == "transfer" && id.starts_with("transfer-")))
|
||||
select->DispatchEvent("change", {});
|
||||
else change(select);
|
||||
}
|
||||
}
|
||||
}
|
||||
void input(Rml::Element *);
|
||||
@@ -783,6 +818,9 @@ class App final : public Rml::EventListener {
|
||||
// open. Never keep that menu's modal/input gate in the destination view.
|
||||
if (menu_ != last_rendered_menu_) {
|
||||
planning_dialog_.clear();
|
||||
lineup_drag_ = Json(); lineup_drag_world_.reset(); lineup_ignore_click_ = false;
|
||||
transfer_dialog_.clear(); transfer_draft_ = transfer_search_draft_ = Json(); transfer_picker_.clear();
|
||||
transfer_world_.reset(); transfer_revision_ = 0; transfer_return_focus_.clear();
|
||||
toto_dialog_.clear();
|
||||
if (menu_ == "toto" && source_)
|
||||
for (size_t c = 0; c < toto_focus_.size(); ++c) {
|
||||
@@ -795,6 +833,15 @@ class App final : public Rml::EventListener {
|
||||
report_detail_kind_.clear();
|
||||
report_picker_.clear();
|
||||
}
|
||||
lineup_roster_scroll_.reset();
|
||||
lineup_bench_scroll_.reset();
|
||||
if (menu_ == "lineup" && last_rendered_menu_ == "lineup") {
|
||||
if (auto *roster = element("lineup-roster-scroll"))
|
||||
lineup_roster_scroll_ = lineup_reset_scroll_ ? 0.f : roster->GetScrollTop();
|
||||
if (auto *bench = element("lineup-bench-scroll"))
|
||||
lineup_bench_scroll_ = bench->GetScrollTop();
|
||||
}
|
||||
lineup_reset_scroll_ = false;
|
||||
training_scroll_.reset();
|
||||
if (menu_ == "training" && last_rendered_menu_ == "training")
|
||||
if (auto *roster = element("training-roster"))
|
||||
@@ -824,11 +871,13 @@ class App final : public Rml::EventListener {
|
||||
markup = render_desktop();
|
||||
if (!menu_.empty())
|
||||
markup += render_menu(menu_);
|
||||
setting_menu_markup_ = true;
|
||||
element("canvas")->SetInnerRML(markup);
|
||||
if (!report_detail_kind_.empty() || !planning_dialog_.empty() || !contracts_dialog_.empty() || !toto_dialog_.empty()) {
|
||||
setting_menu_markup_ = false;
|
||||
if (!report_detail_kind_.empty() || !planning_dialog_.empty() || !contracts_dialog_.empty() || !toto_dialog_.empty() || !transfer_dialog_.empty()) {
|
||||
Rml::ElementList behind;
|
||||
doc_->QuerySelectorAll(behind,
|
||||
"#report-underlay button,#report-underlay input,#report-underlay select,#contracts-underlay button,#toto-underlay button,.window .titlebar button");
|
||||
"#report-underlay button,#report-underlay input,#report-underlay select,#contracts-underlay button,#toto-underlay button,#lineup-underlay button,#lineup-underlay select,#lineup-underlay input,#transfer-underlay button,#transfer-underlay select,#transfer-underlay input,.window .titlebar button");
|
||||
for (auto *node : behind)
|
||||
node->SetProperty("pointer-events", "none");
|
||||
}
|
||||
@@ -867,7 +916,10 @@ class App final : public Rml::EventListener {
|
||||
if (focus_after_render_.starts_with("report-option-") ||
|
||||
focus_after_render_.starts_with("friendly-opponent-") ||
|
||||
focus_after_render_.starts_with("alm-match-") ||
|
||||
focus_after_render_.starts_with("contract-player-"))
|
||||
focus_after_render_.starts_with("contract-player-") ||
|
||||
focus_after_render_.starts_with("lineup-name-") ||
|
||||
focus_after_render_.starts_with("lineup-detail-") ||
|
||||
focus_after_render_.starts_with("lineup-bench-"))
|
||||
report_option_to_scroll_ = focus_after_render_;
|
||||
focus_after_render_.clear();
|
||||
}
|
||||
@@ -973,6 +1025,15 @@ class App final : public Rml::EventListener {
|
||||
list->SetScrollTop(*report_scroll_);
|
||||
report_scroll_.reset();
|
||||
}
|
||||
if (lineup_roster_scroll_) {
|
||||
if (auto *roster = element("lineup-roster-scroll")) roster->SetScrollTop(*lineup_roster_scroll_);
|
||||
lineup_roster_scroll_.reset();
|
||||
}
|
||||
if (lineup_bench_scroll_) {
|
||||
if (auto *bench = element("lineup-bench-scroll")) bench->SetScrollTop(*lineup_bench_scroll_);
|
||||
lineup_bench_scroll_.reset();
|
||||
}
|
||||
if (menu_ == "transfer") transfer_restore_scroll();
|
||||
if (!report_option_to_scroll_.empty()) {
|
||||
if (auto *node = element(report_option_to_scroll_))
|
||||
node->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
|
||||
@@ -1238,6 +1299,11 @@ public:
|
||||
#include "modern/ui/advertising_controls.inc"
|
||||
#include "modern/ui/toto_screens.inc"
|
||||
#include "modern/ui/toto_controls.inc"
|
||||
#include "modern/ui/nation_flags.inc"
|
||||
#include "modern/ui/lineup_screens.inc"
|
||||
#include "modern/ui/lineup_controls.inc"
|
||||
#include "modern/ui/transfer_screens.inc"
|
||||
#include "modern/ui/transfer_controls.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user