The Place to Start


Creating Different Colored Menus 
BigGuy
Intermediate


Creating Different Colored Menus
Editor: RED is new, YELLOW is old.
Fairly simple put, it allows you to create menus of different colors. 
You must have already done the original menu tutorial by Tim Smith.

Lets first start out by changing the stuff in the Server dll (mp.dll):

Change the ShowMenu function declaration from

void ShowMenu (CBasePlayer *pPlayer, int bitsValidSlots, int nDisplayTime, 
	BOOL fNeedMore, char *pszText);

to

void ShowMenu (CBasePlayer *pPlayer, int bitsValidSlots, int nDisplayTime, 
	BOOL fNeedMore, char *pszText, int m_iWhichColor);

Now we need to change the code in the function:

void CWhatEver::ShowMenu (CBasePlayer *pPlayer, int bitsValidSlots, int nDisplayTime, 
	BOOL fNeedMore, char *pszText, int m_iWhichColor)
{
   MESSAGE_BEGIN( MSG_ONE, gmsgShowMenu, NULL, pPlayer ->pev);
        WRITE_SHORT( bitsValidSlots);
        WRITE_CHAR( nDisplayTime );
        WRITE_BYTE( fNeedMore );
	WRITE_STRING (pszText);
	WRITE_BYTE ( m_iWhichColor ); // Added for colors
   MESSAGE_END();
} 

You would now use the ShowMenu() like this:

ShowMenu (pPlayer, 0x1F, 0, 0, szMenu, 1);

The last number represents the number of the color which we will get to later.

Now open up the Client dll:

In hud.h add these to the CHudMenu class:

	int m_iWhichColor;
	int m_aColor[3];

Open menu.cpp now and add these to the MsgFunc_ShowMenu()

**It is critical that you place the next lines exactly as shown**

	m_iWhichColor = READ_BYTE();

	m_fMenuDisplayed = 1;
	m_iFlags |= HUD_ACTIVE;

Now in Draw() at the top of the function:

	m_aColor[3] = WHITE[3];
	
	switch (m_iWhichColor)
	{
	case 1: // RED
		m_aColor[0] = RED[0];
		m_aColor[1] = RED[1];
		m_aColor[2] = RED[2];
		break;
	case 2: // BLUE
		m_aColor[0] = BLUE[0];
		m_aColor[1] = BLUE[1];
		m_aColor[2] = BLUE[2];
		break;
	case 3: // GREEN
		m_aColor[0] = GREEN[0];
		m_aColor[1] = GREEN[1];
		m_aColor[2] = GREEN[2];
		break;
	case 4: // PURPLE
		m_aColor[0] = GREEN[0];
		m_aColor[1] = GREEN[1];
		m_aColor[2] = GREEN[2];
		break;
	default: // WHITE
		m_aColor[0] = WHITE[0];
		m_aColor[1] = WHITE[1];
		m_aColor[2] = WHITE[2];
		break;
	}

Now look a little further down for

gHUD.DrawHudString( x, y, 320, g_szMenuString + i, 255, 255, 255 );

and change it to

gHUD.DrawHudString( x, y, 320, g_szMenuString + i, m_aColor[0], m_aColor[1], m_aColor[2] );

Now for the color tables:

Add this in the menu.cpp file (outside of any function):

int RED[3] = { 255, 0, 0 }; // 1 = RED
int BLUE[3] = { 0, 0, 255 }; // 2 = BLUE
int GREEN[3] = { 0, 255, 0 }; // 3 = GREEN
int PURPLE[3] = { 128, 0, 255 }; // 4 = PURPLE
int WHITE[3] = { 255, 255, 255 }; // anything else defaults to white

By sending a byte this allows up to 255 different colors, negatives wrap around. 
Dont use {0, 0, 0} this is transparent. You select the colors by sending different
number color indexes. Youll have to play around with the colors to get what you want.
Most can be found using a drawing program. Actually in retrospect, you can use the 
UnpackRGB() instead of all the arrays. By using the arrays you dont have to convert
them to hex. Oh well. :)

Any questions or suggestions should be sent to me: bigguy@valveworld.com