Esempio n. 1
0
        public void Update()
        {
            // Checks if there is scrolling.
            int scrollWheel = Mouse.GetState().ScrollWheelValue;
            Rectangle mouseRectangle = InputHelper.MouseRectangle;

            if (_levelCount > 5)
            {
                if (mouseRectangle.Intersects(_scissorRectangle))
                {
                    if (_lastScrollWheel != scrollWheel)
                    {
                        foreach (LevelInfo l in _levelInfos)
                        {
                            l.VelocityY = (scrollWheel - _lastScrollWheel) / 5;
                        }
                    }
                }

                _lastScrollWheel = scrollWheel;

                float velocityY = 0;

                // If first element is below its starting point, make them all go back, but only if the user is not making them go back already.
                if (_levelInfos[0].GetY() > _startingY && _levelInfos[0].VelocityY > -1)
                    velocityY = -1f;

                // If last element is above bottom of box, make them go back, but only if the user is not making them go back already.
                if (_levelInfos[_levelCount - 1].GetY() < _scissorRectangle.Y + _scissorRectangle.Height - _levelInfos[0].GetHeight() - CalcHelper.ApplyHeightRatio(3) && _levelInfos[0].VelocityY < 1)
                    velocityY = 1f;

                if (velocityY != 0)
                    foreach (LevelInfo l in _levelInfos)
                    {
                        l.VelocityY = velocityY;
                    }
            }

            // Makes the level infos scroll.
            foreach (LevelInfo l in _levelInfos)
            {
                l.Update();
            }

            // Check to see if a level info is being selected.
            if (InputHelper.IsLeftMousePressed() && InputHelper.MouseRectangle.Intersects(_scissorRectangle))
            {
                foreach (LevelInfo level in _levelInfos)
                {
                    if (level.IsBeingClickedOn())
                    {
                        _selectedLevelIndex = _levelInfos.IndexOf(level);
                        break;
                    }
                }
            }
            if (_selectedLevelIndex > -1 && _selectedLevelIndex < _levelCount)
                _selectedLevel = _levelInfos[_selectedLevelIndex];
            else _selectedLevel = null;

            // Update buttons.
            foreach (FunctionButton b in _buttons)
            {
                b.Update(_functionButtonContainer);
            }

            // Make the selected level know about it.
            foreach (LevelInfo level in _levelInfos)
            {
                if (level == _selectedLevel)
                {
                    level.IsSelected = true;
                }
                else
                {
                    level.IsSelected = false;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks the Level directory and load all levels.
        /// </summary>
        public void LoadLevels()
        {
            // Retrieves the information of the levels.
            List<string> filePaths = DataFolder.GetLevelPaths();
            List<string> fileNames = DataFolder.GetLevelNames();
            List<DateTime> fileModifiedDates = DataFolder.GetLevelLastModifiedDates();

            // Stores all this inforamtion into separate LevelInfo classes.
            _levelCount = filePaths.Count;
            _levelInfos = new List<LevelInfo>();
            for (int i = 0; i < _levelCount; i++)
            {
                LevelInfo lev = new LevelInfo(fileNames[i], filePaths[i], fileModifiedDates[i]);
                _levelInfos.Add(lev);
            }

            // Arranges the levels in an alphabetical list and sets their position.
            _startingY = _scissorRectangle.Y + CalcHelper.ApplyHeightRatio(3);
            for (int i = 0; i < _levelCount; i++)
            {
                _levelInfos[i].SetPosition(_startingY, i);
            }
        }