Skip to content

Commit

Permalink
Merge branch 'shadps4-emu:main' into mainBB
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolix29 authored Sep 28, 2024
2 parents 234f9f3 + dc96338 commit f467107
Show file tree
Hide file tree
Showing 38 changed files with 311 additions and 66 deletions.
12 changes: 12 additions & 0 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Config {
static bool isNeo = false;
static bool isFullscreen = false;
static bool playBGM = false;
static int BGMvolume = 50;
static u32 screenWidth = 1280;
static u32 screenHeight = 720;
static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto select
Expand Down Expand Up @@ -89,6 +90,10 @@ bool getPlayBGM() {
return playBGM;
}

int getBGMvolume() {
return BGMvolume;
}

u32 getScreenWidth() {
return screenWidth;
}
Expand Down Expand Up @@ -249,6 +254,10 @@ void setPlayBGM(bool enable) {
playBGM = enable;
}

void setBGMvolume(int volume) {
BGMvolume = volume;
}

void setLanguage(u32 language) {
m_language = language;
}
Expand Down Expand Up @@ -412,6 +421,7 @@ void load(const std::filesystem::path& path) {
isNeo = toml::find_or<bool>(general, "isPS4Pro", false);
isFullscreen = toml::find_or<bool>(general, "Fullscreen", false);
playBGM = toml::find_or<bool>(general, "playBGM", false);
BGMvolume = toml::find_or<int>(general, "BGMvolume", 50);
logFilter = toml::find_or<std::string>(general, "logFilter", "");
logType = toml::find_or<std::string>(general, "logType", "sync");
userName = toml::find_or<std::string>(general, "userName", "shadPS4");
Expand Down Expand Up @@ -513,6 +523,7 @@ void save(const std::filesystem::path& path) {
data["General"]["isPS4Pro"] = isNeo;
data["General"]["Fullscreen"] = isFullscreen;
data["General"]["playBGM"] = playBGM;
data["General"]["BGMvolume"] = BGMvolume;
data["General"]["logFilter"] = logFilter;
data["General"]["logType"] = logType;
data["General"]["userName"] = userName;
Expand Down Expand Up @@ -565,6 +576,7 @@ void setDefaultValues() {
isNeo = false;
isFullscreen = false;
playBGM = false;
BGMvolume = 50;
screenWidth = 1280;
screenHeight = 720;
logFilter = "";
Expand Down
3 changes: 3 additions & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void save(const std::filesystem::path& path);
bool isNeoMode();
bool isFullscreenMode();
bool getPlayBGM();
int getBGMvolume();

std::string getLogFilter();
std::string getLogType();
std::string getUserName();
Expand Down Expand Up @@ -49,6 +51,7 @@ void setScreenWidth(u32 width);
void setScreenHeight(u32 height);
void setFullscreenMode(bool enable);
void setPlayBGM(bool enable);
void setBGMvolume(int volume);
void setLanguage(u32 language);
void setNeoMode(bool enable);
void setUserName(const std::string& type);
Expand Down
6 changes: 6 additions & 0 deletions src/qt_gui/background_music_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ BackgroundMusicPlayer::BackgroundMusicPlayer(QObject* parent) : QObject(parent)
m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
}

void BackgroundMusicPlayer::setVolume(int volume) {
float linearVolume = QAudio::convertVolume(volume / 100.0f, QAudio::LogarithmicVolumeScale,
QAudio::LinearVolumeScale);
m_audioOutput->setVolume(linearVolume);
}

void BackgroundMusicPlayer::playMusic(const QString& snd0path) {
if (snd0path.isEmpty()) {
stopMusic();
Expand Down
3 changes: 2 additions & 1 deletion src/qt_gui/background_music_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BackgroundMusicPlayer : public QObject {
return instance;
}

void setVolume(int volume);
void playMusic(const QString& snd0path);
void stopMusic();

Expand All @@ -25,4 +26,4 @@ class BackgroundMusicPlayer : public QObject {
QMediaPlayer* m_mediaPlayer;
QAudioOutput* m_audioOutput;
QUrl m_currentMusic;
};
};
39 changes: 27 additions & 12 deletions src/qt_gui/game_grid_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GameGridFrame::GameGridFrame(std::shared_ptr<GameInfoClass> game_info_get, QWidg
this->setContextMenuPolicy(Qt::CustomContextMenu);
PopulateGameGrid(m_game_info->m_games, false);

connect(this, &QTableWidget::cellClicked, this, &GameGridFrame::SetGridBackgroundImage);
connect(this, &QTableWidget::currentCellChanged, this, &GameGridFrame::onCurrentCellChanged);

connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this,
&GameGridFrame::RefreshGridBackgroundImage);
Expand All @@ -31,22 +31,33 @@ GameGridFrame::GameGridFrame(std::shared_ptr<GameInfoClass> game_info_get, QWidg
connect(this, &QTableWidget::customContextMenuRequested, this, [=, this](const QPoint& pos) {
m_gui_context_menus.RequestGameMenu(pos, m_game_info->m_games, this, false);
});
connect(this, &QTableWidget::cellClicked, this, [&]() {
cellClicked = true;
crtRow = this->currentRow();
crtColumn = this->currentColumn();
columnCnt = this->columnCount();
});
}

void GameGridFrame::PlayBackgroundMusic(QTableWidgetItem* item) {
if (!item) {
void GameGridFrame::onCurrentCellChanged(int currentRow, int currentColumn, int previousRow,
int previousColumn) {
cellClicked = true;
crtRow = currentRow;
crtColumn = currentColumn;
columnCnt = this->columnCount();

auto itemID = (crtRow * columnCnt) + currentColumn;
if (itemID > m_game_info->m_games.count() - 1) {
validCellSelected = false;
BackgroundMusicPlayer::getInstance().stopMusic();
return;
}
QString snd0path;
Common::FS::PathToQString(snd0path, m_game_info->m_games[item->row()].snd0_path);
BackgroundMusicPlayer::getInstance().playMusic(snd0path);
validCellSelected = true;
SetGridBackgroundImage(crtRow, crtColumn);
auto snd0Path = QString::fromStdString(m_game_info->m_games[itemID].snd0_path.string());
PlayBackgroundMusic(snd0Path);
}

void GameGridFrame::PlayBackgroundMusic(QString path) {
if (path.isEmpty()) {
BackgroundMusicPlayer::getInstance().stopMusic();
return;
}
BackgroundMusicPlayer::getInstance().playMusic(path);
}

void GameGridFrame::PopulateGameGrid(QVector<GameInfo> m_games_search, bool fromSearch) {
Expand Down Expand Up @@ -157,3 +168,7 @@ void GameGridFrame::RefreshGridBackgroundImage() {
this->setPalette(palette);
}
}

bool GameGridFrame::IsValidCellSelected() {
return validCellSelected;
}
6 changes: 5 additions & 1 deletion src/qt_gui/game_grid_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@ class GameGridFrame : public QTableWidget {
public Q_SLOTS:
void SetGridBackgroundImage(int row, int column);
void RefreshGridBackgroundImage();
void PlayBackgroundMusic(QTableWidgetItem* item);
void PlayBackgroundMusic(QString path);
void onCurrentCellChanged(int currentRow, int currentColumn, int previousRow,
int previousColumn);

private:
QImage backgroundImage;
GameListUtils m_game_list_utils;
GuiContextMenus m_gui_context_menus;
std::shared_ptr<GameInfoClass> m_game_info;
std::shared_ptr<QVector<GameInfo>> m_games_shared;
bool validCellSelected = false;

public:
explicit GameGridFrame(std::shared_ptr<GameInfoClass> game_info_get, QWidget* parent = nullptr);
void PopulateGameGrid(QVector<GameInfo> m_games, bool fromSearch);
bool IsValidCellSelected();

bool cellClicked = false;
int icon_size;
Expand Down
12 changes: 11 additions & 1 deletion src/qt_gui/game_list_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GameListFrame::GameListFrame(std::shared_ptr<GameInfoClass> game_info_get, QWidg
this->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Fixed);
PopulateGameList();

connect(this, &QTableWidget::itemClicked, this, &GameListFrame::SetListBackgroundImage);
connect(this, &QTableWidget::currentCellChanged, this, &GameListFrame::onCurrentCellChanged);
connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this,
&GameListFrame::RefreshListBackgroundImage);
connect(this->horizontalScrollBar(), &QScrollBar::valueChanged, this,
Expand Down Expand Up @@ -69,6 +69,16 @@ GameListFrame::GameListFrame(std::shared_ptr<GameInfoClass> game_info_get, QWidg
});
}

void GameListFrame::onCurrentCellChanged(int currentRow, int currentColumn, int previousRow,
int previousColumn) {
QTableWidgetItem* item = this->item(currentRow, currentColumn);
if (!item) {
return;
}
SetListBackgroundImage(item);
PlayBackgroundMusic(item);
}

void GameListFrame::PlayBackgroundMusic(QTableWidgetItem* item) {
if (!item) {
BackgroundMusicPlayer::getInstance().stopMusic();
Expand Down
4 changes: 3 additions & 1 deletion src/qt_gui/game_list_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public Q_SLOTS:
void SortNameAscending(int columnIndex);
void SortNameDescending(int columnIndex);
void PlayBackgroundMusic(QTableWidgetItem* item);
void onCurrentCellChanged(int currentRow, int currentColumn, int previousRow,
int previousColumn);

private:
void SetTableItem(int row, int column, QString itemStr);
Expand Down Expand Up @@ -63,4 +65,4 @@ public Q_SLOTS:
}
return false;
}
};
};
39 changes: 20 additions & 19 deletions src/qt_gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later

#include <QDockWidget>
#include <QKeyEvent>
#include <QProgressDialog>

#include <common/scm_rev.h>
Expand All @@ -21,6 +22,7 @@

MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
installEventFilter(this);
setAttribute(Qt::WA_DeleteOnClose);
}

Expand Down Expand Up @@ -306,6 +308,7 @@ void MainWindow::CreateConnects() {
});
// List
connect(ui->setlistModeListAct, &QAction::triggered, m_dock_widget.data(), [this]() {
BackgroundMusicPlayer::getInstance().stopMusic();
m_dock_widget->setWidget(m_game_list_frame.data());
m_game_grid_frame->hide();
m_elf_viewer->hide();
Expand All @@ -322,6 +325,7 @@ void MainWindow::CreateConnects() {
});
// Grid
connect(ui->setlistModeGridAct, &QAction::triggered, m_dock_widget.data(), [this]() {
BackgroundMusicPlayer::getInstance().stopMusic();
m_dock_widget->setWidget(m_game_grid_frame.data());
m_game_grid_frame->show();
m_game_list_frame->hide();
Expand All @@ -338,6 +342,7 @@ void MainWindow::CreateConnects() {
});
// Elf
connect(ui->setlistElfAct, &QAction::triggered, m_dock_widget.data(), [this]() {
BackgroundMusicPlayer::getInstance().stopMusic();
m_dock_widget->setWidget(m_elf_viewer.data());
m_game_grid_frame->hide();
m_game_list_frame->hide();
Expand Down Expand Up @@ -512,25 +517,6 @@ void MainWindow::CreateConnects() {
isIconBlack = false;
}
});

connect(m_game_grid_frame.get(), &QTableWidget::cellClicked, this,
&MainWindow::PlayBackgroundMusic);
connect(m_game_list_frame.get(), &QTableWidget::cellClicked, this,
&MainWindow::PlayBackgroundMusic);
}

void MainWindow::PlayBackgroundMusic() {
if (isGameRunning || !Config::getPlayBGM()) {
BackgroundMusicPlayer::getInstance().stopMusic();
return;
}
int itemID = isTableList ? m_game_list_frame->currentItem()->row()
: m_game_grid_frame->crtRow * m_game_grid_frame->columnCnt +
m_game_grid_frame->crtColumn;

QString snd0path;
Common::FS::PathToQString(snd0path, m_game_info->m_games[itemID].snd0_path);
BackgroundMusicPlayer::getInstance().playMusic(snd0path);
}

void MainWindow::StartGame() {
Expand Down Expand Up @@ -619,6 +605,7 @@ void MainWindow::ConfigureGuiFromSettings() {
} else {
ui->setlistModeGridAct->setChecked(true);
}
BackgroundMusicPlayer::getInstance().setVolume(Config::getBGMvolume());
}

void MainWindow::SaveWindowState() const {
Expand Down Expand Up @@ -1042,3 +1029,17 @@ void MainWindow::OnLanguageChanged(const std::string& locale) {

LoadTranslation();
}

bool MainWindow::eventFilter(QObject* obj, QEvent* event) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
auto tblMode = Config::getTableMode();
if (tblMode != 2 && (tblMode != 1 || m_game_grid_frame->IsValidCellSelected())) {
StartGame();
return true;
}
}
}
return QMainWindow::eventFilter(obj, event);
}
2 changes: 2 additions & 0 deletions src/qt_gui/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ private Q_SLOTS:
QTranslator* translator;

