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
@@ -4643,6 +4643,8 @@ bool ModernSession::acknowledge_mailbox_close(const ui::MailboxCloseRequest& req
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "modern/app/settings_write.inc"
|
||||
|
||||
bool ModernSession::dispatch_settings(const ui::SettingsWriteRequest& request, uint64_t& revision,
|
||||
std::string& error) {
|
||||
if ((live_settings_owner_ && !live_settings_dispatch_active_) ||
|
||||
@@ -4652,159 +4654,11 @@ bool ModernSession::dispatch_settings(const ui::SettingsWriteRequest& request, u
|
||||
}
|
||||
if (balance_draft_ || balance_dispatch_active_ || strengths_owner_ || strengths_dispatch_active_ ||
|
||||
top_scorers_owner_ || top_scorers_dispatch_active_ || stadium_.block_expansion || other_games_owner_ || other_games_dispatch_active_) { error = "strengths_active"; return false; }
|
||||
auto& mem = g_.memory;
|
||||
if (request.manager_slot < 0 || request.manager_slot > 3 ||
|
||||
size_t(request.manager_slot) >= g_.manager_teams.size() || !mem.has(::bmh::layout::ActiveManager) ||
|
||||
int(mem.u8(::bmh::layout::ActiveManager)) != request.manager_slot || request.revision != revision ||
|
||||
revision == std::numeric_limits<uint64_t>::max()) {
|
||||
error = "Diese Einstellungsaktion gehört zu einem veralteten Manager oder Stand.";
|
||||
return false;
|
||||
}
|
||||
if (request.row >= 20 || request.column >= 9 || !mem.has(::bmh::layout::LeaguePresentationOptions + 179) ||
|
||||
!mem.has(::bmh::layout::GameMode) || !mem.has(::bmh::layout::CompetitionSelection)) {
|
||||
error = "Der Einstellungszustand ist unvollständig.";
|
||||
return false;
|
||||
}
|
||||
std::array<uint8_t, 180> raw{};
|
||||
for (size_t i = 0; i < raw.size(); ++i) {
|
||||
const uint32_t address = ::bmh::layout::LeaguePresentationOptions + uint32_t(i);
|
||||
if (!mem.has(address)) { error = "Der Einstellungszustand ist unvollständig."; return false; }
|
||||
raw[i] = mem.u8(address);
|
||||
}
|
||||
if (raw != request.expected_raw) {
|
||||
error = "Die Einstellungen wurden inzwischen geändert.";
|
||||
return false;
|
||||
}
|
||||
const size_t index = size_t(request.row) * 9 + request.column;
|
||||
const uint32_t address = ::bmh::layout::LeaguePresentationOptions + uint32_t(index);
|
||||
ui::SettingsAvailabilityInputs inputs{mem.u8(::bmh::layout::GameMode), mem.u32(::bmh::layout::CompetitionSelection),
|
||||
uint8_t(sound_capabilities_ && !sound_capabilities_->music),
|
||||
uint8_t(sound_capabilities_ && !sound_capabilities_->effects)};
|
||||
auto availability = ui::project_settings_availability(raw, inputs, exe_);
|
||||
// The host supplies the portable sound driver's capabilities. Headless
|
||||
// callers without that provider retain the unknown Source latch boundary.
|
||||
if (!sound_capabilities_) { availability[5] = raw[5]; availability[6] = raw[6]; }
|
||||
const bool sound_cell = request.row == 0 && (request.column == 5 || request.column == 6);
|
||||
if (sound_cell && !sound_capabilities_) {
|
||||
error = "Diese Einstellung ist noch nicht verfügbar.";
|
||||
return false;
|
||||
}
|
||||
const bool scoped_settings = (live_settings_owner_.has_value() && live_settings_dispatch_active_) ||
|
||||
const bool scoped = (live_settings_owner_.has_value() && live_settings_dispatch_active_) ||
|
||||
(desk_settings_owner_.has_value() && desk_settings_dispatch_active_);
|
||||
if (((request.row == 8 && request.column == 7) && !scoped_settings) ||
|
||||
(request.column == 7 && request.row >= 14 && request.row <= 19)) {
|
||||
error = "Diese Einstellung ist noch nicht verfügbar.";
|
||||
return false;
|
||||
}
|
||||
if ((request.operation != ui::SettingsEdit::toggle_binary &&
|
||||
request.operation != ui::SettingsEdit::decrement && request.operation != ui::SettingsEdit::increment) ||
|
||||
(request.column < 7 && request.operation != ui::SettingsEdit::toggle_binary) ||
|
||||
(request.column >= 7 && request.operation == ui::SettingsEdit::toggle_binary)) {
|
||||
error = "Die Aktion passt nicht zum Einstellungsfeld.";
|
||||
return false;
|
||||
}
|
||||
const uint8_t shown = availability[index];
|
||||
const uint8_t raw_value = sound_cell && sound_capabilities_ ? uint8_t(raw[index] & 0x7f) : raw[index];
|
||||
if (request.column < 7 && ((shown & 0x80) || raw_value >= 2)) {
|
||||
error = "Dieses Einstellungsfeld ist im aktuellen Modus gesperrt.";
|
||||
return false;
|
||||
}
|
||||
const uint8_t old = raw_value;
|
||||
uint8_t next = old;
|
||||
if (request.operation == ui::SettingsEdit::toggle_binary) {
|
||||
// Inventory of actual current consumers: direct match-engine buttons,
|
||||
// matchday/season flags and the live-scene switch. Other cells are not
|
||||
// made writable merely because the Original UI displayed a cell.
|
||||
// Tie the write whitelist to the concrete consumer ranges. League
|
||||
// remapping reads rows 0..4, columns 0..3; matchday display kinds 1/2
|
||||
// map to columns 0..2 and rows 0..4 or 17..19.
|
||||
const bool consumed = (sound_cell && sound_capabilities_.has_value()) ||
|
||||
(request.row == 0 && request.column == 4) || // A5: match/Sportschau sound
|
||||
((request.row <= 4 && request.column <= 3) ||
|
||||
((request.row <= 4 || request.row >= 17) && request.column <= 2)) ||
|
||||
((request.row == 5 || (request.row >= 9 && request.row <= 12)) && request.column == 0) ||
|
||||
(request.row == 1 && request.column == 4) || // B5 live-scene option
|
||||
(request.row == 2 && request.column == 4) || // C5: Reality player numbers (RealityMatch_FormatError_ExecutableField)
|
||||
(request.row == 5 && request.column == 5) || // F6: Source manager-match desk gate (MatchdaySetup_MatchdayNeedsManagerDesks_RuntimeField)
|
||||
(request.row == 6 && request.column == 5) || // G6: transfer confirmation wait (OutcomeDelayDisabled)
|
||||
(request.row == 16 && request.column == 6) || // Q7: own-club Sportschau preference (MatchdaySetup_ConsiderSportschauFixture_RuntimeField)
|
||||
(request.row == 13 && request.column == 6) || // N7: Source kickoff competition list (SportschauAwards_MatchdayIntroView_RuntimeField)
|
||||
(request.row == 1 && request.column == 6) || // B7: SportschauIntro intro gate (Controller_FormatError_RuntimeField)
|
||||
(request.row == 2 && request.column == 6) || // C7: SportschauIntro intro-animation gate (Controller_FormatError_RuntimeField2)
|
||||
(request.row == 3 && request.column == 6) || // D7: selected report progression (ReplayProgressionMode)
|
||||
(request.row == 4 && request.column == 6) || // E7: Source-owned Sportschau scenes (ReplayChanceMode)
|
||||
(request.row == 5 && request.column == 6) || // F7: SportschauIntro fixture-report gate (Controller_FormatError_RuntimeField3)
|
||||
(request.row == 6 && request.column == 6) || // G7: MatchdayIntro player/award rating (SportschauAwards_FinishSportschauAwards_RuntimeField)
|
||||
(request.row == 7 && request.column == 6) || // H7: SportschauTeamInfo competition totals (SportschauAwards_SportschauTeamInfoView_RuntimeField)
|
||||
(request.row == 2 && request.column == 5) || // C6 drawer-handle behavior (CareerSession_DispatchDesktopLayout_RuntimeField)
|
||||
(request.row == 3 && request.column == 5) || // D6 native desktop drag raster (CareerSession_DispatchDesktopLayout_RuntimeField2)
|
||||
(request.row == 4 && request.column == 5) || // E6 always-visible shortcut bar (DeskState_FormatError_RuntimeField3)
|
||||
(request.row == 7 && request.column == 5) || // H6 transfer option
|
||||
(request.row == 8 && (request.column == 5 || request.column == 6)) || // I6/I7
|
||||
(request.row >= 10 && request.row <= 13 && request.column == 4) || // K5:N5 match buttons
|
||||
(request.row >= 10 && request.row <= 12 && request.column == 6) || // K7:M7 presentation
|
||||
(request.row == 9 && request.column == 6) || // J7 season-entrant visibility (SeasonEntrants_SeasonEntrantsFromGame_TextPointer)
|
||||
(request.row == 15 && request.column == 4) || // P5
|
||||
(request.row == 16 && request.column == 4) || // Q5
|
||||
(request.row == 17 && request.column == 4); // R5: secondary leagues (CalendarState_FormatError_RuntimeField2)
|
||||
if (!consumed || (old != 0 && old != 1)) {
|
||||
error = "Diese Einstellung ist noch nicht verfügbar.";
|
||||
return false;
|
||||
}
|
||||
if (request.row == 16 && request.column == 4 &&
|
||||
g_.season_day() >= 110 && g_.season_day() <= 230) {
|
||||
error = ui::original_to_utf8(message_text(g_, ::bmh::layout::CareerSession_DispatchSettings_TextPointer));
|
||||
return false;
|
||||
}
|
||||
// SettingsSourceRefusal only permits re-enabling R5 while CareerSessionRuntimeField4 is zero.
|
||||
// LeagueRoundCounters is the saved league_rounds block; CareerSessionRuntimeField4 is its sixth byte.
|
||||
// Turning the leagues off remains possible after they have started.
|
||||
if (request.row == 17 && request.column == 4 && old != 0 &&
|
||||
(g_.league_rounds.size() <= 5 || g_.league_rounds[5] != 0)) {
|
||||
error = ui::original_to_utf8(message_text(g_, ::bmh::layout::CareerSession_DispatchSettings_TextPointer2));
|
||||
return false;
|
||||
}
|
||||
next = old ^ 1;
|
||||
} else {
|
||||
// Column8: existing presentation speeds B8:F8, H8 process budget,
|
||||
// J8 postponed limit and K8 autosave. Column9 only exposes values
|
||||
// already read by Main's Source live presenters or CupDrawScreen.
|
||||
const bool consumed = (request.column == 7 &&
|
||||
((request.row <= 6) || request.row == 7 || request.row == 9 || request.row == 10 ||
|
||||
(scoped_settings && request.row == 8))) ||
|
||||
// A9 match minutes; B9:C9 chance result; D9:E9 bookings; F9:G9 rolling ball;
|
||||
// I9 cup draw; K9 Reality report; M9 preview/shootout; P9 shot.
|
||||
(request.column == 8 && ((request.row >= 0 && request.row <= 6) ||
|
||||
request.row == 7 || request.row == 8 || request.row == 10 || request.row == 12 || request.row == 15));
|
||||
if (!consumed || old >= 200) {
|
||||
error = "Diese Einstellung ist noch nicht verfügbar.";
|
||||
return false;
|
||||
}
|
||||
if (request.column == 8) {
|
||||
// SettingsSourceRefusal's ninth column is stored doubled for display. Its
|
||||
// Source edit step is two raw units; decrement is enabled only
|
||||
// above 1 and increment only below 0xc6 (198). Preserve odd raw
|
||||
// values exactly, as the original does.
|
||||
if (request.operation == ui::SettingsEdit::decrement) {
|
||||
if (old <= 1) { error = "Der Zahlenwert ist bereits am Originalminimum."; return false; }
|
||||
next = uint8_t(old - 2);
|
||||
} else {
|
||||
if (old >= 198) { error = "Der Zahlenwert ist bereits am Originalmaximum."; return false; }
|
||||
next = uint8_t(old + 2);
|
||||
}
|
||||
} else if (request.column == 7) {
|
||||
if (request.operation == ui::SettingsEdit::decrement) {
|
||||
if (old == 0) { error = "Der Zahlenwert ist bereits am Originalminimum."; return false; }
|
||||
next = uint8_t(old - 1);
|
||||
} else {
|
||||
const uint8_t limit = exe_.u8(::bmh::layout::CareerSession_DispatchSettings_RuntimeField + request.row);
|
||||
if (old >= limit) { error = "Der Zahlenwert ist bereits am Originalmaximum."; return false; }
|
||||
next = uint8_t(old + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (next == old) { error = "Die Einstellung hat sich nicht geändert."; return false; }
|
||||
mem.set8(address, next);
|
||||
const auto next = settings_next_value(g_, exe_, sound_capabilities_, request, revision, scoped, error);
|
||||
if (!next) return false;
|
||||
g_.memory.set8(::bmh::layout::LeaguePresentationOptions + uint32_t(request.row) * 9 + request.column, *next);
|
||||
++revision;
|
||||
return true;
|
||||
}
|
||||
@@ -8777,6 +8631,7 @@ std::string ui_text(const cli::Json& j, const char* key) {
|
||||
}
|
||||
|
||||
#include "modern/app/ui_balance.inc"
|
||||
#include "modern/app/ui_settings.inc"
|
||||
|
||||
// The original mailbox of a manager, each message with an id that stays the same while the
|
||||
// mailbox shifts its entries (the entry index does not): "message:<day>-<text hash>", "-<n>"
|
||||
@@ -8985,6 +8840,18 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
|
||||
context.career_ended = career_complete();
|
||||
const std::string kind = ui_text(request, "kind"), request_id = ui_text(request, "requestId");
|
||||
const int manager = context.manager;
|
||||
if (kind == "settings") {
|
||||
if (manager < 0 || manager > 3 || size_t(manager) >= g_.manager_teams.size())
|
||||
return modern::ui_error(request_id, "no_manager", "Kein aktiver Manager.", revision, false);
|
||||
if (const auto wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager))
|
||||
return modern::ui_error(request_id, "manager_not_active", "Dieser Manager sitzt nicht am Schreibtisch.", revision, false);
|
||||
DeskSettingIdentity identity{manager, g_.manager_teams[size_t(manager)], std::nullopt, revision};
|
||||
if (identity.runtime_club >= 0 && size_t(identity.runtime_club) < g_.club_ids.size()) identity.stable_club_identity = int(g_.club_ids[size_t(identity.runtime_club)]);
|
||||
std::string error;
|
||||
const bool automation_available = validate_desk_setting_owner(identity, revision, error);
|
||||
try { return modern::ui_snapshot(g_, context, request_id, ui_settings_data(g_, exe_, sound_capabilities_, manager, revision, automation_available)); }
|
||||
catch (const std::exception &e) { return modern::ui_error(request_id, "settings_unavailable", e.what(), revision, false); }
|
||||
}
|
||||
if (kind == "indoor-standings") {
|
||||
if (manager < 0 || manager > 3 || size_t(manager) >= g_.manager_teams.size() ||
|
||||
g_.manager_teams[size_t(manager)] < 0 || g_.manager_teams[size_t(manager)] >= league_clubs())
|
||||
@@ -10697,6 +10564,62 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
|
||||
if (!dispatch_ticket_price(r, revision, error)) { restore(); return refuse("ticket_refused", error); }
|
||||
if (revision != previous) revision = previous + 1;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"stadium"}, "Eintrittspreis gesetzt.");
|
||||
} else if (kind == "settings.commit") {
|
||||
if (transfer_offer_editor_ || contract_quote_ || stadium_.block_expansion || desk_settings_owner_ || live_settings_owner_)
|
||||
return refuse("decision_pending", "Bitte die offene Entscheidung zuerst abschließen.");
|
||||
try {
|
||||
const auto *edits = ui_field(*payload, "edits"), *automation = ui_field(*payload, "automation");
|
||||
if ((edits && (!edits->array() || edits->array()->size() > 180)) ||
|
||||
(automation && (!automation->array() || automation->array()->size() > 5)))
|
||||
return refuse("invalid_payload", "Ungültige Einstellungsänderungen.");
|
||||
std::set<int> seen;
|
||||
if (edits) for (const auto &edit : *edits->array()) {
|
||||
const auto code = ui_text(edit, "code");
|
||||
const auto *value = ui_field(edit, "value");
|
||||
const int index = ui_setting_index(code);
|
||||
if (index < 0 || !seen.insert(index).second || !value || !value->integer() || *value->integer() < 0 || *value->integer() > 255)
|
||||
throw FormatError("invalid_setting_edit");
|
||||
const auto address = ::bmh::layout::LeaguePresentationOptions + uint32_t(index);
|
||||
const int old = g_.memory.u8(address), column = index % 9;
|
||||
if (column < 7 && ((old & 0x3f) > 1 || *value->integer() > 1)) throw FormatError("setting_not_boolean");
|
||||
const int target = column < 7 ? 1 - int(*value->integer()) : int(*value->integer()) * (column == 8 ? 2 : 1) + (column == 8 ? old % 2 : 0);
|
||||
if (target > 255) throw FormatError("invalid_setting_value");
|
||||
if (column < 7 && (old & 0x3f) == target) continue; // No-op preserves availability flags.
|
||||
for (int count = 0; g_.memory.u8(address) != target; ++count) {
|
||||
if (count >= 200) throw FormatError("setting_step_limit");
|
||||
ui::SettingsWriteRequest write;
|
||||
write.manager_slot = manager; write.revision = revision;
|
||||
write.row = uint8_t(index / 9); write.column = uint8_t(column);
|
||||
for (size_t i = 0; i < write.expected_raw.size(); ++i) write.expected_raw[i] = g_.memory.u8(::bmh::layout::LeaguePresentationOptions + uint32_t(i));
|
||||
write.operation = column < 7 ? ui::SettingsEdit::toggle_binary : g_.memory.u8(address) < target ? ui::SettingsEdit::increment : ui::SettingsEdit::decrement;
|
||||
if (!dispatch_settings(write, revision, error)) throw FormatError(error);
|
||||
}
|
||||
}
|
||||
seen.clear();
|
||||
if (automation) for (const auto &edit : *automation->array()) {
|
||||
const auto id = ui_text(edit, "id");
|
||||
const int index = ui_automation_index(id);
|
||||
const auto *enabled = ui_field(edit, "enabled");
|
||||
if (index < 0 || !seen.insert(index).second || !enabled || !std::holds_alternative<bool>(enabled->value)) throw FormatError("invalid_automation_edit");
|
||||
AutomationRequest write;
|
||||
write.identity = {manager, g_.manager_teams[size_t(manager)], std::nullopt, revision};
|
||||
if (write.identity.runtime_club >= 0 && size_t(write.identity.runtime_club) < g_.club_ids.size()) write.identity.stable_club_identity = int(g_.club_ids[size_t(write.identity.runtime_club)]);
|
||||
write.automation = DeskAutomation(index); write.enabled = std::get<bool>(enabled->value);
|
||||
if (const auto *formation = ui_field(edit, "formation")) {
|
||||
if (!formation->integer() || *formation->integer() < 1 || *formation->integer() > 8) throw FormatError("invalid_formation");
|
||||
write.formation = int(*formation->integer());
|
||||
}
|
||||
if (index == 0 && write.enabled != write.formation.has_value()) throw FormatError("formation_selection_required");
|
||||
if (index != 0 && write.formation) throw FormatError("unexpected_formation");
|
||||
const int current = g_.manager_options.at(size_t(manager) * 5 + size_t(index));
|
||||
if (index == 0 ? current == write.formation.value_or(0) : bool(current & 1) == write.enabled) continue;
|
||||
if (!dispatch_automation(write, revision, error)) throw FormatError(error);
|
||||
}
|
||||
const bool changed = revision != previous;
|
||||
revision = changed ? previous + 1 : previous;
|
||||
answer = modern::ui_command_result(request_id, previous, revision, {"settings", "desktop", "training", "lineup", "tactics"}, changed ? "Einstellungen übernommen." : "Einstellungen unverändert.");
|
||||
if (!changed) std::get<cli::Json::Object>(answer.value)["outcome"] = "no_change";
|
||||
} catch (const std::exception &e) { restore(); return refuse("settings_refused", e.what()); }
|
||||
} else if (kind == "balance.commit") {
|
||||
if (balance_active() || transfer_offer_editor_ || contract_quote_ || stadium_.block_expansion)
|
||||
return refuse("decision_pending", "Bitte die offene Entscheidung zuerst abschließen.");
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// One source of truth for existing settings validation and read-only capability
|
||||
// probes.
|
||||
namespace {
|
||||
std::optional<uint8_t>
|
||||
settings_next_value(const ModernState &state, const LeImage &exe,
|
||||
std::optional<ui::SettingsSoundCapabilities> sound,
|
||||
const ui::SettingsWriteRequest &request, uint64_t revision,
|
||||
bool scoped_settings, std::string &error) {
|
||||
const auto &mem = state.memory;
|
||||
if (request.manager_slot < 0 || request.manager_slot > 3 ||
|
||||
size_t(request.manager_slot) >= state.manager_teams.size() ||
|
||||
!mem.has(::bmh::layout::ActiveManager) ||
|
||||
int(mem.u8(::bmh::layout::ActiveManager)) != request.manager_slot ||
|
||||
request.revision != revision ||
|
||||
revision == std::numeric_limits<uint64_t>::max()) {
|
||||
error = "Diese Einstellungsaktion gehört zu einem veralteten Manager oder "
|
||||
"Stand.";
|
||||
return std::nullopt;
|
||||
}
|
||||
if (request.row >= 20 || request.column >= 9 ||
|
||||
!mem.has(::bmh::layout::LeaguePresentationOptions + 179) ||
|
||||
!mem.has(::bmh::layout::GameMode) ||
|
||||
!mem.has(::bmh::layout::CompetitionSelection)) {
|
||||
error = "Der Einstellungszustand ist unvollständig.";
|
||||
return std::nullopt;
|
||||
}
|
||||
std::array<uint8_t, 180> raw{};
|
||||
for (size_t i = 0; i < raw.size(); ++i) {
|
||||
const uint32_t address =
|
||||
::bmh::layout::LeaguePresentationOptions + uint32_t(i);
|
||||
if (!mem.has(address)) {
|
||||
error = "Der Einstellungszustand ist unvollständig.";
|
||||
return std::nullopt;
|
||||
}
|
||||
raw[i] = mem.u8(address);
|
||||
}
|
||||
if (raw != request.expected_raw) {
|
||||
error = "Die Einstellungen wurden inzwischen geändert.";
|
||||
return std::nullopt;
|
||||
}
|
||||
const size_t index = size_t(request.row) * 9 + request.column;
|
||||
const uint32_t address =
|
||||
::bmh::layout::LeaguePresentationOptions + uint32_t(index);
|
||||
ui::SettingsAvailabilityInputs inputs{
|
||||
mem.u8(::bmh::layout::GameMode),
|
||||
mem.u32(::bmh::layout::CompetitionSelection),
|
||||
uint8_t(sound && !sound->music), uint8_t(sound && !sound->effects)};
|
||||
auto availability = ui::project_settings_availability(raw, inputs, exe);
|
||||
// The host supplies the portable sound driver's capabilities. Headless
|
||||
// callers without that provider retain the unknown Source latch boundary.
|
||||
if (!sound) {
|
||||
availability[5] = raw[5];
|
||||
availability[6] = raw[6];
|
||||
}
|
||||
const bool sound_cell =
|
||||
request.row == 0 && (request.column == 5 || request.column == 6);
|
||||
if (sound_cell && !sound) {
|
||||
error = "Diese Einstellung ist noch nicht verfügbar.";
|
||||
return std::nullopt;
|
||||
}
|
||||
if (((request.row == 8 && request.column == 7) && !scoped_settings) ||
|
||||
(request.column == 7 && request.row >= 14 && request.row <= 19)) {
|
||||
error = "Diese Einstellung ist noch nicht verfügbar.";
|
||||
return std::nullopt;
|
||||
}
|
||||
if ((request.operation != ui::SettingsEdit::toggle_binary &&
|
||||
request.operation != ui::SettingsEdit::decrement &&
|
||||
request.operation != ui::SettingsEdit::increment) ||
|
||||
(request.column < 7 &&
|
||||
request.operation != ui::SettingsEdit::toggle_binary) ||
|
||||
(request.column >= 7 &&
|
||||
request.operation == ui::SettingsEdit::toggle_binary)) {
|
||||
error = "Die Aktion passt nicht zum Einstellungsfeld.";
|
||||
return std::nullopt;
|
||||
}
|
||||
const uint8_t shown = availability[index];
|
||||
const uint8_t raw_value =
|
||||
sound_cell && sound ? uint8_t(raw[index] & 0x7f) : raw[index];
|
||||
if (request.column < 7 && ((shown & 0x80) || raw_value >= 2)) {
|
||||
error = "Dieses Einstellungsfeld ist im aktuellen Modus gesperrt.";
|
||||
return std::nullopt;
|
||||
}
|
||||
const uint8_t old = raw_value;
|
||||
uint8_t next = old;
|
||||
if (request.operation == ui::SettingsEdit::toggle_binary) {
|
||||
// Inventory of actual current consumers: direct match-engine buttons,
|
||||
// matchday/season flags and the live-scene switch. Other cells are not
|
||||
// made writable merely because the Original UI displayed a cell.
|
||||
// Tie the write whitelist to the concrete consumer ranges. League
|
||||
// remapping reads rows 0..4, columns 0..3; matchday display kinds 1/2
|
||||
// map to columns 0..2 and rows 0..4 or 17..19.
|
||||
const bool consumed =
|
||||
(sound_cell && sound.has_value()) ||
|
||||
(request.row == 0 &&
|
||||
request.column == 4) || // A5: match/Sportschau sound
|
||||
((request.row <= 4 && request.column <= 3) ||
|
||||
((request.row <= 4 || request.row >= 17) && request.column <= 2)) ||
|
||||
((request.row == 5 || (request.row >= 9 && request.row <= 12)) &&
|
||||
request.column == 0) ||
|
||||
(request.row == 1 && request.column == 4) || // B5 live-scene option
|
||||
(request.row == 2 &&
|
||||
request.column == 4) || // C5: Reality player numbers
|
||||
// (RealityMatch_FormatError_ExecutableField)
|
||||
(request.row == 5 &&
|
||||
request.column ==
|
||||
5) || // F6: Source manager-match desk gate
|
||||
// (MatchdaySetup_MatchdayNeedsManagerDesks_RuntimeField)
|
||||
(request.row == 6 &&
|
||||
request.column ==
|
||||
5) || // G6: transfer confirmation wait (OutcomeDelayDisabled)
|
||||
(request.row == 16 &&
|
||||
request.column ==
|
||||
6) || // Q7: own-club Sportschau preference
|
||||
// (MatchdaySetup_ConsiderSportschauFixture_RuntimeField)
|
||||
(request.row == 13 &&
|
||||
request.column ==
|
||||
6) || // N7: Source kickoff competition list
|
||||
// (SportschauAwards_MatchdayIntroView_RuntimeField)
|
||||
(request.row == 1 &&
|
||||
request.column == 6) || // B7: SportschauIntro intro gate
|
||||
// (Controller_FormatError_RuntimeField)
|
||||
(request.row == 2 &&
|
||||
request.column == 6) || // C7: SportschauIntro intro-animation gate
|
||||
// (Controller_FormatError_RuntimeField2)
|
||||
(request.row == 3 &&
|
||||
request.column ==
|
||||
6) || // D7: selected report progression (ReplayProgressionMode)
|
||||
(request.row == 4 &&
|
||||
request.column ==
|
||||
6) || // E7: Source-owned Sportschau scenes (ReplayChanceMode)
|
||||
(request.row == 5 &&
|
||||
request.column == 6) || // F7: SportschauIntro fixture-report gate
|
||||
// (Controller_FormatError_RuntimeField3)
|
||||
(request.row == 6 &&
|
||||
request.column ==
|
||||
6) || // G7: MatchdayIntro player/award rating
|
||||
// (SportschauAwards_FinishSportschauAwards_RuntimeField)
|
||||
(request.row == 7 &&
|
||||
request.column ==
|
||||
6) || // H7: SportschauTeamInfo competition totals
|
||||
// (SportschauAwards_SportschauTeamInfoView_RuntimeField)
|
||||
(request.row == 2 &&
|
||||
request.column ==
|
||||
5) || // C6 drawer-handle behavior
|
||||
// (CareerSession_DispatchDesktopLayout_RuntimeField)
|
||||
(request.row == 3 &&
|
||||
request.column ==
|
||||
5) || // D6 native desktop drag raster
|
||||
// (CareerSession_DispatchDesktopLayout_RuntimeField2)
|
||||
(request.row == 4 &&
|
||||
request.column == 5) || // E6 always-visible shortcut bar
|
||||
// (DeskState_FormatError_RuntimeField3)
|
||||
(request.row == 7 && request.column == 5) || // H6 transfer option
|
||||
(request.row == 8 &&
|
||||
(request.column == 5 || request.column == 6)) || // I6/I7
|
||||
(request.row >= 10 && request.row <= 13 &&
|
||||
request.column == 4) || // K5:N5 match buttons
|
||||
(request.row >= 10 && request.row <= 12 &&
|
||||
request.column == 6) || // K7:M7 presentation
|
||||
(request.row == 9 &&
|
||||
request.column ==
|
||||
6) || // J7 season-entrant visibility
|
||||
// (SeasonEntrants_SeasonEntrantsFromGame_TextPointer)
|
||||
(request.row == 15 && request.column == 4) || // P5
|
||||
(request.row == 16 && request.column == 4) || // Q5
|
||||
(request.row == 17 &&
|
||||
request.column == 4); // R5: secondary leagues
|
||||
// (CalendarState_FormatError_RuntimeField2)
|
||||
if (!consumed || (old != 0 && old != 1)) {
|
||||
error = "Diese Einstellung ist noch nicht verfügbar.";
|
||||
return std::nullopt;
|
||||
}
|
||||
if (request.row == 16 && request.column == 4 && state.season_day() >= 110 &&
|
||||
state.season_day() <= 230) {
|
||||
error = ui::original_to_utf8(message_text(
|
||||
state, ::bmh::layout::CareerSession_DispatchSettings_TextPointer));
|
||||
return std::nullopt;
|
||||
}
|
||||
// SettingsSourceRefusal only permits re-enabling R5 while
|
||||
// CareerSessionRuntimeField4 is zero. LeagueRoundCounters is the saved
|
||||
// league_rounds block; CareerSessionRuntimeField4 is its sixth byte.
|
||||
// Turning the leagues off remains possible after they have started.
|
||||
if (request.row == 17 && request.column == 4 && old != 0 &&
|
||||
(state.league_rounds.size() <= 5 || state.league_rounds[5] != 0)) {
|
||||
error = ui::original_to_utf8(message_text(
|
||||
state, ::bmh::layout::CareerSession_DispatchSettings_TextPointer2));
|
||||
return std::nullopt;
|
||||
}
|
||||
next = old ^ 1;
|
||||
} else {
|
||||
// Column8: existing presentation speeds B8:F8, H8 process budget,
|
||||
// J8 postponed limit and K8 autosave. Column9 only exposes values
|
||||
// already read by Main's Source live presenters or CupDrawScreen.
|
||||
const bool consumed =
|
||||
(request.column == 7 &&
|
||||
((request.row <= 6) || request.row == 7 || request.row == 9 ||
|
||||
request.row == 10 || (scoped_settings && request.row == 8))) ||
|
||||
// A9 match minutes; B9:C9 chance result; D9:E9 bookings; F9:G9 rolling
|
||||
// ball; I9 cup draw; K9 Reality report; M9 preview/shootout; P9 shot.
|
||||
(request.column == 8 &&
|
||||
((request.row >= 0 && request.row <= 6) || request.row == 7 ||
|
||||
request.row == 8 || request.row == 10 || request.row == 12 ||
|
||||
request.row == 15));
|
||||
if (!consumed || old >= 200) {
|
||||
error = "Diese Einstellung ist noch nicht verfügbar.";
|
||||
return std::nullopt;
|
||||
}
|
||||
if (request.column == 8) {
|
||||
// SettingsSourceRefusal's ninth column is stored doubled for display. Its
|
||||
// Source edit step is two raw units; decrement is enabled only
|
||||
// above 1 and increment only below 0xc6 (198). Preserve odd raw
|
||||
// values exactly, as the original does.
|
||||
if (request.operation == ui::SettingsEdit::decrement) {
|
||||
if (old <= 1) {
|
||||
error = "Der Zahlenwert ist bereits am Originalminimum.";
|
||||
return std::nullopt;
|
||||
}
|
||||
next = uint8_t(old - 2);
|
||||
} else {
|
||||
if (old >= 198) {
|
||||
error = "Der Zahlenwert ist bereits am Originalmaximum.";
|
||||
return std::nullopt;
|
||||
}
|
||||
next = uint8_t(old + 2);
|
||||
}
|
||||
} else if (request.column == 7) {
|
||||
if (request.operation == ui::SettingsEdit::decrement) {
|
||||
if (old == 0) {
|
||||
error = "Der Zahlenwert ist bereits am Originalminimum.";
|
||||
return std::nullopt;
|
||||
}
|
||||
next = uint8_t(old - 1);
|
||||
} else {
|
||||
const uint8_t limit =
|
||||
exe.u8(::bmh::layout::CareerSession_DispatchSettings_RuntimeField +
|
||||
request.row);
|
||||
if (old >= limit) {
|
||||
error = "Der Zahlenwert ist bereits am Originalmaximum.";
|
||||
return std::nullopt;
|
||||
}
|
||||
next = uint8_t(old + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (next == old) {
|
||||
error = "Die Einstellung hat sich nicht geändert.";
|
||||
return std::nullopt;
|
||||
}
|
||||
return next;
|
||||
}
|
||||
} // namespace
|
||||
@@ -0,0 +1,97 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
int ui_setting_index(const std::string &code) {
|
||||
if (code.size() != 2 || code[0] < 'A' || code[0] > 'T' || code[1] < '1' ||
|
||||
code[1] > '9')
|
||||
return -1;
|
||||
return (code[0] - 'A') * 9 + code[1] - '1';
|
||||
}
|
||||
constexpr const char *ui_automation_ids[] = {"lineup", "substitutions",
|
||||
"tactics", "marking", "training"};
|
||||
int ui_automation_index(const std::string &id) {
|
||||
for (int i = 0; i < 5; ++i)
|
||||
if (id == ui_automation_ids[i])
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
cli::Json ui_settings_data(const ModernState &state, const LeImage &exe,
|
||||
std::optional<ui::SettingsSoundCapabilities> sound,
|
||||
int manager, uint64_t revision,
|
||||
bool automation_available) {
|
||||
using J = cli::Json;
|
||||
using O = J::Object;
|
||||
using A = J::Array;
|
||||
const auto view =
|
||||
ui::settings_from_game(state, manager, revision, exe, sound);
|
||||
A cells, automation, formations;
|
||||
for (size_t i = 0; i < view.cells.size(); ++i) {
|
||||
const int column = int(i % 9), row = int(i / 9), raw = view.cells[i];
|
||||
ui::SettingsWriteRequest request;
|
||||
request.manager_slot = manager;
|
||||
request.revision = revision;
|
||||
request.expected_raw = view.cells;
|
||||
request.row = uint8_t(row);
|
||||
request.column = uint8_t(column);
|
||||
std::string error;
|
||||
request.operation = column < 7 ? ui::SettingsEdit::toggle_binary
|
||||
: ui::SettingsEdit::increment;
|
||||
bool editable =
|
||||
settings_next_value(state, exe, sound, request, revision, false, error)
|
||||
.has_value();
|
||||
if (column >= 7 && !editable) {
|
||||
request.operation = ui::SettingsEdit::decrement;
|
||||
editable = settings_next_value(state, exe, sound, request, revision,
|
||||
false, error)
|
||||
.has_value();
|
||||
}
|
||||
const int binary = raw & 0x3f;
|
||||
const int shown = column < 7 ? 1 - binary : column == 8 ? raw / 2 : raw;
|
||||
const int maximum =
|
||||
column < 7 ? 1
|
||||
: column == 8
|
||||
? 99
|
||||
: exe.u8(
|
||||
::bmh::layout::CareerSession_DispatchSettings_RuntimeField +
|
||||
uint32_t(row));
|
||||
const bool known = column < 7 ? binary <= 1 : raw < 200;
|
||||
const auto code = std::string(1, char('A' + row)) + char('1' + column);
|
||||
cells.push_back(
|
||||
O{{"code", code},
|
||||
{"raw", raw},
|
||||
{"displayRaw",
|
||||
int(view.display_cells ? (*view.display_cells)[i] : view.cells[i])},
|
||||
{"value", known ? J(shown) : J(nullptr)},
|
||||
{"editable", editable},
|
||||
{"min", 0},
|
||||
{"max", maximum},
|
||||
{"step", 1},
|
||||
{"reason", editable ? std::string() : error}});
|
||||
}
|
||||
const size_t base = size_t(manager) * 5, record = size_t(manager) * 0xb0c;
|
||||
const auto mask =
|
||||
state.manager_records.at(record + 0x218 + size_t(state.indoor));
|
||||
for (int i = 1; i <= 8; ++i)
|
||||
if (mask & (1 << (i - 1)))
|
||||
formations.push_back(
|
||||
O{{"value", i}, {"label", "Aufstellung " + std::to_string(i)}});
|
||||
const int selected = state.manager_options.at(base);
|
||||
const int default_formation =
|
||||
selected > 0 && selected <= 8 && (mask & (1 << (selected - 1))) ? selected
|
||||
: formations.empty()
|
||||
? 0
|
||||
: int(*ui_field(formations.front(), "value")->integer());
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
const int raw = state.manager_options.at(base + size_t(i));
|
||||
const bool available =
|
||||
automation_available && (i != 0 || (!formations.empty() && raw <= 8)) &&
|
||||
(i != 4 || state.manager_teams.at(size_t(manager)) != no_team());
|
||||
automation.push_back(O{{"id", ui_automation_ids[i]},
|
||||
{"enabled", i == 0 ? raw != 0 : (raw & 1) != 0},
|
||||
{"raw", raw},
|
||||
{"editable", available}});
|
||||
}
|
||||
return O{{"kind", "settings"},
|
||||
{"cells", std::move(cells)},
|
||||
{"automation", std::move(automation)},
|
||||
{"formations", std::move(formations)},
|
||||
{"formation", default_formation}};
|
||||
}
|
||||
@@ -154,10 +154,10 @@ A allowed_commands(const ModernState& g, const UiContext& c) {
|
||||
"session.advance", "lineup.commit", "tactics.commit", "friendly.book", "manager.resign.commit",
|
||||
"training.commit", "camp.book", "bank.commit", "toto.submit", "quote.request", "contract.offer",
|
||||
"stadium.commit", "advertising.accept", "budget.commit", "ticket.commit", "transfer.submit",
|
||||
"sponsor.answer", "environment.commit", "fixture.reschedule", "contract.cancel", "news.update", "balance.commit"};
|
||||
"sponsor.answer", "environment.commit", "fixture.reschedule", "contract.cancel", "news.update", "balance.commit", "settings.commit"};
|
||||
A out;
|
||||
for (size_t i = 0; i < std::size(kAll); ++i)
|
||||
if (!national || i < 5) out.push_back(kAll[i]);
|
||||
if (!national || i < 5 || std::string(kAll[i]) == "settings.commit") out.push_back(kAll[i]);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -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