Port environment, advertising and Toto menus to native Modern UI (by Codex)

This commit is contained in:
Codex committed 2026-10-24 11:12:25 +02:00
1 parent 0aa0ed68ca
commit d92cfc3110
36 files changed
+1805 -13

No files matched your search

+11 -2
View File
@@ -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)
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)
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)
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)
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")
@@ -79,3 +79,12 @@ if(MSVC)
target_compile_options(modern_control_layout_tests PRIVATE /utf-8)
endif()
add_test(NAME modern_control_layout_tests COMMAND modern_control_layout_tests "${modern_assets}")
foreach(component environment advertising toto)
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)
target_compile_options(modern_${component}_ui_tests PRIVATE /utf-8)
endif()
add_test(NAME modern_${component}_ui_tests COMMAND modern_${component}_ui_tests)
endforeach()
+95
View File
@@ -0,0 +1,95 @@
// SPDX-License-Identifier: GPL-3.0-only
bool App::advertising_action(const std::string &action, Rml::Element *target) {
if (!action.starts_with("ad-")) return false;
if (menu_ != "advertising" || !source_ || !world_) return true;
if (action == "ad-contract" && target) {
const int slot = target->GetAttribute<int>("data-id", -1);
if (slot < 0 || slot > 15) return true;
advertising_selected_ = slot;
advertising_offer_ = 0;
advertising_revision_ = snap().revision;
advertising_world_ = world_;
focus_after_render_ = "ad-contract-" + std::to_string(slot);
refresh();
return true;
}
if (action == "ad-cancel") {
const int slot = advertising_selected_;
advertising_selected_ = -1;
advertising_offer_ = 0;
advertising_world_.reset();
if (slot >= 0 && slot <= 15) focus_after_render_ = "ad-contract-" + std::to_string(slot);
refresh();
return true;
}
if (action == "ad-offer" && target) {
const int step = target->GetAttribute<int>("data-step", 0);
if ((step != -1 && step != 1) || advertising_selected_ < 0 || advertising_selected_ > 15 ||
advertising_world_ != world_ || snap().revision != advertising_revision_) return true;
const auto q = demo_advertising_quote(snap().state, advertising_selected_, advertising_offer_, *world_);
if (!q.value("ok", false) || q.at("active") == true) return true;
advertising_offer_ = (advertising_offer_ + step + 3) % 3;
focus_after_render_ = target->GetId();
refresh();
return true;
}
if (action == "ad-accept") {
if (advertising_selected_ < 0 || advertising_selected_ > 15 || advertising_world_ != world_) return true;
const auto result = source_->apply({advertising_revision_, "advertising",
{{"kind", "accept"}, {"slot", advertising_selected_}, {"offer", advertising_offer_}}});
if (!result.ok) {
message("Das Angebot konnte nicht übernommen werden. Bitte den aktuellen Stand erneut auswählen. (" + result.error + ")");
return true;
}
advertising_revision_ = result.revision;
focus_after_render_ = "ad-cancel";
refresh();
return true;
}
if (action == "ad-spending" && target) {
const int index = target->GetAttribute<int>("data-id", -1);
const auto snapshot = snap();
const auto view = demo_advertising_view(snapshot.state, *world_);
if (!view.value("ok", false) || index < 0 || index > 2) return true;
const auto &row = view.at("spending")[size_t(index)];
const auto world = world_;
const auto *source = source_.get();
const auto revision = snapshot.revision;
AmountRequest request;
request.title = row.at("name").get<std::string>();
request.unit = money_unit();
request.return_focus = target->GetId();
request.value = row.at("amount").get<int64_t>() / finance_currency_factor(*world_);
request.min = 0;
request.max = 99999999;
request.step = 1;
request.suggestion_step = row.at("suggestion_step");
request.review = true;
request.accept = [this, world, source, revision, index](int64_t amount) {
if (menu_ != "advertising" || world_ != world || source_.get() != source) return false;
const auto result = source_->apply({revision, "advertising", {{"kind", "spending"}, {"index", index}, {"value", amount}}});
if (!result.ok) {
message("Das Budget konnte nicht übernommen werden. Bitte den aktuellen Stand prüfen. (" + result.error + ")");
return false;
}
if (advertising_selected_ >= 0 && advertising_world_ == world && advertising_revision_ == revision)
advertising_revision_ = result.revision;
refresh();
return true;
};
open_amount(std::move(request));
return true;
}
return true;
}
bool App::advertising_event(Rml::Event &event) {
if (menu_ != "advertising" || advertising_selected_ < 0 || amount_ || !popup_.empty()) return false;
const auto type = event.GetType();
if ((type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) ||
(type == "mouseup" && event.GetParameter<int>("button", 0) == 1)) {
advertising_action("ad-cancel", nullptr);
event.StopImmediatePropagation();
return true;
}
return false;
}
+60
View File
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: GPL-3.0-only
std::string App::render_advertising() {
const auto snapshot = snap();
const auto view = demo_advertising_view(snapshot.state, *world_);
if (!view.value("ok", false)) return {};
const auto brand = [&](const Json &c) {
if (c.at("sponsor") == -1) return std::string();
return "<span class=\"ad-brand ad-brand-" + std::to_string(c.at("sponsor").get<int>() % 5) +
"\"><span>" + esc(c.at("name").get<std::string>()) + "</span></span>";
};
std::string out = "<div class=\"advertising-page\"><div class=\"advertising-boards\" role=\"group\" aria-label=\"Vierzehn Werbebanden\">";
for (int i = 0; i < 14; ++i) {
const auto &c = view.at("slots")[size_t(i)];
out += btn("ad-contract", (c.at("active") == true ? brand(c) : "<span class=\"advertising-free\">Platz frei</span>") +
"<small><span>Bande " + std::to_string(i + 1) + "</span></small>", "advertising-board " + std::string(advertising_selected_ == i ? "selected" : ""),
"id=\"ad-contract-" + std::to_string(i) + "\" data-ad-contract=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(i) +
"\" aria-pressed=\"" + (advertising_selected_ == i ? "true" : "false") + "\" aria-label=\"Bande " + std::to_string(i + 1) + ", " +
esc(c.at("name").get<std::string>()) + "\" style=\"" + rect(16 + (i % 7) * (354.285714 + 16), 16 + (i / 7) * 145, 354.285714, 129) + "\"");
}
out += "</div>";
const std::array<const char *, 4> headings{"Trikotwerbung", "Fanartikel", "Öffentlichkeitsarbeit", "Fanbetreuung"};
for (int i = 0; i < 4; ++i) {
std::string body = "<strong><span>" + std::string(headings[size_t(i)]) + "</span></strong><div class=\"advertising-art\">" +
img("advertising.panel." + std::to_string(i), 510, 510, false, false, 1000) + "</div>";
if (i == 0) body += brand(view.at("slots")[14]);
else body += "<output><span>" + esc(cash(view.at("spending")[size_t(i - 1)].at("amount").get<int64_t>())) + "</span></output>";
out += btn(i == 0 ? "ad-contract" : "ad-spending", body,
"advertising-card advertising-panel " + std::string(i == 0 ? "advertising-shirt " : "") + (i == 0 && advertising_selected_ == 14 ? "selected" : ""),
"id=\"" + std::string(i == 0 ? "ad-contract-14" : "ad-spending-" + std::to_string(i - 1)) + "\" data-id=\"" + std::to_string(i == 0 ? 14 : i - 1) +
"\" " + (i == 0 ? "data-ad-contract=\"14\" aria-pressed=\"" + std::string(advertising_selected_ == 14 ? "true" : "false") + "\" "
: "data-ad-spending=\"" + std::to_string(i - 1) + "\" ") +
"style=\"" + rect(i * 658.5, 346, 636.5, 650) + "\"");
}
out += btn("ad-contract", "<strong><span>TV-Rechte</span></strong><div class=\"advertising-tv-art\">" +
img("art.advertising-tv-v1.png", 540, 540, false, false, 1000) + "</div>" + brand(view.at("slots")[15]),
"advertising-card advertising-tv " + std::string(advertising_selected_ == 15 ? "selected" : ""),
"id=\"ad-contract-15\" data-ad-contract=\"15\" data-id=\"15\" aria-pressed=\"" + std::string(advertising_selected_ == 15 ? "true" : "false") + "\"");
out += "<section class=\"advertising-details\" aria-label=\"Vertrag und Vorschau\" aria-live=\"polite\">";
if (advertising_selected_ < 0 || advertising_selected_ > 15) {
out += "<div class=\"advertising-hint\"><h2>Werbung und Vereinsausgaben</h2>"
"<p>Bande, Trikot oder TV-Rechte auswählen.</p><p>Die drei Ausgabenbilder öffnen die Zahleneingabe.</p></div>";
} else {
const auto quote = demo_advertising_quote(snapshot.state, advertising_selected_, advertising_offer_, *world_);
const bool active = quote.at("active");
out += "<div class=\"advertising-offer\"><div class=\"ad-offer-mark\">" + brand(quote) +
"</div><div class=\"ad-offer-arrows\">" +
btn("ad-offer", "<span>‹</span>", "ad-offer-arrow", "id=\"ad-offer-previous\" data-step=\"-1\" aria-label=\"Vorheriges Angebot\" " + std::string(active ? "disabled" : "")) +
btn("ad-offer", "<span>›</span>", "ad-offer-arrow", "id=\"ad-offer-next\" data-step=\"1\" aria-label=\"Nächstes Angebot\" " + std::string(active ? "disabled" : "")) +
"</div><div class=\"ad-offer-facts\"><div><span>" + esc(quote.at("label").get<std::string>()) + "</span><strong>" +
esc(quote.at("name").get<std::string>()) + "</strong></div><div><span>Dauer</span><strong>" + std::to_string(quote.at("months").get<int>()) +
" Monate</strong></div><div><span>" + (active ? "Vertrag" : "Angebot") + "</span><strong>" +
esc(cash(quote.at("amount").get<int64_t>())) + " / Monat</strong></div></div></div><nav class=\"advertising-actions\">" +
btn("ad-cancel", active ? "Schließen" : "Abbrechen", "advertising-control", "id=\"ad-cancel\"") +
btn("ad-accept", active ? "Vertrag läuft" : "Annehmen", "advertising-control", "id=\"ad-accept\" " + std::string(active ? "disabled" : "")) + "</nav>";
}
out += "<div class=\"advertising-totals\">";
for (const auto &[label, key] : std::array<std::pair<const char *, const char *>, 3>{{{"Einnahmen", "income"}, {"Ausgaben", "expenses"}, {"Saldo", "balance"}}})
out += "<div><span>" + std::string(label) + "</span><output>" + esc(cash(view.at(key).get<int64_t>())) + "</output></div>";
return out + "</div></section></div>";
}
+5 -1
View File
@@ -152,6 +152,7 @@ void App::ProcessEvent(Rml::Event &event) try {
if (amount_event(event)) return;
if (popup_.empty() && amount_trigger_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;
if (!planning_dialog_.empty() && popup_.empty()) {
const bool key_event = type == "keydown";
@@ -435,6 +436,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 (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;
if (report_detail_action(action, target)) {
@@ -1047,7 +1049,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"};
"save", "load", "training", "tactics", "calendar", "league", "other", "postpone", "friendlies", "indoor", "almanac", "bank", "balance", "contracts", "environment", "advertising", "toto"};
if (!available.contains(route)) {
message("Diese native Ansicht wird im nächsten Menüpaket übertragen.");
return;
@@ -1434,6 +1436,8 @@ void App::script() {
{"planning_dialog", planning_dialog_},
{"bank_view", bank_view_}, {"bank_property", bank_property_}, {"bank_stock", bank_stock_},
{"balance_future", balance_future_},
{"advertising_view", {{"selected", advertising_selected_}, {"offer", advertising_offer_}}},
{"toto_view", {{"column", toto_column_}, {"dialog", toto_dialog_}}},
{"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()},
+123
View File
@@ -0,0 +1,123 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_advertising.hpp"
#include "modern/ui/demo_finance.hpp"
#include <algorithm>
#include <array>
namespace bmh::modern_ui {
namespace {
constexpr int64_t cap = 99999999;
constexpr std::array<const char *, 10> sponsors{"MAINWERK", "BALLWERK", "NORDLICHT", "FELDPUNKT", "RHEINWERK",
"SPORTNETZ", "WESTBAHN", "HAFENWERK", "BERGSTROM", "STADTFUNK"};
constexpr std::array<const char *, 5> broadcasters{"SPORTKANAL", "FUSSBALL TV", "SPIELTAG TV", "ARENA PLUS", "LIGA LIVE"};
constexpr std::array<const char *, 3> spending_names{"Fanartikel", "Öffentlichkeitsarbeit", "Fanbetreuung"};
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(),
[&](const auto *key) { return v.contains(key); });
}
bool integer(const Json &v, int64_t low, int64_t high) {
if (v.is_number_unsigned())
return high >= 0 && v.get<uint64_t>() <= uint64_t(high) &&
(low <= 0 || v.get<uint64_t>() >= uint64_t(low));
return v.is_number_integer() && v.get<int64_t>() >= low && v.get<int64_t>() <= high;
}
Json error(const char *code) { return {{"ok", false}, {"error", code}}; }
std::string label(int slot) {
return slot < 14 ? "Bande " + std::to_string(slot + 1) : slot == 14 ? "Trikotwerbung" : "TV-Rechte";
}
std::string name(int slot, int sponsor) {
return sponsor < 0 ? "frei" : slot == 15 ? broadcasters[size_t(sponsor)] : sponsors[size_t(sponsor)];
}
Json offer(int slot, int choice, int64_t factor) {
return {{"sponsor", (slot * 3 + choice) % (slot == 15 ? 5 : 10)},
{"months", (choice + 1) * 12},
{"amount", ((slot == 15 ? 85000 : slot == 14 ? 110000 : 7000) +
(slot == 15 ? 18000 : slot == 14 ? 24000 : 1800) * choice + (slot % 7) * 1200) * factor}};
}
} // namespace
bool valid_demo_advertising(const Json &state, const Catalog &world) {
try {
if (!state.is_object()) return false;
const auto factor = finance_currency_factor(world);
const auto &a = state.at("advertising");
if (!keys(a, {"spending", "contracts"}) || !a.at("spending").is_array() || a.at("spending").size() != 3 ||
!a.at("contracts").is_array() || a.at("contracts").size() != 16) return false;
for (const auto &value : a.at("spending")) if (!integer(value, 0, cap * factor)) return false;
for (size_t slot = 0; slot < 16; ++slot) {
const auto &c = a.at("contracts")[slot];
if (!keys(c, {"sponsor", "months", "amount"}) || !integer(c.at("sponsor"), -1, slot == 15 ? 4 : 9) ||
!integer(c.at("months"), 0, 36) || !integer(c.at("amount"), 0, cap * factor)) return false;
if (c.at("sponsor") == -1) {
if (c.at("months") != 0 || c.at("amount") != 0) return false;
} else if (!(c.at("months") == 12 || c.at("months") == 24 || c.at("months") == 36) ||
c.at("amount") == 0) return false;
}
return true;
} catch (const std::exception &) { return false; }
}
bool migrate_demo_advertising(Json &state, const Catalog &world) {
try {
if (!state.is_object()) return false;
if (state.contains("advertising")) return valid_demo_advertising(state, world);
const auto factor = finance_currency_factor(world);
auto next = state;
Json contracts = Json::array();
for (int slot = 0; slot < 16; ++slot) contracts.push_back({{"sponsor", -1}, {"months", 0}, {"amount", 0}});
next["advertising"] = {{"spending", {50000 * factor, 15000 * factor, 10000 * factor}}, {"contracts", contracts}};
if (!valid_demo_advertising(next, world)) return false;
state = std::move(next);
return true;
} catch (const std::exception &) { return false; }
}
Json demo_advertising_quote(const Json &state, int slot, int choice, const Catalog &world) {
if (!valid_demo_advertising(state, world)) return error("invalid_advertising_state");
if (slot < 0 || slot > 15 || choice < 0 || choice > 2) return error("invalid_advertising_selection");
const auto &saved = state.at("advertising").at("contracts")[size_t(slot)];
const bool active = saved.at("sponsor") != -1;
const auto c = active ? saved : offer(slot, choice, finance_currency_factor(world));
return {{"ok", true}, {"slot", slot}, {"offer", choice}, {"active", active}, {"label", label(slot)},
{"name", name(slot, c.at("sponsor").get<int>())},
{"sponsor", c.at("sponsor")}, {"months", c.at("months")}, {"amount", c.at("amount")}};
}
std::string edit_demo_advertising(Json &state, const Json &action, const Catalog &world) {
if (!valid_demo_advertising(state, world)) return "invalid_advertising_state";
try {
if (!action.is_object() || !action.contains("kind") || !action.at("kind").is_string()) return "invalid_advertising_action";
const auto kind = action.at("kind").get<std::string>();
auto next = state;
if (kind == "accept") {
if (!keys(action, {"kind", "slot", "offer"}) || !integer(action.at("slot"), 0, 15) ||
!integer(action.at("offer"), 0, 2)) return "invalid_advertising_selection";
const auto slot = action.at("slot").get<size_t>();
if (state.at("advertising").at("contracts")[slot].at("sponsor") != -1) return "advertising_contract_active";
next["advertising"]["contracts"][slot] = offer(int(slot), action.at("offer").get<int>(), finance_currency_factor(world));
} else if (kind == "spending") {
if (!keys(action, {"kind", "index", "value"}) || !integer(action.at("index"), 0, 2) ||
!integer(action.at("value"), 0, cap)) return "invalid_advertising_value";
next["advertising"]["spending"][action.at("index").get<size_t>()] = action.at("value").get<int64_t>() * finance_currency_factor(world);
} else return "unknown_advertising_action";
if (!valid_demo_advertising(next, world)) return "invalid_advertising_state";
state = std::move(next);
return {};
} catch (const std::exception &) { return "invalid_advertising_action"; }
}
Json demo_advertising_view(const Json &state, const Catalog &world) {
if (!valid_demo_advertising(state, world)) return error("invalid_advertising_state");
Json slots = Json::array(), spending = Json::array();
int64_t income = 0, expenses = 0;
const auto &a = state.at("advertising");
for (int i = 0; i < 16; ++i) {
const auto &c = a.at("contracts")[size_t(i)];
const auto sponsor = c.at("sponsor").get<int>();
slots.push_back({{"slot", i}, {"label", label(i)}, {"name", name(i, sponsor)}, {"sponsor", sponsor},
{"months", c.at("months")}, {"amount", c.at("amount")}, {"active", sponsor >= 0}});
income += c.at("amount").get<int64_t>();
}
for (int i = 0; i < 3; ++i) {
const auto value = a.at("spending")[size_t(i)].get<int64_t>();
spending.push_back({{"index", i}, {"name", spending_names[size_t(i)]}, {"amount", value}, {"suggestion_step", i == 0 ? 50000 : 5000}});
expenses += value;
}
return {{"ok", true}, {"slots", slots}, {"spending", spending}, {"income", income}, {"expenses", expenses}, {"balance", income - expenses}};
}
} // namespace bmh::modern_ui
+19
View File
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "modern/ui/catalog.hpp"
namespace bmh::modern_ui {
// Only state.advertising is owned here. Monetary model/projection values are
// currency minor units; the spending editor action uses whole display units.
// Selection and offer navigation belong to the App, never the saved state.
bool migrate_demo_advertising(Json &state, const Catalog &);
bool valid_demo_advertising(const Json &state, const Catalog &);
std::string edit_demo_advertising(Json &state, const Json &action, const Catalog &);
// {kind:"accept",slot:0..15,offer:0..2} recomputes the deterministic offer.
// {kind:"spending",index:0..2,value:0..99999999} changes only that budget.
// Sources bind commits to the observed revision; queries never mutate it.
Json demo_advertising_quote(const Json &state, int slot, int offer, const Catalog &);
// {ok,slots:[{slot,label,name,sponsor,months,amount,active}],
// spending:[{index,name,amount,suggestion_step}],income,expenses,balance}.
Json demo_advertising_view(const Json &state, const Catalog &);
} // namespace bmh::modern_ui
+74
View File
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_environment.hpp"
#include "modern/ui/demo_finance.hpp"
#include <array>
#include <set>
namespace bmh::modern_ui {
namespace {
constexpr std::array<int, 6> defaults{2, 3, 4, 3, 4, 2};
constexpr std::array<int64_t, 6> rates{2000, 3000, 5000, 7500, 6000, 4500};
constexpr std::array<const char *, 6> ids{"youth-a", "youth-b", "youth-c", "coach", "doctor", "physio"};
constexpr std::array<const char *, 6> names{"Nachwuchs · Jüngste", "Nachwuchs · Mittlere",
"Nachwuchs · Ältere", "Co-Trainer", "Vereinsarzt", "Masseur"};
constexpr std::array<int, 3> ranks{11, 3, 7}, leagues{1, 2, 1};
bool integer(const Json &value, int lo, int hi) {
return value.is_number_integer() && value >= lo && value <= hi;
}
bool keys(const Json &value, std::initializer_list<const char *> expected) {
if (!value.is_object() || value.size() != expected.size()) return false;
for (const auto *key : expected) if (!value.contains(key)) return false;
return true;
}
} // namespace
bool valid_demo_environment(const Json &state, const Catalog &world) {
try {
if (!state.is_object() || !state.contains("environment") ||
!keys(state.at("environment"), {"levels"})) return false;
const auto &levels = state.at("environment").at("levels");
if (!levels.is_array() || levels.size() != defaults.size()) return false;
for (const auto &level : levels) if (!integer(level, 0, 6)) return false;
(void)finance_currency_factor(world);
return true;
} catch (const std::exception &) { return false; }
}
bool migrate_demo_environment(Json &state, const Catalog &world) {
if (!state.is_object()) return false;
auto next = state;
if (!next.contains("environment")) next["environment"] = {{"levels", defaults}};
if (!valid_demo_environment(next, world)) return false;
state = std::move(next);
return true;
}
std::string edit_demo_environment(Json &state, const Json &action, const Catalog &world) {
if (!valid_demo_environment(state, world)) return "invalid_environment_state";
if (!keys(action, {"kind", "index", "value"}) || !action.at("kind").is_string())
return "invalid_environment_action";
if (action.at("kind") != "level") return "unknown_environment_action";
if (!integer(action.at("index"), 0, 5) || !integer(action.at("value"), 0, 6))
return "invalid_environment_level";
auto next = state;
next["environment"]["levels"][action.at("index").get<size_t>()] = action.at("value");
if (!valid_demo_environment(next, world)) return "invalid_environment_state";
state = std::move(next);
return {};
}
Json demo_environment_rows(const Json &state, const Catalog &world) {
if (!valid_demo_environment(state, world))
return {{"ok", false}, {"error", "invalid_environment_state"}};
const auto factor = finance_currency_factor(world);
Json rows = Json::array();
int64_t total = 0;
for (size_t i = 0; i < defaults.size(); ++i) {
const int level = state.at("environment").at("levels")[i].get<int>();
const int64_t rate = rates[i] * factor, cost = rate * level;
total += cost;
rows.push_back({{"id", ids[i]}, {"name", names[i]}, {"level", level},
{"rate", rate}, {"cost", cost}, {"image", i < 3 ? "youth" : "staff"},
{"cell", i < 3 ? int(i) : int(i - 3)},
{"rank", i < 3 ? Json(ranks[i]) : Json()},
{"league", i < 3 ? Json(leagues[i]) : Json()}});
}
return {{"ok", true}, {"rows", rows}, {"total", total}};
}
} // namespace bmh::modern_ui
+18
View File
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "modern/ui/catalog.hpp"
namespace bmh::modern_ui {
// FULL demo state, canonical environment={levels:[six integers 0..6]}.
// Only an absent environment is initialized. Rejections are atomic; unrelated
// state and the OBW staff table are never rewritten or interpreted as budgets.
bool migrate_demo_environment(Json &, const Catalog &);
bool valid_demo_environment(const Json &, const Catalog &);
// {kind:"level",index:0..5,value:0..6}; selection is immediate, with no cash
// booking, salary changes, time advancement or engine/RNG access.
std::string edit_demo_environment(Json &, const Json &, const Catalog &);
// {ok,rows:[{id,name,level,rate,cost,image,cell,rank,league}],total}.
// Rates, costs and total use raw currency minor units. Youth places are explicit
// fictional presentation fixtures, independent of any league/report selection.
Json demo_environment_rows(const Json &, const Catalog &);
} // namespace bmh::modern_ui
+132
View File
@@ -0,0 +1,132 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/ui/demo_toto.hpp"
#include "modern/ui/demo_finance.hpp"
#include "modern/ui/demo_reports.hpp"
#include <algorithm>
#include <array>
namespace bmh::modern_ui {
namespace {
constexpr int column_count = 6, row_count = 11;
constexpr int64_t stake_cap = 99999999;
constexpr std::array<int, 3> picks{1, 0, 2};
bool whole(const Json &v, int64_t lo, int64_t 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 keys(const Json &v, std::initializer_list<const char *> names) {
return v.is_object() && v.size() == names.size() &&
std::all_of(names.begin(), names.end(), [&](const auto *name) { return v.contains(name); });
}
bool columns_valid(const Json &v) {
return v.is_array() && v.size() == column_count && std::all_of(v.begin(), v.end(), [](const auto &col) {
return col.is_array() && col.size() == row_count && std::all_of(col.begin(), col.end(), [](const auto &p) { return whole(p, -1, 2); });
});
}
int filled(const Json &col) {
return int(std::count_if(col.begin(), col.end(), [](const auto &p) { return p != -1; }));
}
bool ready(const Json &cols) {
bool any = false;
for (const auto &col : cols) {
const int n = filled(col);
if (n && n != row_count) return false;
any |= n == row_count;
}
return any;
}
bool stake_valid(const Json &v, int64_t factor, bool positive = false) {
return whole(v, positive ? factor : 0, stake_cap * factor) && v.get<int64_t>() % factor == 0;
}
Json initial(int64_t factor) {
auto cols = Json::array();
for (int c = 0; c < column_count; ++c) {
auto col = Json::array();
for (int r = 0; r < row_count; ++r) col.push_back(c ? -1 : picks[size_t(r % 3)]);
cols.push_back(col);
}
return {{"columns", cols}, {"stake", 1000 * factor}, {"coupon", nullptr}};
}
} // namespace
bool valid_demo_toto(const Json &state, const Catalog &world) {
try {
const auto factor = finance_currency_factor(world);
if (!state.is_object() || !state.contains("toto")) return false;
const auto &v = state.at("toto");
if (!keys(v, {"columns", "stake", "coupon"}) || !columns_valid(v.at("columns")) || !stake_valid(v.at("stake"), factor)) return false;
const auto &coupon = v.at("coupon");
return coupon.is_null() || (keys(coupon, {"columns", "stake"}) && columns_valid(coupon.at("columns")) &&
ready(coupon.at("columns")) && stake_valid(coupon.at("stake"), factor, true));
} catch (const std::exception &) { return false; }
}
bool migrate_demo_toto(Json &state, const Catalog &world) {
try {
if (!state.is_object()) return false;
auto next = state;
if (!next.contains("toto")) next["toto"] = initial(finance_currency_factor(world));
if (!valid_demo_toto(next, world)) return false;
state = std::move(next);
return true;
} catch (const std::exception &) { return false; }
}
Json demo_toto_programme(const Catalog &world) {
Json rows = Json::array();
const auto leagues = world.leagues("nation:de");
auto reports = demo_reports(world);
for (size_t i = 0; i < std::min<size_t>(2, leagues.size()); ++i) {
if (!edit_demo_reports(reports, {{"kind", "league"}, {"value", leagues[i]->at("id")}}, world).empty()) continue;
reports["round"] = std::min(26, report_round_count(world, reports) - 1);
const auto matches = report_match_rows(world, reports, false);
const size_t limit = i == 0 ? 9 : 2;
for (size_t n = 0; n < std::min(matches.size(), limit); ++n)
rows.push_back({{"home", matches[n].at("home")}, {"away", matches[n].at("away")},
{"league", leagues[i]->at("id")}, {"tier", i + 1}, {"round", reports.at("round").get<int>() + 1}});
}
auto start = world.manifest().value("start_date", std::string(""));
std::string season = "—";
if (start.size() >= 4 && std::all_of(start.begin(), start.begin() + 4, [](char c) { return c >= '0' && c <= '9'; })) {
const auto year = std::stoi(start.substr(0, 4));
const auto next = std::to_string((year + 1) % 100);
season = start.substr(0, 4) + "/" + (next.size() == 1 ? "0" : "") + next;
}
return {{"rows", rows}, {"complete", rows.size() == row_count}, {"round", 27}, {"season", season}};
}
std::string edit_demo_toto(Json &state, const Json &action, const Catalog &world) {
if (!valid_demo_toto(state, world)) return "invalid_toto_state";
if (!action.is_object() || !action.contains("kind") || !action.at("kind").is_string()) return "invalid_toto_action";
const auto kind = action.at("kind").get<std::string>();
auto next = state.at("toto");
if (kind == "pick" || kind == "auto" || kind == "clear") {
if (!action.contains("column") || !whole(action.at("column"), 0, 5)) return "invalid_toto_column";
auto &col = next["columns"][action.at("column").get<size_t>()];
if (kind == "pick") {
if (!action.contains("row") || !whole(action.at("row"), 0, 10) ||
!action.contains("pick") || !whole(action.at("pick"), 0, 2)) return "invalid_toto_pick";
auto &value = col[action.at("row").get<size_t>()];
value = value == action.at("pick") ? Json(-1) : action.at("pick");
} else for (int r = 0; r < row_count; ++r)
col[size_t(r)] = kind == "clear" ? -1 : picks[size_t((r + action.at("column").get<int>() + 1) % 3)];
} else if (kind == "stake") {
if (!action.contains("value") || !whole(action.at("value"), 0, stake_cap)) return "invalid_toto_stake";
next["stake"] = action.at("value").get<int64_t>() * finance_currency_factor(world);
} else if (kind == "submit") {
if (!ready(next.at("columns")) || next.at("stake") == 0) return "incomplete_toto_coupon";
if (!demo_toto_programme(world).at("complete").get<bool>()) return "unavailable_toto_programme";
next["coupon"] = {{"columns", next.at("columns")}, {"stake", next.at("stake")}};
} else return "unsupported_toto_action";
auto candidate = state;
candidate["toto"] = std::move(next);
if (!valid_demo_toto(candidate, world)) return "invalid_toto_action";
state = std::move(candidate);
return {};
}
Json demo_toto_summary(const Json &state, const Catalog &world) {
if (!valid_demo_toto(state, world)) return {{"ok", false}};
Json counts = Json::array(); int complete = 0, partial = 0;
for (const auto &col : state.at("toto").at("columns")) {
const auto n = filled(col); counts.push_back(n); complete += n == row_count; partial += n && n != row_count;
}
return {{"ok", true}, {"counts", counts}, {"complete", complete}, {"partial", partial},
{"can_submit", complete && !partial && state.at("toto").at("stake") != 0}};
}
} // namespace bmh::modern_ui
+14
View File
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
#include "modern/ui/catalog.hpp"
namespace bmh::modern_ui {
// Presentation-only coupon: six independent columns, eleven games, raw money.
// These helpers accept the full UI state and never debit the shared wallet.
bool migrate_demo_toto(Json &, const Catalog &);
bool valid_demo_toto(const Json &, const Catalog &);
std::string edit_demo_toto(Json &, const Json &, const Catalog &);
Json demo_toto_summary(const Json &, const Catalog &);
// Fixed programme independent of report filters: 9 first-tier + 2 second-tier
// matches. Missing clubs yield an incomplete projection, never invented teams.
Json demo_toto_programme(const Catalog &);
} // namespace bmh::modern_ui
+19
View File
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-3.0-only
bool App::environment_action(const std::string &action, Rml::Element *target) {
if (action != "environment-level") return false;
if (menu_ != "environment" || !source_ || !target) return true;
const auto index = target->GetAttribute<Rml::String>("data-index", "");
const auto value = target->GetAttribute<Rml::String>("data-id", "");
if (index.size() != 1 || index[0] < '0' || index[0] > '5' ||
value.size() != 1 || value[0] < '0' || value[0] > '6') return true;
const auto snapshot = snap();
const auto result = source_->apply({snapshot.revision, "environment",
{{"kind", "level"}, {"index", index[0] - '0'}, {"value", value[0] - '0'}}});
if (!result.ok) {
message("Das Umfeldbudget konnte nicht übernommen werden. Bitte die Ansicht mit dem aktuellen Stand erneut öffnen.");
return true;
}
focus_after_render_ = target->GetId();
refresh();
return true;
}
+64
View File
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: GPL-3.0-only
std::string App::render_environment() {
const auto snapshot = snap();
if (!snapshot.world) return "<p class=\"environment-unavailable\">Die Umfeldvorschau ist derzeit nicht verfügbar.</p>";
const auto view = demo_environment_rows(snapshot.state, *snapshot.world);
if (!view.value("ok", false)) return "<p class=\"environment-unavailable\">Die Umfeldvorschau ist derzeit nicht verfügbar.</p>";
const auto funded = theme_ == "silver" ? "#805b18" : theme_ == "matchday" ? "#e1c68b" : "#e5cd8c";
const auto unfunded = theme_ == "silver" ? "#526779" : theme_ == "matchday" ? "#b7b4b9" : "#6f8595";
const auto star = [&](bool active) {
const auto color = active ? funded : unfunded;
const std::string svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"48\" height=\"48\" viewBox=\"0 0 48 48\">"
"<path fill=\"" + std::string(color) + "\" d=\"m24 3 6 13 15 2-11 11 3 15-13-7-13 7 3-15L3 18l15-2Z\"/></svg>";
return picture(renderer_.diagram("environment-star-" + theme_ + (active ? "-funded" : "-unfunded"), svg, 96), 40, 40);
};
struct Panel { double x, y, w, h, image_h; };
const std::array<Panel, 6> panels{{
{1912,970,600,623.328125,374.78125}, {1056,1060,500,556.40625,307.859375},
{100,970,600,623.328125,374.78125}, {100,160,600,694.375,460.375},
{1056,0,500,612.171875,378.171875}, {1912,160,600,694.375,460.375}}};
std::string out = "<div class=\"environment-ring\" id=\"environment-ring\">";
const auto &rows = view.at("rows");
for (size_t i = 0; i < rows.size(); ++i) {
const auto &row = rows[i];
const auto &panel = panels[i];
const auto name = row.at("name").get<std::string>(), id = row.at("id").get<std::string>();
const auto level = row.at("level").get<int>();
const auto inner = panel.w - 40;
out += "<section class=\"environment-card " + id + "\" style=\"" + rect(panel.x, panel.y, panel.w, panel.h) +
"\" aria-labelledby=\"environment-title-" + std::to_string(i) + "\"><h2 id=\"environment-title-" +
std::to_string(i) + "\">" + esc(name) + "</h2><div class=\"environment-stars\" role=\"group\" aria-label=\"" +
esc(name + " Budget") + "\">";
for (int value = 0; value <= 6; ++value) {
const bool selected = value == level;
const auto label = value ? "<span class=\"environment-level-icon\">" + star(value <= level) + "</span>"
: std::string("<span class=\"environment-zero-label\">×</span>");
out += btn("environment-level", label + (selected ? "<span class=\"environment-selection-line\"></span>" : ""),
"environment-level " + std::string(value == 0 ? "zero " : "") + (selected ? "selected" : ""),
"id=\"environment-level-" + std::to_string(i) + "-" + std::to_string(value) +
"\" data-index=\"" + std::to_string(i) + "\" data-id=\"" + std::to_string(value) +
"\" aria-pressed=\"" + (selected ? "true" : "false") + "\" aria-label=\"" +
esc(name + ": " + std::to_string(value) + (value == 1 ? " Stern" : " Sterne")) +
"\" title=\"" + (value ? std::to_string(value) + (value == 1 ? " Stern" : " Sterne") : "Budget auf null setzen") + "\"");
}
out += "</div><div class=\"environment-picture\" style=\"" + rect(18, 138, inner, panel.image_h) + "\">" +
img("environment." + row.at("image").get<std::string>() + "." + std::to_string(row.at("cell").get<int>()),
inner, panel.image_h, false, false, 1024) +
"</div><div class=\"environment-caption\" style=\"top:" + scalar(152 + panel.image_h) + "dp;height:" +
scalar(i < 3 ? 74.546875 : 60) + "dp;\"><span class=\"environment-cost\" id=\"environment-cost-" + std::to_string(i) +
"\" aria-label=\"" + esc(name + " Monatskosten") + "\">" +
esc(money(row.at("cost").get<int64_t>(), snapshot.world->manifest().value("currency", Json::object())) + " / Monat") + "</span>";
if (i < 3)
out += "<span class=\"environment-standing\">" + std::to_string(row.at("rank").get<int>()) + ". / " +
std::to_string(row.at("league").get<int>()) + ". Liga</span>";
out += "</div></section>";
}
out += "<div class=\"environment-emblem\"><div class=\"environment-ball\">" +
img("art.environment-ball-v1.png", 400, 400, false, false, 640) + "</div>";
const auto &managers = snapshot.state.at("managers");
const auto managed = managers.is_array() && !managers.empty() ? managers[0].value("club", "") : "";
const auto *club = snapshot.world->find("clubs", managed);
out += "<div class=\"environment-crest\" aria-label=\"" + esc(club ? snapshot.world->name(*club) : "Vereinswappen nicht verfügbar") + "\">" +
(club ? img(club->value("crest", ""), 162, 162, true) : "<span>—</span>") + "</div></div></div>";
return out;
}
+12
View File
@@ -2,6 +2,9 @@
#include "modern/ui/model.hpp"
#include "modern/ui/demo_almanac.hpp"
#include "modern/ui/demo_finance.hpp"
#include "modern/ui/demo_environment.hpp"
#include "modern/ui/demo_advertising.hpp"
#include "modern/ui/demo_toto.hpp"
#include "modern/ui/demo_calendar.hpp"
#include "modern/ui/demo_reports.hpp"
#include "modern/ui/demo_sports.hpp"
@@ -87,6 +90,8 @@ DemoSource::DemoSource(std::shared_ptr<const Catalog> catalog)
state_["reports"] = demo_reports(*catalog_);
if (!migrate_demo_finance(state_, *catalog_, club))
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");
saved_ = state_;
}
Snapshot DemoSource::snapshot() const { return {revision_, catalog_, state_}; }
@@ -131,6 +136,11 @@ ActionResult DemoSource::apply(const Action &action) {
{{"kind", "league"}, {"value", next["calendar"]["league"]}}, *catalog_);
if (!error.empty()) return {false, revision_, error};
}
} else if (action.kind == "environment" || action.kind == "advertising" || action.kind == "toto") {
const auto error = action.kind == "environment" ? edit_demo_environment(next, action.value, *catalog_)
: 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 == "finance") {
const auto error = edit_demo_finance(next, action.value, *catalog_, next["managers"][0]["club"]);
if (!error.empty()) return {false, revision_, error};
@@ -255,6 +265,8 @@ Json DemoSource::load(const fs::path &file) {
throw editor::Error("invalid_focus");
if (!migrate_demo_finance(data, *catalog_, club))
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");
auto next = data;
auto desktop = next.value("desktop", Json::object());
if (!migrate_desktop(desktop))
+6
View File
@@ -883,6 +883,12 @@ std::string App::render_menu(const std::string &key) {
body = render_friendlies();
else if (key == "indoor")
body = render_indoor();
else if (key == "environment")
body = render_environment();
else if (key == "advertising")
body = render_advertising();
else if (key == "toto")
body = render_toto();
else if (key == "bank")
body = render_bank();
else if (key == "balance")
+111
View File
@@ -0,0 +1,111 @@
// SPDX-License-Identifier: GPL-3.0-only
bool App::toto_action(const std::string &action, Rml::Element *target) {
if (menu_ != "toto" || !action.starts_with("toto-")) return false;
if (action == "toto-dialog-close") {
toto_dialog_.clear(); focus_after_render_ = toto_return_focus_; refresh(); return true;
}
if (!toto_dialog_.empty()) return true;
if (action == "toto-column") {
const auto col = target ? target->GetAttribute<int>("data-column", -1) : -1;
if (col < 0 || col > 5) return true;
toto_column_ = col; focus_after_render_ = "toto-column-" + std::to_string(col); refresh(); return true;
}
if (action == "toto-stake") {
const auto revision = snap().revision; const auto world = world_;
AmountRequest request;
request.title = "TOTO · Gesamteinsatz"; request.unit = money_unit();
request.suggestion_step = 1000;
request.value = snap().state.at("toto").at("stake").get<int64_t>() / finance_currency_factor(*world_);
request.return_focus = "toto-stake";
request.accept = [this, revision, world](int64_t value) {
if (!source_ || world_ != world || menu_ != "toto") return false;
const auto result = source_->apply({revision, "toto", {{"kind", "stake"}, {"value", value}}});
if (!result.ok) { message("Der Einsatz konnte nicht übernommen werden: " + result.error); return false; }
refresh(); return true;
};
open_amount(std::move(request)); return true;
}
if (action == "toto-last") {
if (snap().state.at("toto").at("coupon").is_null()) return true;
toto_dialog_ = "receipt"; toto_return_focus_ = "toto-last";
focus_after_render_ = "toto-dialog-close"; refresh(); return true;
}
Json change;
if (action == "toto-pick" && target) {
const auto col = target->GetAttribute<int>("data-column", -1), row = target->GetAttribute<int>("data-row", -1), pick = target->GetAttribute<int>("data-pick", -1);
if (col < 0 || col > 5 || row < 0 || row > 10 || pick < 0 || pick > 2) return true;
change = {{"kind", "pick"}, {"column", col}, {"row", row}, {"pick", pick}};
if (apply("toto", change)) {
toto_column_ = col; toto_focus_[size_t(col)] = {row, pick};
focus_after_render_ = toto_pick_id(col, row, pick); refresh();
}
return true;
}
if (action == "toto-auto" || action == "toto-clear") change = {{"kind", action == "toto-auto" ? "auto" : "clear"}, {"column", toto_column_}};
else if (action == "toto-submit") change = {{"kind", "submit"}};
else return false;
if (apply("toto", change)) {
if (action == "toto-submit") {
toto_dialog_ = "notice"; toto_return_focus_ = "toto-submit"; focus_after_render_ = "toto-dialog-close";
} else {
const auto value = snap().state.at("toto").at("columns")[size_t(toto_column_)][0].get<int>();
toto_focus_[size_t(toto_column_)] = {0, value < 0 ? 1 : value};
focus_after_render_ = action == "toto-clear" ? "toto-column-" + std::to_string(toto_column_) : "toto-auto";
}
refresh();
}
return true;
}
bool App::toto_event(Rml::Event &event) {
if (menu_ != "toto" || amount_ || !popup_.empty()) return false;
const auto type = event.GetType(); const bool keyboard = type == "keydown";
const auto key = keyboard ? Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier", 0)) : Rml::Input::KI_UNKNOWN;
auto *target = event.GetTargetElement();
if (!toto_dialog_.empty()) {
if ((keyboard && key == Rml::Input::KI_ESCAPE) || (type == "mouseup" && event.GetParameter<int>("button", 0) == 1)) {
toto_action("toto-dialog-close", nullptr); event.StopImmediatePropagation(); return true;
}
bool inside = false;
for (auto *n = target; n && n != doc_; n = n->GetParentNode()) if (n->GetId() == "toto-layer") inside = true;
if (keyboard && key == Rml::Input::KI_TAB) {
if (auto *button = element("toto-dialog-close")) button->Focus(true);
event.StopImmediatePropagation(); return true;
}
if (!inside && (keyboard || type == "click" || type == "dblclick" || type == "mousedown" || type == "mouseup")) {
event.StopImmediatePropagation(); return true;
}
return false;
}
if (!keyboard) return false;
if (key == Rml::Input::KI_TAB) {
Rml::ElementList fields; doc_->QuerySelectorAll(fields, ".window button");
std::erase_if(fields, [](Rml::Element *n) { return !n->IsVisible(true) || n->HasAttribute("disabled") || n->GetAttribute<Rml::String>("data-tabstop", "true") == "false"; });
const auto found = std::find(fields.begin(), fields.end(), context_->GetFocusElement());
if (!fields.empty()) {
const int count = int(fields.size()), old = found == fields.end() ? -1 : int(found - fields.begin());
const bool back = event.GetParameter<int>("shift_key", 0);
const int next = old < 0 ? back ? count - 1 : 0 : (old + (back ? -1 : 1) + count) % count;
fields[size_t(next)]->Focus(true);
}
event.StopImmediatePropagation(); return true;
}
if (!target->HasAttribute("data-row") ||
(key != Rml::Input::KI_LEFT && key != Rml::Input::KI_RIGHT && key != Rml::Input::KI_UP &&
key != Rml::Input::KI_DOWN && key != Rml::Input::KI_HOME && key != Rml::Input::KI_END)) return false;
constexpr std::array<int, 3> picks{1, 0, 2};
int row = target->GetAttribute<int>("data-row", 0);
const int column = target->GetAttribute<int>("data-column", 0), pick = target->GetAttribute<int>("data-pick", 1);
int cell = column * 3 + int(std::find(picks.begin(), picks.end(), pick) - picks.begin());
if (key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN) row = std::clamp(row + (key == Rml::Input::KI_UP ? -1 : 1), 0, 10);
else if (key == Rml::Input::KI_LEFT || key == Rml::Input::KI_RIGHT) cell = std::clamp(cell + (key == Rml::Input::KI_LEFT ? -1 : 1), 0, 17);
else { cell = key == Rml::Input::KI_HOME ? 0 : 17; if (event.GetParameter<int>("ctrl_key", 0) || event.GetParameter<int>("meta_key", 0)) row = key == Rml::Input::KI_HOME ? 0 : 10; }
const auto col = cell / 3, next = picks[size_t(cell % 3)];
toto_focus_[size_t(col)] = {row, next};
Rml::ElementList fields; doc_->QuerySelectorAll(fields, ".toto-pick");
for (auto *n : fields) if (n->GetAttribute<int>("data-column", -1) == col) {
const bool active = n->GetId() == toto_pick_id(col, row, next);
n->SetAttribute("data-tabstop", active ? "true" : "false"); n->SetProperty("tab-index", active ? "auto" : "none");
}
if (auto *button = element(toto_pick_id(col, row, next))) button->Focus(true);
dirty_ = true; event.StopImmediatePropagation(); return true;
}
+96
View File
@@ -0,0 +1,96 @@
// SPDX-License-Identifier: GPL-3.0-only
namespace {
std::string toto_pick_id(int col, int row, int pick) {
return "toto-pick-" + std::to_string(col) + "-" + std::to_string(row) + "-" + std::to_string(pick);
}
}
std::string App::render_toto() {
const auto state = snap().state;
const auto &t = state.at("toto");
const auto summary = demo_toto_summary(state, *world_), programme = demo_toto_programme(*world_);
const bool available = programme.at("complete").get<bool>();
const auto &games = programme.at("rows");
const std::array<int, 3> picks{1, 0, 2};
std::string out = "<div id=\"toto-underlay\" class=\"toto-native\"><section class=\"toto-program\">"
"<header><p>Die Begegnungen</p><h2>Spielprogramm</h2><span>Spielrunde 27 · Saison " + esc(programme.at("season").get<std::string>()) +
"</span></header><div class=\"toto-program-head\"><span>Nr.</span><span>Heim – Gast</span><span>Liga</span></div>";
const auto club_name = [&](const Json *club, bool home) {
if (!club) return std::string("<span class=\"toto-club-name\">—</span>");
const auto name = "<span class=\"toto-club-name\">" + esc(world_->name(*club)) + "</span>", logo = crest(club, 34);
return "<span class=\"toto-club-label\" title=\"" + esc(world_->name(*club)) + "\">" +
(home ? name + logo : logo + name) + "</span>";
};
for (int r = 0; r < 11; ++r) {
const bool has = size_t(r) < games.size();
const auto *home = has ? world_->find("clubs", games[size_t(r)].at("home")) : nullptr;
const auto *away = has ? world_->find("clubs", games[size_t(r)].at("away")) : nullptr;
out += "<div class=\"toto-match-row" + std::string(r % 2 == 0 ? " striped" : "") + "\" style=\"top:" + scalar(298 + r * 82) + "dp;\">"
"<span class=\"toto-match-number\">" + std::to_string(r + 1) + "</span><div class=\"toto-match-teams\"><div class=\"toto-home\">" +
club_name(home, true) + "</div><span class=\"toto-versus\">–</span><div class=\"toto-away\">" + club_name(away, false) +
"</div></div><span class=\"toto-match-league\">" + (has ? std::to_string(games[size_t(r)].at("tier").get<int>()) + ". BL" : "—") + "</span></div>";
}
out += "<p class=\"toto-program-note\">" + std::string(available ? "Heim links · Gast rechts<br/>Die Spielnummer steht in jeder Tipp-Spalte."
: "Das Spielprogramm ist unvollständig.<br/>Ein Schein kann derzeit nicht vorgemerkt werden.") + "</p></section>"
"<article class=\"toto-coupon\"><span class=\"toto-print-mark top\"></span><span class=\"toto-print-mark bottom\"></span>"
"<header class=\"toto-paper-heading\"><div class=\"toto-paper-brand\"><strong>TOTO</strong><h2>ELFERWETTE</h2></div>"
"<div class=\"toto-paper-caption\"><strong>Spielschein</strong><span>11 Spiele · 6 Tipp-Spalten</span><small>Spielprogramm 27</small></div></header>";
const auto cross = renderer_.diagram("toto-ink-cross", "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"60\" height=\"80\" viewBox=\"0 0 60 80\"><path d=\"M10 14L49 66M48 12L12 69\" fill=\"none\" stroke=\"#253e62\" stroke-width=\"5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg>", 160);
constexpr double col_width = 221.619792, gap = 14, pick_width = (col_width - 43) / 3;
for (int c = 0; c < 6; ++c) {
const auto count = summary.at("counts")[size_t(c)].get<int>();
out += "<section class=\"toto-field" + std::string(c == toto_column_ ? " selected-column" : "") + "\" style=\"left:" + scalar(28 + c * (col_width + gap)) +
"dp;\" aria-label=\"Tipp-Spalte " + std::to_string(c + 1) + "\">" +
btn("toto-column", "<span>Spalte</span><strong>" + std::to_string(c + 1) + "</strong>", "toto-column-heading",
"id=\"toto-column-" + std::to_string(c) + "\" data-column=\"" + std::to_string(c) + "\" aria-pressed=\"" + (c == toto_column_ ? "true" : "false") + "\"") +
"<div class=\"toto-pick-head\"><span style=\"left:0;width:28dp;\">Nr.</span>";
for (int p = 0; p < 3; ++p)
out += "<span style=\"left:" + scalar(33 + p * (pick_width + 5)) + "dp;width:" + scalar(pick_width) + "dp;\">" + std::to_string(picks[size_t(p)]) + "</span>";
out += "</div>";
for (int r = 0; r < 11; ++r) {
out += "<div class=\"toto-pick-row\" style=\"top:" + std::to_string(116 + r * 82) + "dp;\"><span class=\"toto-row-number\">" + std::to_string(r + 1) + "</span>";
for (int p = 0; p < 3; ++p) {
const auto pick = picks[size_t(p)]; const bool chosen = t.at("columns")[size_t(c)][size_t(r)] == pick;
const bool tabstop = toto_focus_[size_t(c)] == std::pair(r, pick);
out += btn("toto-pick", "<span class=\"toto-pick-value\">" + std::to_string(pick) + "</span>" + (chosen ?
"<span class=\"toto-cross\" style=\"transform:rotate(" + std::to_string(((c + r) % 3 - 1) * 3) + "deg);\">" + picture(cross, pick_width, 64) + "</span>" : ""),
"toto-pick", "id=\"" + toto_pick_id(c, r, pick) + "\" data-column=\"" + std::to_string(c) + "\" data-row=\"" + std::to_string(r) +
"\" data-pick=\"" + std::to_string(pick) + "\" aria-pressed=\"" + (chosen ? "true" : "false") + "\" aria-label=\"Spalte " + std::to_string(c + 1) +
", Spiel " + std::to_string(r + 1) + ", " + (pick == 1 ? "Heimsieg" : pick == 0 ? "Unentschieden" : "Auswärtssieg") +
"\" style=\"left:" + scalar(33 + p * (pick_width + 5)) + "dp;width:" + scalar(pick_width) + "dp;tab-index:" + (tabstop ? "auto" : "none") + ";\" data-tabstop=\"" + (tabstop ? "true" : "false") + "\"");
}
out += "</div>";
}
out += "<p class=\"toto-field-progress\">" + (count == 0 ? "Leer" : count == 11 ? "Vollständig" : std::to_string(count) + " / 11") + "</p></section>";
}
out += "<footer class=\"toto-paper-footer\"><p><strong>1</strong> Heimsieg <b>·</b> <strong>0</strong> Unentschieden <b>·</b> <strong>2</strong> Auswärtssieg</p>"
"<span>Pro Spiel und Spalte ein Kreuz. Leere Spalten bleiben unberücksichtigt.</span><small>OpenBMH · Musterschein · Grafik-POC</small></footer></article>";
const int complete = summary.at("complete"), partial = summary.at("partial");
out += "<div class=\"toto-status\"><div><strong>" + std::to_string(complete) + (complete == 1 ? " vollständige Spalte" : " vollständige Spalten") +
"</strong><span>" + (partial ? std::to_string(partial) + (partial == 1 ? " Spalte noch unvollständig" : " Spalten noch unvollständig") :
"Spalte " + std::to_string(toto_column_ + 1) + " für Tippvorschlag und Leeren ausgewählt") + "</span></div><p>Einsatz gesamt <strong>" + esc(cash(t.at("stake"))) + "</strong></p></div>";
out += "<nav class=\"toto-nav\">" + btn("toto-stake", "Einsatz", "toto-control", "id=\"toto-stake\"") +
btn("toto-auto", "Tippvorschlag", "toto-control", "id=\"toto-auto\"") +
btn("toto-clear", "Spalte leeren", "toto-control", "id=\"toto-clear\" " + std::string(summary.at("counts")[size_t(toto_column_)] == 0 ? "disabled" : "")) +
btn("toto-submit", "Übernehmen", "toto-control", "id=\"toto-submit\" " + std::string(available && summary.at("can_submit").get<bool>() ? "" : "disabled")) +
btn("toto-last", "Letzter Schein", "toto-control", "id=\"toto-last\" " + std::string(t.at("coupon").is_null() ? "disabled" : "")) + "</nav></div>";
if (toto_dialog_.empty()) return out;
const auto &coupon = t.at("coupon");
if (coupon.is_null()) { toto_dialog_.clear(); return out; }
std::vector<int> active;
for (int c = 0; c < 6; ++c) if (coupon.at("columns")[size_t(c)][0] != -1) active.push_back(c);
out += "<div id=\"toto-layer\" class=\"toto-layer\"><section class=\"toto-dialog " + toto_dialog_ + "\" role=\"dialog\" aria-modal=\"true\" aria-labelledby=\"toto-dialog-title\">"
"<h2 id=\"toto-dialog-title\">" + std::string(toto_dialog_ == "receipt" ? "Letzter vorgemerkter Schein" : "Tippschein vorgemerkt") + "</h2>";
const auto caption = std::to_string(active.size()) + (active.size() == 1 ? " Spalte" : " Spalten");
if (toto_dialog_ == "receipt") {
out += "<div class=\"toto-receipt\">";
for (int row = -1; row < 11; ++row) {
out += "<div class=\"toto-receipt-row " + std::string(row == -1 ? "head" : row % 2 == 0 ? "striped" : "") + "\"><span style=\"width:16%;\">" + (row == -1 ? "Spiel" : std::to_string(row + 1)) + "</span>";
for (const auto c : active) out += "<span style=\"width:" + scalar(84.0 / active.size()) + "%;\">" +
(row == -1 ? "Spalte " + std::to_string(c + 1) : std::to_string(coupon.at("columns")[size_t(c)][size_t(row)].get<int>())) + "</span>";
out += "</div>";
}
out += "</div><p class=\"toto-receipt-total\">" + caption + " · Einsatz gesamt " + esc(cash(coupon.at("stake"))) + "</p>";
} else out += "<p class=\"toto-notice\">" + caption + " · " + std::to_string(active.size() * 11) + " Tipps · Einsatz gesamt " + esc(cash(coupon.at("stake"))) + "</p>";
out += "<nav class=\"toto-dialog-actions\">" + btn("toto-dialog-close", toto_dialog_ == "receipt" ? "Schließen" : "Verstanden", "toto-control", "id=\"toto-dialog-close\"") + "</nav></section></div>";
return out;
}
+34 -2
View File
@@ -7,6 +7,9 @@
#include "modern/ui/controls.hpp"
#include "modern/ui/demo_calendar.hpp"
#include "modern/ui/demo_finance.hpp"
#include "modern/ui/demo_environment.hpp"
#include "modern/ui/demo_advertising.hpp"
#include "modern/ui/demo_toto.hpp"
#include "modern/ui/demo_reports.hpp"
#include "modern/ui/demo_sports.hpp"
#include "modern/ui/desktop.hpp"
@@ -343,6 +346,12 @@ class App final : public Rml::EventListener {
int contracts_tab_ = 2;
uint64_t contracts_revision_ = 0;
std::shared_ptr<const Catalog> contracts_world_;
int advertising_selected_ = -1, advertising_offer_ = 0;
uint64_t advertising_revision_ = 0;
std::shared_ptr<const Catalog> advertising_world_;
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_;
float device_ratio_ = 1.f;
Json desktop_ = Json::object(), saved_desktop_ = Json::object(),
options_ = Json::object();
@@ -556,6 +565,9 @@ class App final : public Rml::EventListener {
renderer_.world(next);
world_ = std::move(next);
source_ = std::move(demo);
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};
amount_.reset();
amount_select_all_ = amount_caret_end_ = false;
contracts_dialog_.clear();
@@ -694,6 +706,14 @@ class App final : public Rml::EventListener {
bool contracts_action(const std::string &, Rml::Element *);
bool contracts_event(Rml::Event &);
void close_contracts(bool restore = true);
std::string render_environment();
bool environment_action(const std::string &, Rml::Element *);
std::string render_advertising();
bool advertising_action(const std::string &, Rml::Element *);
bool advertising_event(Rml::Event &);
std::string render_toto();
bool toto_action(const std::string &, Rml::Element *);
bool toto_event(Rml::Event &);
std::string render_almanac();
bool almanac_action(const std::string &, Rml::Element *);
std::string render_indoor();
@@ -763,6 +783,12 @@ 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();
toto_dialog_.clear();
if (menu_ == "toto" && source_)
for (size_t c = 0; c < toto_focus_.size(); ++c) {
const int pick = snap().state.at("toto").at("columns")[c][0];
toto_focus_[c] = {0, pick < 0 ? 1 : pick};
}
amount_.reset();
contracts_dialog_.clear();
contract_draft_ = Json();
@@ -799,10 +825,10 @@ class App final : public Rml::EventListener {
if (!menu_.empty())
markup += render_menu(menu_);
element("canvas")->SetInnerRML(markup);
if (!report_detail_kind_.empty() || !planning_dialog_.empty() || !contracts_dialog_.empty()) {
if (!report_detail_kind_.empty() || !planning_dialog_.empty() || !contracts_dialog_.empty() || !toto_dialog_.empty()) {
Rml::ElementList behind;
doc_->QuerySelectorAll(behind,
"#report-underlay button,#report-underlay input,#report-underlay select,#contracts-underlay button,.window .titlebar button");
"#report-underlay button,#report-underlay input,#report-underlay select,#contracts-underlay button,#toto-underlay button,.window .titlebar button");
for (auto *node : behind)
node->SetProperty("pointer-events", "none");
}
@@ -1206,6 +1232,12 @@ public:
#include "modern/ui/finance_controls.inc"
#include "modern/ui/contracts_screens.inc"
#include "modern/ui/contracts_controls.inc"
#include "modern/ui/environment_screens.inc"
#include "modern/ui/environment_controls.inc"
#include "modern/ui/advertising_screens.inc"
#include "modern/ui/advertising_controls.inc"
#include "modern/ui/toto_screens.inc"
#include "modern/ui/toto_controls.inc"
} // namespace
bool is_modern_world(const fs::path &file) {
try {