2009-02-28 14:41:18 +00:00
|
|
|
/*
|
2010-06-18 07:48:31 +00:00
|
|
|
* Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
2010-06-18 07:48:31 +00:00
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2010-06-18 07:48:31 +00:00
|
|
|
*
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
2010-07-13 18:19:42 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
2010-06-18 07:48:31 +00:00
|
|
|
*
|
2010-06-18 15:44:38 +00:00
|
|
|
* =======================================================================
|
|
|
|
*
|
|
|
|
* This file implements the inventory screen
|
|
|
|
*
|
|
|
|
* =======================================================================
|
2010-06-18 07:48:31 +00:00
|
|
|
*/
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-03-03 13:43:32 +00:00
|
|
|
#include "header/client.h"
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
void CL_ParseInventory (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0 ; i<MAX_ITEMS ; i++)
|
|
|
|
cl.inventory[i] = MSG_ReadShort (&net_message);
|
|
|
|
}
|
|
|
|
|
2009-03-01 21:56:05 +00:00
|
|
|
static void Inv_DrawString (int x, int y, char *string)
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
|
|
|
while (*string)
|
|
|
|
{
|
2010-06-18 07:48:31 +00:00
|
|
|
re.DrawChar (x, y, *string);
|
2009-02-28 14:41:18 +00:00
|
|
|
x+=8;
|
|
|
|
string++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-01 21:56:05 +00:00
|
|
|
static void SetStringHighBit (char *s)
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
|
|
|
while (*s)
|
|
|
|
*s++ |= 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DISPLAY_ITEMS 17
|
|
|
|
|
|
|
|
void CL_DrawInventory (void)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int num, selected_num, item;
|
|
|
|
int index[MAX_ITEMS];
|
|
|
|
char string[1024];
|
|
|
|
int x, y;
|
|
|
|
char binding[1024];
|
2009-03-01 21:56:05 +00:00
|
|
|
const char *bind;
|
2009-02-28 14:41:18 +00:00
|
|
|
int selected;
|
|
|
|
int top;
|
|
|
|
|
|
|
|
selected = cl.frame.playerstate.stats[STAT_SELECTED_ITEM];
|
|
|
|
|
|
|
|
num = 0;
|
|
|
|
selected_num = 0;
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
for (i=0 ; i<MAX_ITEMS ; i++)
|
|
|
|
{
|
|
|
|
if (i==selected)
|
|
|
|
selected_num = num;
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (cl.inventory[i])
|
|
|
|
{
|
|
|
|
index[num] = i;
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-18 07:48:31 +00:00
|
|
|
/* determine scroll point */
|
2009-02-28 14:41:18 +00:00
|
|
|
top = selected_num - DISPLAY_ITEMS/2;
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (num - top < DISPLAY_ITEMS)
|
|
|
|
top = num - DISPLAY_ITEMS;
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (top < 0)
|
|
|
|
top = 0;
|
|
|
|
|
|
|
|
x = (viddef.width-256)/2;
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
y = (viddef.height-240)/2;
|
|
|
|
|
2010-06-18 07:48:31 +00:00
|
|
|
/* repaint everything next frame */
|
2009-02-28 14:41:18 +00:00
|
|
|
SCR_DirtyScreen ();
|
|
|
|
|
|
|
|
re.DrawPic (x, y+8, "inventory");
|
|
|
|
|
|
|
|
y += 24;
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
x += 24;
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
Inv_DrawString (x, y, "hotkey ### item");
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
Inv_DrawString (x, y+8, "------ --- ----");
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
y += 16;
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
for (i=top ; i<num && i < top+DISPLAY_ITEMS ; i++)
|
|
|
|
{
|
|
|
|
item = index[i];
|
2010-06-18 07:48:31 +00:00
|
|
|
/* search for a binding */
|
2009-02-28 14:41:18 +00:00
|
|
|
Com_sprintf (binding, sizeof(binding), "use %s", cl.configstrings[CS_ITEMS+item]);
|
|
|
|
bind = "";
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
for (j=0 ; j<256 ; j++)
|
|
|
|
if (keybindings[j] && !Q_stricmp (keybindings[j], binding))
|
|
|
|
{
|
|
|
|
bind = Key_KeynumToString(j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Com_sprintf (string, sizeof(string), "%6s %3i %s", bind, cl.inventory[item],
|
2010-06-18 07:48:31 +00:00
|
|
|
|
|
|
|
cl.configstrings[CS_ITEMS+item] );
|
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
if (item != selected)
|
|
|
|
SetStringHighBit (string);
|
2010-06-18 07:48:31 +00:00
|
|
|
else
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-06-18 07:48:31 +00:00
|
|
|
/* draw a blinky cursor by the selected item */
|
2009-02-28 14:41:18 +00:00
|
|
|
if ( (int)(cls.realtime*10) & 1)
|
|
|
|
re.DrawChar (x-8, y, 15);
|
|
|
|
}
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
Inv_DrawString (x, y, string);
|
2010-06-18 07:48:31 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
y += 8;
|
|
|
|
}
|
|
|
|
}
|
2010-06-18 15:44:38 +00:00
|
|
|
|