> meta = {{"Gestaltung", look == "silver" ? "Silver Glass" : look == "matchday" ? "Matchday" : "Midnight Glass"}, {"Widgets", std::to_string(widgets)}, {"Buttons", std::to_string(apps)}, {"Hintergrund", "Stadion bei Nacht"}};
+ out += "";
+ }
+ const auto data = fresh ? snap().state : files_entry_->data;
+ const auto meta = DemoFiles::career_metadata(data);
+ const auto &managers = meta.at("managers");
+ const Json *own = managers.empty() ? nullptr : world_->find("clubs", managers.at(0).value("club", ""));
+ out = "" + crest(own, 108) + "
" + std::string(fresh ? "Aktuelles Spiel" : "Gespeicherter Spielstand") + "
" + esc(fresh ? "Neuer Speicherstand" : files_entry_->name) + "
" + esc(own ? world_->name(*own) : "") + " ";
+ if (fresh) out += input();
+ out += "Mitspieler
";
+ for (const auto &manager : managers) {
+ const auto *managed = world_->find("clubs", manager.value("club", ""));
+ out += "" + esc(manager.value("name", "")) + "" + esc(managed ? world_->name(*managed) : "") + "
";
+ }
+ return out + "" + (fresh ? "Diese Angaben werden mit dem Spielstand gespeichert." : "Gespeichert am " + esc(files_entry_->created) + "
Geändert am " + esc(files_entry_->modified) + " · " + std::to_string(files_entry_->bytes) + " Bytes") + "
";
+}
+std::string App::render_files(bool layouts, bool save) {
+ if (files_mode_ != menu_) files_begin(menu_);
+ std::string entries;
+ const auto row = [&](const std::string &action, const std::string &id, const std::string &label, const std::string &subtitle, bool selected, const std::string &identity, bool fresh = false) {
+ const auto icon = fresh ? "plus" : id == "standard" ? "grid" : layouts ? "image" : "save";
+ return btn(action, "" + glyph(icon, 40) + "" + esc(label) + "" + esc(subtitle) + "" + (id == "standard" ? "Standard" : ""), std::string("files-entry ") + (selected ? "selected" : ""), "id=\"" + identity + "\" role=\"option\" data-id=\"" + esc(id) + "\" data-file-row=\"true\" aria-selected=\"" + (selected ? "true" : "false") + "\"");
+ };
+ if (save) entries += row("files-new", "", layouts ? "Neue Ansicht" : "Neuer Speicherstand", layouts ? "Aktuellen Desktop mit Vorschau sichern" : "Aktuellen Spielstand neu speichern", files_selected_.empty(), "files-new", true);
+ if (layouts && !save) entries += row("files-standard", "standard", "Standard", "Nach dem Original von BMH · immer verfügbar", files_selected_ == "standard", "files-standard");
+ for (size_t i = 0; i < files_rows_.size(); ++i) {
+ const auto &entry = files_rows_[i];
+ entries += row("files-select", entry.id, entry.name, entry.valid() ? "Gespeichert am " + entry.created : "Datei kann nicht geöffnet werden", files_selected_ == entry.id, "files-entry-" + std::to_string(i));
+ }
+ if (entries.empty()) entries = "Noch keine Spielstände vorhanden.
";
+ std::string details;
+ try { details = files_details(layouts, save); }
+ catch (const std::exception &e) { details = "Datei nicht verfügbar
" + esc(e.what()) + "
"; }
+ const bool selected = files_entry_ && files_entry_->valid();
+ bool can_save = save && (!files_entry_ || selected);
+ if (save && !selected) try { DemoFiles::clean_name(files_name_); } catch (...) { can_save = false; }
+ const auto disabled = selected ? "" : "disabled";
+ std::string footer = "";
+ if (!layouts) footer += btn("files-import", "Importieren") + btn("files-export", "Exportieren", {}, disabled);
+ footer += "
" + btn("files-rename", "Umbenennen", {}, disabled) + btn("files-delete", "Löschen", {}, files_entry_ && !files_entry_->token.empty() ? "" : "disabled") + "
" + btn("files-close", "Abbrechen") + btn(save ? "files-save" : "files-load", save ? "Speichern" : "Laden", "primary", "id=\"files-confirm\" " + std::string((save ? can_save : selected || (layouts && files_selected_ == "standard")) ? "" : "disabled")) + "
";
+ const auto content = "";
+ if (layouts) {
+ const auto feedback = files_feedback_.empty() ? (save ? "Look, Widgets, Größen und Fixierungen werden gemeinsam gespeichert." : "Die Standardansicht ist fixiert und bleibt immer verfügbar.") : files_feedback_;
+ const auto view_actions = "" + esc(feedback) + "
" + btn("files-rename", "Umbenennen", {}, disabled) + btn("files-delete", "Löschen", {}, files_entry_ && !files_entry_->token.empty() ? "" : "disabled") + "
" + btn("files-close", "Abbrechen") + btn(save ? "files-save" : "files-load", save ? "Speichern" : "Laden", "primary", "id=\"files-confirm\" " + std::string((save ? can_save : selected || files_selected_ == "standard") ? "" : "disabled"));
+ return desktop_dialog(save ? "Ansicht speichern" : "Ansicht laden", content, view_actions);
+ }
+ const auto actions = "";
+ return content + "" + esc(files_feedback_) + "
" + actions;
+}
diff --git a/src/modern/ui/files_state.inc b/src/modern/ui/files_state.inc
new file mode 100644
index 0000000..93ffd44
--- /dev/null
+++ b/src/modern/ui/files_state.inc
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-3.0-only
+// App-local browser drafts have no authority over the active career.
+std::string files_mode_, files_selected_, files_name_, files_feedback_;
+Json files_desktop_base_;
+std::string files_theme_base_;
+std::vector files_rows_;
+std::optional files_entry_;
+std::shared_ptr files_world_;
+const DataSource *files_source_ = nullptr;
+uint64_t files_revision_ = 0;
+float files_scroll_ = 0.f;
+bool files_restore_scroll_ = false, files_capturing_ = false;
+DemoFiles files_store() const;
+bool files_bound() const;
+void reset_files();
+void files_begin(const std::string &);
+void files_reload(const std::string &selected = {});
+void files_select(const std::string &);
+void files_before_render();
+void files_after_render();
+std::string render_files(bool layouts, bool save);
+std::string files_details(bool layouts, bool save);
+std::string files_standard_preview();
+bool files_action(const std::string &, Rml::Element *);
+bool files_change(Rml::Element *);
+bool files_event(Rml::Event &);
+std::string files_capture_preview();
+void files_save(const std::string &, const std::string &, const std::string &);
+void files_load();
+void files_saved_success(
+ bool career); // Root owns main-menu / quit continuation.
+void files_loaded_success(); // Root resets source-dependent presenters.
+
+bool files_reveal_selected_ = false;
diff --git a/src/modern/ui/model.cpp b/src/modern/ui/model.cpp
index 63933c7..834c3e7 100644
--- a/src/modern/ui/model.cpp
+++ b/src/modern/ui/model.cpp
@@ -250,7 +250,14 @@ void DemoSource::save(const fs::path &file, const Json &desktop) {
saved_ = state_;
}
Json DemoSource::load(const fs::path &file) {
- auto data = Json::parse(editor::read_file(file));
+ return load_data(Json::parse(editor::read_file(file)));
+}
+bool DemoSource::mark_saved(uint64_t expected_revision) {
+ if (revision_ != expected_revision) return false;
+ saved_ = state_;
+ return true;
+}
+Json DemoSource::load_data(Json data) {
if (data.value("schema", "") != "openbmh-ui-demo@1" ||
data.value("world", "") != catalog_->manifest().value("id", ""))
throw editor::Error("wrong_demo_world");
diff --git a/src/modern/ui/model.hpp b/src/modern/ui/model.hpp
index b23ba61..cda2471 100644
--- a/src/modern/ui/model.hpp
+++ b/src/modern/ui/model.hpp
@@ -42,6 +42,8 @@ public:
Json read_statistics(const Json &) const override;
void save(const fs::path &, const Json &desktop);
Json load(const fs::path &);
+ Json load_data(Json);
+ bool mark_saved(uint64_t expected_revision);
bool dirty() const { return state_ != saved_; }
private:
diff --git a/src/modern/ui/screens.inc b/src/modern/ui/screens.inc
index f804091..77d3a4f 100644
--- a/src/modern/ui/screens.inc
+++ b/src/modern/ui/screens.inc
@@ -1,210 +1,49 @@
// SPDX-License-Identifier: GPL-3.0-only
// Included in the native UI implementation's anonymous namespace.
void App::init_desktop() {
- if (!desktop_.contains("objects")) {
- desktop_ = default_desktop();
- saved_desktop_ = desktop_;
+ if(!desktop_.contains("objects"))desktop_=default_desktop();
+ if(!working_desktop_initialized_){
+ working_desktop_initialized_=true;
+ const auto file=user_dir()/"working-desktop.json";
+ if(config_.state.empty()&&fs::is_regular_file(file)){
+ try{auto next=Json::parse(editor::read_file(file));if(!migrate_desktop(next))throw editor::Error("Ungültige Desktopanordnung.");desktop_=std::move(next);}
+ catch(const std::exception &){message("Die gespeicherte Desktopanordnung konnte nicht geladen werden. Die Standardansicht wird verwendet.");}
+ }
+ working_desktop_base_=desktop_;saved_desktop_=desktop_;
}
}
-std::string App::widget(const std::string &id, const Json &o) {
- const auto s = snap();
- const auto *own = club(s);
- const auto w = o.value("w", 472), h = o.value("h", 472);
- const auto row = world_->clubs(own ? own->value("competition", "") : league_);
- const auto *opponent =
- row.size() > 1 ? (row[0] == own ? row[1] : row[0]) : own;
- auto heading = [&](const std::string &name) {
- return "" + esc(name) + "
";
- };
- if (id == "calendar") {
- const auto date = s.state.value("date", std::string("2026-07-01"));
- const auto year = date.substr(0, 4), day = date.substr(8, 2);
- const int month = std::stoi(date.substr(5, 2));
- const std::array months = {
- "Januar", "Februar", "März", "April", "Mai", "Juni",
- "Juli", "August", "September", "Oktober", "November", "Dezember"};
- return "" +
- std::string(months[size_t(std::clamp(month, 1, 12) - 1)]) + " " +
- year +
- "
Saisonvorbereitung
" +
- std::to_string(std::stoi(day)) + "
" +
- esc(date) + "
" +
- btn("open:calendar",
- glyph("calendar", 32) +
- "Kalender öffnen" +
- glyph("arrow-diagonal", 30) + "",
- "card-button calendar-link",
- "style=\"left:0;bottom:0;width:100%;height:90dp;border-top:2dp "
- "var(--border);font-size:25dp;color:var(--muted);\"");
- }
- if (id == "account") {
- if (h < 300)
- return "Konto" +
- cash(s.state.value("cash", int64_t(0))) + "
" +
- btn("ticket",
- "Eintritt " +
- std::to_string(s.state.value("ticket", 13)) + " €",
- "card-button",
- "id=\"desktop-ticket\" data-interactive=\"true\" "
- "style=\"right:20dp;top:45dp;font-size:32dp;\"");
- return heading("Vereinskasse") +
- "Guthaben
" +
- cash(s.state.value("cash", int64_t(0))) +
- "
Sparbuch" +
- cash(s.state.value("deposit", int64_t(0))) + "
" +
- btn("ticket",
- "Eintritt
" +
- std::to_string(s.state.value("ticket", 13)) + " € ›",
- "card-button",
- "id=\"desktop-ticket\" data-interactive=\"true\" "
- "style=\"right:30dp;bottom:20dp;min-width:200dp;padding:12dp "
- "24dp;font-size:34dp;background-color:var(--soft);border-radius:"
- "18dp;\"");
- }
- if (id == "portrait")
- return img(std::string(manager(s).value("portrait_style", "photo") ==
- "painted"
- ? "manager-painted."
- : "manager.") +
- std::to_string(manager(s).value("portrait", 0)),
- w, h, false, true, 800) +
- "Manager" +
- esc(manager(s).value("name", "")) + "
";
- if (id == "crest" || id == "opponent-crest")
- return "" +
- crest(id == "crest" ? own : opponent, std::min(w - 60, h - 150)) +
- "
" +
- (id == "crest" ? "Dein Verein" : "Nächster Gegner") + "
" +
- esc(world_->name(*(id == "crest" ? own : opponent))) + "
";
- if (id == "competition")
- return heading("Nächste Begegnung") +
- "" +
- crest(own, 80) + "
" +
- esc(own ? world_->name(*own) : "") +
- "
Freundschaftsspiel
19:00
Heim · "
- "Samstag
" +
- crest(opponent, 80) +
- "
" +
- esc(opponent ? world_->name(*opponent) : "") + "
";
- if (id == "warnings") {
- const std::array names = {
- "Aktiengewinn", "Kontostand", "Freie Werbeflächen",
- "Sondertraining", "Erschöpfung", "Startaufstellung",
- "Ersatzspieler", "Taktischer Einsatz", "Auslaufende Verträge",
- "Lizenz"};
- const std::array icons = {
- "chart", "coins", "shirt", "star", "heart",
- "person", "person", "chart", "save", "check"};
- const std::array wide_members = {0, 1, 2, 3, 5, 7, 8, 9};
- const bool wide = h < 300;
- const int columns = wide ? 8 : 5, count = wide ? 8 : 10;
- std::string out = heading("Vereinsstatus");
- for (int i = 0; i < count; ++i) {
- const int member = wide ? wide_members[size_t(i)] : i;
- const int cell_w = (w - 52) / columns;
- const int x = 26 + cell_w * (i % columns),
- y = wide ? 90 : 95 + (i / columns) * 175;
- out += "" +
- glyph(icons[size_t(member)], 36) + "
" +
- (wide ? ""
- : "
" +
- std::string(names[size_t(member)]) + "
") +
- "
";
- }
- return out;
- }
- if (id == "trash")
- return "" +
- glyph("trash", 100) +
- "
Papierkorb
";
- if (id == "fans")
- return heading("Fan-Stimmung") +
- "" +
- std::to_string(s.state.value("fans", 67)) + " %
";
- if (id == "news")
- return render_news_widget(o);
- if (id == "results")
- return heading("Letzte sechs Spiele") +
- "–"
- "span>––––"
- "span>–
";
- if (id == "own-summary" || id == "opponent-summary")
- return heading(id == "own-summary" ? "Platz & Stärke · eigener Verein"
- : "Platz & Stärke · Gegner") +
- "–"
- "span>–
";
- const auto caption = id == "duels" ? "Direkter Vergleich"
- : id == "comparison-curve" ? "Tabellenplätze · Vergleich"
- : id == "own-curve" ? "Tabellenplatz · eigener Verein"
- : "Tabellenplatz · Gegner";
- return heading(caption) +
- "";
-}
std::string App::render_desktop() {
init_desktop();
const auto s = snap();
+ widget_data_ = demo_desktop_widgets(*world_, s.state);
const auto *c = club(s);
std::string out =
- "" +
+ "
" +
btn("desktop-context",
crest(c, 82) + "
" + esc(c ? world_->name(*c) : "") +
"" + esc(manager(s).value("name", "")) +
"",
- "identity") +
- "
Saisonvorbereitung
" +
- esc(s.state.value("date", std::string())) +
+ "identity", "id=\"desktop-identity\"") +
+ "" + std::string(widget_data_.at("matchday")==0?"Saisonvorbereitung":std::to_string(widget_data_.at("matchday").get())+". Spieltag") + "" +
+ esc(widget_data_.at("season").get()) +
"
Guthaben" +
cash(s.state.value("cash", int64_t(0))) + "
";
+ if(desktop_.value("grid",true))for(int row=0;row<7;++row)for(int col=0;col<15;++col)out+="
";
for (const auto &[id, o] : desktop_["objects"].items()) {
if (!o.value("visible", false))
continue;
const auto style = rect(o.value("x", 0), o.value("y", 0), o.value("w", 224),
- o.value("h", 224));
- if (o.value("widget", false))
- out += "
" +
+ o.value("h", 224)) + "z-index:" + std::to_string(o.value("z", 1)) + ";";
+ if (o.value("widget", false)) {
+ std::string size="s",route;
+ for(const auto &d:widget_catalogue())if(d.at("id")==id){route=d.value("route","");for(const auto &[key,span]:d.at("spans").items())if(o.at("w")==span[0].get
()*248-24&&o.at("h")==span[1].get()*248-24)size=key;}
+ out += "" +
widget(id, o) +
(o.value("pinned", true) ? "
" : "") +
"
";
- else {
+ } else {
const auto route = id.substr(4);
const std::array colors = {
"#3d789b", "#375a83", "#477c73", "#42846b", "#a58a49", "#586ba0",
@@ -226,12 +65,12 @@ std::string App::render_desktop() {
"style=\"decorator:linear-gradient(140deg," +
top + "," + bottom + ");\">" +
img("button." + route, 146, 146, false, false, 256) +
- " " + esc(title(route)) + "" +
+ "
" + esc(route=="transfer"?"Transfer":title(route)) + "" +
(o.value("pinned", true) ? "
" : "") +
"";
}
}
- return out;
+ return out + "
";
}
std::string App::render_newgame() {
std::string body = "
Grundeinstellungen
";
return body;
}
-std::string App::render_save(bool save) {
- const auto directory = user_dir() / "saves";
- std::string body = "";
- if (save)
- body += btn("save-new", "Neuer Speicherstand", "choice",
- "style=\"width:100%;text-align:left;min-height:100dp;margin-"
- "bottom:14dp;\"");
- if (fs::exists(directory))
- for (const auto &file : fs::directory_iterator(directory))
- if (file.path().extension() == ".json") {
- const auto name = editor::utf8(file.path().stem());
- body += btn("save-select", esc(name),
- std::string("choice ") +
- (selections_["save"] == name ? "selected" : ""),
- "data-id=\"" + esc(name) +
- "\" "
- "style=\"width:100%;min-height:110dp;text-align:left;"
- "margin-bottom:14dp;\"");
- }
- body += "
" +
- esc(selections_["save"].empty() ? "Speicherstand auswählen"
- : selections_["save"]) +
- "
";
- const auto s = snap();
- body +=
- "
" + crest(club(s), 340) +
- "
Saison" +
- esc(s.state.value("date", std::string()).substr(0, 4)) +
- "
SpieltagSaisonvorbereitung"
- "strong>
Datum" +
- esc(s.state.value("date", std::string())) +
- "
Mitspieler" +
- std::to_string(s.state.at("managers").size()) + "
";
- if (save && selections_["save"].empty())
- body += "
";
- return body + "
" +
- btn("save-delete", "Löschen") + btn("save-rename", "Umbenennen") +
- btn("close", "Abbrechen") +
- btn(save ? "save-confirm" : "load-confirm",
- save ? "Speichern" : "Laden", "primary") +
- "
";
-}
std::string App::render_menu(const std::string &key) {
+ if(key=="view-save"||key=="view-load")return render_files(true,key=="view-save");
+ if (key == "widgets" || key == "background" || key == "warning" || key == "quit") return render_widget_dialog(key);
if (key == "news")
return "" + render_news() + "
";
std::string body;
@@ -813,10 +605,7 @@ std::string App::render_menu(const std::string &key) {
else if (key == "settings")
body = render_settings();
else if (key == "save" || key == "load")
- body = render_save(key == "save");
- else if (key == "widgets" || key == "view-save" || key == "view-load" ||
- key == "background")
- body = render_desktop_tools(key);
+ body = render_files(false,key == "save");
else
throw editor::Error("Diese native Ansicht ist noch nicht verfügbar.");
std::string heading = key == "postpone" ? "Spiel verlegen" : title(key);
diff --git a/src/modern/ui/settings_controls.inc b/src/modern/ui/settings_controls.inc
index 429fb36..a62a0bb 100644
--- a/src/modern/ui/settings_controls.inc
+++ b/src/modern/ui/settings_controls.inc
@@ -247,6 +247,7 @@ void App::settings_commit() {
settings_sync();
return;
}
+ if(scene_=="desktop"&&global.at("theme")!=theme_)desktop_checkpoint(desktop_);
ui_preferences_ = global;
theme_ = global.at("theme").get();
if (changed_global)
diff --git a/src/modern/ui/settings_screens.inc b/src/modern/ui/settings_screens.inc
index f7880e0..db9b207 100644
--- a/src/modern/ui/settings_screens.inc
+++ b/src/modern/ui/settings_screens.inc
@@ -2,7 +2,7 @@
bool App::settings_global_only() const { return scene_ == "main" || !source_; }
fs::path App::ui_preferences_file() const {
return config_.preferences.empty()
- ? root_ / "userdata" / "modern-ui-preferences.json"
+ ? (config_.userdata.empty() ? root_ / "userdata" : config_.userdata) / "modern-ui-preferences.json"
: config_.preferences;
}
void App::reset_settings() {
diff --git a/src/modern/ui/view.cpp b/src/modern/ui/view.cpp
index f2172d7..4f04f6b 100644
--- a/src/modern/ui/view.cpp
+++ b/src/modern/ui/view.cpp
@@ -22,12 +22,15 @@
#include "modern/ui/demo_settings.hpp"
#include "modern/ui/ui_preferences.hpp"
#include "modern/ui/desktop.hpp"
+#include "modern/ui/demo_widgets.hpp"
+#include "modern/ui/demo_files.hpp"
#include "modern/ui/gui_assets.hpp"
#include "modern/ui/model.hpp"
#include "modern/ui/ticket_popover.hpp"
#include "modern/ui/view.hpp"
#include "version.hpp"
#include
+#include
#include
#include
#include
@@ -171,6 +174,15 @@ public:
const auto &r = entries_.at(token).raster;
return {token, r.width, r.height};
}
+ Picture generated_png(const std::string &slot,const std::string &png){
+ const auto token="modern-generated-"+slot+".png",digest=content::sha256(png);
+ auto found=entries_.find(token);
+ if(found==entries_.end()||found->second.key!=digest){
+ if(auto loaded=loaded_sources_.find(token);loaded!=loaded_sources_.end()){Rml::ReleaseTexture(loaded->second,this);loaded_sources_.erase(loaded);}
+ entries_[token]={digest,false,1280,editor::images::decode(png,".png")};
+ }
+ const auto &r=entries_.at(token).raster;return {token,r.width,r.height};
+ }
Picture local_image(const fs::path &file, int pixels) {
const auto identity =
editor::utf8(file) + ":" +
@@ -393,6 +405,7 @@ class App final : public Rml::EventListener {
std::string id;
float x = 0, y = 0;
double left = 0, top = 0;
+ bool pinned=false;
};
Drag drag_;
bool suppress_click_ = false;
@@ -411,6 +424,8 @@ class App final : public Rml::EventListener {
bool draw_playing_ = true;
uint64_t draw_at_ = 0;
#include "modern/ui/settings_state.inc"
+#include "modern/ui/widgets_state.inc"
+#include "modern/ui/files_state.inc"
std::map selections_;
Rml::Element *element(const std::string &id) const {
return doc_->GetElementById(id);
@@ -438,7 +453,7 @@ class App final : public Rml::EventListener {
fs::path user_dir() const {
const auto id = world_ ? world_->manifest().value("id", std::string("none"))
: std::string("none");
- return root_ / "userdata" / "ui-demo" / content::sha256(id);
+ return (config_.userdata.empty() ? root_ / "userdata" : config_.userdata) / "ui-demo" / content::sha256(id);
}
std::string img(const std::string &key, double w, double h,
bool world = false, bool cover = false, int pixels = 512) {
@@ -587,6 +602,7 @@ class App final : public Rml::EventListener {
}
void load_world(const fs::path &file) {
reset_settings();
+ reset_files();
auto next = Catalog::open(file);
auto demo = std::make_unique(next);
ticket_.reset();
@@ -621,6 +637,8 @@ class App final : public Rml::EventListener {
almanac_match_.clear();
almanac_tab_ = "lineups";
desktop_ = Json::object();
+ working_desktop_initialized_=false;working_desktop_base_=Json();
+ files_default_key_.clear();files_default_picture_=Picture();files_default_pending_=false;
ticket_ =
std::make_unique(*context_, *doc_, *source_, [this] {
focus_ticket_ = true;
@@ -787,8 +805,6 @@ class App final : public Rml::EventListener {
const std::string &player = {}, int size = 56,
int gap = 10, bool overtraining = false);
std::string render_settings();
- std::string render_save(bool save);
- std::string render_desktop_tools(const std::string &);
void render_context();
void context_menu(const std::string &id, int x, int y);
void drag_event(Rml::Event &);
@@ -854,6 +870,8 @@ class App final : public Rml::EventListener {
almanac_list_width_ = -1.f;
// A window-close save prompt can leave a menu while its local dialog is
// open. Never keep that menu's modal/input gate in the destination view.
+ if(menu_=="widgets" && last_rendered_menu_=="widgets")widget_remember_scroll();
+ files_before_render();
if (menu_ != last_rendered_menu_) {
if(last_rendered_menu_=="settings")reset_settings();
statistics_trophy_ = Json::object();
@@ -1042,6 +1060,8 @@ class App final : public Rml::EventListener {
ticket_->update();
if (needs_render_)
render();
+ if(files_default_pending_&&!files_capturing_){update_files_default_thumbnail();render();}
+ persist_working_desktop();
render_popup();
render_context();
context_->Update();
@@ -1076,6 +1096,8 @@ class App final : public Rml::EventListener {
if (menu_ == "scorers" || menu_ == "fairplay") rankings_restore_scroll();
if (menu_ == "statistics") statistics_restore_scroll();
if (menu_ == "settings") settings_after_render();
+ files_after_render();
+ if(menu_=="widgets" && widget_restore_scroll_){if(auto *gallery=element("widget-gallery"))gallery->SetScrollTop(widget_gallery_scroll_);widget_restore_scroll_=false;}
if (!report_option_to_scroll_.empty()) {
if (auto *node = element(report_option_to_scroll_))
node->ScrollIntoView(Rml::ScrollIntoViewOptions(Rml::ScrollAlignment::Nearest));
@@ -1085,7 +1107,7 @@ class App final : public Rml::EventListener {
renderer_.BeginFrame();
context_->Render();
renderer_.EndFrame();
- video_.present();
+ if(!files_capturing_)video_.present();
dirty_ = false;
}
void screenshot(const fs::path &file) {
@@ -1320,12 +1342,15 @@ public:
while (got) {
if (event.type == SDL_QUIT) {
if (source_ && scene_ != "main") {
+ quit_closes_app_=true;
dispatch("context-quit", nullptr);
} else
closed_ = true;
} else {
- if (event.type == SDL_WINDOWEVENT)
+ if (event.type == SDL_WINDOWEVENT) {
+ if(event.window.event==SDL_WINDOWEVENT_FOCUS_LOST)desktop_cancel_drag();
resize();
+ }
int w, h, pw, ph;
SDL_GetWindowSize(video_.window, &w, &h);
video_.drawable_size(pw, ph);
@@ -1354,7 +1379,10 @@ public:
}
};
#include "modern/ui/controls.inc"
-#include "modern/ui/desktop_screens.inc"
+#include "modern/ui/widgets_screens.inc"
+#include "modern/ui/widgets_controls.inc"
+#include "modern/ui/files_screens.inc"
+#include "modern/ui/files_controls.inc"
#include "modern/ui/screens.inc"
#include "modern/ui/sports_screens.inc"
#include "modern/ui/calendar_screen.inc"
diff --git a/src/modern/ui/view.hpp b/src/modern/ui/view.hpp
index 8e84ab1..67a026e 100644
--- a/src/modern/ui/view.hpp
+++ b/src/modern/ui/view.hpp
@@ -4,7 +4,7 @@
namespace bmh::modern_ui {
struct Config {
- std::filesystem::path world, gui_assets, screenshot, commands, state, preferences;
+ std::filesystem::path world, gui_assets, screenshot, commands, state, preferences, userdata, file_import, file_export;
std::string scene = "main", theme;
int width = 1280, height = 720;
};
diff --git a/src/modern/ui/widgets_controls.inc b/src/modern/ui/widgets_controls.inc
new file mode 100644
index 0000000..62d856c
--- /dev/null
+++ b/src/modern/ui/widgets_controls.inc
@@ -0,0 +1,461 @@
+// SPDX-License-Identifier: GPL-3.0-only
+void App::desktop_checkpoint(const Json &before) {
+ if (undo_.empty() || undo_.back() != before ||
+ (!undo_themes_.empty() && undo_themes_.back() != theme_)) {
+ undo_.push_back(before);
+ undo_themes_.push_back(theme_);
+ }
+ if (undo_.size() > 40) {
+ undo_.erase(undo_.begin());
+ undo_themes_.erase(undo_themes_.begin());
+ }
+}
+void App::desktop_cancel_drag() {
+ if (!drag_.active)
+ return;
+ if (drag_.moved && !drag_.pinned && !undo_.empty()) {
+ desktop_ = undo_.back();
+ if (undo_.size() > drag_undo_size_) {
+ undo_.pop_back();
+ if (!undo_themes_.empty())
+ undo_themes_.pop_back();
+ }
+ }
+ drag_ = {};
+ suppress_click_ = true;
+ refresh();
+}
+void App::desktop_raise(const std::string &id) {
+ int highest = 0;
+ for (const auto &[key, o] : desktop_.at("objects").items())
+ highest = std::max(highest, o.value("z", 1));
+ if (highest >= 9900) {
+ int index = 0;
+ for (auto &[key, o] : desktop_["objects"].items())
+ o["z"] = ++index;
+ highest = index;
+ }
+ desktop_["objects"][id]["z"] = highest + 1;
+}
+void App::widget_remember_scroll() {
+ if (auto *pane = element("widget-gallery"))
+ widget_gallery_scroll_ = pane->GetScrollTop();
+}
+bool App::widget_change(Rml::Element *target) {
+ if (menu_ != "widgets" || !target)
+ return false;
+ if (target->GetId() == "widget-search") {
+ widget_query_ = field("widget-search");
+ widget_gallery_scroll_ = 0;
+ setting_menu_markup_ = true;
+ if (auto *gallery = element("widget-gallery"))
+ gallery->SetInnerRML(render_widget_gallery_items());
+ setting_menu_markup_ = false;
+ context_->Update();
+ center_selects(*doc_);
+ context_->Update();
+ if (auto *gallery = element("widget-gallery"))
+ gallery->SetScrollTop(0);
+ dirty_ = true;
+ return true;
+ }
+ if (target->HasAttribute("data-widget-size")) {
+ const auto id = target->GetAttribute("data-widget-size", "");
+ const auto value = field(target->GetId());
+ const auto at = value.find('x');
+ if (at != value.npos)
+ widget_choices_[id] = {std::stoi(value.substr(0, at)),
+ std::stoi(value.substr(at + 1))};
+ return true;
+ }
+ return false;
+}
+bool App::widget_action(const std::string &action, Rml::Element *target) {
+ if (action == "context-undo") {
+ focus_after_render_ =
+ context_id_.empty() ? "desktop-identity" : "object-" + context_id_;
+ desktop_undo();
+ context_open_ = false;
+ return true;
+ }
+ if (action == "widget-add") {
+ if (menu_ != "widgets" || !target)
+ return true;
+ widget_remember_scroll();
+ const auto id = target->GetAttribute("data-id", "");
+ std::pair span{0, 0};
+ for (const auto &d : widget_catalogue())
+ if (d.at("id") == id) {
+ const auto &v = d.at("spans").at(d.at("size").get());
+ span = {v[0], v[1]};
+ }
+ if (widget_choices_.contains(id))
+ span = widget_choices_.at(id);
+ auto before = desktop_;
+ if (add_desktop_widget(desktop_, id, span.first, span.second)) {
+ desktop_raise(id);
+ desktop_checkpoint(before);
+ widget_notice_ = "Widget hinzugefügt. Du kannst es direkt auf dem "
+ "Desktop verschieben.";
+ } else
+ widget_notice_ = "Kein freier Rasterplatz. Entferne ein Widget oder "
+ "wähle eine kleinere Größe.";
+ focus_after_render_ = "widget-size-" + id;
+ refresh();
+ return true;
+ }
+ if (action == "widget-warning" && target) {
+ widget_warning_ = target->GetAttribute("data-id", "");
+ menu_ = "warning";
+ refresh();
+ return true;
+ }
+ if (action == "widget-background") {
+ widget_notice_ = "Stadion bei Nacht ist ausgewählt.";
+ refresh();
+ return true;
+ }
+ if (action == "context-grid") {
+ focus_after_render_ = "desktop-identity";
+ auto before = desktop_;
+ if (set_desktop_grid(desktop_, !desktop_.value("grid", true))) {
+ desktop_checkpoint(before);
+ refresh();
+ } else
+ message("Nicht genug freier Platz. Die Anordnung bleibt erhalten.");
+ context_open_ = false;
+ return true;
+ }
+ if (action == "context-widgets") {
+ widget_query_.clear();
+ widget_notice_.clear();
+ widget_gallery_scroll_ = 0;
+ widget_choices_.clear();
+ return false;
+ }
+ if (action == "context-background") {
+ widget_notice_.clear();
+ return false;
+ }
+ if (action == "context-quit") {
+ desktop_cancel_drag();
+ context_open_ = false;
+ quit_origin_menu_ = menu_;
+ menu_ = "quit";
+ refresh();
+ return true;
+ }
+ if (action == "desktop-quit-cancel") {
+ quit_after_save_ = false;
+ quit_closes_app_ = false;
+ menu_ = quit_origin_menu_;
+ refresh();
+ return true;
+ }
+ if (action == "desktop-quit-save") {
+ quit_after_save_ = true;
+ reset_files();
+ menu_ = "save";
+ refresh();
+ return true;
+ }
+ if (action == "desktop-quit-discard" || action == "desktop-quit-confirm") {
+ finish_desktop_quit();
+ return true;
+ }
+ if (action == "context-remove" &&
+ desktop_.at("objects").at(context_id_).at("pinned") == true)
+ return true;
+ if (action == "close" && menu_ == "quit") {
+ widget_action("desktop-quit-cancel", nullptr);
+ return true;
+ }
+ return false;
+}
+bool App::widget_event(Rml::Event &event) {
+ if (!popup_.empty() || amount_)
+ return false;
+ const auto type = event.GetType();
+ auto *target = event.GetTargetElement();
+ if (menu_ == "widgets") {
+ if (type == "input" || type == "change") {
+ if (auto *select = dynamic_cast(target);
+ select && select->IsSelectBoxVisible()) {
+ pending_selects_.insert(select->GetId());
+ dirty_ = true;
+ return true;
+ }
+ return widget_change(target);
+ }
+ }
+ if (type != "keydown" || scene_ != "desktop")
+ return false;
+ const auto key =
+ Rml::Input::KeyIdentifier(event.GetParameter("key_identifier", 0));
+ const bool shift = event.GetParameter("shift_key", 0) != 0,
+ control = event.GetParameter("ctrl_key", 0) ||
+ event.GetParameter("meta_key", 0);
+ if (context_open_) {
+ if (key == Rml::Input::KI_UP || key == Rml::Input::KI_DOWN ||
+ key == Rml::Input::KI_HOME || key == Rml::Input::KI_END) {
+ Rml::ElementList buttons;
+ if (auto *root = element("desktop-context"))
+ root->QuerySelectorAll(buttons, "button");
+ std::erase_if(buttons, [](auto *button) {
+ return button->HasAttribute("disabled");
+ });
+ if (!buttons.empty()) {
+ auto it = std::find(buttons.begin(), buttons.end(),
+ context_->GetFocusElement());
+ int n = int(buttons.size()),
+ index = it == buttons.end() ? 0 : int(it - buttons.begin());
+ index = key == Rml::Input::KI_HOME ? 0
+ : key == Rml::Input::KI_END
+ ? n - 1
+ : (index + (key == Rml::Input::KI_UP ? -1 : 1) + n) % n;
+ buttons[size_t(index)]->Focus(true);
+ }
+ event.StopImmediatePropagation();
+ return true;
+ }
+ if (key == Rml::Input::KI_ESCAPE || key == Rml::Input::KI_TAB) {
+ context_open_ = false;
+ if (auto *opener = context_id_.empty() ? doc_->QuerySelector(".identity")
+ : element("object-" + context_id_))
+ opener->Focus(true);
+ dirty_ = true;
+ event.StopImmediatePropagation();
+ return true;
+ }
+ }
+ if (key == Rml::Input::KI_ESCAPE && drag_.active) {
+ desktop_cancel_drag();
+ event.StopImmediatePropagation();
+ return true;
+ }
+ if (key == Rml::Input::KI_ESCAPE && menu_ == "quit") {
+ widget_action("desktop-quit-cancel", nullptr);
+ event.StopImmediatePropagation();
+ return true;
+ }
+ if (!menu_.empty())
+ return false;
+ if (control && key == Rml::Input::KI_Z) {
+ desktop_undo();
+ event.StopImmediatePropagation();
+ return true;
+ }
+ std::string id;
+ for (auto *n = target; n && n != doc_; n = n->GetParentNode())
+ if (n->HasAttribute("data-object")) {
+ id = n->GetAttribute("data-object", "");
+ break;
+ }
+ if (key == Rml::Input::KI_APPS || (shift && key == Rml::Input::KI_F10)) {
+ const auto at = target->GetAbsoluteOffset(Rml::BoxArea::Border);
+ context_menu(id, int(at.x + 30), int(at.y + 30));
+ event.StopImmediatePropagation();
+ return true;
+ }
+ if (id.empty())
+ return false;
+ const auto &o = desktop_.at("objects").at(id);
+ const bool widget = o.at("widget"), pinned = o.at("pinned");
+ if (key == Rml::Input::KI_RETURN || key == Rml::Input::KI_SPACE) {
+ if (widget) {
+ for (const auto &d : widget_catalogue())
+ if (d.at("id") == id && !d.value("route", "").empty()) {
+ dispatch("open:" + d.at("route").get(), target);
+ break;
+ }
+ event.StopImmediatePropagation();
+ return true;
+ }
+ return false;
+ }
+ if (key == Rml::Input::KI_DELETE) {
+ if (widget && !pinned) {
+ desktop_checkpoint(desktop_);
+ desktop_["objects"][id]["visible"] = false;
+ refresh();
+ }
+ event.StopImmediatePropagation();
+ return true;
+ }
+ const int dx = key == Rml::Input::KI_LEFT ? -1
+ : key == Rml::Input::KI_RIGHT ? 1
+ : 0,
+ dy = key == Rml::Input::KI_UP ? -1
+ : key == Rml::Input::KI_DOWN ? 1
+ : 0;
+ if (!dx && !dy)
+ return false;
+ if (!pinned) {
+ auto before = desktop_;
+ const int step = desktop_.value("grid", true) ? 248 : shift ? 96 : 24;
+ if (place_desktop_object(desktop_, id, o.at("x").get() + dx * step,
+ o.at("y").get() + dy * step)) {
+ desktop_raise(id);
+ desktop_checkpoint(before);
+ focus_after_render_ = "object-" + id;
+ refresh();
+ }
+ }
+ event.StopImmediatePropagation();
+ return true;
+}
+void App::files_loaded_success() {
+ ticket_.reset();
+ reset_settings();
+ reset_news();
+ pending_selects_.clear();
+ undo_.clear();
+ undo_themes_.clear();
+ drag_ = {};
+ context_open_ = false;
+ 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_world_.reset();
+ career_view_ = Json::object();
+ rankings_view_ = Json::object();
+ statistics_view_ = Json::object();
+ statistics_trophy_ = Json::object();
+ statistics_scrolls_ = Json::object();
+ stadium_view_ = Json::object();
+ stadium_world_.reset();
+ stadium_source_ = nullptr;
+ advertising_world_.reset();
+ advertising_selected_ = -1;
+ toto_dialog_.clear();
+ amount_.reset();
+ contracts_dialog_.clear();
+ contract_draft_ = Json();
+ contracts_world_.reset();
+ bank_view_ = "entrance";
+ bank_hint_.clear();
+ balance_future_ = false;
+ report_detail_kind_.clear();
+ report_detail_player_.clear();
+ report_detail_club_.clear();
+ report_picker_.clear();
+ planning_dialog_.clear();
+ almanac_year_ = 0;
+ almanac_day_.clear();
+ almanac_match_.clear();
+ almanac_tab_ = "lineups";
+ widget_data_ = Json();
+ ticket_ = std::make_unique(*context_, *doc_, *source_, [this] {
+ focus_ticket_ = true;
+ refresh();
+ });
+ menu_.clear();
+ scene_ = "desktop";
+ quit_after_save_ = false;
+ quit_closes_app_ = false;
+ refresh();
+}
+void App::files_saved_success(bool career) {
+ if (career && quit_after_save_) {
+ finish_desktop_quit();
+ return;
+ }
+ if (career) {
+ files_revision_ = snap().revision;
+ files_desktop_base_ = desktop_;
+ files_theme_base_ = theme_;
+ files_reload(files_selected_);
+ focus_after_render_ = "files-confirm";
+ refresh();
+ return;
+ }
+ menu_.clear();
+ reset_files();
+}
+void App::finish_desktop_quit() {
+ const bool exit = quit_closes_app_;
+ quit_after_save_ = false;
+ quit_closes_app_ = false;
+ if (exit) {
+ closed_ = true;
+ return;
+ }
+ ticket_.reset();
+ source_ = std::make_unique(world_);
+ saved_desktop_ = desktop_;
+ files_loaded_success();
+ scene_ = "main";
+ menu_.clear();
+ refresh();
+}
+
+void App::persist_working_desktop() {
+ if (!source_ || scene_ != "desktop" || files_capturing_ || drag_.active ||
+ !working_desktop_initialized_ || desktop_ == working_desktop_base_)
+ return;
+ try {
+ fs::create_directories(user_dir());
+ editor::write_atomic(user_dir() / "working-desktop.json", desktop_.dump(2));
+ } catch (const std::exception &) {
+ message("Die Desktopanordnung bleibt in dieser Sitzung erhalten, konnte "
+ "aber nicht gespeichert werden.");
+ }
+ working_desktop_base_ = desktop_;
+}
+
+void App::desktop_undo() {
+ if (undo_.empty())
+ return;
+ const auto theme = undo_themes_.empty() ? theme_ : undo_themes_.back();
+ if (theme != theme_) {
+ auto preferences = ui_preferences_;
+ preferences["theme"] = theme;
+ try {
+ save_ui_preferences(ui_preferences_file(), preferences);
+ } catch (const std::exception &) {
+ message("Die Gestaltung konnte nicht wiederhergestellt werden.");
+ return;
+ }
+ ui_preferences_ = std::move(preferences);
+ theme_ = theme;
+ ui_preferences_loaded_ = true;
+ }
+ desktop_ = undo_.back();
+ undo_.pop_back();
+ if (!undo_themes_.empty())
+ undo_themes_.pop_back();
+ refresh();
+}
+
+Picture App::files_default_thumbnail() {
+ const auto key = content::sha256(snap().state.dump() + theme_);
+ if (key != files_default_key_) {
+ files_default_request_ = key;
+ files_default_pending_ = true;
+ }
+ return key == files_default_key_ ? files_default_picture_ : Picture();
+}
+void App::update_files_default_thumbnail() {
+ const auto layout = desktop_;
+ files_default_pending_ = false;
+ try {
+ desktop_ = default_desktop();
+ const auto png = files_capture_preview();
+ desktop_ = layout;
+ files_default_picture_ = renderer_.generated_png("default-desktop", png);
+ files_default_key_ = files_default_request_;
+ } catch (const std::exception &) {
+ desktop_ = layout;
+ files_default_key_ = files_default_request_;
+ files_default_picture_ = Picture();
+ files_feedback_ = "Die Standardvorschau konnte nicht aufgenommen werden.";
+ }
+}
diff --git a/src/modern/ui/widgets_screens.inc b/src/modern/ui/widgets_screens.inc
new file mode 100644
index 0000000..ab0bf0a
--- /dev/null
+++ b/src/modern/ui/widgets_screens.inc
@@ -0,0 +1,426 @@
+// SPDX-License-Identifier: GPL-3.0-only
+std::string App::widget_heading(const std::string &name, bool link) {
+ return "" + esc(name) + "" +
+ (link ? glyph("arrow-diagonal", 28) : "") + "";
+}
+std::string App::widget_curve(const std::string &id, const Json &o, int w,
+ int h) {
+ const bool compare = id == "comparison-curve",
+ square = (w == 720 || h == 968);
+ const int height = square ? 600 : 330, range = height - 76;
+ const auto accent = theme_ == "silver" ? "#235e78"
+ : theme_ == "matchday" ? "#f1a99e"
+ : "#a5e2cf";
+ const auto other = theme_ == "silver" ? "#a04b30"
+ : theme_ == "matchday" ? "#91cce8"
+ : "#f2b286";
+ const auto muted = theme_ == "silver" ? "#586d80"
+ : theme_ == "matchday" ? "#b4b5b7"
+ : "#afbfcd";
+ std::string svg =
+ "";
+ const int ch = h - (compare ? 180 : 96);
+ std::string out =
+ "" +
+ picture(renderer_.diagram("widget-" + id + "-" + std::to_string(w) + "-" +
+ std::to_string(h),
+ svg, 1600),
+ w - 42, ch) +
+ "SaisonstartHeute
";
+ if (compare)
+ out +=
+ "" +
+ esc(world_->name(*world_->find("clubs", widget_data_.at("own")))) +
+ "" +
+ esc(world_->name(*world_->find("clubs", widget_data_.at("opponent")))) +
+ "
";
+ (void)o;
+ return out;
+}
+std::string App::widget(const std::string &id, const Json &o) {
+ const auto s = snap();
+ if (!widget_data_.is_object())
+ widget_data_ = demo_desktop_widgets(*world_, s.state);
+ const auto *own = world_->find("clubs", widget_data_.at("own")),
+ *opponent = world_->find("clubs", widget_data_.at("opponent"));
+ const int w = o.at("w"), h = o.at("h");
+ const bool wide = h == 224, compact = w == 472;
+ const auto heading = [&](const std::string &name, bool link = true) {
+ return widget_heading(name, link);
+ };
+ if (id == "calendar")
+ return "" +
+ esc(widget_data_.at("month").get()) +
+ "
" +
+ esc(widget_data_.at("weekday").get()) +
+ "" +
+ std::to_string(widget_data_.at("day").get()) +
+ "" +
+ (widget_data_.at("matchday") == 0
+ ? "Saisonvorbereitung"
+ : std::to_string(widget_data_.at("matchday").get()) +
+ ". Spieltag") +
+ "
";
+ if (id == "account")
+ return heading("Vereinskasse") +
+ "Guthaben" +
+ cash(s.state.at("cash")) +
+ "
Sparbuch" +
+ cash(s.state.at("deposit")) + "
" +
+ btn("ticket",
+ glyph("ticket", 36) + "
Eintritt" +
+ std::to_string(s.state.at("ticket").get()) + " " +
+ money_unit() + " ›",
+ "desk-ticket",
+ "id=\"account-ticket\" data-interactive=\"true\"") +
+ "
";
+ if (id == "competition")
+ return heading("Nächste Begegnung") + "" +
+ crest(own, compact ? 68 : 80) + "" +
+ esc(own ? own->value("short_name", world_->name(*own)) : "") +
+ "
Freundschaftsspiel"
+ "small>19:00Heim · "
+ "Samstag
" +
+ crest(opponent, compact ? 68 : 80) + "" +
+ esc(opponent ? opponent->value("short_name", world_->name(*opponent))
+ : "") +
+ "
";
+ if (id == "portrait")
+ return img(std::string(manager(s).value("portrait_style",
+ std::string("photo")) == "painted"
+ ? "manager-painted."
+ : "manager.") +
+ std::to_string(manager(s).value("portrait", 0)),
+ w, h, false, true, 768) +
+ "Manager" +
+ esc(manager(s).value("name", "")) + "
";
+ if (id == "crest" || id == "opponent-crest") {
+ const auto *c = id == "crest" ? own : opponent;
+ return "" +
+ crest(c, std::min(int((w - 48) * .78), int((h - 138) * .9))) +
+ "
" +
+ (id == "crest" ? std::string("Dein Verein") : "Nächster Gegner") +
+ "" + esc(c ? world_->name(*c) : "") +
+ "
";
+ }
+ if (id == "warnings") {
+ const std::vector> groups =
+ wide ? std::vector>{{0}, {1}, {2}, {3, 4},
+ {5, 6}, {7}, {8}, {9}}
+ : std::vector>{{0}, {1}, {2}, {3}, {4},
+ {5}, {6}, {7}, {8}, {9}};
+ std::string out =
+ heading("Vereinsstatus", false) + "";
+ 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();
+ 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",
+ "" +
+ glyph(v.at("icon"), h == 720 ? 42 : 28) + "" +
+ (wide ? ""
+ : "" + esc(label) +
+ ""),
+ "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 + "
";
+ }
+ if (id == "fans")
+ return heading("Fan-Stimmung") + "" +
+ glyph("heart", 36) + "
" +
+ std::to_string(widget_data_.at("fans").get()) +
+ " %()) +
+ "%;\">
Zuversichtlich ";
+ if (id == "news")
+ return render_news_widget(o);
+ if (id == "own-curve" || id == "opponent-curve" || id == "comparison-curve")
+ return heading(id == "comparison-curve"
+ ? "Tabellenplätze"
+ : world_->name(*(id == "own-curve" ? own : opponent))) +
+ widget_curve(id, o, w, h);
+ if (id == "own-summary" || id == "opponent-summary") {
+ bool self = id == "own-summary";
+ return heading(world_->name(*(self ? own : opponent))) +
+ "Tabellenplatz" +
+ std::to_string(widget_data_.at(self ? "own_rank" : "opponent_rank")
+ .get()) +
+ ".
Teamstärke" +
+ std::to_string(
+ widget_data_.at(self ? "own_strength" : "opponent_strength")
+ .get()) +
+ "
";
+ }
+ if (id == "results") {
+ std::string out =
+ heading("Die letzten sechs Spiele") + "" +
+ (wide ? ""
+ : "3 Siege · 2 Unentschieden · 1 "
+ "Niederlage
");
+ }
+ if (id == "duels")
+ return heading("Direkter Vergleich") + "" +
+ crest(own, 75) +
+ "2Siege
1"
+ "strong>Unentschieden
" +
+ crest(opponent, 75) +
+ "3Siege
";
+ if (id == "trash")
+ return "" + glyph("trash", 100) +
+ "
Papierkorb";
+ return {};
+}
+std::string App::desktop_dialog(const std::string &heading,
+ const std::string &body,
+ const std::string &footer, int width,
+ int height) {
+ return "" +
+ btn("close", "×", "desktop-window-close",
+ "id=\"window-close\" aria-label=\"Schließen\"") +
+ "" + esc(heading) +
+ "
" + body +
+ "
";
+}
+std::string App::render_widget_gallery_items() {
+ std::string out;
+ int index = 0;
+ const auto query = settings_search_key(widget_query_);
+ for (const auto &d : widget_catalogue()) {
+ const auto id = d.at("id").get();
+ if (!query.empty() &&
+ settings_search_key(d.at("label").get() + " " +
+ d.at("description").get() + " " +
+ d.at("group").get())
+ .find(query) == std::string::npos)
+ continue;
+ auto preview = desktop_.at("objects").at(id);
+ const auto span = d.at("spans").at(d.at("size").get());
+ const int w = span[0].get() * 248 - 24,
+ h = span[1].get() * 248 - 24;
+ preview["w"] = w;
+ preview["h"] = h;
+ const auto factor = std::min(620. / w, 300. / h);
+ std::string dimensions;
+ for (const auto &def : widget_definitions())
+ if (def.id == id) {
+ auto chosen = widget_choices_.contains(id)
+ ? widget_choices_[id]
+ : std::pair{span[0], span[1]};
+ for (const auto &[cols, rows] : def.sizes) {
+ const auto key = std::to_string(cols) + "x" + std::to_string(rows);
+ dimensions += "";
+ }
+ }
+ auto preview_markup = widget(id, preview);
+ for (size_t at = 0;
+ (at = preview_markup.find("