示例#1
0
        /// <summary>
        /// Shows the inventory screen. Implements the AGI "status" command.
        /// </summary>
        public void ShowInventoryScreen()
        {
            List <InvItem> invItems          = new List <InvItem>();
            byte           selectedItemIndex = 0;
            int            howMany           = 0;
            int            row = 2;

            // Switch to the text screen.
            textGraphics.TextScreen(15);

            // Construct the table of objects being carried, deciding where on
            // the screen they are to be printed as we go.
            for (byte i = 0; i < state.Objects.Count; i++)
            {
                Object obj = state.Objects[i];
                if (obj.Room == Defines.CARRYING)
                {
                    InvItem invItem = new InvItem();
                    invItem.Num  = i;
                    invItem.Name = obj.Name;
                    invItem.Row  = row;

                    if ((howMany & 1) == 0)
                    {
                        invItem.Col = 1;
                    }
                    else
                    {
                        row++;
                        invItem.Col = 39 - invItem.Name.Length;
                    }

                    if (i == state.Vars[Defines.SELECTED_OBJ])
                    {
                        selectedItemIndex = (byte)invItems.Count;
                    }

                    invItems.Add(invItem);
                    howMany++;
                }
            }

            // If no objects in inventory, then say so.
            if (howMany == 0)
            {
                InvItem invItem = new InvItem();
                invItem.Num  = 0;
                invItem.Name = "nothing";
                invItem.Row  = row;
                invItem.Col  = 16;
                invItems.Add(invItem);
            }

            // Display the inventory items.
            DrawInventoryItems(invItems, invItems[selectedItemIndex]);

            // If we are not allowing an item to be selected, we simply wait for a key press then return.
            if (!state.Flags[Defines.ENABLE_SELECT])
            {
                userInput.WaitForKey();
            }
            else
            {
                // Otherwise we handle movement between the items and selection of an item.
                while (true)
                {
                    int key = userInput.WaitForKey();
                    if (key == (int)Keys.Enter)
                    {
                        state.Vars[Defines.SELECTED_OBJ] = invItems[selectedItemIndex].Num;
                        break;
                    }
                    else if (key == (int)Keys.Escape)
                    {
                        state.Vars[Defines.SELECTED_OBJ] = 0xFF;
                        break;
                    }
                    else if ((key == (int)Keys.Up) || (key == (int)Keys.Down) || (key == (int)Keys.Right) || (key == (int)Keys.Left))
                    {
                        selectedItemIndex = MoveSelect(invItems, (Keys)key, selectedItemIndex);
                    }
                }
            }

            // Switch back to the graphics screen.
            textGraphics.GraphicsScreen();
        }