new type of notification when the auto accept config file is used

This commit is contained in:
otavepto 2024-01-06 07:41:32 +02:00
parent 9d533cd945
commit 21545509fd
2 changed files with 42 additions and 0 deletions

View File

@ -48,6 +48,7 @@ enum notification_type
notification_type_message = 0,
notification_type_invite,
notification_type_achievement,
notification_type_auto_accept_invite,
};
struct Notification
@ -150,6 +151,7 @@ class Steam_Overlay
void NotifyUser(friend_window_state& friend_state);
void NotifyUserAchievement();
void NotifySoundAutoAcceptFriendInvite();
// Right click on friend
void BuildContextMenu(Friend const& frd, friend_window_state &state);
@ -195,6 +197,7 @@ public:
void AddMessageNotification(std::string const& message);
void AddAchievementNotification(nlohmann::json const& ach);
void AddInviteNotification(std::pair<const Friend, friend_window_state> &wnd_state);
void AddAutoAcceptInviteNotification();
};
#else
@ -237,6 +240,7 @@ public:
void AddMessageNotification(std::string const& message) {}
void AddAchievementNotification(nlohmann::json const& ach) {}
void AddInviteNotification(std::pair<const Friend, friend_window_state> &wnd_state) {}
void AddAutoAcceptInviteNotification() {}
};
#endif

View File

@ -355,6 +355,17 @@ void Steam_Overlay::NotifyUserAchievement()
}
}
void Steam_Overlay::NotifySoundAutoAcceptFriendInvite()
{
#ifdef __WINDOWS__
if (notif_achievement_wav_custom_inuse) {
PlaySoundA((LPCSTR)notif_achievement_wav_custom, NULL, SND_ASYNC | SND_MEMORY);
} else {
PlaySoundA((LPCSTR)notif_invite_wav, NULL, SND_ASYNC | SND_MEMORY);
}
#endif
}
void Steam_Overlay::SetLobbyInvite(Friend friendId, uint64 lobbyId)
{
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
@ -512,6 +523,31 @@ void Steam_Overlay::AddInviteNotification(std::pair<const Friend, friend_window_
PRINT_DEBUG("No more free id to create a notification window\n");
}
void Steam_Overlay::AddAutoAcceptInviteNotification()
{
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
int id = find_free_notification_id(notifications);
if (id != 0)
{
Notification notif{};
notif.id = id;
notif.type = notification_type_auto_accept_invite;
{
char tmp[TRANSLATION_BUFFER_SIZE]{};
snprintf(tmp, sizeof(tmp), "%s", translationAutoAcceptFriendInvite[current_language]);
notif.message = tmp;
}
notif.start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch());
notifications.emplace_back(notif);
NotifySoundAutoAcceptFriendInvite();
have_notifications = true;
} else {
PRINT_DEBUG("No free id to create an auto-accept notification window\n");
}
}
bool Steam_Overlay::FriendJoinable(std::pair<const Friend, friend_window_state> &f)
{
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
@ -761,6 +797,8 @@ void Steam_Overlay::BuildNotifications(int width, int height)
break;
case notification_type_message:
ImGui::TextWrapped("%s", it->message.c_str()); break;
case notification_type_auto_accept_invite:
ImGui::TextWrapped("%s", it->message.c_str()); break;
}
ImGui::End();