Merge pull request #4263 from lat9nq/fix-screencaps-2

screenshots: Option to save screenshots immediately in a specified directory + Linux workaround
This commit is contained in:
David 2020-08-03 21:00:14 +10:00 committed by GitHub
commit 6c7292de33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 120 additions and 14 deletions

View File

@ -35,6 +35,7 @@
#define KEYS_DIR "keys" #define KEYS_DIR "keys"
#define LOAD_DIR "load" #define LOAD_DIR "load"
#define DUMP_DIR "dump" #define DUMP_DIR "dump"
#define SCREENSHOTS_DIR "screenshots"
#define SHADER_DIR "shader" #define SHADER_DIR "shader"
#define LOG_DIR "log" #define LOG_DIR "log"

View File

@ -695,6 +695,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP); paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP);
paths.emplace(UserPath::LoadDir, user_path + LOAD_DIR DIR_SEP); paths.emplace(UserPath::LoadDir, user_path + LOAD_DIR DIR_SEP);
paths.emplace(UserPath::DumpDir, user_path + DUMP_DIR DIR_SEP); paths.emplace(UserPath::DumpDir, user_path + DUMP_DIR DIR_SEP);
paths.emplace(UserPath::ScreenshotsDir, user_path + SCREENSHOTS_DIR DIR_SEP);
paths.emplace(UserPath::ShaderDir, user_path + SHADER_DIR DIR_SEP); paths.emplace(UserPath::ShaderDir, user_path + SHADER_DIR DIR_SEP);
paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP);
paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP); paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP);

View File

