Annotation of quake2/client/cl_inv.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.