2019-08-01 04:21:02 +08:00
|
|
|
#include "steam_overlay.h"
|
|
|
|
|
2020-01-20 01:55:14 +08:00
|
|
|
#ifdef EMU_OVERLAY
|
2019-08-14 20:55:31 +08:00
|
|
|
|
2019-08-01 04:21:02 +08:00
|
|
|
#include <thread>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2019-08-03 18:58:48 +08:00
|
|
|
#include <cctype>
|
2019-08-01 04:21:02 +08:00
|
|
|
#include <imgui.h>
|
|
|
|
|
2019-08-01 17:35:36 +08:00
|
|
|
#include "../dll/dll.h"
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2019-08-27 21:38:07 +08:00
|
|
|
#include "Renderer_Detector.h"
|
2019-08-18 22:22:07 +08:00
|
|
|
|
2019-10-11 19:10:48 +08: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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int find_free_friend_id(std::map<Friend, friend_window_state, Friend_Less> const& friend_windows)
|
|
|
|
{
|
|
|
|
std::vector<int> ids;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
std::vector<int> ids;
|
|
|
|
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-02 02:48:27 +08:00
|
|
|
#ifdef __WINDOWS__
|
|
|
|
#include "windows/Windows_Hook.h"
|
|
|
|
#endif
|
2019-08-16 04:23:59 +08:00
|
|
|
|
2019-08-17 00:31:56 +08:00
|
|
|
#include "notification.h"
|
|
|
|
|
2019-08-06 19:46:43 +08: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 22:38:01 +08:00
|
|
|
Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking* network) :
|
2019-08-01 04:21:02 +08:00
|
|
|
settings(settings),
|
|
|
|
callback_results(callback_results),
|
|
|
|
callbacks(callbacks),
|
|
|
|
run_every_runcb(run_every_runcb),
|
|
|
|
network(network),
|
2019-08-26 22:38:01 +08:00
|
|
|
setup_overlay_called(false),
|
2019-08-01 04:21:02 +08:00
|
|
|
show_overlay(false),
|
|
|
|
is_ready(false),
|
|
|
|
notif_position(ENotificationPosition::k_EPositionBottomLeft),
|
|
|
|
h_inset(0),
|
|
|
|
v_inset(0),
|
2020-01-26 22:46:57 +08:00
|
|
|
overlay_state_changed(false),
|
|
|
|
i_have_lobby(false)
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
|
|
|
run_every_runcb->add(&Steam_Overlay::steam_overlay_run_every_runcb, this);
|
2019-08-03 18:58:48 +08:00
|
|
|
this->network->setCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::steam_overlay_callback, this);
|
2019-08-01 04:21:02 +08: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-26 04:23:16 +08:00
|
|
|
PRINT_DEBUG("%s\n", __FUNCTION__);
|
2020-01-21 00:47:12 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-26 22:38:01 +08:00
|
|
|
if (!setup_overlay_called)
|
|
|
|
{
|
|
|
|
setup_overlay_called = true;
|
2019-08-27 21:38:07 +08:00
|
|
|
Renderer_Detector::Inst().find_renderer();
|
2019-08-26 22:38:01 +08:00
|
|
|
}
|
2019-08-18 20:29:08 +08:00
|
|
|
}
|
|
|
|
|
2019-08-18 22:22:07 +08:00
|
|
|
void Steam_Overlay::HookReady()
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2019-09-05 15:00:02 +08:00
|
|
|
if (!is_ready)
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2019-08-18 22:22:07 +08:00
|
|
|
// TODO: Uncomment this and draw our own cursor (cosmetics)
|
|
|
|
//ImGuiIO &io = ImGui::GetIO();
|
|
|
|
//io.WantSetMousePos = false;
|
|
|
|
//io.MouseDrawCursor = false;
|
|
|
|
//io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
|
|
|
|
|
|
|
|
is_ready = true;
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlayInvite(CSteamID lobbyId)
|
|
|
|
{
|
2019-08-02 17:16:30 +08:00
|
|
|
ShowOverlay(true);
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::OpenOverlay(const char* pchDialog)
|
|
|
|
{
|
|
|
|
// TODO: Show pages depending on pchDialog
|
2019-08-02 17:16:30 +08:00
|
|
|
ShowOverlay(true);
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
|
2019-08-18 22:22:07 +08:00
|
|
|
bool Steam_Overlay::ShowOverlay() const
|
|
|
|
{
|
|
|
|
return show_overlay;
|
|
|
|
}
|
|
|
|
|
2019-08-01 04:21:02 +08:00
|
|
|
void Steam_Overlay::ShowOverlay(bool state)
|
|
|
|
{
|
2019-09-01 02:49:07 +08:00
|
|
|
if (!Ready() || show_overlay == state)
|
|
|
|
return;
|
|
|
|
|
2019-10-16 22:56:41 +08:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
|
|
|
|
|
if(state)
|
|
|
|
{
|
|
|
|
io.MouseDrawCursor = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
io.MouseDrawCursor = false;
|
|
|
|
}
|
|
|
|
|
2019-09-02 02:48:27 +08:00
|
|
|
#ifdef __WINDOWS__
|
2019-08-01 04:21:02 +08:00
|
|
|
static RECT old_clip;
|
|
|
|
|
2019-08-28 03:15:58 +08:00
|
|
|
if (state)
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2019-08-27 21:38:07 +08:00
|
|
|
HWND game_hwnd = Windows_Hook::Inst()->GetGameHwnd();
|
2019-08-01 04:21:02 +08: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-09-01 02:49:07 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-08-28 03:15:58 +08:00
|
|
|
show_overlay = state;
|
2019-08-01 04:21:02 +08:00
|
|
|
overlay_state_changed = true;
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:52:38 +08:00
|
|
|
void Steam_Overlay::NotifyUser(friend_window_state& friend_state)
|
2019-09-05 01:31:31 +08:00
|
|
|
{
|
2019-09-05 15:00:02 +08:00
|
|
|
if (!(friend_state.window_state & window_state_show) || !show_overlay)
|
2019-09-05 01:31:31 +08:00
|
|
|
{
|
|
|
|
friend_state.window_state |= window_state_need_attention;
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
PlaySound((LPCSTR)notif_invite_wav, NULL, SND_ASYNC | SND_MEMORY);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-03 05:01:24 +08:00
|
|
|
void Steam_Overlay::SetLobbyInvite(Friend friendId, uint64 lobbyId)
|
2019-08-02 17:16:30 +08:00
|
|
|
{
|
2019-08-16 16:37:45 +08:00
|
|
|
if (!Ready())
|
|
|
|
return;
|
|
|
|
|
2020-01-21 00:47:12 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-02 19:02:20 +08: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-03 05:01:24 +08: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 22:52:38 +08:00
|
|
|
AddInviteNotification(*i);
|
|
|
|
NotifyUser(i->second);
|
2019-08-02 19:02:20 +08:00
|
|
|
}
|
2019-08-02 17:16:30 +08:00
|
|
|
}
|
|
|
|
|
2019-08-03 05:01:24 +08:00
|
|
|
void Steam_Overlay::SetRichInvite(Friend friendId, const char* connect_str)
|
2019-08-02 17:16:30 +08:00
|
|
|
{
|
2019-08-16 16:37:45 +08:00
|
|
|
if (!Ready())
|
|
|
|
return;
|
|
|
|
|
2020-01-21 00:47:12 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-02 19:02:20 +08: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-03 05:01:24 +08: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 22:52:38 +08:00
|
|
|
AddInviteNotification(*i);
|
|
|
|
NotifyUser(i->second);
|
2019-08-02 19:02:20 +08:00
|
|
|
}
|
2019-08-02 17:16:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::FriendConnect(Friend _friend)
|
|
|
|
{
|
2020-01-21 00:47:12 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-10-11 19:10:48 +08:00
|
|
|
int id = find_free_friend_id(friends);
|
|
|
|
if (id != 0)
|
|
|
|
{
|
|
|
|
auto& item = friends[_friend];
|
2019-10-14 22:35:36 +08:00
|
|
|
item.window_title = std::move(_friend.name() + " playing " + std::to_string(_friend.appid()));
|
2019-10-11 19:10:48 +08:00
|
|
|
item.window_state = window_state_none;
|
|
|
|
item.id = id;
|
|
|
|
memset(item.chat_input, 0, max_chat_len);
|
2020-02-03 08:07:30 +08:00
|
|
|
item.joinable = false;
|
2019-10-11 19:10:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
PRINT_DEBUG("No more free id to create a friend window\n");
|
2019-08-02 17:16:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::FriendDisconnect(Friend _friend)
|
|
|
|
{
|
2020-01-21 00:47:12 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-02 17:16:30 +08:00
|
|
|
auto it = friends.find(_friend);
|
|
|
|
if (it != friends.end())
|
|
|
|
friends.erase(it);
|
|
|
|
}
|
|
|
|
|
2019-11-08 22:52:38 +08:00
|
|
|
void Steam_Overlay::AddMessageNotification(std::string const& message)
|
2019-09-05 01:31:31 +08:00
|
|
|
{
|
2020-01-27 06:24:16 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
|
2019-10-11 19:10:48 +08:00
|
|
|
int id = find_free_notification_id(notifications);
|
|
|
|
if (id != 0)
|
|
|
|
{
|
|
|
|
Notification notif;
|
|
|
|
notif.id = id;
|
2019-11-08 22:52:38 +08:00
|
|
|
notif.type = notification_type_message;
|
2019-10-11 19:10:48 +08: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);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PRINT_DEBUG("No more free id to create a notification window\n");
|
2019-09-05 01:31:31 +08:00
|
|
|
}
|
|
|
|
|
2019-11-08 22:52:38 +08:00
|
|
|
void Steam_Overlay::AddAchievementNotification(nlohmann::json const& ach)
|
|
|
|
{
|
2020-01-27 06:24:16 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
|
2019-11-08 22:52:38 +08:00
|
|
|
int id = find_free_notification_id(notifications);
|
|
|
|
if (id != 0)
|
|
|
|
{
|
|
|
|
Notification notif;
|
|
|
|
notif.id = id;
|
|
|
|
notif.type = notification_type_achievement;
|
|
|
|
// Load achievement image
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PRINT_DEBUG("No more free id to create a notification window\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Overlay::AddInviteNotification(std::pair<const Friend, friend_window_state>& wnd_state)
|
|
|
|
{
|
2020-01-27 06:24:16 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
|
2019-11-08 22:52:38 +08: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;
|
|
|
|
notif.message = wnd_state.first.name() + " invited you to join a game";
|
|
|
|
notif.start_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch());
|
|
|
|
notifications.emplace_back(notif);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PRINT_DEBUG("No more free id to create a notification window\n");
|
|
|
|
}
|
|
|
|
|
2020-02-03 08:07:30 +08:00
|
|
|
bool Steam_Overlay::FriendJoinable(std::pair<const Friend, friend_window_state> &f)
|
2019-08-06 19:46:43 +08:00
|
|
|
{
|
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
|
2020-02-03 08:07:30 +08:00
|
|
|
if( std::string(steamFriends->GetFriendRichPresence(f.first.id(), "connect")).length() > 0 )
|
2019-08-06 19:46:43 +08:00
|
|
|
return true;
|
|
|
|
|
|
|
|
FriendGameInfo_t friend_game_info = {};
|
2020-02-03 08:07:30 +08: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 19:46:43 +08: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-09-01 02:49:07 +08:00
|
|
|
|
2019-08-06 19:46:43 +08:00
|
|
|
if (settings->get_lobby().IsValid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:26:16 +08:00
|
|
|
void Steam_Overlay::BuildContextMenu(Friend const& frd, friend_window_state& state)
|
|
|
|
{
|
2019-10-11 19:10:48 +08:00
|
|
|
if (ImGui::BeginPopupContextItem("Friends_ContextMenu", 1))
|
2019-08-02 21:26:16 +08:00
|
|
|
{
|
2019-08-06 19:46:43 +08:00
|
|
|
bool close_popup = false;
|
|
|
|
|
|
|
|
if (ImGui::Button("Chat"))
|
|
|
|
{
|
|
|
|
state.window_state |= window_state_show;
|
|
|
|
close_popup = true;
|
|
|
|
}
|
2019-10-14 22:35:36 +08:00
|
|
|
// If we have the same appid, activate the invite/join buttons
|
|
|
|
if (settings->get_local_game_id().AppID() == frd.appid())
|
2019-08-02 21:26:16 +08:00
|
|
|
{
|
2020-01-26 22:46:57 +08:00
|
|
|
if (i_have_lobby && ImGui::Button("Invite###PopupInvite"))
|
2019-10-14 22:35:36 +08:00
|
|
|
{
|
|
|
|
state.window_state |= window_state_invite;
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
close_popup = true;
|
|
|
|
}
|
2020-02-03 08:07:30 +08:00
|
|
|
if (state.joinable && ImGui::Button("Join###PopupJoin"))
|
2019-10-14 22:35:36 +08:00
|
|
|
{
|
|
|
|
state.window_state |= window_state_join;
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
close_popup = true;
|
|
|
|
}
|
2019-08-02 21:26:16 +08:00
|
|
|
}
|
2019-08-06 19:46:43 +08:00
|
|
|
if( close_popup)
|
|
|
|
{
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:26:16 +08: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 19:46:43 +08:00
|
|
|
bool send_chat_msg = false;
|
2019-08-03 18:58:48 +08:00
|
|
|
|
2019-10-11 19:10:48 +08: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-18 11:58:42 +08:00
|
|
|
ImGui::SetNextWindowSizeConstraints(ImVec2{ width, ImGui::GetFontSize()*8 + ImGui::GetFrameHeightWithSpacing()*4 },
|
2019-10-11 19:10:48 +08: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 22:35:36 +08: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 21:26:16 +08:00
|
|
|
{
|
2019-08-17 00:31:56 +08:00
|
|
|
if (state.window_state & window_state_need_attention && ImGui::IsWindowFocused())
|
|
|
|
{
|
|
|
|
state.window_state &= ~window_state_need_attention;
|
|
|
|
}
|
|
|
|
|
2019-08-02 21:26:16 +08:00
|
|
|
// Fill this with the chat box and maybe the invitation
|
|
|
|
if (state.window_state & (window_state_lobby_invite | window_state_rich_invite))
|
|
|
|
{
|
2019-08-03 18:58:48 +08:00
|
|
|
ImGui::LabelText("##label", "%s invited you to join the game.", frd.name().c_str());
|
2019-08-02 21:26:16 +08:00
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Button("Accept"))
|
|
|
|
{
|
2020-02-03 08:07:30 +08:00
|
|
|
state.window_state |= window_state_join;
|
2019-08-02 21:26:16 +08:00
|
|
|
this->has_friend_action.push(frd);
|
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (ImGui::Button("Refuse"))
|
|
|
|
{
|
|
|
|
state.window_state &= ~(window_state_lobby_invite | window_state_rich_invite);
|
|
|
|
}
|
|
|
|
}
|
2019-08-03 18:58:48 +08:00
|
|
|
|
2021-01-18 11:58:42 +08:00
|
|
|
ImGui::InputTextMultiline("##chat_history", &state.chat_history[0], state.chat_history.length(), { -1.0f, 0 }, ImGuiInputTextFlags_ReadOnly);
|
2019-08-14 20:56:57 +08: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 19:10:48 +08:00
|
|
|
float wnd_width = ImGui::GetWindowContentRegionWidth();
|
|
|
|
ImGuiStyle &style = ImGui::GetStyle();
|
|
|
|
wnd_width -= ImGui::CalcTextSize("Send").x + style.FramePadding.x * 2 + style.ItemSpacing.x + 1;
|
|
|
|
|
|
|
|
ImGui::PushItemWidth(wnd_width);
|
2019-08-03 18:58:48 +08:00
|
|
|
if (ImGui::InputText("##chat_line", state.chat_input, max_chat_len, ImGuiInputTextFlags_EnterReturnsTrue))
|
|
|
|
{
|
2019-08-06 19:46:43 +08:00
|
|
|
send_chat_msg = true;
|
2019-08-03 18:58:48 +08:00
|
|
|
}
|
2019-10-11 19:10:48 +08:00
|
|
|
ImGui::PopItemWidth();
|
2019-08-03 18:58:48 +08:00
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
|
|
|
if (ImGui::Button("Send"))
|
2019-08-06 19:46:43 +08:00
|
|
|
{
|
|
|
|
send_chat_msg = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (send_chat_msg)
|
2019-08-03 18:58:48 +08:00
|
|
|
{
|
|
|
|
if (!(state.window_state & window_state_send_message))
|
|
|
|
{
|
|
|
|
has_friend_action.push(frd);
|
|
|
|
state.window_state |= window_state_send_message;
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 21:26:16 +08:00
|
|
|
}
|
|
|
|
// User closed the friend window
|
|
|
|
if (!show)
|
|
|
|
state.window_state &= ~window_state_show;
|
2019-08-06 19:46:43 +08:00
|
|
|
|
2019-08-02 21:26:16 +08:00
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
2019-09-05 15:00:02 +08:00
|
|
|
ImFont *font_default;
|
|
|
|
ImFont *font_notif;
|
|
|
|
|
2019-09-05 01:31:31 +08:00
|
|
|
void Steam_Overlay::BuildNotifications(int width, int height)
|
2019-08-27 01:36:07 +08:00
|
|
|
{
|
2019-09-05 01:31:31 +08:00
|
|
|
auto now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
|
|
|
|
int i = 0;
|
2019-09-05 15:00:02 +08:00
|
|
|
|
|
|
|
int font_size = ImGui::GetFontSize();
|
|
|
|
|
2020-01-27 06:24:16 +08:00
|
|
|
std::queue<Friend> friend_actions_temp;
|
2020-01-26 22:46:57 +08:00
|
|
|
|
2019-09-05 01:31:31 +08:00
|
|
|
{
|
2020-01-27 06:24:16 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(notifications_mutex);
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2020-01-27 06:24:16 +08:00
|
|
|
for (auto it = notifications.begin(); it != notifications.end(); ++it, ++i)
|
2019-09-05 01:31:31 +08:00
|
|
|
{
|
2020-01-27 06:24:16 +08:00
|
|
|
auto elapsed_notif = now - it->start_time;
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2020-01-27 06:24:16 +08:00
|
|
|
if ( elapsed_notif < Notification::fade_in)
|
|
|
|
{
|
|
|
|
float alpha = Notification::max_alpha * (elapsed_notif.count() / static_cast<float>(Notification::fade_in.count()));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(Notification::r, Notification::g, Notification::b, alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, alpha*2));
|
|
|
|
}
|
|
|
|
else if ( elapsed_notif > Notification::fade_out_start)
|
|
|
|
{
|
|
|
|
float alpha = Notification::max_alpha * ((Notification::show_time - elapsed_notif).count() / static_cast<float>(Notification::fade_out.count()));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(Notification::r, Notification::g, Notification::b, alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, alpha*2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, Notification::max_alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(Notification::r, Notification::g, Notification::b, Notification::max_alpha));
|
|
|
|
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 255, Notification::max_alpha*2));
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetNextWindowPos(ImVec2((float)width - width * Notification::width, Notification::height * font_size * i ));
|
|
|
|
ImGui::SetNextWindowSize(ImVec2( width * Notification::width, Notification::height * font_size ));
|
|
|
|
ImGui::Begin(std::to_string(it->id).c_str(), nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus |
|
|
|
|
ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoDecoration);
|
|
|
|
|
|
|
|
switch (it->type)
|
|
|
|
{
|
|
|
|
case notification_type_achievement:
|
2019-11-08 22:52:38 +08:00
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
2020-01-27 06:24:16 +08:00
|
|
|
break;
|
|
|
|
case notification_type_invite:
|
2019-11-08 22:52:38 +08:00
|
|
|
{
|
2020-01-27 06:24:16 +08:00
|
|
|
ImGui::TextWrapped("%s", it->message.c_str());
|
|
|
|
if (ImGui::Button("Join"))
|
|
|
|
{
|
2020-02-03 08:07:30 +08:00
|
|
|
it->frd->second.window_state |= window_state_join;
|
2020-01-27 06:24:16 +08:00
|
|
|
friend_actions_temp.push(it->frd->first);
|
|
|
|
it->start_time = std::chrono::seconds(0);
|
|
|
|
}
|
2019-11-08 22:52:38 +08:00
|
|
|
}
|
2020-01-27 06:24:16 +08:00
|
|
|
break;
|
|
|
|
case notification_type_message:
|
|
|
|
ImGui::TextWrapped("%s", it->message.c_str()); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::End();
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2020-01-27 06:24:16 +08: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());
|
|
|
|
}
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2020-01-27 06:24:16 +08: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-05 01:31:31 +08:00
|
|
|
}
|
2019-08-27 01:36:07 +08:00
|
|
|
}
|
|
|
|
|
2019-09-05 15:00:02 +08:00
|
|
|
void Steam_Overlay::CreateFonts()
|
|
|
|
{
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
ImFontConfig fontcfg;
|
|
|
|
|
|
|
|
fontcfg.OversampleH = fontcfg.OversampleV = 1;
|
|
|
|
fontcfg.PixelSnapH = true;
|
|
|
|
fontcfg.GlyphRanges = io.Fonts->GetGlyphRangesDefault();
|
|
|
|
|
|
|
|
fontcfg.SizePixels = std::round(io.DisplaySize.y / 68);
|
|
|
|
font_default = io.Fonts->AddFontDefault(&fontcfg);
|
|
|
|
|
|
|
|
fontcfg.SizePixels = std::round(io.DisplaySize.y / 60);
|
|
|
|
font_notif = io.Fonts->AddFontDefault(&fontcfg);
|
|
|
|
|
|
|
|
ImGuiStyle& style = ImGui::GetStyle();
|
|
|
|
style.WindowRounding = 0.0; // Disable round window
|
|
|
|
}
|
|
|
|
|
2019-08-14 20:56:57 +08:00
|
|
|
// Try to make this function as short as possible or it might affect game's fps.
|
2019-09-05 15:00:02 +08:00
|
|
|
void Steam_Overlay::OverlayProc()
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2019-08-16 16:37:45 +08:00
|
|
|
if (!Ready())
|
|
|
|
return;
|
|
|
|
|
2019-09-05 15:00:02 +08:00
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
|
|
|
|
|
|
ImGui::PushFont(font_notif);
|
|
|
|
BuildNotifications(io.DisplaySize.x, io.DisplaySize.y);
|
|
|
|
ImGui::PopFont();
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2019-08-14 20:56:57 +08:00
|
|
|
if (show_overlay)
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2020-02-15 04:03:20 +08:00
|
|
|
io.ConfigFlags &= ~ImGuiConfigFlags_NoMouseCursorChange;
|
2019-08-14 20:56:57 +08:00
|
|
|
// Set the overlay windows to the size of the game window
|
|
|
|
ImGui::SetNextWindowPos({ 0,0 });
|
2019-09-05 15:00:02 +08:00
|
|
|
ImGui::SetNextWindowSize({ static_cast<float>(io.DisplaySize.x),
|
|
|
|
static_cast<float>(io.DisplaySize.y) });
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2019-08-14 20:56:57 +08:00
|
|
|
ImGui::SetNextWindowBgAlpha(0.50);
|
2019-09-05 15:00:02 +08:00
|
|
|
|
|
|
|
ImGui::PushFont(font_default);
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2019-10-11 12:45:27 +08:00
|
|
|
bool show = true;
|
2019-10-11 06:25:44 +08:00
|
|
|
|
|
|
|
if (ImGui::Begin("SteamOverlay", &show, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus))
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2019-08-14 20:56:57 +08:00
|
|
|
ImGui::LabelText("##label", "Username: %s(%llu) playing %u",
|
|
|
|
settings->get_local_name(),
|
|
|
|
settings->get_local_steam_id().ConvertToUint64(),
|
|
|
|
settings->get_local_game_id().AppID());
|
2019-08-26 22:38:01 +08:00
|
|
|
ImGui::SameLine();
|
2019-08-27 21:38:07 +08:00
|
|
|
Base_Hook* hook = Renderer_Detector::Inst().get_renderer();
|
2019-08-26 22:38:01 +08:00
|
|
|
ImGui::LabelText("##label", "Renderer: %s", (hook == nullptr ? "Unknown" : hook->get_lib_name()));
|
2019-08-02 21:26:16 +08:00
|
|
|
|
2019-08-14 20:56:57 +08:00
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
ImGui::LabelText("##label", "Friends");
|
2020-01-26 22:46:57 +08:00
|
|
|
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-17 00:31:56 +08:00
|
|
|
if (!friends.empty())
|
2019-08-02 17:16:30 +08:00
|
|
|
{
|
2020-01-26 22:46:57 +08:00
|
|
|
ImGui::ListBoxHeader("##label", friends.size());
|
2019-09-01 02:49:07 +08:00
|
|
|
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i)
|
2019-08-14 20:56:57 +08:00
|
|
|
{
|
2019-10-11 19:10:48 +08:00
|
|
|
ImGui::PushID(i.second.id-base_friend_window_id+base_friend_item_id);
|
2019-08-17 00:31:56 +08:00
|
|
|
|
2019-10-14 22:35:36 +08:00
|
|
|
ImGui::Selectable(i.second.window_title.c_str(), false, ImGuiSelectableFlags_AllowDoubleClick);
|
2019-08-17 00:31:56 +08:00
|
|
|
BuildContextMenu(i.first, i.second);
|
|
|
|
if (ImGui::IsItemClicked() && ImGui::IsMouseDoubleClicked(0))
|
|
|
|
{
|
|
|
|
i.second.window_state |= window_state_show;
|
|
|
|
}
|
|
|
|
ImGui::PopID();
|
|
|
|
|
|
|
|
BuildFriendWindow(i.first, i.second);
|
|
|
|
});
|
|
|
|
ImGui::ListBoxFooter();
|
|
|
|
}
|
2019-08-14 20:56:57 +08:00
|
|
|
}
|
|
|
|
ImGui::End();
|
2019-09-05 15:00:02 +08:00
|
|
|
|
|
|
|
ImGui::PopFont();
|
2019-10-11 06:25:44 +08:00
|
|
|
|
|
|
|
if (!show)
|
|
|
|
ShowOverlay(false);
|
2020-02-15 04:03:20 +08:00
|
|
|
} else {
|
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange;
|
|
|
|
}
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
|
|
|
|
2019-08-03 18:58:48 +08:00
|
|
|
void Steam_Overlay::Callback(Common_Message *msg)
|
|
|
|
{
|
2020-01-21 00:47:12 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2019-08-03 18:58:48 +08: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
|
2019-08-14 20:56:57 +08:00
|
|
|
friend_info->second.chat_history.append("\x1""00FFFFFF", 9).append(steam_message.message()).append("\n", 1);
|
2019-08-17 00:31:56 +08:00
|
|
|
if (!(friend_info->second.window_state & window_state_show))
|
|
|
|
{
|
|
|
|
friend_info->second.window_state |= window_state_need_attention;
|
|
|
|
}
|
2019-09-05 01:31:31 +08:00
|
|
|
|
2019-11-08 22:52:38 +08:00
|
|
|
AddMessageNotification(friend_info->first.name() + " says: " + steam_message.message());
|
|
|
|
NotifyUser(friend_info->second);
|
2019-08-03 18:58:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 04:21:02 +08:00
|
|
|
void Steam_Overlay::RunCallbacks()
|
|
|
|
{
|
|
|
|
if (overlay_state_changed)
|
|
|
|
{
|
|
|
|
GameOverlayActivated_t data = { 0 };
|
|
|
|
data.m_bActive = show_overlay;
|
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
|
|
|
|
|
|
|
overlay_state_changed = false;
|
|
|
|
}
|
|
|
|
|
2019-08-01 17:15:38 +08:00
|
|
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
|
|
|
Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking;
|
|
|
|
|
2020-01-26 22:46:57 +08:00
|
|
|
i_have_lobby = IHaveLobby();
|
2020-01-26 04:23:16 +08:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(overlay_mutex);
|
2020-01-26 22:46:57 +08:00
|
|
|
std::for_each(friends.begin(), friends.end(), [this](std::pair<Friend const, friend_window_state> &i)
|
|
|
|
{
|
2020-02-03 08:07:30 +08:00
|
|
|
i.second.joinable = FriendJoinable(i);
|
2020-01-26 22:46:57 +08:00
|
|
|
});
|
|
|
|
|
2019-08-02 19:02:20 +08:00
|
|
|
while (!has_friend_action.empty())
|
2019-08-01 04:21:02 +08:00
|
|
|
{
|
2019-08-02 19:02:20 +08:00
|
|
|
auto friend_info = friends.find(has_friend_action.front());
|
|
|
|
if (friend_info != friends.end())
|
|
|
|
{
|
|
|
|
uint64 friend_id = friend_info->first.id();
|
2019-08-06 19:46:43 +08:00
|
|
|
// The user clicked on "Send"
|
2019-08-03 18:58:48 +08:00
|
|
|
if (friend_info->second.window_state & window_state_send_message)
|
|
|
|
{
|
|
|
|
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 19:46:43 +08:00
|
|
|
// Check if the message contains something else than blanks
|
2019-08-03 18:58:48 +08:00
|
|
|
if (printable_char != end_input)
|
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
|
2019-08-14 20:56:57 +08:00
|
|
|
friend_info->second.chat_history.append("\x1""00FF00FF", 9).append(input).append("\n", 1);
|
2019-08-03 18:58:48 +08:00
|
|
|
}
|
|
|
|
*input = 0; // Reset the input field
|
|
|
|
friend_info->second.window_state &= ~window_state_send_message;
|
|
|
|
}
|
2019-08-02 19:02:20 +08:00
|
|
|
// The user clicked on "Invite"
|
|
|
|
if (friend_info->second.window_state & window_state_invite)
|
|
|
|
{
|
|
|
|
std::string connect = steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect");
|
|
|
|
if (connect.length() > 0)
|
|
|
|
steamFriends->InviteUserToGame(friend_id, connect.c_str());
|
|
|
|
else if (settings->get_lobby().IsValid())
|
|
|
|
steamMatchmaking->InviteUserToLobby(settings->get_lobby(), friend_id);
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2019-08-02 19:02:20 +08:00
|
|
|
friend_info->second.window_state &= ~window_state_invite;
|
|
|
|
}
|
|
|
|
// The user clicked on "Join"
|
|
|
|
if (friend_info->second.window_state & window_state_join)
|
|
|
|
{
|
|
|
|
std::string connect = steamFriends->GetFriendRichPresence(friend_id, "connect");
|
2020-02-03 08:07:30 +08:00
|
|
|
// The user got a lobby invite and accepted it
|
|
|
|
if (friend_info->second.window_state & window_state_lobby_invite)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
} else
|
|
|
|
// The user got a rich presence invite and accepted it
|
|
|
|
if (friend_info->second.window_state & window_state_rich_invite)
|
2019-08-02 19:02:20 +08:00
|
|
|
{
|
|
|
|
GameRichPresenceJoinRequested_t data = {};
|
|
|
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
2020-02-03 08:07:30 +08:00
|
|
|
strncpy(data.m_rgchConnect, friend_info->second.connect, k_cchMaxRichPresenceValueLength - 1);
|
2019-08-02 19:02:20 +08:00
|
|
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
2020-02-03 08:07:30 +08:00
|
|
|
|
|
|
|
friend_info->second.window_state &= ~window_state_rich_invite;
|
|
|
|
} else if (connect.length() > 0)
|
2019-08-02 19:02:20 +08:00
|
|
|
{
|
2020-02-03 08:07:30 +08: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));
|
2019-08-02 19:02:20 +08:00
|
|
|
}
|
2019-08-01 04:21:02 +08:00
|
|
|
|
2019-08-02 19:02:20 +08:00
|
|
|
friend_info->second.window_state &= ~window_state_join;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
has_friend_action.pop();
|
2019-08-01 04:21:02 +08:00
|
|
|
}
|
2019-08-14 20:55:31 +08:00
|
|
|
}
|
|
|
|
|
2019-09-01 02:49:07 +08:00
|
|
|
#endif
|