Platform: Go over some of the RichPresence APIs I was working on.

This commit is contained in:
Marco Cawthorne 2022-04-25 17:00:13 -07:00
parent 2d403202b9
commit 36b9661abd
Signed by: eukara
GPG Key ID: C196CD8BA993248A
11 changed files with 85 additions and 3 deletions

View File

@ -49,6 +49,7 @@ int g_active;
float g_btnofs;
float frametime;
var int g_background = FALSE;
var int g_gamestate;
/* Font IDs */
font_s font_label;

View File

@ -113,6 +113,7 @@ m_init(void)
registercommand("menu_customgame");
registercommand("map_background");
registercommand("menu_musicstart");
registercommand("richpresence_dump");
Font_Load("fonts/fontcon.font", font_console);
Font_Load("fonts/menu_label.font", font_label);
@ -229,6 +230,14 @@ m_draw(vector screensize)
/* to prevent TCP timeouts */
menu_chatrooms_keepalive();
/* rich presence sanity check */
if (RichPresence_WasSet() == false) {
if (clientstate() == 2)
RichPresence_Set("status", "In-game (Unknown)");
else
RichPresence_Set("status", "Main Menu");
}
if (!g_active && !g_background) {
/* make sure we're redirecting input when the background's gone */
if (getkeydest() != KEY_GAME) {
@ -351,6 +360,9 @@ m_consolecommand(string cmd)
{
tokenize(cmd);
switch (argv(0)) {
case "richpresence_dump":
RichPresence_DumpInfo();
break;
case "menu_musicstart":
Music_MenuStart();
break;

View File

@ -46,6 +46,8 @@ create_btnok_start(void)
localcmd(sprintf("password %s\n", create_tbPassword.m_text));
localcmd(sprintf("map %s\n", startmap));
g_menupage = PAGE_MULTIPLAYER;
RichPresence_Clear();
RichPresence_Set("status", sprintf("Multiplayer (LAN): %s", startmap));
}
/* Strip .bsp extension before submitting */
startmap = substring(create_lbMaps.GetSelectedItem(), 0, -5);

View File

@ -24,13 +24,18 @@ createinet_btnok_start(void)
{
static string startmap;
static void createinet_btnok_end(void) {
localcmd("stopmusic\nset sv_public 2\n");
int r = random(1000,9999);
localcmd(sprintf("stopmusic\nset sv_public /%i\n", r));
localcmd(sprintf("hostname %s\n", create_tbHostname.m_text));
localcmd(sprintf("sv_playerslots %s\n", create_tbMaxplayers.m_text));
localcmd(sprintf("password %s\n", create_tbPassword.m_text));
localcmd(sprintf("map %s\n", startmap));
g_menupage = PAGE_MULTIPLAYER;
cr_input_enter(sprintf("ACTION is now hosting '%s' on the map %s\n", create_tbHostname.m_text, startmap));
RichPresence_Clear();
RichPresence_Set("status", sprintf("Multiplayer: %s", startmap));
RichPresence_Set("connect", sprintf("+connect /%i", r));
}
/* Strip .bsp extension before submitting */

View File

@ -48,6 +48,8 @@ inet_btnjoin(void)
if (addr) {
localcmd("stopmusic\n");
localcmd(sprintf("connect %s\n", addr));
RichPresence_Clear();
RichPresence_Set("connect", strcat("+connect ", addr));
g_menupage = PAGE_MULTIPLAYER;
}
}

View File

@ -39,6 +39,8 @@ lan_btnjoin(void)
if (addr) {
localcmd("stopmusic\n");
localcmd(sprintf("connect %s\n", addr));
RichPresence_Clear();
RichPresence_Set("status", sprintf("Multiplayer (LAN): %s", "Unknown"));
g_menupage = PAGE_MULTIPLAYER;
}
}

View File

@ -79,6 +79,10 @@ btn_training(void)
localcmd("stopmusic\n");
localcmd("maxplayers 1\n");
localcmd(games[gameinfo_current].trainingmap);
/* TODO: Some mods may choose to put movies in this... */
RichPresence_Clear();
RichPresence_Set("status", "Singleplayer: Training");
}
void

View File

@ -168,6 +168,7 @@ void
mp_btndisconnect(void)
{
localcmd("disconnect\n");
RichPresence_Clear();
}
void

View File

@ -29,6 +29,8 @@ ng_btneasy_start(void)
localcmd("stopmusic\n");
localcmd("set skill 1; maxplayers 1\n");
localcmd(games[gameinfo_current].startmap);
RichPresence_Clear();
RichPresence_Set("status", "Singleplayer: Easy");
}
localsound("../media/launch_upmenu1.wav");
header.SetStartEndPos(45,45,70,208);
@ -47,6 +49,8 @@ ng_btnnormal_start(void)
localcmd("stopmusic\n");
localcmd("set skill 2; maxplayers 1\n");
localcmd(games[gameinfo_current].startmap);
RichPresence_Clear();
RichPresence_Set("status", "Singleplayer: Normal");
}
localsound("../media/launch_upmenu1.wav");
header.SetStartEndPos(45,45,70,208);
@ -65,6 +69,8 @@ ng_btnhard_start(void)
localcmd("stopmusic\n");
localcmd("set skill 3; maxplayers 1\n");
localcmd(games[gameinfo_current].startmap);
RichPresence_Clear();
RichPresence_Set("status", "Singleplayer: Hard");
}
localsound("../media/launch_upmenu1.wav");
header.SetStartEndPos(45,45,70,208);

View File

@ -15,5 +15,7 @@
*/
void RichPresence_Set(string strKey, string strValue);
void RichPresence_DumpInfo(void);
void RichPresence_Clear(void);
//string RichPresence_Get(string strKey);
bool RichPresence_WasSet(void);

View File

@ -1,8 +1,53 @@
/* extremely primitive rich presence stuff that'll be extended later down the line or something */
#define RICHPRESENCE_KEYS 2
typedef enum
{
RICHPRES_STATUS,
RICHPRES_CONNECT
} richpresence_e;
string g_richpres[RICHPRESENCE_KEYS];
var bool g_richpresence_set = false;
void
RichPresence_Set(string strKey, string strValue)
{
switch (strKey) {
/* just fluff */
case "status":
g_richpres[RICHPRES_STATUS] = strValue;
//print(sprintf("^2Client Rich Presence: Status changed to '%s'\n", strValue));
break;
/* a command line that'll allow others to join our game */
case "connect":
g_richpres[RICHPRES_CONNECT] = strValue;
//print(sprintf("^2Client Rich Presence: Connection parm changed to '%s'\n", strValue));
break;
}
g_richpresence_set = true;
};
void
RichPresence_Clear(void)
{
for (int i = 0; i < RICHPRESENCE_KEYS; i++)
g_richpres[i] = "";
g_richpresence_set = false;
}
void
RichPresence_DumpInfo(void)
{
for (int i = 0; i < RICHPRESENCE_KEYS; i++)
print(sprintf("[%i] %s\n", i, g_richpres[i]));
}
bool
RichPresence_WasSet(void)
{
return g_richpresence_set;
}