protected:
bool eventFilter(QObject* obj, QEvent* event) override;

void dragEnterEvent(QDragEnterEvent* event1) override {
if (event1->mimeData()->hasUrls()) {
event1->acceptProposedAction();
Expand Down
16 changes: 13 additions & 3 deletions src/qt_gui/settings_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,17 @@ SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidge
checkUpdate->exec();
});

connect(ui->playBGMCheckBox, &QCheckBox::stateChanged, this,
[](int val) { Config::setPlayBGM(val); });
connect(ui->playBGMCheckBox, &QCheckBox::stateChanged, this, [](int val) {
Config::setPlayBGM(val);
if (val == Qt::Unchecked) {
BackgroundMusicPlayer::getInstance().stopMusic();
}
});

connect(ui->BGMVolumeSlider, &QSlider::valueChanged, this, [](float val) {
Config::setBGMvolume(val);
BackgroundMusicPlayer::getInstance().setVolume(val);
});
}

// GPU TAB
Expand Down Expand Up @@ -231,6 +240,7 @@ void SettingsDialog::LoadValuesFromConfig() {
ui->nullGpuCheckBox->setChecked(Config::nullGpu());
ui->dumpPM4CheckBox->setChecked(Config::dumpPM4());
ui->playBGMCheckBox->setChecked(Config::getPlayBGM());
ui->BGMVolumeSlider->setValue((Config::getBGMvolume()));
ui->fullscreenCheckBox->setChecked(Config::isFullscreenMode());
ui->showSplashCheckBox->setChecked(Config::showSplash());
ui->ps4proCheckBox->setChecked(Config::isNeoMode());
Expand Down Expand Up @@ -371,4 +381,4 @@ bool SettingsDialog::eventFilter(QObject* obj, QEvent* event) {
}
}
return QDialog::eventFilter(obj, event);
}
}
Loading

0 comments on commit f467107

Please sign in to comment.