From ba556cb4047ede07bae0303405e5237d9b77b560 Mon Sep 17 00:00:00 2001 From: Dmugetsu Date: Fri, 28 Feb 2025 10:40:43 -0600 Subject: [PATCH] Adding top button option for trophy pop up --- src/common/config.cpp | 11 ++++++++ src/common/config.h | 2 ++ src/core/libraries/np_trophy/trophy_ui.cpp | 32 ++++++++++++++++------ src/qt_gui/settings_dialog.cpp | 4 ++- src/qt_gui/settings_dialog.ui | 8 +++++- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 36566a14c..d39b74868 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -53,6 +53,7 @@ static bool isShaderDebug = false; static bool isShowSplash = false; static bool isAutoUpdate = false; static bool isAlwaysShowChangelog = false; +static bool isTopSideTrophy = false; static bool isLeftSideTrophy = false; static bool isNullGpu = false; static bool shouldCopyGPUBuffers = false; @@ -270,6 +271,10 @@ bool alwaysShowChangelog() { return isAlwaysShowChangelog; } +bool TopSideTrophy() { + return isTopSideTrophy; +} + bool leftSideTrophy() { return isLeftSideTrophy; } @@ -381,6 +386,9 @@ void setAutoUpdate(bool enable) { void setAlwaysShowChangelog(bool enable) { isAlwaysShowChangelog = enable; } +void setTopSideTrophy(bool enable) { + isTopSideTrophy = enable; +} void setLeftSideTrophy(bool enable) { isLeftSideTrophy = enable; } @@ -737,6 +745,7 @@ void load(const std::filesystem::path& path) { isShowSplash = toml::find_or(general, "showSplash", true); isAutoUpdate = toml::find_or(general, "autoUpdate", false); isAlwaysShowChangelog = toml::find_or(general, "alwaysShowChangelog", false); + isTopSideTrophy = toml::find_or(general, "TopSideTrophy", false); isLeftSideTrophy = toml::find_or(general, "leftSideTrophy", false); separateupdatefolder = toml::find_or(general, "separateUpdateEnabled", false); compatibilityData = toml::find_or(general, "compatibilityEnabled", false); @@ -888,6 +897,7 @@ void save(const std::filesystem::path& path) { data["General"]["showSplash"] = isShowSplash; data["General"]["autoUpdate"] = isAutoUpdate; data["General"]["alwaysShowChangelog"] = isAlwaysShowChangelog; + data["General"]["TopSideTrophy"] = isTopSideTrophy; data["General"]["leftSideTrophy"] = isLeftSideTrophy; data["General"]["separateUpdateEnabled"] = separateupdatefolder; data["General"]["compatibilityEnabled"] = compatibilityData; @@ -1018,6 +1028,7 @@ void setDefaultValues() { isShowSplash = false; isAutoUpdate = false; isAlwaysShowChangelog = false; + isTopSideTrophy = false; isLeftSideTrophy = false; isNullGpu = false; shouldDumpShaders = false; diff --git a/src/common/config.h b/src/common/config.h index 988734b93..81826b26a 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -63,6 +63,7 @@ bool collectShadersForDebug(); bool showSplash(); bool autoUpdate(); bool alwaysShowChangelog(); +bool TopSideTrophy(); bool leftSideTrophy(); bool nullGpu(); bool copyGPUCmdBuffers(); @@ -77,6 +78,7 @@ void setCollectShaderForDebug(bool enable); void setShowSplash(bool enable); void setAutoUpdate(bool enable); void setAlwaysShowChangelog(bool enable); +void setTopSideTrophy(bool enable); void setLeftSideTrophy(bool enable); void setNullGpu(bool enable); void setAllowHDR(bool enable); diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index 2564cbf5d..8ff20e52c 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -27,6 +27,7 @@ namespace Libraries::NpTrophy { std::optional current_trophy_ui; std::queue trophy_queue; std::mutex queueMtx; +bool isTopSide; bool isLeftSide; double trophy_timer; @@ -34,6 +35,7 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin const std::string_view& rarity) : trophy_name(trophyName), trophy_type(rarity) { + isTopSide = Config::TopSideTrophy(); isLeftSide = Config::leftSideTrophy(); trophy_timer = Config::getTrophyNotificationDuration(); @@ -115,8 +117,8 @@ float fade_out_duration = 0.5f; // Final fade duration void TrophyUI::Draw() { const auto& io = GetIO(); - float AdjustWidth = io.DisplaySize.x / 1280; - float AdjustHeight = io.DisplaySize.y / 720; + float AdjustWidth = io.DisplaySize.x / 1920; + float AdjustHeight = io.DisplaySize.y / 1080; const ImVec2 window_size{ std::min(io.DisplaySize.x, (350 * AdjustWidth)), std::min(io.DisplaySize.y, (70 * AdjustHeight)), @@ -125,21 +127,33 @@ void TrophyUI::Draw() { elapsed_time += io.DeltaTime; float progress = std::min(elapsed_time / animation_duration, 1.0f); - // left or right position - float final_pos_x; - if (isLeftSide) { - start_pos.x = -window_size.x; + float final_pos_x, start_x; + float final_pos_y, start_y; + + if (isTopSide) { + start_x = (io.DisplaySize.x - window_size.x) * 0.5f; + start_y = -window_size.y; + final_pos_x = start_x; + final_pos_y = 50 * AdjustHeight; + } else if (isLeftSide) { + start_x = -window_size.x; + start_y = 50 * AdjustHeight; final_pos_x = 20 * AdjustWidth; + final_pos_y = start_y; } else { - start_pos.x = io.DisplaySize.x; + start_x = io.DisplaySize.x; + start_y = 50 * AdjustHeight; final_pos_x = io.DisplaySize.x - window_size.x - 20 * AdjustWidth; + final_pos_y = start_y; } - ImVec2 current_pos = ImVec2(start_pos.x + (final_pos_x - start_pos.x) * progress, - start_pos.y + (target_pos.y - start_pos.y) * progress); + ImVec2 current_pos = ImVec2(start_x + (final_pos_x - start_x) * progress, + start_y + (final_pos_y - start_y) * progress); trophy_timer -= io.DeltaTime; + ImGui::SetNextWindowPos(current_pos); + // If the remaining time of the trophy is less than or equal to 1 second, the fade-out begins. if (trophy_timer <= 1.0f) { float fade_out_time = 1.0f - (trophy_timer / 1.0f); diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index bde104828..db7490be9 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -418,8 +418,9 @@ void SettingsDialog::LoadValuesFromConfig() { ui->disableTrophycheckBox->setChecked( toml::find_or(data, "General", "isTrophyPopupDisabled", false)); ui->popUpDurationSpinBox->setValue(Config::getTrophyNotificationDuration()); + ui->radioButton_Top->setChecked(Config::TopSideTrophy()); ui->radioButton_Left->setChecked(Config::leftSideTrophy()); - ui->radioButton_Right->setChecked(!ui->radioButton_Left->isChecked()); + ui->radioButton_Right->setChecked(!(ui->radioButton_Left->isChecked() || ui->radioButton_Top->isChecked())); ui->BGMVolumeSlider->setValue(toml::find_or(data, "General", "BGMvolume", 50)); ui->discordRPCCheckbox->setChecked( toml::find_or(data, "General", "enableDiscordRPC", true)); @@ -706,6 +707,7 @@ void SettingsDialog::UpdateSettings() { Config::setIsMotionControlsEnabled(ui->motionControlsCheckBox->isChecked()); Config::setisTrophyPopupDisabled(ui->disableTrophycheckBox->isChecked()); Config::setTrophyNotificationDuration(ui->popUpDurationSpinBox->value()); + Config::setTopSideTrophy(ui->radioButton_Top->isChecked()); Config::setLeftSideTrophy(ui->radioButton_Left->isChecked()); Config::setPlayBGM(ui->playBGMCheckBox->isChecked()); Config::setAllowHDR(ui->enableHDRCheckBox->isChecked()); diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index c793aced5..3c866cddc 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -1285,7 +1285,13 @@ Trophy Notification Position - + + + + Top + + +