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,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);
|
||||
|
||||
Reference in new issue
Block a user