Make setting into an enum

This commit is contained in:
RickyRister 2025-05-01 21:19:37 -07:00
parent c6fcb5be1d
commit f046c26b04
8 changed files with 47 additions and 23 deletions

View file

@ -814,10 +814,19 @@ void TabSupervisor::talkLeft(TabMessage *tab)
*/
void TabSupervisor::openDeckInNewTab(const DeckLoader *deckToOpen)
{
if (SettingsCache::instance().getOpenInVisualDeckEditor()) {
addVisualDeckEditorTab(deckToOpen);
} else {
addDeckEditorTab(deckToOpen);
int type = SettingsCache::instance().getDefaultDeckEditorType();
switch (type) {
case ClassicDeckEditor:
addDeckEditorTab(deckToOpen);
break;
case VisualDeckEditor:
addVisualDeckEditorTab(deckToOpen);
break;
default:
qCWarning(TabSupervisorLog) << "Unknown DeckEditorType [" << type
<< "]; opening ClassicDeckEditor as fallback";
addDeckEditorTab(deckToOpen);
break;
}
}

View file

@ -75,6 +75,14 @@ protected:
class TabSupervisor : public QTabWidget
{
Q_OBJECT
public:
enum DeckEditorType
{
ClassicDeckEditor,
VisualDeckEditor
};
private:
ServerInfo_User *userInfo;
AbstractClient *client;

View file

@ -4,6 +4,7 @@
#include "../client/network/release_channel.h"
#include "../client/network/spoiler_background_updater.h"
#include "../client/sound_engine.h"
#include "../client/tabs/tab_supervisor.h"
#include "../client/ui/picture_loader/picture_loader.h"
#include "../client/ui/theme_manager.h"
#include "../deck/custom_line_edit.h"
@ -681,10 +682,6 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
connect(&visualDeckStorageSelectionAnimationCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setVisualDeckStorageSelectionAnimation);
openInVisualDeckEditorCheckBox.setChecked(SettingsCache::instance().getOpenInVisualDeckEditor());
connect(&openInVisualDeckEditorCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
&SettingsCache::setOpenInVisualDeckEditor);
visualDeckStoragePromptForConversionSelector.addItem(""); // these will be set in retranslateUI
visualDeckStoragePromptForConversionSelector.addItem("");
visualDeckStoragePromptForConversionSelector.addItem("");
@ -703,13 +700,20 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage()
index == visualDeckStoragePromptForConversionIndexAlways);
});
defaultDeckEditorTypeSelector.addItem(""); // these will be set in retranslateUI
defaultDeckEditorTypeSelector.addItem("");
defaultDeckEditorTypeSelector.setCurrentIndex(SettingsCache::instance().getDefaultDeckEditorType());
connect(&defaultDeckEditorTypeSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
&SettingsCache::instance(), &SettingsCache::setDefaultDeckEditorType);
auto *deckEditorGrid = new QGridLayout;
deckEditorGrid->addWidget(&openDeckInNewTabCheckBox, 0, 0);
deckEditorGrid->addWidget(&visualDeckStorageInGameCheckBox, 1, 0);
deckEditorGrid->addWidget(&visualDeckStorageSelectionAnimationCheckBox, 2, 0);
deckEditorGrid->addWidget(&openInVisualDeckEditorCheckBox, 3, 0);
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionLabel, 4, 0);
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionSelector, 4, 1);
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionLabel, 3, 0);
deckEditorGrid->addWidget(&visualDeckStoragePromptForConversionSelector, 3, 1);
deckEditorGrid->addWidget(&defaultDeckEditorTypeLabel, 4, 0);
deckEditorGrid->addWidget(&defaultDeckEditorTypeSelector, 4, 1);
deckEditorGroupBox = new QGroupBox;
deckEditorGroupBox->setLayout(deckEditorGrid);
@ -771,7 +775,6 @@ void UserInterfaceSettingsPage::retranslateUi()
openDeckInNewTabCheckBox.setText(tr("Open deck in new tab by default"));
visualDeckStorageInGameCheckBox.setText(tr("Use visual deck storage in game lobby"));
visualDeckStorageSelectionAnimationCheckBox.setText(tr("Use selection animation for Visual Deck Storage"));
openInVisualDeckEditorCheckBox.setText(tr("Open decks in visual deck editor"));
visualDeckStoragePromptForConversionLabel.setText(
tr("When adding a tag in the visual deck storage to a .txt deck:"));
visualDeckStoragePromptForConversionSelector.setItemText(visualDeckStoragePromptForConversionIndexNone,
@ -780,6 +783,9 @@ void UserInterfaceSettingsPage::retranslateUi()
tr("ask to convert to .cod"));
visualDeckStoragePromptForConversionSelector.setItemText(visualDeckStoragePromptForConversionIndexAlways,
tr("always convert to .cod"));
defaultDeckEditorTypeLabel.setText(tr("Default deck editor type"));
defaultDeckEditorTypeSelector.setItemText(TabSupervisor::ClassicDeckEditor, tr("Classic Deck Editor"));
defaultDeckEditorTypeSelector.setItemText(TabSupervisor::VisualDeckEditor, tr("Visual Deck Editor"));
replayGroupBox->setTitle(tr("Replay settings"));
rewindBufferingMsLabel.setText(tr("Buffer time for backwards skip via shortcut:"));
rewindBufferingMsBox.setSuffix(" ms");

