NScumm.Sky.Logic.FnStartMenu C# (CSharp) Method

FnStartMenu() private method

private FnStartMenu ( uint firstObject, uint b, uint c ) : bool
firstObject uint
b uint
c uint
return bool
        private bool FnStartMenu(uint firstObject, uint b, uint c)
        {
            // initialize the top menu bar
            // firstObject is o0 for game menu, k0 for linc

            uint i;
            firstObject /= 4;

            // (1) FIRST, SET UP THE 2 ARROWS SO THEY APPEAR ON SCREEN

            Compact cpt = _skyCompact.FetchCpt(47);
            cpt.Core.status = ST_MOUSE + ST_FOREGROUND + ST_LOGIC + ST_RECREATE;
            cpt.Core.screen = (ushort)(_scriptVariables[SCREEN] & 0xffff);

            cpt = _skyCompact.FetchCpt(48);
            cpt.Core.status = ST_MOUSE + ST_FOREGROUND + ST_LOGIC + ST_RECREATE;
            cpt.Core.screen = (ushort)(_scriptVariables[SCREEN] & 0xffff);

            // (2) COPY OBJECTS FROM NON-ZERO INVENTORY VARIABLES INTO OBJECT DISPLAY LIST (& COUNT THEM)

            // sort the objects and pad with blanks

            uint menuLength = 0;
            for (i = firstObject; i < firstObject + _objectList.Length; i++)
            {
                if (_scriptVariables[(int)i] != 0)
                    _objectList[menuLength++] = _scriptVariables[(int)i];
            }
            _scriptVariables[MENU_LENGTH] = menuLength;

            // (3) OK, NOW TOP UP THE LIST WITH THE REQUIRED NO. OF BLANK OBJECTS (for min display length 11)

            uint blankId = 51;
            for (i = menuLength; i < 11; i++)
                _objectList[i] = blankId++;

            // (4) KILL ID's OF ALL 20 OBJECTS SO UNWANTED ICONS (SCROLLED OFF) DON'T REMAIN ON SCREEN
            // (There should be a better way of doing this - only kill id of 12th item when menu has scrolled right)

            for (i = 0; i < _objectList.Length; i++)
            {
                if (_objectList[i] != 0)
                    _skyCompact.FetchCpt((ushort)_objectList[i]).Core.status = ST_LOGIC;
                else break;
            }

            // (5) NOW FIND OUT WHICH OBJECT TO START THE DISPLAY FROM (depending on scroll offset)

            if (menuLength < 11) // check we can scroll
                _scriptVariables[SCROLL_OFFSET] = 0;
            else if (menuLength < _scriptVariables[SCROLL_OFFSET] + 11)
                _scriptVariables[SCROLL_OFFSET] = menuLength - 11;

            // (6) AND FINALLY, INITIALIZE THE 11 OBJECTS SO THEY APPEAR ON SCREEEN

            ushort rollingX = TOP_LEFT_X + 28;
            for (i = 0; i < 11; i++)
            {
                cpt = _skyCompact.FetchCpt((ushort)_objectList[_scriptVariables[SCROLL_OFFSET] + i]);

                cpt.Core.status = ST_MOUSE + ST_FOREGROUND + ST_LOGIC + ST_RECREATE;
                cpt.Core.screen = (ushort)(_scriptVariables[SCREEN] & 0xffff);

                cpt.Core.xcood = rollingX;
                rollingX += 24;

                if (_scriptVariables[MENU] == 2)
                    cpt.Core.ycood = 136;
                else
                    cpt.Core.ycood = 112;
            }

            return true;
        }
Logic