VGUI2: Overview Display

From Valve Developer Community
Revision as of 10:30, 5 February 2012 by ZhenB012 (talk | contribs) (Undo revision 164982 by ZhenB012 (talk))

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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: Source.

Example overview map

Woodsy 800.jpg
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.

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 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: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 its behavior.

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( const CCommand &args )
    {
    	KeyDown( &in_overview, args[1]);
    	if ( gViewPortInterface )
    	{
    		gViewPortInterface->ShowPanel( PANEL_OVERVIEW, true );
    	}
    }
    
    void IN_OverviewUp( const CCommand &args )
    {
    	KeyUp(&in_overview, args[1]);
    	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: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, but less than 32.

Making the Overview show on startup

Probably not the best way of doing this BUT

  1. Open c_hl2mp_player.cpp and find function C_HL2MP_Player::Initialize 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 initializes, it'll also send an 'overview_mode' command to the console, switching on the overview display.


Changes for SDK update 31st Oct. 2006

Since the last SDK update, the code for the overview map has changed somewhat - vgui_TeamFortressViewport.cpp has been replaced with baseviewport.cpp and the overview map panel is no longer a panel but a HUD element instead.

To enabled the overview map with this update, you should do the following:

Note:The code in the previous sections is no longer needed!

Add missing declare statement

In cl_dll\game_controls\MapOverview.cpp add the following DECLARE_HUDELEMENT before the CMapOverview construct function:

////////////////////////////////
// Construction/Destruction
////////////////////////////////

// Without this the overview map element doesn't get created
DECLARE_HUDELEMENT( CMapOverview );

using namespace vgui;

CMapOverview::CMapOverview( const char *pElementName ) : BaseClass( NULL, pElementName ), CHudElement( pElementName )
{
  ...

Without this declare, the overview map HUD element doesn't get created.

Remove old creation call

In cl_dll\game_controls\baseviewport.cpp look in the CBaseViewport::CreateDefaultPanels function. If you have the following, remove it:

AddNewPanel( CreatePanelByName( PANEL_OVERVIEW ) );

Reason: The DECLARE_HUDELEMENT statement in the MapOverview.cpp will automatically create and instance of your overview map class. If you attempt to create it in CreateDefaultPanels as well, you end up with two panels called "overview" only one of which is valid, the other is NULL. When you try to use the HUD animations to zoom the map, they fail because the animation control tries to talk to the wrong "overview" panel and fails.

Add an entry for the panel in your HudLayout.res

Open scripts\HudLayout.res in your Mod folder and add the following:

	overview
	{
		"fieldname"				"overview"
		"visible"				"1"
		"enabled"				"1"
		"xpos"					"0"
		"ypos"					"0"
		"wide"					"480"
		"tall"					"0"
	}

This will set the basic layout of the HUD element. Size and position are altered in code so leave the values as above for now.

Copy the HUD animations

Open scripts\HudAnimations.txt in your Mod folder and add the following:

event MapOff
{
	Animate overview Position "0 0" Linear 0.0 0.001
	Animate overview Size "0 0" Linear 0.0 0.001
}

event MapZoomToSmall
{
	Animate overview Position "16 16" Linear 0.0 0.2
	Animate overview Size "160 120" Linear 0.0 0.2
	
	StopAnimation overview zoom 0.0
	Animate overview zoom "1.0" Linear 0.0 0.0001
	Animate overview zoom "3.0" Spline 0.0001 1.0
}

event MapZoomToLarge
{
	Animate overview Position "c-300 20" Linear 0.0 0.2
	Animate overview Size "600 440" Linear 0.0 0.2
	
	StopAnimation overview zoom 0.0
	Animate overview zoom "1.0" Spline 0.0 0.2
}

These events handle animating and positioning the map when switching between modes.

Create your overview map

Create your levels overview map/image as per Level Overviews guide.

See also