public override void Initialize()
        {
            _menuButtons = _contentChest.Get <Texture2D>("UI/title_menu_buttons");
            _buttonScale = 3f;
            _hair        = _hairContentLoader.GetContent("assets/characters/player_hair.json").ToArray();
            _heads       = _headContentLoader.GetContent("assets/characters/player_heads.json").ToArray();
            _eyes        = _eyeContentLoader.GetContent("assets/characters/player_eyes.json").ToArray();

            SetupUserInterface();
        }
Example #2
0
        public void Update(float delta)
        {
            _timeShown += delta;

            if (_timeShown < TimeToShow)
            {
                return;
            }

            MediaPlayer.Play(_contentChest.Get <Song>($"Music/MenuSong{_songNum}"));
            RequestNextScene?.Invoke(SceneType.Menu);
        }
Example #3
0
 public ScrollBox(IContentChest contentChest, string textContent, Rectangle bounds)
 {
     _contentChest = contentChest;
     _font         = _contentChest.Get <SpriteFont>("Fonts/InterfaceFont");
     Bounds        = bounds;
     _lines        = WrapString(textContent);
     _nibSprite    = new Sprite(_contentChest.Get <Texture2D>("UI/title_menu_buttons"),
                                new Rectangle(192, 14, 10, 30));
     _upArrowSprite = new Sprite(_contentChest.Get <Texture2D>("UI/title_menu_buttons"),
                                 new Rectangle(192, 4, 10, 10));
     _downArrowSprite = new Sprite(_contentChest.Get <Texture2D>("UI/title_menu_buttons"),
                                   new Rectangle(202, 4, 10, 10));
 }
Example #4
0
        public TextBox(IContentChest contentChest, IKeyboardDispatcher keyboardDispatcher, Vector2 position,
                       SpriteFont font, int width)
        {
            _keyboardDispatcher = keyboardDispatcher;
            _font = font;

            var(x, y) = position;
            Bounds    = new Rectangle((int)x, (int)y, width, 30);

            _keyboardDispatcher.SubscribeToAnyKeyPress(OnKeyPressed);


            _nineSlice = new NineSlice(contentChest.Get <Texture2D>("UI/title_menu_buttons"),
                                       new Dictionary <Segment, Rectangle>
            {
                { Segment.TopLeft, new Rectangle(233, 4, 1, 1) },
                { Segment.Top, new Rectangle(234, 4, 1, 1) },
                { Segment.TopRight, new Rectangle(235, 4, 1, 1) },
                { Segment.Right, new Rectangle(235, 5, 1, 1) },
                { Segment.BottomRight, new Rectangle(235, 6, 1, 1) },
                { Segment.Bottom, new Rectangle(234, 6, 1, 1) },
                { Segment.BottomLeft, new Rectangle(233, 6, 1, 1) },
                { Segment.Left, new Rectangle(233, 5, 1, 1) },
                { Segment.Center, new Rectangle(234, 5, 1, 1) },
            });
        }
Example #5
0
        public override void Initialize()
        {
            _titleYOffset = _viewPortManager.ViewPort.Height / 2.0f - 50;
            _menuButtons  = _contentChest.Get <Texture2D>("UI/title_menu_buttons");
            _buttonScale  = 3f;

            SetupUserInterface();
        }
Example #6
0
        public AsepriteSpriteMap GetContent(string path)
        {
            var asepriteData = _contentDeserializer.Get <AsepriteData>(path);
            var name         = Path.GetFileNameWithoutExtension(asepriteData.Meta.Image);
            var image        = _contentChest.Get <Texture2D>(Path.Combine(Path.GetDirectoryName(path) ?? "",
                                                                          Path.GetFileNameWithoutExtension(path)));

            return(new AsepriteSpriteMap(name, image, asepriteData.Meta.Slices));
        }
Example #7
0
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin(samplerState: SamplerState.PointClamp);
            spriteBatch.Draw(_contentChest.Get <Texture2D>("background"),
                             new Rectangle(0, 0, _viewPortManager.ViewPort.Width, _viewPortManager.ViewPort.Height),
                             Color.White * 0.2f);
            spriteBatch.End();

            _activeMenu.Draw(spriteBatch);
        }
Example #8
0
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();

            var sprite = _contentChest.Get <Texture2D>("characters/player_body");
            var anim   = _testAnimator.CurrentAnimation;
            var frame  = anim.CurrentFrame;

            spriteBatch.Draw(sprite, new Vector2(100, 100), frame.Source, Color.White);
            spriteBatch.End();
        }
