icculus quake2 doxygen  1.0 dev
cl_inv.c
Go to the documentation of this file.
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++)
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 #ifdef QMAX
48  re.DrawChar (x, y, *string, 256);
49 #else
50  re.DrawChar (x, y, *string);
51 #endif
52  x+=8;
53  string++;
54  }
55 }
56 
57 void SetStringHighBit (char *s)
58 {
59  while (*s)
60  *s++ |= 128;
61 }
62 
63 /*
64 ================
65 CL_DrawInventory
66 ================
67 */
68 #define DISPLAY_ITEMS 17
69 
70 void CL_DrawInventory (void)
71 {
72  int i, j;
73  int num, selected_num, item;
74  int index[MAX_ITEMS];
75  char string[1024];
76  int x, y;
77  char binding[1024];
78  char *bind;
79  int selected;
80  int top;
81 
83 
84  num = 0;
85  selected_num = 0;
86  for (i=0 ; i<MAX_ITEMS ; i++)
87  {
88  if (i==selected)
89  selected_num = num;
90  if (cl.inventory[i])
91  {
92  index[num] = i;
93  num++;
94  }
95  }
96 
97  // determine scroll point
98  top = selected_num - DISPLAY_ITEMS/2;
99  if (num - top < DISPLAY_ITEMS)
100  top = num - DISPLAY_ITEMS;
101  if (top < 0)
102  top = 0;
103 
104  x = (viddef.width-256)/2;
105  y = (viddef.height-240)/2;
106 
107  // repaint everything next frame
108  SCR_DirtyScreen ();
109 
110  re.DrawPic (x, y+8, "inventory");
111 
112  y += 24;
113  x += 24;
114  Inv_DrawString (x, y, "hotkey ### item");
115  Inv_DrawString (x, y+8, "------ --- ----");
116  y += 16;
117  for (i=top ; i<num && i < top+DISPLAY_ITEMS ; i++)
118  {
119  item = index[i];
120  // search for a binding
121  Com_sprintf (binding, sizeof(binding), "use %s", cl.configstrings[CS_ITEMS+item]);
122  bind = "";
123  for (j=0 ; j<256 ; j++)
124  if (keybindings[j] && !Q_stricmp (keybindings[j], binding))
125  {
126  bind = Key_KeynumToString(j);
127  break;
128  }
129 
130  Com_sprintf (string, sizeof(string), "%6s %3i %s", bind, cl.inventory[item],
131  cl.configstrings[CS_ITEMS+item] );
132  if (item != selected)
133  SetStringHighBit (string);
134  else // draw a blinky cursor by the selected item
135  {
136  if ( (int)(cls.realtime*10) & 1)
137 #ifdef QMAX
138  re.DrawChar (x-8, y, 15, 256);
139 #else
140  re.DrawChar (x-8, y, 15);
141 #endif
142  }
143  Inv_DrawString (x, y, string);
144  y += 8;
145  }
146 
147 
148 }
149 
150 
CL_ParseInventory
void CL_ParseInventory(void)
Definition: cl_inv.c:29
MSG_ReadShort
int MSG_ReadShort(sizebuf_t *msg_read)
Definition: common.c:735
net_message
sizebuf_t net_message
Definition: net_chan.c:82
Inv_DrawString
void Inv_DrawString(int x, int y, char *string)
Definition: cl_inv.c:43
CS_ITEMS
#define CS_ITEMS
Definition: q_shared.h:1140
x
GLint GLenum GLint x
Definition: qgl_win.c:116
viddef_t::width
int width
Definition: vid.h:29
i
int i
Definition: q_shared.c:305
keybindings
char * keybindings[K_LAST]
Definition: keys.c:39
viddef_t::height
int height
Definition: vid.h:29
CL_DrawInventory
void CL_DrawInventory(void)
Definition: cl_inv.c:70
SCR_DirtyScreen
void SCR_DirtyScreen(void)
Definition: cl_scrn.c:687
STAT_SELECTED_ITEM
#define STAT_SELECTED_ITEM
Definition: q_shared.h:1037
viddef
viddef_t viddef
Definition: vid_dll.c:49
j
GLint j
Definition: qgl_win.c:150
Key_KeynumToString
char * Key_KeynumToString(int keynum)
Definition: keys.c:482
client_state_t::frame
frame_t frame
Definition: client.h:136
MAX_ITEMS
#define MAX_ITEMS
Definition: q_shared.h:85
refexport_t::DrawPic
void(* DrawPic)(int x, int y, char *name)
Definition: ref.h:196
Q_stricmp
int Q_stricmp(char *s1, char *s2)
Definition: q_shared.c:1192
SetStringHighBit
void SetStringHighBit(char *s)
Definition: cl_inv.c:57
y
GLint y
Definition: qgl_win.c:115
re
refexport_t re
Definition: vid_dll.c:31
frame_t::playerstate
player_state_t playerstate
Definition: client.h:70
DISPLAY_ITEMS
#define DISPLAY_ITEMS
Definition: cl_inv.c:68
client_state_t::inventory
int inventory[MAX_ITEMS]
Definition: client.h:159
client_state_t::configstrings
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]
Definition: client.h:178
refexport_t::DrawChar
void(* DrawChar)(int x, int y, int c)
Definition: ref.h:193
top
GLdouble GLdouble GLdouble top
Definition: qgl_win.c:159
cls
client_static_t cls
Definition: cl_main.c:105
cl
client_state_t cl
Definition: cl_main.c:106
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1236
client.h
player_state_t::stats
short stats[MAX_STATS]
Definition: q_shared.h:1220
client_static_t::realtime
int realtime
Definition: client.h:228