Ejemplo n.º 1
0
        /// <summary>
        /// Shows the menu items for the given MenuHeader.
        /// </summary>
        /// <param name="header">The MenuHeader to show the menu items of.</param>
        private void ShowMenu(MenuHeader header)
        {
            // Interestingly, it would seem that the width is always calculated using the first item. The
            // original AGI games tended to make the item names a consistent length within each menu.
            MenuItem firstItem = (header.Items.Count > 0 ? header.Items[0] : null);
            int      height    = header.Height;
            int      width     = (firstItem != null ? firstItem.Name.Length : header.Title.Name.Length);
            int      column    = (firstItem != null ? firstItem.Col : header.Title.Col);

            // Compute window size and position and put them into the appropriate bytes of the words.
            int menuDim = ((height * CHARHEIGHT + 2 * VMARGIN) << 8) | (width * CHARWIDTH + 2 * HMARGIN);
            int menuPos = (((column - 1) * CHARWIDTH) << 8) | ((height + 1) * CHARHEIGHT + VMARGIN - 1);

            // Show the menu title as being selected.
            Select(header.Title);

            // Open a window for this menu using the calculated position and dimensions.
            textGraphics.OpenWindow(new TextWindow(menuPos, menuDim, 15, 0));

            // Render each of the items in this menu.
            foreach (MenuItem item in header.Items)
            {
                if (item == header.CurrentItem)
                {
                    Select(item);
                }
                else
                {
                    Deselect(item);
                }
            }
        }