gbe_fork/overlay_experimental/overlay/steam_overlay.h

268 lines
8.0 KiB
C
Raw Normal View History

#ifndef __INCLUDED_STEAM_OVERLAY_H__
#define __INCLUDED_STEAM_OVERLAY_H__
2019-07-26 05:33:07 +08:00
2023-12-27 15:15:10 +08:00
#include "dll/base.h"
2019-08-02 17:16:30 +08:00
#include <map>
2019-08-02 19:02:20 +08:00
#include <queue>
2019-07-26 05:33:07 +08:00
2019-08-03 18:58:48 +08:00
static constexpr size_t max_chat_len = 768;
2019-08-02 19:02:20 +08:00
enum window_state
{
window_state_none = 0,
window_state_show = 1<<0,
window_state_invite = 1<<1,
window_state_join = 1<<2,
window_state_lobby_invite = 1<<3,
window_state_rich_invite = 1<<4,
window_state_send_message = 1<<5,
window_state_need_attention = 1<<6,
};
2019-07-26 05:33:07 +08:00
2019-08-02 19:02:20 +08:00
struct friend_window_state
2019-08-02 17:16:30 +08:00
{
int id;
2019-08-02 19:02:20 +08:00
uint8 window_state;
std::string window_title;
2019-08-03 18:58:48 +08:00
union // The invitation (if any)
2019-08-02 17:16:30 +08:00
{
uint64 lobbyId;
char connect[k_cchMaxRichPresenceValueLength];
};
2019-08-03 18:58:48 +08:00
std::string chat_history;
char chat_input[max_chat_len];
2020-01-26 22:46:57 +08:00
bool joinable;
2019-08-02 17:16:30 +08:00
};
struct Friend_Less
{
bool operator()(const Friend& lhs, const Friend& rhs) const
{
return lhs.id() < rhs.id();
}
};
enum notification_type
{
notification_type_message = 0,
notification_type_invite,
notification_type_achievement,
notification_type_auto_accept_invite,
};
2019-09-05 01:31:31 +08:00
struct Notification
{
static constexpr float width_percent = 0.25f; // percentage from total width
static constexpr float height = 5.0f;
2019-09-05 01:31:31 +08:00
static constexpr std::chrono::milliseconds fade_in = std::chrono::milliseconds(2000);
static constexpr std::chrono::milliseconds fade_out = std::chrono::milliseconds(2000);
static constexpr std::chrono::milliseconds show_time = std::chrono::milliseconds(6000) + fade_in + fade_out;
static constexpr std::chrono::milliseconds fade_out_start = show_time - fade_out;
int id;
uint8 type;
2019-09-05 01:31:31 +08:00
std::chrono::seconds start_time;
std::string message;
std::pair<const Friend, friend_window_state>* frd;
std::weak_ptr<uint64_t> icon;
2019-09-05 01:31:31 +08:00
};
struct Overlay_Achievement
{
std::string name;
std::string title;
std::string description;
std::string icon_name;
std::string icon_gray_name;
bool hidden;
bool achieved;
uint32 unlock_time;
std::weak_ptr<uint64_t> icon;
std::weak_ptr<uint64_t> icon_gray;
constexpr const static int ICON_LOAD_MAX_TRIALS = 3;
uint8_t icon_load_trials = ICON_LOAD_MAX_TRIALS;
uint8_t icon_gray_load_trials = ICON_LOAD_MAX_TRIALS;
};
2019-08-14 20:55:31 +08:00
#ifdef EMU_OVERLAY
#include <future>
#include <atomic>
#include "InGameOverlay/RendererHook.h"
struct NotificationsIndexes {
int top_left = 0, top_center = 0, top_right = 0;
int bot_left = 0, bot_center = 0, bot_right = 0;
};
2019-07-26 05:33:07 +08:00
class Steam_Overlay
{
Settings* settings;
SteamCallResults* callback_results;
SteamCallBacks* callbacks;
RunEveryRunCB* run_every_runcb;
Networking* network;
2019-08-02 17:16:30 +08:00
// friend id, show client window (to chat and accept invite maybe)
2019-08-02 19:02:20 +08:00
std::map<Friend, friend_window_state, Friend_Less> friends;
2019-07-26 05:33:07 +08:00
// avoids spam loading on failure
std::atomic<int32_t> load_achievements_trials = 3;
bool is_ready = false;
2019-07-26 05:33:07 +08:00
bool show_overlay;
ENotificationPosition notif_position;
int h_inset, v_inset;
std::string show_url;
std::vector<Overlay_Achievement> achievements;
bool show_achievements, show_settings;
2023-12-29 09:55:11 +08:00
// disable input when force_*.txt file is used
bool disable_user_input;
// warn when force_*.txt file is used
bool warn_forced_setting;
// warn when using local save
bool warn_local_save;
// warn when app ID = 0
bool warn_bad_appid;
char username_text[256];
std::atomic<bool> save_settings;
int current_language;
std::string warning_message;
2019-07-26 05:33:07 +08:00
// Callback infos
2019-08-02 19:02:20 +08:00
std::queue<Friend> has_friend_action;
2019-09-05 01:31:31 +08:00
std::vector<Notification> notifications;
// used when the button "Invite all" is clicked
std::atomic<bool> invite_all_friends_clicked = false;
bool overlay_state_changed;
2020-01-26 22:46:57 +08:00
std::atomic<bool> i_have_lobby;
InGameOverlay::RendererHook_t *_renderer;
2019-07-26 05:33:07 +08:00
Steam_Overlay(Steam_Overlay const&) = delete;
Steam_Overlay(Steam_Overlay&&) = delete;
Steam_Overlay& operator=(Steam_Overlay const&) = delete;
Steam_Overlay& operator=(Steam_Overlay&&) = delete;
static void steam_overlay_run_every_runcb(void* object);
2019-08-03 18:58:48 +08:00
static void steam_overlay_callback(void* object, Common_Message* msg);
void Callback(Common_Message* msg);
void RunCallbacks();
2019-07-26 05:33:07 +08:00
bool FriendJoinable(std::pair<const Friend, friend_window_state> &f);
bool IHaveLobby();
bool submit_notification(notification_type type, const std::string &msg, std::pair<const Friend, friend_window_state> *frd = nullptr, const std::weak_ptr<uint64_t> &icon = {});
void NotifySoundUserInvite(friend_window_state& friend_state);
void NotifySoundUserAchievement();
void NotifySoundAutoAcceptFriendInvite();
2019-09-05 01:31:31 +08:00
2019-08-02 21:26:16 +08:00
// Right click on friend
void BuildContextMenu(Friend const& frd, friend_window_state &state);
// Double click on friend
void BuildFriendWindow(Friend const& frd, friend_window_state &state);
// Notifications like achievements, chat and invitations
void SetNextNotificationPos(float width, float height, float font_size, notification_type type, struct NotificationsIndexes &idx);
2019-09-05 01:31:31 +08:00
void BuildNotifications(int width, int height);
// invite a single friend
void InviteFriend(uint64 friend_id, class Steam_Friends* steamFriends, class Steam_Matchmaking* steamMatchmaking);
void renderer_hook_init_thread();
void CreateFonts();
void LoadAudio();
void HookReady(bool ready);
void allow_renderer_frame_processing(bool state);
2019-07-26 05:33:07 +08:00
public:
Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking *network);
2019-07-26 05:33:07 +08:00
~Steam_Overlay();
2019-07-26 05:33:07 +08:00
bool Ready() const;
2019-07-26 05:33:07 +08:00
bool NeedPresent() const;
2019-07-26 05:33:07 +08:00
void SetNotificationPosition(ENotificationPosition eNotificationPosition);
2019-07-26 05:33:07 +08:00
void SetNotificationInset(int nHorizontalInset, int nVerticalInset);
void SetupOverlay();
void UnSetupOverlay();
2019-07-26 05:33:07 +08:00
void OverlayProc();
2019-07-26 05:33:07 +08:00
void OpenOverlayInvite(CSteamID lobbyId);
void OpenOverlay(const char* pchDialog);
void OpenOverlayWebpage(const char* pchURL);
2019-07-26 05:33:07 +08:00
bool ShowOverlay() const;
void ShowOverlay(bool state);
bool OpenOverlayHook(bool toggle);
2019-08-02 17:16:30 +08:00
void SetLobbyInvite(Friend friendId, uint64 lobbyId);
void SetRichInvite(Friend friendId, const char* connect_str);
2019-08-02 17:16:30 +08:00
void FriendConnect(Friend _friend);
void FriendDisconnect(Friend _friend);
2019-09-05 01:31:31 +08:00
void AddChatMessageNotification(std::string const& message);
void AddAchievementNotification(nlohmann::json const& ach);
void AddInviteNotification(std::pair<const Friend, friend_window_state> &wnd_state);
void AddAutoAcceptInviteNotification();
};
2019-07-26 05:33:07 +08:00
2019-08-14 20:55:31 +08:00
#else
class Steam_Overlay
{
public:
Steam_Overlay(Settings* settings, SteamCallResults* callback_results, SteamCallBacks* callbacks, RunEveryRunCB* run_every_runcb, Networking* network) {}
2019-08-15 00:11:00 +08:00
~Steam_Overlay() {}
2019-08-14 20:55:31 +08:00
2019-08-15 00:11:00 +08:00
bool Ready() const { return false; }
2019-08-14 20:55:31 +08:00
bool NeedPresent() const { return false; }
void SetNotificationPosition(ENotificationPosition eNotificationPosition) {}
void SetNotificationInset(int nHorizontalInset, int nVerticalInset) {}
void SetupOverlay() {}
void UnSetupOverlay() {}
2019-08-14 20:55:31 +08:00
void HookReady(bool ready) {}
2019-08-14 20:55:31 +08:00
void CreateFonts() {}
void OverlayProc() {}
2019-08-14 20:55:31 +08:00
void OpenOverlayInvite(CSteamID lobbyId) {}
void OpenOverlay(const char* pchDialog) {}
void OpenOverlayWebpage(const char* pchURL) {}
2019-08-14 20:55:31 +08:00
bool ShowOverlay() const { return false; }
2019-08-14 20:55:31 +08:00
void ShowOverlay(bool state) {}
bool OpenOverlayHook(bool toggle) { return false; }
2019-08-14 20:55:31 +08:00
void SetLobbyInvite(Friend friendId, uint64 lobbyId) {}
void SetRichInvite(Friend friendId, const char* connect_str) {}
void FriendConnect(Friend _friend) {}
void FriendDisconnect(Friend _friend) {}
2019-10-16 01:08:14 +08:00
void AddChatMessageNotification(std::string const& message) {}
2019-10-16 01:08:14 +08:00
void AddAchievementNotification(nlohmann::json const& ach) {}
void AddInviteNotification(std::pair<const Friend, friend_window_state> &wnd_state) {}
void AddAutoAcceptInviteNotification() {}
2019-08-14 20:55:31 +08:00
};
#endif
#endif//__INCLUDED_STEAM_OVERLAY_H__