View file

@ -155,7 +155,8 @@ private:
QComboBox visualDeckStoragePromptForConversionSelector;
QCheckBox visualDeckStorageInGameCheckBox;
QCheckBox visualDeckStorageSelectionAnimationCheckBox;
QCheckBox openInVisualDeckEditorCheckBox;
QLabel defaultDeckEditorTypeLabel;
QComboBox defaultDeckEditorTypeSelector;
QLabel rewindBufferingMsLabel;
QSpinBox rewindBufferingMsBox;
QGroupBox *generalGroupBox;

View file

@ -285,7 +285,7 @@ SettingsCache::SettingsCache()
visualDeckStorageInGame = settings->value("interface/visualdeckstorageingame", true).toBool();
visualDeckStorageSelectionAnimation =
settings->value("interface/visualdeckstorageselectionanimation", true).toBool();
openInVisualDeckEditor = settings->value("interface/openInVisualDeckEditor", true).toBool();
defaultDeckEditorType = settings->value("interface/defaultDeckEditorType", 1).toInt();
visualDatabaseDisplayFilterToMostRecentSetsEnabled =
settings->value("interface/visualdatabasedisplayfiltertomostrecentsetsenabled", true).toBool();
visualDatabaseDisplayFilterToMostRecentSetsAmount =
@ -792,10 +792,10 @@ void SettingsCache::setVisualDeckStorageSelectionAnimation(QT_STATE_CHANGED_T va
emit visualDeckStorageSelectionAnimationChanged(visualDeckStorageSelectionAnimation);
}
void SettingsCache::setOpenInVisualDeckEditor(QT_STATE_CHANGED_T value)
void SettingsCache::setDefaultDeckEditorType(int value)
{
openInVisualDeckEditor = value;
settings->setValue("interface/openInVisualDeckEditor", openInVisualDeckEditor);
defaultDeckEditorType = value;
settings->setValue("interface/defaultDeckEditorType", defaultDeckEditorType);
}
void SettingsCache::setVisualDatabaseDisplayFilterToMostRecentSetsEnabled(QT_STATE_CHANGED_T _enabled)

View file

@ -153,7 +153,7 @@ private:
bool visualDeckStorageAlwaysConvert;
bool visualDeckStorageInGame;
bool visualDeckStorageSelectionAnimation;
bool openInVisualDeckEditor;
int defaultDeckEditorType;
bool visualDatabaseDisplayFilterToMostRecentSetsEnabled;
int visualDatabaseDisplayFilterToMostRecentSetsAmount;
bool horizontalHand;
@ -489,9 +489,9 @@ public:
{
return visualDeckStorageSelectionAnimation;
}
bool getOpenInVisualDeckEditor() const
int getDefaultDeckEditorType() const
{
return openInVisualDeckEditor;
return defaultDeckEditorType;
}
bool getVisualDatabaseDisplayFilterToMostRecentSetsEnabled() const
{
@ -844,7 +844,7 @@ public slots:
void setVisualDeckStorageAlwaysConvert(bool _visualDeckStorageAlwaysConvert);
void setVisualDeckStorageInGame(QT_STATE_CHANGED_T value);
void setVisualDeckStorageSelectionAnimation(QT_STATE_CHANGED_T value);
void setOpenInVisualDeckEditor(QT_STATE_CHANGED_T value);
void setDefaultDeckEditorType(int value);
void setVisualDatabaseDisplayFilterToMostRecentSetsEnabled(QT_STATE_CHANGED_T _enabled);
void setVisualDatabaseDisplayFilterToMostRecentSetsAmount(int _amount);
void setHorizontalHand(QT_STATE_CHANGED_T _horizontalHand);

View file

@ -256,7 +256,7 @@ void SettingsCache::setVisualDeckStorageInGame(QT_STATE_CHANGED_T /* value */)
void SettingsCache::setVisualDeckStorageSelectionAnimation(QT_STATE_CHANGED_T /* value */)
{
}
void SettingsCache::setOpenInVisualDeckEditor(QT_STATE_CHANGED_T /* value */)
void SettingsCache::setDefaultDeckEditorType(int /* value */)
{
}
void SettingsCache::setVisualDatabaseDisplayFilterToMostRecentSetsEnabled(QT_STATE_CHANGED_T /* _enabled */)

View file

@ -260,7 +260,7 @@ void SettingsCache::setVisualDeckStorageInGame(QT_STATE_CHANGED_T /* value */)
void SettingsCache::setVisualDeckStorageSelectionAnimation(QT_STATE_CHANGED_T /* value */)
{
}
void SettingsCache::setOpenInVisualDeckEditor(QT_STATE_CHANGED_T /* value */)
void SettingsCache::setDefaultDeckEditorType(int /* value */)
{
}
void SettingsCache::setVisualDatabaseDisplayFilterToMostRecentSetsEnabled(QT_STATE_CHANGED_T /* _enabled */)