Add per game configuration options (#6187)
* common: Move settings to common from core. - Removes a dependency on core and input_common from common. * code: Wrap settings values * Port from yuzu to allow per game settings * citra_qt: Initial per-game settings dialog * citra_qt: Use new API for read/save of config values * citra_qt: Per game audio settings * citra_qt: Per game graphics settings * citra_qt: Per game system settings * citra_qt: Per game general settings * citra_qt: Document and run clang format * citra_qt: Make icon smaller and centered * citra_qt: Remove version number * Not sure how to extract that, can always add it back later * citra_qt: Wrap UISettings * citra_qt: Fix unthottled fps setting * citra_qt: Remove margin in emulation tab * citra_qt: Implement some suggestions * Bring back speed switch hotkey * Allow configuration when game is running * Rename/adjust UI stuff * citra_qt: Fix build with separate windows * citra_qt: Address feedback * citra_qt: Log per-game settings before launching games * citra_qt: Add shader cache options * Also fix android build * citra_qt: Add DLC menu option * citra_qt: Run clang-format * citra_qt: Adjust for time offset * citra_qt: Implement suggestions * Run clang-format Co-authored-by: bunnei <bunneidev@gmail.com>
This commit is contained in:
128
src/citra_qt/configuration/configure_per_game.cpp
Normal file
128
src/citra_qt/configuration/configure_per_game.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <QPushButton>
|
||||
#include <QString>
|
||||
#include <fmt/format.h>
|
||||
#include "citra_qt/configuration/config.h"
|
||||
#include "citra_qt/configuration/configure_audio.h"
|
||||
#include "citra_qt/configuration/configure_general.h"
|
||||
#include "citra_qt/configuration/configure_graphics.h"
|
||||
#include "citra_qt/configuration/configure_per_game.h"
|
||||
#include "citra_qt/configuration/configure_system.h"
|
||||
#include "citra_qt/util/util.h"
|
||||
#include "core/core.h"
|
||||
#include "core/loader/loader.h"
|
||||
#include "core/loader/smdh.h"
|
||||
#include "ui_configure_per_game.h"
|
||||
|
||||
ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id_, const QString& file_name,
|
||||
Core::System& system_)
|
||||
: QDialog(parent), ui(std::make_unique<Ui::ConfigurePerGame>()),
|
||||
filename{file_name.toStdString()}, title_id{title_id_}, system{system_} {
|
||||
const auto config_file_name = title_id == 0 ? filename : fmt::format("{:016X}", title_id);
|
||||
game_config = std::make_unique<Config>(config_file_name, Config::ConfigType::PerGameConfig);
|
||||
|
||||
audio_tab = std::make_unique<ConfigureAudio>(this);
|
||||
general_tab = std::make_unique<ConfigureGeneral>(this);
|
||||
graphics_tab = std::make_unique<ConfigureGraphics>(this);
|
||||
system_tab = std::make_unique<ConfigureSystem>(this);
|
||||
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->tabWidget->addTab(general_tab.get(), tr("General"));
|
||||
ui->tabWidget->addTab(system_tab.get(), tr("System"));
|
||||
ui->tabWidget->addTab(graphics_tab.get(), tr("Graphics"));
|
||||
ui->tabWidget->addTab(audio_tab.get(), tr("Audio"));
|
||||
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
setWindowTitle(tr("Properties"));
|
||||
// remove Help question mark button from the title bar
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
scene = new QGraphicsScene;
|
||||
ui->icon_view->setScene(scene);
|
||||
|
||||
if (system.IsPoweredOn()) {
|
||||
QPushButton* apply_button = ui->buttonBox->addButton(QDialogButtonBox::Apply);
|
||||
connect(apply_button, &QAbstractButton::clicked, this,
|
||||
&ConfigurePerGame::HandleApplyButtonClicked);
|
||||
}
|
||||
|
||||
LoadConfiguration();
|
||||
}
|
||||
|
||||
ConfigurePerGame::~ConfigurePerGame() = default;
|
||||
|
||||
void ConfigurePerGame::ApplyConfiguration() {
|
||||
general_tab->ApplyConfiguration();
|
||||
system_tab->ApplyConfiguration();
|
||||
graphics_tab->ApplyConfiguration();
|
||||
audio_tab->ApplyConfiguration();
|
||||
|
||||
Settings::LogSettings();
|
||||
|
||||
game_config->Save();
|
||||
}
|
||||
|
||||
void ConfigurePerGame::changeEvent(QEvent* event) {
|
||||
if (event->type() == QEvent::LanguageChange) {
|
||||
RetranslateUI();
|
||||
}
|
||||
|
||||
QDialog::changeEvent(event);
|
||||
}
|
||||
|
||||
void ConfigurePerGame::RetranslateUI() {
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
|
||||
void ConfigurePerGame::HandleApplyButtonClicked() {
|
||||
ApplyConfiguration();
|
||||
}
|
||||
|
||||
static QPixmap GetQPixmapFromSMDH(std::vector<u8>& smdh_data) {
|
||||
Loader::SMDH smdh;
|
||||
memcpy(&smdh, smdh_data.data(), sizeof(Loader::SMDH));
|
||||
|
||||
bool large = true;
|
||||
std::vector<u16> icon_data = smdh.GetIcon(large);
|
||||
const uchar* data = reinterpret_cast<const uchar*>(icon_data.data());
|
||||
int size = large ? 48 : 24;
|
||||
QImage icon(data, size, size, QImage::Format::Format_RGB16);
|
||||
return QPixmap::fromImage(icon);
|
||||
}
|
||||
|
||||
void ConfigurePerGame::LoadConfiguration() {
|
||||
if (filename.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ui->display_title_id->setText(
|
||||
QStringLiteral("%1").arg(title_id, 16, 16, QLatin1Char{'0'}).toUpper());
|
||||
|
||||
const auto loader = Loader::GetLoader(filename);
|
||||
|
||||
std::string title;
|
||||
if (loader->ReadTitle(title) == Loader::ResultStatus::Success)
|
||||
ui->display_name->setText(QString::fromStdString(title));
|
||||
|
||||
std::vector<u8> bytes;
|
||||
if (loader->ReadIcon(bytes) == Loader::ResultStatus::Success) {
|
||||
scene->clear();
|
||||
|
||||
QPixmap map = GetQPixmapFromSMDH(bytes);
|
||||
scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(),
|
||||
Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
|
||||
ui->display_filepath->setText(QString::fromStdString(filename));
|
||||
|
||||
ui->display_format->setText(
|
||||
QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType())));
|
||||
|
||||
const auto valueText = ReadableByteSize(FileUtil::GetSize(filename));
|
||||
ui->display_size->setText(valueText);
|
||||
}
|
Reference in New Issue
Block a user