Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 68 additions & 5 deletions cl_dll/cdll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
#include "pm_shared.h"

#include <string.h>
#include "interface.h" // not used here
#include "interface.h"
#include "render_api.h"
#include "mobility_int.h"
#include "vgui_parser.h"
#include "cl_dll/IGameMenuExports.h"

cl_enginefunc_t gEngfuncs = { };
render_api_t gRenderAPI = { };
Expand All @@ -38,6 +39,31 @@ CHud gHUD;
int g_iXash = 0; // indicates a buildnum
int g_iMobileAPIVersion = 0;

IGameMenuExports *g_pMenu = nullptr;

static IGameMenuExports *GetNativeMenuExports( void )
{
if( !g_iMobileAPIVersion || !gMobileAPI.pfnGetNativeObject )
return nullptr;

void *nativeFactory = gMobileAPI.pfnGetNativeObject( "MenuFactory" );
if( !nativeFactory )
return nullptr;

CreateInterfaceFn menuFactory = reinterpret_cast<CreateInterfaceFn>( nativeFactory );
return static_cast<IGameMenuExports *>( menuFactory( GAMEMENUEXPORTS_INTERFACE_VERSION, NULL ) );
}

static void LoadMenuInterface( void )
{
if( g_pMenu )
return;

g_pMenu = GetNativeMenuExports();
if( !g_pMenu )
gEngfuncs.Con_Printf( "Error: native object \"MenuFactory\" is unavailable\n" );
}

void InitInput (void);
void Game_HookEvents( void );
void IN_Commands( void );
Expand Down Expand Up @@ -205,8 +231,15 @@ the hud variables.

void DLLEXPORT HUD_Init( void )
{
LoadMenuInterface();
InitInput();
gHUD.Init();

// Initialize menu if it's loaded
if( g_pMenu && !g_pMenu->Initialize( Sys_GetFactoryThis() ) )
{
gEngfuncs.Con_Printf( "Warning: Menu initialization failed\n" );
}
//Scheme_Init();
}

Expand Down Expand Up @@ -258,7 +291,7 @@ Called at start and end of demos to restore to "non"HUD state.

void DLLEXPORT HUD_Reset( void )
{
gHUD.VidInit();
gHUD.Reset();
}

