Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve trophy pop-up #11078

Merged
merged 3 commits into from Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 43 additions & 6 deletions rpcs3/Emu/RSX/Overlays/overlay_trophy_notification.cpp
Expand Up @@ -40,7 +40,6 @@ namespace rsx
frame.back_color.g = 0.250980f;
frame.back_color.b = 0.247059f;
frame.back_color.a = 0.88f;


image.set_pos(78, 64);
image.set_size(53, 53);
Expand All @@ -54,9 +53,9 @@ namespace rsx

sliding_animation.duration = 1.5f;
sliding_animation.type = animation_type::ease_in_out_cubic;
sliding_animation.current = { -f32(frame.w), 0, 0 };
sliding_animation.end = { 0, 0, 0};
sliding_animation.active = true;

// Make the fade animation a bit shorter to see the trophy better.
fade_animation.duration = 1.0f;
}

void trophy_notification::update()
Expand All @@ -75,11 +74,14 @@ namespace rsx
return;
}

if (((t - creation_time) / 1000) > 5000)
const u64 time_since_creation = ((t - creation_time) / 1000);
u64 end_animation_begin = 5000;

if (time_since_creation > end_animation_begin)
{
if (!sliding_animation.active)
{
sliding_animation.end = { -f32(frame.w), 0, 0 };
sliding_animation.end = { -f32(frame.x + frame.w), 0, 0 };
sliding_animation.on_finish = [this]
{
s_trophy_semaphore.release();
Expand All @@ -90,10 +92,32 @@ namespace rsx
}
}

// Match both animation ends based on their durations
if (sliding_animation.duration > fade_animation.duration)
{
end_animation_begin += static_cast<u64>((sliding_animation.duration - fade_animation.duration) * 1000);
}

if (time_since_creation > end_animation_begin)
{
if (!fade_animation.active)
{
fade_animation.current = color4f(1.f);
fade_animation.end = color4f(0.f);

fade_animation.active = true;
}
}

if (sliding_animation.active)
{
sliding_animation.update(rsx::get_current_renderer()->vblank_count);
}

if (fade_animation.active)
{
fade_animation.update(rsx::get_current_renderer()->vblank_count);
}
}

compiled_resource trophy_notification::get_compiled()
Expand All @@ -108,6 +132,8 @@ namespace rsx
result.add(text_view.get_compiled());

sliding_animation.apply(result);
fade_animation.apply(result);

return result;
}

Expand Down Expand Up @@ -140,7 +166,18 @@ namespace rsx
u16 margin_sz = 9;
frame.w = margin_sz * 3 + image.w + text_view.w;

sliding_animation.current = { -f32(frame.x + frame.w), 0, 0 };
sliding_animation.end = { 0, 0, 0 };
sliding_animation.active = true;

fade_animation.current = color4f(0.f);
fade_animation.end = color4f(1.f);
fade_animation.active = true;

visible = true;

Emu.GetCallbacks().play_sound(fs::get_config_dir() + "sounds/trophy.wav");

return CELL_OK;
}
} // namespace overlays
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/RSX/Overlays/overlay_trophy_notification.h
Expand Up @@ -19,6 +19,7 @@ namespace rsx
std::unique_ptr<image_info> icon_info;

animation_translate sliding_animation;
animation_color_interpolate fade_animation;

public:
trophy_notification();
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/System.h
Expand Up @@ -80,6 +80,7 @@ struct EmuCallbacks
std::function<std::unique_ptr<class TrophyNotificationBase>()> get_trophy_notification_dialog;
std::function<std::string(localized_string_id, const char*)> get_localized_string;
std::function<std::u32string(localized_string_id, const char*)> get_localized_u32string;
std::function<void(const std::string&)> play_sound;
std::string(*resolve_path)(std::string_view) = nullptr; // Resolve path using Qt
};

Expand Down
2 changes: 2 additions & 0 deletions rpcs3/headless_application.cpp
Expand Up @@ -110,6 +110,8 @@ void headless_application::InitializeCallbacks()
callbacks.get_localized_string = [](localized_string_id, const char*) -> std::string { return {}; };
callbacks.get_localized_u32string = [](localized_string_id, const char*) -> std::u32string { return {}; };

callbacks.play_sound = [](const std::string&){};

callbacks.resolve_path = [](std::string_view sv)
{
return QFileInfo(QString::fromUtf8(sv.data(), static_cast<int>(sv.size()))).canonicalFilePath().toStdString();
Expand Down
12 changes: 12 additions & 0 deletions rpcs3/rpcs3qt/gui_application.cpp
Expand Up @@ -39,6 +39,7 @@
#include <QLibraryInfo>
#include <QDirIterator>
#include <QFileInfo>
#include <QSound>

#include <clocale>

Expand Down Expand Up @@ -412,6 +413,17 @@ void gui_application::InitializeCallbacks()
return localized_emu::get_u32string(id, args);
};

callbacks.play_sound = [](const std::string& path)
{
Emu.CallAfter([path]()
{
if (fs::is_file(path))
{
QSound::play(qstr(path));
}
});
};

callbacks.resolve_path = [](std::string_view sv)
{
return QFileInfo(QString::fromUtf8(sv.data(), static_cast<int>(sv.size()))).canonicalFilePath().toStdString();
Expand Down
4 changes: 4 additions & 0 deletions rpcs3/rpcs3qt/trophy_notification_helper.cpp
Expand Up @@ -5,6 +5,8 @@
#include "../Emu/System.h"
#include "../Emu/RSX/Overlays/overlay_trophy_notification.h"

#include "Utilities/File.h"

s32 trophy_notification_helper::ShowTrophyNotification(const SceNpTrophyDetails& trophy, const std::vector<uchar>& trophy_icon_buffer)
{
if (auto manager = g_fxo->try_get<rsx::overlays::display_manager>())
Expand All @@ -26,6 +28,8 @@ s32 trophy_notification_helper::ShowTrophyNotification(const SceNpTrophyDetails&
// Move notification to upper lefthand corner
trophy_notification->move(m_game_window->mapToGlobal(QPoint(0, 0)));
trophy_notification->show();

Emu.GetCallbacks().play_sound(fs::get_config_dir() + "sounds/trophy.wav");
});

return 0;
Expand Down