From e0b83881f00d24a18b47708e8f49030ff4b68309 Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Thu, 13 Jun 2024 11:32:48 +0200 Subject: [PATCH 01/13] move TerminateIfNothingLoaded to gframe instead of data_handler --- gframe/data_handler.cpp | 2 -- gframe/gframe.cpp | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gframe/data_handler.cpp b/gframe/data_handler.cpp index 89a95f028..458edb2a6 100644 --- a/gframe/data_handler.cpp +++ b/gframe/data_handler.cpp @@ -138,8 +138,6 @@ DataHandler::DataHandler() { gitManager->ToggleReadOnly(cli_args[REPOS_READ_ONLY].enabled); gitManager->LoadRepositoriesFromJson(configs->user_configs); gitManager->LoadRepositoriesFromJson(configs->configs); - if(gitManager->TerminateIfNothingLoaded()) - deckManager->StopDummyLoading(); imageDownloader = std::make_unique(); LoadDatabases(); LoadPicUrls(); diff --git a/gframe/gframe.cpp b/gframe/gframe.cpp index 2d31e31d8..a9fd17468 100644 --- a/gframe/gframe.cpp +++ b/gframe/gframe.cpp @@ -200,6 +200,9 @@ int edopro_main(const args_t& args) { firstlaunch = false; CheckArguments(args); } + if(ygo::gRepoManager->TerminateIfNothingLoaded()) + ygo::gdeckManager->StopDummyLoading(); + reset = ygo::mainGame->MainLoop(); data->tmp_device = ygo::mainGame->device; if(reset) { From dfb7c0e8869b503de64813d806b830a0f6f91b1a Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Thu, 13 Jun 2024 11:37:33 +0200 Subject: [PATCH 02/13] implement OnAsyncLoadingCompleted, called when all the async loading is complete --- gframe/game.cpp | 9 +++++++-- gframe/game.h | 2 ++ gframe/gframe.cpp | 2 +- gframe/repo_manager.cpp | 4 ++++ gframe/repo_manager.h | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/gframe/game.cpp b/gframe/game.cpp index 66a5e71ff..e91b8fd16 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -2696,8 +2696,7 @@ void Game::ParseGithubRepositories(const std::vector& repos) { deckBuilder.StartFilter(true); } if(gRepoManager->GetUpdatingReposNumber() == 0) { - gdeckManager->StopDummyLoading(); - ReloadElementsStrings(); + OnAsyncLoadingCompleted(); } } void Game::UpdateRepoInfo(const GitRepo* repo, RepoGui* grepo) { @@ -3629,6 +3628,12 @@ void Game::ReloadElementsStrings() { ReloadCBCurrentSkin(); } + +void Game::OnAsyncLoadingCompleted() { + gdeckManager->StopDummyLoading(); + ReloadElementsStrings(); +} + void Game::OnResize() { env->getRootGUIElement()->setRelativePosition(irr::core::recti(0, 0, window_size.Width, window_size.Height)); { diff --git a/gframe/game.h b/gframe/game.h index 9c9783b69..80096b99c 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -216,6 +216,8 @@ class Game { void ReloadCBVsync(); void ReloadElementsStrings(); + void OnAsyncLoadingCompleted(); + void OnResize(); template T Scale(T val) const; diff --git a/gframe/gframe.cpp b/gframe/gframe.cpp index a9fd17468..3b33438cd 100644 --- a/gframe/gframe.cpp +++ b/gframe/gframe.cpp @@ -201,7 +201,7 @@ int edopro_main(const args_t& args) { CheckArguments(args); } if(ygo::gRepoManager->TerminateIfNothingLoaded()) - ygo::gdeckManager->StopDummyLoading(); + ygo::mainGame->OnAsyncLoadingCompleted(); reset = ygo::mainGame->MainLoop(); data->tmp_device = ygo::mainGame->device; diff --git a/gframe/repo_manager.cpp b/gframe/repo_manager.cpp index 707fa71f0..ea2b7d4c7 100644 --- a/gframe/repo_manager.cpp +++ b/gframe/repo_manager.cpp @@ -97,6 +97,10 @@ RepoManager::~RepoManager() { TerminateThreads(); } +size_t RepoManager::GetAllReposNumber() const { + return all_repos_count; +} + size_t RepoManager::GetUpdatingReposNumber() const { return available_repos.size(); } diff --git a/gframe/repo_manager.h b/gframe/repo_manager.h index dfe029db9..14c997240 100644 --- a/gframe/repo_manager.h +++ b/gframe/repo_manager.h @@ -65,6 +65,7 @@ class RepoManager { // Cancel fetching of repos and synchronize with futures ~RepoManager(); + size_t GetAllReposNumber() const; size_t GetUpdatingReposNumber() const; std::vector GetAllRepos() const; std::vector GetReadyRepos(); // changes available_repos From 5b85f22146eb74e3b39aa83abdd53849b5cbb2d7 Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Thu, 13 Jun 2024 11:39:40 +0200 Subject: [PATCH 03/13] implement open replay command line option --- gframe/cli_args.h | 2 ++ gframe/edopro_main.cpp | 3 +++ gframe/game.cpp | 42 +++++++++++++++++++++++++++++++++++++++++ gframe/game.h | 9 +++++++++ gframe/gframe.cpp | 7 +++++++ gframe/menu_handler.cpp | 2 +- gframe/menu_handler.h | 1 + gframe/replay_mode.cpp | 2 ++ 8 files changed, 67 insertions(+), 1 deletion(-) diff --git a/gframe/cli_args.h b/gframe/cli_args.h index 4b785ef39..422669648 100644 --- a/gframe/cli_args.h +++ b/gframe/cli_args.h @@ -13,6 +13,8 @@ enum LAUNCH_PARAM { WANTS_TO_RUN_AS_ADMIN, REPOS_READ_ONLY, ONLY_CLONE_REPOS, + EXIT_AFTER, + REPLAY, COUNT, }; diff --git a/gframe/edopro_main.cpp b/gframe/edopro_main.cpp index e4db4a6ec..087688fea 100644 --- a/gframe/edopro_main.cpp +++ b/gframe/edopro_main.cpp @@ -31,11 +31,14 @@ auto GetOption(epro::path_stringview option) { case EPRO_TEXT('u'): return LAUNCH_PARAM::OVERRIDE_UPDATE_URL; case EPRO_TEXT('r'): return LAUNCH_PARAM::REPOS_READ_ONLY; case EPRO_TEXT('c'): return LAUNCH_PARAM::ONLY_CLONE_REPOS; + case EPRO_TEXT('q'): return LAUNCH_PARAM::EXIT_AFTER; default: return LAUNCH_PARAM::COUNT; } } if(option == EPRO_TEXT("i-want-to-be-admin"_sv)) return LAUNCH_PARAM::WANTS_TO_RUN_AS_ADMIN; + if(option == EPRO_TEXT("replay"_sv)) + return LAUNCH_PARAM::REPLAY; return LAUNCH_PARAM::COUNT; } diff --git a/gframe/game.cpp b/gframe/game.cpp index e91b8fd16..0acf23b90 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -68,6 +68,16 @@ inline T AlignElementWithParent(T elem) { elem->setAlignment(irr::gui::EGUIA_SCALE, irr::gui::EGUIA_SCALE, irr::gui::EGUIA_SCALE, irr::gui::EGUIA_SCALE); return elem; } +inline void TriggerEvent(irr::gui::IGUIElement* target, irr::gui::EGUI_EVENT_TYPE type) { + irr::SEvent event; + event.EventType = irr::EET_GUI_EVENT; + event.GUIEvent.EventType = type; + event.GUIEvent.Caller = target; + ygo::mainGame->device->postEventFromUser(event); +} +static inline void ClickButton(irr::gui::IGUIElement* btn) { + TriggerEvent(btn, irr::gui::EGET_BUTTON_CLICKED); +} } namespace ygo { @@ -1098,6 +1108,15 @@ void Game::Initialize() { env->getRootGUIElement()->bringToFront(wBtnSettings); env->getRootGUIElement()->bringToFront(mTopMenu); env->setFocus(wMainMenu); + + //loading modal + wLoadingModal = env->addWindow(Scale(490, 240, 840, 300), false, L""); + wLoadingModal->getCloseButton()->setVisible(false); + SetCentered(wLoadingModal); + auto stLoadingMessage = irr::gui::CGUICustomText::addCustomText(L"Loading...", true, env, wLoadingModal, -1, Scale(0, 0, 350, 60), true); + stLoadingMessage->setWordWrap(true); + stLoadingMessage->setBackgroundColor(skin::DUELFIELD_ANNOUNCE_TEXT_BACKGROUND_COLOR_VAL); + stLoadingMessage->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); } bool Game::LoadCore() { @@ -3632,6 +3651,29 @@ void Game::ReloadElementsStrings() { void Game::OnAsyncLoadingCompleted() { gdeckManager->StopDummyLoading(); ReloadElementsStrings(); + + if(onLoadAction.enabled) { + wLoadingModal->setVisible(false); + //process onload cmd parameters + if(!onLoadAction.replay.empty()) { + open_file = true; + open_file_name = onLoadAction.replay; + ClickButton(btnReplayMode); + menuHandler.LoadReplay(); + } else { + wMainMenu->setVisible(true); + } + } + + onLoadAction.enabled = false; +} + +void Game::SetOnLoadActionReplay(epro::path_string replay) { + onLoadAction.enabled = true; + onLoadAction.replay = replay; + wLoadingModal->setVisible(true); + wMainMenu->setVisible(false); + env->setFocus(wLoadingModal); } void Game::OnResize() { diff --git a/gframe/game.h b/gframe/game.h index 80096b99c..5dacc2b24 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -217,6 +217,7 @@ class Game { void ReloadElementsStrings(); void OnAsyncLoadingCompleted(); + void SetOnLoadActionReplay(epro::path_string file); void OnResize(); template @@ -411,10 +412,18 @@ class Game { epro::mutex progressStatusLock; ProgressBarStatus progressStatus; + struct OnLoadAction { + bool enabled; + bool exitAfter; + epro::path_string replay; + }; + OnLoadAction onLoadAction; + //main menu int mainMenuLeftX; int mainMenuRightX; irr::gui::IGUIWindow* wMainMenu; + irr::gui::IGUIWindow* wLoadingModal; irr::gui::IGUIWindow* wCommitsLog; irr::gui::IGUIContextMenu* mTopMenu; irr::gui::IGUIContextMenu* mRepositoriesInfo; diff --git a/gframe/gframe.cpp b/gframe/gframe.cpp index 3b33438cd..33c5be807 100644 --- a/gframe/gframe.cpp +++ b/gframe/gframe.cpp @@ -54,6 +54,13 @@ void CheckArguments(const args_t& args) { SetCheckbox(ygo::mainGame->tabSettings.chkEnableSound, false); SetCheckbox(ygo::mainGame->tabSettings.chkEnableMusic, false); } + if (args[LAUNCH_PARAM::REPLAY].enabled && !args[LAUNCH_PARAM::REPLAY].argument.empty()) { + auto replay = ygo::Utils::ToPathString(args[LAUNCH_PARAM::REPLAY].argument); + ygo::mainGame->SetOnLoadActionReplay(replay); + } + if (args[LAUNCH_PARAM::EXIT_AFTER].enabled) { + ygo::mainGame->onLoadAction.exitAfter = true; + } } inline void ThreadsStartup() { diff --git a/gframe/menu_handler.cpp b/gframe/menu_handler.cpp index 0675942c7..4e8df1a56 100644 --- a/gframe/menu_handler.cpp +++ b/gframe/menu_handler.cpp @@ -50,7 +50,7 @@ static void UpdateDeck() { DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf); gdeckManager->sent_deck = mainGame->deckBuilder.GetCurrentDeck(); } -static void LoadReplay() { +void MenuHandler::LoadReplay() { auto& replay = ReplayMode::cur_replay; if(std::exchange(open_file, false)) { bool res = replay.OpenReplay(open_file_name); diff --git a/gframe/menu_handler.h b/gframe/menu_handler.h index 7d82c3e4d..d495f2795 100644 --- a/gframe/menu_handler.h +++ b/gframe/menu_handler.h @@ -292,6 +292,7 @@ enum GUI { class MenuHandler final : public irr::IEventReceiver { public: + void LoadReplay(); bool OnEvent(const irr::SEvent& event) override; void SynchronizeElement(irr::gui::IGUIElement* elem) const; std::unordered_multimap synchronized_elements; diff --git a/gframe/replay_mode.cpp b/gframe/replay_mode.cpp index a396a112d..89f978f12 100644 --- a/gframe/replay_mode.cpp +++ b/gframe/replay_mode.cpp @@ -173,6 +173,8 @@ void ReplayMode::EndDuel() { mainGame->stTip->setVisible(false); gSoundManager->StopSounds(); mainGame->device->setEventReceiver(&mainGame->menuHandler); + if (mainGame->onLoadAction.enabled && mainGame->onLoadAction.exitAfter) + mainGame->device->closeDevice(); } } void ReplayMode::Restart(bool refresh) { From 3ee0b622e7a79198e837a4b13858ef5221da67a6 Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Thu, 13 Jun 2024 12:10:22 +0200 Subject: [PATCH 04/13] fix OnAsyncLoadingCompleted when we also have to load the core --- gframe/game.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/gframe/game.cpp b/gframe/game.cpp index 0acf23b90..e2a942324 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -1158,6 +1158,7 @@ void Game::LoadCoreFromRepos() { btnHandTestSettings->setEnabled(true); stHandTestSettings->setEnabled(true); } + OnAsyncLoadingCompleted(); break; } cores_to_load.clear(); From 721e50ffd2b894058d9e3754c40d967db8478103 Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Thu, 13 Jun 2024 12:10:52 +0200 Subject: [PATCH 05/13] command line start replay paused --- gframe/game.cpp | 5 +++++ gframe/replay_mode.cpp | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gframe/game.cpp b/gframe/game.cpp index e2a942324..e5b1f0527 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -3661,6 +3661,11 @@ void Game::OnAsyncLoadingCompleted() { open_file_name = onLoadAction.replay; ClickButton(btnReplayMode); menuHandler.LoadReplay(); + ReplayMode::Pause(true, false); + mainGame->btnReplayStart->setVisible(true); + mainGame->btnReplayPause->setVisible(false); + mainGame->btnReplayStep->setVisible(true); + mainGame->btnReplayUndo->setVisible(true); } else { wMainMenu->setVisible(true); } diff --git a/gframe/replay_mode.cpp b/gframe/replay_mode.cpp index 89f978f12..8cad32fc8 100644 --- a/gframe/replay_mode.cpp +++ b/gframe/replay_mode.cpp @@ -117,6 +117,15 @@ int ReplayMode::ReplayThread() { current_step = 0; if(mainGame->dInfo.isCatchingUp) mainGame->gMutex.lock(); + + // check pause after load + if (is_pausing) { + is_paused = true; + std::unique_lock lock(mainGame->gMutex); + mainGame->actionSignal.Wait(lock); + is_paused = false; + } + for(auto it = current_stream.begin(); is_continuing && !exit_pending && it != current_stream.end();) { is_continuing = ReplayAnalyze((*it)); if(is_restarting) { @@ -173,7 +182,7 @@ void ReplayMode::EndDuel() { mainGame->stTip->setVisible(false); gSoundManager->StopSounds(); mainGame->device->setEventReceiver(&mainGame->menuHandler); - if (mainGame->onLoadAction.enabled && mainGame->onLoadAction.exitAfter) + if(mainGame->onLoadAction.exitAfter) mainGame->device->closeDevice(); } } From 9bc1d26603465e925307fcab8eb30eb0d4488cbe Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Tue, 18 Jun 2024 15:24:07 +0200 Subject: [PATCH 06/13] report created game ids to console --- gframe/duelclient.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gframe/duelclient.cpp b/gframe/duelclient.cpp index 10fd18f36..0fd10b263 100644 --- a/gframe/duelclient.cpp +++ b/gframe/duelclient.cpp @@ -686,7 +686,9 @@ void DuelClient::HandleSTOCPacketLanAsync(const std::vector& data) { break; } case STOC_CREATE_GAME: { - mainGame->dInfo.secret.game_id = BufferIO::getStruct(pdata, len).gameid; + auto gameid = BufferIO::getStruct(pdata, len).gameid; + mainGame->dInfo.secret.game_id = gameid; + epro::print("CREATE_GAME - id: {}\n", gameid); break; } case STOC_JOIN_GAME: { From 03656b8cb56ce9bd580ea7424adc0476f1cc6c23 Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Tue, 18 Jun 2024 15:25:08 +0200 Subject: [PATCH 07/13] implement cli args: -n, -d, -host, -join --- gframe/cli_args.h | 4 + gframe/edopro_main.cpp | 6 ++ gframe/game.cpp | 230 ++++++++++++++++++++++++++++++++++++++++- gframe/game.h | 33 ++++++ gframe/gframe.cpp | 21 +++- 5 files changed, 288 insertions(+), 6 deletions(-) diff --git a/gframe/cli_args.h b/gframe/cli_args.h index 422669648..564925ab9 100644 --- a/gframe/cli_args.h +++ b/gframe/cli_args.h @@ -15,6 +15,10 @@ enum LAUNCH_PARAM { ONLY_CLONE_REPOS, EXIT_AFTER, REPLAY, + HOST, + JOIN, + SET_NICKNAME, + SET_DECK, COUNT, }; diff --git a/gframe/edopro_main.cpp b/gframe/edopro_main.cpp index 087688fea..46bdebcb0 100644 --- a/gframe/edopro_main.cpp +++ b/gframe/edopro_main.cpp @@ -32,6 +32,8 @@ auto GetOption(epro::path_stringview option) { case EPRO_TEXT('r'): return LAUNCH_PARAM::REPOS_READ_ONLY; case EPRO_TEXT('c'): return LAUNCH_PARAM::ONLY_CLONE_REPOS; case EPRO_TEXT('q'): return LAUNCH_PARAM::EXIT_AFTER; + case EPRO_TEXT('n'): return LAUNCH_PARAM::SET_NICKNAME; + case EPRO_TEXT('d'): return LAUNCH_PARAM::SET_DECK; default: return LAUNCH_PARAM::COUNT; } } @@ -39,6 +41,10 @@ auto GetOption(epro::path_stringview option) { return LAUNCH_PARAM::WANTS_TO_RUN_AS_ADMIN; if(option == EPRO_TEXT("replay"_sv)) return LAUNCH_PARAM::REPLAY; + if(option == EPRO_TEXT("host"_sv)) + return LAUNCH_PARAM::HOST; + if(option == EPRO_TEXT("join"_sv)) + return LAUNCH_PARAM::JOIN; return LAUNCH_PARAM::COUNT; } diff --git a/gframe/game.cpp b/gframe/game.cpp index e5b1f0527..d1217963e 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -1111,6 +1111,7 @@ void Game::Initialize() { //loading modal wLoadingModal = env->addWindow(Scale(490, 240, 840, 300), false, L""); + wLoadingModal->setVisible(false); wLoadingModal->getCloseButton()->setVisible(false); SetCentered(wLoadingModal); auto stLoadingMessage = irr::gui::CGUICustomText::addCustomText(L"Loading...", true, env, wLoadingModal, -1, Scale(0, 0, 350, 60), true); @@ -3662,10 +3663,102 @@ void Game::OnAsyncLoadingCompleted() { ClickButton(btnReplayMode); menuHandler.LoadReplay(); ReplayMode::Pause(true, false); - mainGame->btnReplayStart->setVisible(true); - mainGame->btnReplayPause->setVisible(false); - mainGame->btnReplayStep->setVisible(true); - mainGame->btnReplayUndo->setVisible(true); + btnReplayStart->setVisible(true); + btnReplayPause->setVisible(false); + btnReplayStep->setVisible(true); + btnReplayUndo->setVisible(true); + } else if(onLoadAction.host.configured) { + ebServerName->setText(onLoadAction.host.host.c_str()); + ebHostPort->setText(fmt::to_wstring(onLoadAction.host.port).c_str()); + ebServerPass->setText(onLoadAction.host.password.c_str()); + ebStartLP->setText(fmt::to_wstring(onLoadAction.host.startLP).c_str()); + ebTeam1->setText(fmt::to_wstring(onLoadAction.host.team1).c_str()); + ebTeam2->setText(fmt::to_wstring(onLoadAction.host.team2).c_str()); + ebBestOf->setText(fmt::to_wstring(onLoadAction.host.bestOf).c_str()); + ebStartHand->setText(fmt::to_wstring(onLoadAction.host.startHand).c_str()); + ebDrawCount->setText(fmt::to_wstring(onLoadAction.host.drawCount).c_str()); + ebHostNotes->setText(fmt::to_wstring(onLoadAction.host.notes).c_str()); + + RefreshLFLists(); + for(irr::u32 i = 0; i < gdeckManager->_lfList.size(); ++i) { + if(gdeckManager->_lfList[i].hash == onLoadAction.host.lfList) { + cbHostLFList->setSelected(i); + } + } + + duel_param = onLoadAction.host.duelParam; + auto duel_param_ignoretcg = duel_param & ~DUEL_TCG_SEGOC_NONPUBLIC; + extra_rules = static_cast(onLoadAction.host.extraRules); + if (onLoadAction.host.forbiddenTypes < 0) { + if (duel_param == DUEL_MODE_SPEED) forbiddentypes = DUEL_MODE_MR5_FORB; + else if (duel_param == DUEL_MODE_RUSH) forbiddentypes = DUEL_MODE_MR5_FORB; + else if (duel_param == DUEL_MODE_GOAT) forbiddentypes = DUEL_MODE_MR1_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR1) forbiddentypes = DUEL_MODE_MR1_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR2) forbiddentypes = DUEL_MODE_MR2_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR3) forbiddentypes = DUEL_MODE_MR3_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR4) forbiddentypes = DUEL_MODE_MR4_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR5) forbiddentypes = DUEL_MODE_MR5_FORB; + else forbiddentypes = DUEL_MODE_MR5_FORB; + } + else { + forbiddentypes = static_cast(onLoadAction.host.forbiddenTypes); + } + + chkTcgRulings->setChecked(duel_param & DUEL_TCG_SEGOC_NONPUBLIC); + chkNoShuffleDeck->setChecked(onLoadAction.host.noShuffleDeck); + chkNoShuffleDeckSecondary->setChecked(onLoadAction.host.noShuffleDeck); + chkNoCheckDeckContent->setChecked(onLoadAction.host.noCheckDeckContent); + chkNoCheckDeckContentSecondary->setChecked(onLoadAction.host.noCheckDeckContent); + chkNoCheckDeckSize->setChecked(onLoadAction.host.noCheckDeckSize); + chkNoCheckDeckSizeSecondary->setChecked(onLoadAction.host.noCheckDeckSize); + + for (auto i = 0u; i < sizeofarr(chkCustomRules); ++i) { + if (i == 19) + chkCustomRules[i]->setChecked(duel_param & (DUEL_USE_TRAPS_IN_NEW_CHAIN)); + else if (i == 20) + chkCustomRules[i]->setChecked(duel_param & (DUEL_6_STEP_BATLLE_STEP)); + else if (i == 21) + chkCustomRules[i]->setChecked(duel_param & (DUEL_TRIGGER_WHEN_PRIVATE_KNOWLEDGE)); + else if (i > 21) + chkCustomRules[i]->setChecked(duel_param & (0x100ULL << (i - 3))); + else + chkCustomRules[i]->setChecked(duel_param & (0x100ULL << i)); + } + chkTypeLimit[0]->setChecked(forbiddentypes & TYPE_FUSION); + chkTypeLimit[1]->setChecked(forbiddentypes & TYPE_SYNCHRO); + chkTypeLimit[2]->setChecked(forbiddentypes & TYPE_XYZ); + chkTypeLimit[3]->setChecked(forbiddentypes & TYPE_PENDULUM); + chkTypeLimit[4]->setChecked(forbiddentypes & TYPE_LINK); + + if (onLoadAction.host.serverIndex >= 0) { + isHostingOnline = true; + serverChoice->setSelected(onLoadAction.host.serverIndex); + } else { + isHostingOnline = false; + } + + UpdateDuelParam(); + UpdateExtraRules(true); + + btnHostConfirm->setEnabled(true); + btnHostCancel->setEnabled(true); + stHostPort->setVisible(true); + ebHostPort->setVisible(true); + stHostNotes->setVisible(false); + ebHostNotes->setVisible(true); + wCreateHost->setVisible(true); + ClickButton(btnHostConfirm); + } else if(onLoadAction.join.configured) { + if(onLoadAction.join.serverIndex >= 0) { + isHostingOnline = true; + serverChoice->setSelected(onLoadAction.join.serverIndex); + const auto& serverinfo = ServerLobby::serversVector[onLoadAction.join.serverIndex].Resolved(); + DuelClient::StartClient(serverinfo.address, serverinfo.port, onLoadAction.join.gameId, false); + } else { + isHostingOnline = false; + auto addr = Utils::ToUTF8IfNeeded(onLoadAction.join.host); + DuelClient::StartClient(static_cast(addr.c_str()), onLoadAction.join.port, onLoadAction.join.gameId, false); + } } else { wMainMenu->setVisible(true); } @@ -3674,6 +3767,19 @@ void Game::OnAsyncLoadingCompleted() { onLoadAction.enabled = false; } +bool Game::TrySetDeck(std::string selectedDeck) { + auto selectedDeckW = Utils::ToUnicodeIfNeeded(selectedDeck); + RefreshDeck(cbDeckSelect); + for (irr::u32 i = 0; i < cbDeckSelect->getItemCount(); ++i) { + if (selectedDeckW == cbDeckSelect->getItem(i)) { + cbDeckSelect->setSelected(static_cast(i)); + gGameConfig->lastdeck = selectedDeckW; + return true; + } + } + return false; +} + void Game::SetOnLoadActionReplay(epro::path_string replay) { onLoadAction.enabled = true; onLoadAction.replay = replay; @@ -3682,6 +3788,122 @@ void Game::SetOnLoadActionReplay(epro::path_string replay) { env->setFocus(wLoadingModal); } +void Game::SetOnLoadActionHost(std::string config_raw) { + // host: string = ""; + // port: number = 7911; + // password: string = ""; + // startHand: number = 5; + // startLP: number = 8000; + // drawCount: number = 1; + // timeLimit: number = 0; + // lfList: number = 0; // hash, 0 for the null list + // duelParam: string; // bit field of params, 64 + // noCheckDeckSize: boolean = false; + // noCheckDeckContent: boolean = false; + // noShuffleDeck: boolean = false; + // forbiddenTypes: number = 0; // bit field, 32 + // extraRules: number = 0; // bit field, 16 + // serverIndex: number = -1; // host online + + try { + const auto j = nlohmann::json::parse(config_raw); + if (!j.is_object()) { + return; + } +#define GET(field, type, def) j.template value(field, def) + onLoadAction.host.host = Utils::ToUnicodeIfNeeded(GET("host", std::string, "")); + onLoadAction.host.port = GET("port", int, 7911); + onLoadAction.host.password = Utils::ToUnicodeIfNeeded(GET("password", std::string, "")); + onLoadAction.host.notes = Utils::ToUnicodeIfNeeded(GET("notes", std::string, "")); + onLoadAction.host.team1 = GET("team1", int, 1); + onLoadAction.host.team2 = GET("team2", int, 1); + onLoadAction.host.bestOf = GET("bestOf", int, 1); + onLoadAction.host.startHand = GET("startHand", int, 5); + onLoadAction.host.startLP = GET("startLP", int, 8000); + onLoadAction.host.drawCount = GET("drawCount", int, 1); + onLoadAction.host.timeLimit = GET("timeLimit", int, 0); + onLoadAction.host.lfList = GET("lfList", int, 0); + onLoadAction.host.noCheckDeckSize = GET("noCheckDeckSize", bool, false); + onLoadAction.host.noCheckDeckContent = GET("noCheckDeckContent", bool, false); + onLoadAction.host.noShuffleDeck = GET("noShuffleDeck", bool, false); + onLoadAction.host.duelParam = static_cast(GET("duelParam", uint64_t, DUEL_MODE_MR5)); + onLoadAction.host.forbiddenTypes = static_cast(GET("forbiddenTypes", int, -1)); + onLoadAction.host.extraRules = static_cast(GET("extraRules", int, 0)); + onLoadAction.host.serverIndex = GET("serverIndex", int, -1); +#undef GET + + epro::print(L"parsed host config:\n"); + epro::print(L"host = {}\n", onLoadAction.host.host); + epro::print(L"port = {}\n", onLoadAction.host.port); + epro::print(L"password = {}\n", onLoadAction.host.password); + epro::print(L"team1 = {}\n", onLoadAction.host.team1); + epro::print(L"team2 = {}\n", onLoadAction.host.team2); + epro::print(L"bestOf = {}\n", onLoadAction.host.bestOf); + epro::print(L"startHand = {}\n", onLoadAction.host.startHand); + epro::print(L"startLP = {}\n", onLoadAction.host.startLP); + epro::print(L"drawCount = {}\n", onLoadAction.host.drawCount); + epro::print(L"timeLimit = {}\n", onLoadAction.host.timeLimit); + epro::print(L"lfList = {}\n", onLoadAction.host.lfList); + epro::print(L"noCheckDeckSize = {}\n", onLoadAction.host.noCheckDeckSize); + epro::print(L"noCheckDeckContent = {}\n", onLoadAction.host.noCheckDeckContent); + epro::print(L"noShuffleDeck = {}\n", onLoadAction.host.noShuffleDeck); + epro::print(L"duelParam = {}\n", onLoadAction.host.duelParam); + epro::print(L"forbiddenTypes = {}\n", onLoadAction.host.forbiddenTypes); + epro::print(L"extraRules = {}\n", onLoadAction.host.extraRules); + epro::print(L"serverIndex = {}\n", onLoadAction.host.serverIndex); + + } catch(const std::exception& e) { + ErrorLog("Failed to parse host option \"{}\": {}", config_raw, e.what()); + return; + } + + onLoadAction.host.configured = true; + onLoadAction.enabled = true; + wLoadingModal->setVisible(true); + wMainMenu->setVisible(false); + env->setFocus(wLoadingModal); +} + +void Game::SetOnLoadActionJoin(std::string config_raw) { + // host: string = ""; + // port: number = 7911; + // password: string = ""; + // serverIndex: number = -1; // join online + // gameId: number = 0; // only for + + try { + const auto j = nlohmann::json::parse(config_raw); + if (!j.is_object()) { + return; + } + +#define GET(field, type, def) j.template value(field, def) + onLoadAction.join.host = Utils::ToUnicodeIfNeeded(GET("host", std::string, "")); + onLoadAction.join.port = GET("port", int, 7911); + onLoadAction.join.password = Utils::ToUnicodeIfNeeded(GET("password", std::string, "")); + onLoadAction.join.serverIndex = GET("serverIndex", int, -1); + onLoadAction.join.gameId = GET("gameId", int, 0); +#undef GET + + epro::print(L"parsed join config:\n"); + epro::print(L"host = {}\n", onLoadAction.join.host); + epro::print(L"port = {}\n", onLoadAction.join.port); + epro::print(L"password = {}\n", onLoadAction.join.password); + epro::print(L"serverIndex = {}\n", onLoadAction.join.serverIndex); + epro::print(L"gameId = {}\n", onLoadAction.join.gameId); + + } catch(const std::exception& e) { + ErrorLog("Failed to parse join option \"{}\": {}", config_raw, e.what()); + return; + } + + onLoadAction.join.configured = true; + onLoadAction.enabled = true; + wLoadingModal->setVisible(true); + wMainMenu->setVisible(false); + env->setFocus(wLoadingModal); +} + void Game::OnResize() { env->getRootGUIElement()->setRelativePosition(irr::core::recti(0, 0, window_size.Width, window_size.Height)); { diff --git a/gframe/game.h b/gframe/game.h index 5dacc2b24..1656c15f9 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -217,7 +217,10 @@ class Game { void ReloadElementsStrings(); void OnAsyncLoadingCompleted(); + bool TrySetDeck(std::string selectedDeck); void SetOnLoadActionReplay(epro::path_string file); + void SetOnLoadActionHost(std::string params); + void SetOnLoadActionJoin(std::string params); void OnResize(); template @@ -416,6 +419,36 @@ class Game { bool enabled; bool exitAfter; epro::path_string replay; + struct { + bool configured; + std::wstring host; + int port; + std::wstring password; + int team1; + int team2; + int bestOf; + int startHand; + int startLP; + int drawCount; + int timeLimit; + int lfList; + uint64_t duelParam; + bool noCheckDeckSize; + bool noCheckDeckContent; + bool noShuffleDeck; + int forbiddenTypes; + int extraRules; + int serverIndex; + std::wstring notes; + } host; + struct { + bool configured; + std::wstring host; + int port; + std::wstring password; + int serverIndex; + int gameId; + } join; }; OnLoadAction onLoadAction; diff --git a/gframe/gframe.cpp b/gframe/gframe.cpp index 33c5be807..1fb0e38d4 100644 --- a/gframe/gframe.cpp +++ b/gframe/gframe.cpp @@ -54,11 +54,28 @@ void CheckArguments(const args_t& args) { SetCheckbox(ygo::mainGame->tabSettings.chkEnableSound, false); SetCheckbox(ygo::mainGame->tabSettings.chkEnableMusic, false); } - if (args[LAUNCH_PARAM::REPLAY].enabled && !args[LAUNCH_PARAM::REPLAY].argument.empty()) { + if(args[LAUNCH_PARAM::REPLAY].enabled && !args[LAUNCH_PARAM::REPLAY].argument.empty()) { auto replay = ygo::Utils::ToPathString(args[LAUNCH_PARAM::REPLAY].argument); ygo::mainGame->SetOnLoadActionReplay(replay); } - if (args[LAUNCH_PARAM::EXIT_AFTER].enabled) { + if(args[LAUNCH_PARAM::HOST].enabled && !args[LAUNCH_PARAM::HOST].argument.empty()) { + auto host_params = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::HOST].argument); + ygo::mainGame->SetOnLoadActionHost(host_params); + } + if(args[LAUNCH_PARAM::JOIN].enabled && !args[LAUNCH_PARAM::JOIN].argument.empty()) { + auto join_params = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::JOIN].argument); + ygo::mainGame->SetOnLoadActionJoin(join_params); + } + if(args[LAUNCH_PARAM::SET_NICKNAME].enabled && !args[LAUNCH_PARAM::SET_NICKNAME].argument.empty()) { + auto nickname = ygo::Utils::ToUnicodeIfNeeded(args[LAUNCH_PARAM::SET_NICKNAME].argument); + ygo::mainGame->ebNickName->setText(nickname.c_str()); + ygo::mainGame->ebNickNameOnline->setText(nickname.c_str()); + } + if(args[LAUNCH_PARAM::SET_DECK].enabled && !args[LAUNCH_PARAM::SET_DECK].argument.empty()) { + auto selectedDeck = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::SET_DECK].argument); + ygo::mainGame->TrySetDeck(selectedDeck); + } + if(args[LAUNCH_PARAM::EXIT_AFTER].enabled) { ygo::mainGame->onLoadAction.exitAfter = true; } } From 128de06cef05ea30c58002c2160280cb5c7982b8 Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Tue, 18 Jun 2024 15:25:18 +0200 Subject: [PATCH 08/13] add more exit after logic --- gframe/duelclient.cpp | 4 ++++ gframe/menu_handler.cpp | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/gframe/duelclient.cpp b/gframe/duelclient.cpp index 0fd10b263..5b5582c9b 100644 --- a/gframe/duelclient.cpp +++ b/gframe/duelclient.cpp @@ -1034,6 +1034,10 @@ void DuelClient::HandleSTOCPacketLanAsync(const std::vector& data) { mainGame->HideElement(mainGame->wANCard); mainGame->PopupElement(mainGame->wMessage); mainGame->actionSignal.Wait(lock); + if (mainGame->onLoadAction.exitAfter) { + mainGame->device->closeDevice(); + break; + } mainGame->closeDuelWindow = true; mainGame->closeDoneSignal.Wait(lock); mainGame->dInfo.isInLobby = false; diff --git a/gframe/menu_handler.cpp b/gframe/menu_handler.cpp index 4e8df1a56..6369ca0e1 100644 --- a/gframe/menu_handler.cpp +++ b/gframe/menu_handler.cpp @@ -342,6 +342,12 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { } case BUTTON_HP_CANCEL: { DuelClient::StopClient(); + + if(mainGame->onLoadAction.exitAfter) { + mainGame->device->closeDevice(); + break; + } + mainGame->dInfo.isInLobby = false; mainGame->btnCreateHost->setEnabled(mainGame->coreloaded); mainGame->btnJoinHost->setEnabled(true); From cbbc1d35a227a46c7adcc13cf99bc086df81739d Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Fri, 21 Jun 2024 09:29:15 +0200 Subject: [PATCH 09/13] add -deckbuilder cli argument to open the deck editor or test hand --- gframe/cli_args.h | 1 + gframe/deck_con.cpp | 4 + gframe/edopro_main.cpp | 2 + gframe/game.cpp | 392 ++++++++++++++++++++++++----------------- gframe/game.h | 14 +- gframe/gframe.cpp | 26 +-- 6 files changed, 269 insertions(+), 170 deletions(-) diff --git a/gframe/cli_args.h b/gframe/cli_args.h index 564925ab9..d0d53af82 100644 --- a/gframe/cli_args.h +++ b/gframe/cli_args.h @@ -17,6 +17,7 @@ enum LAUNCH_PARAM { REPLAY, HOST, JOIN, + DECKBUILDER, SET_NICKNAME, SET_DECK, COUNT, diff --git a/gframe/deck_con.cpp b/gframe/deck_con.cpp index 8668b1f8b..bc92de0a6 100644 --- a/gframe/deck_con.cpp +++ b/gframe/deck_con.cpp @@ -109,6 +109,10 @@ void DeckBuilder::Initialize(bool refresh) { mainGame->device->setEventReceiver(this); } void DeckBuilder::Terminate(bool showmenu) { + if (showmenu && mainGame->onLoadAction.exitAfter) { + mainGame->device->closeDevice(); + return; + } mainGame->is_building = false; mainGame->is_siding = false; if(showmenu) { diff --git a/gframe/edopro_main.cpp b/gframe/edopro_main.cpp index 46bdebcb0..edb14e911 100644 --- a/gframe/edopro_main.cpp +++ b/gframe/edopro_main.cpp @@ -45,6 +45,8 @@ auto GetOption(epro::path_stringview option) { return LAUNCH_PARAM::HOST; if(option == EPRO_TEXT("join"_sv)) return LAUNCH_PARAM::JOIN; + if(option == EPRO_TEXT("deckbuilder")) + return LAUNCH_PARAM::DECKBUILDER; return LAUNCH_PARAM::COUNT; } diff --git a/gframe/game.cpp b/gframe/game.cpp index d1217963e..eadaa9631 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -1159,7 +1159,6 @@ void Game::LoadCoreFromRepos() { btnHandTestSettings->setEnabled(true); stHandTestSettings->setEnabled(true); } - OnAsyncLoadingCompleted(); break; } cores_to_load.clear(); @@ -2035,6 +2034,11 @@ bool Game::MainLoop() { LoadCoreFromRepos(); } #endif //YGOPRO_BUILD_DLL + + if (cores_to_load.size() == 0 && gRepoManager->GetUpdatingReposNumber() == 0) { + OnAsyncLoadingCompleted(); + } + for(auto& repo : gRepoManager->GetRepoStatus()) { repoInfoGui[repo.first].progress1->setProgress(repo.second); repoInfoGui[repo.first].progress2->setProgress(repo.second); @@ -2716,9 +2720,6 @@ void Game::ParseGithubRepositories(const std::vector& repos) { if(deckBuilder.results.size()) deckBuilder.StartFilter(true); } - if(gRepoManager->GetUpdatingReposNumber() == 0) { - OnAsyncLoadingCompleted(); - } } void Game::UpdateRepoInfo(const GitRepo* repo, RepoGui* grepo) { if(repo->history.error.size()) { @@ -3651,128 +3652,147 @@ void Game::ReloadElementsStrings() { } void Game::OnAsyncLoadingCompleted() { + if(!onLoadAction.enabled) { + return; + } + gdeckManager->StopDummyLoading(); ReloadElementsStrings(); + onLoadAction.enabled = false; - if(onLoadAction.enabled) { - wLoadingModal->setVisible(false); - //process onload cmd parameters - if(!onLoadAction.replay.empty()) { - open_file = true; - open_file_name = onLoadAction.replay; - ClickButton(btnReplayMode); - menuHandler.LoadReplay(); - ReplayMode::Pause(true, false); - btnReplayStart->setVisible(true); - btnReplayPause->setVisible(false); - btnReplayStep->setVisible(true); - btnReplayUndo->setVisible(true); - } else if(onLoadAction.host.configured) { - ebServerName->setText(onLoadAction.host.host.c_str()); - ebHostPort->setText(fmt::to_wstring(onLoadAction.host.port).c_str()); - ebServerPass->setText(onLoadAction.host.password.c_str()); - ebStartLP->setText(fmt::to_wstring(onLoadAction.host.startLP).c_str()); - ebTeam1->setText(fmt::to_wstring(onLoadAction.host.team1).c_str()); - ebTeam2->setText(fmt::to_wstring(onLoadAction.host.team2).c_str()); - ebBestOf->setText(fmt::to_wstring(onLoadAction.host.bestOf).c_str()); - ebStartHand->setText(fmt::to_wstring(onLoadAction.host.startHand).c_str()); - ebDrawCount->setText(fmt::to_wstring(onLoadAction.host.drawCount).c_str()); - ebHostNotes->setText(fmt::to_wstring(onLoadAction.host.notes).c_str()); - - RefreshLFLists(); - for(irr::u32 i = 0; i < gdeckManager->_lfList.size(); ++i) { - if(gdeckManager->_lfList[i].hash == onLoadAction.host.lfList) { - cbHostLFList->setSelected(i); - } + wLoadingModal->setVisible(false); + //process onload cmd parameters + if(!onLoadAction.replay.empty()) { + open_file = true; + open_file_name = onLoadAction.replay; + ClickButton(btnReplayMode); + menuHandler.LoadReplay(); + ReplayMode::Pause(true, false); + btnReplayStart->setVisible(true); + btnReplayPause->setVisible(false); + btnReplayStep->setVisible(true); + btnReplayUndo->setVisible(true); + } else if(onLoadAction.host.configured) { + ebServerName->setText(onLoadAction.host.host.c_str()); + ebHostPort->setText(fmt::to_wstring(onLoadAction.host.port).c_str()); + ebServerPass->setText(onLoadAction.host.password.c_str()); + ebStartLP->setText(fmt::to_wstring(onLoadAction.host.startLP).c_str()); + ebTeam1->setText(fmt::to_wstring(onLoadAction.host.team1).c_str()); + ebTeam2->setText(fmt::to_wstring(onLoadAction.host.team2).c_str()); + ebBestOf->setText(fmt::to_wstring(onLoadAction.host.bestOf).c_str()); + ebStartHand->setText(fmt::to_wstring(onLoadAction.host.startHand).c_str()); + ebDrawCount->setText(fmt::to_wstring(onLoadAction.host.drawCount).c_str()); + ebHostNotes->setText(fmt::to_wstring(onLoadAction.host.notes).c_str()); + + RefreshLFLists(); + for(irr::u32 i = 0; i < gdeckManager->_lfList.size(); ++i) { + if(gdeckManager->_lfList[i].hash == onLoadAction.host.lfList) { + cbHostLFList->setSelected(i); } + } - duel_param = onLoadAction.host.duelParam; - auto duel_param_ignoretcg = duel_param & ~DUEL_TCG_SEGOC_NONPUBLIC; - extra_rules = static_cast(onLoadAction.host.extraRules); - if (onLoadAction.host.forbiddenTypes < 0) { - if (duel_param == DUEL_MODE_SPEED) forbiddentypes = DUEL_MODE_MR5_FORB; - else if (duel_param == DUEL_MODE_RUSH) forbiddentypes = DUEL_MODE_MR5_FORB; - else if (duel_param == DUEL_MODE_GOAT) forbiddentypes = DUEL_MODE_MR1_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR1) forbiddentypes = DUEL_MODE_MR1_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR2) forbiddentypes = DUEL_MODE_MR2_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR3) forbiddentypes = DUEL_MODE_MR3_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR4) forbiddentypes = DUEL_MODE_MR4_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR5) forbiddentypes = DUEL_MODE_MR5_FORB; - else forbiddentypes = DUEL_MODE_MR5_FORB; - } - else { - forbiddentypes = static_cast(onLoadAction.host.forbiddenTypes); - } + duel_param = onLoadAction.host.duelParam; + auto duel_param_ignoretcg = duel_param & ~DUEL_TCG_SEGOC_NONPUBLIC; + extra_rules = static_cast(onLoadAction.host.extraRules); + if (onLoadAction.host.forbiddenTypes < 0) { + if (duel_param == DUEL_MODE_SPEED) forbiddentypes = DUEL_MODE_MR5_FORB; + else if (duel_param == DUEL_MODE_RUSH) forbiddentypes = DUEL_MODE_MR5_FORB; + else if (duel_param == DUEL_MODE_GOAT) forbiddentypes = DUEL_MODE_MR1_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR1) forbiddentypes = DUEL_MODE_MR1_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR2) forbiddentypes = DUEL_MODE_MR2_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR3) forbiddentypes = DUEL_MODE_MR3_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR4) forbiddentypes = DUEL_MODE_MR4_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR5) forbiddentypes = DUEL_MODE_MR5_FORB; + else forbiddentypes = DUEL_MODE_MR5_FORB; + } + else { + forbiddentypes = static_cast(onLoadAction.host.forbiddenTypes); + } - chkTcgRulings->setChecked(duel_param & DUEL_TCG_SEGOC_NONPUBLIC); - chkNoShuffleDeck->setChecked(onLoadAction.host.noShuffleDeck); - chkNoShuffleDeckSecondary->setChecked(onLoadAction.host.noShuffleDeck); - chkNoCheckDeckContent->setChecked(onLoadAction.host.noCheckDeckContent); - chkNoCheckDeckContentSecondary->setChecked(onLoadAction.host.noCheckDeckContent); - chkNoCheckDeckSize->setChecked(onLoadAction.host.noCheckDeckSize); - chkNoCheckDeckSizeSecondary->setChecked(onLoadAction.host.noCheckDeckSize); - - for (auto i = 0u; i < sizeofarr(chkCustomRules); ++i) { - if (i == 19) - chkCustomRules[i]->setChecked(duel_param & (DUEL_USE_TRAPS_IN_NEW_CHAIN)); - else if (i == 20) - chkCustomRules[i]->setChecked(duel_param & (DUEL_6_STEP_BATLLE_STEP)); - else if (i == 21) - chkCustomRules[i]->setChecked(duel_param & (DUEL_TRIGGER_WHEN_PRIVATE_KNOWLEDGE)); - else if (i > 21) - chkCustomRules[i]->setChecked(duel_param & (0x100ULL << (i - 3))); - else - chkCustomRules[i]->setChecked(duel_param & (0x100ULL << i)); - } - chkTypeLimit[0]->setChecked(forbiddentypes & TYPE_FUSION); - chkTypeLimit[1]->setChecked(forbiddentypes & TYPE_SYNCHRO); - chkTypeLimit[2]->setChecked(forbiddentypes & TYPE_XYZ); - chkTypeLimit[3]->setChecked(forbiddentypes & TYPE_PENDULUM); - chkTypeLimit[4]->setChecked(forbiddentypes & TYPE_LINK); - - if (onLoadAction.host.serverIndex >= 0) { - isHostingOnline = true; - serverChoice->setSelected(onLoadAction.host.serverIndex); - } else { - isHostingOnline = false; - } + chkTcgRulings->setChecked(duel_param & DUEL_TCG_SEGOC_NONPUBLIC); + chkNoShuffleDeck->setChecked(onLoadAction.host.noShuffleDeck); + chkNoShuffleDeckSecondary->setChecked(onLoadAction.host.noShuffleDeck); + chkNoCheckDeckContent->setChecked(onLoadAction.host.noCheckDeckContent); + chkNoCheckDeckContentSecondary->setChecked(onLoadAction.host.noCheckDeckContent); + chkNoCheckDeckSize->setChecked(onLoadAction.host.noCheckDeckSize); + chkNoCheckDeckSizeSecondary->setChecked(onLoadAction.host.noCheckDeckSize); + + for (auto i = 0u; i < sizeofarr(chkCustomRules); ++i) { + if (i == 19) + chkCustomRules[i]->setChecked(duel_param & (DUEL_USE_TRAPS_IN_NEW_CHAIN)); + else if (i == 20) + chkCustomRules[i]->setChecked(duel_param & (DUEL_6_STEP_BATLLE_STEP)); + else if (i == 21) + chkCustomRules[i]->setChecked(duel_param & (DUEL_TRIGGER_WHEN_PRIVATE_KNOWLEDGE)); + else if (i > 21) + chkCustomRules[i]->setChecked(duel_param & (0x100ULL << (i - 3))); + else + chkCustomRules[i]->setChecked(duel_param & (0x100ULL << i)); + } + chkTypeLimit[0]->setChecked(forbiddentypes & TYPE_FUSION); + chkTypeLimit[1]->setChecked(forbiddentypes & TYPE_SYNCHRO); + chkTypeLimit[2]->setChecked(forbiddentypes & TYPE_XYZ); + chkTypeLimit[3]->setChecked(forbiddentypes & TYPE_PENDULUM); + chkTypeLimit[4]->setChecked(forbiddentypes & TYPE_LINK); + + if (onLoadAction.host.serverIndex >= 0) { + isHostingOnline = true; + serverChoice->setSelected(onLoadAction.host.serverIndex); + } else { + isHostingOnline = false; + } - UpdateDuelParam(); - UpdateExtraRules(true); - - btnHostConfirm->setEnabled(true); - btnHostCancel->setEnabled(true); - stHostPort->setVisible(true); - ebHostPort->setVisible(true); - stHostNotes->setVisible(false); - ebHostNotes->setVisible(true); - wCreateHost->setVisible(true); - ClickButton(btnHostConfirm); - } else if(onLoadAction.join.configured) { - if(onLoadAction.join.serverIndex >= 0) { - isHostingOnline = true; - serverChoice->setSelected(onLoadAction.join.serverIndex); - const auto& serverinfo = ServerLobby::serversVector[onLoadAction.join.serverIndex].Resolved(); - DuelClient::StartClient(serverinfo.address, serverinfo.port, onLoadAction.join.gameId, false); - } else { - isHostingOnline = false; - auto addr = Utils::ToUTF8IfNeeded(onLoadAction.join.host); - DuelClient::StartClient(static_cast(addr.c_str()), onLoadAction.join.port, onLoadAction.join.gameId, false); - } + UpdateDuelParam(); + UpdateExtraRules(true); + + btnHostConfirm->setEnabled(true); + btnHostCancel->setEnabled(true); + stHostPort->setVisible(true); + ebHostPort->setVisible(true); + stHostNotes->setVisible(false); + ebHostNotes->setVisible(true); + wCreateHost->setVisible(true); + ClickButton(btnHostConfirm); + } else if(onLoadAction.join.configured) { + if(onLoadAction.join.serverIndex >= 0) { + isHostingOnline = true; + serverChoice->setSelected(onLoadAction.join.serverIndex); + const auto& serverinfo = ServerLobby::serversVector[onLoadAction.join.serverIndex].Resolved(); + DuelClient::StartClient(serverinfo.address, serverinfo.port, onLoadAction.join.gameId, false); } else { - wMainMenu->setVisible(true); + isHostingOnline = false; + auto addr = Utils::ToUTF8IfNeeded(onLoadAction.join.host); + DuelClient::StartClient(static_cast(addr.c_str()), onLoadAction.join.port, onLoadAction.join.gameId, false); + } + } else if(onLoadAction.deckbuilder.configured) { + wMainMenu->setVisible(true); + deckBuilder.SetCurrentDeckFromFile(Utils::ToPathString(cbDBDecks->getItem(cbDBDecks->getSelected())), true); + ebDeckname->setText(L""); + HideElement(mainGame->wMainMenu); + deckBuilder.Initialize(); + if (onLoadAction.deckbuilder.testHand.configured) { + deckBuilder.Terminate(false); + SingleMode::DuelOptions options("hand-test-mode"); + options.handTestNoOpponent = onLoadAction.deckbuilder.testHand.noOpponent; + options.startingDrawCount = onLoadAction.deckbuilder.testHand.startingHand; + options.duelFlags = onLoadAction.deckbuilder.testHand.duelParam; + options.duelFlags |= onLoadAction.deckbuilder.testHand.dontShuffleDeck ? DUEL_PSEUDO_SHUFFLE : 0; + SingleMode::singleSignal.SetNoWait(false); + SingleMode::StartPlay(std::move(options)); } + } else { + wMainMenu->setVisible(true); } - - onLoadAction.enabled = false; } bool Game::TrySetDeck(std::string selectedDeck) { auto selectedDeckW = Utils::ToUnicodeIfNeeded(selectedDeck); RefreshDeck(cbDeckSelect); - for (irr::u32 i = 0; i < cbDeckSelect->getItemCount(); ++i) { + RefreshDeck(cbDBDecks); + for(irr::u32 i = 0; i < cbDeckSelect->getItemCount(); ++i) { if (selectedDeckW == cbDeckSelect->getItem(i)) { cbDeckSelect->setSelected(static_cast(i)); + cbDBDecks->setSelected(static_cast(i)); gGameConfig->lastdeck = selectedDeckW; return true; } @@ -3805,59 +3825,61 @@ void Game::SetOnLoadActionHost(std::string config_raw) { // extraRules: number = 0; // bit field, 16 // serverIndex: number = -1; // host online + auto& host = onLoadAction.host; + try { const auto j = nlohmann::json::parse(config_raw); if (!j.is_object()) { return; } #define GET(field, type, def) j.template value(field, def) - onLoadAction.host.host = Utils::ToUnicodeIfNeeded(GET("host", std::string, "")); - onLoadAction.host.port = GET("port", int, 7911); - onLoadAction.host.password = Utils::ToUnicodeIfNeeded(GET("password", std::string, "")); - onLoadAction.host.notes = Utils::ToUnicodeIfNeeded(GET("notes", std::string, "")); - onLoadAction.host.team1 = GET("team1", int, 1); - onLoadAction.host.team2 = GET("team2", int, 1); - onLoadAction.host.bestOf = GET("bestOf", int, 1); - onLoadAction.host.startHand = GET("startHand", int, 5); - onLoadAction.host.startLP = GET("startLP", int, 8000); - onLoadAction.host.drawCount = GET("drawCount", int, 1); - onLoadAction.host.timeLimit = GET("timeLimit", int, 0); - onLoadAction.host.lfList = GET("lfList", int, 0); - onLoadAction.host.noCheckDeckSize = GET("noCheckDeckSize", bool, false); - onLoadAction.host.noCheckDeckContent = GET("noCheckDeckContent", bool, false); - onLoadAction.host.noShuffleDeck = GET("noShuffleDeck", bool, false); - onLoadAction.host.duelParam = static_cast(GET("duelParam", uint64_t, DUEL_MODE_MR5)); - onLoadAction.host.forbiddenTypes = static_cast(GET("forbiddenTypes", int, -1)); - onLoadAction.host.extraRules = static_cast(GET("extraRules", int, 0)); - onLoadAction.host.serverIndex = GET("serverIndex", int, -1); + host.host = Utils::ToUnicodeIfNeeded(GET("host", std::string, "")); + host.port = GET("port", int, 7911); + host.password = Utils::ToUnicodeIfNeeded(GET("password", std::string, "")); + host.notes = Utils::ToUnicodeIfNeeded(GET("notes", std::string, "")); + host.team1 = GET("team1", int, 1); + host.team2 = GET("team2", int, 1); + host.bestOf = GET("bestOf", int, 1); + host.startHand = GET("startHand", int, 5); + host.startLP = GET("startLP", int, 8000); + host.drawCount = GET("drawCount", int, 1); + host.timeLimit = GET("timeLimit", int, 0); + host.lfList = GET("lfList", uint32_t, 0); + host.noCheckDeckSize = GET("noCheckDeckSize", bool, false); + host.noCheckDeckContent = GET("noCheckDeckContent", bool, false); + host.noShuffleDeck = GET("noShuffleDeck", bool, false); + host.duelParam = static_cast(GET("duelParam", uint64_t, DUEL_MODE_MR5)); + host.forbiddenTypes = static_cast(GET("forbiddenTypes", int, -1)); + host.extraRules = static_cast(GET("extraRules", int, 0)); + host.serverIndex = GET("serverIndex", int, -1); #undef GET epro::print(L"parsed host config:\n"); - epro::print(L"host = {}\n", onLoadAction.host.host); - epro::print(L"port = {}\n", onLoadAction.host.port); - epro::print(L"password = {}\n", onLoadAction.host.password); - epro::print(L"team1 = {}\n", onLoadAction.host.team1); - epro::print(L"team2 = {}\n", onLoadAction.host.team2); - epro::print(L"bestOf = {}\n", onLoadAction.host.bestOf); - epro::print(L"startHand = {}\n", onLoadAction.host.startHand); - epro::print(L"startLP = {}\n", onLoadAction.host.startLP); - epro::print(L"drawCount = {}\n", onLoadAction.host.drawCount); - epro::print(L"timeLimit = {}\n", onLoadAction.host.timeLimit); - epro::print(L"lfList = {}\n", onLoadAction.host.lfList); - epro::print(L"noCheckDeckSize = {}\n", onLoadAction.host.noCheckDeckSize); - epro::print(L"noCheckDeckContent = {}\n", onLoadAction.host.noCheckDeckContent); - epro::print(L"noShuffleDeck = {}\n", onLoadAction.host.noShuffleDeck); - epro::print(L"duelParam = {}\n", onLoadAction.host.duelParam); - epro::print(L"forbiddenTypes = {}\n", onLoadAction.host.forbiddenTypes); - epro::print(L"extraRules = {}\n", onLoadAction.host.extraRules); - epro::print(L"serverIndex = {}\n", onLoadAction.host.serverIndex); + epro::print(L"host = {}\n", host.host); + epro::print(L"port = {}\n", host.port); + epro::print(L"password = {}\n", host.password); + epro::print(L"team1 = {}\n", host.team1); + epro::print(L"team2 = {}\n", host.team2); + epro::print(L"bestOf = {}\n", host.bestOf); + epro::print(L"startHand = {}\n", host.startHand); + epro::print(L"startLP = {}\n", host.startLP); + epro::print(L"drawCount = {}\n", host.drawCount); + epro::print(L"timeLimit = {}\n", host.timeLimit); + epro::print(L"lfList = {}\n", host.lfList); + epro::print(L"noCheckDeckSize = {}\n", host.noCheckDeckSize); + epro::print(L"noCheckDeckContent = {}\n", host.noCheckDeckContent); + epro::print(L"noShuffleDeck = {}\n", host.noShuffleDeck); + epro::print(L"duelParam = {}\n", host.duelParam); + epro::print(L"forbiddenTypes = {}\n", host.forbiddenTypes); + epro::print(L"extraRules = {}\n", host.extraRules); + epro::print(L"serverIndex = {}\n", host.serverIndex); } catch(const std::exception& e) { ErrorLog("Failed to parse host option \"{}\": {}", config_raw, e.what()); return; } - onLoadAction.host.configured = true; + host.configured = true; onLoadAction.enabled = true; wLoadingModal->setVisible(true); wMainMenu->setVisible(false); @@ -3871,6 +3893,8 @@ void Game::SetOnLoadActionJoin(std::string config_raw) { // serverIndex: number = -1; // join online // gameId: number = 0; // only for + auto& join = onLoadAction.join; + try { const auto j = nlohmann::json::parse(config_raw); if (!j.is_object()) { @@ -3878,26 +3902,78 @@ void Game::SetOnLoadActionJoin(std::string config_raw) { } #define GET(field, type, def) j.template value(field, def) - onLoadAction.join.host = Utils::ToUnicodeIfNeeded(GET("host", std::string, "")); - onLoadAction.join.port = GET("port", int, 7911); - onLoadAction.join.password = Utils::ToUnicodeIfNeeded(GET("password", std::string, "")); - onLoadAction.join.serverIndex = GET("serverIndex", int, -1); - onLoadAction.join.gameId = GET("gameId", int, 0); + join.host = Utils::ToUnicodeIfNeeded(GET("host", std::string, "")); + join.port = GET("port", int, 7911); + join.password = Utils::ToUnicodeIfNeeded(GET("password", std::string, "")); + join.serverIndex = GET("serverIndex", int, -1); + join.gameId = GET("gameId", int, 0); #undef GET epro::print(L"parsed join config:\n"); - epro::print(L"host = {}\n", onLoadAction.join.host); - epro::print(L"port = {}\n", onLoadAction.join.port); - epro::print(L"password = {}\n", onLoadAction.join.password); - epro::print(L"serverIndex = {}\n", onLoadAction.join.serverIndex); - epro::print(L"gameId = {}\n", onLoadAction.join.gameId); + epro::print(L"host = {}\n", join.host); + epro::print(L"port = {}\n", join.port); + epro::print(L"password = {}\n", join.password); + epro::print(L"serverIndex = {}\n", join.serverIndex); + epro::print(L"gameId = {}\n", join.gameId); } catch(const std::exception& e) { ErrorLog("Failed to parse join option \"{}\": {}", config_raw, e.what()); return; } - onLoadAction.join.configured = true; + join.configured = true; + onLoadAction.enabled = true; + wLoadingModal->setVisible(true); + wMainMenu->setVisible(false); + env->setFocus(wLoadingModal); +} + +void Game::SetOnLoadActionDeckbuilder(std::string config_raw) { + // testHand?: { + // noOpponent?: boolean = false; + // dontShuffleDeck?: boolean = false; + // startingHand?: number = 5; + // duelParam?: number = DUEL_MODE_MR5; + // saveReplay?: boolean = false; + // }; + + auto& db = onLoadAction.deckbuilder; + + try { + const auto j = nlohmann::json::parse(config_raw); + if (!j.is_object()) { + return; + } + +#define GET(from, field, type, def) from.template value(field, def) + auto testHandIt = j.find("testHand"); + if(testHandIt != j.end()) { + auto& testHand = *testHandIt; + db.testHand.noOpponent = GET(testHand, "noOpponent", bool, false); + db.testHand.dontShuffleDeck = GET(testHand, "dontShuffleDeck", bool, false); + db.testHand.startingHand = GET(testHand, "startingHand", int, 5); + db.testHand.saveReplay = GET(testHand, "saveReplay", bool, false); + db.testHand.duelParam = static_cast(GET(testHand, "duelParam", uint64_t, DUEL_MODE_MR5)); + db.testHand.configured = true; + } +#undef GET + + epro::print(L"parsed deckbuilder config:\n"); + if(db.testHand.configured) { + epro::print(L"testHand.noOpponent = {}\n", db.testHand.noOpponent); + epro::print(L"testHand.dontShuffleDeck = {}\n", db.testHand.dontShuffleDeck); + epro::print(L"testHand.startingHand = {}\n", db.testHand.startingHand); + epro::print(L"testHand.saveReplay = {}\n", db.testHand.saveReplay); + epro::print(L"testHand.duelParam = {}\n", db.testHand.duelParam); + } else { + epro::print(L"testHand = null\n"); + } + } catch (const std::exception& e) { + ErrorLog("Failed to parse join option \"{}\": {}", config_raw, e.what()); + return; + } + + db.configured = true; onLoadAction.enabled = true; wLoadingModal->setVisible(true); wMainMenu->setVisible(false); diff --git a/gframe/game.h b/gframe/game.h index 1656c15f9..97520bffd 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -221,6 +221,7 @@ class Game { void SetOnLoadActionReplay(epro::path_string file); void SetOnLoadActionHost(std::string params); void SetOnLoadActionJoin(std::string params); + void SetOnLoadActionDeckbuilder(std::string params); void OnResize(); template @@ -431,7 +432,7 @@ class Game { int startLP; int drawCount; int timeLimit; - int lfList; + uint32_t lfList; uint64_t duelParam; bool noCheckDeckSize; bool noCheckDeckContent; @@ -449,6 +450,17 @@ class Game { int serverIndex; int gameId; } join; + struct { + bool configured; + struct { + bool configured; + bool noOpponent; + bool dontShuffleDeck; + int startingHand; + uint64_t duelParam; + bool saveReplay; + } testHand; + } deckbuilder; }; OnLoadAction onLoadAction; diff --git a/gframe/gframe.cpp b/gframe/gframe.cpp index 1fb0e38d4..d00c01e86 100644 --- a/gframe/gframe.cpp +++ b/gframe/gframe.cpp @@ -54,6 +54,18 @@ void CheckArguments(const args_t& args) { SetCheckbox(ygo::mainGame->tabSettings.chkEnableSound, false); SetCheckbox(ygo::mainGame->tabSettings.chkEnableMusic, false); } + if(args[LAUNCH_PARAM::SET_NICKNAME].enabled && !args[LAUNCH_PARAM::SET_NICKNAME].argument.empty()) { + auto nickname = ygo::Utils::ToUnicodeIfNeeded(args[LAUNCH_PARAM::SET_NICKNAME].argument); + ygo::mainGame->ebNickName->setText(nickname.c_str()); + ygo::mainGame->ebNickNameOnline->setText(nickname.c_str()); + } + if(args[LAUNCH_PARAM::SET_DECK].enabled && !args[LAUNCH_PARAM::SET_DECK].argument.empty()) { + auto selectedDeck = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::SET_DECK].argument); + ygo::mainGame->TrySetDeck(selectedDeck); + } + if(args[LAUNCH_PARAM::EXIT_AFTER].enabled) { + ygo::mainGame->onLoadAction.exitAfter = true; + } if(args[LAUNCH_PARAM::REPLAY].enabled && !args[LAUNCH_PARAM::REPLAY].argument.empty()) { auto replay = ygo::Utils::ToPathString(args[LAUNCH_PARAM::REPLAY].argument); ygo::mainGame->SetOnLoadActionReplay(replay); @@ -66,17 +78,9 @@ void CheckArguments(const args_t& args) { auto join_params = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::JOIN].argument); ygo::mainGame->SetOnLoadActionJoin(join_params); } - if(args[LAUNCH_PARAM::SET_NICKNAME].enabled && !args[LAUNCH_PARAM::SET_NICKNAME].argument.empty()) { - auto nickname = ygo::Utils::ToUnicodeIfNeeded(args[LAUNCH_PARAM::SET_NICKNAME].argument); - ygo::mainGame->ebNickName->setText(nickname.c_str()); - ygo::mainGame->ebNickNameOnline->setText(nickname.c_str()); - } - if(args[LAUNCH_PARAM::SET_DECK].enabled && !args[LAUNCH_PARAM::SET_DECK].argument.empty()) { - auto selectedDeck = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::SET_DECK].argument); - ygo::mainGame->TrySetDeck(selectedDeck); - } - if(args[LAUNCH_PARAM::EXIT_AFTER].enabled) { - ygo::mainGame->onLoadAction.exitAfter = true; + if(args[LAUNCH_PARAM::DECKBUILDER].enabled && !args[LAUNCH_PARAM::DECKBUILDER].argument.empty()) { + auto deckbuilder_params = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::DECKBUILDER].argument); + ygo::mainGame->SetOnLoadActionDeckbuilder(deckbuilder_params); } } From 17d2146e224327646aa570dd5d3e4f005d1b45c7 Mon Sep 17 00:00:00 2001 From: n1xx1 Date: Wed, 26 Jun 2024 11:44:27 +0200 Subject: [PATCH 10/13] remove onLoadAction, force read only repos if needed --- gframe/data_handler.cpp | 2 + gframe/deck_con.cpp | 2 +- gframe/duelclient.cpp | 2 +- gframe/game.cpp | 327 +++++++++++++++++++--------------------- gframe/game.h | 59 +------- gframe/gframe.cpp | 23 ++- gframe/menu_handler.cpp | 2 +- gframe/replay_mode.cpp | 2 +- 8 files changed, 179 insertions(+), 240 deletions(-) diff --git a/gframe/data_handler.cpp b/gframe/data_handler.cpp index 458edb2a6..89a95f028 100644 --- a/gframe/data_handler.cpp +++ b/gframe/data_handler.cpp @@ -138,6 +138,8 @@ DataHandler::DataHandler() { gitManager->ToggleReadOnly(cli_args[REPOS_READ_ONLY].enabled); gitManager->LoadRepositoriesFromJson(configs->user_configs); gitManager->LoadRepositoriesFromJson(configs->configs); + if(gitManager->TerminateIfNothingLoaded()) + deckManager->StopDummyLoading(); imageDownloader = std::make_unique(); LoadDatabases(); LoadPicUrls(); diff --git a/gframe/deck_con.cpp b/gframe/deck_con.cpp index bc92de0a6..5b379e69b 100644 --- a/gframe/deck_con.cpp +++ b/gframe/deck_con.cpp @@ -109,7 +109,7 @@ void DeckBuilder::Initialize(bool refresh) { mainGame->device->setEventReceiver(this); } void DeckBuilder::Terminate(bool showmenu) { - if (showmenu && mainGame->onLoadAction.exitAfter) { + if (showmenu && mainGame->exitAfter) { mainGame->device->closeDevice(); return; } diff --git a/gframe/duelclient.cpp b/gframe/duelclient.cpp index 5b5582c9b..568d56b3e 100644 --- a/gframe/duelclient.cpp +++ b/gframe/duelclient.cpp @@ -1034,7 +1034,7 @@ void DuelClient::HandleSTOCPacketLanAsync(const std::vector& data) { mainGame->HideElement(mainGame->wANCard); mainGame->PopupElement(mainGame->wMessage); mainGame->actionSignal.Wait(lock); - if (mainGame->onLoadAction.exitAfter) { + if (mainGame->exitAfter) { mainGame->device->closeDevice(); break; } diff --git a/gframe/game.cpp b/gframe/game.cpp index eadaa9631..48a71c6a2 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -1108,16 +1108,6 @@ void Game::Initialize() { env->getRootGUIElement()->bringToFront(wBtnSettings); env->getRootGUIElement()->bringToFront(mTopMenu); env->setFocus(wMainMenu); - - //loading modal - wLoadingModal = env->addWindow(Scale(490, 240, 840, 300), false, L""); - wLoadingModal->setVisible(false); - wLoadingModal->getCloseButton()->setVisible(false); - SetCentered(wLoadingModal); - auto stLoadingMessage = irr::gui::CGUICustomText::addCustomText(L"Loading...", true, env, wLoadingModal, -1, Scale(0, 0, 350, 60), true); - stLoadingMessage->setWordWrap(true); - stLoadingMessage->setBackgroundColor(skin::DUELFIELD_ANNOUNCE_TEXT_BACKGROUND_COLOR_VAL); - stLoadingMessage->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER); } bool Game::LoadCore() { @@ -2036,7 +2026,8 @@ bool Game::MainLoop() { #endif //YGOPRO_BUILD_DLL if (cores_to_load.size() == 0 && gRepoManager->GetUpdatingReposNumber() == 0) { - OnAsyncLoadingCompleted(); + gdeckManager->StopDummyLoading(); + ReloadElementsStrings(); } for(auto& repo : gRepoManager->GetRepoStatus()) { @@ -2720,6 +2711,10 @@ void Game::ParseGithubRepositories(const std::vector& repos) { if(deckBuilder.results.size()) deckBuilder.StartFilter(true); } + if (gRepoManager->GetUpdatingReposNumber() == 0) { + gdeckManager->StopDummyLoading(); + ReloadElementsStrings(); + } } void Game::UpdateRepoInfo(const GitRepo* repo, RepoGui* grepo) { if(repo->history.error.size()) { @@ -3651,140 +3646,6 @@ void Game::ReloadElementsStrings() { ReloadCBCurrentSkin(); } -void Game::OnAsyncLoadingCompleted() { - if(!onLoadAction.enabled) { - return; - } - - gdeckManager->StopDummyLoading(); - ReloadElementsStrings(); - onLoadAction.enabled = false; - - wLoadingModal->setVisible(false); - //process onload cmd parameters - if(!onLoadAction.replay.empty()) { - open_file = true; - open_file_name = onLoadAction.replay; - ClickButton(btnReplayMode); - menuHandler.LoadReplay(); - ReplayMode::Pause(true, false); - btnReplayStart->setVisible(true); - btnReplayPause->setVisible(false); - btnReplayStep->setVisible(true); - btnReplayUndo->setVisible(true); - } else if(onLoadAction.host.configured) { - ebServerName->setText(onLoadAction.host.host.c_str()); - ebHostPort->setText(fmt::to_wstring(onLoadAction.host.port).c_str()); - ebServerPass->setText(onLoadAction.host.password.c_str()); - ebStartLP->setText(fmt::to_wstring(onLoadAction.host.startLP).c_str()); - ebTeam1->setText(fmt::to_wstring(onLoadAction.host.team1).c_str()); - ebTeam2->setText(fmt::to_wstring(onLoadAction.host.team2).c_str()); - ebBestOf->setText(fmt::to_wstring(onLoadAction.host.bestOf).c_str()); - ebStartHand->setText(fmt::to_wstring(onLoadAction.host.startHand).c_str()); - ebDrawCount->setText(fmt::to_wstring(onLoadAction.host.drawCount).c_str()); - ebHostNotes->setText(fmt::to_wstring(onLoadAction.host.notes).c_str()); - - RefreshLFLists(); - for(irr::u32 i = 0; i < gdeckManager->_lfList.size(); ++i) { - if(gdeckManager->_lfList[i].hash == onLoadAction.host.lfList) { - cbHostLFList->setSelected(i); - } - } - - duel_param = onLoadAction.host.duelParam; - auto duel_param_ignoretcg = duel_param & ~DUEL_TCG_SEGOC_NONPUBLIC; - extra_rules = static_cast(onLoadAction.host.extraRules); - if (onLoadAction.host.forbiddenTypes < 0) { - if (duel_param == DUEL_MODE_SPEED) forbiddentypes = DUEL_MODE_MR5_FORB; - else if (duel_param == DUEL_MODE_RUSH) forbiddentypes = DUEL_MODE_MR5_FORB; - else if (duel_param == DUEL_MODE_GOAT) forbiddentypes = DUEL_MODE_MR1_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR1) forbiddentypes = DUEL_MODE_MR1_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR2) forbiddentypes = DUEL_MODE_MR2_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR3) forbiddentypes = DUEL_MODE_MR3_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR4) forbiddentypes = DUEL_MODE_MR4_FORB; - else if (duel_param_ignoretcg == DUEL_MODE_MR5) forbiddentypes = DUEL_MODE_MR5_FORB; - else forbiddentypes = DUEL_MODE_MR5_FORB; - } - else { - forbiddentypes = static_cast(onLoadAction.host.forbiddenTypes); - } - - chkTcgRulings->setChecked(duel_param & DUEL_TCG_SEGOC_NONPUBLIC); - chkNoShuffleDeck->setChecked(onLoadAction.host.noShuffleDeck); - chkNoShuffleDeckSecondary->setChecked(onLoadAction.host.noShuffleDeck); - chkNoCheckDeckContent->setChecked(onLoadAction.host.noCheckDeckContent); - chkNoCheckDeckContentSecondary->setChecked(onLoadAction.host.noCheckDeckContent); - chkNoCheckDeckSize->setChecked(onLoadAction.host.noCheckDeckSize); - chkNoCheckDeckSizeSecondary->setChecked(onLoadAction.host.noCheckDeckSize); - - for (auto i = 0u; i < sizeofarr(chkCustomRules); ++i) { - if (i == 19) - chkCustomRules[i]->setChecked(duel_param & (DUEL_USE_TRAPS_IN_NEW_CHAIN)); - else if (i == 20) - chkCustomRules[i]->setChecked(duel_param & (DUEL_6_STEP_BATLLE_STEP)); - else if (i == 21) - chkCustomRules[i]->setChecked(duel_param & (DUEL_TRIGGER_WHEN_PRIVATE_KNOWLEDGE)); - else if (i > 21) - chkCustomRules[i]->setChecked(duel_param & (0x100ULL << (i - 3))); - else - chkCustomRules[i]->setChecked(duel_param & (0x100ULL << i)); - } - chkTypeLimit[0]->setChecked(forbiddentypes & TYPE_FUSION); - chkTypeLimit[1]->setChecked(forbiddentypes & TYPE_SYNCHRO); - chkTypeLimit[2]->setChecked(forbiddentypes & TYPE_XYZ); - chkTypeLimit[3]->setChecked(forbiddentypes & TYPE_PENDULUM); - chkTypeLimit[4]->setChecked(forbiddentypes & TYPE_LINK); - - if (onLoadAction.host.serverIndex >= 0) { - isHostingOnline = true; - serverChoice->setSelected(onLoadAction.host.serverIndex); - } else { - isHostingOnline = false; - } - - UpdateDuelParam(); - UpdateExtraRules(true); - - btnHostConfirm->setEnabled(true); - btnHostCancel->setEnabled(true); - stHostPort->setVisible(true); - ebHostPort->setVisible(true); - stHostNotes->setVisible(false); - ebHostNotes->setVisible(true); - wCreateHost->setVisible(true); - ClickButton(btnHostConfirm); - } else if(onLoadAction.join.configured) { - if(onLoadAction.join.serverIndex >= 0) { - isHostingOnline = true; - serverChoice->setSelected(onLoadAction.join.serverIndex); - const auto& serverinfo = ServerLobby::serversVector[onLoadAction.join.serverIndex].Resolved(); - DuelClient::StartClient(serverinfo.address, serverinfo.port, onLoadAction.join.gameId, false); - } else { - isHostingOnline = false; - auto addr = Utils::ToUTF8IfNeeded(onLoadAction.join.host); - DuelClient::StartClient(static_cast(addr.c_str()), onLoadAction.join.port, onLoadAction.join.gameId, false); - } - } else if(onLoadAction.deckbuilder.configured) { - wMainMenu->setVisible(true); - deckBuilder.SetCurrentDeckFromFile(Utils::ToPathString(cbDBDecks->getItem(cbDBDecks->getSelected())), true); - ebDeckname->setText(L""); - HideElement(mainGame->wMainMenu); - deckBuilder.Initialize(); - if (onLoadAction.deckbuilder.testHand.configured) { - deckBuilder.Terminate(false); - SingleMode::DuelOptions options("hand-test-mode"); - options.handTestNoOpponent = onLoadAction.deckbuilder.testHand.noOpponent; - options.startingDrawCount = onLoadAction.deckbuilder.testHand.startingHand; - options.duelFlags = onLoadAction.deckbuilder.testHand.duelParam; - options.duelFlags |= onLoadAction.deckbuilder.testHand.dontShuffleDeck ? DUEL_PSEUDO_SHUFFLE : 0; - SingleMode::singleSignal.SetNoWait(false); - SingleMode::StartPlay(std::move(options)); - } - } else { - wMainMenu->setVisible(true); - } -} - bool Game::TrySetDeck(std::string selectedDeck) { auto selectedDeckW = Utils::ToUnicodeIfNeeded(selectedDeck); RefreshDeck(cbDeckSelect); @@ -3800,15 +3661,20 @@ bool Game::TrySetDeck(std::string selectedDeck) { return false; } -void Game::SetOnLoadActionReplay(epro::path_string replay) { - onLoadAction.enabled = true; - onLoadAction.replay = replay; - wLoadingModal->setVisible(true); +void Game::LaunchReplay(epro::path_string replay) { + open_file = true; + open_file_name = replay; wMainMenu->setVisible(false); - env->setFocus(wLoadingModal); + ClickButton(btnReplayMode); + menuHandler.LoadReplay(); + ReplayMode::Pause(true, false); + btnReplayStart->setVisible(true); + btnReplayPause->setVisible(false); + btnReplayStep->setVisible(true); + btnReplayUndo->setVisible(true); } -void Game::SetOnLoadActionHost(std::string config_raw) { +void Game::LaunchHost(std::string config_raw) { // host: string = ""; // port: number = 7911; // password: string = ""; @@ -3825,7 +3691,27 @@ void Game::SetOnLoadActionHost(std::string config_raw) { // extraRules: number = 0; // bit field, 16 // serverIndex: number = -1; // host online - auto& host = onLoadAction.host; + struct { + std::wstring host; + int port; + std::wstring password; + int team1; + int team2; + int bestOf; + int startHand; + int startLP; + int drawCount; + int timeLimit; + uint32_t lfList; + uint64_t duelParam; + bool noCheckDeckSize; + bool noCheckDeckContent; + bool noShuffleDeck; + int forbiddenTypes; + int extraRules; + int serverIndex; + std::wstring notes; + } host; try { const auto j = nlohmann::json::parse(config_raw); @@ -3853,7 +3739,6 @@ void Game::SetOnLoadActionHost(std::string config_raw) { host.extraRules = static_cast(GET("extraRules", int, 0)); host.serverIndex = GET("serverIndex", int, -1); #undef GET - epro::print(L"parsed host config:\n"); epro::print(L"host = {}\n", host.host); epro::print(L"port = {}\n", host.port); @@ -3873,27 +3758,107 @@ void Game::SetOnLoadActionHost(std::string config_raw) { epro::print(L"forbiddenTypes = {}\n", host.forbiddenTypes); epro::print(L"extraRules = {}\n", host.extraRules); epro::print(L"serverIndex = {}\n", host.serverIndex); - } catch(const std::exception& e) { ErrorLog("Failed to parse host option \"{}\": {}", config_raw, e.what()); return; } - host.configured = true; - onLoadAction.enabled = true; - wLoadingModal->setVisible(true); + ebServerName->setText(host.host.c_str()); + ebHostPort->setText(fmt::to_wstring(host.port).c_str()); + ebServerPass->setText(host.password.c_str()); + ebStartLP->setText(fmt::to_wstring(host.startLP).c_str()); + ebTeam1->setText(fmt::to_wstring(host.team1).c_str()); + ebTeam2->setText(fmt::to_wstring(host.team2).c_str()); + ebBestOf->setText(fmt::to_wstring(host.bestOf).c_str()); + ebStartHand->setText(fmt::to_wstring(host.startHand).c_str()); + ebDrawCount->setText(fmt::to_wstring(host.drawCount).c_str()); + ebHostNotes->setText(fmt::to_wstring(host.notes).c_str()); + + RefreshLFLists(); + for(irr::u32 i = 0; i < gdeckManager->_lfList.size(); ++i) { + if(gdeckManager->_lfList[i].hash == host.lfList) { + cbHostLFList->setSelected(i); + } + } + + duel_param = host.duelParam; + auto duel_param_ignoretcg = duel_param & ~DUEL_TCG_SEGOC_NONPUBLIC; + extra_rules = static_cast(host.extraRules); + if (host.forbiddenTypes < 0) { + if (duel_param == DUEL_MODE_SPEED) forbiddentypes = DUEL_MODE_MR5_FORB; + else if (duel_param == DUEL_MODE_RUSH) forbiddentypes = DUEL_MODE_MR5_FORB; + else if (duel_param == DUEL_MODE_GOAT) forbiddentypes = DUEL_MODE_MR1_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR1) forbiddentypes = DUEL_MODE_MR1_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR2) forbiddentypes = DUEL_MODE_MR2_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR3) forbiddentypes = DUEL_MODE_MR3_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR4) forbiddentypes = DUEL_MODE_MR4_FORB; + else if (duel_param_ignoretcg == DUEL_MODE_MR5) forbiddentypes = DUEL_MODE_MR5_FORB; + else forbiddentypes = DUEL_MODE_MR5_FORB; + } + else { + forbiddentypes = static_cast(host.forbiddenTypes); + } + + chkTcgRulings->setChecked(duel_param & DUEL_TCG_SEGOC_NONPUBLIC); + chkNoShuffleDeck->setChecked(host.noShuffleDeck); + chkNoShuffleDeckSecondary->setChecked(host.noShuffleDeck); + chkNoCheckDeckContent->setChecked(host.noCheckDeckContent); + chkNoCheckDeckContentSecondary->setChecked(host.noCheckDeckContent); + chkNoCheckDeckSize->setChecked(host.noCheckDeckSize); + chkNoCheckDeckSizeSecondary->setChecked(host.noCheckDeckSize); + + for (auto i = 0u; i < sizeofarr(chkCustomRules); ++i) { + if (i == 19) + chkCustomRules[i]->setChecked(duel_param & (DUEL_USE_TRAPS_IN_NEW_CHAIN)); + else if (i == 20) + chkCustomRules[i]->setChecked(duel_param & (DUEL_6_STEP_BATLLE_STEP)); + else if (i == 21) + chkCustomRules[i]->setChecked(duel_param & (DUEL_TRIGGER_WHEN_PRIVATE_KNOWLEDGE)); + else if (i > 21) + chkCustomRules[i]->setChecked(duel_param & (0x100ULL << (i - 3))); + else + chkCustomRules[i]->setChecked(duel_param & (0x100ULL << i)); + } + chkTypeLimit[0]->setChecked(forbiddentypes & TYPE_FUSION); + chkTypeLimit[1]->setChecked(forbiddentypes & TYPE_SYNCHRO); + chkTypeLimit[2]->setChecked(forbiddentypes & TYPE_XYZ); + chkTypeLimit[3]->setChecked(forbiddentypes & TYPE_PENDULUM); + chkTypeLimit[4]->setChecked(forbiddentypes & TYPE_LINK); + + if (host.serverIndex >= 0) { + isHostingOnline = true; + serverChoice->setSelected(host.serverIndex); + } else { + isHostingOnline = false; + } + + UpdateDuelParam(); + UpdateExtraRules(true); + wMainMenu->setVisible(false); - env->setFocus(wLoadingModal); + btnHostConfirm->setEnabled(true); + btnHostCancel->setEnabled(true); + stHostPort->setVisible(true); + ebHostPort->setVisible(true); + stHostNotes->setVisible(false); + ebHostNotes->setVisible(true); + wCreateHost->setVisible(true); + ClickButton(btnHostConfirm); } -void Game::SetOnLoadActionJoin(std::string config_raw) { +void Game::LaunchJoin(std::string config_raw) { // host: string = ""; // port: number = 7911; // password: string = ""; // serverIndex: number = -1; // join online // gameId: number = 0; // only for - - auto& join = onLoadAction.join; + struct { + std::wstring host; + int port; + std::wstring password; + int serverIndex; + int gameId; + } join; try { const auto j = nlohmann::json::parse(config_raw); @@ -3915,20 +3880,25 @@ void Game::SetOnLoadActionJoin(std::string config_raw) { epro::print(L"password = {}\n", join.password); epro::print(L"serverIndex = {}\n", join.serverIndex); epro::print(L"gameId = {}\n", join.gameId); - } catch(const std::exception& e) { ErrorLog("Failed to parse join option \"{}\": {}", config_raw, e.what()); return; } - join.configured = true; - onLoadAction.enabled = true; - wLoadingModal->setVisible(true); wMainMenu->setVisible(false); - env->setFocus(wLoadingModal); + if(join.serverIndex >= 0) { + isHostingOnline = true; + serverChoice->setSelected(join.serverIndex); + const auto& serverinfo = ServerLobby::serversVector[join.serverIndex].Resolved(); + DuelClient::StartClient(serverinfo.address, serverinfo.port, join.gameId, false); + } else { + isHostingOnline = false; + auto addr = Utils::ToUTF8IfNeeded(join.host); + DuelClient::StartClient(static_cast(addr.c_str()), join.port, join.gameId, false); + } } -void Game::SetOnLoadActionDeckbuilder(std::string config_raw) { +void Game::LaunchDeckbuilder(std::string config_raw) { // testHand?: { // noOpponent?: boolean = false; // dontShuffleDeck?: boolean = false; @@ -3936,8 +3906,17 @@ void Game::SetOnLoadActionDeckbuilder(std::string config_raw) { // duelParam?: number = DUEL_MODE_MR5; // saveReplay?: boolean = false; // }; - - auto& db = onLoadAction.deckbuilder; + struct { + struct { + bool noOpponent; + bool dontShuffleDeck; + int startingHand; + uint64_t duelParam; + bool saveReplay; + bool configured; + } testHand; + bool configured; + } db; try { const auto j = nlohmann::json::parse(config_raw); @@ -3956,6 +3935,7 @@ void Game::SetOnLoadActionDeckbuilder(std::string config_raw) { db.testHand.duelParam = static_cast(GET(testHand, "duelParam", uint64_t, DUEL_MODE_MR5)); db.testHand.configured = true; } + db.configured = true; #undef GET epro::print(L"parsed deckbuilder config:\n"); @@ -3973,11 +3953,10 @@ void Game::SetOnLoadActionDeckbuilder(std::string config_raw) { return; } - db.configured = true; - onLoadAction.enabled = true; - wLoadingModal->setVisible(true); - wMainMenu->setVisible(false); - env->setFocus(wLoadingModal); + deckBuilder.SetCurrentDeckFromFile(Utils::ToPathString(cbDBDecks->getItem(cbDBDecks->getSelected())), true); + ebDeckname->setText(L""); + HideElement(mainGame->wMainMenu); + deckBuilder.Initialize(); } void Game::OnResize() { diff --git a/gframe/game.h b/gframe/game.h index 97520bffd..9940ae0e0 100644 --- a/gframe/game.h +++ b/gframe/game.h @@ -216,12 +216,11 @@ class Game { void ReloadCBVsync(); void ReloadElementsStrings(); - void OnAsyncLoadingCompleted(); bool TrySetDeck(std::string selectedDeck); - void SetOnLoadActionReplay(epro::path_string file); - void SetOnLoadActionHost(std::string params); - void SetOnLoadActionJoin(std::string params); - void SetOnLoadActionDeckbuilder(std::string params); + void LaunchReplay(epro::path_string file); + void LaunchHost(std::string params); + void LaunchJoin(std::string params); + void LaunchDeckbuilder(std::string params); void OnResize(); template @@ -415,60 +414,12 @@ class Game { epro::mutex progressStatusLock; ProgressBarStatus progressStatus; - - struct OnLoadAction { - bool enabled; - bool exitAfter; - epro::path_string replay; - struct { - bool configured; - std::wstring host; - int port; - std::wstring password; - int team1; - int team2; - int bestOf; - int startHand; - int startLP; - int drawCount; - int timeLimit; - uint32_t lfList; - uint64_t duelParam; - bool noCheckDeckSize; - bool noCheckDeckContent; - bool noShuffleDeck; - int forbiddenTypes; - int extraRules; - int serverIndex; - std::wstring notes; - } host; - struct { - bool configured; - std::wstring host; - int port; - std::wstring password; - int serverIndex; - int gameId; - } join; - struct { - bool configured; - struct { - bool configured; - bool noOpponent; - bool dontShuffleDeck; - int startingHand; - uint64_t duelParam; - bool saveReplay; - } testHand; - } deckbuilder; - }; - OnLoadAction onLoadAction; + bool exitAfter; //main menu int mainMenuLeftX; int mainMenuRightX; irr::gui::IGUIWindow* wMainMenu; - irr::gui::IGUIWindow* wLoadingModal; irr::gui::IGUIWindow* wCommitsLog; irr::gui::IGUIContextMenu* mTopMenu; irr::gui::IGUIContextMenu* mRepositoriesInfo; diff --git a/gframe/gframe.cpp b/gframe/gframe.cpp index d00c01e86..aabbb0b15 100644 --- a/gframe/gframe.cpp +++ b/gframe/gframe.cpp @@ -64,23 +64,23 @@ void CheckArguments(const args_t& args) { ygo::mainGame->TrySetDeck(selectedDeck); } if(args[LAUNCH_PARAM::EXIT_AFTER].enabled) { - ygo::mainGame->onLoadAction.exitAfter = true; + ygo::mainGame->exitAfter = true; } if(args[LAUNCH_PARAM::REPLAY].enabled && !args[LAUNCH_PARAM::REPLAY].argument.empty()) { auto replay = ygo::Utils::ToPathString(args[LAUNCH_PARAM::REPLAY].argument); - ygo::mainGame->SetOnLoadActionReplay(replay); + ygo::mainGame->LaunchReplay(replay); } if(args[LAUNCH_PARAM::HOST].enabled && !args[LAUNCH_PARAM::HOST].argument.empty()) { auto host_params = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::HOST].argument); - ygo::mainGame->SetOnLoadActionHost(host_params); + ygo::mainGame->LaunchHost(host_params); } if(args[LAUNCH_PARAM::JOIN].enabled && !args[LAUNCH_PARAM::JOIN].argument.empty()) { auto join_params = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::JOIN].argument); - ygo::mainGame->SetOnLoadActionJoin(join_params); + ygo::mainGame->LaunchJoin(join_params); } if(args[LAUNCH_PARAM::DECKBUILDER].enabled && !args[LAUNCH_PARAM::DECKBUILDER].argument.empty()) { auto deckbuilder_params = ygo::Utils::ToUTF8IfNeeded(args[LAUNCH_PARAM::DECKBUILDER].argument); - ygo::mainGame->SetOnLoadActionDeckbuilder(deckbuilder_params); + ygo::mainGame->LaunchDeckbuilder(deckbuilder_params); } } @@ -134,6 +134,13 @@ using Game = ygo::Game; #define ADMIN_STR "root" #endif +static bool args_require_repo_read_only() { + return cli_args[LAUNCH_PARAM::REPLAY].enabled + || cli_args[LAUNCH_PARAM::HOST].enabled + || cli_args[LAUNCH_PARAM::JOIN].enabled + || cli_args[LAUNCH_PARAM::DECKBUILDER].enabled; +} + int edopro_main(const args_t& args) { std::puts(EDOPRO_VERSION_STRING_DEBUG); if(ygo::Utils::IsRunningAsAdmin() && !args[LAUNCH_PARAM::WANTS_TO_RUN_AS_ADMIN].enabled) { @@ -166,6 +173,9 @@ int edopro_main(const args_t& args) { ygo::GUIUtils::ShowErrorWindow("Initialization fail", text); return EXIT_FAILURE; } + if(args_require_repo_read_only()) { + cli_args[LAUNCH_PARAM::REPOS_READ_ONLY].enabled = true; + } show_changelog = args[LAUNCH_PARAM::CHANGELOG].enabled; ygo::ClientUpdater updater(args[LAUNCH_PARAM::OVERRIDE_UPDATE_URL].argument); ygo::gClientUpdater = &updater; @@ -228,9 +238,6 @@ int edopro_main(const args_t& args) { firstlaunch = false; CheckArguments(args); } - if(ygo::gRepoManager->TerminateIfNothingLoaded()) - ygo::mainGame->OnAsyncLoadingCompleted(); - reset = ygo::mainGame->MainLoop(); data->tmp_device = ygo::mainGame->device; if(reset) { diff --git a/gframe/menu_handler.cpp b/gframe/menu_handler.cpp index 6369ca0e1..a8cc20e18 100644 --- a/gframe/menu_handler.cpp +++ b/gframe/menu_handler.cpp @@ -343,7 +343,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { case BUTTON_HP_CANCEL: { DuelClient::StopClient(); - if(mainGame->onLoadAction.exitAfter) { + if(mainGame->exitAfter) { mainGame->device->closeDevice(); break; } diff --git a/gframe/replay_mode.cpp b/gframe/replay_mode.cpp index 8cad32fc8..904f8d204 100644 --- a/gframe/replay_mode.cpp +++ b/gframe/replay_mode.cpp @@ -182,7 +182,7 @@ void ReplayMode::EndDuel() { mainGame->stTip->setVisible(false); gSoundManager->StopSounds(); mainGame->device->setEventReceiver(&mainGame->menuHandler); - if(mainGame->onLoadAction.exitAfter) + if(mainGame->exitAfter) mainGame->device->closeDevice(); } } From 13359ad6e15006a920f516ced209c0e706fd4b19 Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Sun, 30 Mar 2025 22:45:07 +0200 Subject: [PATCH 11/13] Fix merge error --- gframe/edopro_main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gframe/edopro_main.cpp b/gframe/edopro_main.cpp index 98acad2d0..5a3fc033f 100644 --- a/gframe/edopro_main.cpp +++ b/gframe/edopro_main.cpp @@ -41,11 +41,11 @@ auto GetOption(epro::path_stringview option) { } if(option == EPRO_TEXT("i-want-to-be-admin"sv)) return LAUNCH_PARAM::WANTS_TO_RUN_AS_ADMIN; - if(option == EPRO_TEXT("replay"_sv)) + if(option == EPRO_TEXT("replay"sv)) return LAUNCH_PARAM::REPLAY; - if(option == EPRO_TEXT("host"_sv)) + if(option == EPRO_TEXT("host"sv)) return LAUNCH_PARAM::HOST; - if(option == EPRO_TEXT("join"_sv)) + if(option == EPRO_TEXT("join"sv)) return LAUNCH_PARAM::JOIN; if(option == EPRO_TEXT("deckbuilder")) return LAUNCH_PARAM::DECKBUILDER; From f5ce702cf10657b4347f37235e340d5dda85ccfc Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Sun, 30 Mar 2025 22:51:25 +0200 Subject: [PATCH 12/13] Use ClickButton function from utils_gui --- gframe/game.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/gframe/game.cpp b/gframe/game.cpp index 989eecada..c64c4f378 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -69,16 +69,6 @@ inline T AlignElementWithParent(T elem) { elem->setAlignment(irr::gui::EGUIA_SCALE, irr::gui::EGUIA_SCALE, irr::gui::EGUIA_SCALE, irr::gui::EGUIA_SCALE); return elem; } -inline void TriggerEvent(irr::gui::IGUIElement* target, irr::gui::EGUI_EVENT_TYPE type) { - irr::SEvent event; - event.EventType = irr::EET_GUI_EVENT; - event.GUIEvent.EventType = type; - event.GUIEvent.Caller = target; - ygo::mainGame->device->postEventFromUser(event); -} -static inline void ClickButton(irr::gui::IGUIElement* btn) { - TriggerEvent(btn, irr::gui::EGET_BUTTON_CLICKED); -} } namespace ygo { @@ -3669,7 +3659,7 @@ void Game::LaunchReplay(epro::path_string replay) { open_file = true; open_file_name = replay; wMainMenu->setVisible(false); - ClickButton(btnReplayMode); + GUIUtils::ClickButton(device, btnReplayMode); menuHandler.LoadReplay(); ReplayMode::Pause(true, false); btnReplayStart->setVisible(true); @@ -3847,7 +3837,7 @@ void Game::LaunchHost(std::string config_raw) { stHostNotes->setVisible(false); ebHostNotes->setVisible(true); wCreateHost->setVisible(true); - ClickButton(btnHostConfirm); + GUIUtils::ClickButton(device, btnHostConfirm); } void Game::LaunchJoin(std::string config_raw) { From d301136eb958678b2cc327be3a0e1b17b9020651 Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Sun, 30 Mar 2025 22:56:47 +0200 Subject: [PATCH 13/13] Revery extra github repo checking logic It was implemented into master already --- gframe/game.cpp | 8 +------- gframe/repo_manager.cpp | 4 ---- gframe/repo_manager.h | 1 - 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/gframe/game.cpp b/gframe/game.cpp index c64c4f378..40428dca6 100644 --- a/gframe/game.cpp +++ b/gframe/game.cpp @@ -2020,12 +2020,6 @@ bool Game::MainLoop() { LoadCoreFromRepos(); } #endif //YGOPRO_BUILD_DLL - - if (cores_to_load.size() == 0 && gRepoManager->GetUpdatingReposNumber() == 0) { - gdeckManager->StopDummyLoading(); - ReloadElementsStrings(); - } - for(auto& repo : gRepoManager->GetRepoStatus()) { repoInfoGui[repo.first].progress1->setProgress(repo.second); repoInfoGui[repo.first].progress2->setProgress(repo.second); @@ -2708,7 +2702,7 @@ void Game::ParseGithubRepositories(const std::vector& repos) { if(deckBuilder.results.size()) deckBuilder.StartFilter(true); } - if (gRepoManager->GetUpdatingReposNumber() == 0) { + if(gRepoManager->GetUpdatingReposNumber() == 0) { gdeckManager->StopDummyLoading(); ReloadElementsStrings(); } diff --git a/gframe/repo_manager.cpp b/gframe/repo_manager.cpp index ec8c14e24..43891d9f9 100644 --- a/gframe/repo_manager.cpp +++ b/gframe/repo_manager.cpp @@ -102,10 +102,6 @@ RepoManager::~RepoManager() { TerminateThreads(); } -size_t RepoManager::GetAllReposNumber() const { - return all_repos_count; -} - size_t RepoManager::GetUpdatingReposNumber() const { return available_repos.size(); } diff --git a/gframe/repo_manager.h b/gframe/repo_manager.h index a66a4c829..82ce4b096 100644 --- a/gframe/repo_manager.h +++ b/gframe/repo_manager.h @@ -55,7 +55,6 @@ class RepoManager { // Cancel fetching of repos and synchronize with futures ~RepoManager(); - size_t GetAllReposNumber() const; size_t GetUpdatingReposNumber() const; std::vector GetAllRepos() const; std::vector GetReadyRepos(); // changes available_repos