mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-19 13:05:45 -04:00
UI: Massive revamp, new features and improvements
This commit is contained in:
@ -1,19 +1,96 @@
|
||||
#include "biossettingswidget.h"
|
||||
#include "core/bios.h"
|
||||
#include "qthostinterface.h"
|
||||
#include "qthost.h"
|
||||
#include "qtutils.h"
|
||||
#include "settingsdialog.h"
|
||||
#include "settingwidgetbinder.h"
|
||||
#include <QtWidgets/QFileDialog>
|
||||
#include <algorithm>
|
||||
|
||||
static void populateDropDownForRegion(ConsoleRegion region, QComboBox* cb,
|
||||
std::vector<std::pair<std::string, const BIOS::ImageInfo*>>& images)
|
||||
BIOSSettingsWidget::BIOSSettingsWidget(SettingsDialog* dialog, QWidget* parent) : QWidget(parent), m_dialog(dialog)
|
||||
{
|
||||
SettingsInterface* sif = dialog->getSettingsInterface();
|
||||
|
||||
m_ui.setupUi(this);
|
||||
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.enableTTYOutput, "BIOS", "PatchTTYEnable", false);
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(sif, m_ui.fastBoot, "BIOS", "PatchFastBoot", false);
|
||||
|
||||
dialog->registerWidgetHelp(m_ui.fastBoot, tr("Fast Boot"), tr("Unchecked"),
|
||||
tr("Patches the BIOS to skip the console's boot animation. Does not work with all games, "
|
||||
"but usually safe to enable."));
|
||||
dialog->registerWidgetHelp(
|
||||
m_ui.enableTTYOutput, tr("Enable TTY Output"), tr("Unchecked"),
|
||||
tr("Patches the BIOS to log calls to printf(). Only use when debugging, can break games."));
|
||||
|
||||
connect(m_ui.imageNTSCJ, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
if (m_dialog->isPerGameSettings() && index == 0)
|
||||
{
|
||||
m_dialog->removeSettingValue("BIOS", "PathNTSCJ");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dialog->setStringSettingValue("BIOS", "PathNTSCJ",
|
||||
m_ui.imageNTSCJ->itemData(index).toString().toStdString().c_str());
|
||||
}
|
||||
});
|
||||
connect(m_ui.imageNTSCU, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
if (m_dialog->isPerGameSettings() && index == 0)
|
||||
{
|
||||
m_dialog->removeSettingValue("BIOS", "PathNTSCU");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dialog->setStringSettingValue("BIOS", "PathNTSCU",
|
||||
m_ui.imageNTSCU->itemData(index).toString().toStdString().c_str());
|
||||
}
|
||||
});
|
||||
connect(m_ui.imagePAL, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
if (m_dialog->isPerGameSettings() && index == 0)
|
||||
{
|
||||
m_dialog->removeSettingValue("BIOS", "PathPAL");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dialog->setStringSettingValue("BIOS", "PathPAL",
|
||||
m_ui.imagePAL->itemData(index).toString().toStdString().c_str());
|
||||
}
|
||||
});
|
||||
|
||||
connect(m_ui.refresh, &QPushButton::clicked, this, &BIOSSettingsWidget::refreshList);
|
||||
|
||||
m_ui.searchDirectory->setText(QString::fromStdString(EmuFolders::Bios));
|
||||
SettingWidgetBinder::BindWidgetToFolderSetting(sif, m_ui.searchDirectory, m_ui.browseSearchDirectory,
|
||||
m_ui.openSearchDirectory, nullptr, "BIOS", "SearchDirectory",
|
||||
Path::Combine(EmuFolders::DataRoot, "bios"));
|
||||
connect(m_ui.searchDirectory, &QLineEdit::textChanged, this, &BIOSSettingsWidget::refreshList);
|
||||
refreshList();
|
||||
}
|
||||
|
||||
BIOSSettingsWidget::~BIOSSettingsWidget() = default;
|
||||
|
||||
void BIOSSettingsWidget::refreshList()
|
||||
{
|
||||
auto images = BIOS::FindBIOSImagesInDirectory(m_ui.searchDirectory->text().toUtf8().constData());
|
||||
populateDropDownForRegion(ConsoleRegion::NTSC_J, m_ui.imageNTSCJ, images);
|
||||
populateDropDownForRegion(ConsoleRegion::NTSC_U, m_ui.imageNTSCU, images);
|
||||
populateDropDownForRegion(ConsoleRegion::PAL, m_ui.imagePAL, images);
|
||||
|
||||
setDropDownValue(m_ui.imageNTSCJ, m_dialog->getStringValue("BIOS", "PathNTSCJ", std::nullopt));
|
||||
setDropDownValue(m_ui.imageNTSCU, m_dialog->getStringValue("BIOS", "PathNTSCU", std::nullopt));
|
||||
setDropDownValue(m_ui.imagePAL, m_dialog->getStringValue("BIOS", "PathPAL", std::nullopt));
|
||||
}
|
||||
|
||||
void BIOSSettingsWidget::populateDropDownForRegion(ConsoleRegion region, QComboBox* cb,
|
||||
std::vector<std::pair<std::string, const BIOS::ImageInfo*>>& images)
|
||||
{
|
||||
QSignalBlocker sb(cb);
|
||||
cb->clear();
|
||||
|
||||
cb->addItem(QIcon(QStringLiteral(":/icons/system-search.png")), qApp->translate("BIOSSettingsWidget", "Auto-Detect"));
|
||||
if (m_dialog->isPerGameSettings())
|
||||
cb->addItem(QIcon(QStringLiteral(":/icons/system-search.png")), tr("Use Global Setting"));
|
||||
|
||||
cb->addItem(QIcon(QStringLiteral(":/icons/system-search.png")), tr("Auto-Detect"));
|
||||
|
||||
std::sort(images.begin(), images.end(), [region](const auto& left, const auto& right) {
|
||||
const bool left_region_match = (left.second && left.second->region == region);
|
||||
@ -28,32 +105,8 @@ static void populateDropDownForRegion(ConsoleRegion region, QComboBox* cb,
|
||||
|
||||
for (const auto& [name, info] : images)
|
||||
{
|
||||
QIcon icon;
|
||||
if (info)
|
||||
{
|
||||
switch (info->region)
|
||||
{
|
||||
case ConsoleRegion::NTSC_J:
|
||||
icon = QIcon(QStringLiteral(":/icons/flag-jp.png"));
|
||||
break;
|
||||
case ConsoleRegion::PAL:
|
||||
icon = QIcon(QStringLiteral(":/icons/flag-eu.png"));
|
||||
break;
|
||||
case ConsoleRegion::NTSC_U:
|
||||
icon = QIcon(QStringLiteral(":/icons/flag-uc.png"));
|
||||
break;
|
||||
default:
|
||||
icon = QIcon(QStringLiteral(":/icons/applications-other.png"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = QIcon(QStringLiteral(":/icons/applications-other.png"));
|
||||
}
|
||||
|
||||
QString name_str(QString::fromStdString(name));
|
||||
cb->addItem(icon,
|
||||
cb->addItem(QtUtils::GetIconForRegion(info ? info->region : ConsoleRegion::Count),
|
||||
QStringLiteral("%1 (%2)")
|
||||
.arg(info ? QString(info->description) : qApp->translate("BIOSSettingsWidget", "Unknown"))
|
||||
.arg(name_str),
|
||||
@ -61,17 +114,17 @@ static void populateDropDownForRegion(ConsoleRegion region, QComboBox* cb,
|
||||
}
|
||||
}
|
||||
|
||||
static void setDropDownValue(QComboBox* cb, const std::string& name)
|
||||
void BIOSSettingsWidget::setDropDownValue(QComboBox* cb, const std::optional<std::string>& name)
|
||||
{
|
||||
QSignalBlocker sb(cb);
|
||||
|
||||
if (name.empty())
|
||||
if (!name.has_value() || name->empty())
|
||||
{
|
||||
cb->setCurrentIndex(0);
|
||||
cb->setCurrentIndex((m_dialog->isPerGameSettings() && name.has_value()) ? 1 : 0);
|
||||
return;
|
||||
}
|
||||
|
||||
QString qname(QString::fromStdString(name));
|
||||
QString qname(QString::fromStdString(name.value()));
|
||||
for (int i = 1; i < cb->count(); i++)
|
||||
{
|
||||
if (cb->itemData(i) == qname)
|
||||
@ -84,84 +137,3 @@ static void setDropDownValue(QComboBox* cb, const std::string& name)
|
||||
cb->addItem(qname, QVariant(qname));
|
||||
cb->setCurrentIndex(cb->count() - 1);
|
||||
}
|
||||
|
||||
BIOSSettingsWidget::BIOSSettingsWidget(QtHostInterface* host_interface, QWidget* parent, SettingsDialog* dialog)
|
||||
: QWidget(parent), m_host_interface(host_interface)
|
||||
{
|
||||
m_ui.setupUi(this);
|
||||
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.enableTTYOutput, "BIOS", "PatchTTYEnable");
|
||||
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.fastBoot, "BIOS", "PatchFastBoot");
|
||||
|
||||
dialog->registerWidgetHelp(m_ui.fastBoot, tr("Fast Boot"), tr("Unchecked"),
|
||||
tr("Patches the BIOS to skip the console's boot animation. Does not work with all games, "
|
||||
"but usually safe to enable."));
|
||||
dialog->registerWidgetHelp(m_ui.enableTTYOutput, tr("Enable TTY Output"), tr("Unchecked"),
|
||||
tr("Patches the BIOS to log calls to printf(). Only use when debugging, can break games."));
|
||||
|
||||
refreshList();
|
||||
|
||||
connect(m_ui.imageNTSCJ, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
m_host_interface->SetStringSettingValue("BIOS", "PathNTSCJ",
|
||||
m_ui.imageNTSCJ->itemData(index).toString().toStdString().c_str());
|
||||
m_host_interface->applySettings();
|
||||
});
|
||||
connect(m_ui.imageNTSCU, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
m_host_interface->SetStringSettingValue("BIOS", "PathNTSCU",
|
||||
m_ui.imageNTSCU->itemData(index).toString().toStdString().c_str());
|
||||
m_host_interface->applySettings();
|
||||
});
|
||||
connect(m_ui.imagePAL, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
|
||||
m_host_interface->SetStringSettingValue("BIOS", "PathPAL",
|
||||
m_ui.imagePAL->itemData(index).toString().toStdString().c_str());
|
||||
m_host_interface->applySettings();
|
||||
});
|
||||
|
||||
connect(m_ui.refresh, &QPushButton::clicked, this, &BIOSSettingsWidget::refreshList);
|
||||
|
||||
std::string current_search_directory = g_host_interface->GetBIOSDirectory();
|
||||
m_ui.searchDirectory->setText(QString::fromStdString(current_search_directory));
|
||||
connect(m_ui.searchDirectory, &QLineEdit::textChanged, [this](const QString& text) {
|
||||
if (text.isEmpty())
|
||||
{
|
||||
m_host_interface->RemoveSettingValue("BIOS", "SearchDirectory");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_host_interface->SetStringSettingValue("BIOS", "SearchDirectory", text.toStdString().c_str());
|
||||
}
|
||||
refreshList();
|
||||
});
|
||||
connect(m_ui.browseSearchDirectory, &QPushButton::clicked, this, &BIOSSettingsWidget::browseSearchDirectory);
|
||||
connect(m_ui.openSearchDirectory, &QPushButton::clicked, this, &BIOSSettingsWidget::openSearchDirectory);
|
||||
}
|
||||
|
||||
BIOSSettingsWidget::~BIOSSettingsWidget() = default;
|
||||
|
||||
void BIOSSettingsWidget::refreshList()
|
||||
{
|
||||
auto images = m_host_interface->FindBIOSImagesInDirectory(m_host_interface->GetBIOSDirectory().c_str());
|
||||
populateDropDownForRegion(ConsoleRegion::NTSC_J, m_ui.imageNTSCJ, images);
|
||||
populateDropDownForRegion(ConsoleRegion::NTSC_U, m_ui.imageNTSCU, images);
|
||||
populateDropDownForRegion(ConsoleRegion::PAL, m_ui.imagePAL, images);
|
||||
|
||||
setDropDownValue(m_ui.imageNTSCJ, m_host_interface->GetStringSettingValue("BIOS", "PathNTSCJ", ""));
|
||||
setDropDownValue(m_ui.imageNTSCU, m_host_interface->GetStringSettingValue("BIOS", "PathNTSCU", ""));
|
||||
setDropDownValue(m_ui.imagePAL, m_host_interface->GetStringSettingValue("BIOS", "PathPAL", ""));
|
||||
}
|
||||
|
||||
void BIOSSettingsWidget::browseSearchDirectory()
|
||||
{
|
||||
QString directory = QFileDialog::getExistingDirectory(QtUtils::GetRootWidget(this), tr("Select Directory"),
|
||||
m_ui.searchDirectory->text());
|
||||
if (directory.isEmpty())
|
||||
return;
|
||||
|
||||
m_ui.searchDirectory->setText(directory);
|
||||
}
|
||||
|
||||
void BIOSSettingsWidget::openSearchDirectory()
|
||||
{
|
||||
QString dir = QString::fromStdString(m_host_interface->GetBIOSDirectory());
|
||||
QtUtils::OpenURL(this, QUrl::fromLocalFile(dir));
|
||||
}
|
||||
|
Reference in New Issue
Block a user