/*
Expand All @@ -275,6 +308,17 @@ void DLLEXPORT HUD_Frame( double time )
gEngfuncs.VGui_ViewportPaintBackground(HUD_GetRect());
#endif

// Handle menu input and mouse movement
if( g_pMenu )
{
int x = 0, y = 0;
if( g_pMenu->IsActive() )
{
gEngfuncs.GetMousePosition( &x, &y );
g_pMenu->MouseMove( x, y );
}
}

GetClientVoice()->Frame( time );
}

Expand Down Expand Up @@ -342,7 +386,7 @@ int DLLEXPORT HUD_GetRenderInterface( int version, render_api_t *renderfuncs, re
// we have here a Host_Error, so check Xash for version
if( g_iXash < MIN_XASH_VERSION )
{
gRenderAPI.Host_Error("Xash3D version check failed!\nPlease update your Xash3D!\n");
gRenderAPI.Host_Error("Xash3D FWGS version check failed!\nPlease update your Xash3D FWGS!\n");
}

return true;
Expand Down Expand Up @@ -416,7 +460,7 @@ extern "C" void DLLEXPORT HUD_ChatInputPosition( int *x, int *y )
extern "C" int DLLEXPORT HUD_GetPlayerTeam(int iplayer)
{
// original seems to return team_id, but I'm not sure it's even set somewhere
if ( iplayer <= MAX_PLAYERS )
if ( iplayer >= 0 && iplayer < MAX_PLAYERS )
return g_PlayerExtraInfo[iplayer].teamnumber;
return 0;
}
Expand Down Expand Up @@ -520,7 +564,26 @@ class CClientExports : public IGameClientExports
GetClientVoice()->SetPlayerBlockedState( playerIndex, false );
}
}

const char *GetLevelName( void ) override
{
const char *fullname = gEngfuncs.pfnGetLevelName();
if( fullname[0] )
{
strncpy( mapname, fullname + 5, sizeof( mapname ));
mapname[strlen(mapname) - 4] = '\0';
}
else mapname[0] = 0;

return mapname;
}

int GetLocalPlayerTeam() override
{
return g_PlayerExtraInfo[gHUD.m_Scoreboard.m_iPlayerNum].teamnumber;
}
private:
char mapname[64];
};

EXPOSE_SINGLE_INTERFACE(CClientExports, IGameClientExports, GAMECLIENTEXPORTS_INTERFACE_VERSION)

3 changes: 0 additions & 3 deletions cl_dll/death.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,3 @@ int CHudDeathNotice :: MsgFunc_DeathMsg( const char *pszName, int iSize, void *p
return 1;
}




6 changes: 6 additions & 0 deletions cl_dll/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,12 @@ void CHud :: VidInit( void )
firstinit = false;
}

void CHud::Reset( void )
{
for( HUDLIST *pList = m_pHudList; pList; pList = pList->pNext )
pList->p->Reset();
}

void CHud::Shutdown( void )
{
for( HUDLIST *pList = m_pHudList; pList; pList = pList->pNext )
Expand Down
13 changes: 13 additions & 0 deletions cl_dll/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ inline bool BIsValidCTModelIndex( int i )
return false;
}

inline bool IsASMapType()
{
const char *a = gEngfuncs.pfnGetLevelName();
return a && (!strnicmp( a, "maps/as_", 8 ) || !strnicmp( a, "as_", 3 ));
}

inline bool IsDEMapType()
{
const char *a = gEngfuncs.pfnGetLevelName();
return a && (!strnicmp( a, "maps/de_", 8 ) || !strnicmp( a, "de_", 3 ));
}

#define HUD_DRAW (1 << 0)
#define HUD_THINK (1 << 1)
#define HUD_ACTIVE (HUD_DRAW | HUD_THINK)
Expand Down Expand Up @@ -956,6 +968,7 @@ class CHud
void Init( void );
void VidInit( void );
void Think( void );
void Reset( void );
void Shutdown( void );
int Redraw( float flTime, int intermission );
int UpdateClientData( client_data_t *cdata, float time );
Expand Down
6 changes: 5 additions & 1 deletion cl_dll/hud/scoreboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,13 @@ int CHudScoreboard :: MsgFunc_TeamInfo( const char *pszName, int iSize, void *pb
teamNumber = TEAM_TERRORIST;
else if( !strcmp( teamName, "CT") )
teamNumber = TEAM_CT;
else if( !strcmp( teamName, "SPECTATOR" ) || !strcmp( teamName, "UNASSIGNED" ) )
else if( !strcmp( teamName, "SPECTATOR" ) )
{
teamNumber = TEAM_SPECTATOR;
}
else if( !strcmp( teamName, "UNASSIGNED" ) )
{
teamNumber = TEAM_UNASSIGNED;
strncpy( teamName, "SPECTATOR", MAX_TEAM_NAME );
}
// just in case
Expand Down
2 changes: 2 additions & 0 deletions cl_dll/include/cl_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef int (*pfnUserMsgHook)(const char *pszName, int iSize, void *pbuf);

#include <stdint.h>

#include "cl_dll/IGameMenuExports.h"
#include "util_vector.h"

#include "../engine/cdll_int.h"
Expand Down Expand Up @@ -99,6 +100,7 @@ void DLLEXPORT IN_ClientLookEvent( float relyaw, float relpitch );
extern cl_enginefunc_t gEngfuncs;
extern render_api_t gRenderAPI;
extern mobile_engfuncs_t gMobileAPI;
extern IGameMenuExports *g_pMenu;
extern int g_iXash; // indicates buildnum
extern int g_iMobileAPIVersion; // indicates version. 0 if no mobile API
#endif // CL_DLL_H
3 changes: 3 additions & 0 deletions cl_dll/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ Return 1 to allow engine to process the key, otherwise, act on it as needed
*/
int DLLEXPORT HUD_Key_Event( int down, int keynum, const char *pszCurrentBinding )
{
if( g_pMenu )
g_pMenu->Key( keynum, down );

return 1;
}

Expand Down
57 changes: 53 additions & 4 deletions cl_dll/menu.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
Expand All @@ -20,6 +20,7 @@
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include "com_weapons.h"

#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -121,7 +122,7 @@ int CHudMenu :: Draw( float flTime )
if ( g_szMenuString[i] == '\n' )
i++;
}

return 1;
}

Expand Down Expand Up @@ -240,6 +241,9 @@ int CHudMenu::MsgFunc_BuyClose(const char *pszName, int iSize, void *pbuf)
{
Touch_CloseMenu();

if (g_pMenu)
g_pMenu->HideVGUIMenu();

return 1;
}

Expand Down Expand Up @@ -272,6 +276,51 @@ void CHudMenu::UserCmd_OldStyleMenuClose()

