mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-22 18:15:14 +00:00
first commit
This commit is contained in:
parent
b403e1be33
commit
e7ba1cb303
@ -8,6 +8,7 @@
|
|||||||
#include <QPlainTextEdit>
|
#include <QPlainTextEdit>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
#include <QStatusBar>
|
#include <QStatusBar>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include "about_dialog.h"
|
#include "about_dialog.h"
|
||||||
#include "cheats_patches.h"
|
#include "cheats_patches.h"
|
||||||
@ -398,7 +399,9 @@ void MainWindow::CreateConnects() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(ui->playButton, &QPushButton::clicked, this, &MainWindow::StartGame);
|
connect(ui->playButton, &QPushButton::clicked, this, &MainWindow::StartGame);
|
||||||
|
connect(ui->stopButton, &QPushButton::clicked, this, &MainWindow::StopGame);
|
||||||
connect(ui->pauseButton, &QPushButton::clicked, this, &MainWindow::PauseGame);
|
connect(ui->pauseButton, &QPushButton::clicked, this, &MainWindow::PauseGame);
|
||||||
|
connect(ui->restartButton, &QPushButton::clicked, this, &MainWindow::RestartGame);
|
||||||
connect(m_game_grid_frame.get(), &QTableWidget::cellDoubleClicked, this,
|
connect(m_game_grid_frame.get(), &QTableWidget::cellDoubleClicked, this,
|
||||||
&MainWindow::StartGame);
|
&MainWindow::StartGame);
|
||||||
connect(m_game_list_frame.get(), &QTableWidget::cellDoubleClicked, this,
|
connect(m_game_list_frame.get(), &QTableWidget::cellDoubleClicked, this,
|
||||||
@ -862,19 +865,41 @@ void MainWindow::StartGame() {
|
|||||||
gamePath = m_elf_viewer->m_elf_list[itemID];
|
gamePath = m_elf_viewer->m_elf_list[itemID];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gamePath != "") {
|
|
||||||
AddRecentFiles(gamePath);
|
|
||||||
const auto path = Common::FS::PathFromQString(gamePath);
|
|
||||||
if (!std::filesystem::exists(path)) {
|
|
||||||
QMessageBox::critical(nullptr, tr("Run Game"), QString(tr("Eboot.bin file not found")));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
StartEmulator(path);
|
|
||||||
|
|
||||||
UpdateToolbarButtons();
|
if (!gamePath.isEmpty()) {
|
||||||
|
StartGameWithPath(gamePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::StartGameWithPath(const QString& gamePath) {
|
||||||
|
if (gamePath.isEmpty()) {
|
||||||
|
QMessageBox::warning(this, tr("Run Game"), tr("No game path provided."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AddRecentFiles(gamePath);
|
||||||
|
|
||||||
|
const auto path = Common::FS::PathFromQString(gamePath);
|
||||||
|
if (!std::filesystem::exists(path)) {
|
||||||
|
QMessageBox::critical(nullptr, tr("Run Game"), tr("Eboot.bin file not found"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start emulator detached
|
||||||
|
QString exePath = QCoreApplication::applicationFilePath();
|
||||||
|
bool started =
|
||||||
|
QProcess::startDetached(exePath, QStringList() << gamePath, QString(), &detachedGamePid);
|
||||||
|
if (!started) {
|
||||||
|
QMessageBox::critical(this, tr("Run Game"), tr("Failed to start emulator."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastGamePath = gamePath;
|
||||||
|
isGameRunning = true;
|
||||||
|
|
||||||
|
UpdateToolbarButtons();
|
||||||
|
}
|
||||||
|
|
||||||
bool isTable;
|
bool isTable;
|
||||||
void MainWindow::SearchGameTable(const QString& text) {
|
void MainWindow::SearchGameTable(const QString& text) {
|
||||||
if (isTableList) {
|
if (isTableList) {
|
||||||
@ -1209,20 +1234,80 @@ bool MainWindow::eventFilter(QObject* obj, QEvent* event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::StartEmulator(std::filesystem::path path) {
|
void MainWindow::StartEmulator(std::filesystem::path path) {
|
||||||
if (isGameRunning) {
|
// Normalize path slashes for display only:
|
||||||
QMessageBox::critical(nullptr, tr("Run Game"), QString(tr("Game is already running!")));
|
QString normalizedPath = QString::fromStdString(path.string()).replace("\\", "/");
|
||||||
return;
|
lastGamePath = normalizedPath;
|
||||||
}
|
|
||||||
isGameRunning = true;
|
isGameRunning = true;
|
||||||
|
|
||||||
|
emulator = std::make_unique<Core::Emulator>();
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
// SDL on macOS requires main thread.
|
|
||||||
Core::Emulator emulator;
|
Core::Emulator emulator;
|
||||||
emulator.Run(path);
|
emulator.Run(path, {});
|
||||||
#else
|
#else
|
||||||
std::thread emulator_thread([=] {
|
std::thread emulator_thread([this, path]() {
|
||||||
Core::Emulator emulator;
|
emulator->Run(path, {});
|
||||||
emulator.Run(path);
|
isGameRunning = false;
|
||||||
});
|
});
|
||||||
emulator_thread.detach();
|
emulator_thread.detach();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_QT_GUI
|
||||||
|
|
||||||
|
void MainWindow::StopGame() {
|
||||||
|
if (!isGameRunning) {
|
||||||
|
QMessageBox::information(this, tr("Stop Game"), tr("No game is currently running."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
QProcess::execute("taskkill", {"/PID", QString::number(detachedGamePid), "/F", "/T"});
|
||||||
|
#else
|
||||||
|
::kill(detachedGamePid, SIGKILL);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
detachedGamePid = -1;
|
||||||
|
isGameRunning = false;
|
||||||
|
|
||||||
|
QMessageBox::information(this, tr("Stop Game"), tr("Game has been stopped successfully."));
|
||||||
|
UpdateToolbarButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::RestartGame() {
|
||||||
|
if (!isGameRunning) {
|
||||||
|
QMessageBox::warning(this, tr("Restart Game"), tr("No game is running to restart."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastGamePath.isEmpty()) {
|
||||||
|
QMessageBox::warning(this, tr("Restart Game"), tr("No recent game found."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
if (detachedGamePid > 0) {
|
||||||
|
QProcess::execute("taskkill", {"/PID", QString::number(detachedGamePid), "/F", "/T"});
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (detachedGamePid > 0) {
|
||||||
|
::kill(detachedGamePid, SIGKILL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
detachedGamePid = -1;
|
||||||
|
isGameRunning = false;
|
||||||
|
|
||||||
|
const QString exePath = QCoreApplication::applicationFilePath();
|
||||||
|
qint64 newPid = -1;
|
||||||
|
bool started =
|
||||||
|
QProcess::startDetached(exePath, QStringList() << lastGamePath, QString(), &newPid);
|
||||||
|
if (started) {
|
||||||
|
detachedGamePid = newPid;
|
||||||
|
isGameRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateToolbarButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -37,9 +37,15 @@ public:
|
|||||||
bool Init();
|
bool Init();
|
||||||
void InstallDirectory();
|
void InstallDirectory();
|
||||||
void StartGame();
|
void StartGame();
|
||||||
|
void StartGameWithPath(const QString&);
|
||||||
void PauseGame();
|
void PauseGame();
|
||||||
bool showLabels;
|
bool showLabels;
|
||||||
|
void StopGame();
|
||||||
|
void RestartGame();
|
||||||
|
std::unique_ptr<Core::Emulator> emulator;
|
||||||
|
bool pendingRestart = false;
|
||||||
|
qint64 detachedGamePid = -1;
|
||||||
|
bool isDetachedLaunch = false;
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void ConfigureGuiFromSettings();
|
void ConfigureGuiFromSettings();
|
||||||
void SaveWindowState();
|
void SaveWindowState();
|
||||||
@ -66,6 +72,10 @@ private:
|
|||||||
void CheckUpdateMain(bool checkSave);
|
void CheckUpdateMain(bool checkSave);
|
||||||
#endif
|
#endif
|
||||||
void CreateConnects();
|
void CreateConnects();
|
||||||
|
#ifdef ENABLE_QT_GUI
|
||||||
|
QString getLastEbootPath();
|
||||||
|
QString lastGamePath;
|
||||||
|
#endif
|
||||||
void SetLastUsedTheme();
|
void SetLastUsedTheme();
|
||||||
void SetLastIconSizeBullet();
|
void SetLastIconSizeBullet();
|
||||||
void SetUiIcons(bool isWhite);
|
void SetUiIcons(bool isWhite);
|
||||||
@ -121,4 +131,4 @@ protected:
|
|||||||
std::filesystem::path last_install_dir = "";
|
std::filesystem::path last_install_dir = "";
|
||||||
bool delete_file_on_install = false;
|
bool delete_file_on_install = false;
|
||||||
bool use_for_all_queued = false;
|
bool use_for_all_queued = false;
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user