From c6fcb5be1d99a49b52e63751d5fbdcf6d071b71c Mon Sep 17 00:00:00 2001 From: RickyRister Date: Wed, 30 Apr 2025 23:14:48 -0700 Subject: [PATCH] implement functionality --- .../tabs/api/edhrec/tab_edhrec_main.cpp | 2 +- cockatrice/src/client/tabs/tab_supervisor.cpp | 20 ++++++++++++++++--- cockatrice/src/client/tabs/tab_supervisor.h | 1 + .../tab_deck_storage_visual.cpp | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/client/tabs/api/edhrec/tab_edhrec_main.cpp b/cockatrice/src/client/tabs/api/edhrec/tab_edhrec_main.cpp index 0bd4e843a..2eed749af 100644 --- a/cockatrice/src/client/tabs/api/edhrec/tab_edhrec_main.cpp +++ b/cockatrice/src/client/tabs/api/edhrec/tab_edhrec_main.cpp @@ -356,7 +356,7 @@ void TabEdhRecMain::processAverageDeckResponse(QJsonObject reply) { EdhrecAverageDeckApiResponse deckData; deckData.fromJson(reply); - tabSupervisor->addVisualDeckEditorTab(deckData.deck.deckLoader); + tabSupervisor->openDeckInNewTab(deckData.deck.deckLoader); } void TabEdhRecMain::prettyPrintJson(const QJsonValue &value, int indentLevel) diff --git a/cockatrice/src/client/tabs/tab_supervisor.cpp b/cockatrice/src/client/tabs/tab_supervisor.cpp index 5d9600d11..6c383dd19 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.cpp +++ b/cockatrice/src/client/tabs/tab_supervisor.cpp @@ -590,7 +590,7 @@ void TabSupervisor::actTabDeckStorage(bool checked) void TabSupervisor::openTabDeckStorage() { tabDeckStorage = new TabDeckStorage(this, client, userInfo); - connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::addDeckEditorTab); + connect(tabDeckStorage, &TabDeckStorage::openDeckEditor, this, &TabSupervisor::openDeckInNewTab); myAddTab(tabDeckStorage, aTabDeckStorage); connect(tabDeckStorage, &Tab::closed, this, [this] { tabDeckStorage = nullptr; @@ -691,7 +691,7 @@ void TabSupervisor::gameJoined(const Event_GameJoined &event) auto *tab = new TabGame(this, QList() << client, event, roomGameTypes); connect(tab, &TabGame::gameClosing, this, &TabSupervisor::gameLeft); connect(tab, &TabGame::openMessageDialog, this, &TabSupervisor::addMessageTab); - connect(tab, &TabGame::openDeckEditor, this, &TabSupervisor::addDeckEditorTab); + connect(tab, &TabGame::openDeckEditor, this, &TabSupervisor::openDeckInNewTab); myAddTab(tab); gameTabs.insert(event.game_info().game_id(), tab); setCurrentWidget(tab); @@ -701,7 +701,7 @@ void TabSupervisor::localGameJoined(const Event_GameJoined &event) { auto *tab = new TabGame(this, localClients, event, QMap()); connect(tab, &TabGame::gameClosing, this, &TabSupervisor::gameLeft); - connect(tab, &TabGame::openDeckEditor, this, &TabSupervisor::addDeckEditorTab); + connect(tab, &TabGame::openDeckEditor, this, &TabSupervisor::openDeckInNewTab); myAddTab(tab); gameTabs.insert(event.game_info().game_id(), tab); setCurrentWidget(tab); @@ -807,6 +807,20 @@ void TabSupervisor::talkLeft(TabMessage *tab) removeTab(indexOf(tab)); } +/** + * Creates a new deck editor tab and loads the deck into it. + * Creates either a classic or visual deck editor tab depending on settings + * @param deckToOpen The deck to open in the tab. Creates a copy of the DeckLoader instance. + */ +void TabSupervisor::openDeckInNewTab(const DeckLoader *deckToOpen) +{ + if (SettingsCache::instance().getOpenInVisualDeckEditor()) { + addVisualDeckEditorTab(deckToOpen); + } else { + addDeckEditorTab(deckToOpen); + } +} + /** * Creates a new deck editor tab * @param deckToOpen The deck to open in the tab. Creates a copy of the DeckLoader instance. diff --git a/cockatrice/src/client/tabs/tab_supervisor.h b/cockatrice/src/client/tabs/tab_supervisor.h index 0ca13ac41..95efec921 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.h +++ b/cockatrice/src/client/tabs/tab_supervisor.h @@ -152,6 +152,7 @@ signals: void showWindowIfHidden(); public slots: + void openDeckInNewTab(const DeckLoader *deckToOpen); TabDeckEditor *addDeckEditorTab(const DeckLoader *deckToOpen); TabDeckEditorVisual *addVisualDeckEditorTab(const DeckLoader *deckToOpen); TabVisualDatabaseDisplay *addVisualDatabaseDisplayTab(); diff --git a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp index 38af03c59..65b4fcab0 100644 --- a/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp +++ b/cockatrice/src/client/tabs/visual_deck_storage/tab_deck_storage_visual.cpp @@ -12,7 +12,7 @@ TabDeckStorageVisual::TabDeckStorageVisual(TabSupervisor *_tabSupervisor) : Tab(_tabSupervisor), visualDeckStorageWidget(new VisualDeckStorageWidget(this)) { - connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::addVisualDeckEditorTab); + connect(this, &TabDeckStorageVisual::openDeckEditor, tabSupervisor, &TabSupervisor::openDeckInNewTab); connect(visualDeckStorageWidget, &VisualDeckStorageWidget::deckLoadRequested, this, &TabDeckStorageVisual::actOpenLocalDeck); connect(visualDeckStorageWidget, &VisualDeckStorageWidget::openDeckEditor, this,