// SPDX-License-Identifier: GPL-3.0-only bool App::settings_global_only() const { return !engine_mode_ && (scene_ == "main" || !source_); } fs::path App::ui_preferences_file() const { return config_.preferences.empty() ? (config_.userdata.empty() ? root_ / "userdata" : config_.userdata) / "modern-ui-preferences.json" : config_.preferences; } void App::reset_settings() { settings_draft_ = Json(); settings_base_ = Json(); settings_notice_.clear(); settings_query_.clear(); settings_jump_ = "rules"; settings_category_ = "display"; settings_scrolls_ = Json::object(); settings_restore_scroll_ = false; settings_rendered_category_.clear(); settings_world_.reset(); settings_source_ = nullptr; settings_revision_ = 0; } void App::begin_settings() { if (!settings_draft_.is_null()) return; settings_draft_ = {{"global", ui_preferences_}}; if (engine_mode_) { settings_draft_["local"] = engine_settings_value_.at("local"); engine_settings_context_ = engine_data_.at("desktop").at("meta"); settings_world_ = world_; } else if (!settings_global_only()) { const auto s = snap(); settings_draft_["local"] = s.state.at("settings"); settings_revision_ = s.revision; settings_world_ = s.world; settings_source_ = source_.get(); } settings_base_ = settings_draft_; } bool App::settings_dirty() const { return settings_draft_.is_object() && settings_draft_ != settings_base_; } bool App::settings_valid() const { if (!settings_draft_.is_object() || !valid_ui_preferences(settings_draft_.at("global"))) return false; if (settings_global_only()) return true; if (engine_mode_) return engine_settings_valid(); auto copy = snap().state; return edit_demo_settings(copy, settings_draft_.at("local")).empty(); } std::string App::settings_row(const std::string &id, const std::string &label, const std::string &help, const std::string &control) const { return "
" + control + "
"; } std::string App::settings_switch(const std::string &id, const std::string &scope, const std::string &key, bool on, bool mixed) const { return btn("settings-toggle", "", "settings-switch " + std::string(on ? "checked " : "") + (mixed ? "mixed" : ""), "id=\"" + esc(id) + "\" role=\"switch\" aria-checked=\"" + (mixed ? "mixed" : on ? "true" : "false") + "\" data-scope=\"" + scope + "\" data-key=\"" + key + "\""); } std::string App::settings_select( const std::string &id, const std::vector> &rows, const std::string &value, const std::string &scope, const std::string §ion, const std::string &key) const { std::string out = ""; } std::string App::settings_option(const Json &option) const { const auto code = option.at("code").get(), id = "game-setting-" + code; const auto &value = settings_draft_.at("local").at("cells")[size_t(settings_index(code))]; const auto type = option.at("type").get(); if (engine_mode_ && !engine_settings_editable("cell", code)) { const auto shown = value.is_number_integer() ? (type == "toggle" ? (value == 1 ? std::string("An") : std::string("Aus")) : number(value)) : std::string("—"); return settings_row(id, option.at("label"), option.value("help", ""), "" + esc(shown) + ""); } const int maximum = engine_mode_ ? engine_settings_value_.at("cells").at(code).at("max").get() : option.value("max",99); std::string control; if (type == "toggle") control = settings_switch(id, "cell", code, value == 1); else if (type == "choice") { std::vector> rows; for (const auto &choice : option.at("choices")) rows.emplace_back(std::to_string(choice[0].get()), choice[1].get()); control = settings_select( id, rows, value.is_number_integer() ? std::to_string(value.get()) : "", "cell", "", code); } else control = "()) + "\" data-settings-max=\"" + std::to_string(maximum) + "\" maxlength=\"3\" value=\"" + (value.is_number_integer() ? std::to_string(value.get()) : "") + "\"/>"; return settings_row(id, option.at("label").get(), option.value("help", ""), control); } std::string App::render_settings_groups(int *count) const { std::istringstream words(settings_search_key(settings_query_)); std::vector terms; for (std::string word; words >> word;) terms.push_back(word); int found = 0; std::string out; for (const auto &group : live_settings_catalogue().at("groups")) { std::string rows; const auto matches = [&](const Json &o, const std::string &competition) { const auto text = settings_search_key( group.at("title").get() + " " + competition + " " + o.at("label").get() + " " + o.value("help", "")); return std::all_of(terms.begin(), terms.end(), [&](const auto &w) { return text.find(w) != text.npos; }); }; if (group.contains("options")) { for (const auto &o : group.at("options")) if (matches(o, "")) { rows += settings_option(o); ++found; } } else for (const auto &competition : group.at("competitions")) { std::string entries; for (const auto &o : competition.at("options")) if (matches(o, competition.at("title").get())) { entries += settings_option(o); ++found; } if (!entries.empty()) rows += "

" + esc(competition.at("title").get()) + "

" + entries + "
"; } if (!rows.empty()) out += "
() + "\" class=\"settings-group\">

" + esc(group.at("title").get()) + "

" + (group.contains("help") ? "

" + esc(group.at("help").get()) + "

" : "") + rows + "
"; } if (count) *count = found; if (!found) out = "

Keine Einstellungen " "gefunden.Versuche einen anderen " "Suchbegriff.

"; return out; } std::string App::render_settings() { begin_settings(); settings_remember_scroll(); const auto &p = settings_draft_.at("global"); std::string nav, pane; const std::array, 4> categories{ {{"display", "Anzeige"}, {"sound", "Sound"}, {"game", "Spiel"}, {"automation", "Automatik"}}}; for (const auto &[id, label] : categories) if (!settings_global_only() || std::string(id) == "display" || std::string(id) == "sound") nav += btn("settings-category", "" + std::string(label) + "", settings_category_ == id ? "active" : "", "id=\"settings-tab-" + std::string(id) + "\" role=\"tab\" aria-selected=\"" + (settings_category_ == id ? "true" : "false") + "\" data-id=\"" + id + "\""); const std::map> captions = { {"display", {"Anzeige", "Bildschirm und Sprache"}}, {"sound", {"Sound", "Lautstärke, Effekte und Spielton"}}, {"game", {"Spiel", "Spielablauf und Live-Ticker"}}, {"automation", {"Automatik", "Aufstellung, Wechsel, Taktik, Manndeckung und Training"}}}; std::string head = "

" + captions.at(settings_category_).first + "

" + captions.at(settings_category_).second + "

"; if(settings_category_=="display")head+="Live-Ticker · feste Darstellungsart"; if (settings_category_ == "display") { pane = "

Gestaltung

Wähle deinen Look. Die Gestaltung wird " "mit „Anwenden“ übernommen.

"; const std::array, 3> themes{ {{{"midnight", "Midnight Glass", "Dunkles Glas · ruhige Blautöne · Mint"}}, {{"silver", "Silver Glass", "Helles Glas · klare Schrift · Silberblau"}}, {{"matchday", "Matchday", "Graphit · klare Flächen · Vereinsrot"}}}}; for (const auto &t : themes) { const std::string type = t[0]; const auto mini = "
" + img("background", 647.333333, 404.583333, false, true, 650) + "
"; pane += btn("settings-theme", mini + "" + t[1] + "" + t[2] + "", "settings-theme-choice", "id=\"settings-theme-" + type + "\" data-id=\"" + type + "\" aria-pressed=\"" + (p.at("theme") == type ? "true" : "false") + "\""); } pane += "
"; if (engine_mode_) { int width=0,height=0; SDL_GetWindowSize(video_.window,&width,&height); pane += "

