win_discord: configurability

This commit is contained in:
David Hrdlička
2019-12-04 21:55:35 +01:00
parent a77a7a15db
commit 539ef0044a
10 changed files with 89 additions and 20 deletions

View File

@@ -115,6 +115,9 @@ extern int network_type; /* (C) net provider type */
extern int network_card; /* (C) net interface num */
extern char network_host[522]; /* (C) host network intf */
extern int hdd_format_type; /* (C) hard disk file format */
#ifdef USE_DISCORD
extern int enable_discord; /* (C) enable Discord integration */
#endif
extern int is_pentium; /* TODO: Move back to cpu/cpu.h when it's figured out,
how to remove that hack from the ET4000/W32p. */

View File

@@ -486,6 +486,10 @@ load_general(void)
*/
plat_langid = config_get_hex16(cat, "language", 0x0409);
#endif
#if USE_DISCORD
enable_discord = !!config_get_int(cat, "enable_discord", 0);
#endif
}
@@ -1387,6 +1391,13 @@ save_general(void)
config_set_hex16(cat, "language", plat_langid);
#endif
#if USE_DISCORD
if (enable_discord)
config_set_int(cat, "enable_discord", enable_discord);
else
config_delete_var(cat, "enable_discord");
#endif
delete_section_if_empty(cat);
}

View File

@@ -131,7 +131,10 @@ int cpu_manufacturer = 0, /* (C) cpu manufacturer */
cpu_use_dynarec = 0, /* (C) cpu uses/needs Dyna */
cpu = 3, /* (C) cpu type */
enable_external_fpu = 0; /* (C) enable external FPU */
int time_sync = 0; /* (C) enable time sync */
int time_sync = 0; /* (C) enable time sync */
#ifdef USE_DISCORD
int enable_discord = 0; /* (C) enable Discord integration */
#endif
/* Statistics. */
extern int

View File

@@ -120,6 +120,10 @@ BEGIN
BEGIN
MENUITEM "&Settings...", IDM_CONFIG
MENUITEM "&Update status bar icons", IDM_UPDATE_ICONS
# ifdef USE_DISCORD
MENUITEM SEPARATOR
MENUITEM "Enable &Discord integration", IDM_DISCORD
# endif
MENUITEM SEPARATOR
MENUITEM "Take s&creenshot\tCtrl+F11", IDM_ACTION_SCREENSHOT
END

View File

@@ -428,6 +428,7 @@ endif
ifeq ($(DISCORD), y)
OPTS += -DUSE_DISCORD
RFLAGS += -DUSE_DISCORD
DISCORDOBJ := win_discord.o
endif

View File

@@ -434,6 +434,7 @@ endif
ifeq ($(DISCORD), y)
OPTS += -DUSE_DISCORD
RFLAGS += -DUSE_DISCORD
DISCORDOBJ := win_discord.o
endif

View File

@@ -301,6 +301,10 @@
#define IDM_VID_GRAY_GREEN 40083
#define IDM_VID_GRAY_WHITE 40084
#ifdef USE_DISCORD
#define IDM_DISCORD 40090
#endif
#define IDM_LOG_BREAKPOINT 51201
#define IDM_DUMP_VRAM 51202 // should be an Action

View File

@@ -36,6 +36,8 @@
#define PATH_DISCORD_DLL "discord_game_sdk.dll"
int discord_loaded = 0;
static void *discord_handle = NULL;
static struct IDiscordCore *discord_core = NULL;
static struct IDiscordActivityManager *discord_activities = NULL;
@@ -114,25 +116,36 @@ discord_update_activity(int paused)
discord_activities->update_activity(discord_activities, &activity, NULL, NULL);
}
void
discord_init()
int
discord_load()
{
enum EDiscordResult result;
struct DiscordCreateParams params;
discord_log("win_discord: init\n");
if (discord_handle != NULL)
return(1);
// Try to load the DLL
if (discord_handle == NULL)
discord_handle = dynld_module(PATH_DISCORD_DLL, discord_imports);
discord_handle = dynld_module(PATH_DISCORD_DLL, discord_imports);
if (discord_handle == NULL)
{
discord_log("win_discord: couldn't load " PATH_DISCORD_DLL "\n");
discord_close();
return;
return(0);
}
discord_loaded = 1;
return(1);
}
void
discord_init()
{
enum EDiscordResult result;
struct DiscordCreateParams params;
if(discord_handle == NULL)
return;
DiscordCreateParamsSetDefault(&params);
params.client_id = 651478134352248832;
params.flags = DiscordCreateFlags_NoRequireDiscord;

View File

@@ -17,6 +17,9 @@
#ifndef WIN_DISCORD_H
# define WIN_DISCORD_H
extern int discord_loaded;
extern int discord_load();
extern void discord_init();
extern void discord_close();
extern void discord_update_activity(int paused);

View File

@@ -237,6 +237,13 @@ ResetAllMenus(void)
CheckMenuItem(menuMain, IDM_VID_CGACON, vid_cga_contrast?MF_CHECKED:MF_UNCHECKED);
CheckMenuItem(menuMain, IDM_VID_GRAYCT_601+video_graytype, MF_CHECKED);
CheckMenuItem(menuMain, IDM_VID_GRAY_RGB+video_grayscale, MF_CHECKED);
#ifdef USE_DISCORD
if (discord_loaded)
CheckMenuItem(menuMain, IDM_DISCORD, enable_discord ? MF_CHECKED : MF_UNCHECKED);
else
EnableMenuItem(menuMain, IDM_DISCORD, MF_DISABLED);
#endif
}
@@ -530,6 +537,19 @@ MainWindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
config_save();
break;
#ifdef USE_DISCORD
case IDM_DISCORD:
if (! discord_loaded) break;
enable_discord ^= 1;
CheckMenuItem(hmenu, IDM_DISCORD, enable_discord ? MF_CHECKED : MF_UNCHECKED);
if(enable_discord) {
discord_init();
discord_update_activity(dopause);
} else
discord_close();
break;
#endif
#ifdef ENABLE_LOG_TOGGLES
# ifdef ENABLE_BUSLOGIC_LOG
case IDM_LOG_BUSLOGIC:
@@ -845,6 +865,18 @@ ui_init(int nCmdShow)
return(0);
}
#ifdef USE_DISCORD
if(! discord_load()) {
enable_discord = 0;
} else if (enable_discord) {
/* Initialize the Discord API */
discord_init();
/* Update Discord status */
discord_update_activity(dopause);
}
#endif
/* Create our main window's class and register it. */
wincl.hInstance = hinstance;
wincl.lpszClassName = CLASS_NAME;
@@ -995,14 +1027,6 @@ ui_init(int nCmdShow)
if (source_hwnd)
PostMessage((HWND) (uintptr_t) source_hwnd, WM_SENDHWND, (WPARAM) unique_id, (LPARAM) hwndMain);
#ifdef USE_DISCORD
/* Initialize the Discord API */
discord_init();
/* Update Discord status */
discord_update_activity(dopause);
#endif
/*
* Everything has been configured, and all seems to work,
* so now it is time to start the main thread to do some
@@ -1042,7 +1066,8 @@ ui_init(int nCmdShow)
#ifdef USE_DISCORD
/* Run Discord API callbacks */
discord_run_callbacks();
if (enable_discord)
discord_run_callbacks();
#endif
}
@@ -1124,7 +1149,8 @@ plat_pause(int p)
#if USE_DISCORD
/* Update Discord status */
discord_update_activity(dopause);
if(enable_discord)
discord_update_activity(dopause);
#endif
/* Send the WM to a manager if needed. */