Animations, config: position, duration

This commit is contained in:
DanielSvoboda 2025-02-26 15:03:48 -03:00
parent a18c594b6c
commit 2caaaa294d
8 changed files with 2316 additions and 90 deletions

View File

@ -53,6 +53,7 @@ static bool isShaderDebug = false;
static bool isShowSplash = false;
static bool isAutoUpdate = false;
static bool isAlwaysShowChangelog = false;
static bool isLeftSideTrophy = false;
static bool isNullGpu = false;
static bool shouldCopyGPUBuffers = false;
static bool shouldDumpShaders = false;
@ -69,6 +70,7 @@ static bool isFpsColor = true;
static bool isSeparateLogFilesEnabled = false;
static s16 cursorState = HideCursorState::Idle;
static int cursorHideTimeout = 5; // 5 seconds (default)
static double trophyNotificationDuration = 6.0;
static bool useUnifiedInputConfig = true;
static bool overrideControllerColor = false;
static int controllerCustomColorRGB[3] = {0, 0, 255};
@ -196,6 +198,10 @@ int getCursorHideTimeout() {
return cursorHideTimeout;
}
double getTrophyNotificationDuration() {
return trophyNotificationDuration;
}
u32 getScreenWidth() {
return screenWidth;
}
@ -264,6 +270,10 @@ bool alwaysShowChangelog() {
return isAlwaysShowChangelog;
}
bool leftSideTrophy() {
return isLeftSideTrophy;
}
bool nullGpu() {
return isNullGpu;
}
@ -371,6 +381,9 @@ void setAutoUpdate(bool enable) {
void setAlwaysShowChangelog(bool enable) {
isAlwaysShowChangelog = enable;
}
void setLeftSideTrophy(bool enable) {
isLeftSideTrophy = enable;
}
void setNullGpu(bool enable) {
isNullGpu = enable;
@ -435,6 +448,9 @@ void setCursorState(s16 newCursorState) {
void setCursorHideTimeout(int newcursorHideTimeout) {
cursorHideTimeout = newcursorHideTimeout;
}
void setTrophyNotificationDuration(double newTrophyNotificationDuration) {
trophyNotificationDuration = newTrophyNotificationDuration;
}
void setLanguage(u32 language) {
m_language = language;
@ -706,6 +722,7 @@ void load(const std::filesystem::path& path) {
isNeo = toml::find_or<bool>(general, "isPS4Pro", false);
playBGM = toml::find_or<bool>(general, "playBGM", false);
isTrophyPopupDisabled = toml::find_or<bool>(general, "isTrophyPopupDisabled", false);
trophyNotificationDuration = toml::find_or<double>(general, "trophyNotificationDuration", 5.0);
BGMvolume = toml::find_or<int>(general, "BGMvolume", 50);
enableDiscordRPC = toml::find_or<bool>(general, "enableDiscordRPC", true);
logFilter = toml::find_or<std::string>(general, "logFilter", "");
@ -719,6 +736,7 @@ void load(const std::filesystem::path& path) {
isShowSplash = toml::find_or<bool>(general, "showSplash", true);
isAutoUpdate = toml::find_or<bool>(general, "autoUpdate", false);
isAlwaysShowChangelog = toml::find_or<bool>(general, "alwaysShowChangelog", false);
isLeftSideTrophy = toml::find_or<bool>(general, "leftSideTrophy", false);
separateupdatefolder = toml::find_or<bool>(general, "separateUpdateEnabled", false);
compatibilityData = toml::find_or<bool>(general, "compatibilityEnabled", false);
checkCompatibilityOnStartup =
@ -856,6 +874,7 @@ void save(const std::filesystem::path& path) {
data["General"]["isPS4Pro"] = isNeo;
data["General"]["isTrophyPopupDisabled"] = isTrophyPopupDisabled;
data["General"]["trophyNotificationDuration"] = trophyNotificationDuration;
data["General"]["playBGM"] = playBGM;
data["General"]["BGMvolume"] = BGMvolume;
data["General"]["enableDiscordRPC"] = enableDiscordRPC;
@ -867,6 +886,7 @@ void save(const std::filesystem::path& path) {
data["General"]["showSplash"] = isShowSplash;
data["General"]["autoUpdate"] = isAutoUpdate;
data["General"]["alwaysShowChangelog"] = isAlwaysShowChangelog;
data["General"]["leftSideTrophy"] = isLeftSideTrophy;
data["General"]["separateUpdateEnabled"] = separateupdatefolder;
data["General"]["compatibilityEnabled"] = compatibilityData;
data["General"]["checkCompatibilityOnStartup"] = checkCompatibilityOnStartup;
@ -986,6 +1006,7 @@ void setDefaultValues() {
chooseHomeTab = "General";
cursorState = HideCursorState::Idle;
cursorHideTimeout = 5;
trophyNotificationDuration = 6.0;
backButtonBehavior = "left";
useSpecialPad = false;
specialPadClass = 1;
@ -994,6 +1015,7 @@ void setDefaultValues() {
isShowSplash = false;
isAutoUpdate = false;
isAlwaysShowChangelog = false;
isLeftSideTrophy = false;
isNullGpu = false;
shouldDumpShaders = false;
vblankDivider = 1;

View File

@ -41,6 +41,7 @@ std::string getChooseHomeTab();
s16 getCursorState();
int getCursorHideTimeout();
double getTrophyNotificationDuration();
std::string getBackButtonBehavior();
bool getUseSpecialPad();
int getSpecialPadClass();
@ -62,6 +63,7 @@ bool collectShadersForDebug();
bool showSplash();
bool autoUpdate();
bool alwaysShowChangelog();
bool leftSideTrophy();
bool nullGpu();
bool copyGPUCmdBuffers();
bool dumpShaders();
@ -75,6 +77,7 @@ void setCollectShaderForDebug(bool enable);
void setShowSplash(bool enable);
void setAutoUpdate(bool enable);
void setAlwaysShowChangelog(bool enable);
void setLeftSideTrophy(bool enable);
void setNullGpu(bool enable);
void setAllowHDR(bool enable);
void setCopyGPUCmdBuffers(bool enable);
@ -104,6 +107,7 @@ void setShowBackgroundImage(bool show);
void setCursorState(s16 cursorState);
void setCursorHideTimeout(int newcursorHideTimeout);
void setTrophyNotificationDuration(double newTrophyNotificationDuration);
void setBackButtonBehavior(const std::string& type);
void setUseSpecialPad(bool use);
void setSpecialPadClass(int type);

View File

@ -27,11 +27,16 @@ namespace Libraries::NpTrophy {
std::optional<TrophyUI> current_trophy_ui;
std::queue<TrophyInfo> trophy_queue;
std::mutex queueMtx;
bool isLeftSide;
double trophy_timer;
TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::string& trophyName,
const std::string_view& rarity)
: trophy_name(trophyName), trophy_type(rarity) {
isLeftSide = Config::leftSideTrophy();
trophy_timer = Config::getTrophyNotificationDuration();
if (std::filesystem::exists(trophyIconPath)) {
trophy_icon = RefCountedTexture::DecodePngFile(trophyIconPath);
} else {
@ -100,6 +105,13 @@ void TrophyUI::Finish() {
RemoveLayer(this);
}
float fade_opacity = 0.0f; // Initial opacity (invisible)
ImVec2 start_pos = ImVec2(1280.0f, 50.0f); // Starts off screen, right
ImVec2 target_pos = ImVec2(0.0f, 50.0f); // Final position
float animation_duration = 0.5f; // Animation duration
float elapsed_time = 0.0f; // Animation time
float fade_out_duration = 0.5f; // Final fade duration
void TrophyUI::Draw() {
const auto& io = GetIO();
@ -110,26 +122,60 @@ void TrophyUI::Draw() {
std::min(io.DisplaySize.y, (70 * AdjustHeight)),
};
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;
final_pos_x = 20 * AdjustWidth;
} else {
start_pos.x = io.DisplaySize.x;
final_pos_x = io.DisplaySize.x - window_size.x - 20 * AdjustWidth;
}
ImVec2 current_pos = ImVec2(start_pos.x + (final_pos_x - start_pos.x) * progress,
start_pos.y + (target_pos.y - start_pos.y) * progress);
trophy_timer -= io.DeltaTime;
// 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);
fade_opacity = 1.0f - fade_out_time;
} else {
// Fade in , 0 to 1
fade_opacity = progress;
}
fade_opacity = std::max(0.0f, std::min(fade_opacity, 1.0f));
SetNextWindowSize(window_size);
SetNextWindowPos(current_pos);
SetNextWindowCollapsed(false);
SetNextWindowPos(ImVec2(io.DisplaySize.x - (370 * AdjustWidth), (50 * AdjustHeight)));
KeepNavHighlight();
PushStyleVar(ImGuiStyleVar_Alpha, fade_opacity);
if (Begin("Trophy Window", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings |
ImGuiWindowFlags_NoInputs)) {
// Displays the trophy icon
if (trophy_type_icon) {
SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight));
Image(trophy_type_icon.GetTexture().im_id,
ImVec2((50 * AdjustWidth), (50 * AdjustHeight)));
ImGui::SameLine();
} else {
// placeholder
// Placeholder
const auto pos = GetCursorScreenPos();
ImGui::GetWindowDrawList()->AddRectFilled(pos, pos + ImVec2{50.0f * AdjustHeight},
GetColorU32(ImVec4{0.7f}));
ImGui::Indent(60);
}
// Displays the name of the trophy
const std::string combinedString = "Trophy earned!\n%s" + trophy_name;
const float wrap_width =
CalcWrapWidthForPos(GetCursorScreenPos(), (window_size.x - (60 * AdjustWidth)));
@ -150,11 +196,12 @@ void TrophyUI::Draw() {
TextWrapped("Trophy earned!\n%s", trophy_name.c_str());
ImGui::SameLine(window_size.x - (60 * AdjustWidth));
// Displays the trophy icon
if (trophy_icon) {
SetCursorPosY((window_size.y * 0.5f) - (25 * AdjustHeight));
Image(trophy_icon.GetTexture().im_id, ImVec2((50 * AdjustWidth), (50 * AdjustHeight)));
} else {
// placeholder
// Placeholder
const auto pos = GetCursorScreenPos();
ImGui::GetWindowDrawList()->AddRectFilled(pos, pos + ImVec2{50.0f * AdjustHeight},
GetColorU32(ImVec4{0.7f}));
@ -162,7 +209,8 @@ void TrophyUI::Draw() {
}
End();
trophy_timer -= io.DeltaTime;
PopStyleVar();
if (trophy_timer <= 0) {
std::lock_guard<std::mutex> lock(queueMtx);
if (!trophy_queue.empty()) {
@ -193,6 +241,11 @@ void AddTrophyToQueue(const std::filesystem::path& trophyIconPath, const std::st
trophy_queue.push(new_trophy);
if (!current_trophy_ui.has_value()) {
// Resetting the animation for the next trophy
BackgroundMusicPlayer::getInstance().stopMusic();
elapsed_time = 0.0f; // Resetting animation time
fade_opacity = 0.0f; // Starts invisible
start_pos = ImVec2(1280.0f, 50.0f); // Starts off screen, right
TrophyInfo next_trophy = trophy_queue.front();
trophy_queue.pop();
current_trophy_ui.emplace(next_trophy.trophy_icon_path, next_trophy.trophy_name,

View File

@ -28,7 +28,6 @@ public:
private:
std::string trophy_name;
std::string_view trophy_type;
float trophy_timer = 5.0f;
ImGui::RefCountedTexture trophy_icon;
ImGui::RefCountedTexture trophy_type_icon;
};

View File

@ -417,6 +417,9 @@ void SettingsDialog::LoadValuesFromConfig() {
ui->playBGMCheckBox->setChecked(toml::find_or<bool>(data, "General", "playBGM", false));
ui->disableTrophycheckBox->setChecked(
toml::find_or<bool>(data, "General", "isTrophyPopupDisabled", false));
ui->popUpDurationSpinBox->setValue(Config::getTrophyNotificationDuration());
ui->radioButton_Left->setChecked(Config::leftSideTrophy());
ui->radioButton_Right->setChecked(!ui->radioButton_Left->isChecked());
ui->BGMVolumeSlider->setValue(toml::find_or<int>(data, "General", "BGMvolume", 50));
ui->discordRPCCheckbox->setChecked(
toml::find_or<bool>(data, "General", "enableDiscordRPC", true));
@ -702,6 +705,8 @@ void SettingsDialog::UpdateSettings() {
screenModeMap.value(ui->displayModeComboBox->currentText()).toStdString());
Config::setIsMotionControlsEnabled(ui->motionControlsCheckBox->isChecked());
Config::setisTrophyPopupDisabled(ui->disableTrophycheckBox->isChecked());
Config::setTrophyNotificationDuration(ui->popUpDurationSpinBox->value());
Config::setLeftSideTrophy(ui->radioButton_Left->isChecked());
Config::setPlayBGM(ui->playBGMCheckBox->isChecked());
Config::setAllowHDR(ui->enableHDRCheckBox->isChecked());
Config::setLogType(logTypeMap.value(ui->logTypeComboBox->currentText()).toStdString());

View File

@ -73,8 +73,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>718</width>
<height>332</height>
<width>946</width>
<height>545</height>
</rect>
</property>
<layout class="QVBoxLayout" name="generalTabVLayout" stretch="0">
@ -454,8 +454,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>646</width>
<height>395</height>
<width>946</width>
<height>545</height>
</rect>
</property>
<layout class="QVBoxLayout" name="guiTabVLayout" stretch="0">
@ -903,8 +903,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>141</height>
<width>946</width>
<height>545</height>
</rect>
</property>
<layout class="QVBoxLayout" name="graphicsTabVLayout" stretch="0,0">
@ -1198,8 +1198,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>234</width>
<height>292</height>
<width>946</width>
<height>545</height>
</rect>
</property>
<layout class="QVBoxLayout" name="userTabVLayout" stretch="0,0,1">
@ -1264,10 +1264,92 @@
<item>
<widget class="QCheckBox" name="disableTrophycheckBox">
<property name="text">
<string>Disable Trophy Pop-ups</string>
<string>Disable Trophy Notification</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_SidePopUps">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_SidePopUps">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Trophy Notification Position</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_Left">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_Right">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Right</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_PopUpsDuration">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_PopUpDuration">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Notification Duration</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="popUpDurationSpinBox">
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_trophyKey">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_Trophy">
<property name="text">
@ -1291,6 +1373,8 @@
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="OpenCustomTrophyLocationButton">
<property name="text">
@ -1349,8 +1433,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>455</width>
<height>252</height>
<width>946</width>
<height>545</height>
</rect>
</property>
<layout class="QVBoxLayout" name="inputTabVLayout" stretch="0,0">
@ -1633,8 +1717,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>216</width>
<height>254</height>
<width>946</width>
<height>545</height>
</rect>
</property>
<layout class="QVBoxLayout" name="pathsTabLayout">
@ -1724,7 +1808,7 @@
<x>0</x>
<y>0</y>
<width>946</width>
<height>536</height>
<height>545</height>
</rect>
</property>
<layout class="QVBoxLayout" name="debugTabVLayout" stretch="0,0">

File diff suppressed because it is too large Load Diff

View File

@ -1480,8 +1480,8 @@
<translation>Title Music</translation>
</message>
<message>
<source>Disable Trophy Pop-ups</source>
<translation>Disable Trophy Pop-ups</translation>
<source>Disable Trophy Notification</source>
<translation>Disable Trophy Notification</translation>
</message>
<message>
<source>Background Image</source>