Fenster

" + std::to_string(width) + " × " + std::to_string(height) + " · Automatische Anpassung

"; } else { pane += "

Bildschirm

"; const auto pref = [&](const char *key, const char *label, const std::vector> &rows, const char *help = "") { return settings_row( std::string("preference-") + key, label, help, settings_select(std::string("preference-") + key, rows, p.at("display").at(key).get(), "global", "display", key)); }; pane += pref("mode", "Modus", {{"fullscreen", "Vollbild"}, {"window", "Fenster"}}); pane += pref("resolution", "Auflösung", {{"1280x720", "1280 × 720"}, {"1600x900", "1600 × 900"}, {"1920x1080", "1920 × 1080"}, {"2560x1440", "2560 × 1440"}, {"3840x2160", "3840 × 2160"}}, "Beispielauflösungen für den POC."); pane += pref("scale", "Skalierung", {{"auto", "Auto"}, {"1", "1×"}, {"1.5", "1,5×"}, {"2", "2×"}}) + "

Sprache

" + pref("language", "Sprache", {{"de", "Deutsch"}, {"en", "Englisch"}}) + "
"; } } else if (settings_category_ == "sound") { if (engine_mode_) { pane="

Spielton

"; for (const auto &o:live_settings_catalogue().at("sound")) pane+=settings_option(o); pane+="
"; } else { const auto &s = p.at("sound"); pane = "

