Browse Source

engine: gameui: add new extended API and declare old engine menu extensions deprecated

pull/2/head
Alibek Omarov 6 years ago
parent
commit
9e30fc253f
  1. 60
      engine/client/cl_gameui.c
  2. 43
      engine/menu_int.h

60
engine/client/cl_gameui.c

@ -21,8 +21,6 @@ GNU General Public License for more details.
#include "server.h" // !!svgame.hInstance #include "server.h" // !!svgame.hInstance
#include "vid_common.h" #include "vid_common.h"
static MENUAPI GetMenuAPI;
static ADDTOUCHBUTTONTOLIST pfnAddTouchButtonToList;
static void UI_UpdateUserinfo( void ); static void UI_UpdateUserinfo( void );
gameui_static_t gameui; gameui_static_t gameui;
@ -499,9 +497,25 @@ send button parameters to menu
*/ */
void UI_AddTouchButtonToList( const char *name, const char *texture, const char *command, unsigned char *color, int flags ) void UI_AddTouchButtonToList( const char *name, const char *texture, const char *command, unsigned char *color, int flags )
{ {
if( pfnAddTouchButtonToList ) if( gameui.dllFuncs2.pfnAddTouchButtonToList )
{ {
pfnAddTouchButtonToList( name, texture, command, color, flags ); gameui.dllFuncs2.pfnAddTouchButtonToList( name, texture, command, color, flags );
}
}
void UI_ResetPing( void )
{
if( gameui.dllFuncs2.pfnResetPing )
{
gameui.dllFuncs2.pfnResetPing( );
}
}
void UI_ShowConnectionWarning( void )
{
if( gameui.dllFuncs2.pfnShowConnectionWarning )
{
gameui.dllFuncs2.pfnShowConnectionWarning();
} }
} }
@ -1047,7 +1061,7 @@ static void pfnEnableTextInput( int enable )
Key_EnableTextInput( enable, false ); Key_EnableTextInput( enable, false );
} }
static ui_textfuncs_t gTextfuncs = static ui_extendedfuncs_t gExtendedfuncs =
{ {
pfnEnableTextInput, pfnEnableTextInput,
Con_UtfProcessChar, Con_UtfProcessChar,
@ -1075,9 +1089,11 @@ void UI_UnloadProgs( void )
qboolean UI_LoadProgs( void ) qboolean UI_LoadProgs( void )
{ {
static ui_enginefuncs_t gpEngfuncs; static ui_enginefuncs_t gpEngfuncs;
static ui_textfuncs_t gpTextfuncs; static ui_extendedfuncs_t gpExtendedfuncs;
static ui_globalvars_t gpGlobals; static ui_globalvars_t gpGlobals;
UIEXTENEDEDAPI GetExtAPI;
UITEXTAPI GiveTextApi; UITEXTAPI GiveTextApi;
MENUAPI GetMenuAPI;
string dllpath; string dllpath;
int i; int i;
@ -1132,19 +1148,39 @@ qboolean UI_LoadProgs( void )
return false; return false;
} }
// make local copy of engfuncs to prevent overwrite it with user dll
memcpy( &gpExtendedfuncs, &gExtendedfuncs, sizeof( gExtendedfuncs ));
memset( &gameui.dllFuncs2, 0, sizeof( gameui.dllFuncs2 ));
// try to initialize new extended API
if( ( GetExtAPI = (UIEXTENEDEDAPI)COM_GetProcAddress( gameui.hInstance, "GetExtAPI" ) ) )
{
Con_Reportf( "UI_LoadProgs: extended Menu API found\n" );
if( GetExtAPI( MENU_EXTENDED_API_VERSION, &gameui.dllFuncs2, &gpExtendedfuncs ) )
{
Con_Reportf( "UI_LoadProgs: extended Menu API initialized\n" );
gameui.use_text_api = true;
}
}
else // otherwise, fallback to old and deprecated extensions
{
if( ( GiveTextApi = (UITEXTAPI)COM_GetProcAddress( gameui.hInstance, "GiveTextAPI" ) ) ) if( ( GiveTextApi = (UITEXTAPI)COM_GetProcAddress( gameui.hInstance, "GiveTextAPI" ) ) )
{ {
Con_Reportf( "UI_LoadProgs: extended Text API initialized\n" ); Con_Reportf( "UI_LoadProgs: extended text API found\n" );
// make local copy of engfuncs to prevent overwrite it with user dll Con_Reportf( S_WARN "Text API is deprecated! If you are mod developer, consider moving to Extended Menu API!\n" );
memcpy( &gpTextfuncs, &gTextfuncs, sizeof( gpTextfuncs )); if( GiveTextApi( &gpExtendedfuncs ) ) // they are binary compatible, so we can just pass extended funcs API to menu
if( GiveTextApi( &gpTextfuncs ) ) {
Con_Reportf( "UI_LoadProgs: extended text API initialized\n" );
gameui.use_text_api = true; gameui.use_text_api = true;
} }
}
pfnAddTouchButtonToList = (ADDTOUCHBUTTONTOLIST)COM_GetProcAddress( gameui.hInstance, "AddTouchButtonToList" ); gameui.dllFuncs2.pfnAddTouchButtonToList = (ADDTOUCHBUTTONTOLIST)COM_GetProcAddress( gameui.hInstance, "AddTouchButtonToList" );
if( pfnAddTouchButtonToList ) if( gameui.dllFuncs2.pfnAddTouchButtonToList )
{ {
Con_Reportf( "UI_LoadProgs: AddTouchButtonToList call found\n" ); Con_Reportf( "UI_LoadProgs: AddTouchButtonToList call found\n" );
Con_Reportf( S_WARN "AddTouchButtonToList is deprecated! If you are mod developer, consider moving to Extended Menu API!\n" );
}
} }
Cvar_FullSet( "host_gameuiloaded", "1", FCVAR_READ_ONLY ); Cvar_FullSet( "host_gameuiloaded", "1", FCVAR_READ_ONLY );

43
engine/menu_int.h

@ -172,13 +172,6 @@ typedef struct ui_enginefuncs_s
int (*COM_RemoveFile)( const char *filepath ); int (*COM_RemoveFile)( const char *filepath );
} ui_enginefuncs_t; } ui_enginefuncs_t;
typedef struct ui_textfuncs_s {
void (*pfnEnableTextInput)( int enable );
int (*pfnUtfProcessChar) ( int ch );
int (*pfnUtfMoveLeft) ( char *str, int pos );
int (*pfnUtfMoveRight) ( char *str, int pos, int length );
} ui_textfuncs_t;
typedef struct typedef struct
{ {
int (*pfnVidInit)( void ); int (*pfnVidInit)( void );
@ -199,12 +192,44 @@ typedef struct
void (*pfnFinalCredits)( void ); // show credits + game end void (*pfnFinalCredits)( void ); // show credits + game end
} UI_FUNCTIONS; } UI_FUNCTIONS;
typedef int (*MENUAPI)( UI_FUNCTIONS *pFunctionTable, ui_enginefuncs_t* engfuncs, ui_globalvars_t *pGlobals ); #define MENU_EXTENDED_API_VERSION 1
typedef struct ui_extendedfuncs_s {
// text functions, frozen
void (*pfnEnableTextInput)( int enable );
int (*pfnUtfProcessChar) ( int ch );
int (*pfnUtfMoveLeft) ( char *str, int pos );
int (*pfnUtfMoveRight) ( char *str, int pos, int length );
typedef int (*UITEXTAPI)( ui_textfuncs_t* engfuncs ); // new engine extended api start here
} ui_extendedfuncs_t;
// deprecated export from old engine
typedef void (*ADDTOUCHBUTTONTOLIST)( const char *name, const char *texture, const char *command, unsigned char *color, int flags ); typedef void (*ADDTOUCHBUTTONTOLIST)( const char *name, const char *texture, const char *command, unsigned char *color, int flags );
typedef struct
{
ADDTOUCHBUTTONTOLIST pfnAddTouchButtonToList;
void (*pfnResetPing)( void );
void (*pfnShowConnectionWarning)( void );
void (*pfnShowUpdateDialog)( int preferStore );
void (*pfnShowMessageBox)( const char *text );
void (*pfnConnectionProgress_Disconnect)( void );
void (*pfnConnectionProgress_Download)( const char *pszFileName, const char *pszServerName, int iCurrent, int iTotal, const char *comment );
void (*pfnConnectionProgress_DownloadEnd)( void );
void (*pfnConnectionProgress_Precache)( void );
void (*pfnConnectionProgress_Connect)( const char *server ); // NULL for local server
void (*pfnConnectionProgress_ChangeLevel)( void );
void (*pfnConnectionProgress_ParseServerInfo)( const char *server );
} UI_EXTENDED_FUNCTIONS;
typedef int (*MENUAPI)( UI_FUNCTIONS *pFunctionTable, ui_enginefuncs_t* engfuncs, ui_globalvars_t *pGlobals );
typedef int (*UIEXTENEDEDAPI)( int version, UI_EXTENDED_FUNCTIONS *pFunctionTable, ui_extendedfuncs_t *engfuncs );
// deprecated interface from old engine
typedef int (*UITEXTAPI)( ui_extendedfuncs_t* engfuncs );
#define PLATFORM_UPDATE_PAGE "PlatformUpdatePage" #define PLATFORM_UPDATE_PAGE "PlatformUpdatePage"
#define GENERIC_UPDATE_PAGE "GenericUpdatePage" #define GENERIC_UPDATE_PAGE "GenericUpdatePage"

Loading…
Cancel
Save