Buttons in spectator mode

This commit is contained in:
a1batross 2016-03-18 01:45:34 +03:00
parent 4fbe104ea5
commit 51a942babc
5 changed files with 314 additions and 40 deletions

View File

@ -262,10 +262,16 @@ void CHud :: VidInit( void )
m_hsprLogo = 0;
m_hsprCursor = 0;
if (ScreenWidth < 640)
m_iRes = 320;
else
m_iRes = 640;
if( ScreenWidth < 640 && CVAR_GET_FLOAT("hud_scale") <= 1.0f )
{
gEngfuncs.Cvar_SetValue("hud_scale", ScreenWidth / 640.0f );
}
else if( CVAR_GET_FLOAT("hud_scale") < 1.0f )
{
gEngfuncs.Cvar_SetValue("hud_scale", 1.0f );
}
GetScreenInfo(&m_scrinfo);
m_iRes = 640;
// Only load this once
if ( !m_pSpriteList )

View File

@ -85,22 +85,15 @@ void SpectatorSpray(void)
}
void SpectatorHelp(void)
{
/*if ( gViewPort )
{
gViewPort->ShowVGUIMenu( MENU_SPECHELP );
}
else*/
{
char *text = CHudTextMessage::BufferedLocaliseTextString( "#Spec_Help_Text" );
char *text = CHudTextMessage::BufferedLocaliseTextString( "#Spec_Help_Text" );
if ( text )
if ( text )
{
while ( *text )
{
while ( *text )
{
if ( *text != 13 )
gEngfuncs.Con_Printf( "%c", *text );
text++;
}
if ( *text != 13 )
gEngfuncs.Con_Printf( "%c", *text );
text++;
}
}
}
@ -112,8 +105,6 @@ void SpectatorMenu( void )
gEngfuncs.Con_Printf( "usage: spec_menu <0|1>\n" );
return;
}
//gViewPort->m_pSpectatorPanel->ShowMenu( atoi( gEngfuncs.Cmd_Argv(1))!=0 );
}
void ToggleScores( void )
@ -131,6 +122,51 @@ void ToggleScores( void )
}*/
}
void SpecDrawNames( void )
{
if ( gEngfuncs.Cmd_Argc() <= 1 )
{
gEngfuncs.Con_Printf( "usage: spec_menu <0|1>\n" );
return;
}
}
void SpecDrawCone( void )
{
if ( gEngfuncs.Cmd_Argc() <= 1 )
{
gEngfuncs.Con_Printf( "usage: spec_menu <0|1>\n" );
return;
}
}
void SpecDrawStatus( void )
{
if ( gEngfuncs.Cmd_Argc() <= 1 )
{
gEngfuncs.Con_Printf( "usage: spec_menu <0|1>\n" );
return;
}
}
void SpecAutoDirector( void )
{
if ( gEngfuncs.Cmd_Argc() <= 1 )
{
gEngfuncs.Con_Printf( "usage: spec_menu <0|1>\n" );
return;
}
}
void SpecPip( void )
{
if ( gEngfuncs.Cmd_Argc() <= 1 )
{
gEngfuncs.Con_Printf( "usage: spec_menu <0|1>\n" );
return;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
@ -154,13 +190,18 @@ int CHudSpectator::Init()
gEngfuncs.pfnAddCommand ("spec_help", SpectatorHelp );
gEngfuncs.pfnAddCommand ("spec_menu", SpectatorMenu );
gEngfuncs.pfnAddCommand ("togglescores", ToggleScores );
gEngfuncs.pfnAddCommand ("spec_drawnames", SpecDrawNames );
gEngfuncs.pfnAddCommand ("spec_drawcone", SpecDrawCone );
gEngfuncs.pfnAddCommand ("spec_drawstatus", SpecDrawStatus );
gEngfuncs.pfnAddCommand ("spec_autodirector", SpecAutoDirector );
gEngfuncs.pfnAddCommand ("spec_pip", SpecPip );
m_drawnames = gEngfuncs.pfnRegisterVariable("spec_drawnames_internal","1",0);
m_specmode = gEngfuncs.pfnRegisterVariable("spec_mode_internal","1",0);
m_drawcone = gEngfuncs.pfnRegisterVariable("spec_drawcone_internal","1",0);
m_drawstatus = gEngfuncs.pfnRegisterVariable("spec_drawstatus_internal","1",0);
m_autoDirector = gEngfuncs.pfnRegisterVariable("spec_autodirector_internal","1",0);
m_pip = gEngfuncs.pfnRegisterVariable("spec_pip","1",0);
m_pip = gEngfuncs.pfnRegisterVariable("spec_pip_internal","1",0);
m_lastAutoDirector = 0.0f;
if ( !m_drawnames || !m_drawcone || !m_drawstatus || !m_autoDirector || !m_pip)
@ -720,7 +761,6 @@ void CHudSpectator::HandleButtonsDown( int ButtonPressed )
// gEngfuncs.Con_Printf(" HandleButtons:%i\n", ButtonPressed );
// if ( !gViewPort )
return;
//Not in intermission.
if ( gHUD.m_iIntermission )
@ -737,8 +777,10 @@ void CHudSpectator::HandleButtonsDown( int ButtonPressed )
return;
// enable spectator screen
//if ( ButtonPressed & IN_DUCK )
// gViewPort->m_pSpectatorPanel->ShowMenu(!gViewPort->m_pSpectatorPanel->m_menuVisible);
if ( ButtonPressed & IN_DUCK )
{
gHUD.m_SpectatorGui.UserCmd_ToggleSpectatorMenu();
}
// 'Use' changes inset window mode
if ( ButtonPressed & IN_USE )
@ -1692,3 +1734,9 @@ int CHudSpectator::MsgFunc_Spectator(const char *pszName, int iSize, void *buf)
{
return 1;
}
int CHudSpectator::MsgFunc_ADStop(const char *pszName, int iSize, void *buf)
{
m_autoDirector->value = 0;
return 1;
}

View File

@ -33,21 +33,97 @@ version.
#include "cl_util.h"
#include "parsemsg.h"
#define DIVIDER_XPOS (ScreenWidth * 0.85)
#define DIVIDER_GAP (15)
/*
* We will draw all elements inside a box. It's size 16x9.
*/
#define BAR_HEIGHT (ScreenHeight / 7)
#define XPOS( x ) ( (x) / 16.0f )
#define YPOS( x ) ( (x) / 9.0f )
/*
* Black bar:
* Height = 2/9 of ScreenHeight.
* Width = ScreenWidth.
*/
#define BAR_HEIGHT ( ( 2.0f / 9.0f ) * ScreenHeight )
#define BAR_WIDTH ( ScreenWidth )
/*
* Button:
* Height = bar's height * 0.5
* Width = ScreenWidth * 0.25
*/
#define BUTTON_HEIGHT ( BAR_HEIGHT * 0.5 )
#define BUTTON_WIDTH ( ScreenWidth * 0.25 )
/*
* Little button:
* Height = button's height
* Width = button's height
*/
#define LITTLE_BUTTON_HEIGHT BUTTON_HEIGHT
#define LITTLE_BUTTON_WIDTH BUTTON_HEIGHT
/*
* DIVIDER POSITION AND HEIGHT
*/
#define DIVIDER_XPOS (ScreenWidth * 0.85f)
#define DIVIDER_GAP (20)
DECLARE_MESSAGE( m_SpectatorGui, SpecHealth );
DECLARE_MESSAGE( m_SpectatorGui, SpecHealth2 );
DECLARE_COMMAND( m_SpectatorGui, ToggleSpectatorMenu );
DECLARE_COMMAND( m_SpectatorGui, ToggleSpectatorMenuOptions );
// close
// help
// settings
// pip
// autodirector
// showscores
DECLARE_COMMAND( m_SpectatorGui, ToggleSpectatorMenuOptionsSettings );
// settings
// // chat msgs
// // show status
// // view cone
// // player names
DECLARE_COMMAND( m_SpectatorGui, ToggleSpectatorMenuSpectateOptions );
// chase map overview
// free map overview
// first person
// free look
// free chase camera
// locked chase camera
void __CmdFunc_FindNextPlayerReverse( void )
{
gHUD.m_Spectator.FindNextPlayer(true);
}
void __CmdFunc_FindNextPlayer( void )
{
gHUD.m_Spectator.FindNextPlayer(false);
}
int CHudSpectatorGui::Init()
{
HOOK_MESSAGE( SpecHealth );
HOOK_MESSAGE( SpecHealth2 );
HOOK_COMMAND( "_spec_toggle_menu", ToggleSpectatorMenu );
HOOK_COMMAND( "_spec_toggle_menu_options", ToggleSpectatorMenuOptions );
HOOK_COMMAND( "_spec_toggle_menu_options_settings", ToggleSpectatorMenuOptionsSettings );
HOOK_COMMAND( "_spec_toggle_menu_spectate_options", ToggleSpectatorMenuSpectateOptions );
HOOK_COMMAND( "_spec_find_next_player_reverse", FindNextPlayerReverse );
HOOK_COMMAND( "_spec_find_next_player", FindNextPlayer );
gHUD.AddHudElem(this);
m_iFlags = HUD_ACTIVE;
m_bIsMenuShown = false;
return 1;
}
@ -72,18 +148,32 @@ int CHudSpectatorGui::Draw( float flTime )
return 1;
// check for scoreboard. We will don't draw it, because screen space econodmy
if( gHUD.m_Scoreboard.m_bForceDraw || !(!gHUD.m_Scoreboard.m_bShowscoresHeld && gHUD.m_Health.m_iHealth > 0 && !gHUD.m_iIntermission ))
return 1;
/*if( gHUD.m_Scoreboard.m_bForceDraw || !(!gHUD.m_Scoreboard.m_bShowscoresHeld && gHUD.m_Health.m_iHealth > 0 && !gHUD.m_iIntermission ))
return 1;*/
int r, g, b;
r = 255; g = 140; b = 0;
// at first, draw these silly black bars
DrawUtils::DrawRectangle(0, 0, ScreenWidth, BAR_HEIGHT, 0, 0, 0, 153, false);
DrawUtils::DrawRectangle(0, BAR_HEIGHT * 6, ScreenWidth, BAR_HEIGHT, 0, 0, 0, 153, false);
if( gHUD.m_Spectator.m_pip->value == INSET_OFF )
{
DrawUtils::DrawRectangle(0, 0, BAR_WIDTH, BAR_HEIGHT, 0, 0, 0, 153, false);
}
else
{
int startpos;
startpos = XRES(gHUD.m_Spectator.m_OverviewData.insetWindowWidth) + XRES(gHUD.m_Spectator.m_OverviewData.insetWindowX);
startpos *= ScreenWidth / TrueWidth; // hud_scale adjust
DrawUtils::DrawRectangle(startpos, 0, BAR_WIDTH - startpos, BAR_HEIGHT, 0, 0, 0, 153, false);
}
DrawUtils::DrawRectangle(0, ScreenHeight - BAR_HEIGHT, ScreenWidth, BAR_HEIGHT, 0, 0, 0, 153, false);
// divider
FillRGBABlend( ScreenWidth * 0.85, BAR_HEIGHT * 0.25, 1, BAR_HEIGHT * 0.5, r, g, b, 255 );
FillRGBABlend( DIVIDER_XPOS, BAR_HEIGHT * 0.25, 1, BAR_HEIGHT * 0.5, r, g, b, 255 );
// function name says it
CalcAllNeededData( );
@ -123,7 +213,7 @@ int CHudSpectatorGui::Draw( float flTime )
int iLen = DrawUtils::HudStringLen( szNameAndHealth );
GetTeamColor( r, g, b, g_PlayerExtraInfo[ pEnt->index ].teamnumber );
DrawUtils::DrawHudString( ScreenWidth * 0.5 - iLen * 0.5, BAR_HEIGHT * 13 / 2, ScreenWidth, szNameAndHealth, r, g, b );
DrawUtils::DrawHudString( ScreenWidth * 0.5 - iLen * 0.5, ScreenHeight - BAR_HEIGHT * 0.5 , ScreenWidth, szNameAndHealth, r, g, b );
}
}
}
@ -142,15 +232,18 @@ void CHudSpectatorGui::CalcAllNeededData( )
// team
label.m_iTerrorists = 0;
label.m_iCounterTerrorists = 0;
for( int i = 0; i < MAX_TEAMS; i++ )
for( int i = 0; i < MAX_PLAYERS; i++ )
{
if( !stricmp( g_TeamInfo[i].name, "CT") )
label.m_iCounterTerrorists = g_TeamInfo[i].players;
else if( !stricmp( g_TeamInfo[i].name, "TERRORIST") )
label.m_iTerrorists = g_TeamInfo[i].players;
if( g_PlayerExtraInfo[i].dead )
continue; // show remaining
if( label.m_iTerrorists && label.m_iCounterTerrorists )
break;
switch( g_PlayerExtraInfo[i].teamnumber )
{
case TEAM_CT:
label.m_iCounterTerrorists++;
case TEAM_TERRORIST:
label.m_iTerrorists++;
}
}
// timer
@ -207,3 +300,121 @@ int CHudSpectatorGui::MsgFunc_SpecHealth2(const char *pszName, int iSize, void *
return 1;
}
#define PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y(x, y) XPOS(x), YPOS(y), XPOS(x + 4.0f), YPOS(y + 1.0f)
void CHudSpectatorGui::UserCmd_ToggleSpectatorMenu()
{
static byte color[4] = {0, 0, 0, 153};
m_bIsMenuShown = !m_bIsMenuShown;
gMobileAPI.pfnTouchSetClientOnly( m_bIsMenuShown );
if( m_bIsMenuShown )
{
ClientCmd("touch_set_stroke 1 255 140 0 255");
gMobileAPI.pfnTouchAddClientButton( "_spec_menu_options", "*white", "_spec_menu_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 0.5f, 7.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_menu_find_next_player_reverse", "*white", "_spec_find_next_player_reverse",
XPOS(5.0f), YPOS(7.5f), XPOS(6.0f), YPOS(8.5f), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_menu_nick", "*white", "*white",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 6.0f, 7.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_menu_find_next_player", "*white", "_spec_find_next_player",
XPOS(10.0f),YPOS(7.5f), XPOS(11.0f),YPOS(8.5f), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_menu_spectate_options", "*white", "_spec_menu_spectate_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 11.5f, 7.5f ),color, 0, 1.0f, TOUCH_FL_STROKE );
}
else
{
gMobileAPI.pfnTouchRemoveButton( "_spec_*" );
}
}
void CHudSpectatorGui::UserCmd_ToggleSpectatorMenuOptions()
{
static byte color[4] = {0, 0, 0, 153};
static bool isShown = false;
if( !m_bIsMenuShown )
return;
if( isShown = !isShown )
{
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_close", "*white", "_spec_menu_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 0.5f, 1.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_help", "*white", "TODO; _spec_menu_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 0.5f, 2.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_settings", "*white", "_spec_toggle_menu_options_settings",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 0.5f, 3.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_pip", "*white", "spec_pip t; _spec_menu_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 0.5f, 4.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_ad", "*white", "spec_autodirector t; _spec_menu_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 0.5f, 5.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_showscores", "*white", "scoreboard; _spec_menu_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 0.5f, 6.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
}
else
{
gMobileAPI.pfnTouchRemoveButton( "_spec_opt_*" );
}
}
void CHudSpectatorGui::UserCmd_ToggleSpectatorMenuOptionsSettings()
{
static byte color[4] = {0, 0, 0, 153};
static bool isShown = false;
if( !m_bIsMenuShown )
return;
if( isShown = !isShown )
{
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_chat_msgs", "*white", "TODO; _spec_toggle_menu_options_settings",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 4.5f, 3.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_set_status", "*white", "spec_drawstatus t; _spec_toggle_menu_options_settings",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 4.5f, 4.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_draw_cones", "*white", "spec_drawcone t; _spec_toggle_menu_options_settings",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 4.5f, 5.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_opt_draw_names", "*white", "spec_drawnames t; _spec_toggle_menu_options_settings",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 4.5f, 6.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
}
else
{
gMobileAPI.pfnTouchRemoveButton( "_spec_opt_set_*" );
}
}
void CHudSpectatorGui::UserCmd_ToggleSpectatorMenuSpectateOptions()
{
static byte color[4] = {0, 0, 0, 153};
static bool isShown = false;
if( !m_bIsMenuShown )
return;
if( isShown = !isShown )
{
gMobileAPI.pfnTouchAddClientButton( "_spec_spec_6", "*white", "spec_mode 6; _spec_menu_spectate_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 11.5f, 1.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_spec_5", "*white", "spec_mode 5; _spec_menu_spectate_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 11.5f, 2.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_spec_4", "*white", "spec_mode 4; _spec_menu_spectate_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 11.5f, 3.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_spec_3", "*white", "spec_mode 3; _spec_menu_spectate_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 11.5f, 4.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_spec_2", "*white", "spec_mode 2; _spec_menu_spectate_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 11.5f, 5.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
gMobileAPI.pfnTouchAddClientButton( "_spec_spec_1", "*white", "spec_mode 1; _spec_menu_spectate_options",
PLACE_DEFAULT_SIZE_BUTTON_AT_X_Y( 11.5f, 6.5f ), color, 0, 1.0f, TOUCH_FL_STROKE );
}
else
{
gMobileAPI.pfnTouchRemoveButton( "_spec_spec_*" );
}
}

View File

@ -811,6 +811,11 @@ public:
CHudMsgFunc( SpecHealth );
CHudMsgFunc( SpecHealth2 );
CHudUserCmd( ToggleSpectatorMenu );
CHudUserCmd( ToggleSpectatorMenuOptions );
CHudUserCmd( ToggleSpectatorMenuOptionsSettings );
CHudUserCmd( ToggleSpectatorMenuSpectateOptions );
void CalcAllNeededData( );
bool m_bBombPlanted;
@ -827,6 +832,9 @@ private:
char m_szMap[64];
} label;
int m_hTimerTexture;
bool m_bIsMenuShown;
byte m_pucColor[4];
};
//

View File

@ -78,6 +78,7 @@ public:
void DirectorMessage( int iSize, void *pbuf );
void SetSpectatorStartPosition();
CHudMsgFunc(Spectator);
CHudMsgFunc(ADStop);
int Init();
int VidInit();