UI: Massive revamp, new features and improvements

This commit is contained in:
Connor McLaughlin
2022-07-11 23:03:29 +10:00
parent 3fb61865e5
commit b42b5501f6
425 changed files with 39701 additions and 29487 deletions

View File

@@ -4,7 +4,7 @@
#include "core/settings.h"
#include "inputbindingwidgets.h"
#include "mainwindow.h"
#include "qthostinterface.h"
#include "qthost.h"
#include "qtutils.h"
#include "settingsdialog.h"
#include "settingwidgetbinder.h"
@@ -15,9 +15,8 @@
static constexpr char MEMORY_CARD_IMAGE_FILTER[] =
QT_TRANSLATE_NOOP("MemoryCardSettingsWidget", "All Memory Card Types (*.mcd *.mcr *.mc)");
MemoryCardSettingsWidget::MemoryCardSettingsWidget(QtHostInterface* host_interface, QWidget* parent,
SettingsDialog* dialog)
: QWidget(parent), m_host_interface(host_interface)
MemoryCardSettingsWidget::MemoryCardSettingsWidget(SettingsDialog* dialog, QWidget* parent)
: QWidget(parent), m_dialog(dialog)
{
createUi(dialog);
}
@@ -38,6 +37,9 @@ void MemoryCardSettingsWidget::createUi(SettingsDialog* dialog)
{
QGroupBox* box = new QGroupBox(tr("Shared Settings"), this);
QVBoxLayout* box_layout = new QVBoxLayout(box);
QPushButton* browse = new QPushButton(tr("Browse..."), box);
QPushButton* reset = new QPushButton(tr("Reset"), box);
QPushButton* open_memcards = new QPushButton(tr("Open Directory..."), box);
{
QLabel* label = new QLabel(tr("Memory Card Directory:"), box);
@@ -45,29 +47,17 @@ void MemoryCardSettingsWidget::createUi(SettingsDialog* dialog)
QHBoxLayout* hbox = new QHBoxLayout();
m_memory_card_directory = new QLineEdit(box);
SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, m_memory_card_directory, "MemoryCards",
"Directory");
if (m_memory_card_directory->text().isEmpty())
{
QSignalBlocker sb(m_memory_card_directory);
m_memory_card_directory->setText(QString::fromStdString(m_host_interface->GetMemoryCardDirectory()));
}
hbox->addWidget(m_memory_card_directory);
QPushButton* browse = new QPushButton(tr("Browse..."), box);
connect(browse, &QPushButton::clicked, this, &MemoryCardSettingsWidget::onBrowseMemCardsDirectoryClicked);
hbox->addWidget(browse);
QPushButton* reset = new QPushButton(tr("Reset"), box);
connect(reset, &QPushButton::clicked, this, &MemoryCardSettingsWidget::onResetMemCardsDirectoryClicked);
hbox->addWidget(reset);
box_layout->addLayout(hbox);
}
QCheckBox* playlist_title_as_game_title = new QCheckBox(tr("Use Single Card For Sub-Images"), box);
SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, playlist_title_as_game_title, "MemoryCards",
"UsePlaylistTitle", true);
SettingWidgetBinder::BindWidgetToBoolSetting(m_dialog->getSettingsInterface(), playlist_title_as_game_title,
"MemoryCards", "UsePlaylistTitle", true);
box_layout->addWidget(playlist_title_as_game_title);
dialog->registerWidgetHelp(
playlist_title_as_game_title, tr("Use Single Card For Sub-Images"), tr("Checked"),
@@ -86,8 +76,6 @@ void MemoryCardSettingsWidget::createUi(SettingsDialog* dialog)
note_label->setWordWrap(true);
note_layout->addWidget(note_label, 1);
QPushButton* open_memcards = new QPushButton(tr("Open Directory..."), box);
connect(open_memcards, &QPushButton::clicked, this, &MemoryCardSettingsWidget::onOpenMemCardsDirectoryClicked);
note_layout->addWidget(open_memcards);
box_layout->addLayout(note_layout);
}
@@ -101,13 +89,16 @@ void MemoryCardSettingsWidget::createUi(SettingsDialog* dialog)
hbox->addWidget(label, 1);
QPushButton* button = new QPushButton(tr("Memory Card Editor..."), box);
connect(button, &QPushButton::clicked,
[]() { QtHostInterface::GetInstance()->getMainWindow()->openMemoryCardEditor(QString(), QString()); });
connect(button, &QPushButton::clicked, []() { g_main_window->openMemoryCardEditor(QString(), QString()); });
hbox->addWidget(button);
box_layout->addLayout(hbox);
}
layout->addWidget(box);
SettingWidgetBinder::BindWidgetToFolderSetting(m_dialog->getSettingsInterface(), m_memory_card_directory, browse,
open_memcards, reset, "MemoryCards", "Directory",
Path::Combine(EmuFolders::DataRoot, "memcards"));
}
layout->addStretch(1);
@@ -128,30 +119,32 @@ void MemoryCardSettingsWidget::createPortSettingsUi(SettingsDialog* dialog, int
}
const MemoryCardType default_value = (index == 0) ? MemoryCardType::PerGameTitle : MemoryCardType::None;
SettingWidgetBinder::BindWidgetToEnumSetting(
m_host_interface, ui->memory_card_type, "MemoryCards", StringUtil::StdStringFromFormat("Card%dType", index + 1),
&Settings::ParseMemoryCardTypeName, &Settings::GetMemoryCardTypeName, default_value);
SettingWidgetBinder::BindWidgetToEnumSetting(m_dialog->getSettingsInterface(), ui->memory_card_type, "MemoryCards",
StringUtil::StdStringFromFormat("Card%dType", index + 1),
&Settings::ParseMemoryCardTypeName, &Settings::GetMemoryCardTypeName,
default_value);
ui->layout->addWidget(new QLabel(tr("Memory Card Type:"), ui->container));
ui->layout->addWidget(ui->memory_card_type);
QHBoxLayout* memory_card_layout = new QHBoxLayout();
ui->memory_card_path = new QLineEdit(ui->container);
SettingWidgetBinder::BindWidgetToStringSetting(m_host_interface, ui->memory_card_path, "MemoryCards",
StringUtil::StdStringFromFormat("Card%dPath", index + 1));
updateMemoryCardPath(index);
connect(ui->memory_card_path, &QLineEdit::textChanged, this, [this, index]() { onMemoryCardPathChanged(index); });
if (ui->memory_card_path->text().isEmpty())
{
QSignalBlocker sb(ui->memory_card_path);
ui->memory_card_path->setText(
QString::fromStdString(m_host_interface->GetSharedMemoryCardPath(static_cast<u32>(index))));
ui->memory_card_path->setText(QString::fromStdString(g_settings.GetSharedMemoryCardPath(static_cast<u32>(index))));
}
memory_card_layout->addWidget(ui->memory_card_path);
QPushButton* memory_card_path_browse = new QPushButton(tr("Browse..."), ui->container);
connect(memory_card_path_browse, &QPushButton::clicked, [this, index]() { onBrowseMemoryCardPathClicked(index); });
connect(memory_card_path_browse, &QPushButton::clicked, this,
[this, index]() { onBrowseMemoryCardPathClicked(index); });
memory_card_layout->addWidget(memory_card_path_browse);
QPushButton* memory_card_path_reset = new QPushButton(tr("Reset"), ui->container);
connect(memory_card_path_reset, &QPushButton::clicked, [this, index]() { onResetMemoryCardPathClicked(index); });
connect(memory_card_path_reset, &QPushButton::clicked, this,
[this, index]() { onResetMemoryCardPathClicked(index); });
memory_card_layout->addWidget(memory_card_path_reset);
ui->layout->addWidget(new QLabel(tr("Shared Memory Card Path:"), ui->container));
@@ -170,38 +163,33 @@ void MemoryCardSettingsWidget::onBrowseMemoryCardPathClicked(int index)
m_port_ui[index].memory_card_path->setText(path);
}
void MemoryCardSettingsWidget::onMemoryCardPathChanged(int index)
{
const auto key = TinyString::FromFormat("Card%dPath", index + 1);
std::string relative_path(
Path::MakeRelative(m_port_ui[index].memory_card_path->text().toStdString(), EmuFolders::MemoryCards));
m_dialog->setStringSettingValue("MemoryCards", key, relative_path.c_str());
}
void MemoryCardSettingsWidget::onResetMemoryCardPathClicked(int index)
{
m_host_interface->RemoveSettingValue("MemoryCards", TinyString::FromFormat("Card%dPath", index + 1));
m_host_interface->applySettings();
const auto key = TinyString::FromFormat("Card%dPath", index + 1);
if (m_dialog->isPerGameSettings())
m_dialog->removeSettingValue("MemoryCards", key);
else
m_dialog->setStringSettingValue("MemoryCards", key, Settings::GetDefaultSharedMemoryCardName(index).c_str());
updateMemoryCardPath(index);
}
void MemoryCardSettingsWidget::updateMemoryCardPath(int index)
{
const auto key = TinyString::FromFormat("Card%dPath", index + 1);
std::string path(
m_dialog->getEffectiveStringValue("MemoryCards", key, Settings::GetDefaultSharedMemoryCardName(index).c_str()));
if (!Path::IsAbsolute(path))
path = Path::Combine(EmuFolders::MemoryCards, path);
QSignalBlocker db(m_port_ui[index].memory_card_path);
m_port_ui[index].memory_card_path->setText(QString::fromStdString(m_host_interface->GetSharedMemoryCardPath(index)));
}
void MemoryCardSettingsWidget::onOpenMemCardsDirectoryClicked()
{
QtUtils::OpenURL(this, QUrl::fromLocalFile(m_memory_card_directory->text()));
}
void MemoryCardSettingsWidget::onBrowseMemCardsDirectoryClicked()
{
QString path =
QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this, tr("Select path to memory card directory")));
if (path.isEmpty())
return;
m_memory_card_directory->setText(path);
m_host_interface->applySettings();
}
void MemoryCardSettingsWidget::onResetMemCardsDirectoryClicked()
{
m_host_interface->RemoveSettingValue("MemoryCards", "Directory");
m_host_interface->applySettings();
// This sucks.. settings are applied asynchronously, so we have to manually build the path here.
QString memory_card_directory(m_host_interface->getUserDirectoryRelativePath(QStringLiteral("memcards")));
QSignalBlocker db(m_memory_card_directory);
m_memory_card_directory->setText(memory_card_directory);
m_port_ui[index].memory_card_path->setText(QString::fromStdString(path));
}