File: client\cl_inv.c
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 #include "client.h"
23
24 /*
25 ================
26 CL_ParseInventory
27 ================
28 */
29 void CL_ParseInventory (void)
30 {
31 int i;
32
33 for (i=0 ; i<MAX_ITEMS ; i++)
34 cl.inventory[i] = MSG_ReadShort (&net_message);
35 }
36
37
38 /*
39 ================
40 Inv_DrawString
41 ================
42 */
43 void Inv_DrawString (int x, int y, char *string)
44 {
45 while (*string)
46 {
47 re.DrawChar (x, y, *string);
48 x+=8;
49 string++;
50 }
51 }
52
53 void SetStringHighBit (char *s)
54 {
55 while (*s)
56 *s++ |= 128;
57 }
58
59 /*
60 ================
61 CL_DrawInventory
62 ================
63 */
64 #define DISPLAY_ITEMS 17
65
66 void CL_DrawInventory (void)
67 {
68 int i, j;
69 int num, selected_num, item;
70 int index[MAX_ITEMS];
71 char string[1024];
72 int x, y;
73 char binding[1024];
74 char *bind;
75 int selected;
76 int top;
77
78 selected = cl.frame.playerstate.stats[STAT_SELECTED_ITEM];
79
80 num = 0;
81 selected_num = 0;
82 for (i=0 ; i<MAX_ITEMS ; i++)
83 {
84 if (i==selected)
85 selected_num = num;
86 if (cl.inventory[i])
87 {
88 index[num] = i;
89 num++;
90 }
91 }
92
93 // determine scroll point
94 top = selected_num - DISPLAY_ITEMS/2;
95 if (num - top < DISPLAY_ITEMS)
96 top = num - DISPLAY_ITEMS;
97 if (top < 0)
98 top = 0;
99
100 x = (viddef.width-256)/2;
101 y = (viddef.height-240)/2;
102
103 // repaint everything next frame
104 SCR_DirtyScreen ();
105
106 re.DrawPic (x, y+8, "inventory");
107
108 y += 24;
109 x += 24;
110 Inv_DrawString (x, y, "hotkey ### item");
111 Inv_DrawString (x, y+8, "------ --- ----");
112 y += 16;
113 for (i=top ; i<num && i < top+DISPLAY_ITEMS ; i++)
114 {
115 item = index[i];
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_stricmp (keybindings[j], binding))
121 {
122 bind = Key_KeynumToString(j);
123 break;
124 }
125
126 Com_sprintf (string, sizeof(string), "%6s %3i %s", bind, cl.inventory[item],
127 cl.configstrings[CS_ITEMS+item] );
128 if (item != selected)
129 SetStringHighBit (string);
130 else // draw a blinky cursor by the selected item
131 {
132 if ( (int)(cls.realtime*10) & 1)
133 re.DrawChar (x-8, y, 15);
134 }
135 Inv_DrawString (x, y, string);
136 y += 8;
137 }
138
139
140 }
141
142
143