1 /*
2 Copyright (C) 1997-2001 Id Software, Inc.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 // cl_inv.c -- client inventory screen
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include "client.h"
27 
28 /*
29 ================
30 CL_ParseInventory
31 ================
32 */
CL_ParseInventory(void)33 void CL_ParseInventory (void)
34 {
35 	int		i;
36 
37 	for (i=0 ; i<MAX_ITEMS ; i++)
38 		cl.inventory[i] = MSG_ReadShort (&net_message);
39 }
40 
41 
42 /*
43 ================
44 CL_DrawInventory
45 ================
46 */
47 #define	DISPLAY_ITEMS	17
48 
CL_DrawInventory(void)49 void CL_DrawInventory (void)
50 {
51 	FNT_font_t		font;
52 	struct FNT_window_s	box;
53 	int			i, j;
54 	int			num;
55 	int			selected_num;
56 	int			selected;
57 	int			top;
58 	int			index[ MAX_ITEMS ];
59 	float			scale;
60 	int			colWidth[ 3 ];
61 	int			colPos[ 3 ];
62 
63 	// Find selected item
64 	num = 0;
65 	selected = cl.frame.playerstate.stats[ STAT_SELECTED_ITEM ];
66 	selected_num = 0;
67 	for ( i = 0 ; i < MAX_ITEMS ; i++ ) {
68 		if ( i == selected) {
69 			selected_num = num;
70 		}
71 		if (cl.inventory[i]) {
72 			index[num] = i;
73 			num++;
74 		}
75 	}
76 
77 	// Load font and compute scaled size
78 	font = FNT_AutoGet( CL_gameFont );
79 	scale = font->size / 8.0;
80 
81 	// determine scroll point
82 	top = selected_num - DISPLAY_ITEMS/2;
83 	if (num - top < DISPLAY_ITEMS)
84 		top = num - DISPLAY_ITEMS;
85 	if (top < 0)
86 		top = 0;
87 
88 	// Draw frame and headers
89 	box.x = (int)( ( viddef.width - 416 * scale ) / 2 );
90 	box.y = (int)( ( viddef.height - 256 * scale ) / 2 );
91 	Draw_StretchPic( box.x , box.y , 416 * scale , 256 * scale , "inventory" );
92 
93 	colPos[ 0 ] = ( box.x += 56 * scale ) , box.y += 32 * scale;
94 	colWidth[ 0 ] = box.width = 55 * scale , box.height = 0;
95 	FNT_BoundedPrint( font , "Hotkey" , FNT_CMODE_NONE , FNT_ALIGN_RIGHT , &box , FNT_colors[ 7 ] );
96 
97 	colPos[ 1 ] = ( box.x += 60 * scale );
98 	colWidth[ 1 ] = box.width = 43 * scale , box.height = 0;
99 	FNT_BoundedPrint( font , "###" , FNT_CMODE_NONE , FNT_ALIGN_CENTER , &box , FNT_colors[ 7 ] );
100 
101 	colPos[ 2 ] = ( box.x += 48 * scale );
102 	colWidth[ 2 ] = box.width = 100 * scale , box.height = 0;
103 	FNT_BoundedPrint( font , "Item" , FNT_CMODE_NONE , FNT_ALIGN_LEFT , &box , FNT_colors[ 7 ] );
104 
105 	Draw_Fill( colPos[ 0 ] + scale , box.y + 11 * scale , 302 * scale , 2 * scale , RGBA8(235,235,235,255));
106 
107 	// Draw inventory contents
108 	box.y += 16 * scale;
109 	for ( i = top ; i < num && i < top + DISPLAY_ITEMS ; i++ ) {
110 		int		item = index[ i ];
111 		char		binding[ MAX_QPATH + 5 ];
112 		const char *	bind;
113 		const float *	color = FNT_colors[ index[ i ] == selected ? 7 : 2 ];
114 		char		count[ 5 ];
115 
116 		// search for a binding
117 		Com_sprintf (binding, sizeof(binding), "use %s", cl.configstrings[CS_ITEMS+item]);
118 		bind = "";
119 		for (j=0 ; j<256 ; j++) {
120 			if (keybindings[j] && !Q_strcasecmp (keybindings[j], binding))
121 			{
122 				bind = Key_KeynumToString(j);
123 				break;
124 			}
125 		}
126 
127 		// Draw inventory line
128 		Com_sprintf( count , sizeof( count ) , "%i" , cl.inventory[item] );
129 		box.x = colPos[ 0 ] , box.width = colWidth[ 0 ] , box.height = 0;
130 		FNT_BoundedPrint( font , bind , FNT_CMODE_NONE , FNT_ALIGN_RIGHT , &box , color );
131 		box.x = colPos[ 1 ] , box.width = colWidth[ 1 ] , box.height = 0;
132 		FNT_BoundedPrint( font , count , FNT_CMODE_NONE , FNT_ALIGN_CENTER , &box , color );
133 		box.x = colPos[ 2 ] , box.width = colWidth[ 2 ] , box.height = 0;
134 		FNT_BoundedPrint( font , cl.configstrings[ CS_ITEMS + item ] , FNT_CMODE_NONE , FNT_ALIGN_LEFT , &box , color );
135 
136 		box.y += 8 * scale;
137 	}
138 }
139