General GameCubePane improvements (squashed commit)

This commit is contained in:
0xFEEDC0DE64 2019-01-24 21:08:21 +01:00
parent 3627ef8a04
commit e1fdf4ae9a
2 changed files with 100 additions and 134 deletions

View File

@ -10,11 +10,14 @@
#include <QFileInfo> #include <QFileInfo>
#include <QGridLayout> #include <QGridLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QInputDialog>
#include <QLabel> #include <QLabel>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <utility>
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
#include "Common/Config/Config.h" #include "Common/Config/Config.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
@ -27,21 +30,12 @@
#include "DolphinQt/Config/Mapping/MappingWindow.h" #include "DolphinQt/Config/Mapping/MappingWindow.h"
constexpr int SLOT_A_INDEX = 0; enum
constexpr int SLOT_B_INDEX = 1;
constexpr int SLOT_SP1_INDEX = 2;
constexpr int SLOT_COUNT = 3;
enum ExpansionSelection
{ {
EXP_NOTHING = 0, SLOT_A_INDEX,
EXP_DUMMY = 1, SLOT_B_INDEX,
EXP_MEMORYCARD = 2, SLOT_SP1_INDEX,
EXP_BROADBAND = 2, SLOT_COUNT
EXP_GCI_FOLDER = 3,
EXP_GECKO = 4,
EXP_AGP = 5,
EXP_MICROPHONE = 6
}; };
GameCubePane::GameCubePane() GameCubePane::GameCubePane()
@ -53,21 +47,25 @@ GameCubePane::GameCubePane()
void GameCubePane::CreateWidgets() void GameCubePane::CreateWidgets()
{ {
QVBoxLayout* layout = new QVBoxLayout; QVBoxLayout* layout = new QVBoxLayout(this);
// IPL Settings // IPL Settings
QGroupBox* ipl_box = new QGroupBox(tr("IPL Settings")); QGroupBox* ipl_box = new QGroupBox(tr("IPL Settings"), this);
QGridLayout* ipl_layout = new QGridLayout; QGridLayout* ipl_layout = new QGridLayout(ipl_box);
ipl_box->setLayout(ipl_layout); ipl_box->setLayout(ipl_layout);
m_skip_main_menu = new QCheckBox(tr("Skip Main Menu")); m_skip_main_menu = new QCheckBox(tr("Skip Main Menu"), ipl_box);
m_override_language_ntsc = new QCheckBox(tr("Override Language on NTSC Games")); m_override_language_ntsc = new QCheckBox(tr("Override Language on NTSC Games"), ipl_box);
m_language_combo = new QComboBox; m_language_combo = new QComboBox(ipl_box);
m_language_combo->setCurrentIndex(-1);
// Add languages // Add languages
for (const auto& language : for (const auto& entry : {std::make_pair(tr("English"), 0), std::make_pair(tr("German"), 1),
{tr("English"), tr("German"), tr("French"), tr("Spanish"), tr("Italian"), tr("Dutch")}) std::make_pair(tr("French"), 2), std::make_pair(tr("Spanish"), 3),
m_language_combo->addItem(language); std::make_pair(tr("Italian"), 4), std::make_pair(tr("Dutch"), 5)})
{
m_language_combo->addItem(entry.first, entry.second);
}
ipl_layout->addWidget(m_skip_main_menu, 0, 0); ipl_layout->addWidget(m_skip_main_menu, 0, 0);
ipl_layout->addWidget(new QLabel(tr("System Language:")), 1, 0); ipl_layout->addWidget(new QLabel(tr("System Language:")), 1, 0);
@ -75,37 +73,40 @@ void GameCubePane::CreateWidgets()
ipl_layout->addWidget(m_override_language_ntsc, 2, 0); ipl_layout->addWidget(m_override_language_ntsc, 2, 0);
// Device Settings // Device Settings
QGroupBox* device_box = new QGroupBox(tr("Device Settings")); QGroupBox* device_box = new QGroupBox(tr("Device Settings"), this);
QGridLayout* device_layout = new QGridLayout; QGridLayout* device_layout = new QGridLayout(device_box);
device_box->setLayout(device_layout); device_box->setLayout(device_layout);
m_slot_combos[0] = new QComboBox; for (int i = 0; i < SLOT_COUNT; i++)
m_slot_combos[1] = new QComboBox; {
m_slot_combos[2] = new QComboBox; m_slot_combos[i] = new QComboBox(device_box);
m_slot_buttons[i] = new QPushButton(tr("..."), device_box);
m_slot_buttons[0] = new QPushButton(tr("...")); m_slot_buttons[i]->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_slot_buttons[1] = new QPushButton(tr("...")); }
m_slot_buttons[0]->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_slot_buttons[1]->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
const QString i10n_nothing = tr("<Nothing>");
const QString i10n_dummy = tr("Dummy");
// Add slot devices // Add slot devices
for (const auto& device : {i10n_nothing, i10n_dummy, tr("Memory Card"), tr("GCI Folder"), for (const auto& entry :
tr("USB Gecko"), tr("Advance Game Port"), tr("Microphone")}) {std::make_pair(tr("<Nothing>"), ExpansionInterface::EXIDEVICE_NONE),
std::make_pair(tr("Dummy"), ExpansionInterface::EXIDEVICE_DUMMY),
std::make_pair(tr("Memory Card"), ExpansionInterface::EXIDEVICE_MEMORYCARD),
std::make_pair(tr("GCI Folder"), ExpansionInterface::EXIDEVICE_MEMORYCARDFOLDER),
std::make_pair(tr("USB Gecko"), ExpansionInterface::EXIDEVICE_GECKO),
std::make_pair(tr("Advance Game Port"), ExpansionInterface::EXIDEVICE_AGP),
std::make_pair(tr("Microphone"), ExpansionInterface::EXIDEVICE_MIC)})
{ {
m_slot_combos[0]->addItem(device); m_slot_combos[0]->addItem(entry.first, entry.second);
m_slot_combos[1]->addItem(device); m_slot_combos[1]->addItem(entry.first, entry.second);
} }
// Add SP1 devices // Add SP1 devices
for (const auto& device : {i10n_nothing, i10n_dummy, tr("Broadband Adapter")}) for (const auto& entry :
{std::make_pair(tr("<Nothing>"), ExpansionInterface::EXIDEVICE_NONE),
std::make_pair(tr("Dummy"), ExpansionInterface::EXIDEVICE_DUMMY),
std::make_pair(tr("Broadband Adapter"), ExpansionInterface::EXIDEVICE_ETH)})
{ {
m_slot_combos[2]->addItem(device); m_slot_combos[2]->addItem(entry.first, entry.second);
} }
device_layout->addWidget(new QLabel(tr("Slot A:")), 0, 0); device_layout->addWidget(new QLabel(tr("Slot A:")), 0, 0);
@ -116,6 +117,7 @@ void GameCubePane::CreateWidgets()
device_layout->addWidget(m_slot_buttons[1], 1, 2); device_layout->addWidget(m_slot_buttons[1], 1, 2);
device_layout->addWidget(new QLabel(tr("SP1:")), 2, 0); device_layout->addWidget(new QLabel(tr("SP1:")), 2, 0);
device_layout->addWidget(m_slot_combos[2], 2, 1); device_layout->addWidget(m_slot_combos[2], 2, 1);
device_layout->addWidget(m_slot_buttons[2], 2, 2);
layout->addWidget(ipl_box); layout->addWidget(ipl_box);
layout->addWidget(device_box); layout->addWidget(device_box);
@ -129,44 +131,71 @@ void GameCubePane::ConnectWidgets()
{ {
// IPL Settings // IPL Settings
connect(m_skip_main_menu, &QCheckBox::stateChanged, this, &GameCubePane::SaveSettings); connect(m_skip_main_menu, &QCheckBox::stateChanged, this, &GameCubePane::SaveSettings);
connect(m_language_combo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(m_language_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
this, &GameCubePane::SaveSettings); &GameCubePane::SaveSettings);
connect(m_override_language_ntsc, &QCheckBox::stateChanged, this, &GameCubePane::SaveSettings); connect(m_override_language_ntsc, &QCheckBox::stateChanged, this, &GameCubePane::SaveSettings);
// Device Settings // Device Settings
for (int i = 0; i < SLOT_COUNT; i++) for (int i = 0; i < SLOT_COUNT; i++)
{ {
connect(m_slot_combos[i], connect(m_slot_combos[i], QOverload<int>::of(&QComboBox::currentIndexChanged), this,
static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [this, i] { UpdateButton(i); });
connect(m_slot_combos[i], QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&GameCubePane::SaveSettings); &GameCubePane::SaveSettings);
if (i <= SLOT_B_INDEX) connect(m_slot_buttons[i], &QPushButton::pressed, this, [this, i] { OnConfigPressed(i); });
{
connect(m_slot_buttons[i], &QPushButton::pressed, this, [this, i] { OnConfigPressed(i); });
}
} }
} }
void GameCubePane::UpdateButton(int slot)
{
const auto value = m_slot_combos[slot]->currentData().toInt();
bool has_config = false;
switch (slot)
{
case SLOT_A_INDEX:
case SLOT_B_INDEX:
has_config =
(value == ExpansionInterface::EXIDEVICE_MEMORYCARD ||
value == ExpansionInterface::EXIDEVICE_AGP || value == ExpansionInterface::EXIDEVICE_MIC);
break;
case SLOT_SP1_INDEX:
has_config = (value == ExpansionInterface::EXIDEVICE_ETH);
break;
}
m_slot_buttons[slot]->setEnabled(has_config);
}
void GameCubePane::OnConfigPressed(int slot) void GameCubePane::OnConfigPressed(int slot)
{ {
QString filter; QString filter;
bool memcard = false; bool memcard = false;
switch (m_slot_combos[slot]->currentIndex()) switch (m_slot_combos[slot]->currentData().toInt())
{ {
// Memory card case ExpansionInterface::EXIDEVICE_MEMORYCARD:
case 2:
filter = tr("GameCube Memory Cards (*.raw *.gcp)"); filter = tr("GameCube Memory Cards (*.raw *.gcp)");
memcard = true; memcard = true;
break; break;
// Advance Game Port case ExpansionInterface::EXIDEVICE_AGP:
case 5:
filter = tr("Game Boy Advance Carts (*.gba)"); filter = tr("Game Boy Advance Carts (*.gba)");
memcard = false;
break; break;
// Microphone case ExpansionInterface::EXIDEVICE_MIC:
case 6:
MappingWindow(this, MappingWindow::Type::MAPPING_GC_MICROPHONE, slot).exec(); MappingWindow(this, MappingWindow::Type::MAPPING_GC_MICROPHONE, slot).exec();
return; return;
case ExpansionInterface::EXIDEVICE_ETH:
{
bool ok;
const auto new_mac = QInputDialog::getText(
this, tr("Broadband adapter MAC address"), tr("Enter new broadband adapter MAC address:"),
QLineEdit::Normal, QString::fromStdString(SConfig::GetInstance().m_bba_mac), &ok);
if (ok)
SConfig::GetInstance().m_bba_mac = new_mac.toStdString();
return;
}
default:
qFatal("unknown settings pressed");
} }
QString filename = QFileDialog::getSaveFileName( QString filename = QFileDialog::getSaveFileName(
@ -197,8 +226,8 @@ void GameCubePane::OnConfigPressed(int slot)
} }
bool other_slot_memcard = bool other_slot_memcard =
m_slot_combos[slot == 0 ? SLOT_B_INDEX : SLOT_A_INDEX]->currentIndex() == EXP_MEMORYCARD; m_slot_combos[slot == SLOT_A_INDEX ? SLOT_B_INDEX : SLOT_A_INDEX]->currentData().toInt() ==
ExpansionInterface::EXIDEVICE_MEMORYCARD;
if (other_slot_memcard) if (other_slot_memcard)
{ {
QString path_b = QString path_b =
@ -270,7 +299,7 @@ void GameCubePane::LoadSettings()
// IPL Settings // IPL Settings
m_skip_main_menu->setChecked(params.bHLE_BS2); m_skip_main_menu->setChecked(params.bHLE_BS2);
m_language_combo->setCurrentIndex(params.SelectedLanguage); m_language_combo->setCurrentIndex(m_language_combo->findData(params.SelectedLanguage));
m_override_language_ntsc->setChecked(params.bOverrideGCLanguage); m_override_language_ntsc->setChecked(params.bOverrideGCLanguage);
bool have_menu = false; bool have_menu = false;
@ -294,44 +323,10 @@ void GameCubePane::LoadSettings()
for (int i = 0; i < SLOT_COUNT; i++) for (int i = 0; i < SLOT_COUNT; i++)
{ {
int index = EXP_NOTHING; QSignalBlocker blocker(m_slot_combos[i]);
switch (SConfig::GetInstance().m_EXIDevice[i]) m_slot_combos[i]->setCurrentIndex(
{ m_slot_combos[i]->findData(SConfig::GetInstance().m_EXIDevice[i]));
case ExpansionInterface::EXIDEVICE_NONE: UpdateButton(i);
index = EXP_NOTHING;
break;
case ExpansionInterface::EXIDEVICE_DUMMY:
index = EXP_DUMMY;
break;
case ExpansionInterface::EXIDEVICE_MEMORYCARD:
index = EXP_MEMORYCARD;
break;
case ExpansionInterface::EXIDEVICE_ETH:
index = EXP_BROADBAND;
break;
case ExpansionInterface::EXIDEVICE_MEMORYCARDFOLDER:
index = EXP_GCI_FOLDER;
break;
case ExpansionInterface::EXIDEVICE_GECKO:
index = EXP_GECKO;
break;
case ExpansionInterface::EXIDEVICE_AGP:
index = EXP_AGP;
break;
case ExpansionInterface::EXIDEVICE_MIC:
index = EXP_MICROPHONE;
break;
default:
break;
}
if (i <= SLOT_B_INDEX)
{
bool has_config = (index == EXP_MEMORYCARD || index > EXP_GECKO);
m_slot_buttons[i]->setEnabled(has_config);
}
m_slot_combos[i]->setCurrentIndex(index);
} }
} }
@ -342,45 +337,15 @@ void GameCubePane::SaveSettings()
// IPL Settings // IPL Settings
params.bHLE_BS2 = m_skip_main_menu->isChecked(); params.bHLE_BS2 = m_skip_main_menu->isChecked();
Config::SetBaseOrCurrent(Config::MAIN_SKIP_IPL, m_skip_main_menu->isChecked()); Config::SetBaseOrCurrent(Config::MAIN_SKIP_IPL, m_skip_main_menu->isChecked());
params.SelectedLanguage = m_language_combo->currentIndex(); params.SelectedLanguage = m_language_combo->currentData().toInt();
Config::SetBaseOrCurrent(Config::MAIN_GC_LANGUAGE, m_language_combo->currentIndex()); Config::SetBaseOrCurrent(Config::MAIN_GC_LANGUAGE, m_language_combo->currentData().toInt());
params.bOverrideGCLanguage = m_override_language_ntsc->isChecked(); params.bOverrideGCLanguage = m_override_language_ntsc->isChecked();
Config::SetBaseOrCurrent(Config::MAIN_OVERRIDE_GC_LANGUAGE, Config::SetBaseOrCurrent(Config::MAIN_OVERRIDE_GC_LANGUAGE,
m_override_language_ntsc->isChecked()); m_override_language_ntsc->isChecked());
for (int i = 0; i < SLOT_COUNT; i++) for (int i = 0; i < SLOT_COUNT; i++)
{ {
auto dev = SConfig::GetInstance().m_EXIDevice[i]; const auto dev = ExpansionInterface::TEXIDevices(m_slot_combos[i]->currentData().toInt());
int index = m_slot_combos[i]->currentIndex();
switch (index)
{
case EXP_NOTHING:
dev = ExpansionInterface::EXIDEVICE_NONE;
break;
case EXP_DUMMY:
dev = ExpansionInterface::EXIDEVICE_DUMMY;
break;
case EXP_MEMORYCARD:
if (i == SLOT_SP1_INDEX)
dev = ExpansionInterface::EXIDEVICE_ETH;
else
dev = ExpansionInterface::EXIDEVICE_MEMORYCARD;
break;
case EXP_GCI_FOLDER:
dev = ExpansionInterface::EXIDEVICE_MEMORYCARDFOLDER;
break;
case EXP_GECKO:
dev = ExpansionInterface::EXIDEVICE_GECKO;
break;
case EXP_AGP:
dev = ExpansionInterface::EXIDEVICE_AGP;
break;
case EXP_MICROPHONE:
dev = ExpansionInterface::EXIDEVICE_MIC;
break;
}
if (Core::IsRunning() && SConfig::GetInstance().m_EXIDevice[i] != dev) if (Core::IsRunning() && SConfig::GetInstance().m_EXIDevice[i] != dev)
{ {

View File

@ -23,12 +23,13 @@ private:
void LoadSettings(); void LoadSettings();
void SaveSettings(); void SaveSettings();
void UpdateButton(int slot);
void OnConfigPressed(int slot); void OnConfigPressed(int slot);
QCheckBox* m_skip_main_menu; QCheckBox* m_skip_main_menu;
QCheckBox* m_override_language_ntsc; QCheckBox* m_override_language_ntsc;
QComboBox* m_language_combo; QComboBox* m_language_combo;
QPushButton* m_slot_buttons[2]; QPushButton* m_slot_buttons[3];
QComboBox* m_slot_combos[3]; QComboBox* m_slot_combos[3];
}; };