Beispiel #1
0
        public bool Initialize(GameMain gameMain, out string reason)
        {
            _gameMain = gameMain;
            _backGroundStar = SpriteManager.GetSprite("BackgroundStar", _gameMain.Random);
            if (_backGroundStar == null)
            {
                reason = "Star sprite doesn't exist.";
                return false;
            }

            int numOfStars = (_gameMain.ScreenSize.X * _gameMain.ScreenSize.Y) / 500;

            _backGroundStars = new BackgroundStar[numOfStars];
            List<BackgroundStar> orderedBackgroundStars = new List<BackgroundStar>();
            for (int i = 0; i < numOfStars; i++)
            {
                Color color = Color.White;
                switch (_gameMain.Random.Next(6))
                {
                    case 0:
                        color = Color.OrangeRed;
                        break;
                    case 1:
                        color = Color.LightBlue;
                        break;
                    case 2:
                        color = Color.Violet;
                        break;
                    case 3:
                        color = Color.LightGreen;
                        break;
                    case 4:
                        color = Color.Yellow;
                        break;
                }
                BackgroundStar newStar = new BackgroundStar(gameMain.Random.Next(gameMain.ScreenSize.X), gameMain.Random.Next(gameMain.ScreenSize.Y), _gameMain.Random.Next(1, 20), color);
                orderedBackgroundStars.Add(newStar);
            }
            orderedBackgroundStars.Sort((a, b) => { return a.Layer.CompareTo(b.Layer); });
            _backGroundStars = orderedBackgroundStars.ToArray();

            reason = null;
            return true;
        }