@ -32,6 +32,7 @@ enum class UserPath {
SDMCDir, SDMCDir,
LoadDir, LoadDir,
DumpDir, DumpDir,
ScreenshotsDir,
ShaderDir, ShaderDir,
SysDataDir, SysDataDir,
UserDir, UserDir,

View File

@ -578,7 +578,6 @@ void Config::ReadPathValues() {
UISettings::values.roms_path = ReadSetting(QStringLiteral("romsPath")).toString(); UISettings::values.roms_path = ReadSetting(QStringLiteral("romsPath")).toString();
UISettings::values.symbols_path = ReadSetting(QStringLiteral("symbolsPath")).toString(); UISettings::values.symbols_path = ReadSetting(QStringLiteral("symbolsPath")).toString();
UISettings::values.screenshot_path = ReadSetting(QStringLiteral("screenshotPath")).toString();
UISettings::values.game_dir_deprecated = UISettings::values.game_dir_deprecated =
ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString(); ReadSetting(QStringLiteral("gameListRootDir"), QStringLiteral(".")).toString();
UISettings::values.game_dir_deprecated_deepscan = UISettings::values.game_dir_deprecated_deepscan =
@ -673,6 +672,22 @@ void Config::ReadRendererValues() {
qt_config->endGroup(); qt_config->endGroup();
} }
void Config::ReadScreenshotValues() {
qt_config->beginGroup(QStringLiteral("Screenshots"));
UISettings::values.enable_screenshot_save_as =
ReadSetting(QStringLiteral("enable_screenshot_save_as"), true).toBool();
FileUtil::GetUserPath(
FileUtil::UserPath::ScreenshotsDir,
qt_config
->value(QStringLiteral("screenshot_path"), QString::fromStdString(FileUtil::GetUserPath(
FileUtil::UserPath::ScreenshotsDir)))
.toString()
.toStdString());
qt_config->endGroup();
}
void Config::ReadShortcutValues() { void Config::ReadShortcutValues() {
qt_config->beginGroup(QStringLiteral("Shortcuts")); qt_config->beginGroup(QStringLiteral("Shortcuts"));
@ -754,6 +769,7 @@ void Config::ReadUIValues() {
ReadUIGamelistValues(); ReadUIGamelistValues();
ReadUILayoutValues(); ReadUILayoutValues();
ReadPathValues(); ReadPathValues();
ReadScreenshotValues();
ReadShortcutValues(); ReadShortcutValues();
UISettings::values.single_window_mode = UISettings::values.single_window_mode =
@ -1083,7 +1099,6 @@ void Config::SavePathValues() {
WriteSetting(QStringLiteral("romsPath"), UISettings::values.roms_path); WriteSetting(QStringLiteral("romsPath"), UISettings::values.roms_path);
WriteSetting(QStringLiteral("symbolsPath"), UISettings::values.symbols_path); WriteSetting(QStringLiteral("symbolsPath"), UISettings::values.symbols_path);
WriteSetting(QStringLiteral("screenshotPath"), UISettings::values.screenshot_path);
qt_config->beginWriteArray(QStringLiteral("gamedirs")); qt_config->beginWriteArray(QStringLiteral("gamedirs"));
for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) { for (int i = 0; i < UISettings::values.game_dirs.size(); ++i) {
qt_config->setArrayIndex(i); qt_config->setArrayIndex(i);
@ -1159,6 +1174,17 @@ void Config::SaveRendererValues() {
qt_config->endGroup(); qt_config->endGroup();
} }
void Config::SaveScreenshotValues() {
qt_config->beginGroup(QStringLiteral("Screenshots"));
WriteSetting(QStringLiteral("enable_screenshot_save_as"),
UISettings::values.enable_screenshot_save_as);
WriteSetting(QStringLiteral("screenshot_path"),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir)));
qt_config->endGroup();
}
void Config::SaveShortcutValues() { void Config::SaveShortcutValues() {
qt_config->beginGroup(QStringLiteral("Shortcuts")); qt_config->beginGroup(QStringLiteral("Shortcuts"));
@ -1221,6 +1247,7 @@ void Config::SaveUIValues() {
SaveUIGamelistValues(); SaveUIGamelistValues();
SaveUILayoutValues(); SaveUILayoutValues();
SavePathValues(); SavePathValues();
SaveScreenshotValues();
SaveShortcutValues(); SaveShortcutValues();
WriteSetting(QStringLiteral("singleWindowMode"), UISettings::values.single_window_mode, true); WriteSetting(QStringLiteral("singleWindowMode"), UISettings::values.single_window_mode, true);

View File

@ -51,6 +51,7 @@ private:
void ReadPathValues(); void ReadPathValues();
void ReadCpuValues(); void ReadCpuValues();
void ReadRendererValues(); void ReadRendererValues();
void ReadScreenshotValues();
void ReadShortcutValues(); void ReadShortcutValues();
void ReadSystemValues(); void ReadSystemValues();
void ReadUIValues(); void ReadUIValues();
@ -76,6 +77,7 @@ private:
void SavePathValues(); void SavePathValues();
void SaveCpuValues(); void SaveCpuValues();
void SaveRendererValues(); void SaveRendererValues();
void SaveScreenshotValues();
void SaveShortcutValues(); void SaveShortcutValues();
void SaveSystemValues(); void SaveSystemValues();
void SaveUIValues(); void SaveUIValues();

View File

@ -4,9 +4,11 @@
#include <array> #include <array>
#include <utility> #include <utility>
#include <QFileDialog>
#include <QDirIterator> #include <QDirIterator>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/file_util.h"
#include "core/settings.h" #include "core/settings.h"
#include "ui_configure_ui.h" #include "ui_configure_ui.h"
#include "yuzu/configuration/configure_ui.h" #include "yuzu/configuration/configure_ui.h"
@ -55,6 +57,18 @@ ConfigureUi::ConfigureUi(QWidget* parent) : QWidget(parent), ui(new Ui::Configur
[=]() { ConfigureUi::UpdateSecondRowComboBox(); }); [=]() { ConfigureUi::UpdateSecondRowComboBox(); });
connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::activated), connect(ui->row_2_text_combobox, QOverload<int>::of(&QComboBox::activated),
[=]() { ConfigureUi::UpdateFirstRowComboBox(); }); [=]() { ConfigureUi::UpdateFirstRowComboBox(); });
// Set screenshot path to user specification.
connect(ui->screenshot_path_button, &QToolButton::pressed, this, [this] {
const QString& filename =
QFileDialog::getExistingDirectory(
this, tr("Select Screenshots Path..."),
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir))) +
QDir::separator();
if (!filename.isEmpty()) {
ui->screenshot_path_edit->setText(filename);
}
});
} }
ConfigureUi::~ConfigureUi() = default; ConfigureUi::~ConfigureUi() = default;
@ -66,6 +80,10 @@ void ConfigureUi::ApplyConfiguration() {
UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt(); UISettings::values.icon_size = ui->icon_size_combobox->currentData().toUInt();
UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt(); UISettings::values.row_1_text_id = ui->row_1_text_combobox->currentData().toUInt();
UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt(); UISettings::values.row_2_text_id = ui->row_2_text_combobox->currentData().toUInt();
UISettings::values.enable_screenshot_save_as = ui->enable_screenshot_save_as->isChecked();
FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir,
ui->screenshot_path_edit->text().toStdString());
Settings::Apply(); Settings::Apply();
} }
@ -80,6 +98,10 @@ void ConfigureUi::SetConfiguration() {
ui->show_add_ons->setChecked(UISettings::values.show_add_ons); ui->show_add_ons->setChecked(UISettings::values.show_add_ons);
ui->icon_size_combobox->setCurrentIndex( ui->icon_size_combobox->setCurrentIndex(
ui->icon_size_combobox->findData(UISettings::values.icon_size)); ui->icon_size_combobox->findData(UISettings::values.icon_size));
ui->enable_screenshot_save_as->setChecked(UISettings::values.enable_screenshot_save_as);
ui->screenshot_path_edit->setText(
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir)));
} }
void ConfigureUi::changeEvent(QEvent* event) { void ConfigureUi::changeEvent(QEvent* event) {

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>300</width> <width>363</width>
<height>377</height> <height>391</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -127,6 +127,47 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="screenshots_GroupBox">
<property name="title">
<string>Screenshots</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="enable_screenshot_save_as">
<property name="text">
<string>Ask Where To Save Screenshots (Windows Only)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Screenshots Path: </string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="screenshot_path_edit"/>
</item>
<item>
<widget class="QToolButton" name="screenshot_path_button">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View File

@ -2321,17 +2321,28 @@ void GMainWindow::OnToggleFilterBar() {
void GMainWindow::OnCaptureScreenshot() { void GMainWindow::OnCaptureScreenshot() {
OnPauseGame(); OnPauseGame();
QFileDialog png_dialog(this, tr("Capture Screenshot"), UISettings::values.screenshot_path,
tr("PNG Image (*.png)")); const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID();
png_dialog.setAcceptMode(QFileDialog::AcceptSave); const auto screenshot_path =
png_dialog.setDefaultSuffix(QStringLiteral("png")); QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::ScreenshotsDir));
if (png_dialog.exec()) { const auto date =
const QString path = png_dialog.selectedFiles().first(); QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd_hh-mm-ss-zzz"));
if (!path.isEmpty()) { QString filename = QStringLiteral("%1%2_%3.png")
UISettings::values.screenshot_path = QFileInfo(path).path(); .arg(screenshot_path)
render_window->CaptureScreenshot(UISettings::values.screenshot_resolution_factor, path); .arg(title_id, 16, 16, QLatin1Char{'0'})
.arg(date);
#ifdef _WIN32
if (UISettings::values.enable_screenshot_save_as) {
filename = QFileDialog::getSaveFileName(this, tr("Capture Screenshot"), filename,
tr("PNG Image (*.png)"));
if (filename.isEmpty()) {
OnStartGame();
return;
} }
} }
#endif
render_window->CaptureScreenshot(UISettings::values.screenshot_resolution_factor, filename);
OnStartGame(); OnStartGame();
} }

View File

@ -66,11 +66,11 @@ struct Values {
// Discord RPC // Discord RPC
bool enable_discord_presence; bool enable_discord_presence;
bool enable_screenshot_save_as;
u16 screenshot_resolution_factor; u16 screenshot_resolution_factor;
QString roms_path; QString roms_path;
QString symbols_path; QString symbols_path;
QString screenshot_path;
QString game_dir_deprecated; QString game_dir_deprecated;
bool game_dir_deprecated_deepscan; bool game_dir_deprecated_deepscan;
QVector<UISettings::GameDir> game_dirs; QVector<UISettings::GameDir> game_dirs;