vkQuake2 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 extern cvar_t *vid_hudscale;
25 
26 /*
27 ================
28 CL_ParseInventory
29 ================
30 */
31 void CL_ParseInventory (void)
32 {
33  int i;
34 
35  for (i=0 ; i<MAX_ITEMS ; i++)
37 }
38 
39 
40 /*
41 ================
42 Inv_DrawString
43 ================
44 */
45 void Inv_DrawString (int x, int y, char *string)
46 {
47  while (*string)
48  {
49  re.DrawChar (x, y, *string);
50  x+=8 * vid_hudscale->value;
51  string++;
52  }
53 }
54 
55 void SetStringHighBit (char *s)
56 {
57  while (*s)
58  *s++ |= 128;
59 }
60 
61 /*
62 ================
63 CL_DrawInventory
64 ================
65 */
66 #define DISPLAY_ITEMS 17
67 
68 void CL_DrawInventory (void)
69 {
70  int i, j;
71  int num, selected_num, item;
72  int index[MAX_ITEMS];
73  char string[1024];
74  int x, y;
75  char binding[1024];
76  char *bind;
77  int selected;
78  int top;
79 
81 
82  num = 0;
83  selected_num = 0;
84  for (i=0 ; i<MAX_ITEMS ; i++)
85  {
86  if (i==selected)
87  selected_num = num;
88  if (cl.inventory[i])
89  {
90  index[num] = i;
91  num++;
92  }
93  }
94 
95  // determine scroll point
96  top = selected_num - DISPLAY_ITEMS/2;
97  if (num - top < DISPLAY_ITEMS)
98  top = num - DISPLAY_ITEMS;
99  if (top < 0)
100  top = 0;
101 
102  x = (viddef.width-256 * vid_hudscale->value)/2;
103  y = (viddef.height-240 * vid_hudscale->value)/2;
104 
105  // repaint everything next frame
106  SCR_DirtyScreen ();
107 
108  re.DrawPic (x, y + 8 * vid_hudscale->value, "inventory");
109 
110  y += 24 * vid_hudscale->value;
111  x += 24 * vid_hudscale->value;
112  Inv_DrawString (x, y, "hotkey ### item");
113  Inv_DrawString (x, y+8*vid_hudscale->value, "------ --- ----");
114  y += 16 * vid_hudscale->value;
115  for (i=top ; i<num && i < top+DISPLAY_ITEMS ; i++)
116  {
117  item = index[i];
118  // search for a binding
119  Com_sprintf (binding, sizeof(binding), "use %s", cl.configstrings[CS_ITEMS+item]);
120  bind = "";
121  for (j=0 ; j<256 ; j++)
122  if (keybindings[j] && !Q_stricmp (keybindings[j], binding))
123  {
124  bind = Key_KeynumToString(j);
125  break;
126  }
127 
128  Com_sprintf (string, sizeof(string), "%6s %3i %s", bind, cl.inventory[item],
129  cl.configstrings[CS_ITEMS+item] );
130  if (item != selected)
131  SetStringHighBit (string);
132  else // draw a blinky cursor by the selected item
133  {
134  if ( (int)(cls.realtime*10) & 1)
135  re.DrawChar (x - 8 * vid_hudscale->value, y * vid_hudscale->value, 15);
136  }
137  Inv_DrawString (x, y, string);
138  y += 8 * vid_hudscale->value;
139  }
140 
141 
142 }
143 
144 
CL_ParseInventory
void CL_ParseInventory(void)
Definition: cl_inv.c:31
MSG_ReadShort
int MSG_ReadShort(sizebuf_t *msg_read)
Definition: common.c:716
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:45
CS_ITEMS
#define CS_ITEMS
Definition: q_shared.h:1116
x
GLint GLenum GLint x
Definition: qgl_win.c:116
i
int i
Definition: q_shared.c:305
vid_hudscale
cvar_t * vid_hudscale
Definition: vid_dll.c:48
CL_DrawInventory
void CL_DrawInventory(void)
Definition: cl_inv.c:68
SCR_DirtyScreen
void SCR_DirtyScreen(void)
Definition: cl_scrn.c:681
STAT_SELECTED_ITEM
#define STAT_SELECTED_ITEM
Definition: q_shared.h:1013
cvar_s
Definition: q_shared.h:324
viddef
viddef_t viddef
Definition: vid_dll.c:54
j
GLint j
Definition: qgl_win.c:150
viddef_t::width
unsigned width
Definition: vid.h:29
Key_KeynumToString
char * Key_KeynumToString(int keynum)
Definition: keys.c:479
viddef_t::height
unsigned height
Definition: vid.h:29
cvar_s::value
float value
Definition: q_shared.h:331
client_state_t::frame
frame_t frame
Definition: client.h:116
MAX_ITEMS
#define MAX_ITEMS
Definition: q_shared.h:92
refexport_t::DrawPic
void(* DrawPic)(int x, int y, char *name)
Definition: ref.h:167
Q_stricmp
int Q_stricmp(char *s1, char *s2)
Definition: q_shared.c:1180
SetStringHighBit
void SetStringHighBit(char *s)
Definition: cl_inv.c:55
s
static fixed16_t s
Definition: r_scan.c:30
y
GLint y
Definition: qgl_win.c:115
re
refexport_t re
Definition: vid_dll.c:32
frame_t::playerstate
player_state_t playerstate
Definition: client.h:50
DISPLAY_ITEMS
#define DISPLAY_ITEMS
Definition: cl_inv.c:66
client_state_t::inventory
int inventory[MAX_ITEMS]
Definition: client.h:139
client_state_t::configstrings
char configstrings[MAX_CONFIGSTRINGS][MAX_QPATH]
Definition: client.h:158
refexport_t::DrawChar
void(* DrawChar)(int x, int y, int c)
Definition: ref.h:169
top
GLdouble GLdouble GLdouble top
Definition: qgl_win.c:159
cls
client_static_t cls
Definition: cl_main.c:90
keybindings
char * keybindings[256]
Definition: keys.c:40
cl
client_state_t cl
Definition: cl_main.c:91
Com_sprintf
void Com_sprintf(char *dest, int size, char *fmt,...)
Definition: q_shared.c:1223
client.h
player_state_t::stats
short stats[MAX_STATS]
Definition: q_shared.h:1196
client_static_t::realtime
int realtime
Definition: client.h:208