dolphin/Source/Core/DolphinQt/Settings/GameCubePane.cpp

377 lines
12 KiB
C++
Raw Normal View History

2018-01-04 00:41:31 +00:00
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
2018-07-06 22:40:15 +00:00
#include "DolphinQt/Settings/GameCubePane.h"
2018-01-04 00:41:31 +00:00
#include <QCheckBox>
#include <QComboBox>
#include <QFileDialog>
#include <QFileInfo>
#include <QGridLayout>
#include <QGroupBox>
#include <QInputDialog>
2018-01-04 00:41:31 +00:00
#include <QLabel>
#include <QMessageBox>
#include <QPushButton>
#include <QVBoxLayout>
#include <utility>
2018-01-04 00:41:31 +00:00
#include "Common/CommonPaths.h"
#include "Common/Config/Config.h"
2018-01-04 00:41:31 +00:00
#include "Common/FileUtil.h"
2018-05-28 01:48:04 +00:00
#include "Core/Config/MainSettings.h"
2018-01-04 00:41:31 +00:00
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/HW/EXI/EXI.h"
#include "Core/HW/GCMemcard/GCMemcard.h"
2018-05-28 01:48:04 +00:00
2018-07-06 22:40:15 +00:00
#include "DolphinQt/Config/Mapping/MappingWindow.h"
2018-01-04 00:41:31 +00:00
enum
{
SLOT_A_INDEX,
SLOT_B_INDEX,
SLOT_SP1_INDEX,
SLOT_COUNT
};
2018-01-04 00:41:31 +00:00
GameCubePane::GameCubePane()
{
CreateWidgets();
LoadSettings();
ConnectWidgets();
2018-01-04 00:41:31 +00:00
}
void GameCubePane::CreateWidgets()
{
QVBoxLayout* layout = new QVBoxLayout(this);
2018-01-04 00:41:31 +00:00
// IPL Settings
QGroupBox* ipl_box = new QGroupBox(tr("IPL Settings"), this);
QGridLayout* ipl_layout = new QGridLayout(ipl_box);
2018-01-04 00:41:31 +00:00
ipl_box->setLayout(ipl_layout);
m_skip_main_menu = new QCheckBox(tr("Skip Main Menu"), ipl_box);
m_override_language_ntsc = new QCheckBox(tr("Override Language on NTSC Games"), ipl_box);
m_language_combo = new QComboBox(ipl_box);
m_language_combo->setCurrentIndex(-1);
2018-01-04 00:41:31 +00:00
// Add languages
for (const auto& entry : {std::make_pair(tr("English"), 0), std::make_pair(tr("German"), 1),
std::make_pair(tr("French"), 2), std::make_pair(tr("Spanish"), 3),
std::make_pair(tr("Italian"), 4), std::make_pair(tr("Dutch"), 5)})
{
m_language_combo->addItem(entry.first, entry.second);
}
2018-01-04 00:41:31 +00:00
ipl_layout->addWidget(m_skip_main_menu, 0, 0);
ipl_layout->addWidget(new QLabel(tr("System Language:")), 1, 0);
ipl_layout->addWidget(m_language_combo, 1, 1);
ipl_layout->addWidget(m_override_language_ntsc, 2, 0);
// Device Settings
QGroupBox* device_box = new QGroupBox(tr("Device Settings"), this);
QGridLayout* device_layout = new QGridLayout(device_box);
2018-01-04 00:41:31 +00:00
device_box->setLayout(device_layout);
for (int i = 0; i < SLOT_COUNT; i++)
{
m_slot_combos[i] = new QComboBox(device_box);
m_slot_buttons[i] = new QPushButton(tr("..."), device_box);
m_slot_buttons[i]->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}
2018-01-04 00:41:31 +00:00
// Add slot devices
for (const auto& entry :
{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)})
2018-01-04 00:41:31 +00:00
{
m_slot_combos[0]->addItem(entry.first, entry.second);
m_slot_combos[1]->addItem(entry.first, entry.second);
2018-01-04 00:41:31 +00:00
}
// Add SP1 devices
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)})
2018-01-04 00:41:31 +00:00
{
m_slot_combos[2]->addItem(entry.first, entry.second);
2018-01-04 00:41:31 +00:00
}
device_layout->addWidget(new QLabel(tr("Slot A:")), 0, 0);
device_layout->addWidget(m_slot_combos[0], 0, 1);
device_layout->addWidget(m_slot_buttons[0], 0, 2);
device_layout->addWidget(new QLabel(tr("Slot B:")), 1, 0);
device_layout->addWidget(m_slot_combos[1], 1, 1);
device_layout->addWidget(m_slot_buttons[1], 1, 2);
device_layout->addWidget(new QLabel(tr("SP1:")), 2, 0);
device_layout->addWidget(m_slot_combos[2], 2, 1);
device_layout->addWidget(m_slot_buttons[2], 2, 2);
2018-01-04 00:41:31 +00:00
layout->addWidget(ipl_box);
layout->addWidget(device_box);
2018-03-24 17:18:17 +00:00
layout->addStretch();
2018-01-04 00:41:31 +00:00
setLayout(layout);
}
void GameCubePane::ConnectWidgets()
{
// IPL Settings
connect(m_skip_main_menu, &QCheckBox::stateChanged, this, &GameCubePane::SaveSettings);
connect(m_language_combo, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&GameCubePane::SaveSettings);
2018-01-04 00:41:31 +00:00
connect(m_override_language_ntsc, &QCheckBox::stateChanged, this, &GameCubePane::SaveSettings);
// Device Settings
for (int i = 0; i < SLOT_COUNT; i++)
{
connect(m_slot_combos[i], QOverload<int>::of(&QComboBox::currentIndexChanged), this,
[this, i] { UpdateButton(i); });
connect(m_slot_combos[i], QOverload<int>::of(&QComboBox::currentIndexChanged), this,
2018-01-04 00:41:31 +00:00
&GameCubePane::SaveSettings);
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;
2018-01-04 00:41:31 +00:00
}
m_slot_buttons[slot]->setEnabled(has_config);
2018-01-04 00:41:31 +00:00
}
void GameCubePane::OnConfigPressed(int slot)
{
QString filter;
bool memcard = false;
switch (m_slot_combos[slot]->currentData().toInt())
2018-01-04 00:41:31 +00:00
{
case ExpansionInterface::EXIDEVICE_MEMORYCARD:
filter = tr("GameCube Memory Cards (*.raw *.gcp)");
2018-01-04 00:41:31 +00:00
memcard = true;
break;
case ExpansionInterface::EXIDEVICE_AGP:
2018-01-04 00:41:31 +00:00
filter = tr("Game Boy Advance Carts (*.gba)");
break;
case ExpansionInterface::EXIDEVICE_MIC:
2018-01-04 00:41:31 +00:00
MappingWindow(this, MappingWindow::Type::MAPPING_GC_MICROPHONE, slot).exec();
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");
2018-01-04 00:41:31 +00:00
}
QString filename = QFileDialog::getSaveFileName(
this, tr("Choose a file to open"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
filter, 0, QFileDialog::DontConfirmOverwrite);
2018-01-04 00:41:31 +00:00
if (filename.isEmpty())
2018-01-04 00:41:31 +00:00
return;
2018-02-02 11:28:57 +00:00
QString path_abs = QFileInfo(filename).absoluteFilePath();
2018-01-04 00:41:31 +00:00
// Memcard validity checks
if (memcard)
{
if (File::Exists(filename.toStdString()))
2018-01-04 00:41:31 +00:00
{
GCMemcard mc(filename.toStdString());
if (!mc.IsValid())
{
QMessageBox::critical(this, tr("Error"),
tr("Cannot use that file as a memory card.\n%1\n"
"is not a valid GameCube memory card file")
.arg(filename));
return;
}
2018-01-04 00:41:31 +00:00
}
2018-02-02 11:28:57 +00:00
bool other_slot_memcard =
m_slot_combos[slot == SLOT_A_INDEX ? SLOT_B_INDEX : SLOT_A_INDEX]->currentData().toInt() ==
ExpansionInterface::EXIDEVICE_MEMORYCARD;
2018-02-02 11:28:57 +00:00
if (other_slot_memcard)
2018-01-04 00:41:31 +00:00
{
2018-02-02 11:28:57 +00:00
QString path_b =
QFileInfo(QString::fromStdString(slot == 0 ? Config::Get(Config::MAIN_MEMCARD_B_PATH) :
Config::Get(Config::MAIN_MEMCARD_A_PATH)))
2018-02-02 11:28:57 +00:00
.absoluteFilePath();
if (path_abs == path_b)
{
QMessageBox::critical(this, tr("Error"), tr("The same file can't be used in both slots."));
return;
}
2018-01-04 00:41:31 +00:00
}
}
QString path_old;
if (memcard)
{
path_old =
QFileInfo(QString::fromStdString(slot == 0 ? Config::Get(Config::MAIN_MEMCARD_A_PATH) :
Config::Get(Config::MAIN_MEMCARD_B_PATH)))
.absoluteFilePath();
}
else
{
path_old = QFileInfo(QString::fromStdString(slot == 0 ? SConfig::GetInstance().m_strGbaCartA :
SConfig::GetInstance().m_strGbaCartB))
.absoluteFilePath();
}
2018-01-04 00:41:31 +00:00
if (memcard)
{
if (slot == SLOT_A_INDEX)
{
Config::SetBase(Config::MAIN_MEMCARD_A_PATH, path_abs.toStdString());
2018-01-04 00:41:31 +00:00
}
else
{
Config::SetBase(Config::MAIN_MEMCARD_B_PATH, path_abs.toStdString());
2018-01-04 00:41:31 +00:00
}
}
else
{
if (slot == SLOT_A_INDEX)
{
SConfig::GetInstance().m_strGbaCartA = path_abs.toStdString();
}
else
{
SConfig::GetInstance().m_strGbaCartB = path_abs.toStdString();
}
}
if (Core::IsRunning() && path_abs != path_old)
{
ExpansionInterface::ChangeDevice(
// SlotB is on channel 1, slotA and SP1 are on 0
slot,
// The device enum to change to
memcard ? ExpansionInterface::EXIDEVICE_MEMORYCARD : ExpansionInterface::EXIDEVICE_AGP,
// SP1 is device 2, slots are device 0
0);
}
2018-01-04 00:41:31 +00:00
}
void GameCubePane::LoadSettings()
{
const SConfig& params = SConfig::GetInstance();
// IPL Settings
m_skip_main_menu->setChecked(params.bHLE_BS2);
m_language_combo->setCurrentIndex(m_language_combo->findData(params.SelectedLanguage));
2018-01-04 00:41:31 +00:00
m_override_language_ntsc->setChecked(params.bOverrideGCLanguage);
bool have_menu = false;
for (const std::string& dir : {USA_DIR, JAP_DIR, EUR_DIR})
{
const auto path = DIR_SEP + dir + DIR_SEP GC_IPL;
2018-01-04 00:41:31 +00:00
if (File::Exists(File::GetUserPath(D_GCUSER_IDX) + path) ||
File::Exists(File::GetSysDirectory() + GC_SYS_DIR + path))
2018-01-04 00:41:31 +00:00
{
have_menu = true;
break;
}
}
m_skip_main_menu->setEnabled(have_menu);
m_skip_main_menu->setToolTip(have_menu ? QStringLiteral("") :
tr("Put Main Menu roms in User/GC/{region}."));
// Device Settings
for (int i = 0; i < SLOT_COUNT; i++)
{
QSignalBlocker blocker(m_slot_combos[i]);
m_slot_combos[i]->setCurrentIndex(
m_slot_combos[i]->findData(SConfig::GetInstance().m_EXIDevice[i]));
UpdateButton(i);
2018-01-04 00:41:31 +00:00
}
}
void GameCubePane::SaveSettings()
{
SConfig& params = SConfig::GetInstance();
// IPL Settings
params.bHLE_BS2 = m_skip_main_menu->isChecked();
Config::SetBaseOrCurrent(Config::MAIN_SKIP_IPL, m_skip_main_menu->isChecked());
params.SelectedLanguage = m_language_combo->currentData().toInt();
Config::SetBaseOrCurrent(Config::MAIN_GC_LANGUAGE, m_language_combo->currentData().toInt());
2018-01-04 00:41:31 +00:00
params.bOverrideGCLanguage = m_override_language_ntsc->isChecked();
Config::SetBaseOrCurrent(Config::MAIN_OVERRIDE_GC_LANGUAGE,
m_override_language_ntsc->isChecked());
2018-01-04 00:41:31 +00:00
for (int i = 0; i < SLOT_COUNT; i++)
{
const auto dev = ExpansionInterface::TEXIDevices(m_slot_combos[i]->currentData().toInt());
2018-01-04 00:41:31 +00:00
if (Core::IsRunning() && SConfig::GetInstance().m_EXIDevice[i] != dev)
{
ExpansionInterface::ChangeDevice(
// SlotB is on channel 1, slotA and SP1 are on 0
(i == 1) ? 1 : 0,
// The device enum to change to
dev,
// SP1 is device 2, slots are device 0
(i == 2) ? 2 : 0);
2018-01-04 00:41:31 +00:00
}
SConfig::GetInstance().m_EXIDevice[i] = dev;
switch (i)
{
case SLOT_A_INDEX:
Config::SetBaseOrCurrent(Config::MAIN_SLOT_A, dev);
break;
case SLOT_B_INDEX:
Config::SetBaseOrCurrent(Config::MAIN_SLOT_B, dev);
break;
case SLOT_SP1_INDEX:
Config::SetBaseOrCurrent(Config::MAIN_SERIAL_PORT_1, dev);
break;
}
2018-01-04 00:41:31 +00:00
}
LoadSettings();
}