cl_inv.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. Copyright (C) 1997-2001 Id Software, Inc.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. // cl_inv.c -- client inventory screen
  16. #include "client.h"
  17. /*
  18. ================
  19. CL_ParseInventory
  20. ================
  21. */
  22. void CL_ParseInventory (void)
  23. {
  24. int i;
  25. for (i=0 ; i<MAX_ITEMS ; i++)
  26. cl.inventory[i] = MSG_ReadShort (&net_message);
  27. }
  28. /*
  29. ================
  30. Inv_DrawString
  31. ================
  32. */
  33. void Inv_DrawString (int x, int y, char *string)
  34. {
  35. while (*string)
  36. {
  37. re.DrawChar (x, y, *string);
  38. x+=8;
  39. string++;
  40. }
  41. }
  42. void SetStringHighBit (char *s)
  43. {
  44. while (*s)
  45. *s++ |= 128;
  46. }
  47. /*
  48. ================
  49. CL_DrawInventory
  50. ================
  51. */
  52. #define DISPLAY_ITEMS 17
  53. void CL_DrawInventory (void)
  54. {
  55. int i, j;
  56. int num, selected_num, item;
  57. int index[MAX_ITEMS];
  58. char string[1024];
  59. int x, y;
  60. char binding[1024];
  61. char *bind;
  62. int selected;
  63. int top;
  64. selected = cl.frame.playerstate.stats[STAT_SELECTED_ITEM];
  65. num = 0;
  66. selected_num = 0;
  67. for (i=0 ; i<MAX_ITEMS ; i++)
  68. {
  69. if (i==selected)
  70. selected_num = num;
  71. if (cl.inventory[i])
  72. {
  73. index[num] = i;
  74. num++;
  75. }
  76. }
  77. // determine scroll point
  78. top = selected_num - DISPLAY_ITEMS/2;
  79. if (num - top < DISPLAY_ITEMS)
  80. top = num - DISPLAY_ITEMS;
  81. if (top < 0)
  82. top = 0;
  83. x = (viddef.width-256)/2;
  84. y = (viddef.height-240)/2;
  85. // repaint everything next frame
  86. SCR_DirtyScreen ();
  87. re.DrawPic (x, y+8, "inventory");
  88. y += 24;
  89. x += 24;
  90. Inv_DrawString (x, y, "hotkey ### item");
  91. Inv_DrawString (x, y+8, "------ --- ----");
  92. y += 16;
  93. for (i=top ; i<num && i < top+DISPLAY_ITEMS ; i++)
  94. {
  95. item = index[i];
  96. // search for a binding
  97. Com_sprintf (binding, sizeof(binding), "use %s", cl.configstrings[CS_ITEMS+item]);
  98. bind = "";
  99. for (j=0 ; j<256 ; j++)
  100. if (keybindings[j] && !Q_stricmp (keybindings[j], binding))
  101. {
  102. bind = Key_KeynumToString(j);
  103. break;
  104. }
  105. Com_sprintf (string, sizeof(string), "%6s %3i %s", bind, cl.inventory[item],
  106. cl.configstrings[CS_ITEMS+item] );
  107. if (item != selected)
  108. SetStringHighBit (string);
  109. else // draw a blinky cursor by the selected item
  110. {
  111. if ( (int)(cls.realtime*10) & 1)
  112. re.DrawChar (x-8, y, 15);
  113. }
  114. Inv_DrawString (x, y, string);
  115. y += 8;
  116. }
  117. }