Example #9
0
        protected override void InternalDraw(SpriteBatch spriteBatch)
        {
            for (var i = 0; i < _segments; i++)
            {
                var color = ColorHelpers.HsvToRgb((double)i / _segments * 360.0, 1, 1);
                spriteBatch.Draw(_contentChest.Get <Texture2D>("Utils/pixel"),
                                 new Rectangle((int)(_position.X + _width / _segments * i), (int)_position.Y, _width / _segments,
                                               Height), color);

                color = ColorHelpers.HsvToRgb(_hue / 100 * 306, (double)i / _segments, _value / 100);
                spriteBatch.Draw(_contentChest.Get <Texture2D>("Utils/pixel"),
                                 new Rectangle((int)(_position.X + _width / _segments * i), (int)_position.Y + Height + Margin,
                                               _width / _segments,
                                               Height), color);

                color = ColorHelpers.HsvToRgb(_hue / 100 * 360, _saturation / 100, (double)i / _segments);
                spriteBatch.Draw(_contentChest.Get <Texture2D>("Utils/pixel"),
                                 new Rectangle((int)(_position.X + _width / _segments * i),
                                               (int)_position.Y + Height + Margin + Height + Margin, _width / _segments,
                                               Height), color);
            }
        }
Example #10
0
        public Slider(IContentChest contentChest, Vector2 position, float minValue, float maxValue, float startingValue, int width, float scale)
        {
            _minValue     = minValue;
            _maxValue     = maxValue;
            _currentValue = startingValue;
            _width        = width;
            _scale        = scale;

            _sliderSource = new Rectangle(34, 189, 10, 10);
            _texture      = contentChest.Get <Texture2D>("UI/title_menu_buttons");

            var(x, y) = position;
            Bounds    = new Rectangle((int)x, (int)y, width, 10);
        }
Example #11
0
 public void Initialize() => _cursorTexture = _contentChest.Get <Texture2D>("UI/cursors");
Example #12
0
        protected override void InternalDraw(SpriteBatch spriteBatch)
        {
            var currentY = 0f;

            for (var i = _visibleLine; i < _lines.Count; i++)
            {
                var line = _lines[i];
                if (line.Contains("{line}"))
                {
                    var pixel = _contentChest.Get <Texture2D>("Utils/pixel");
                    var(_, _, width, _) = Bounds;

                    currentY += 15;

                    if (Bounds.Y + currentY > Bounds.Bottom)
                    {
                        break;
                    }

                    width -= 20;

                    spriteBatch.Draw(pixel, new Rectangle(Bounds.X + 1, (int)(Bounds.Y - 1 + currentY), width, 2),
                                     Color.Black);
                    spriteBatch.Draw(pixel, new Rectangle(Bounds.X + 1, (int)(Bounds.Y + 1 + currentY), width, 2),
                                     Color.Black);
                    spriteBatch.Draw(pixel, new Rectangle(Bounds.X - 1, (int)(Bounds.Y - 1 + currentY), width, 2),
                                     Color.Black);
                    spriteBatch.Draw(pixel, new Rectangle(Bounds.X - 1, (int)(Bounds.Y + 1 + currentY), width, 2),
                                     Color.Black);
                    spriteBatch.Draw(pixel, new Rectangle(Bounds.X, (int)(Bounds.Y + currentY), width, 2),
                                     Color.White);
                    currentY += 15;
                }
                else
                {
                    var ySize = _font.MeasureString(line).Y;

                    if (Bounds.Y + currentY + ySize > Bounds.Bottom)
                    {
                        break;
                    }

                    var width = _font.MeasureString(line).X;
                    spriteBatch.DrawString(_font, line,
                                           new Vector2(Bounds.X + Bounds.Width / 2f - width / 2f - 1, Bounds.Y + currentY + 1),
                                           Color.Black);
                    spriteBatch.DrawString(_font, line,
                                           new Vector2(Bounds.X + Bounds.Width / 2f - width / 2f - 1, Bounds.Y + currentY - 1),
                                           Color.Black);
                    spriteBatch.DrawString(_font, line,
                                           new Vector2(Bounds.X + Bounds.Width / 2f - width / 2f + 1, Bounds.Y + currentY + 1),
                                           Color.Black);
                    spriteBatch.DrawString(_font, line,
                                           new Vector2(Bounds.X + Bounds.Width / 2f - width / 2f + 1, Bounds.Y + currentY - 1),
                                           Color.Black);
                    spriteBatch.DrawString(_font, line,
                                           new Vector2(Bounds.X + Bounds.Width / 2f - width / 2f, Bounds.Y + currentY), Color.White);
                    currentY += ySize;
                }
            }

            spriteBatch.Draw(_contentChest.Get <Texture2D>("Utils/pixel"),
                             new Rectangle(Bounds.Right - 10, Bounds.Top, 10, Bounds.Height),
                             new Color(221, 190, 137));
            var scrollBounds = ScrollBarBounds();

            spriteBatch.Draw(_upArrowSprite.Texture, TopNibBounds(), _upArrowSprite.Source, Color.White);
            spriteBatch.Draw(_downArrowSprite.Texture, BottomNibBounds(), _downArrowSprite.Source, Color.White);
            spriteBatch.Draw(_nibSprite.Texture, scrollBounds, _nibSprite.Source, Color.White);
        }
 public void Initialize()
 {
     _pixel = _contentChest.Get <Texture2D>("Utils/pixel");
 }
