Populate native desktop status, fixture and news widgets from the session (by Codex)
This commit is contained in:
1 parent
fd5c2b5330
commit
dc911f3281
21 files changed
+419
-91
No files matched your search
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_statistics.cpp engine_toto.cpp engine_stadium.cpp engine_transfer.cpp engine_achievements.cpp engine_news.cpp engine_balance.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp career_files.cpp demo_opening.cpp)
|
||||
add_library(bmh_modern_ui_core STATIC catalog.cpp crest_contrast.cpp engine_dto.cpp engine_statistics.cpp engine_toto.cpp engine_stadium.cpp engine_transfer.cpp engine_achievements.cpp engine_news.cpp engine_balance.cpp engine_widgets.cpp model.cpp demo_career.cpp demo_national_ui.cpp gui_assets.cpp desktop.cpp demo_sports.cpp demo_calendar.cpp demo_reports.cpp demo_almanac.cpp demo_finance.cpp demo_environment.cpp demo_advertising.cpp demo_toto.cpp demo_lineup.cpp demo_live.cpp demo_post_match.cpp demo_transfer.cpp demo_career_reports.cpp demo_rankings.cpp demo_stadium.cpp demo_statistics.cpp demo_news.cpp news_catalog.cpp news_journal.cpp demo_settings.cpp ui_preferences.cpp demo_widgets.cpp demo_files.cpp career_files.cpp demo_opening.cpp)
|
||||
target_include_directories(bmh_modern_ui_core PUBLIC ../..)
|
||||
target_link_libraries(bmh_modern_ui_core PUBLIC bmh_asset_io)
|
||||
add_library(bmh_modern_ui_mods STATIC mod_library.cpp)
|
||||
@@ -49,7 +49,7 @@ foreach(asset modern.rml theme.rcss ticket.rcss sports.rcss calendar.rcss report
|
||||
configure_file("${CMAKE_SOURCE_DIR}/assets/modern/${asset}" "${modern_assets}/${asset}" COPYONLY)
|
||||
endforeach()
|
||||
|
||||
foreach(component career_reports rankings career_files statistics_projection toto_projection stadium_projection transfer_projection achievements_projection news_projection balance_projection)
|
||||
foreach(component career_reports rankings career_files statistics_projection toto_projection stadium_projection transfer_projection achievements_projection news_projection balance_projection widgets_projection)
|
||||
add_executable(modern_${component}_tests ../../../tests/modern_${component}_tests.cpp)
|
||||
target_link_libraries(modern_${component}_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_widgets.hpp"
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include "modern/ui/demo_career.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -88,31 +89,9 @@ Json demo_desktop_widgets(const Catalog &world, const Json &state) {
|
||||
for (const auto &[id, c] : state.at("contracts").at("players").items())
|
||||
if (c.at("months") < 4)
|
||||
flags[8] = true;
|
||||
const std::array<const char *, 10> names{
|
||||
"Aktiengewinn", "Kontostand", "Freie Werbeflächen",
|
||||
"Sondertraining", "Erschöpfung", "Startaufstellung",
|
||||
"Ersatzspieler", "Taktischer Einsatz", "Auslaufende Verträge",
|
||||
"Lizenz"};
|
||||
const std::array<const char *, 10> icons{"chart", "coins", "shirt", "star",
|
||||
"heart", "person", "person", "chart",
|
||||
"save", "check"};
|
||||
const std::array<const char *, 10> notes{
|
||||
"Aktien im Bestand können mit Gewinn verkauft werden.",
|
||||
"Das verfügbare Guthaben wird knapp.",
|
||||
"Mindestens eine Werbefläche ist noch nicht vermietet.",
|
||||
"Ein spezieller Trainingsbedarf sollte geprüft werden.",
|
||||
"Die Belastung einzelner Spieler ist zu hoch.",
|
||||
"Die Startaufstellung ist noch unvollständig.",
|
||||
"Es stehen weniger als fünf Ersatzspieler bereit.",
|
||||
"Der eingestellte Einsatz ist sehr hoch.",
|
||||
"Mindestens ein Vertrag läuft in weniger als vier Monaten aus.",
|
||||
"Die Voraussetzungen für die Lizenz müssen geprüft werden."};
|
||||
result["warnings"] = Json::array();
|
||||
result["warnings"] = desktop_warning_definitions();
|
||||
for (size_t i = 0; i < flags.size(); ++i)
|
||||
result["warnings"].push_back({{"name", names[i]},
|
||||
{"icon", icons[i]},
|
||||
{"attention", flags[i]},
|
||||
{"description", notes[i]}});
|
||||
result["warnings"][i]["attention"] = flags[i];
|
||||
return result;
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
@@ -104,6 +105,32 @@ const std::vector<WidgetDefinition> &widget_definitions() {
|
||||
{"trash", "Papierkorb", {{1, 1}, {2, 2}}}};
|
||||
return value;
|
||||
}
|
||||
Json desktop_warning_definitions() {
|
||||
const std::array<const char *, 10> names{
|
||||
"Aktiengewinn", "Kontostand", "Freie Werbeflächen",
|
||||
"Sondertraining", "Erschöpfung", "Startaufstellung",
|
||||
"Ersatzspieler", "Taktischer Einsatz", "Auslaufende Verträge",
|
||||
"Lizenz"};
|
||||
const std::array<const char *, 10> icons{"chart", "coins", "shirt", "star",
|
||||
"heart", "person", "person", "chart",
|
||||
"save", "check"};
|
||||
const std::array<const char *, 10> notes{
|
||||
"Aktien im Bestand können mit Gewinn verkauft werden.",
|
||||
"Das verfügbare Guthaben wird knapp.",
|
||||
"Mindestens eine Werbefläche ist noch nicht vermietet.",
|
||||
"Ein spezieller Trainingsbedarf sollte geprüft werden.",
|
||||
"Die Belastung einzelner Spieler ist zu hoch.",
|
||||
"Die Startaufstellung ist noch unvollständig.",
|
||||
"Es stehen weniger als fünf Ersatzspieler bereit.",
|
||||
"Der eingestellte Einsatz ist sehr hoch.",
|
||||
"Mindestens ein Vertrag läuft in weniger als vier Monaten aus.",
|
||||
"Die Voraussetzungen für die Lizenz müssen geprüft werden."};
|
||||
Json rows = Json::array();
|
||||
for (size_t i = 0; i < names.size(); ++i)
|
||||
rows.push_back({{"name", names[i]}, {"icon", icons[i]},
|
||||
{"attention", nullptr}, {"description", notes[i]}});
|
||||
return rows;
|
||||
}
|
||||
Json default_desktop() {
|
||||
Json layout = {{"schema", "openbmh-modern-desktop@1"},
|
||||
{"grid", true},
|
||||
|
||||
@@ -8,6 +8,7 @@ struct WidgetDefinition {
|
||||
std::vector<std::pair<int, int>> sizes;
|
||||
};
|
||||
const std::vector<WidgetDefinition> &widget_definitions();
|
||||
Json desktop_warning_definitions();
|
||||
const std::vector<std::string> &desktop_routes();
|
||||
// These operations stage the whole layout. Failed placement leaves it
|
||||
// untouched.
|
||||
|
||||
@@ -17,7 +17,7 @@ Json from_engine(const cli::Json &v) { return Json::parse(cli::dump_json(v)); }
|
||||
namespace {
|
||||
Json session_snapshot(modern::app::ModernSession &session,uint64_t revision) {
|
||||
Json bundle=Json::object();
|
||||
for(const auto *kind:{"session","desktop","camps","squad","lineup","tactics","training","bank","stadium","credit","environment","advertising","contracts","friendly-plan","toto","transfer","achievements","news","balance"})bundle[kind]=from_engine(session.ui_read(cli::Json::Object{{"kind",kind}},revision));
|
||||
for(const auto *kind:{"session","desktop","camps","squad","lineup","tactics","training","bank","stadium","credit","environment","advertising","contracts","friendly-plan","toto","transfer","achievements","news","balance","desktop-widgets"})bundle[kind]=from_engine(session.ui_read(cli::Json::Object{{"kind",kind}},revision));
|
||||
validate_engine_desk(bundle);const auto &season=bundle.at("desktop").at("meta").at("season");
|
||||
bundle["calendar"]=from_engine(session.ui_read(cli::Json::Object{{"kind","calendar"},{"from",season.at("startDate").get<std::string>()},{"until",season.at("endDate").get<std::string>()}},revision));
|
||||
bundle["scheduling"]=from_engine(session.ui_read(cli::Json::Object{{"kind","scheduling"}},revision));return bundle;
|
||||
|
||||
@@ -72,6 +72,7 @@ Json engine_toto_command(const Json &bundle,const Json "e,const std::string
|
||||
|
||||
Json engine_statistics_projection(const Json &bundle,const Json &read);
|
||||
|
||||
Json engine_widgets_projection(const Json &bundle);
|
||||
Json engine_balance_projection(const Json &,const Json &);
|
||||
Json engine_balance_command(const Json &,const Json &,const std::string &);
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_TAB) {
|
||||
auto *root = !popup_.empty() ? element("popup") : !engine_player_.empty() ? element("engine-player-dialog") : !menu_.empty() ? doc_->QuerySelector(".window") : element("canvas"); Rml::ElementList controls;
|
||||
if (!root) return;
|
||||
root->QuerySelectorAll(controls, "button,input");
|
||||
root->QuerySelectorAll(controls, "button,input,[data-engine-route]");
|
||||
controls.erase(std::remove_if(controls.begin(), controls.end(), [](auto *node) { return !node->IsVisible(true) || node->HasAttribute("disabled"); }), controls.end());
|
||||
if (!controls.empty()) {
|
||||
const auto found = std::find(controls.begin(), controls.end(), context_->GetFocusElement());
|
||||
@@ -251,7 +251,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
if(type=="keydown") {
|
||||
const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
|
||||
if(key==Rml::Input::KI_RETURN||key==Rml::Input::KI_SPACE) {
|
||||
for(auto *node=target;node&&node!=doc_;node=node->GetParentNode())if(node->GetTagName()=="button") {
|
||||
for(auto *node=target;node&&node!=doc_;node=node->GetParentNode())if(node->GetTagName()=="button"||node->HasAttribute("data-engine-route")) {
|
||||
if(!node->HasAttribute("disabled"))node->DispatchEvent("click",{});
|
||||
event.StopImmediatePropagation();return;
|
||||
}
|
||||
@@ -269,6 +269,21 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (action == "popup-confirm") { auto callback=std::move(confirm_);auto text_callback=std::move(text_accept_);const auto text=field("popup-text");popup_.clear();reset_popup();dirty_=true;if(text_callback)text_callback(text);else if(callback)callback(); }
|
||||
return;
|
||||
}
|
||||
if (action == "engine-widget-warning" && menu_.empty() && !engine_busy_) {
|
||||
const auto rows = engine_widgets_projection(engine_data_).at("warnings");
|
||||
std::string text;
|
||||
for (size_t i = 0; i < rows.size(); ++i) {
|
||||
if (id != std::to_string(i) && id != "3,4" && id != "5,6") continue;
|
||||
if ((id == "3,4" && i != 3 && i != 4) || (id == "5,6" && i != 5 && i != 6)) continue;
|
||||
const auto &row = rows[i];
|
||||
if (!text.empty()) text += "\n";
|
||||
text += row.at("name").get<std::string>() + ": ";
|
||||
text += row.at("attention").is_null() ? "Nicht bekannt." : row.at("attention") == true
|
||||
? row.at("description").get<std::string>() : "Kein Hinweis.";
|
||||
}
|
||||
if (!text.empty()) message(text);
|
||||
return;
|
||||
}
|
||||
if(files_native_&&files_action(action,node))return;
|
||||
if(action.starts_with("rankings-")&&menu_=="scorers"){rankings_action(action,node);return;}
|
||||
if (engine_reports_action(action,node)) return;
|
||||
|
||||
@@ -58,8 +58,7 @@ void App::engine_render() {
|
||||
} else {
|
||||
const auto &desk = engine_data_.at("desktop").at("data"), &meta = engine_data_.at("desktop").at("meta");
|
||||
const auto &team = desk.at("team"), &person = desk.at("manager");
|
||||
const auto *club = world_->find("clubs", team.at("id").get<std::string>());
|
||||
out = "<div class=\"desktop-layer\"><div class=\"info-bar\"><div class=\"identity\">" + crest(club, 82) +
|
||||
out = "<div class=\"desktop-layer\"><div class=\"info-bar\"><div class=\"identity\">" + engine_widget_crest(team, 82) +
|
||||
"<span><strong>" + esc(engine_text(team.at("name"))) + "</strong><small>" + esc(engine_text(person.at("name"))) +
|
||||
"</small></span></div><div class=\"info-date\">" + esc(meta.at("date").get<std::string>()) + "<small>" +
|
||||
esc(meta.at("season").at("label").get<std::string>()) + "</small></div><div class=\"info-cash\"><small>Guthaben</small><strong id=\"engine-cash\" class=\"" + money_classes(engine_money_minor(desk.at("accounts").at("cash"))) + "\">" +
|
||||
@@ -90,9 +89,12 @@ void App::engine_render() {
|
||||
init_desktop();
|
||||
for (const auto &[id, o] : desktop_.at("objects").items()) {
|
||||
if (!o.value("visible", false)) continue;
|
||||
if (meta.at("scope").at("role") == "national" &&
|
||||
(id == "account" || id == "warnings" || id == "fans" || id == "results" ||
|
||||
id == "own-curve" || id == "opponent-curve" || id == "comparison-curve")) continue;
|
||||
const auto style = rect(o.at("x"), o.at("y"), o.at("w"), o.at("h"));
|
||||
if (o.value("widget", false)) {
|
||||
std::string body;
|
||||
std::string body = engine_widget(id, o);
|
||||
if (id == "portrait") {
|
||||
auto portrait = person.value("portraitGuiKey", "");
|
||||
if (portrait.starts_with("gui:manager/photo/"))
|
||||
@@ -113,9 +115,18 @@ void App::engine_render() {
|
||||
} else if (id == "opponent-crest" && desk.at("nextFixture").is_object()) {
|
||||
const auto &next = desk.at("nextFixture");
|
||||
const auto &other = next.at(next.at("home").at("id") == team.at("id") ? "away" : "home");
|
||||
body = widget_heading("Nächster Gegner", false) + "<div class=\"center\" style=\"padding:30dp;\">" + crest(world_->find("clubs", other.at("id").get<std::string>()), 220) + "<p>" + esc(engine_text(other.at("name"))) + "</p></div>";
|
||||
body = widget_heading("Nächster Gegner", false) + "<div class=\"center\" style=\"padding:30dp;\">" + engine_widget_crest(other, 220) + "<p>" + esc(engine_text(other.at("name"))) + "</p></div>";
|
||||
}
|
||||
if (!body.empty()) {
|
||||
std::string size = "s";
|
||||
for (const auto &definition : widget_catalogue()) if (definition.at("id") == id)
|
||||
for (const auto &[key, span] : definition.at("spans").items())
|
||||
if (o.at("w") == span[0].get<int>() * 248 - 24 && o.at("h") == span[1].get<int>() * 248 - 24) size = key;
|
||||
const auto route = id == "calendar" || id == "competition" ? std::string("calendar") : std::string();
|
||||
out += "<div id=\"object-" + esc(id) + "\" class=\"desktop-card desk-card\" data-widget=\"" + esc(id) + "\" data-size=\"" + size + "\" " +
|
||||
(route.empty() ? "" : "data-engine-route=\"" + route + "\" data-action=\"engine-open\" data-id=\"" + route + "\" tabindex=\"0\" role=\"button\" ") +
|
||||
"style=\"" + style + "\">" + body + "</div>";
|
||||
}
|
||||
if (!body.empty()) out += "<div class=\"desktop-card desk-card\" style=\"" + style + "\">" + body + "</div>";
|
||||
} else {
|
||||
const auto route = id.substr(4);
|
||||
const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available";
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/desktop.hpp"
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
void require_widget(bool yes, const char *message) {
|
||||
if (!yes)
|
||||
throw editor::Error(message);
|
||||
}
|
||||
} // namespace
|
||||
Json engine_widgets_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &read = bundle.at("desktop-widgets");
|
||||
require_widget(read.value("messageType", "") == "snapshot" &&
|
||||
read.at("data").value("kind", "") == "desktop-widgets",
|
||||
"Desktopwerte sind nicht verfügbar.");
|
||||
const auto &meta = bundle.at("desktop").at("meta");
|
||||
for (auto *key : {"contractVersion", "careerId", "worldId", "worldRevision",
|
||||
"stateRevision", "scope"})
|
||||
require_widget(read.at("meta").at(key) == meta.at(key),
|
||||
"Veraltete Desktopwerte.");
|
||||
const auto &d = read.at("data");
|
||||
require_widget(d.at("own").at("teamId") == meta.at("scope").at("teamId"),
|
||||
"Desktopwerte gehören einem anderen Verein.");
|
||||
auto summary = [](const Json &v) {
|
||||
require_widget(v.at("teamId").is_string(), "Vereinskennung fehlt.");
|
||||
const auto &rank = v.at("rank"), &strength = v.at("strength");
|
||||
require_widget(rank.is_null() ||
|
||||
(rank.is_number_integer() && rank >= 1 && rank <= 255),
|
||||
"Ungültiger Tabellenplatz.");
|
||||
require_widget(strength.is_null() || (strength.is_number_integer() &&
|
||||
strength >= 0 && strength <= 99),
|
||||
"Ungültige Teamstärke.");
|
||||
return v;
|
||||
};
|
||||
auto warnings = desktop_warning_definitions();
|
||||
require_widget(d.at("warnings").is_array() &&
|
||||
d.at("warnings").size() == warnings.size(),
|
||||
"Unvollständiger Vereinsstatus.");
|
||||
for (size_t i = 0; i < warnings.size(); ++i) {
|
||||
const auto &v = d.at("warnings")[i];
|
||||
require_widget(v.is_null() || v.is_boolean(), "Ungültiger Vereinsstatus.");
|
||||
warnings[i]["attention"] = v;
|
||||
}
|
||||
const auto &fixture = bundle.at("desktop").at("data").at("nextFixture");
|
||||
Json opponent = nullptr;
|
||||
if (d.at("opponent").is_object()) {
|
||||
opponent = summary(d.at("opponent"));
|
||||
require_widget(fixture.is_object(), "Gegner ohne bestätigte Begegnung.");
|
||||
const auto &home = fixture.at("home").at("id"),
|
||||
&away = fixture.at("away").at("id");
|
||||
const auto &own = d.at("own").at("teamId");
|
||||
require_widget((home == own && away == opponent.at("teamId")) ||
|
||||
(away == own && home == opponent.at("teamId")),
|
||||
"Gegner passt nicht zur Begegnung.");
|
||||
} else
|
||||
require_widget(d.at("opponent").is_null(), "Ungültiger Gegner.");
|
||||
return {{"own", summary(d.at("own"))},
|
||||
{"opponent", opponent},
|
||||
{"warnings", warnings},
|
||||
{"fixture", fixture}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,68 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
std::string App::engine_widget_crest(const Json &team, double size) {
|
||||
const auto *club = world_->find("clubs", team.at("id").get<std::string>());
|
||||
if (club)
|
||||
return crest(club, size);
|
||||
return picture(renderer_.crest(team.value("crestAssetId", std::string()),
|
||||
theme_ == "silver"),
|
||||
size, size);
|
||||
}
|
||||
std::string App::engine_widget(const std::string &id, const Json &o) {
|
||||
if (id == "news")
|
||||
return engine_news_value_.is_object() ? render_news_widget(o)
|
||||
: std::string();
|
||||
if (id != "warnings" && id != "competition" && id != "own-summary" &&
|
||||
id != "opponent-summary")
|
||||
return {};
|
||||
const auto data = engine_widgets_projection(engine_data_);
|
||||
if (id == "warnings")
|
||||
return widget_warnings(data.at("warnings"), o);
|
||||
if (id == "own-summary" || id == "opponent-summary") {
|
||||
const auto &row = data.at(id == "own-summary" ? "own" : "opponent");
|
||||
if (!row.is_object())
|
||||
return widget_heading("Platz & Stärke", false) +
|
||||
"<div class=\"center\">Noch kein Gegner bestätigt.</div>";
|
||||
const auto *club =
|
||||
world_->find("clubs", row.at("teamId").get<std::string>());
|
||||
const auto number = [&](const char *key) {
|
||||
return row.at(key).is_null() ? std::string("—")
|
||||
: std::to_string(row.at(key).get<int>());
|
||||
};
|
||||
std::string name = club ? world_->name(*club) : "Nationalteam";
|
||||
if (!club) {
|
||||
const auto &desk = engine_data_.at("desktop").at("data");
|
||||
if (desk.at("team").at("id") == row.at("teamId"))
|
||||
name = engine_text(desk.at("team").at("name"));
|
||||
else if (data.at("fixture").is_object())
|
||||
for (const auto *side : {"home", "away"})
|
||||
if (data.at("fixture").at(side).at("id") == row.at("teamId"))
|
||||
name = engine_text(data.at("fixture").at(side).at("name"));
|
||||
}
|
||||
return widget_heading(name, false) +
|
||||
"<div "
|
||||
"class=\"desk-summary\"><div><small>Tabellenplatz</small><strong>" +
|
||||
number("rank") +
|
||||
"</strong></div><div><small>Teamstärke</small><strong>" +
|
||||
number("strength") + "</strong></div></div>";
|
||||
}
|
||||
const auto &next = data.at("fixture");
|
||||
if (!next.is_object())
|
||||
return widget_heading("Nächste Begegnung", false) +
|
||||
"<div class=\"desk-fixture center\"><span>Keine bestätigte "
|
||||
"Begegnung.</span></div>";
|
||||
const auto &home = next.at("home"), &away = next.at("away");
|
||||
const auto team = [&](const Json &v) {
|
||||
return "<div>" +
|
||||
engine_widget_crest(v, o.at("w").get<int>() <= 472 ? 68 : 80) +
|
||||
"<span>" + esc(engine_text(v.at("name"))) + "</span></div>";
|
||||
};
|
||||
return widget_heading("Nächste Begegnung", false) +
|
||||
"<div class=\"desk-fixture\">" + team(home) +
|
||||
"<div class=\"desk-fixture-centre\"><small>" +
|
||||
esc(engine_text(next.at("competition"))) +
|
||||
"</small><strong>–</strong><span>" +
|
||||
(home.at("id") == data.at("own").at("teamId")
|
||||
? std::string("Heimspiel")
|
||||
: std::string("Auswärtsspiel")) +
|
||||
"</span></div>" + team(away) + "</div>";
|
||||
}
|
||||
@@ -217,28 +217,27 @@ std::string App::render_news() {
|
||||
}
|
||||
|
||||
std::string App::render_news_widget(const Json &object) {
|
||||
const auto s = snap();
|
||||
const auto data = demo_news_view(
|
||||
*s.world, s.state, "inbox", "",
|
||||
ui_preferences_.at("display").value("language", std::string("de")));
|
||||
const auto data = news_data("inbox", "");
|
||||
const auto raw_items = engine_mode_ ? engine_news_value_.at("items")
|
||||
: snap().state.at("news").at("items");
|
||||
if (!data.value("ok", false))
|
||||
return "";
|
||||
const bool compact_preview =
|
||||
object.value("w", 472) <= 472 && object.value("h", 472) <= 472;
|
||||
const int limit = compact_preview ? 2 : 3;
|
||||
std::string out =
|
||||
btn("open:news",
|
||||
"<span>Postfach · " + std::to_string(data.at("unread").get<int>()) +
|
||||
btn(engine_mode_ ? "engine-open" : "open:news",
|
||||
"<span>Postfach · " + std::to_string(data.at(engine_mode_ ? "shown_unread" : "unread").get<int>()) +
|
||||
" ungelesen</span><span class=\"news-widget-arrow\">" +
|
||||
glyph("arrow-diagonal", 26) + "</span>",
|
||||
"news-widget-heading",
|
||||
"id=\"desktop-news-open\" data-interactive=\"true\" "
|
||||
"id=\"desktop-news-open\" data-id=\"news\" data-interactive=\"true\" "
|
||||
"aria-label=\"Nachrichten öffnen\"");
|
||||
out += "<div class=\"news-widget-feed\">";
|
||||
int count = 0;
|
||||
// Gold's widget uses source order, independently of the open tablet's folder,
|
||||
// search and sorted list. Resolve templates through the same read projection.
|
||||
for (const auto &raw : s.state.at("news").at("items")) {
|
||||
for (const auto &raw : raw_items) {
|
||||
if (raw.at("folder") != "inbox")
|
||||
continue;
|
||||
const auto &shown = data.at("items");
|
||||
@@ -248,7 +247,7 @@ std::string App::render_news_widget(const Json &object) {
|
||||
if (found == shown.end())
|
||||
continue;
|
||||
out += "<div class=\"news-widget-row" +
|
||||
std::string(found->at("read").get<bool>() ? "" : " unread") +
|
||||
std::string(found->at("read") == false ? " unread" : "") +
|
||||
"\"><span class=\"news-widget-dot\"></span><div "
|
||||
"class=\"news-widget-copy\"><span class=\"news-widget-date\">" +
|
||||
esc(found->at("display_date").get<std::string>()) +
|
||||
|
||||
@@ -1551,6 +1551,7 @@ public:
|
||||
#include "modern/ui/engine_achievements.inc"
|
||||
#include "modern/ui/engine_news.inc"
|
||||
#include "modern/ui/engine_balance.inc"
|
||||
#include "modern/ui/engine_widgets.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
@@ -64,6 +64,58 @@ std::string App::widget_curve(const std::string &id, const Json &o, int w,
|
||||
(void)o;
|
||||
return out;
|
||||
}
|
||||
std::string App::widget_warnings(const Json &rows, const Json &o) {
|
||||
const int w = o.at("w"), h = o.at("h");
|
||||
const bool wide = h == 224;
|
||||
const std::vector<std::vector<int>> groups =
|
||||
wide ? std::vector<std::vector<int>>{{0}, {1}, {2}, {3, 4},
|
||||
{5, 6}, {7}, {8}, {9}}
|
||||
: std::vector<std::vector<int>>{{0}, {1}, {2}, {3}, {4},
|
||||
{5}, {6}, {7}, {8}, {9}};
|
||||
std::string out = widget_heading("Vereinsstatus", false) +
|
||||
"<div class=\"desk-warning-grid\">";
|
||||
const int cols = wide ? 8 : 5,
|
||||
cw = (w - (wide ? 56 : 52) - (wide ? 7 * 18 : 4 * 14)) / cols,
|
||||
rh = wide ? h - 76 : (h - 120) / 2;
|
||||
for (size_t i = 0; i < groups.size(); ++i) {
|
||||
std::string label, key;
|
||||
bool attention = false, known = true;
|
||||
for (int n : groups[i]) {
|
||||
const auto &v = rows[size_t(n)];
|
||||
if (!label.empty()) {
|
||||
label += " & ";
|
||||
key += ",";
|
||||
}
|
||||
label += v.at("name").get<std::string>();
|
||||
key += std::to_string(n);
|
||||
attention = attention || v.at("attention") == true;
|
||||
known = known && v.at("attention").is_boolean();
|
||||
}
|
||||
const auto &v = rows[size_t(groups[i][0])];
|
||||
out += btn(engine_mode_ ? "engine-widget-warning" : "widget-warning",
|
||||
"<span class=\"status-lamp " +
|
||||
std::string(attention ? "attention"
|
||||
: known ? "okay"
|
||||
: "unknown") +
|
||||
"\">" + glyph(v.at("icon"), h == 720 ? 42 : 28) + "</span>" +
|
||||
(wide ? ""
|
||||
: "<span class=\"warning-caption\">" + esc(label) +
|
||||
"</span>"),
|
||||
"desk-warning",
|
||||
"data-id=\"" + key + "\" data-interactive=\"true\" title=\"" +
|
||||
esc(label) + "\" aria-label=\"" + esc(label) + ": " +
|
||||
(attention ? "Handlungsbedarf"
|
||||
: known ? "In Ordnung"
|
||||
: "Nicht bekannt") +
|
||||
"\" style=\"left:" +
|
||||
std::to_string((wide ? 28 : 26) +
|
||||
(int(i) % cols) * (cw + (wide ? 18 : 14))) +
|
||||
"dp;top:" + std::to_string(int(i) / cols * (rh + 20)) +
|
||||
"dp;width:" + std::to_string(cw) +
|
||||
"dp;height:" + std::to_string(rh) + "dp;\"");
|
||||
}
|
||||
return out + "</div>";
|
||||
}
|
||||
std::string App::widget(const std::string &id, const Json &o) {
|
||||
const auto s = snap();
|
||||
if (!widget_data_.is_object())
|
||||
@@ -140,51 +192,8 @@ std::string App::widget(const std::string &id, const Json &o) {
|
||||
"</small><strong>" + esc(c ? world_->name(*c) : "") +
|
||||
"</strong></div>";
|
||||
}
|
||||
if (id == "warnings") {
|
||||
const std::vector<std::vector<int>> groups =
|
||||
wide ? std::vector<std::vector<int>>{{0}, {1}, {2}, {3, 4},
|
||||
{5, 6}, {7}, {8}, {9}}
|
||||
: std::vector<std::vector<int>>{{0}, {1}, {2}, {3}, {4},
|
||||
{5}, {6}, {7}, {8}, {9}};
|
||||
std::string out =
|
||||
heading("Vereinsstatus", false) + "<div class=\"desk-warning-grid\">";
|
||||
const int cols = wide ? 8 : 5,
|
||||
cw = (w - (wide ? 56 : 52) - (wide ? 7 * 18 : 4 * 14)) / cols,
|
||||
rh = wide ? h - 76 : (h - 120) / 2;
|
||||
for (size_t i = 0; i < groups.size(); ++i) {
|
||||
std::string label, key;
|
||||
bool attention = false;
|
||||
for (int n : groups[i]) {
|
||||
const auto &v = widget_data_.at("warnings")[size_t(n)];
|
||||
if (!label.empty()) {
|
||||
label += " & ";
|
||||
key += ",";
|
||||
}
|
||||
label += v.at("name").get<std::string>();
|
||||
key += std::to_string(n);
|
||||
attention = attention || v.at("attention") == true;
|
||||
}
|
||||
const auto &v = widget_data_.at("warnings")[size_t(groups[i][0])];
|
||||
out += btn("widget-warning",
|
||||
"<span class=\"status-lamp " +
|
||||
std::string(attention ? "attention" : "okay") + "\">" +
|
||||
glyph(v.at("icon"), h == 720 ? 42 : 28) + "</span>" +
|
||||
(wide ? ""
|
||||
: "<span class=\"warning-caption\">" + esc(label) +
|
||||
"</span>"),
|
||||
"desk-warning",
|
||||
"data-id=\"" + key + "\" data-interactive=\"true\" title=\"" +
|
||||
esc(label) + "\" aria-label=\"" + esc(label) + ": " +
|
||||
(attention ? "Handlungsbedarf" : "In Ordnung") +
|
||||
"\" style=\"left:" +
|
||||
std::to_string((wide ? 28 : 26) +
|
||||
(int(i) % cols) * (cw + (wide ? 18 : 14))) +
|
||||
"dp;top:" + std::to_string(int(i) / cols * (rh + 20)) +
|
||||
"dp;width:" + std::to_string(cw) +
|
||||
"dp;height:" + std::to_string(rh) + "dp;\"");
|
||||
}
|
||||
return out + "</div>";
|
||||
}
|
||||
if (id == "warnings")
|
||||
return widget_warnings(widget_data_.at("warnings"), o);
|
||||
if (id == "fans")
|
||||
return heading("Fan-Stimmung") + "<div class=\"desk-mood\">" +
|
||||
glyph("heart", 36) + "<div><strong>" +
|
||||
|
||||
@@ -8,6 +8,9 @@ std::string desktop_dialog(const std::string &, const std::string &,
|
||||
const std::string &, int width = 2560,
|
||||
int height = 1840);
|
||||
std::string widget_heading(const std::string &, bool link = true);
|
||||
std::string widget_warnings(const Json &, const Json &);
|
||||
std::string engine_widget_crest(const Json &, double);
|
||||
std::string engine_widget(const std::string &, const Json &);
|
||||
std::string widget_curve(const std::string &, const Json &, int, int);
|
||||
std::string render_widget_gallery_items();
|
||||
std::string render_widget_dialog(const std::string &);
|
||||
|
||||
Reference in new issue
Block a user