Beispiel #1
0
    public static void AddRPGMenuKey(RPGMenu menu, char k, int value)
    {
        //{ Add a dynamically defined RPGMenuKey to the menu.}

        //{ Initialize the values.}
        RPGMenuKey key = new RPGMenuKey(k, value);

        key.next      = menu.firstKey;
        menu.firstKey = key;
    }
Beispiel #2
0
    public static int SelectMenu(RPGMenu menu, int mode)
    {
        //{ This function will allow the user to browse through the menu and will}
        //{ return a value based upon the user's selection.}

        //{The menu is now active!}
        menu.active = true;

        //{Show the menu to the user.}
        DisplayMenu(menu);

        //{Initialize UK and r}
        bool UK = false;
        int  r  = -1;

        char getit = '\0';

        //{Start the loop. Remain in this loop until either the player makes a selection}
        //{or cancels the menu using the ESC key.}
        do
        {
            //{Read the input from the keyboard.}
            getit = rpgtext.RPGKey();

            //{Certain keys need processing- if so, process them.}
            switch (getit)
            {
            //{Selection Movement Keys}
            case (char)72:
            case '8':
                RPMUpKey(menu);
                break;

            case (char)80:
            case '2':
                RPMDownKey(menu);
                break;

            //{If we recieve an ESC, better check to make sure we're in a}
            //{cancelable menu. If not, convert the ESC to an unused key.}
            case (char)27:
                if (mode == RPMNoCancel)
                {
                    getit = 'Q';
                }
                break;
            }

            //{Check to see if a special MENU KEY has been pressed.}
            if (menu.firstKey != null)
            {
                RPGMenuKey m = menu.firstKey;
                while (m != null)
                {
                    if (getit == m.k)
                    {
                        UK = true;
                        r  = m.value;
                        break;
                    }

                    m = m.next;
                }
            }

            //{Check for a SPACE or ESC.}
        }while ((getit != ' ') && (getit != (char)27) && !UK);

        //{The menu is no longer active.}
        menu.active = false;

        //{We have to send back a different value depending upon whether a selection}
        //{was made or the menu was cancelled. If an item was selected, return its}
        //{value field. The value always returned by a cancel will be -1.}
        //{If a MenuKey was pressed, r already contains the right value.}
        if (getit == ' ')
        {
            r = RPMLocateByPosition(menu, menu.selectItem).value;
        }

        if (mode != RPMNoCleanup)
        {
            //{Remove the menu from the display. I'm gonna use Window for this, since}
            //{ClrScr in this language doesn't take paramters. Bummer.}

            //{Check to see whether or not a border was used.}
            if (menu.borderColor == Crt.Color.Black)
            {
                Crt.Window(menu.x1 + 1, menu.y1 + 1, menu.x2 - 1, menu.y2 - 1);
                Crt.ClrScr();
            }
            else
            {
                Crt.Window(menu.x1, menu.y1, menu.x2, menu.y2);
                Crt.ClrScr();
            }

            //{If there's an associated description box, clear that too.}
            if (menu.dx1 > 0)
            {
                Crt.Window(menu.dx1, menu.dy1, menu.dx2, menu.dy2);
                Crt.ClrScr();
            }
        }

        //{Reset the window to normal values}
        Crt.Window(1, 1, WDM.CON_WIDTH, WDM.CON_HEIGHT);

        return(r);
    }