VGUI2: Overview Display

From Valve Developer Community
Revision as of 09:04, 26 October 2005 by Fallen (talk | contribs)
Jump to: navigation, search

The Source SDK includes code to create overview maps for multiplayer games. Overview maps let the player see an overview of the game map with markers showing their location and the location of other players. This is similar to the overview map available in Day of Defeat.

Example overview map

Here is an example overview map for a custom mod. The overview is in the upper right corner of the screen, and you can see the player's name and position drawn on the overview. Note in this case the overview is a custom image representing the topography of the terrain the player is on.


Woodsy 800.jpg

Enabling basic overview map display

1. In the file vgui_TeamFortressViewport.cpp, add this line to CreateDefaultPanels:

AddNewPanel( CreatePanelByName( PANEL_OVERVIEW ) );

Then rebuild your mod.

2. Create an overview map texture and configuration for your level. See Creating Level Overviews for instructions.

3. Start up your mod, and bind a key to "overview_mode". Pressing this key will toggle the overview map between off, small, and full screen modes.

Note.png Note: It's important you get your overview map created correctly so that the player locations are properly overlayed on the map!


Displaying the overview only when holding down a key

The previous section describes how to make the overview map cycle between three modes (off, mini, full screen). The following more complex modification allows you to have the overview map only display when a key is held down - much like how the scoreboard is displayed when the (default) TAB key is pressed. This takes a bit more coding to implement, but isn't that much more difficult.

What we'll do here is duplicate the code that displays the score board as we want our overview map to basically emulate it's behaviour.

Changes to cl_dll\in_main.cpp

1. Add this definition for a new key command to show/hide our overview:

static	kbutton_t	in_overview;

To know where to place it, search for the similar declaration for in_score.

2. Add the following code to define two new functions which handle showing and hiding the overview:

void IN_OverviewDown(void)
{
	KeyDown(&in_overview);

	if ( gViewPortInterface )
	{
		gViewPortInterface->ShowPanel( PANEL_OVERVIEW, true );
	}
}

void IN_OverviewUp(void)
{
	KeyUp(&in_overview);
	if ( gViewPortInterface )
	{
		gViewPortInterface->ShowPanel( PANEL_OVERVIEW, false );
		GetClientVoiceMgr()->StopSquelchMode();
	}
}

They can go just after the IN_ScoreUp function.

3. Add the following line of code with all the other CalcButtonBits calls:

CalcButtonBits( bits, IN_OVERVIEW, s_ClearInputState, &in_overview, bResetState );

4. Add the following 4 lines of code near all the other ConCommand lines:

static ConCommand startoverview("+overview", IN_OverviewDown);
static ConCommand endoverview("-overview", IN_OverviewUp);
static ConCommand startshowoverview("+showoverview", IN_OverviewDown);
static ConCommand endshowoverview("-showoverview", IN_OverviewUp);

Changes to game_shared\in_buttons.h

1. Add the following definition:

#define IN_OVERVIEW		(1 << 23)
Note.png Note: At the time of writing this, the last official IN_ defined is IN_BULLRUSH (bit shift 22). So our new define is bit shift 23. If for some reason 23 is already being used, just use some number not already being used.

Making the Overview show on startup

Probably not the best way of doing this BUT
1. Open c_hl2mp_player.cpp and find:

void C_HL2MP_Player::Initialize( void )
{
	m_headYawPoseParam = LookupPoseParameter( "head_yaw" );
	if ( m_headYawPoseParam != -1 )
	{
		const mstudioposeparamdesc_t &info = GetPoseParameterPtr( "head_yaw" );
		if ( &info != 0 )
		{
			m_headYawMin = info.start;
			m_headYawMax = info.end;
		}
	}

	m_headPitchPoseParam = LookupPoseParameter( "head_pitch" );
	if ( m_headPitchPoseParam != -1 )
	{
		const mstudioposeparamdesc_t &info = GetPoseParameterPtr( "head_pitch" );
		if ( &info != 0 )
		{
			m_headPitchMin = info.start;
			m_headPitchMax = info.end;
		}
	}
}

And change it to:

void C_HL2MP_Player::Initialize( void )
{
	m_headYawPoseParam = LookupPoseParameter( "head_yaw" );
	if ( m_headYawPoseParam != -1 )
	{
		const mstudioposeparamdesc_t &info = GetPoseParameterPtr( "head_yaw" );
		if ( &info != 0 )
		{
			m_headYawMin = info.start;
			m_headYawMax = info.end;
		}
	}

	m_headPitchPoseParam = LookupPoseParameter( "head_pitch" );
	if ( m_headPitchPoseParam != -1 )
	{
		const mstudioposeparamdesc_t &info = GetPoseParameterPtr( "head_pitch" );
		if ( &info != 0 )
		{
			m_headPitchMin = info.start;
			m_headPitchMax = info.end;
		}
	}
	engine->ClientCmd( "overview_mode" );
}

Now when your player model spawns and initialises, it'll also send an 'overview_mode' command to the console, switching on the overview display.


See also

Creating Level Overviews


Thanks to

Ginger Lord provided the starting nudge to get this working.