Beispiel #2
0
        public bool Initialize(int screenWidth, int screenHeight, Xasteroids parentForm, out string reason)
        {
            _parentForm = parentForm;
            Random = new Random();
            MousePos = new Point();
            ScreenSize = new Point(screenWidth, screenHeight);
            PlayerList = new PlayerList();

            ShipShader = GorgonLibrary.Graphics.FXShader.FromFile("ColorShader.fx", GorgonLibrary.Graphics.ShaderCompileOptions.OptimizationLevel3);

            if (!SpriteManager.Initialize(out reason))
            {
                return false;
            }
            if (!FontManager.Initialize(out reason))
            {
                return false;
            }

            _backgroundStars = new BackgroundStars();
            if (!_backgroundStars.Initialize(this, out reason))
            {
                return false;
            }

            Cursor = SpriteManager.GetSprite("Cursor", Random);
            if (Cursor == null)
            {
                reason = "Cursor is not defined in sprites.xml";
                return false;
            }

            PlayerManager = new PlayerManager(this);
            AsteroidManager = new AsteroidManager(this);
            ObjectManager = new ObjectManager(this);
            ShipSelectionWindow = new ShipSelectionWindow();
            if (!ShipSelectionWindow.Initialize(this, out reason))
            {
                return false;
            }
            ShipSelectionWindow.ShipSelected += OnShipSelected;

            _mainMenu = new MainMenu();
            if (!_mainMenu.Initialize(this, out reason))
            {
                return false;
            }

            _screenInterface = _mainMenu;
            _currentScreen = Screen.MainMenu;

            ChatText = new StringBuilder();
            NewChatMessage = false;

            return true;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="items"></param>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="maxVisible"></param>
        /// <param name="r"></param>
        /// <param name="reason"></param>
        public bool Initialize(List<string> items, int xPos, int yPos, int width, int height, int maxVisible, Random r, out string reason)
        {
            _items = items;
            _xPos = xPos;
            _yPos = yPos;
            _width = width;
            _height = height;

            _selectedIndex = 0;
            Dropped = false;
            _downArrowSprite = SpriteManager.GetSprite("ScrollDownBGButton", r);

            if (items.Count < maxVisible)
            {
                _haveScroll = false;
                maxVisible = items.Count;
            }
            else if (items.Count > maxVisible)
            {
                _haveScroll = true;
            }

            Enabled = true;

            _buttons = new List<BBInvisibleStretchButton>();
            _dropBackground = new BBStretchableImage();
            _scrollBar = new BBScrollBar();

            for (int i = 0; i <= maxVisible; i++)
            {
                BBInvisibleStretchButton button = new BBInvisibleStretchButton();
                if (!button.Initialize(string.Empty, ButtonTextAlignment.LEFT, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, _xPos, _yPos + (i * height), _width, _height, r, out reason))
                {
                    return false;
                }
                _buttons.Add(button);
            }
            if (!_dropBackground.Initialize(_xPos, _yPos, width, height, StretchableImageType.ThinBorderBG, r, out reason))
            {
                return false;
            }
            if (!_scrollBar.Initialize(_xPos + _width, _yPos + _height, maxVisible * _height, maxVisible, items.Count, false, false, r, out reason))
            {
                return false;
            }
            RefreshSelection();
            RefreshLabels();
            return true;
        }
        public bool Initialize(int xPos, int yPos, int length, int amountOfVisibleItems, int amountOfItems, bool isHorizontal, bool isSlider, Random r, out string reason)
        {
            _xPos = xPos;
            _yPos = yPos;
            _scroll = new BBUniStretchButton();

            _amountOfItems = amountOfItems;
            _amountVisible = amountOfVisibleItems;
            _isSlider = isSlider;
            _isHorizontal = isHorizontal;

            _scrollBarLength = length;

            if (!isSlider)
            {
                _scrollButtonLength = (int)(((float)amountOfVisibleItems / amountOfItems) * _scrollBarLength);
                if (!isHorizontal)
                {
                    if (!_scroll.Initialize(new List<string> { "TinyScrollVerticalBGButton1", "TinyScrollVerticalBGButton2", "TinyScrollVerticalBGButton3" },
                                           new List<string> { "TinyScrollVerticalFGButton1", "TinyScrollVerticalFGButton2", "TinyScrollVerticalFGButton3" },
                                           isHorizontal, "", ButtonTextAlignment.LEFT, xPos, yPos, 5, _scrollButtonLength, 3, 1, r, out reason))
                    {
                        return false;
                    }
                    _scrollBar = SpriteManager.GetSprite("TinyScrollVerticalBar", r);
                    if (_scrollBar == null)
                    {
                        reason = "\"TinyScrollVerticalBar\" sprite does not exist";
                        return false;
                    }
                }
                else
                {
                    if (!_scroll.Initialize(new List<string> { "TinyScrollHorizontalBGButton1", "TinyScrollHorizontalBGButton2", "TinyScrollHorizontalBGButton3" },
                                           new List<string> { "TinyScrollHorizontalFGButton1", "TinyScrollHorizontalFGButton2", "TinyScrollHorizontalFGButton3" },
                                           isHorizontal, "", ButtonTextAlignment.LEFT, xPos, yPos, _scrollButtonLength, 5, 3, 1, r, out reason))
                    {
                        return false;
                    }
                    _scrollBar = SpriteManager.GetSprite("TinyScrollHorizontalBar", r);
                    if (_scrollBar == null)
                    {
                        reason = "\"TinyScrollHorizontalBar\" sprite does not exist";
                        return false;
                    }
                }
            }
            else
            {
                _scrollButtonLength = 16;
                if (!_scroll.Initialize(new List<string> { "TinySliderHorizontalBGButton1", "TinySliderHorizontalBGButton2", "TinySliderHorizontalBGButton3" },
                                       new List<string> { "TinySliderHorizontalFGButton1", "TinySliderHorizontalFGButton2", "TinySliderHorizontalFGButton3" },
                                       true, "", ButtonTextAlignment.LEFT, xPos, yPos, _scrollButtonLength, 5, 3, 1, r, out reason))
                {
                    return false;
                }
                _scrollBar = SpriteManager.GetSprite("TinySliderBGBar", r);
                if (_scrollBar == null)
                {
                    reason = "\"TinySliderBGBar\" sprite does not exist";
                    return false;
                }
                _highlightedScrollBar = SpriteManager.GetSprite("TinySliderFGBar", r);
                if (_highlightedScrollBar == null)
                {
                    reason = "\"SliderFGBar\" sprite does not exist";
                    return false;
                }
            }

            _topIndex = 0;
            _scrollPos = 0; //relative to the scrollbar itself
            _scrollSelected = false;
            _isEnabled = true;
            reason = null;
            return true;
        }
        public bool Initialize(string backgroundSprite, string foregroundSprite, string buttonText, string font, ButtonTextAlignment alignment, int xPos, int yPos, int width, int height, Random r, out string reason, int xTextOffset = 0, int yTextOffset = 0)
        {
            _backgroundSprite = SpriteManager.GetSprite(backgroundSprite, r);
            _foregroundSprite = SpriteManager.GetSprite(foregroundSprite, r);
            if (backgroundSprite == null || foregroundSprite == null)
            {
                reason = string.Format("One of those sprites does not exist in sprites.xml: \"{0}\" or \"{1}\"", backgroundSprite, foregroundSprite);
                return false;
            }
            _xPos = xPos;
            _yPos = yPos;
            _width = width;
            _height = height;
            _xTextOffset = xTextOffset;
            _yTextOffset = yTextOffset;
            _alignment = alignment;

            _label = new BBLabel();
            if (string.IsNullOrEmpty(font))
            {
                if (!_label.Initialize(0, 0, buttonText, Color.White, out reason))
                {
                    return false;
                }
            }
            else
            {
                if (!_label.Initialize(0, 0, buttonText, Color.White, font, out reason))
                {
                    return false;
                }
            }
            SetText(buttonText);

            Reset();
            reason = null;
            return true;
        }
        public bool Initialize(int xPos, int yPos, int length, int amountOfVisibleItems, int amountOfItems, bool isHorizontal, bool isSlider, Random r, out string reason)
        {
            this.xPos = xPos;
            this.yPos = yPos;
            Up = new BBButton();
            Down = new BBButton();
            Scroll = new BBUniStretchButton();

            this.amountOfItems = amountOfItems;
            this.amountVisible = amountOfVisibleItems;
            this.isSlider = isSlider;
            this.isHorizontal = isHorizontal;

            scrollBarLength = length - 32;

            if (!isSlider)
            {
                scrollButtonLength = (int)(((float)amountOfVisibleItems / amountOfItems) * scrollBarLength);
                if (!isHorizontal)
                {
                    if (!Up.Initialize("ScrollUpBGButton", "ScrollUpFGButton", "", ButtonTextAlignment.CENTER, xPos, yPos, 16, 16, r, out reason))
                    {
                        return false;
                    }
                    if (!Down.Initialize("ScrollDownBGButton", "ScrollDownFGButton", "", ButtonTextAlignment.CENTER, xPos, yPos + length - 16, 16, 16, r, out reason))
                    {
                        return false;
                    }
                    if (!Scroll.Initialize(new List<string> { "ScrollVerticalBGButton1", "ScrollVerticalBGButton2", "ScrollVerticalBGButton3" },
                                           new List<string> { "ScrollVerticalFGButton1", "ScrollVerticalFGButton2", "ScrollVerticalFGButton3" },
                                           false, "", ButtonTextAlignment.LEFT, xPos, yPos + 16, 16, 7, 2, scrollButtonLength, r, out reason))
                    {
                        return false;
                    }
                    scrollBar = SpriteManager.GetSprite("ScrollVerticalBar", r);
                    if (scrollBar == null)
                    {
                        reason = "\"ScrollVerticalBar\" sprite does not exist";
                        return false;
                    }
                }
                else
                {
                    if (!Up.Initialize("ScrollLeftBGButton", "ScrollLeftFGButton", "", ButtonTextAlignment.CENTER, xPos, yPos, 16, 16, r, out reason))
                    {
                        return false;
                    }
                    if (!Down.Initialize("ScrollRightBGButton", "ScrollRightFGButton", "", ButtonTextAlignment.CENTER, xPos + length - 16, yPos, 16, 16, r, out reason))
                    {
                        return false;
                    }
                    if (!Scroll.Initialize(new List<string> { "ScrollHorizontalBGButton1", "ScrollHorizontalBGButton2", "ScrollHorizontalBGButton3" },
                                           new List<string> { "ScrollHorizontalFGButton1", "ScrollHorizontalFGButton2", "ScrollHorizontalFGButton3" },
                                           false, "", ButtonTextAlignment.LEFT, xPos + 16, yPos, 16, 7, 2, scrollButtonLength, r, out reason))
                    {
                        return false;
                    }
                    scrollBar = SpriteManager.GetSprite("ScrollHorizontalBar", r);
                    if (scrollBar == null)
                    {
                        reason = "\"ScrollHorizontalBar\" sprite does not exist";
                        return false;
                    }
                }
            }
            else
            {
                scrollButtonLength = 16;
                if (!Up.Initialize("ScrollLeftBGButton", "ScrollLeftFGButton", "", ButtonTextAlignment.CENTER, xPos, yPos, 16, 16, r, out reason))
                {
                    return false;
                }
                if (!Down.Initialize("ScrollRightBGButton", "ScrollRightFGButton", "", ButtonTextAlignment.CENTER, xPos + length - 16, yPos, 16, 16, r, out reason))
                {
                    return false;
                }
                if (!Scroll.Initialize(new List<string> { "SliderHorizontalBGButton1", "SliderHorizontalBGButton2", "SliderHorizontalBGButton3" },
                                       new List<string> { "SliderHorizontalFGButton1", "SliderHorizontalFGButton2", "SliderHorizontalFGButton3" },
                                       true, "", ButtonTextAlignment.LEFT, xPos + 16, yPos, 16, 7, 2, scrollButtonLength, r, out reason))
                {
                    return false;
                }
                scrollBar = SpriteManager.GetSprite("SliderBGBar", r);
                if (scrollBar == null)
                {
                    reason = "\"SliderBGBar\" sprite does not exist";
                    return false;
                }
                highlightedScrollBar = SpriteManager.GetSprite("SliderFGBar", r);
                if (highlightedScrollBar == null)
                {
                    reason = "\"SliderFGBar\" sprite does not exist";
                    return false;
                }
            }

            topIndex = 0;
            scrollPos = 0; //relative to the scrollbar itself
            scrollSelected = false;
            isEnabled = true;
            reason = null;
            return true;
        }