Bind original settings and automation to atomic native drafts (by Codex)
This commit is contained in:
1 parent
2ce563a4b9
commit
98cff2185d
23 files changed
+959
-189
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 engine_widgets.cpp engine_indoor.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 engine_indoor.cpp engine_settings.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 widgets_projection indoor_projection)
|
||||
foreach(component career_reports rankings career_files statistics_projection toto_projection stadium_projection transfer_projection achievements_projection news_projection balance_projection widgets_projection indoor_projection settings_projection)
|
||||
add_executable(modern_${component}_tests ../../../tests/modern_${component}_tests.cpp)
|
||||
target_link_libraries(modern_${component}_tests PRIVATE bmh_modern_ui_core)
|
||||
if(MSVC)
|
||||
|
||||
@@ -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","desktop-widgets","indoor-standings"})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","indoor-standings","settings"})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;
|
||||
|
||||
@@ -74,6 +74,8 @@ Json engine_statistics_projection(const Json &bundle,const Json &read);
|
||||
|
||||
Json engine_widgets_projection(const Json &bundle);
|
||||
Json engine_indoor_projection(const Json &bundle);
|
||||
Json engine_settings_projection(const Json &bundle);
|
||||
Json engine_settings_command(const Json &bundle, const Json &draft, const std::string &request_id);
|
||||
Json engine_balance_projection(const Json &,const Json &);
|
||||
Json engine_balance_command(const Json &,const Json &,const std::string &);
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ void App::engine_accept(EngineReply result) {
|
||||
engine_news_sync();
|
||||
engine_balance_sync();
|
||||
engine_indoor_sync();
|
||||
engine_settings_sync();
|
||||
engine_contracts_poll();
|
||||
engine_calendar_sync();
|
||||
engine_friendly_sync();
|
||||
@@ -90,6 +91,7 @@ void App::engine_frame() {
|
||||
if (ticket_) ticket_->update();
|
||||
render_popup(); context_->Update();
|
||||
if(center_fixture_columns())context_->Update();
|
||||
if (menu_ == "settings") { settings_after_render(); context_->Update(); }
|
||||
if (rendered && menu_ == "friendlies") if (auto *list = element("friendly-opponents")) list->SetScrollTop(engine_friendly_scroll_);
|
||||
if (menu_ == "contracts" && engine_contract_scroll_) {
|
||||
if (auto *roster = element("contracts-roster-scroll")) roster->SetScrollTop(*engine_contract_scroll_);
|
||||
@@ -161,6 +163,10 @@ void App::engine_event(Rml::Event &event) {
|
||||
if (node->GetId() == "native-ticket-layer") return; // owned by the compact control
|
||||
if (ticket_ && ticket_->is_open()) return;
|
||||
if (amount_event(event)) return;
|
||||
if (menu_ == "settings") {
|
||||
if (engine_busy_) { event.StopImmediatePropagation(); return; }
|
||||
if (settings_event(event)) return;
|
||||
}
|
||||
if (!engine_busy_ && bank_event(event)) return;
|
||||
if (!engine_busy_ && advertising_event(event)) return;
|
||||
if (!engine_busy_ && popup_.empty() && contracts_event(event)) return;
|
||||
@@ -296,6 +302,8 @@ void App::engine_event(Rml::Event &event) {
|
||||
if(menu_=="news"&&dispatch_news(action,node))return;
|
||||
if(menu_=="balance"&&engine_balance_action(action,node))return;
|
||||
if(menu_=="indoor"&&indoor_action(action,node))return;
|
||||
if(menu_=="settings"&&settings_action(action,node))return;
|
||||
if(menu_=="settings"&&action=="close"){reset_settings();menu_.clear();refresh();return;}
|
||||
if (almanac_action(action,node)) return;
|
||||
if (engine_friendly_action(action, node)) return;
|
||||
if ((menu_ == "friendlies" || menu_ == "almanac" || menu_=="tables" || menu_=="strengths" || menu_=="league" || menu_=="other" || menu_=="scorers" || menu_=="statistics") && report_picker_action(action,node)) return;
|
||||
@@ -312,6 +320,7 @@ void App::engine_event(Rml::Event &event) {
|
||||
ticket_->open(node, device_ratio_, price.at("min"), price.at("max")); dirty_ = true;
|
||||
}
|
||||
else if (action == "engine-open" && (id == "environment" || id == "advertising")) { menu_ = id; advertising_selected_ = -1; advertising_offer_ = 0; refresh(); }
|
||||
else if(action=="engine-open"&&id=="settings"){reset_settings();menu_=id;refresh();}
|
||||
else if(action=="engine-open"&&id=="indoor"){menu_=id;engine_reports_sync();refresh();}
|
||||
else if(action=="engine-open"&&id=="balance"){menu_=id;balance_future_=false;engine_balance_feedback_="Gebuchte Saisonwerte.";refresh();}
|
||||
else if(action=="engine-open"&&id=="news"){menu_=id;news_dialog_.clear();refresh();}
|
||||
@@ -351,5 +360,5 @@ void App::engine_event(Rml::Event &event) {
|
||||
}
|
||||
Json App::engine_snapshot() const {
|
||||
return {{"mode", engine_mode_}, {"creation_busy",engine_creation_busy_}, {"busy", engine_busy_}, {"dirty", engine_dirty_}, {"fresh", engine_fresh_}, {"bundle", engine_data_},
|
||||
{"indoor_value",engine_indoor_value_},{"balance_future",engine_balance_future_},{"balance_edits",engine_balance_edits_},{"balance_view_future",balance_future_},{"news_error",engine_news_error_},{"news_value",engine_news_value_},{"news_view",news_view_},{"news_undo",engine_news_undo_},{"achievements_value",engine_mode_&&engine_data_.value("achievements",Json()).value("messageType","")=="snapshot"?achievements_data(career_view_.value("page",0)):Json()},{"career_view",career_view_},{"transfer_value",engine_transfer_value_},{"transfer_filters",engine_transfer_filters_},{"transfer_draft",transfer_draft_},{"transfer_view",transfer_view_},{"response", engine_response_}, {"stadium_view",stadium_view_},{"stadium_value",engine_stadium_value_},{"toto_value",engine_toto_value_},{"toto_draft",engine_toto_edit_},{"toto_quote",engine_toto_quote_},{"toto_feedback",engine_toto_feedback_},{"statistics_read",engine_statistics_read_},{"statistics_value",engine_statistics_value_},{"statistics_query",engine_statistics_query_},{"files_native",files_native_},{"files_busy",engine_files_busy_},{"files_current",engine_files_metadata_},{"opening_read",engine_opening_read_},{"opening_state",engine_opening_state_},{"rankings_read",engine_rankings_read_},{"rankings_state",engine_rankings_state_},{"fairplay_read",engine_fairplay_read_},{"other_index",engine_other_index_},{"other_read",engine_other_read_},{"fixtures_read",engine_fixtures_read_},{"reports_state",engine_reports_state_},{"reports_index",engine_reports_index_},{"reports_read",engine_reports_read_},{"reports_roster",engine_reports_roster_},{"almanac_cache",engine_almanac_cache_}, {"almanac_context",engine_almanac_context_}, {"friendly_quote", engine_friendly_read_}, {"friendly_league", engine_friendly_league_}, {"friendly_opponent", engine_friendly_opponent_}, {"friendly_date", engine_friendly_date_}, {"friendly_home", engine_friendly_home_}, {"friendly_stage", engine_friendly_stage_}, {"friendly_month", engine_friendly_month_}, {"calendar_day", engine_calendar_day_}, {"move_id", engine_move_id_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
{"settings_value",engine_settings_value_},{"settings_context",engine_settings_context_},{"indoor_value",engine_indoor_value_},{"balance_future",engine_balance_future_},{"balance_edits",engine_balance_edits_},{"balance_view_future",balance_future_},{"news_error",engine_news_error_},{"news_value",engine_news_value_},{"news_view",news_view_},{"news_undo",engine_news_undo_},{"achievements_value",engine_mode_&&engine_data_.value("achievements",Json()).value("messageType","")=="snapshot"?achievements_data(career_view_.value("page",0)):Json()},{"career_view",career_view_},{"transfer_value",engine_transfer_value_},{"transfer_filters",engine_transfer_filters_},{"transfer_draft",transfer_draft_},{"transfer_view",transfer_view_},{"response", engine_response_}, {"stadium_view",stadium_view_},{"stadium_value",engine_stadium_value_},{"toto_value",engine_toto_value_},{"toto_draft",engine_toto_edit_},{"toto_quote",engine_toto_quote_},{"toto_feedback",engine_toto_feedback_},{"statistics_read",engine_statistics_read_},{"statistics_value",engine_statistics_value_},{"statistics_query",engine_statistics_query_},{"files_native",files_native_},{"files_busy",engine_files_busy_},{"files_current",engine_files_metadata_},{"opening_read",engine_opening_read_},{"opening_state",engine_opening_state_},{"rankings_read",engine_rankings_read_},{"rankings_state",engine_rankings_state_},{"fairplay_read",engine_fairplay_read_},{"other_index",engine_other_index_},{"other_read",engine_other_read_},{"fixtures_read",engine_fixtures_read_},{"reports_state",engine_reports_state_},{"reports_index",engine_reports_index_},{"reports_read",engine_reports_read_},{"reports_roster",engine_reports_roster_},{"almanac_cache",engine_almanac_cache_}, {"almanac_context",engine_almanac_context_}, {"friendly_quote", engine_friendly_read_}, {"friendly_league", engine_friendly_league_}, {"friendly_opponent", engine_friendly_opponent_}, {"friendly_date", engine_friendly_date_}, {"friendly_home", engine_friendly_home_}, {"friendly_stage", engine_friendly_stage_}, {"friendly_month", engine_friendly_month_}, {"calendar_day", engine_calendar_day_}, {"move_id", engine_move_id_}, {"credit_preview", engine_credit_}, {"credit_edits", engine_credit_edits_}, {"training_draft", engine_training_draft_}, {"tactics_draft", engine_tactics_draft_}, {"player_profile", engine_player_}, {"lineup_selected", lineup_selected_}, {"focus", engine_focus_}, {"selected_camp", engine_camp_}, {"notice", engine_notice_}};
|
||||
}
|
||||
@@ -42,6 +42,7 @@ void App::engine_render() {
|
||||
if(menu_=="statistics")statistics_remember_scroll();
|
||||
fixture_half_width_=-1.f;
|
||||
almanac_list_width_=-1.f;
|
||||
if (menu_ == "settings") { settings_remember_scroll(); last_rendered_menu_ = menu_; }
|
||||
if (menu_ == "friendlies") if (auto *list = element("friendly-opponents")) engine_friendly_scroll_ = list->GetScrollTop();
|
||||
if (menu_ == "contracts") if (auto *roster = element("contracts-roster-scroll")) engine_contract_scroll_ = roster->GetScrollTop();
|
||||
if (menu_ == "lineup") {
|
||||
@@ -131,7 +132,7 @@ void App::engine_render() {
|
||||
const auto route = id.substr(4);
|
||||
const bool camp_allowed = desk.at("menuAvailability").at("camps").value("status", "") == "available";
|
||||
const auto commands = meta.at("scope").value("allowedCommands", Json::array());
|
||||
const bool supported = (route=="indoor"&&engine_fresh_&&engine_indoor_value_.is_object()) || ((route=="tables"||route=="strengths"||route=="league"||route=="other"||route=="scorers"||route=="fairplay")&&engine_fresh_&&meta.at("scope").at("role")=="club") || (route == "almanac" && engine_fresh_) || (route == "friendlies" && friendlies_available && engine_fresh_) || (route == "calendar" && calendar_available && engine_fresh_) || (route == "postpone" && scheduling_available && engine_fresh_) || (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || (route=="balance"&&engine_fresh_&&engine_data_.at("balance").value("messageType","")=="snapshot") || (route=="news"&&engine_fresh_&&engine_news_value_.is_object()) || (route=="achievements"&&engine_fresh_&&engine_data_.at("achievements").value("messageType","")=="snapshot"&&engine_data_.at("achievements").at("data").at("available")==true) || (route=="transfer"&&engine_fresh_&&engine_transfer_value_.is_object()) || (route=="stadium"&&engine_fresh_&&engine_stadium_value_.is_object()) || (route=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&engine_fresh_) || route == "save" || route == "load" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
const bool supported = (route=="settings"&&engine_fresh_&&engine_settings_value_.is_object()) || (route=="indoor"&&engine_fresh_&&engine_indoor_value_.is_object()) || ((route=="tables"||route=="strengths"||route=="league"||route=="other"||route=="scorers"||route=="fairplay")&&engine_fresh_&&meta.at("scope").at("role")=="club") || (route == "almanac" && engine_fresh_) || (route == "friendlies" && friendlies_available && engine_fresh_) || (route == "calendar" && calendar_available && engine_fresh_) || (route == "postpone" && scheduling_available && engine_fresh_) || (route == "contracts" && contracts_available && engine_fresh_) || (route == "environment" && environment_available && engine_fresh_) || (route == "advertising" && advertising_available && engine_fresh_) || (route == "bank" && bank_available && engine_fresh_) || (route == "training" && training_available && engine_fresh_) || (route == "tactics" && tactics_available && engine_fresh_) || (route == "lineup" && lineup_available && engine_fresh_) || (route=="balance"&&engine_fresh_&&engine_data_.at("balance").value("messageType","")=="snapshot") || (route=="news"&&engine_fresh_&&engine_news_value_.is_object()) || (route=="achievements"&&engine_fresh_&&engine_data_.at("achievements").value("messageType","")=="snapshot"&&engine_data_.at("achievements").at("data").at("available")==true) || (route=="transfer"&&engine_fresh_&&engine_transfer_value_.is_object()) || (route=="stadium"&&engine_fresh_&&engine_stadium_value_.is_object()) || (route=="toto"&&engine_fresh_&&engine_toto_value_.is_object()) || (route=="statistics"&&engine_fresh_) || route == "save" || route == "load" || (route == "camp" && engine_fresh_ && camp_allowed && std::find(commands.begin(), commands.end(), Json("camp.book")) != commands.end());
|
||||
out += desktop_button(id, o, "engine-open", supported && !engine_busy_);
|
||||
}
|
||||
}
|
||||
@@ -140,6 +141,7 @@ void App::engine_render() {
|
||||
if(menu_=="scorers")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Spielerstatistiken",engine_rankings_value_.is_object()?render_scorers():"<div class=\"fill center\">"+esc(engine_busy_?"Spielerstatistiken werden geladen …":engine_notice_)+"</div>")+"</div>";
|
||||
if(menu_=="fairplay")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Fairplay",engine_fairplay_value_.is_object()?render_fairplay():"<div class=\"fill center\">"+esc(engine_busy_?"Fairplay wird geladen …":engine_notice_)+"</div>")+"</div>";
|
||||
if(menu_=="other")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Übrige Spiele",engine_other_value_.is_object()?render_reports("other"):"<div class=\"fill center\">"+esc(engine_busy_?"Wettbewerbe werden geladen …":engine_other_index_.is_object()?"Keine aktiven Wettbewerbe.":engine_notice_)+"</div>")+"</div>";
|
||||
if(menu_=="settings")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Einstellungen",render_settings())+"</div>";
|
||||
if(menu_=="indoor")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Hallentabellen",render_indoor())+"</div>";
|
||||
if(menu_=="balance")out+="<div class=\"fill\" style=\"z-index:100;\">"+window("Bilanz",render_balance())+"</div>";
|
||||
if(menu_=="news")out+="<div class=\"fill\" style=\"z-index:100;\">"+render_news()+"</div>";
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#include "modern/ui/demo_settings.hpp"
|
||||
#include "modern/ui/engine_bridge.hpp"
|
||||
#include <set>
|
||||
namespace bmh::modern_ui {
|
||||
namespace {
|
||||
void require_settings(bool yes, const char *message) {
|
||||
if (!yes)
|
||||
throw editor::Error(message);
|
||||
}
|
||||
} // namespace
|
||||
Json engine_settings_projection(const Json &bundle) {
|
||||
validate_engine_desk(bundle);
|
||||
const auto &read = bundle.at("settings"),
|
||||
&meta = bundle.at("desktop").at("meta");
|
||||
require_settings(read.value("messageType", "") == "snapshot" &&
|
||||
read.at("data").value("kind", "") == "settings",
|
||||
"Einstellungen sind nicht verfügbar.");
|
||||
for (auto *key : {"contractVersion", "careerId", "worldId", "worldRevision",
|
||||
"stateRevision", "scope"})
|
||||
require_settings(read.at("meta").at(key) == meta.at(key),
|
||||
"Die Einstellungen sind veraltet.");
|
||||
const auto &data = read.at("data");
|
||||
require_settings(data.at("cells").is_array() &&
|
||||
data.at("cells").size() == 180,
|
||||
"Unvollständige Spieloptionen.");
|
||||
Json cells = Json::array(), capabilities = Json::object(),
|
||||
automation = Json::object(), auto_caps = Json::object();
|
||||
for (size_t i = 0; i < 180; ++i) {
|
||||
const auto &row = data.at("cells")[i];
|
||||
const auto code = row.at("code").get<std::string>();
|
||||
require_settings(
|
||||
settings_index(code) == int(i) && row.at("raw").is_number_integer() &&
|
||||
row.at("raw") >= 0 && row.at("raw") <= 255 &&
|
||||
row.at("displayRaw").is_number_integer() &&
|
||||
row.at("displayRaw") >= 0 && row.at("displayRaw") <= 255 &&
|
||||
row.at("editable").is_boolean(),
|
||||
"Ungültige Einstellungszelle.");
|
||||
const auto &value = row.at("value");
|
||||
require_settings(value.is_null() || (value.is_number_integer() &&
|
||||
value >= 0 && value <= 255),
|
||||
"Ungültiger Einstellungswert.");
|
||||
require_settings(row.at("min").is_number_integer() &&
|
||||
row.at("max").is_number_integer() &&
|
||||
row.at("min") >= 0 && row.at("max") >= row.at("min") &&
|
||||
row.at("max") <= 255 && row.at("step") == 1,
|
||||
"Ungültige Einstellungsgrenze.");
|
||||
if (i % 9 < 7) {
|
||||
const int binary = row.at("raw").get<int>() & 0x3f;
|
||||
require_settings(
|
||||
binary <= 1 ? value == 1 - binary : value.is_null(),
|
||||
"Die Schalterbedeutung passt nicht zu den Originalbytes.");
|
||||
}
|
||||
if (row.at("editable") == true)
|
||||
require_settings(value.is_number_integer() && value >= row.at("min") &&
|
||||
value <= row.at("max"),
|
||||
"Schreibbarer Wert außerhalb der Grenzen.");
|
||||
cells.push_back(value);
|
||||
capabilities[code] = row;
|
||||
}
|
||||
const std::set<std::string> keys{"lineup", "substitutions", "tactics",
|
||||
"marking", "training"};
|
||||
for (const auto &row : data.at("automation")) {
|
||||
const auto key = row.at("id").get<std::string>();
|
||||
require_settings(keys.contains(key) && !auto_caps.contains(key) &&
|
||||
row.at("enabled").is_boolean() &&
|
||||
row.at("editable").is_boolean(),
|
||||
"Ungültige Automatik.");
|
||||
automation[key] = row.at("enabled");
|
||||
auto_caps[key] = row;
|
||||
}
|
||||
require_settings(auto_caps.size() == 5 && data.at("formations").is_array(),
|
||||
"Unvollständige Automatik.");
|
||||
std::set<int> slots;
|
||||
for (const auto &slot : data.at("formations"))
|
||||
require_settings(slot.at("value").is_number_integer() &&
|
||||
slot.at("value") >= 1 && slot.at("value") <= 8 &&
|
||||
slots.insert(slot.at("value").get<int>()).second &&
|
||||
slot.at("label").is_string(),
|
||||
"Ungültige gespeicherte Aufstellung.");
|
||||
require_settings(data.at("formation").is_number_integer() &&
|
||||
(data.at("formation") == 0 ||
|
||||
slots.contains(data.at("formation").get<int>())),
|
||||
"Gespeicherte Aufstellung nicht verfügbar.");
|
||||
return {{"local",
|
||||
{{"version", 1},
|
||||
{"cells", cells},
|
||||
{"automation", automation},
|
||||
{"formation", data.at("formation")}}},
|
||||
{"cells", capabilities},
|
||||
{"automation", auto_caps},
|
||||
{"formations", data.at("formations")}};
|
||||
}
|
||||
Json engine_settings_command(const Json &bundle, const Json &draft,
|
||||
const std::string &request_id) {
|
||||
const auto value = engine_settings_projection(bundle),
|
||||
&base = value.at("local"), &meta = bundle.at("desktop").at("meta");
|
||||
const auto commands = meta.at("scope").at("allowedCommands");
|
||||
require_settings(!request_id.empty() &&
|
||||
std::find(commands.begin(), commands.end(),
|
||||
Json("settings.commit")) != commands.end(),
|
||||
"Einstellungsänderungen sind gesperrt.");
|
||||
require_settings(draft.at("version") == 1 && draft.at("cells").is_array() &&
|
||||
draft.at("cells").size() == 180 &&
|
||||
draft.at("automation").is_object() &&
|
||||
draft.at("automation").size() == 5,
|
||||
"Ungültiger Einstellungsentwurf.");
|
||||
Json edits = Json::array(), autos = Json::array();
|
||||
for (size_t i = 0; i < 180; ++i) {
|
||||
if (draft.at("cells")[i] == base.at("cells")[i])
|
||||
continue;
|
||||
const auto code = std::string(1, char('A' + i / 9)) + char('1' + i % 9);
|
||||
const auto &cap = value.at("cells").at(code), &v = draft.at("cells")[i];
|
||||
require_settings(cap.at("editable") == true && v.is_number_integer() &&
|
||||
v >= cap.at("min") && v <= cap.at("max"),
|
||||
"Gesperrte oder ungültige Spieloption.");
|
||||
edits.push_back({{"code", code}, {"value", v}});
|
||||
}
|
||||
for (const auto &[key, before] : base.at("automation").items()) {
|
||||
const auto &on = draft.at("automation").at(key);
|
||||
require_settings(on.is_boolean(), "Ungültige Automatik.");
|
||||
const bool slot_changed = key == "lineup" && on == true &&
|
||||
draft.at("formation") != base.at("formation");
|
||||
if (on == before && !slot_changed)
|
||||
continue;
|
||||
require_settings(value.at("automation").at(key).at("editable") == true,
|
||||
"Diese Automatik ist gesperrt.");
|
||||
Json row = {{"id", key}, {"enabled", on}};
|
||||
if (key == "lineup" && on == true) {
|
||||
require_settings(draft.at("formation").is_number_integer(),
|
||||
"Bitte eine gespeicherte Aufstellung wählen.");
|
||||
bool found = false;
|
||||
for (const auto &slot : value.at("formations"))
|
||||
found |= slot.at("value") == draft.at("formation");
|
||||
require_settings(found, "Diese Aufstellung ist nicht verfügbar.");
|
||||
row["formation"] = draft.at("formation");
|
||||
}
|
||||
autos.push_back(row);
|
||||
}
|
||||
return {{"messageType", "command"},
|
||||
{"requestId", request_id},
|
||||
{"careerId", meta.at("careerId")},
|
||||
{"expectedRevision", meta.at("stateRevision")},
|
||||
{"owner", {{"managerId", meta.at("scope").at("managerId")}}},
|
||||
{"kind", "settings.commit"},
|
||||
{"payload", {{"edits", edits}, {"automation", autos}}}};
|
||||
}
|
||||
} // namespace bmh::modern_ui
|
||||
@@ -0,0 +1,116 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
void App::engine_settings_sync() {
|
||||
engine_settings_value_ = Json();
|
||||
try {
|
||||
engine_settings_value_ = engine_settings_projection(engine_data_);
|
||||
} catch (const std::exception &) {
|
||||
}
|
||||
if (!engine_settings_committing_)
|
||||
return;
|
||||
engine_settings_committing_ = false;
|
||||
if (engine_response_.value("messageType", "") == "command_result") {
|
||||
const bool changed_global = engine_settings_global_ != ui_preferences_;
|
||||
ui_preferences_ = engine_settings_global_;
|
||||
theme_ = ui_preferences_.at("theme");
|
||||
ui_preferences_loaded_ = ui_preferences_loaded_ || changed_global;
|
||||
reset_settings();
|
||||
menu_.clear();
|
||||
} else
|
||||
settings_notice_ = engine_notice_;
|
||||
engine_settings_global_ = Json();
|
||||
}
|
||||
bool App::engine_settings_valid() const {
|
||||
try {
|
||||
if (!engine_fresh_ || engine_busy_ ||
|
||||
engine_settings_context_ != engine_data_.at("desktop").at("meta"))
|
||||
return false;
|
||||
(void)engine_settings_command(engine_data_, settings_draft_.at("local"),
|
||||
"request:settings-validation");
|
||||
return true;
|
||||
} catch (const std::exception &) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool App::engine_settings_editable(const std::string &scope,
|
||||
const std::string &key) const {
|
||||
if (!engine_mode_)
|
||||
return true;
|
||||
if (!engine_settings_value_.is_object())
|
||||
return false;
|
||||
if (scope == "cell" || scope == "number")
|
||||
return engine_settings_value_.at("cells").contains(key) &&
|
||||
engine_settings_value_.at("cells").at(key).at("editable") == true;
|
||||
if (scope == "automation")
|
||||
return engine_settings_value_.at("automation").contains(key) &&
|
||||
engine_settings_value_.at("automation").at(key).at("editable") ==
|
||||
true;
|
||||
return true;
|
||||
}
|
||||
void App::engine_settings_apply() {
|
||||
if (!settings_dirty() || !settings_valid())
|
||||
return;
|
||||
const auto command = engine_settings_command(
|
||||
engine_data_, settings_draft_.at("local"), editor::new_id("request:ui-"));
|
||||
const auto global = settings_draft_.at("global");
|
||||
const bool changed_global = global != settings_base_.at("global");
|
||||
const auto &payload = command.at("payload");
|
||||
const bool local =
|
||||
!payload.at("edits").empty() || !payload.at("automation").empty();
|
||||
if (!local) {
|
||||
try {
|
||||
if (changed_global)
|
||||
save_ui_preferences(ui_preferences_file(), global);
|
||||
} catch (const std::exception &) {
|
||||
settings_notice_ = "Die Gestaltung konnte nicht gespeichert werden.";
|
||||
settings_sync();
|
||||
return;
|
||||
}
|
||||
ui_preferences_ = global;
|
||||
theme_ = global.at("theme");
|
||||
ui_preferences_loaded_ = ui_preferences_loaded_ || changed_global;
|
||||
reset_settings();
|
||||
menu_.clear();
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
const auto file = ui_preferences_file();
|
||||
const bool had = changed_global && fs::exists(file);
|
||||
std::string previous;
|
||||
try {
|
||||
if (had)
|
||||
previous = editor::read_file(file);
|
||||
if (changed_global)
|
||||
save_ui_preferences(file, global);
|
||||
} catch (const std::exception &) {
|
||||
settings_notice_ = "Die Einstellungen konnten nicht gespeichert werden.";
|
||||
settings_sync();
|
||||
return;
|
||||
}
|
||||
auto link = engine_link_;
|
||||
engine_settings_global_ = global;
|
||||
engine_settings_committing_ = true;
|
||||
engine_start(
|
||||
"Einstellungen werden übernommen …",
|
||||
[link, command, file, had, previous, changed_global] {
|
||||
try {
|
||||
const auto response = link->command(command);
|
||||
if (changed_global &&
|
||||
response.value("messageType", "") != "command_result") {
|
||||
if (had)
|
||||
editor::write_atomic(file, previous);
|
||||
else
|
||||
fs::remove(file);
|
||||
}
|
||||
return EngineReply{link, link->snapshot(), response, nullptr};
|
||||
} catch (...) {
|
||||
if (changed_global) {
|
||||
if (had)
|
||||
editor::write_atomic(file, previous);
|
||||
else
|
||||
fs::remove(file);
|
||||
}
|
||||
throw;
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
@@ -159,3 +159,10 @@
|
||||
|
||||
Json engine_indoor_value_;
|
||||
void engine_indoor_sync();
|
||||
|
||||
Json engine_settings_value_, engine_settings_context_, engine_settings_global_;
|
||||
bool engine_settings_committing_ = false;
|
||||
void engine_settings_sync();
|
||||
void engine_settings_apply();
|
||||
bool engine_settings_valid() const;
|
||||
bool engine_settings_editable(const std::string &, const std::string &) const;
|
||||
@@ -62,12 +62,10 @@ void App::settings_sync() {
|
||||
else if (scope == "automation") {
|
||||
const auto &a = settings_draft_["local"]["automation"];
|
||||
if (key == "all") {
|
||||
int n = 0;
|
||||
for (const auto &[k, v] : a.items())
|
||||
if (v == true)
|
||||
++n;
|
||||
on = n == 5;
|
||||
mixed = n > 0 && n < 5;
|
||||
int n=0,total=0;
|
||||
for (const auto &[k,v]:a.items()) if(engine_settings_editable("automation",k)){++total;if(v==true)++n;}
|
||||
on = total > 0 && n == total;
|
||||
mixed = n > 0 && n < total;
|
||||
} else
|
||||
on = a.at(key).get<bool>();
|
||||
}
|
||||
@@ -82,6 +80,14 @@ void App::settings_sync() {
|
||||
: "5") +
|
||||
"dp");
|
||||
}
|
||||
if (engine_mode_) {
|
||||
for (const auto &[key,cap]:engine_settings_value_.at("automation").items()) if(auto *node=element("automation-"+key)) {
|
||||
if(cap.at("editable")==true)node->RemoveAttribute("disabled");else node->SetAttribute("disabled",true);
|
||||
}
|
||||
if(auto *node=element("automation-formation")) {
|
||||
if(engine_settings_editable("automation","lineup")&&settings_draft_.at("local").at("automation").at("lineup")==true)node->RemoveAttribute("disabled");else node->SetAttribute("disabled",true);
|
||||
}
|
||||
}
|
||||
for (const auto *theme : {"midnight", "silver", "matchday"})
|
||||
if (auto *button = element(std::string("settings-theme-") + theme))
|
||||
button->SetAttribute(
|
||||
@@ -184,13 +190,16 @@ bool App::settings_change(Rml::Element *target) {
|
||||
dirty_ = true;
|
||||
return true;
|
||||
}
|
||||
if (scope == "global")
|
||||
if (scope == "formation" && engine_mode_) {
|
||||
for(const auto &slot:engine_settings_value_.at("formations")) if(std::to_string(slot.at("value").get<int>())==value)settings_draft_["local"]["formation"]=slot.at("value");
|
||||
} else if (scope == "global")
|
||||
settings_draft_["global"][section][key] = value;
|
||||
else if (scope == "number" || scope == "cell") {
|
||||
const int index = settings_index(key);
|
||||
if (engine_mode_ && !engine_settings_editable("cell",key)) return true;
|
||||
if (index < 0)
|
||||
return true;
|
||||
const bool digits = !value.empty() && value.size() <= 2 &&
|
||||
const bool digits = !value.empty() && value.size() <= (engine_mode_?3u:2u) &&
|
||||
std::all_of(value.begin(), value.end(), [](char c) {
|
||||
return c >= '0' && c <= '9';
|
||||
});
|
||||
@@ -204,6 +213,7 @@ bool App::settings_change(Rml::Element *target) {
|
||||
void App::settings_commit() {
|
||||
if (!settings_dirty() || !settings_valid())
|
||||
return;
|
||||
if (engine_mode_) { engine_settings_apply(); return; }
|
||||
const bool local = !settings_global_only();
|
||||
if (local &&
|
||||
(settings_source_ != source_.get() || settings_world_ != world_ ||
|
||||
@@ -311,17 +321,17 @@ bool App::settings_action(const std::string &action, Rml::Element *target) {
|
||||
!settings_draft_["global"]["sound"][key].get<bool>();
|
||||
else if (!settings_global_only() && scope == "cell" &&
|
||||
settings_index(key) >= 0) {
|
||||
if (!engine_settings_editable("cell",key)) return true;
|
||||
auto &value =
|
||||
settings_draft_["local"]["cells"][size_t(settings_index(key))];
|
||||
value = value == 1 ? 0 : 1;
|
||||
} else if (!settings_global_only() && scope == "automation") {
|
||||
auto &a = settings_draft_["local"]["automation"];
|
||||
if (key == "all") {
|
||||
const bool on = !std::all_of(a.begin(), a.end(),
|
||||
[](const Json &v) { return v == true; });
|
||||
for (auto &[k, v] : a.items())
|
||||
v = on;
|
||||
} else if (a.contains(key))
|
||||
bool all=true;
|
||||
for(const auto &[k,v]:a.items()) if(engine_settings_editable("automation",k))all=all&&v==true;
|
||||
for(auto &[k,v]:a.items()) if(engine_settings_editable("automation",k))v=!all;
|
||||
} else if (a.contains(key) && engine_settings_editable("automation",key))
|
||||
a[key] = !a[key].get<bool>();
|
||||
}
|
||||
settings_notice_.clear();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
bool App::settings_global_only() const { return scene_ == "main" || !source_; }
|
||||
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"
|
||||
@@ -23,7 +23,11 @@ void App::begin_settings() {
|
||||
if (!settings_draft_.is_null())
|
||||
return;
|
||||
settings_draft_ = {{"global", ui_preferences_}};
|
||||
if (!settings_global_only()) {
|
||||
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;
|
||||
@@ -41,6 +45,7 @@ bool App::settings_valid() const {
|
||||
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();
|
||||
}
|
||||
@@ -92,6 +97,11 @@ std::string App::settings_option(const Json &option) const {
|
||||
const auto &value =
|
||||
settings_draft_.at("local").at("cells")[size_t(settings_index(code))];
|
||||
const auto type = option.at("type").get<std::string>();
|
||||
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", ""), "<span class=\"settings-readonly\">" + esc(shown) + "</span>");
|
||||
}
|
||||
const int maximum = engine_mode_ ? engine_settings_value_.at("cells").at(code).at("max").get<int>() : option.value("max",99);
|
||||
std::string control;
|
||||
if (type == "toggle")
|
||||
control = settings_switch(id, "cell", code, value == 1);
|
||||
@@ -110,8 +120,8 @@ std::string App::settings_option(const Json &option) const {
|
||||
"\" data-settings-scope=\"number\" data-settings-key=\"" + code +
|
||||
"\" data-settings-title=\"" +
|
||||
esc(option.at("label").get<std::string>()) + "\" data-settings-max=\"" +
|
||||
std::to_string(option.at("max").get<int>()) +
|
||||
"\" maxlength=\"2\" value=\"" +
|
||||
std::to_string(maximum) +
|
||||
"\" maxlength=\"3\" value=\"" +
|
||||
(value.is_number_integer() ? std::to_string(value.get<int>()) : "") +
|
||||
"\"/>";
|
||||
return settings_row(id, option.at("label").get<std::string>(),
|
||||
@@ -235,7 +245,12 @@ std::string App::render_settings() {
|
||||
"\" aria-pressed=\"" +
|
||||
(p.at("theme") == type ? "true" : "false") + "\"");
|
||||
}
|
||||
pane += "</div></div><div class=\"settings-group\"><h3>Bildschirm</h3>";
|
||||
pane += "</div></div>";
|
||||
if (engine_mode_) {
|
||||
int width=0,height=0; SDL_GetWindowSize(video_.window,&width,&height);
|
||||
pane += "<div class=\"settings-group\"><h3>Fenster</h3><p>" + std::to_string(width) + " × " + std::to_string(height) + " · Automatische Anpassung</p></div>";
|
||||
} else {
|
||||
pane += "<div class=\"settings-group\"><h3>Bildschirm</h3>";
|
||||
const auto pref =
|
||||
[&](const char *key, const char *label,
|
||||
const std::vector<std::pair<std::string, std::string>> &rows,
|
||||
@@ -261,7 +276,13 @@ std::string App::render_settings() {
|
||||
"</div><div class=\"settings-group\"><h3>Sprache</h3>" +
|
||||
pref("language", "Sprache", {{"de", "Deutsch"}, {"en", "Englisch"}}) +
|
||||
"</div>";
|
||||
}
|
||||
} else if (settings_category_ == "sound") {
|
||||
if (engine_mode_) {
|
||||
pane="<div class=\"settings-group\"><h3>Spielton</h3>";
|
||||
for (const auto &o:live_settings_catalogue().at("sound")) pane+=settings_option(o);
|
||||
pane+="</div>";
|
||||
} else {
|
||||
const auto &s = p.at("sound");
|
||||
pane = "<div class=\"settings-group\"><h3>Lautstärke und Effekte</h3>";
|
||||
pane += settings_row(
|
||||
@@ -288,17 +309,16 @@ std::string App::render_settings() {
|
||||
pane += settings_option(o);
|
||||
pane += "</div>";
|
||||
}
|
||||
}
|
||||
} else if (settings_category_ == "automation") {
|
||||
const auto &a = settings_draft_.at("local").at("automation");
|
||||
int on = 0;
|
||||
for (const auto &[k, v] : a.items())
|
||||
if (v == true)
|
||||
++on;
|
||||
int on = 0, total = 0;
|
||||
for (const auto &[k, v] : a.items()) if (engine_settings_editable("automation",k)) { ++total; if (v == true) ++on; }
|
||||
pane = "<div class=\"settings-automation-master\">" +
|
||||
settings_row("automation-all", "Alles automatisch",
|
||||
"Alle fünf Bereiche gemeinsam ein- oder ausschalten.",
|
||||
engine_mode_ ? "Alle verfügbaren Bereiche gemeinsam ein- oder ausschalten." : "Alle fünf Bereiche gemeinsam ein- oder ausschalten.",
|
||||
settings_switch("automation-all", "automation", "all",
|
||||
on == 5, on > 0 && on < 5)) +
|
||||
total > 0 && on == total, on > 0 && on < total)) +
|
||||
"</div><div class=\"settings-group\"><h3>Aufgaben an den Co-Trainer "
|
||||
"abgeben</h3><p class=\"settings-group-help\">Die fünf "
|
||||
"Automatikfunktionen des Originals. Änderungen werden erst mit "
|
||||
@@ -310,6 +330,12 @@ std::string App::render_settings() {
|
||||
settings_switch("automation-" + key, "automation",
|
||||
key, a.at(key).get<bool>()));
|
||||
}
|
||||
if (engine_mode_) {
|
||||
std::vector<std::pair<std::string,std::string>> choices;
|
||||
for (const auto &slot:engine_settings_value_.at("formations")) choices.emplace_back(std::to_string(slot.at("value").get<int>()),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<int>()),"formation","",""));
|
||||
}
|
||||
pane += "</div>";
|
||||
} else {
|
||||
std::vector<std::pair<std::string, std::string>> groups;
|
||||
|
||||
@@ -1553,6 +1553,7 @@ public:
|
||||
#include "modern/ui/engine_balance.inc"
|
||||
#include "modern/ui/engine_widgets.inc"
|
||||
#include "modern/ui/engine_indoor.inc"
|
||||
#include "modern/ui/engine_settings.inc"
|
||||
} // namespace
|
||||
bool is_modern_world(const fs::path &file) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user