Manage real OBS careers in native save and load dialogs (by Codex)

This commit is contained in:
Codex committed 2026-10-29 02:57:32 +01:00
1 parent 693744a961
commit e3ea03a05d
25 files changed
+539 -39

No files matched your search

+17 -7
View File
@@ -87,6 +87,7 @@ void App::engine_frame() {
engine_contract_scroll_.reset();
}
if(rendered&&(menu_=="scorers"||menu_=="fairplay")){rankings_restore_scroll();context_->Update();}
if(rendered&&files_native_){files_after_render();context_->Update();}
if (center_selects(*doc_)) context_->Update();
if (menu_ == "lineup" && lineup_roster_scroll_) {
if (auto *roster = element("lineup-roster-scroll")) roster->SetScrollTop(*lineup_roster_scroll_);
@@ -114,7 +115,8 @@ void App::engine_frame() {
renderer_.Clear(); renderer_.BeginFrame(); context_->Render(); renderer_.EndFrame(); video_.present(); dirty_ = false;
}
void App::engine_save() {
if (engine_busy_ || !engine_link_) return;
if (engine_busy_ || engine_files_busy_ || !engine_link_) return;
if(config_.file_export.empty()){engine_files_begin("save");return;}
auto output = config_.file_export;
if (output.empty()) {
NFD::Guard guard; NFD::UniquePath chosen;
@@ -128,7 +130,7 @@ void App::engine_save() {
engine_start("Spielstand wird gespeichert …", [link, output] { auto response = link->save_copy(output); return EngineReply{link, link->snapshot(), response, nullptr}; });
}
void App::engine_quit() {
if (engine_busy_) { engine_notice_ = "Bitte den laufenden Vorgang abwarten."; dirty_ = true; return; }
if (engine_busy_ || engine_files_busy_) { engine_notice_ = "Bitte den laufenden Vorgang abwarten."; dirty_ = true; return; }
if (engine_dirty_) {
confirmation("Die Partie enthält ungespeicherte Änderungen. Vor dem Beenden speichern?",[this]{closed_=true;});
popup_accept_="Ohne Speichern beenden";
@@ -147,13 +149,14 @@ void App::engine_event(Rml::Event &event) {
if (!engine_busy_ && bank_event(event)) return;
if (!engine_busy_ && advertising_event(event)) return;
if (!engine_busy_ && popup_.empty() && contracts_event(event)) return;
if(engine_opening_active()&&popup_.empty()) {
if(engine_opening_active()&&menu_.empty()&&popup_.empty()) {
if(type=="keydown") {const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
if(key==Rml::Input::KI_TAB){Rml::ElementList nodes;doc_->QuerySelectorAll(nodes,".opening-actions button");std::erase_if(nodes,[](auto *n){return n->HasAttribute("disabled");});if(!nodes.empty()){const auto it=std::find(nodes.begin(),nodes.end(),context_->GetFocusElement());const int i=it==nodes.end()?-1:int(it-nodes.begin()),n=int(nodes.size());nodes[size_t((i+n+(event.GetParameter<int>("shift_key",0)?-1:1))%n)]->Focus(true);}event.StopImmediatePropagation();return;}
if(key==Rml::Input::KI_RETURN||key==Rml::Input::KI_SPACE){for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->GetTagName()=="button"&&!n->HasAttribute("disabled")){n->DispatchEvent("click",{});break;}}}
if(type=="click")for(auto *n=target;n&&n!=doc_;n=n->GetParentNode())if(n->HasAttribute("data-action")){opening_action(n->GetAttribute<Rml::String>("data-action",""),n);break;}
event.StopImmediatePropagation();return;
}
if(files_native_&&files_event(event))return;
if (engine_reports_event(event)) return;
if(!engine_busy_&&popup_.empty()&&rankings_event(event))return;
if (!engine_busy_ && popup_.empty() && engine_friendly_event(event)) return;
@@ -183,7 +186,7 @@ void App::engine_event(Rml::Event &event) {
}
if (type == "keydown" && event.GetParameter<int>("key_identifier", 0) == Rml::Input::KI_ESCAPE) {
if (menu_ == "almanac" && engine_busy_) { event.StopImmediatePropagation(); return; }
if (!popup_.empty()) { popup_.clear(); confirm_ = {}; dirty_ = true; }
if (!popup_.empty()) { popup_.clear(); reset_popup(); engine_files_pending_load_.reset(); engine_exit_after_save_=false; dirty_ = true; }
else if (!engine_busy_ && !engine_player_.empty()) { focus_after_render_ = "lineup-detail-" + engine_player_ + "-0"; engine_player_.clear(); refresh(); }
else if (!engine_busy_ && menu_ == "almanac") engine_almanac_action("alm-back",nullptr);
else if (!engine_busy_ && !menu_.empty()) { if (menu_ == "training" || menu_ == "tactics") engine_sports_reset(); if(menu_=="scorers"||menu_=="fairplay")rankings_remember_scroll(); menu_.clear(); refresh(); }
@@ -208,6 +211,10 @@ void App::engine_event(Rml::Event &event) {
}
event.StopImmediatePropagation(); return;
}
if(type=="keydown"&&popup_.empty()&&menu_.empty()&&!engine_busy_&&!engine_files_busy_) {
const auto key=Rml::Input::KeyIdentifier(event.GetParameter<int>("key_identifier",0));
if(event.GetParameter<int>("ctrl_key",0)&&(key==Rml::Input::KI_S||key==Rml::Input::KI_O)){engine_files_begin(key==Rml::Input::KI_S?"save":"load");event.StopImmediatePropagation();return;}
}
if (engine_busy_) return;
if ((type == "input" || type == "change") && menu_ == "camp" && popup_.empty() && target->GetId().starts_with("camp-focus-")) {
const int index = target->GetAttribute<int>("data-id", -1);
@@ -233,11 +240,13 @@ void App::engine_event(Rml::Event &event) {
if (!node->HasAttribute("data-action") || node->HasAttribute("disabled")) continue;
const auto action = node->GetAttribute<Rml::String>("data-action", ""), id = node->GetAttribute<Rml::String>("data-id", "");
if (!popup_.empty()) {
if (action == "popup-close") { popup_.clear(); confirm_ = {}; dirty_ = true; }
if (action == "popup-close") { popup_.clear(); reset_popup(); engine_files_pending_load_.reset(); engine_exit_after_save_=false; dirty_ = true; }
if(action=="files-save-before-load"){const auto pending=engine_files_pending_load_;reset_popup();popup_.clear();engine_files_begin("save");engine_files_pending_load_=pending;return;}
if(action=="engine-save-exit"){reset_popup();popup_.clear();engine_exit_after_save_=true;try{engine_save();}catch(const std::exception &e){engine_exit_after_save_=false;message(e.what());}return;}
if (action == "popup-confirm") { auto callback = std::move(confirm_); popup_.clear(); dirty_ = true; if (callback) callback(); }
if (action == "popup-confirm") { auto callback=std::move(confirm_);auto text_callback=std::move(text_accept_);const auto text=field("popup-text");popup_.clear();reset_popup();dirty_=true;if(text_callback)text_callback(text);else if(callback)callback(); }
return;
}
if(files_native_&&files_action(action,node))return;
if(action.starts_with("rankings-")&&menu_=="scorers"){rankings_action(action,node);return;}
if (engine_reports_action(action,node)) return;
if (almanac_action(action,node)) return;
@@ -256,6 +265,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=="load"){engine_files_begin("load");}
else if(action=="engine-open"&&id=="scorers"){menu_=id;engine_reports_sync();engine_rankings_load(engine_rankings_state_.at("league"),engine_rankings_state_.at("scope"));}
else if(action=="engine-open"&&id=="fairplay"){menu_=id;engine_reports_sync();engine_fairplay_load();}
else if(action=="engine-open"&&id=="other"){menu_=id;engine_reports_sync();engine_other_load(engine_other_value_.is_object()?engine_other_value_.at("viewId").get<std::string>():"",engine_other_value_.is_object()?engine_other_value_.at("round").get<int>():0);}
@@ -286,5 +296,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_},
{"response", engine_response_}, {"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_}};
{"response", engine_response_}, {"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_}};
}