Lautstärke und Effekte

"; pane += settings_row( "preference-volume", "Lautstärke", "", "
()) + "\"/>" + std::to_string(s.at("volume").get()) + " %
"); pane += settings_row("preference-effects", "Effekte", "", settings_switch("preference-effects", "sound", "effects", s.at("effects").get())); pane += settings_row("preference-style", "Effektstil", "", settings_select( "preference-style", {{"classic", "Klassisch"}, {"modern", "Modern"}}, s.at("style").get(), "global", "sound", "style")) + "
"; if (!settings_global_only()) { pane += "

Ton im Spiel

"; for (const auto &o : live_settings_catalogue().at("sound")) pane += settings_option(o); pane += "
"; } } } else if (settings_category_ == "automation") { const auto &a = settings_draft_.at("local").at("automation"); int on = 0, total = 0; for (const auto &[k, v] : a.items()) if (engine_settings_editable("automation",k)) { ++total; if (v == true) ++on; } pane = "
" + settings_row("automation-all", "Alles automatisch", engine_mode_ ? "Alle verfügbaren Bereiche gemeinsam ein- oder ausschalten." : "Alle fünf Bereiche gemeinsam ein- oder ausschalten.", settings_switch("automation-all", "automation", "all", total > 0 && on == total, on > 0 && on < total)) + "

Aufgaben an den Co-Trainer " "abgeben

Die fünf " "Automatikfunktionen des Originals. Änderungen werden erst mit " "„Anwenden“ übernommen.

"; for (const auto &o : live_settings_catalogue().at("automation")) { const auto key = o[0].get(); pane += settings_row("automation-" + key, o[1].get(), o[2].get(), settings_switch("automation-" + key, "automation", key, a.at(key).get())); } if (engine_mode_) { std::vector> choices; for (const auto &slot:engine_settings_value_.at("formations")) choices.emplace_back(std::to_string(slot.at("value").get()),slot.at("label")); if (choices.empty()) choices.emplace_back("0","Keine gespeicherte Aufstellung"); pane += settings_row("automation-formation","Gespeicherte Aufstellung","Für die automatische Aufstellung.",settings_select("automation-formation",choices,std::to_string(settings_draft_.at("local").at("formation").get()),"formation","","")); } pane += "
"; } else { std::vector> groups; for (const auto &g : live_settings_catalogue().at("groups")) groups.emplace_back(g.at("id").get(), g.at("title").get()); head += "
Zum Abschnitt" + settings_select("settings-jump", groups, settings_jump_, "jump", "", "") + "
"; pane = "
" + render_settings_groups() + "
"; } const std::string search = settings_category_ == "game" ? "
" + glyph("search", 30) + "" + btn("settings-search-clear", "×", "", "id=\"settings-search-clear\" aria-label=\"Suche " "leeren\"") + "
" : ""; settings_restore_scroll_ = true; return "
" + head + "
" + search + "
" + pane + "

" + btn("settings-cancel", "Abbrechen", "", "id=\"settings-cancel\"") + btn("settings-apply", "Anwenden", "", "id=\"settings-apply\"") + "
"; }