2024-01-22 01:31:02 +02:00
|
|
|
#ifdef EMU_OVERLAY
|
|
|
|
|
|
|
|
// if you're wondering about text like: ##PopupAcceptInvite
|
|
|
|
// these are unique labels (keys) for each button/label/text,etc...
|
|
|
|
// ImGui uses the labels as keys, adding a suffic like "My Text##SomeKey"
|
|
|
|
// avoids confusing ImGui when another label has the same text "MyText"
|
|
|
|
|
2023-12-27 09:21:59 +02:00
|
|
|
#include "overlay/steam_overlay.h"
|
|
|
|
#include "overlay/steam_overlay_translations.h"
|
2019-07-31 22:21:02 +02:00
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2019-08-03 12:58:48 +02:00
|
|
|
#include <cctype>
|
2019-07-31 22:21:02 +02:00
|
|
|
#include <imgui.h>
|
|
|
|
|
2023-12-27 09:21:59 +02:00
|
|
|
#include "dll/dll.h"
|
|
|
|
#include "dll/settings_parser.h"
|
2019-07-31 22:21:02 +02:00
|
|
|
|
2023-12-27 09:21:59 +02:00
|
|
|
#include "overlay/Renderer_Detector.h"
|
2019-08-18 16:22:07 +02:00
|
|
|
|
2019-10-11 13:10:48 +02:00
|
|
|
static constexpr int max_window_id = 10000;
|
|
|
|
static constexpr int base_notif_window_id = 0 * max_window_id;
|
|
|
|
static constexpr int base_friend_window_id = 1 * max_window_id;
|
|
|
|
static constexpr int base_friend_item_id = 2 * max_window_id;
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
static constexpr char *valid_languages[] = {
|
|
|
|
"english",
|
|
|
|
"arabic",
|
|
|
|
"bulgarian",
|
|
|
|
"schinese",
|
|
|
|
"tchinese",
|
|
|
|
"czech",
|
|
|
|
"danish",
|
|
|
|
"dutch",
|
|
|
|
"finnish",
|
|
|
|
"french",
|
|
|
|
"german",
|
|
|
|
"greek",
|
|
|
|
"hungarian",
|
|
|
|
"italian",
|
|
|
|
"japanese",
|
|
|
|
"koreana",
|
|
|
|
"norwegian",
|
|
|
|
"polish",
|
|
|
|
"portuguese",
|
|
|
|
"brazilian",
|
|
|
|
"romanian",
|
|
|
|
"russian",
|
|
|
|
"spanish",
|
|
|
|
"latam",
|
|
|
|
"swedish",
|
|
|
|
"thai",
|
|
|
|
"turkish",
|
|
|
|
"ukrainian",
|
2023-08-24 20:59:01 +03:00
|
|
|
"vietnamese",
|
|
|
|
"croatian"
|
2022-08-05 02:09:43 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define URL_WINDOW_NAME "URL Window"
|
|
|
|
|
2019-10-11 13:10:48 +02:00
|
|
|
int find_free_id(std::vector<int> & ids, int base)
|
|
|
|
{
|
|
|
|
std::sort(ids.begin(), ids.end());
|
|
|
|
|
|
|
|
int id = base;
|
|
|
|
for (auto i : ids)
|
|
|
|
{
|
|
|
|
if (id < i)
|
|
|
|
break;
|
|
|
|
id = i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return id > (base+max_window_id) ? 0 : id;
|
|
|
|
}
|
|
|
|
|
2024-01-22 01:31:02 +02:00
|
|
|
int find_free_friend_id(const std::map<Friend, friend_window_state, Friend_Less> &friend_windows)
|
2019-10-11 13:10:48 +02:00
|
|
|
{
|
2024-01-22 01:31:02 +02:00
|
|
|
std::vector<int> ids{};
|
2019-10-11 13:10:48 +02:00
|
|
|
ids.reserve(friend_windows.size());
|
|
|
|
|
|
|
|
std::for_each(friend_windows.begin(), friend_windows.end(), [&ids](std::pair<Friend const, friend_window_state> const& i)
|
|
|
|
{
|
|
|
|
ids.emplace_back(i.second.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
return find_free_id(ids, base_friend_window_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int find_free_notification_id(std::vector<Notification> const& notifications)
|
|
|
|
{
|
2024-01-22 01:31:02 +02:00
|
|
|
std::vector<int> ids{};
|
2019-10-11 13:10:48 +02:00
|
|
|
ids.reserve(notifications.size());
|
|
|
|
|
|
|
|
std::for_each(notifications.begin(), notifications.end(), [&ids](Notification const& i)
|
|
|
|
{
|
|
|
|
ids.emplace_back(i.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return find_free_id(ids, base_friend_window_id);
|
|
|
|
}
|
|
|
|
|
2019-09-01 20:48:27 +02:00
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#include "windows/Windows_Hook.h"
|
|
|
|
#endif
|
2019-08-15 22:23:59 +02:00
|
|
|
|
2023-12-27 09:21:59 +02:00
|
|
|
#include "overlay/notification.h"
|
2023-11-10 17:25:36 +02:00
|
|
|
char *notif_achievement_wav_custom;
|
|
|
|
char *notif_invite_wav_custom;
|
|
|
|
bool notif_achievement_wav_custom_inuse = false;
|
|
|
|
bool notif_invite_wav_custom_inuse = false;
|
2019-08-16 18:31:56 +02:00
|
|
|
|
2019-08-06 13:46:43 +02:00
|
|
|
void Steam_Overlay::steam_overlay_run_every_runcb(void* object)
|
|
|
|
{
|
|
|
|
Steam_Overlay* _this = reinterpret_cast<Steam_Overlay*>(object);
|
|
|
|
_this->RunCallbacks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::steam_overlay_callback(void* object, Common_Message* msg)
|
|
|
|
{
|
|
|
|
Steam_Overlay* _this = reinterpret_cast<Steam_Overlay*>(object);
|
|
|
|
_this->Callback(msg);
|
|
|
|
}
|
|
|
|
|
2019-08-26 16:38:01 +02:00
|
|
|
Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking* network) :
|
2019-07-31 22:21:02 +02:00
|
|
|
settings(settings),
|
|
|
|
callback_results(callback_results),
|
|
|
|
callbacks(callbacks),
|
|
|
|
run_every_runcb(run_every_runcb),
|
|
|
|
network(network),
|
2019-08-26 16:38:01 +02:00
|
|
|
setup_overlay_called(false),
|
2019-07-31 22:21:02 +02:00
|
|
|
show_overlay(false),
|
|
|
|
is_ready(false),
|
|
|
|
notif_position(ENotificationPosition::k_EPositionBottomLeft),
|
|
|
|
h_inset(0),
|
|
|
|
v_inset(0),
|
2020-01-26 09:46:57 -05:00
|
|
|
overlay_state_changed(false),
|
2022-08-05 02:09:43 -04:00
|
|
|
i_have_lobby(false),
|
|
|
|
show_achievements(false),
|
|
|
|
show_settings(false),
|
2022-08-21 03:45:11 -04:00
|
|
|
_renderer(nullptr),
|
|
|
|
fonts_atlas(nullptr)
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2022-08-05 02:09:43 -04:00
|
|
|
strncpy(username_text, settings->get_local_name(), sizeof(username_text));
|
|
|
|
|
2023-12-29 03:55:11 +02:00
|
|
|
// we need these copies to show the warning only once, then disable the flag
|
|
|
|
// avoid manipulating settings->xxx
|
|
|
|
this->warn_forced_setting =
|
|
|
|
!settings->disable_overlay_warning_any && !settings->disable_overlay_warning_forced_setting && settings->overlay_warn_forced_setting;
|
|
|
|
this->warn_local_save =
|
|
|
|
!settings->disable_overlay_warning_any && !settings->disable_overlay_warning_local_save && settings->overlay_warn_local_save;
|
|
|
|
this->warn_bad_appid =
|
|
|
|
!settings->disable_overlay_warning_any && !settings->disable_overlay_warning_bad_appid && settings->get_local_game_id().AppID() == 0;
|
2022-08-05 02:09:43 -04:00
|
|
|
|
2023-12-29 03:55:11 +02:00
|
|
|
this->disable_user_input = this->warn_forced_setting;
|
2022-08-05 02:09:43 -04:00
|
|
|
|
|
|
|
current_language = 0;
|
|
|
|
const char *language = settings->get_language();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (auto l : valid_languages) {
|
|
|
|
if (strcmp(l, language) == 0) {
|
|
|
|
current_language = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
run_every_runcb->add(&Steam_Overlay::steam_overlay_run_every_runcb, this);
|
2019-08-03 12:58:48 +02:00
|
|
|
this->network->setCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::steam_overlay_callback, this);
|
2019-07-31 22:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Steam_Overlay::~Steam_Overlay()
|
|
|
|
{
|
|
|
|
run_every_runcb->remove(&Steam_Overlay::steam_overlay_run_every_runcb, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::Ready() const
|
|
|
|
{
|
|
|
|
return is_ready;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::NeedPresent() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetNotificationPosition(ENotificationPosition eNotificationPosition)
|
|
|
|
{
|
|
|
|
notif_position = eNotificationPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetNotificationInset(int nHorizontalInset, int nVerticalInset)
|
|
|
|
{
|
|
|
|
h_inset = nHorizontalInset;
|
|
|
|
v_inset = nVerticalInset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::SetupOverlay()
|
|
|
|
{
|
2020-01-25 15:23:16 -05:00
|
|
|
PRINT_DEBUG("%s\n", __FUNCTION__);
|
2020-01-20 11:47:12 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-26 16:38:01 +02:00
|
|
|
if (!setup_overlay_called)
|
|
|
|
{
|
|
|
|
setup_overlay_called = true;
|
2022-08-10 03:22:23 -04:00
|
|
|
future_renderer = ingame_overlay::DetectRenderer();
|
2019-08-26 16:38:01 +02:00
|
|
|
}
|
2019-08-18 14:29:08 +02:00
|
|
|
}
|
|
|
|
|
2022-08-07 23:11:21 -04:00
|
|
|
|
|
|
|
void Steam_Overlay::UnSetupOverlay()
|
|
|
|
{
|
2023-12-19 22:17:29 +02:00
|
|
|
PRINT_DEBUG("%s\n", __FUNCTION__);
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2022-08-10 03:22:23 -04:00
|
|
|
ingame_overlay::StopRendererDetection();
|
2022-08-07 23:11:21 -04:00
|
|
|
if (!Ready() && future_renderer.valid()) {
|
|
|
|
if (future_renderer.wait_for(std::chrono::milliseconds{500}) == std::future_status::ready) {
|
|
|
|
future_renderer.get();
|
2022-08-21 03:43:24 -04:00
|
|
|
ingame_overlay::FreeDetector();
|
2022-08-07 23:11:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
void Steam_Overlay::HookReady(bool ready)
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2022-08-13 14:35:59 -04:00
|
|
|
PRINT_DEBUG("%s %u\n", __FUNCTION__, ready);
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2019-08-18 16:22:07 +02:00
|
|
|
// TODO: Uncomment this and draw our own cursor (cosmetics)
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
2019-08-18 16:22:07 +02:00
|
|
|
//io.WantSetMousePos = false;
|
|
|
|
//io.MouseDrawCursor = false;
|
|
|
|
//io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
io.IniFilename = NULL;
|
|
|
|
|
|
|
|
is_ready = ready;
|
2019-07-31 22:21:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlayInvite(CSteamID lobbyId)
|
|
|
|
{
|
2019-08-02 11:16:30 +02:00
|
|
|
ShowOverlay(true);
|
2019-07-31 22:21:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlay(const char* pchDialog)
|
|
|
|
{
|
|
|
|
// TODO: Show pages depending on pchDialog
|
2024-01-22 01:24:22 +02:00
|
|
|
if ((strncmp(pchDialog, "Friends", sizeof("Friends") - 1) == 0) && (settings->overlayAutoAcceptInvitesCount() > 0)) {
|
2024-01-06 07:43:09 +02:00
|
|
|
PRINT_DEBUG("Not opening overlay's friends list because some friends are defined in the auto accept list\n");
|
|
|
|
AddAutoAcceptInviteNotification();
|
|
|
|
} else {
|
|
|
|
ShowOverlay(true);
|
|
|
|
}
|
2019-07-31 22:21:02 +02:00
|
|
|
}
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
void Steam_Overlay::OpenOverlayWebpage(const char* pchURL)
|
|
|
|
{
|
|
|
|
show_url = pchURL;
|
|
|
|
ShowOverlay(true);
|
|
|
|
}
|
|
|
|
|
2019-08-18 16:22:07 +02:00
|
|
|
bool Steam_Overlay::ShowOverlay() const
|
|
|
|
{
|
|
|
|
return show_overlay;
|
|
|
|
}
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
bool Steam_Overlay::OpenOverlayHook(bool toggle)
|
|
|
|
{
|
|
|
|
if (toggle) {
|
|
|
|
ShowOverlay(!show_overlay);
|
|
|
|
}
|
|
|
|
|
|
|
|
return show_overlay;
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
void Steam_Overlay::ShowOverlay(bool state)
|
|
|
|
{
|
2019-08-31 20:49:07 +02:00
|
|
|
if (!Ready() || show_overlay == state)
|
|
|
|
return;
|
|
|
|
|
2019-10-16 16:56:41 +02:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
|
|
|
|
|
if(state)
|
|
|
|
{
|
|
|
|
io.MouseDrawCursor = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
io.MouseDrawCursor = false;
|
|
|
|
}
|
|
|
|
|
2019-09-01 20:48:27 +02:00
|
|
|
#ifdef __WINDOWS__
|
2019-07-31 22:21:02 +02:00
|
|
|
static RECT old_clip;
|
|
|
|
|
2019-08-27 21:15:58 +02:00
|
|
|
if (state)
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2019-08-27 15:38:07 +02:00
|
|
|
HWND game_hwnd = Windows_Hook::Inst()->GetGameHwnd();
|
2019-07-31 22:21:02 +02:00
|
|
|
RECT cliRect, wndRect, clipRect;
|
|
|
|
|
|
|
|
GetClipCursor(&old_clip);
|
|
|
|
// The window rectangle has borders and menus counted in the size
|
|
|
|
GetWindowRect(game_hwnd, &wndRect);
|
|
|
|
// The client rectangle is the window without borders
|
|
|
|
GetClientRect(game_hwnd, &cliRect);
|
|
|
|
|
|
|
|
clipRect = wndRect; // Init clip rectangle
|
|
|
|
|
|
|
|
// Get Window width with borders
|
|
|
|
wndRect.right -= wndRect.left;
|
|
|
|
// Get Window height with borders & menus
|
|
|
|
wndRect.bottom -= wndRect.top;
|
|
|
|
// Compute the border width
|
|
|
|
int borderWidth = (wndRect.right - cliRect.right) / 2;
|
|
|
|
// Client top clip is the menu bar width minus bottom border
|
|
|
|
clipRect.top += wndRect.bottom - cliRect.bottom - borderWidth;
|
|
|
|
// Client left clip is the left border minus border width
|
|
|
|
clipRect.left += borderWidth;
|
|
|
|
// Here goes the same for right and bottom
|
|
|
|
clipRect.right -= borderWidth;
|
|
|
|
clipRect.bottom -= borderWidth;
|
|
|
|
|
|
|
|
ClipCursor(&clipRect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ClipCursor(&old_clip);
|
|
|
|
}
|
2019-08-31 20:49:07 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-08-27 21:15:58 +02:00
|
|
|
show_overlay = state;
|
2019-07-31 22:21:02 +02:00
|
|
|
overlay_state_changed = true;
|
|
|
|
}
|
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
void Steam_Overlay::NotifySoundUserInvite(friend_window_state& friend_state)
|
2019-09-04 19:31:31 +02:00
|
|
|
{
|
2023-08-24 20:59:01 +03:00
|
|
|
if (settings->disable_overlay_friend_notification) return;
|
2019-09-05 09:00:02 +02:00
|
|
|
if (!(friend_state.window_state & window_state_show) || !show_overlay)
|
2019-09-04 19:31:31 +02:00
|
|
|
{
|
|
|
|
friend_state.window_state |= window_state_need_attention;
|
|
|
|
#ifdef __WINDOWS__
|
2023-11-10 17:25:36 +02:00
|
|
|
if (notif_invite_wav_custom_inuse) {
|
|
|
|
PlaySoundA((LPCSTR)notif_invite_wav_custom, NULL, SND_ASYNC | SND_MEMORY);
|
|
|
|
} else {
|
|
|
|
PlaySoundA((LPCSTR)notif_invite_wav, NULL, SND_ASYNC | SND_MEMORY);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
void Steam_Overlay::NotifySoundUserAchievement()
|
2023-11-10 17:25:36 +02:00
|
|
|
{
|
|
|
|
if (settings->disable_overlay_achievement_notification) return;
|
|
|
|
if (!show_overlay)
|
|
|
|
{
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
if (notif_achievement_wav_custom_inuse) {
|
|
|
|
PlaySoundA((LPCSTR)notif_achievement_wav_custom, NULL, SND_ASYNC | SND_MEMORY);
|
|
|
|
}
|
2019-09-04 19:31:31 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-06 07:41:32 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-08-02 23:01:24 +02:00
|
|
|
void Steam_Overlay::SetLobbyInvite(Friend friendId, uint64 lobbyId)
|
2019-08-02 11:16:30 +02:00
|
|
|
{
|
2023-12-19 22:17:29 +02:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-16 10:37:45 +02:00
|
|
|
if (!Ready())
|
|
|
|
return;
|
|
|
|
|
2019-08-02 13:02:20 +02:00
|
|
|
auto i = friends.find(friendId);
|
|
|
|
if (i != friends.end())
|
|
|
|
{
|
|
|
|
auto& frd = i->second;
|
|
|
|
frd.lobbyId = lobbyId;
|
|
|
|
frd.window_state |= window_state_lobby_invite;
|
2019-08-02 23:01:24 +02:00
|
|
|
// Make sure don't have rich presence invite and a lobby invite (it should not happen but who knows)
|
|
|
|
frd.window_state &= ~window_state_rich_invite;
|
2019-11-08 15:52:38 +01:00
|
|
|
AddInviteNotification(*i);
|
2024-01-26 05:49:03 +02:00
|
|
|
NotifySoundUserInvite(i->second);
|
2019-08-02 13:02:20 +02:00
|
|
|
}
|
2019-08-02 11:16:30 +02:00
|
|
|
}
|
|
|
|
|
2019-08-02 23:01:24 +02:00
|
|
|
void Steam_Overlay::SetRichInvite(Friend friendId, const char* connect_str)
|
2019-08-02 11:16:30 +02:00
|
|
|
{
|
2023-12-19 22:17:29 +02:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-16 10:37:45 +02:00
|
|
|
if (!Ready())
|
|
|
|
return;
|
|
|
|
|
2019-08-02 13:02:20 +02:00
|
|
|
auto i = friends.find(friendId);
|
|
|
|
if (i != friends.end())
|
|
|
|
{
|
|
|
|
auto& frd = i->second;
|
|
|
|
strncpy(frd.connect, connect_str, k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
frd.window_state |= window_state_rich_invite;
|
2019-08-02 23:01:24 +02:00
|
|
|
// Make sure don't have rich presence invite and a lobby invite (it should not happen but who knows)
|
|
|
|
frd.window_state &= ~window_state_lobby_invite;
|
2019-11-08 15:52:38 +01:00
|
|
|
AddInviteNotification(*i);
|
2024-01-26 05:49:03 +02:00
|
|
|
NotifySoundUserInvite(i->second);
|
2019-08-02 13:02:20 +02:00
|
|
|
}
|
2019-08-02 11:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::FriendConnect(Friend _friend)
|
|
|
|
{
|
2020-01-20 11:47:12 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-10-11 13:10:48 +02:00
|
|
|
int id = find_free_friend_id(friends);
|
|
|
|
if (id != 0)
|
|
|
|
{
|
|
|
|
auto& item = friends[_friend];
|
2023-08-21 06:58:55 +03:00
|
|
|
item.window_title = std::move(_friend.name() + translationPlaying[current_language] + std::to_string(_friend.appid()));
|
2019-10-11 13:10:48 +02:00
|
|
|
item.window_state = window_state_none;
|
|
|
|
item.id = id;
|
|
|
|
memset(item.chat_input, 0, max_chat_len);
|
2020-02-02 19:07:30 -05:00
|
|
|
item.joinable = false;
|
2019-10-11 13:10:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
PRINT_DEBUG("No more free id to create a friend window\n");
|
2019-08-02 11:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::FriendDisconnect(Friend _friend)
|
|
|
|
{
|
2020-01-20 11:47:12 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-02 11:16:30 +02:00
|
|
|
auto it = friends.find(_friend);
|
|
|
|
if (it != friends.end())
|
|
|
|
friends.erase(it);
|
|
|
|
}
|
|
|
|
|
2019-11-08 15:52:38 +01:00
|
|
|
void Steam_Overlay::AddMessageNotification(std::string const& message)
|
2019-09-04 19:31:31 +02:00
|
|
|
{
|
2020-01-26 17:24:16 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
|
2023-12-19 22:17:29 +02:00
|
|
|
if (settings->disable_overlay_friend_notification) return;
|
2019-10-11 13:10:48 +02:00
|
|
|
int id = find_free_notification_id(notifications);
|
|
|
|
if (id != 0)
|
|
|
|
{
|
|
|
|
Notification notif;
|
|
|
|
notif.id = id;
|
2019-11-08 15:52:38 +01:00
|
|
|
notif.type = notification_type_message;
|
2019-10-11 13:10:48 +02:00
|
|
|
notif.message = message;
|
|
|
|
notif.start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch());
|
|
|
|
notifications.emplace_back(notif);
|
2022-08-05 02:09:43 -04:00
|
|
|
have_notifications = true;
|
2019-10-11 13:10:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
PRINT_DEBUG("No more free id to create a notification window\n");
|
2019-09-04 19:31:31 +02:00
|
|
|
}
|
|
|
|
|
2024-01-24 02:21:09 +02:00
|
|
|
// show a notification when the user unlocks an achievement
|
2019-11-08 15:52:38 +01:00
|
|
|
void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach)
|
|
|
|
{
|
2020-01-26 17:24:16 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
|
2023-08-21 06:58:55 +03:00
|
|
|
if (!settings->disable_overlay_achievement_notification) {
|
|
|
|
int id = find_free_notification_id(notifications);
|
|
|
|
if (id != 0)
|
|
|
|
{
|
|
|
|
Notification notif;
|
|
|
|
notif.id = id;
|
|
|
|
notif.type = notification_type_achievement;
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2023-08-21 06:58:55 +03:00
|
|
|
// Load achievement image
|
2023-11-10 17:25:36 +02:00
|
|
|
std::string file_path = Local_Storage::get_game_settings_path() + ach["icon"].get<std::string>();
|
|
|
|
unsigned long long file_size = file_size_(file_path);
|
2023-11-12 23:09:17 +02:00
|
|
|
if (!file_size) {
|
|
|
|
file_path = Local_Storage::get_game_settings_path() + "achievement_images/" + ach["icon"].get<std::string>();
|
|
|
|
file_size = file_size_(file_path);
|
|
|
|
}
|
2023-11-10 17:25:36 +02:00
|
|
|
if (file_size) {
|
|
|
|
std::string img = Local_Storage::load_image_resized(file_path, "", settings->overlay_appearance.icon_size);
|
|
|
|
if (img.length() > 0) {
|
|
|
|
if (_renderer) notif.icon = _renderer->CreateImageResource((void*)img.c_str(), settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-21 06:58:55 +03:00
|
|
|
notif.message = ach["displayName"].get<std::string>() + "\n" + ach["description"].get<std::string>();
|
|
|
|
notif.start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch());
|
|
|
|
notifications.emplace_back(notif);
|
2024-01-26 05:49:03 +02:00
|
|
|
NotifySoundUserAchievement();
|
2023-08-21 06:58:55 +03:00
|
|
|
have_notifications = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PRINT_DEBUG("No more free id to create a notification window\n");
|
2019-11-08 15:52:38 +01:00
|
|
|
}
|
2022-08-05 02:09:43 -04:00
|
|
|
|
|
|
|
std::string ach_name = ach.value("name", "");
|
|
|
|
for (auto &a : achievements) {
|
|
|
|
if (a.name == ach_name) {
|
|
|
|
bool achieved = false;
|
|
|
|
uint32 unlock_time = 0;
|
|
|
|
get_steam_client()->steam_user_stats->GetAchievementAndUnlockTime(a.name.c_str(), &achieved, &unlock_time);
|
|
|
|
a.achieved = achieved;
|
|
|
|
a.unlock_time = unlock_time;
|
|
|
|
}
|
|
|
|
}
|
2019-11-08 15:52:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::AddInviteNotification(std::pair<const Friend, friend_window_state>& wnd_state)
|
|
|
|
{
|
2020-01-26 17:24:16 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
|
2023-12-19 22:17:29 +02:00
|
|
|
if (settings->disable_overlay_friend_notification) return;
|
2019-11-08 15:52:38 +01:00
|
|
|
int id = find_free_notification_id(notifications);
|
|
|
|
if (id != 0)
|
|
|
|
{
|
|
|
|
Notification notif;
|
|
|
|
notif.id = id;
|
|
|
|
notif.type = notification_type_invite;
|
|
|
|
notif.frd = &wnd_state;
|
2023-08-21 06:58:55 +03:00
|
|
|
|
2024-01-06 07:43:34 +02:00
|
|
|
{
|
|
|
|
char tmp[TRANSLATION_BUFFER_SIZE]{};
|
2024-01-22 01:23:21 +02:00
|
|
|
auto &first_friend = wnd_state.first;
|
|
|
|
auto &name = first_friend.name();
|
|
|
|
snprintf(tmp, sizeof(tmp), translationInvitedYouToJoinTheGame[current_language], name.c_str(), (uint64)first_friend.id());
|
2024-01-06 07:43:34 +02:00
|
|
|
notif.message = tmp;
|
|
|
|
}
|
2023-08-21 06:58:55 +03:00
|
|
|
|
2019-11-08 15:52:38 +01:00
|
|
|
notif.start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch());
|
|
|
|
notifications.emplace_back(notif);
|
2022-08-05 02:09:43 -04:00
|
|
|
have_notifications = true;
|
2019-11-08 15:52:38 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
PRINT_DEBUG("No more free id to create a notification window\n");
|
|
|
|
}
|
|
|
|
|
2024-01-06 07:41:32 +02:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-02 19:07:30 -05:00
|
|
|
bool Steam_Overlay::FriendJoinable(std::pair<const Friend, friend_window_state> &f)
|
2019-08-06 13:46:43 +02:00
|
|
|
{
|
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
|
2020-02-02 19:07:30 -05:00
|
|
|
if( std::string(steamFriends->GetFriendRichPresence(f.first.id(), "connect")).length() > 0 )
|
2019-08-06 13:46:43 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
FriendGameInfo_t friend_game_info = {};
|
2020-02-02 19:07:30 -05:00
|
|
|
steamFriends->GetFriendGamePlayed(f.first.id(), &friend_game_info);
|
|
|
|
if (friend_game_info.m_steamIDLobby.IsValid() && (f.second.window_state & window_state_lobby_invite))
|
2019-08-06 13:46:43 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Steam_Overlay::IHaveLobby()
|
|
|
|
{
|
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
if (std::string(steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect")).length() > 0)
|
|
|
|
return true;
|
2019-08-31 20:49:07 +02:00
|
|
|
|
2019-08-06 13:46:43 +02:00
|
|
|
if (settings->get_lobby().IsValid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-02 15:26:16 +02:00
|
|
|
void Steam_Overlay::BuildContextMenu(Friend const& frd, friend_window_state& state)
|
|
|
|
{
|
2024-01-23 01:44:32 +02:00
|
|
|
if (ImGui::BeginPopupContextItem("Friends_ContextMenu", 1)) {
|
2024-01-22 01:31:02 +02:00
|
|
|
// this is set to true if any button was clicked
|
|
|
|
// otherwise, after clicking any button, the menu will be persistent
|
2019-08-06 13:46:43 +02:00
|
|
|
bool close_popup = false;
|
|
|
|
|
2024-01-22 01:31:02 +02:00
|
|
|
// user clicked on "chat"
|
2024-01-23 01:44:32 +02:00
|
|
|
if (ImGui::Button(translationChat[current_language])) {
|
2019-08-06 13:46:43 +02:00
|
|
|
close_popup = true;
|
2024-01-22 01:31:02 +02:00
|
|
|
state.window_state |= window_state_show;
|
2019-08-06 13:46:43 +02:00
|
|
|
}
|
2024-01-23 01:44:32 +02:00
|
|
|
// user clicked on "copy id" on a friend
|
|
|
|
if (ImGui::Button(translationCopyId[current_language])) {
|
|
|
|
close_popup = true;
|
|
|
|
auto friend_id_str = std::to_string(frd.id());
|
|
|
|
ImGui::SetClipboardText(friend_id_str.c_str());
|
|
|
|
}
|
2019-10-14 16:35:36 +02:00
|
|
|
// If we have the same appid, activate the invite/join buttons
|
2024-01-23 01:44:32 +02:00
|
|
|
if (settings->get_local_game_id().AppID() == frd.appid()) {
|
2024-01-22 01:31:02 +02:00
|
|
|
// user clicked on "invite to game"
|
|
|
|
std::string translationInvite_tmp(translationInvite[current_language]);
|
|
|
|
translationInvite_tmp.append("##PopupInviteToGame");
|
2024-01-23 01:44:32 +02:00
|
|
|
if (i_have_lobby && ImGui::Button(translationInvite_tmp.c_str())) {
|
2024-01-22 01:31:02 +02:00
|
|
|
close_popup = true;
|
2019-10-14 16:35:36 +02:00
|
|
|
state.window_state |= window_state_invite;
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
}
|
2024-01-22 01:31:02 +02:00
|
|
|
|
|
|
|
// user clicked on "accept game invite"
|
|
|
|
std::string translationJoin_tmp(translationJoin[current_language]);
|
|
|
|
translationJoin_tmp.append("##PopupAcceptInvite");
|
|
|
|
|
2024-01-23 01:44:32 +02:00
|
|
|
if (state.joinable && ImGui::Button(translationJoin_tmp.c_str())) {
|
2019-10-14 16:35:36 +02:00
|
|
|
close_popup = true;
|
2024-01-22 01:31:02 +02:00
|
|
|
// don't bother adding this friend if the button "invite all" was clicked
|
|
|
|
// we will send them the invitation later in Steam_Overlay::RunCallbacks()
|
|
|
|
if (!invite_all_friends_clicked) {
|
|
|
|
state.window_state |= window_state_join;
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
}
|
2019-10-14 16:35:36 +02:00
|
|
|
}
|
2019-08-02 15:26:16 +02:00
|
|
|
}
|
2024-01-22 01:31:02 +02:00
|
|
|
|
2024-01-23 01:44:32 +02:00
|
|
|
if (close_popup || invite_all_friends_clicked) {
|
2019-08-06 13:46:43 +02:00
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
2019-08-02 15:26:16 +02:00
|
|
|
ImGui::EndPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::BuildFriendWindow(Friend const& frd, friend_window_state& state)
|
|
|
|
{
|
|
|
|
if (!(state.window_state & window_state_show))
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool show = true;
|
2019-08-06 13:46:43 +02:00
|
|
|
bool send_chat_msg = false;
|
2019-08-03 12:58:48 +02:00
|
|
|
|
2019-10-11 13:10:48 +02:00
|
|
|
float width = ImGui::CalcTextSize("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").x;
|
|
|
|
|
|
|
|
if (state.window_state & window_state_need_attention && ImGui::IsWindowFocused())
|
|
|
|
{
|
|
|
|
state.window_state &= ~window_state_need_attention;
|
|
|
|
}
|
2021-01-17 22:58:42 -05:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2{ width, ImGui::GetFontSize()*8 + ImGui::GetFrameHeightWithSpacing()*4 },
|
2019-10-11 13:10:48 +02:00
|
|
|
ImVec2{ std::numeric_limits<float>::max() , std::numeric_limits<float>::max() });
|
|
|
|
|
|
|
|
// Window id is after the ###, the window title is the friend name
|
2019-10-14 16:35:36 +02:00
|
|
|
std::string friend_window_id = std::move("###" + std::to_string(state.id));
|
|
|
|
if (ImGui::Begin((state.window_title + friend_window_id).c_str(), &show))
|
2019-08-02 15:26:16 +02:00
|
|
|
{
|
2019-08-16 18:31:56 +02:00
|
|
|
if (state.window_state & window_state_need_attention && ImGui::IsWindowFocused())
|
|
|
|
{
|
|
|
|
state.window_state &= ~window_state_need_attention;
|
|
|
|
}
|
|
|
|
|
2019-08-02 15:26:16 +02:00
|
|
|
// Fill this with the chat box and maybe the invitation
|
|
|
|
if (state.window_state & (window_state_lobby_invite | window_state_rich_invite))
|
|
|
|
{
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::LabelText("##label", translationInvitedYouToJoinTheGame[current_language], frd.name().c_str(), frd.appid());
|
2019-08-02 15:26:16 +02:00
|
|
|
ImGui::SameLine();
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Button(translationAccept[current_language]))
|
2019-08-02 15:26:16 +02:00
|
|
|
{
|
2020-02-02 19:07:30 -05:00
|
|
|
state.window_state |= window_state_join;
|
2019-08-02 15:26:16 +02:00
|
|
|
this->has_friend_action.push(frd);
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Button(translationRefuse[current_language]))
|
2019-08-02 15:26:16 +02:00
|
|
|
{
|
|
|
|
state.window_state &= ~(window_state_lobby_invite | window_state_rich_invite);
|
|
|
|
}
|
|
|
|
}
|
2019-08-03 12:58:48 +02:00
|
|
|
|
2022-09-03 04:13:58 -04:00
|
|
|
ImGui::InputTextMultiline("##chat_history", &state.chat_history[0], state.chat_history.length(), { -1.0f, -2.0f * ImGui::GetFontSize() }, ImGuiInputTextFlags_ReadOnly);
|
2019-08-14 14:56:57 +02:00
|
|
|
// TODO: Fix the layout of the chat line + send button.
|
|
|
|
// It should be like this: chat input should fill the window size minus send button size (button size is fixed)
|
|
|
|
// |------------------------------|
|
|
|
|
// | /--------------------------\ |
|
|
|
|
// | | | |
|
|
|
|
// | | chat history | |
|
|
|
|
// | | | |
|
|
|
|
// | \--------------------------/ |
|
|
|
|
// | [____chat line______] [send] |
|
|
|
|
// |------------------------------|
|
|
|
|
//
|
|
|
|
// And it is like this
|
|
|
|
// |------------------------------|
|
|
|
|
// | /--------------------------\ |
|
|
|
|
// | | | |
|
|
|
|
// | | chat history | |
|
|
|
|
// | | | |
|
|
|
|
// | \--------------------------/ |
|
|
|
|
// | [__chat line__] [send] |
|
|
|
|
// |------------------------------|
|
2019-10-11 13:10:48 +02:00
|
|
|
float wnd_width = ImGui::GetWindowContentRegionWidth();
|
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
2023-08-21 06:58:55 +03:00
|
|
|
wnd_width -= ImGui::CalcTextSize(translationSend[current_language]).x + style.FramePadding.x * 2 + style.ItemSpacing.x + 1;
|
2019-10-11 13:10:48 +02:00
|
|
|
|
2024-01-23 01:44:32 +02:00
|
|
|
uint64_t frd_id = frd.id();
|
|
|
|
ImGui::PushID((const char *)&frd_id, (const char *)&frd_id + sizeof(frd_id));
|
2019-10-11 13:10:48 +02:00
|
|
|
ImGui::PushItemWidth(wnd_width);
|
2024-01-23 01:44:32 +02:00
|
|
|
|
2019-08-03 12:58:48 +02:00
|
|
|
if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
{
|
2019-08-06 13:46:43 +02:00
|
|
|
send_chat_msg = true;
|
2022-09-03 04:13:58 -04:00
|
|
|
ImGui::SetKeyboardFocusHere(-1);
|
2019-08-03 12:58:48 +02:00
|
|
|
}
|
2019-10-11 13:10:48 +02:00
|
|
|
ImGui::PopItemWidth();
|
2024-01-23 01:44:32 +02:00
|
|
|
ImGui::PopID();
|
2019-08-03 12:58:48 +02:00
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Button(translationSend[current_language]))
|
2019-08-06 13:46:43 +02:00
|
|
|
{
|
|
|
|
send_chat_msg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (send_chat_msg)
|
2019-08-03 12:58:48 +02:00
|
|
|
{
|
|
|
|
if (!(state.window_state & window_state_send_message))
|
|
|
|
{
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
state.window_state |= window_state_send_message;
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 15:26:16 +02:00
|
|
|
}
|
|
|
|
// User closed the friend window
|
|
|
|
if (!show)
|
|
|
|
state.window_state &= ~window_state_show;
|
2019-08-06 13:46:43 +02:00
|
|
|
|
2019-08-02 15:26:16 +02:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2019-09-05 09:00:02 +02:00
|
|
|
ImFont *font_default;
|
|
|
|
ImFont *font_notif;
|
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
// set the position of the next notification
|
|
|
|
void Steam_Overlay::SetNextNotificationPos(float width, float height, float font_size, notification_type type, struct NotificationsIndexes &idx)
|
|
|
|
{
|
|
|
|
// 0 on the y-axis is top, 0 on the x-axis is left
|
|
|
|
|
|
|
|
// get the required position
|
|
|
|
Overlay_Appearance::NotificationPosition pos = Overlay_Appearance::default_pos;
|
|
|
|
switch (type) {
|
|
|
|
case notification_type::notification_type_achievement: pos = settings->overlay_appearance.ach_earned_pos; break;
|
|
|
|
case notification_type::notification_type_invite: pos = settings->overlay_appearance.invite_pos; break;
|
|
|
|
case notification_type::notification_type_message: pos = settings->overlay_appearance.chat_msg_pos; break;
|
|
|
|
default: /* satisfy compiler warning */ break;
|
|
|
|
}
|
|
|
|
|
|
|
|
float x = 0.0f;
|
|
|
|
float y = 0.0f;
|
|
|
|
const float noti_width = width * Notification::width_percent;
|
|
|
|
const float noti_height = Notification::height * font_size;
|
|
|
|
switch (pos) {
|
|
|
|
// top
|
|
|
|
case Overlay_Appearance::NotificationPosition::top_left:
|
|
|
|
x = 0.0f;
|
|
|
|
y = noti_height * idx.top_left;
|
|
|
|
++idx.top_left;
|
|
|
|
break;
|
|
|
|
case Overlay_Appearance::NotificationPosition::top_center:
|
|
|
|
x = (width / 2) - (noti_width / 2);
|
|
|
|
y = noti_height * idx.top_center;
|
|
|
|
++idx.top_center;
|
|
|
|
break;
|
|
|
|
case Overlay_Appearance::NotificationPosition::top_right:
|
|
|
|
x = width - noti_width;
|
|
|
|
y = noti_height * idx.top_right;
|
|
|
|
++idx.top_right;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// bot
|
|
|
|
case Overlay_Appearance::NotificationPosition::bot_left:
|
|
|
|
x = 0.0f;
|
|
|
|
y = height - noti_height * (idx.bot_left + 1);
|
|
|
|
++idx.bot_left;
|
|
|
|
break;
|
|
|
|
case Overlay_Appearance::NotificationPosition::bot_center:
|
|
|
|
x = (width / 2) - (noti_width / 2);
|
|
|
|
y = height - noti_height * (idx.bot_center + 1);
|
|
|
|
++idx.bot_center;
|
|
|
|
break;
|
|
|
|
case Overlay_Appearance::NotificationPosition::bot_right:
|
|
|
|
x = width - noti_width;
|
|
|
|
y = height - noti_height * (idx.bot_right + 1);
|
|
|
|
++idx.bot_right;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* satisfy compiler warning */ break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2( x, y ));
|
|
|
|
}
|
|
|
|
|
2019-09-04 19:31:31 +02:00
|
|
|
void Steam_Overlay::BuildNotifications(int width, int height)
|
2019-08-26 19:36:07 +02:00
|
|
|
{
|
2019-09-04 19:31:31 +02:00
|
|
|
auto now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
2019-09-05 09:00:02 +02:00
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
float font_size = ImGui::GetFontSize();
|
2019-09-05 09:00:02 +02:00
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
std::queue<Friend> friend_actions_temp{};
|
2020-01-26 09:46:57 -05:00
|
|
|
|
2019-09-04 19:31:31 +02:00
|
|
|
{
|
2020-01-26 17:24:16 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
|
2019-09-04 19:31:31 +02:00
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
NotificationsIndexes idx{};
|
|
|
|
for (auto it = notifications.begin(); it != notifications.end(); ++it)
|
2019-09-04 19:31:31 +02:00
|
|
|
{
|
2020-01-26 17:24:16 -05:00
|
|
|
auto elapsed_notif = now - it->start_time;
|
2019-09-04 19:31:31 +02:00
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
if ( elapsed_notif < Notification::fade_in) {
|
2023-11-12 23:09:17 +02:00
|
|
|
float alpha = settings->overlay_appearance.notification_a * (elapsed_notif.count() / static_cast<float>(Notification::fade_in.count()));
|
2020-01-26 17:24:16 -05:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, alpha));
|
2023-11-12 23:09:17 +02:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(settings->overlay_appearance.notification_r, settings->overlay_appearance.notification_g, settings->overlay_appearance.notification_b, alpha));
|
2020-01-26 17:24:16 -05:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, alpha*2));
|
|
|
|
}
|
2024-01-26 05:49:03 +02:00
|
|
|
else if ( elapsed_notif > Notification::fade_out_start) {
|
2023-11-12 23:09:17 +02:00
|
|
|
float alpha = settings->overlay_appearance.notification_a * ((Notification::show_time - elapsed_notif).count() / static_cast<float>(Notification::fade_out.count()));
|
2020-01-26 17:24:16 -05:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, alpha));
|
2023-11-12 23:09:17 +02:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(settings->overlay_appearance.notification_r, settings->overlay_appearance.notification_g, settings->overlay_appearance.notification_b, alpha));
|
2020-01-26 17:24:16 -05:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, alpha*2));
|
2024-01-26 05:49:03 +02:00
|
|
|
} else {
|
2023-11-12 23:09:17 +02:00
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, settings->overlay_appearance.notification_a));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(settings->overlay_appearance.notification_r, settings->overlay_appearance.notification_g, settings->overlay_appearance.notification_b, settings->overlay_appearance.notification_a));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, settings->overlay_appearance.notification_a*2));
|
2020-01-26 17:24:16 -05:00
|
|
|
}
|
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
SetNextNotificationPos(width, height, font_size, (notification_type)it->type, idx);
|
|
|
|
ImGui::SetNextWindowSize(ImVec2( width * Notification::width_percent, Notification::height * font_size ));
|
|
|
|
std::string wnd_name = "NotiPopupShow" + std::to_string(it->id);
|
|
|
|
ImGui::Begin(wnd_name.c_str(), nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus |
|
2020-01-26 17:24:16 -05:00
|
|
|
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoDecoration);
|
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
switch (it->type) {
|
2020-01-26 17:24:16 -05:00
|
|
|
case notification_type_achievement:
|
2024-01-26 05:49:03 +02:00
|
|
|
{
|
|
|
|
if (!it->icon.expired()) {
|
|
|
|
ImGui::BeginTable("imgui_table", 2);
|
|
|
|
ImGui::TableSetupColumn("imgui_table_image", ImGuiTableColumnFlags_WidthFixed, settings->overlay_appearance.icon_size);
|
|
|
|
ImGui::TableSetupColumn("imgui_table_text");
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, settings->overlay_appearance.icon_size);
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
ImGui::TableSetColumnIndex(0);
|
|
|
|
ImGui::Image((ImU64)*it->icon.lock().get(), ImVec2(settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size));
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2024-01-26 05:49:03 +02:00
|
|
|
ImGui::EndTable();
|
|
|
|
} else {
|
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
2023-11-10 17:25:36 +02:00
|
|
|
}
|
2024-01-26 05:49:03 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-01-26 17:24:16 -05:00
|
|
|
case notification_type_invite:
|
2024-01-26 05:49:03 +02:00
|
|
|
{
|
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
|
|
|
if (ImGui::Button(translationJoin[current_language]))
|
2019-11-08 15:52:38 +01:00
|
|
|
{
|
2024-01-26 05:49:03 +02:00
|
|
|
it->frd->second.window_state |= window_state_join;
|
|
|
|
friend_actions_temp.push(it->frd->first);
|
|
|
|
it->start_time = std::chrono::seconds(0);
|
2019-11-08 15:52:38 +01:00
|
|
|
}
|
2024-01-26 05:49:03 +02:00
|
|
|
}
|
|
|
|
break;
|
2020-01-26 17:24:16 -05:00
|
|
|
case notification_type_message:
|
2024-01-26 05:49:03 +02:00
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
|
|
|
break;
|
2024-01-06 07:41:32 +02:00
|
|
|
case notification_type_auto_accept_invite:
|
2024-01-26 05:49:03 +02:00
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
|
|
|
break;
|
2020-01-26 17:24:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::End();
|
2019-09-04 19:31:31 +02:00
|
|
|
|
2020-01-26 17:24:16 -05:00
|
|
|
ImGui::PopStyleColor(3);
|
|
|
|
}
|
|
|
|
notifications.erase(std::remove_if(notifications.begin(), notifications.end(), [&now](Notification &item) {
|
|
|
|
return (now - item.start_time) > Notification::show_time;
|
|
|
|
}), notifications.end());
|
2022-08-05 02:09:43 -04:00
|
|
|
|
|
|
|
have_notifications = !notifications.empty();
|
2020-01-26 17:24:16 -05:00
|
|
|
}
|
2019-09-04 19:31:31 +02:00
|
|
|
|
2020-01-26 17:24:16 -05:00
|
|
|
if (!friend_actions_temp.empty()) {
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
|
|
|
while (!friend_actions_temp.empty()) {
|
|
|
|
has_friend_action.push(friend_actions_temp.front());
|
|
|
|
friend_actions_temp.pop();
|
|
|
|
}
|
2019-09-04 19:31:31 +02:00
|
|
|
}
|
2019-08-26 19:36:07 +02:00
|
|
|
}
|
|
|
|
|
2019-09-05 09:00:02 +02:00
|
|
|
void Steam_Overlay::CreateFonts()
|
|
|
|
{
|
2022-08-21 03:45:11 -04:00
|
|
|
if (fonts_atlas) return;
|
|
|
|
|
|
|
|
ImFontAtlas *Fonts = new ImFontAtlas();
|
2022-08-13 14:35:59 -04:00
|
|
|
|
2019-09-05 09:00:02 +02:00
|
|
|
ImFontConfig fontcfg;
|
|
|
|
|
2023-08-24 20:59:01 +03:00
|
|
|
float font_size = settings->overlay_appearance.font_size;
|
2019-09-05 09:00:02 +02:00
|
|
|
fontcfg.OversampleH = fontcfg.OversampleV = 1;
|
|
|
|
fontcfg.PixelSnapH = true;
|
2022-08-13 14:35:59 -04:00
|
|
|
fontcfg.SizePixels = font_size;
|
|
|
|
|
|
|
|
ImFontGlyphRangesBuilder font_builder;
|
|
|
|
for (auto & x : achievements) {
|
|
|
|
font_builder.AddText(x.title.c_str());
|
|
|
|
font_builder.AddText(x.description.c_str());
|
|
|
|
}
|
2023-08-21 06:58:55 +03:00
|
|
|
for (int i = 0; i < TRANSLATION_NUMBER_OF_LANGUAGES; i++) {
|
|
|
|
font_builder.AddText(translationChat[i]);
|
|
|
|
font_builder.AddText(translationInvite[i]);
|
|
|
|
font_builder.AddText(translationJoin[i]);
|
|
|
|
font_builder.AddText(translationInvitedYouToJoinTheGame[i]);
|
|
|
|
font_builder.AddText(translationAccept[i]);
|
|
|
|
font_builder.AddText(translationRefuse[i]);
|
|
|
|
font_builder.AddText(translationSend[i]);
|
|
|
|
font_builder.AddText(translationSteamOverlay[i]);
|
|
|
|
font_builder.AddText(translationUserPlaying[i]);
|
|
|
|
font_builder.AddText(translationRenderer[i]);
|
|
|
|
font_builder.AddText(translationShowAchievements[i]);
|
|
|
|
font_builder.AddText(translationSettings[i]);
|
|
|
|
font_builder.AddText(translationFriends[i]);
|
|
|
|
font_builder.AddText(translationAchievementWindow[i]);
|
|
|
|
font_builder.AddText(translationListOfAchievements[i]);
|
|
|
|
font_builder.AddText(translationAchievements[i]);
|
|
|
|
font_builder.AddText(translationHiddenAchievement[i]);
|
|
|
|
font_builder.AddText(translationAchievedOn[i]);
|
|
|
|
font_builder.AddText(translationNotAchieved[i]);
|
|
|
|
font_builder.AddText(translationGlobalSettingsWindow[i]);
|
|
|
|
font_builder.AddText(translationGlobalSettingsWindowDescription[i]);
|
|
|
|
font_builder.AddText(translationUsername[i]);
|
|
|
|
font_builder.AddText(translationLanguage[i]);
|
|
|
|
font_builder.AddText(translationSelectedLanguage[i]);
|
|
|
|
font_builder.AddText(translationRestartTheGameToApply[i]);
|
|
|
|
font_builder.AddText(translationSave[i]);
|
|
|
|
font_builder.AddText(translationWarning[i]);
|
|
|
|
font_builder.AddText(translationWarningWarningWarning[i]);
|
|
|
|
font_builder.AddText(translationWarningDescription1[i]);
|
|
|
|
font_builder.AddText(translationWarningDescription2[i]);
|
|
|
|
font_builder.AddText(translationWarningDescription3[i]);
|
|
|
|
font_builder.AddText(translationWarningDescription4[i]);
|
|
|
|
font_builder.AddText(translationSteamOverlayURL[i]);
|
|
|
|
font_builder.AddText(translationClose[i]);
|
|
|
|
font_builder.AddText(translationPlaying[i]);
|
|
|
|
}
|
2022-08-13 14:35:59 -04:00
|
|
|
|
2022-08-21 03:45:11 -04:00
|
|
|
font_builder.AddRanges(Fonts->GetGlyphRangesDefault());
|
2019-09-05 09:00:02 +02:00
|
|
|
|
2022-08-13 14:35:59 -04:00
|
|
|
ImVector<ImWchar> ranges;
|
|
|
|
font_builder.BuildRanges(&ranges);
|
|
|
|
|
|
|
|
bool need_extra_fonts = false;
|
|
|
|
for (auto &x : ranges) {
|
|
|
|
if (x > 0xFF) {
|
|
|
|
need_extra_fonts = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fontcfg.GlyphRanges = ranges.Data;
|
|
|
|
ImFont *font = NULL;
|
|
|
|
|
|
|
|
#if defined(__WINDOWS__)
|
2022-08-21 03:45:11 -04:00
|
|
|
font = Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\micross.ttf", font_size, &fontcfg);
|
2022-08-13 14:35:59 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!font) {
|
2022-08-21 03:45:11 -04:00
|
|
|
font = Fonts->AddFontDefault(&fontcfg);
|
2022-08-13 14:35:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
font_notif = font_default = font;
|
|
|
|
|
|
|
|
if (need_extra_fonts) {
|
|
|
|
PRINT_DEBUG("loading extra fonts\n");
|
|
|
|
fontcfg.MergeMode = true;
|
|
|
|
#if defined(__WINDOWS__)
|
2022-08-21 03:45:11 -04:00
|
|
|
Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\simsun.ttc", font_size, &fontcfg);
|
|
|
|
Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\malgun.ttf", font_size, &fontcfg);
|
2022-08-13 14:35:59 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-21 03:45:11 -04:00
|
|
|
Fonts->Build();
|
|
|
|
fonts_atlas = (void *)Fonts;
|
2019-09-05 09:00:02 +02:00
|
|
|
|
2022-08-21 03:45:11 -04:00
|
|
|
// ImGuiStyle& style = ImGui::GetStyle();
|
|
|
|
// style.WindowRounding = 0.0; // Disable round window
|
2022-08-13 14:35:59 -04:00
|
|
|
reset_LastError();
|
2019-09-05 09:00:02 +02:00
|
|
|
}
|
|
|
|
|
2023-11-10 17:25:36 +02:00
|
|
|
void Steam_Overlay::LoadAudio()
|
|
|
|
{
|
|
|
|
std::string file_path;
|
|
|
|
std::string file_name;
|
|
|
|
unsigned long long file_size;
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
if (i == 0) file_name = "overlay_achievement_notification.wav";
|
|
|
|
if (i == 1) file_name = "overlay_friend_notification.wav";
|
|
|
|
|
|
|
|
file_path = Local_Storage::get_game_settings_path() + file_name;
|
|
|
|
file_size = file_size_(file_path);
|
|
|
|
if (!file_size) {
|
|
|
|
if (settings->local_save.length() > 0) {
|
|
|
|
file_path = settings->local_save + "/settings/" + file_name;
|
|
|
|
} else {
|
|
|
|
file_path = Local_Storage::get_user_appdata_path() + "/settings/" + file_name;
|
|
|
|
}
|
|
|
|
file_size = file_size_(file_path);
|
|
|
|
}
|
|
|
|
if (file_size) {
|
|
|
|
std::ifstream myfile;
|
|
|
|
myfile.open(utf8_decode(file_path), std::ios::binary | std::ios::in);
|
|
|
|
if (myfile.is_open()) {
|
|
|
|
myfile.seekg (0, myfile.end);
|
|
|
|
int length = myfile.tellg();
|
|
|
|
myfile.seekg (0, myfile.beg);
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
notif_achievement_wav_custom = new char [length];
|
|
|
|
myfile.read (notif_achievement_wav_custom, length);
|
|
|
|
notif_achievement_wav_custom_inuse = true;
|
|
|
|
}
|
|
|
|
if (i == 1) {
|
|
|
|
notif_invite_wav_custom = new char [length];
|
|
|
|
myfile.read (notif_invite_wav_custom, length);
|
|
|
|
notif_invite_wav_custom_inuse = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
myfile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 14:56:57 +02:00
|
|
|
// Try to make this function as short as possible or it might affect game's fps.
|
2019-09-05 09:00:02 +02:00
|
|
|
void Steam_Overlay::OverlayProc()
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2019-08-16 10:37:45 +02:00
|
|
|
if (!Ready())
|
|
|
|
return;
|
|
|
|
|
2019-09-05 09:00:02 +02:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
if (have_notifications) {
|
|
|
|
ImGui::PushFont(font_notif);
|
|
|
|
BuildNotifications(io.DisplaySize.x, io.DisplaySize.y);
|
|
|
|
ImGui::PopFont();
|
|
|
|
}
|
2019-09-04 19:31:31 +02:00
|
|
|
|
2019-08-14 14:56:57 +02:00
|
|
|
if (show_overlay)
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2020-02-14 15:03:20 -05:00
|
|
|
io.ConfigFlags &= ~ImGuiConfigFlags_NoMouseCursorChange;
|
2019-08-14 14:56:57 +02:00
|
|
|
// Set the overlay windows to the size of the game window
|
|
|
|
ImGui::SetNextWindowPos({ 0,0 });
|
2019-09-05 09:00:02 +02:00
|
|
|
ImGui::SetNextWindowSize({ static_cast<float>(io.DisplaySize.x),
|
|
|
|
static_cast<float>(io.DisplaySize.y) });
|
2019-07-31 22:21:02 +02:00
|
|
|
|
2019-08-14 14:56:57 +02:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.50);
|
2019-09-05 09:00:02 +02:00
|
|
|
|
|
|
|
ImGui::PushFont(font_default);
|
2019-07-31 22:21:02 +02:00
|
|
|
|
2019-10-11 06:45:27 +02:00
|
|
|
bool show = true;
|
2019-10-11 00:25:44 +02:00
|
|
|
|
2024-01-06 07:43:34 +02:00
|
|
|
char tmp[TRANSLATION_BUFFER_SIZE]{};
|
2023-11-10 17:25:36 +02:00
|
|
|
snprintf(tmp, sizeof(tmp), translationRenderer[current_language], (_renderer == nullptr ? "Unknown" : _renderer->GetLibraryName().c_str()));
|
|
|
|
std::string windowTitle;
|
|
|
|
windowTitle.append(translationSteamOverlay[current_language]);
|
|
|
|
windowTitle.append(" (");
|
|
|
|
windowTitle.append(tmp);
|
|
|
|
windowTitle.append(")");
|
|
|
|
|
2023-11-12 23:09:17 +02:00
|
|
|
if ((settings->overlay_appearance.background_r != -1.0) && (settings->overlay_appearance.background_g != -1.0) && (settings->overlay_appearance.background_b != -1.0) && (settings->overlay_appearance.background_a != -1.0)) {
|
|
|
|
ImVec4 colorSet = ImVec4(settings->overlay_appearance.background_r, settings->overlay_appearance.background_g, settings->overlay_appearance.background_b, settings->overlay_appearance.background_a);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, colorSet);
|
|
|
|
}
|
|
|
|
if ((settings->overlay_appearance.element_r != -1.0) && (settings->overlay_appearance.element_g != -1.0) && (settings->overlay_appearance.element_b != -1.0) && (settings->overlay_appearance.element_a != -1.0)) {
|
|
|
|
ImVec4 colorSet = ImVec4(settings->overlay_appearance.element_r, settings->overlay_appearance.element_g, settings->overlay_appearance.element_b, settings->overlay_appearance.element_a);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_TitleBgActive, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Button, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBg, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ResizeGrip, colorSet);
|
|
|
|
}
|
|
|
|
if ((settings->overlay_appearance.element_hovered_r != -1.0) && (settings->overlay_appearance.element_hovered_g != -1.0) && (settings->overlay_appearance.element_hovered_b != -1.0) && (settings->overlay_appearance.element_hovered_a != -1.0)) {
|
|
|
|
ImVec4 colorSet = ImVec4(settings->overlay_appearance.element_hovered_r, settings->overlay_appearance.element_hovered_g, settings->overlay_appearance.element_hovered_b, settings->overlay_appearance.element_hovered_a);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ResizeGripHovered, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, colorSet);
|
|
|
|
}
|
|
|
|
if ((settings->overlay_appearance.element_active_r != -1.0) && (settings->overlay_appearance.element_active_g != -1.0) && (settings->overlay_appearance.element_active_b != -1.0) && (settings->overlay_appearance.element_active_a != -1.0)) {
|
|
|
|
ImVec4 colorSet = ImVec4(settings->overlay_appearance.element_active_r, settings->overlay_appearance.element_active_g, settings->overlay_appearance.element_active_b, settings->overlay_appearance.element_active_a);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_FrameBgActive, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_ResizeGripActive, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Header, colorSet);
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_HeaderActive, colorSet);
|
|
|
|
}
|
|
|
|
|
2023-11-10 17:25:36 +02:00
|
|
|
if (ImGui::Begin(windowTitle.c_str(), &show, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus))
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::LabelText("##label", translationUserPlaying[current_language],
|
2019-08-14 14:56:57 +02:00
|
|
|
settings->get_local_name(),
|
|
|
|
settings->get_local_steam_id().ConvertToUint64(),
|
|
|
|
settings->get_local_game_id().AppID());
|
2022-08-05 02:09:43 -04:00
|
|
|
|
2024-01-23 01:44:32 +02:00
|
|
|
ImGui::SameLine();
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGui::Spacing();
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Button(translationShowAchievements[current_language])) {
|
2022-08-05 02:09:43 -04:00
|
|
|
show_achievements = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Button(translationSettings[current_language])) {
|
2022-08-05 02:09:43 -04:00
|
|
|
show_settings = true;
|
|
|
|
}
|
2024-01-23 01:44:32 +02:00
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
// user clicked on "copy id" on themselves
|
|
|
|
if (ImGui::Button(translationCopyId[current_language])) {
|
|
|
|
auto friend_id_str = std::to_string(settings->get_local_steam_id().ConvertToUint64());
|
|
|
|
ImGui::SetClipboardText(friend_id_str.c_str());
|
|
|
|
}
|
|
|
|
|
2019-08-02 15:26:16 +02:00
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGui::Spacing();
|
2019-08-14 14:56:57 +02:00
|
|
|
ImGui::Spacing();
|
|
|
|
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::LabelText("##label", translationFriends[current_language]);
|
2020-01-26 09:46:57 -05:00
|
|
|
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-16 18:31:56 +02:00
|
|
|
if (!friends.empty())
|
2019-08-02 11:16:30 +02:00
|
|
|
{
|
2024-01-22 01:31:02 +02:00
|
|
|
if (i_have_lobby) {
|
|
|
|
std::string inviteAll(translationInviteAll[current_language]);
|
|
|
|
inviteAll.append("##PopupInviteAllFriends");
|
|
|
|
if (ImGui::Button(inviteAll.c_str())) { // if btn clicked
|
|
|
|
invite_all_friends_clicked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-09 10:11:35 +02:00
|
|
|
if (ImGui::ListBoxHeader("##label", friends.size()))
|
2019-08-14 14:56:57 +02:00
|
|
|
{
|
2021-05-09 10:11:35 +02:00
|
|
|
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i)
|
2019-08-16 18:31:56 +02:00
|
|
|
{
|
2021-05-09 10:11:35 +02:00
|
|
|
ImGui::PushID(i.second.id-base_friend_window_id+base_friend_item_id);
|
|
|
|
|
|
|
|
ImGui::Selectable(i.second.window_title.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick);
|
|
|
|
BuildContextMenu(i.first, i.second);
|
|
|
|
if (ImGui::IsItemClicked() && ImGui::IsMouseDoubleClicked(0))
|
|
|
|
{
|
|
|
|
i.second.window_state |= window_state_show;
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
2019-08-16 18:31:56 +02:00
|
|
|
|
2021-05-09 10:11:35 +02:00
|
|
|
BuildFriendWindow(i.first, i.second);
|
|
|
|
});
|
|
|
|
ImGui::ListBoxFooter();
|
|
|
|
}
|
2019-08-16 18:31:56 +02:00
|
|
|
}
|
2022-08-05 02:09:43 -04:00
|
|
|
|
2024-01-24 02:21:09 +02:00
|
|
|
if (show_achievements && achievements.size()) { // display achievements list when the button "show achievements" is pressed
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(ImGui::GetFontSize() * 32, ImGui::GetFontSize() * 32), ImVec2(8192, 8192));
|
|
|
|
bool show = show_achievements;
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Begin(translationAchievementWindow[current_language], &show)) {
|
|
|
|
ImGui::Text(translationListOfAchievements[current_language]);
|
|
|
|
ImGui::BeginChild(translationAchievements[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
for (auto & x : achievements) {
|
|
|
|
bool achieved = x.achieved;
|
|
|
|
bool hidden = x.hidden && !achieved;
|
|
|
|
|
2023-11-10 17:25:36 +02:00
|
|
|
if (x.icon.expired()) {
|
|
|
|
std::string file_path = Local_Storage::get_game_settings_path() + x.icon_name;
|
|
|
|
unsigned long long file_size = file_size_(file_path);
|
2023-11-12 23:09:17 +02:00
|
|
|
if (!file_size) {
|
|
|
|
file_path = Local_Storage::get_game_settings_path() + "achievement_images/" + x.icon_name;
|
|
|
|
file_size = file_size_(file_path);
|
|
|
|
}
|
2023-11-10 17:25:36 +02:00
|
|
|
if (file_size) {
|
|
|
|
std::string img = Local_Storage::load_image_resized(file_path, "", settings->overlay_appearance.icon_size);
|
|
|
|
if (img.length() > 0) {
|
|
|
|
if (_renderer) x.icon = _renderer->CreateImageResource((void*)img.c_str(), settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-12 23:09:17 +02:00
|
|
|
if (x.icon_gray.expired()) {
|
|
|
|
std::string file_path = Local_Storage::get_game_settings_path() + x.icon_gray_name;
|
|
|
|
unsigned long long file_size = file_size_(file_path);
|
|
|
|
if (!file_size) {
|
|
|
|
file_path = Local_Storage::get_game_settings_path() + "achievement_images/" + x.icon_gray_name;
|
|
|
|
file_size = file_size_(file_path);
|
|
|
|
}
|
|
|
|
if (file_size) {
|
|
|
|
std::string img = Local_Storage::load_image_resized(file_path, "", settings->overlay_appearance.icon_size);
|
|
|
|
if (img.length() > 0) {
|
|
|
|
if (_renderer) x.icon_gray = _renderer->CreateImageResource((void*)img.c_str(), settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGui::Separator();
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2023-11-12 23:09:17 +02:00
|
|
|
if (!x.icon.expired() && !x.icon_gray.expired()) {
|
2023-11-10 17:25:36 +02:00
|
|
|
ImGui::BeginTable(x.title.c_str(), 2);
|
|
|
|
ImGui::TableSetupColumn("imgui_table_image", ImGuiTableColumnFlags_WidthFixed, settings->overlay_appearance.icon_size);
|
|
|
|
ImGui::TableSetupColumn("imgui_table_text");
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_None, settings->overlay_appearance.icon_size);
|
|
|
|
|
|
|
|
ImGui::TableSetColumnIndex(0);
|
2023-11-12 23:09:17 +02:00
|
|
|
if (achieved) {
|
|
|
|
ImGui::Image((ImU64)*x.icon.lock().get(), ImVec2(settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size));
|
|
|
|
} else {
|
|
|
|
ImGui::Image((ImU64)*x.icon_gray.lock().get(), ImVec2(settings->overlay_appearance.icon_size, settings->overlay_appearance.icon_size));
|
|
|
|
}
|
2023-11-10 17:25:36 +02:00
|
|
|
|
|
|
|
ImGui::TableSetColumnIndex(1);
|
|
|
|
ImGui::Text("%s", x.title.c_str());
|
|
|
|
} else {
|
|
|
|
ImGui::Text("%s", x.title.c_str());
|
|
|
|
}
|
|
|
|
|
2022-08-06 05:23:49 -04:00
|
|
|
if (hidden) {
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::Text(translationHiddenAchievement[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
} else {
|
2022-08-05 18:45:33 -04:00
|
|
|
ImGui::TextWrapped("%s", x.description.c_str());
|
2022-08-05 02:09:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (achieved) {
|
|
|
|
char buffer[80] = {};
|
|
|
|
time_t unlock_time = (time_t)x.unlock_time;
|
|
|
|
std::strftime(buffer, 80, "%Y-%m-%d at %H:%M:%S", std::localtime(&unlock_time));
|
|
|
|
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::TextColored(ImVec4(0, 255, 0, 255), translationAchievedOn[current_language], buffer);
|
2022-08-05 02:09:43 -04:00
|
|
|
} else {
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationNotAchieved[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
}
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2023-11-12 23:09:17 +02:00
|
|
|
if (!x.icon.expired() && !x.icon_gray.expired()) ImGui::EndTable();
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGui::Separator();
|
|
|
|
}
|
|
|
|
ImGui::EndChild();
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
show_achievements = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_settings) {
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Begin(translationGlobalSettingsWindow[current_language], &show_settings)) {
|
|
|
|
ImGui::Text(translationGlobalSettingsWindowDescription[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::Text(translationUsername[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGui::SameLine();
|
2023-12-29 03:55:11 +02:00
|
|
|
ImGui::InputText("##username", username_text, sizeof(username_text), disable_user_input ? ImGuiInputTextFlags_ReadOnly : 0);
|
2022-08-05 02:09:43 -04:00
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::Text(translationLanguage[current_language]);
|
2023-12-29 03:55:11 +02:00
|
|
|
ImGui::ListBox("##language", ¤t_language, valid_languages, sizeof(valid_languages) / sizeof(char *), 7);
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::Text(translationSelectedLanguage[current_language], valid_languages[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
|
|
|
|
ImGui::Separator();
|
|
|
|
|
2023-12-29 03:55:11 +02:00
|
|
|
if (!disable_user_input) {
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::Text(translationRestartTheGameToApply[current_language]);
|
|
|
|
if (ImGui::Button(translationSave[current_language])) {
|
2022-08-05 02:09:43 -04:00
|
|
|
save_settings = true;
|
|
|
|
show_settings = false;
|
|
|
|
}
|
|
|
|
} else {
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]);
|
|
|
|
ImGui::TextWrapped(translationWarningDescription1[current_language]);
|
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string url = show_url;
|
|
|
|
if (url.size()) {
|
|
|
|
bool show = true;
|
|
|
|
if (ImGui::Begin(URL_WINDOW_NAME, &show)) {
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::Text(translationSteamOverlayURL[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::PushItemWidth(ImGui::CalcTextSize(url.c_str()).x + 20);
|
|
|
|
ImGui::InputText("##url_copy", (char *)url.data(), url.size(), ImGuiInputTextFlags_ReadOnly);
|
|
|
|
ImGui::PopItemWidth();
|
|
|
|
ImGui::Spacing();
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Button(translationClose[current_language]) || !show)
|
2022-08-05 02:09:43 -04:00
|
|
|
show_url = "";
|
|
|
|
// ImGui::SetWindowSize(ImVec2(ImGui::CalcTextSize(url.c_str()).x + 10, 0));
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2023-12-29 03:55:11 +02:00
|
|
|
bool show_warning = warn_local_save || warn_forced_setting || warn_bad_appid;
|
2022-08-05 02:09:43 -04:00
|
|
|
if (show_warning) {
|
2022-08-13 14:35:59 -04:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2(ImGui::GetFontSize() * 32, ImGui::GetFontSize() * 32), ImVec2(8192, 8192));
|
2022-08-05 02:09:43 -04:00
|
|
|
ImGui::SetNextWindowFocus();
|
2023-08-21 06:58:55 +03:00
|
|
|
if (ImGui::Begin(translationWarning[current_language], &show_warning)) {
|
2023-12-29 03:55:11 +02:00
|
|
|
if (warn_bad_appid) {
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]);
|
|
|
|
ImGui::TextWrapped(translationWarningDescription2[current_language]);
|
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
}
|
2023-12-29 03:55:11 +02:00
|
|
|
if (warn_local_save) {
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]);
|
|
|
|
ImGui::TextWrapped(translationWarningDescription3[current_language]);
|
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
}
|
2023-12-29 03:55:11 +02:00
|
|
|
if (warn_forced_setting) {
|
2023-08-21 06:58:55 +03:00
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]);
|
|
|
|
ImGui::TextWrapped(translationWarningDescription4[current_language]);
|
|
|
|
ImGui::TextColored(ImVec4(255, 0, 0, 255), translationWarningWarningWarning[current_language]);
|
2022-08-05 02:09:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ImGui::End();
|
|
|
|
if (!show_warning) {
|
2023-12-29 03:55:11 +02:00
|
|
|
warn_local_save = warn_forced_setting = false;
|
2022-08-05 02:09:43 -04:00
|
|
|
}
|
|
|
|
}
|
2019-08-14 14:56:57 +02:00
|
|
|
}
|
|
|
|
ImGui::End();
|
2019-09-05 09:00:02 +02:00
|
|
|
|
|
|
|
ImGui::PopFont();
|
2019-10-11 00:25:44 +02:00
|
|
|
|
|
|
|
if (!show)
|
|
|
|
ShowOverlay(false);
|
2020-02-14 15:03:20 -05:00
|
|
|
} else {
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
|
|
|
|
}
|
2019-07-31 22:21:02 +02:00
|
|
|
}
|
|
|
|
|
2019-08-03 12:58:48 +02:00
|
|
|
void Steam_Overlay::Callback(Common_Message *msg)
|
|
|
|
{
|
2020-01-20 11:47:12 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-03 12:58:48 +02:00
|
|
|
if (msg->has_steam_messages())
|
|
|
|
{
|
|
|
|
Friend frd;
|
|
|
|
frd.set_id(msg->source_id());
|
|
|
|
auto friend_info = friends.find(frd);
|
|
|
|
if (friend_info != friends.end())
|
|
|
|
{
|
|
|
|
Steam_Messages const& steam_message = msg->steam_messages();
|
|
|
|
// Change color to cyan for friend
|
2022-09-03 04:13:58 -04:00
|
|
|
friend_info->second.chat_history.append(friend_info->first.name() + ": " + steam_message.message()).append("\n", 1);
|
2019-08-16 18:31:56 +02:00
|
|
|
if (!(friend_info->second.window_state & window_state_show))
|
|
|
|
{
|
|
|
|
friend_info->second.window_state |= window_state_need_attention;
|
|
|
|
}
|
2019-09-04 19:31:31 +02:00
|
|
|
|
2023-08-21 06:58:55 +03:00
|
|
|
AddMessageNotification(friend_info->first.name() + ": " + steam_message.message());
|
2024-01-26 05:49:03 +02:00
|
|
|
NotifySoundUserInvite(friend_info->second);
|
2019-08-03 12:58:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
void Steam_Overlay::RunCallbacks()
|
|
|
|
{
|
2024-01-24 02:21:09 +02:00
|
|
|
if (!achievements.size() && load_achievements_trials > 0) {
|
|
|
|
--load_achievements_trials;
|
2022-08-13 14:35:59 -04:00
|
|
|
Steam_User_Stats* steamUserStats = get_steam_client()->steam_user_stats;
|
|
|
|
uint32 achievements_num = steamUserStats->GetNumAchievements();
|
|
|
|
if (achievements_num) {
|
|
|
|
PRINT_DEBUG("POPULATE OVERLAY ACHIEVEMENTS\n");
|
|
|
|
for (unsigned i = 0; i < achievements_num; ++i) {
|
|
|
|
Overlay_Achievement ach;
|
|
|
|
ach.name = steamUserStats->GetAchievementName(i);
|
|
|
|
ach.title = steamUserStats->GetAchievementDisplayAttribute(ach.name.c_str(), "name");
|
|
|
|
ach.description = steamUserStats->GetAchievementDisplayAttribute(ach.name.c_str(), "desc");
|
|
|
|
const char *hidden = steamUserStats->GetAchievementDisplayAttribute(ach.name.c_str(), "hidden");
|
|
|
|
if (strlen(hidden) && hidden[0] == '1') {
|
|
|
|
ach.hidden = true;
|
|
|
|
} else {
|
|
|
|
ach.hidden = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool achieved = false;
|
|
|
|
uint32 unlock_time = 0;
|
|
|
|
if (steamUserStats->GetAchievementAndUnlockTime(ach.name.c_str(), &achieved, &unlock_time)) {
|
|
|
|
ach.achieved = achieved;
|
|
|
|
ach.unlock_time = unlock_time;
|
|
|
|
} else {
|
|
|
|
ach.achieved = false;
|
|
|
|
ach.unlock_time = 0;
|
|
|
|
}
|
|
|
|
|
2023-11-12 23:09:17 +02:00
|
|
|
ach.icon_name = steamUserStats->get_achievement_icon_name(ach.name.c_str(), true);
|
|
|
|
ach.icon_gray_name = steamUserStats->get_achievement_icon_name(ach.name.c_str(), false);
|
2023-11-10 17:25:36 +02:00
|
|
|
|
2022-08-13 14:35:59 -04:00
|
|
|
achievements.push_back(ach);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRINT_DEBUG("POPULATE OVERLAY ACHIEVEMENTS DONE\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
if (!Ready() && future_renderer.valid()) {
|
|
|
|
if (future_renderer.wait_for(std::chrono::milliseconds{0}) == std::future_status::ready) {
|
|
|
|
_renderer = future_renderer.get();
|
|
|
|
PRINT_DEBUG("got renderer %p\n", _renderer);
|
2022-08-13 14:35:59 -04:00
|
|
|
CreateFonts();
|
2023-11-10 17:25:36 +02:00
|
|
|
LoadAudio();
|
2022-08-05 02:09:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Ready() && _renderer) {
|
|
|
|
_renderer->OverlayHookReady = std::bind(&Steam_Overlay::HookReady, this, std::placeholders::_1);
|
|
|
|
_renderer->OverlayProc = std::bind(&Steam_Overlay::OverlayProc, this);
|
|
|
|
auto callback = std::bind(&Steam_Overlay::OpenOverlayHook, this, std::placeholders::_1);
|
|
|
|
PRINT_DEBUG("start renderer\n", _renderer);
|
2022-08-13 14:32:43 -04:00
|
|
|
std::set<ingame_overlay::ToggleKey> keys = {ingame_overlay::ToggleKey::SHIFT, ingame_overlay::ToggleKey::TAB};
|
2022-08-21 03:45:11 -04:00
|
|
|
_renderer->ImGuiFontAtlas = fonts_atlas;
|
2022-08-13 14:32:43 -04:00
|
|
|
bool started = _renderer->StartHook(callback, keys);
|
2022-08-05 02:09:43 -04:00
|
|
|
PRINT_DEBUG("tried to start renderer %u\n", started);
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:21:02 +02:00
|
|
|
if (overlay_state_changed)
|
|
|
|
{
|
|
|
|
GameOverlayActivated_t data = { 0 };
|
|
|
|
data.m_bActive = show_overlay;
|
2023-05-08 22:36:51 -04:00
|
|
|
data.m_bUserInitiated = true;
|
|
|
|
data.m_nAppID = settings->get_local_game_id().AppID();
|
2019-07-31 22:21:02 +02:00
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
|
|
|
|
overlay_state_changed = false;
|
|
|
|
}
|
|
|
|
|
2019-08-01 11:15:38 +02:00
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking;
|
|
|
|
|
2022-08-05 02:09:43 -04:00
|
|
|
if (save_settings) {
|
|
|
|
char *language_text = valid_languages[current_language];
|
|
|
|
save_global_settings(get_steam_client()->local_storage, username_text, language_text);
|
|
|
|
get_steam_client()->settings_client->set_local_name(username_text);
|
|
|
|
get_steam_client()->settings_server->set_local_name(username_text);
|
|
|
|
get_steam_client()->settings_client->set_language(language_text);
|
|
|
|
get_steam_client()->settings_server->set_language(language_text);
|
|
|
|
steamFriends->resend_friend_data();
|
|
|
|
save_settings = false;
|
|
|
|
}
|
|
|
|
|
2020-01-26 09:46:57 -05:00
|
|
|
i_have_lobby = IHaveLobby();
|
2020-01-25 15:23:16 -05:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2020-01-26 09:46:57 -05:00
|
|
|
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i)
|
|
|
|
{
|
2020-02-02 19:07:30 -05:00
|
|
|
i.second.joinable = FriendJoinable(i);
|
2020-01-26 09:46:57 -05:00
|
|
|
});
|
|
|
|
|
2019-08-02 13:02:20 +02:00
|
|
|
while (!has_friend_action.empty())
|
2019-07-31 22:21:02 +02:00
|
|
|
{
|
2019-08-02 13:02:20 +02:00
|
|
|
auto friend_info = friends.find(has_friend_action.front());
|
2024-01-22 01:31:02 +02:00
|
|
|
if (friend_info != friends.end()) {
|
|
|
|
uint64 friend_id = (uint64)friend_info->first.id();
|
2019-08-06 13:46:43 +02:00
|
|
|
// The user clicked on "Send"
|
2024-01-22 01:31:02 +02:00
|
|
|
if (friend_info->second.window_state & window_state_send_message) {
|
2019-08-03 12:58:48 +02:00
|
|
|
char* input = friend_info->second.chat_input;
|
|
|
|
char* end_input = input + strlen(input);
|
|
|
|
char* printable_char = std::find_if(input, end_input, [](char c) {
|
|
|
|
return std::isgraph(c);
|
|
|
|
});
|
2019-08-06 13:46:43 +02:00
|
|
|
// Check if the message contains something else than blanks
|
2024-01-22 01:31:02 +02:00
|
|
|
if (printable_char != end_input) {
|
2019-08-03 12:58:48 +02:00
|
|
|
// Handle chat send
|
|
|
|
Common_Message msg;
|
|
|
|
Steam_Messages* steam_messages = new Steam_Messages;
|
|
|
|
steam_messages->set_type(Steam_Messages::FRIEND_CHAT);
|
|
|
|
steam_messages->set_message(friend_info->second.chat_input);
|
|
|
|
msg.set_allocated_steam_messages(steam_messages);
|
|
|
|
msg.set_source_id(settings->get_local_steam_id().ConvertToUint64());
|
|
|
|
msg.set_dest_id(friend_id);
|
|
|
|
network->sendTo(&msg, true);
|
|
|
|
|
2022-09-03 04:13:58 -04:00
|
|
|
friend_info->second.chat_history.append(get_steam_client()->settings_client->get_local_name()).append(": ").append(input).append("\n", 1);
|
2019-08-03 12:58:48 +02:00
|
|
|
}
|
|
|
|
*input = 0; // Reset the input field
|
2024-01-22 01:31:02 +02:00
|
|
|
|
2019-08-03 12:58:48 +02:00
|
|
|
friend_info->second.window_state &= ~window_state_send_message;
|
|
|
|
}
|
2024-01-22 01:31:02 +02:00
|
|
|
// The user clicked on "Invite" (but invite all wasn't clicked)
|
|
|
|
if (friend_info->second.window_state & window_state_invite) {
|
|
|
|
InviteFriend(friend_id, steamFriends, steamMatchmaking);
|
|
|
|
|
2019-08-02 13:02:20 +02:00
|
|
|
friend_info->second.window_state &= ~window_state_invite;
|
|
|
|
}
|
|
|
|
// The user clicked on "Join"
|
2024-01-22 01:31:02 +02:00
|
|
|
if (friend_info->second.window_state & window_state_join) {
|
2019-08-02 13:02:20 +02:00
|
|
|
std::string connect = steamFriends->GetFriendRichPresence(friend_id, "connect");
|
2020-02-02 19:07:30 -05:00
|
|
|
// The user got a lobby invite and accepted it
|
2024-01-22 01:31:02 +02:00
|
|
|
if (friend_info->second.window_state & window_state_lobby_invite) {
|
2020-02-02 19:07:30 -05:00
|
|
|
GameLobbyJoinRequested_t data;
|
|
|
|
data.m_steamIDLobby.SetFromUint64(friend_info->second.lobbyId);
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
|
|
|
|
friend_info->second.window_state &= ~window_state_lobby_invite;
|
2021-03-07 19:04:01 -05:00
|
|
|
} else {
|
2020-02-02 19:07:30 -05:00
|
|
|
// The user got a rich presence invite and accepted it
|
2024-01-22 01:31:02 +02:00
|
|
|
if (friend_info->second.window_state & window_state_rich_invite) {
|
2021-03-07 19:04:01 -05:00
|
|
|
GameRichPresenceJoinRequested_t data = {};
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
strncpy(data.m_rgchConnect, friend_info->second.connect, k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
2024-01-22 01:31:02 +02:00
|
|
|
|
2021-03-07 19:04:01 -05:00
|
|
|
friend_info->second.window_state &= ~window_state_rich_invite;
|
2024-01-22 01:31:02 +02:00
|
|
|
} else if (connect.length() > 0) {
|
2021-03-07 19:04:01 -05:00
|
|
|
GameRichPresenceJoinRequested_t data = {};
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
strncpy(data.m_rgchConnect, connect.c_str(), k_cchMaxRichPresenceValueLength - 1);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
}
|
|
|
|
|
|
|
|
//Not sure about this but it fixes sonic racing transformed invites
|
|
|
|
FriendGameInfo_t friend_game_info = {};
|
|
|
|
steamFriends->GetFriendGamePlayed(friend_id, &friend_game_info);
|
|
|
|
uint64 lobby_id = friend_game_info.m_steamIDLobby.ConvertToUint64();
|
|
|
|
if (lobby_id) {
|
|
|
|
GameLobbyJoinRequested_t data;
|
|
|
|
data.m_steamIDLobby.SetFromUint64(lobby_id);
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
}
|
2019-08-02 13:02:20 +02:00
|
|
|
}
|
2024-01-22 01:31:02 +02:00
|
|
|
|
2019-08-02 13:02:20 +02:00
|
|
|
friend_info->second.window_state &= ~window_state_join;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
has_friend_action.pop();
|
2019-07-31 22:21:02 +02:00
|
|
|
}
|
2024-01-22 01:31:02 +02:00
|
|
|
|
|
|
|
// if variable == true, then set it to false and return true (because state was changed) in that case
|
|
|
|
bool true_tmp = true;
|
|
|
|
if (invite_all_friends_clicked.compare_exchange_weak(true_tmp, false)) {
|
|
|
|
PRINT_DEBUG("Overlay will send invitations to [%zu] friends if they're using the same app\n", friends.size());
|
|
|
|
uint32 current_appid = settings->get_local_game_id().AppID();
|
|
|
|
for (auto &fr : friends) {
|
|
|
|
if (fr.first.appid() == current_appid) { // friend is playing the same game
|
|
|
|
uint64 friend_id = (uint64)fr.first.id();
|
|
|
|
InviteFriend(friend_id, steamFriends, steamMatchmaking);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::InviteFriend(uint64 friend_id, class Steam_Friends* steamFriends, class Steam_Matchmaking* steamMatchmaking)
|
|
|
|
{
|
|
|
|
std::string connect_str = steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect");
|
|
|
|
if (connect_str.length() > 0) {
|
|
|
|
steamFriends->InviteUserToGame(friend_id, connect_str.c_str());
|
|
|
|
PRINT_DEBUG("Overlay sent game invitation to friend with id = %llu\n", friend_id);
|
|
|
|
} else if (settings->get_lobby().IsValid()) {
|
|
|
|
steamMatchmaking->InviteUserToLobby(settings->get_lobby(), friend_id);
|
|
|
|
PRINT_DEBUG("Overlay sent lobby invitation to friend with id = %llu\n", friend_id);
|
|
|
|
}
|
2019-08-14 14:55:31 +02:00
|
|
|
}
|
|
|
|
|
2019-08-31 20:49:07 +02:00
|
|
|
#endif
|