diff --git a/engine/client/cl_gameui.c b/engine/client/cl_gameui.c index 0cb0a3c2..d4553c47 100644 --- a/engine/client/cl_gameui.c +++ b/engine/client/cl_gameui.c @@ -21,8 +21,6 @@ GNU General Public License for more details. #include "server.h" // !!svgame.hInstance #include "vid_common.h" -static MENUAPI GetMenuAPI; -static ADDTOUCHBUTTONTOLIST pfnAddTouchButtonToList; static void UI_UpdateUserinfo( void ); 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 ) { - 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 ); } -static ui_textfuncs_t gTextfuncs = +static ui_extendedfuncs_t gExtendedfuncs = { pfnEnableTextInput, Con_UtfProcessChar, @@ -1075,9 +1089,11 @@ void UI_UnloadProgs( void ) qboolean UI_LoadProgs( void ) { static ui_enginefuncs_t gpEngfuncs; - static ui_textfuncs_t gpTextfuncs; + static ui_extendedfuncs_t gpExtendedfuncs; static ui_globalvars_t gpGlobals; - UITEXTAPI GiveTextApi; + UIEXTENEDEDAPI GetExtAPI; + UITEXTAPI GiveTextApi; + MENUAPI GetMenuAPI; string dllpath; int i; @@ -1132,19 +1148,39 @@ qboolean UI_LoadProgs( void ) return false; } - if( ( GiveTextApi = (UITEXTAPI)COM_GetProcAddress( gameui.hInstance, "GiveTextAPI" ) ) ) + // 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 Text API initialized\n" ); - // make local copy of engfuncs to prevent overwrite it with user dll - memcpy( &gpTextfuncs, &gTextfuncs, sizeof( gpTextfuncs )); - if( GiveTextApi( &gpTextfuncs ) ) + 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; + } } - - pfnAddTouchButtonToList = (ADDTOUCHBUTTONTOLIST)COM_GetProcAddress( gameui.hInstance, "AddTouchButtonToList" ); - if( pfnAddTouchButtonToList ) + else // otherwise, fallback to old and deprecated extensions { - Con_Reportf( "UI_LoadProgs: AddTouchButtonToList call found\n" ); + if( ( GiveTextApi = (UITEXTAPI)COM_GetProcAddress( gameui.hInstance, "GiveTextAPI" ) ) ) + { + Con_Reportf( "UI_LoadProgs: extended text API found\n" ); + Con_Reportf( S_WARN "Text API is deprecated! If you are mod developer, consider moving to Extended Menu API!\n" ); + if( GiveTextApi( &gpExtendedfuncs ) ) // they are binary compatible, so we can just pass extended funcs API to menu + { + Con_Reportf( "UI_LoadProgs: extended text API initialized\n" ); + gameui.use_text_api = true; + } + } + + gameui.dllFuncs2.pfnAddTouchButtonToList = (ADDTOUCHBUTTONTOLIST)COM_GetProcAddress( gameui.hInstance, "AddTouchButtonToList" ); + if( gameui.dllFuncs2.pfnAddTouchButtonToList ) + { + 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 ); diff --git a/engine/menu_int.h b/engine/menu_int.h index 3dfd0f91..fbb0a008 100644 --- a/engine/menu_int.h +++ b/engine/menu_int.h @@ -172,13 +172,6 @@ typedef struct ui_enginefuncs_s int (*COM_RemoveFile)( const char *filepath ); } 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 { int (*pfnVidInit)( void ); @@ -199,12 +192,44 @@ typedef struct void (*pfnFinalCredits)( void ); // show credits + game end } 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 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 GENERIC_UPDATE_PAGE "GenericUpdatePage"