void CHudMenu::ShowVGUIMenu( int menuType )
{
int team = g_PlayerExtraInfo[gHUD.m_Scoreboard.m_iPlayerNum].teamnumber;
int haveCancel = team != TEAM_UNASSIGNED ? 1 : 0;

if( g_pMenu )
{
switch( menuType )
{
case MENU_TEAM:
{
int param = 0;
if( m_bAllowSpec )
{
if( g_iTeamNumber == TEAM_UNASSIGNED ||
g_PlayerExtraInfo[gHUD.m_Scoreboard.m_iPlayerNum].dead ||
!g_iFreezeTimeOver )
{
param |= 1 << 0;
}
}

if( IsASMapType() && g_iTeamNumber == TEAM_CT )
param |= 1 << 1;

if( haveCancel )
param |= 1 << 2;

g_pMenu->ShowVGUIMenu( menuType, param, 0 );
return;
}
case MENU_CLASS_T:
case MENU_CLASS_CT:
g_pMenu->ShowVGUIMenu( menuType, gHUD.GetGameType() == GAME_CZERO, haveCancel );
return;
case MENU_BUY:
case MENU_BUY_PISTOL:
case MENU_BUY_SHOTGUN:
case MENU_BUY_RIFLE:
case MENU_BUY_SUBMACHINEGUN:
case MENU_BUY_MACHINEGUN:
case MENU_BUY_ITEM:
g_pMenu->ShowVGUIMenu( menuType, gHUD.GetGameType() == GAME_CZERO, team );
return;
}
}

const char *szCmd;

switch(menuType)
Expand Down
6 changes: 6 additions & 0 deletions engine/mobility_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ typedef struct mobile_engfuncs_s
// Draw scaled font for client
int (*pfnDrawScaledCharacter)( int x, int y, int number, int r, int g, int b, float scale );

void (*pfnSys_Warn)( const char *format, ... );

// Get native object for current platform.
// Pass NULL to arguments to receive an array of available objects or NULL if nothing
void *(*pfnGetNativeObject)( const char *obj );

// To be continued...
} mobile_engfuncs_t;

Expand Down
4 changes: 4 additions & 0 deletions public/cl_dll/IGameClientExports.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class IGameClientExports : public IBaseInterface
virtual bool IsPlayerGameVoiceMuted(int playerIndex) = 0;
virtual void MutePlayerGameVoice(int playerIndex) = 0;
virtual void UnmutePlayerGameVoice(int playerIndex) = 0;

virtual const char *GetLevelName( void ) = 0;

virtual int GetLocalPlayerTeam( void ) = 0;
};

#define GAMECLIENTEXPORTS_INTERFACE_VERSION "GameClientExports001"
Expand Down
58 changes: 58 additions & 0 deletions public/cl_dll/IGameMenuExports.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================

#ifndef IGAMEMENUEXPORTS_H
#define IGAMEMENUEXPORTS_H
#ifdef _WIN32
#pragma once
#endif

#include "interface.h"
#include "mainui/font/FontRenderer.h"
#include "../dlls/cdll_dll.h"

//-----------------------------------------------------------------------------
// Purpose: Exports a set of functions for the game client to interact with the GameUI
//-----------------------------------------------------------------------------

class IGameMenuExports : public IBaseInterface
{
public:
virtual bool Initialize( CreateInterfaceFn factory ) = 0;

virtual const char *L( const char *szStr ) = 0;

virtual bool IsActive( void ) = 0;
virtual bool IsMainMenuActive( void ) = 0;

virtual void Key( int key, int down ) = 0;
virtual void MouseMove( int x, int y ) = 0;

virtual HFont BuildFont( CFontBuilder &builder ) = 0;

virtual void GetCharABCWide( HFont font, int ch, int &a, int &b, int &c ) = 0;
virtual int GetFontTall( HFont font ) = 0;

virtual int GetCharacterWidth(HFont font, int ch, int charH ) = 0;

virtual void GetTextSize( HFont font, const char *text, int *wide, int *height = 0, int size = -1 ) = 0;
virtual int GetTextHeight( HFont font, const char *text, int size = -1 ) = 0;

virtual int DrawCharacter( HFont font, int ch, int x, int y, int charH, const unsigned int color, bool forceAdditive = false ) = 0;

virtual void SetupScoreboard( int xstart, int xend, int ystart, int yend, unsigned int color, bool drawStroke ) = 0;
virtual void DrawScoreboard( void ) = 0;

virtual void DrawSpectatorMenu( void ) = 0;

virtual void ShowVGUIMenu( int menuType, int param1, int param2 ) = 0;
virtual void HideVGUIMenu( void ) = 0;
};

#define GAMEMENUEXPORTS_INTERFACE_VERSION "GameMenuExports001"

#endif // IGAMEMENUEXPORTS_H
Loading
Loading