Example #14
0
        private void SetupUserInterface()
        {
            var mainMenuSpriteMap = _spriteMapLoader.GetContent("assets/UI/title_menu_buttons.json");

            _buttonScale = 3f;
            var font = _contentChest.Get <SpriteFont>("Fonts/TitleFont");

            // Main Menu Heading
            var signTopSprite = mainMenuSpriteMap.CreateSpriteFromRegion("Title_Button_Heading");

            SignTopImage = _userInterface.AddWidget(new Image(signTopSprite,
                                                              new Vector2(_viewPortManager.ViewPort.Center().X - signTopSprite.Source.Width * _buttonScale / 2f,
                                                                          _viewPortManager.ViewPort.Center().Y - _viewPortManager.ViewPort.Height / 6f), _buttonScale));

            // Title Text
            TitleTextBlock = new TextBlock(Title,
                                           new Vector2(_viewPortManager.ViewPort.Center().X - font.MeasureString(Title).X / 2,
                                                       SignTopImage.Bounds.Top -
                                                       font.MeasureString(Title).Y), font, Color.Black, null);

            // News Section
            var newsPanelSprite   = mainMenuSpriteMap.CreateSpriteFromRegion("Main_Menu_Empty");
            var newsPanelPosition = new Vector2(SignTopImage.Bounds.Right - newsPanelSprite.Source.Width * _buttonScale,
                                                SignTopImage.Bounds.Bottom);

            NewsPanelImage = SignTopImage.AddChild(new Image(newsPanelSprite,
                                                             newsPanelPosition, _buttonScale));
            ScrollBox = new ScrollBox(_contentChest,
                                      "{line} Welcome to Project Sanctuary! {line} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi congue finibus maximus. Maecenas rhoncus malesuada eros vitae tincidunt. Nam suscipit, justo ac gravida rhoncus, ante neque auctor urna, a egestas dui odio eget ante. Aenean nec eros nisi. Nam bibendum viverra tincidunt. Phasellus elementum urna nibh, ac egestas nibh pellentesque vitae. Nulla in mollis nisl. Vivamus nec mauris rutrum magna sollicitudin venenatis et a enim. Phasellus quis mi ex. {line} ",
                                      NewsPanelImage.Bounds.Add(5 * _buttonScale, 14 * _buttonScale, -11 * _buttonScale, -20 * _buttonScale));

            // New Game Button
            var newButtonPosition = new Vector2(SignTopImage.Bounds.Left,
                                                SignTopImage.Bounds.Bottom);

            NewGameButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("New_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("New_On"),
                newButtonPosition, _buttonScale);
            NewGameButton.OnClick += () => { };

            // Load Game Button
            LoadGameButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Load_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("Load_On"),
                newButtonPosition + new Vector2(0, NewGameButton.Height * _buttonScale), _buttonScale);
            LoadGameButton.OnClick += () => { };

            // Exit Game Button
            ExitGameButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Exit_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("Exit_On"),
                newButtonPosition + new Vector2(0,
                                                NewGameButton.Height * _buttonScale + LoadGameButton.Height * _buttonScale),
                _buttonScale);
            ExitGameButton.OnClick += () => Console.WriteLine("Closing Game...");

            var settingsSprite = mainMenuSpriteMap.CreateSpriteFromRegion("Settings_On");
            var settingsButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Settings_Off"), settingsSprite,
                new Vector2(_viewPortManager.ViewPort.Width - settingsSprite.Source.Width * _buttonScale - 10,
                            _viewPortManager.ViewPort.Height - settingsSprite.Source.Height * _buttonScale - 10), _buttonScale);

            // Add all elements to the parent.
            SignTopImage.AddChild(TitleTextBlock);
            SignTopImage.AddChild(ScrollBox);
            SignTopImage.AddChild(NewGameButton as IWidget);
            SignTopImage.AddChild(LoadGameButton as IWidget);
            SignTopImage.AddChild(ExitGameButton as IWidget);
            SignTopImage.AddChild(settingsButton);

            _userInterface.AddWidget(SignTopImage);
        }