public IReadOnlyCollection <Head> GetContent(string path)
        {
            var spriteMap = _spriteMapLoader.GetContent(path);
            var heads     = _contentDeserializer.Get <AsepriteData>(path);

            return(heads.Meta.Slices.Select(x => ProcessHeadType(x, spriteMap.Image)).ToArray());
        }
Exemple #2
0
        private void SetupUserInterface()
        {
            var mainMenuSpriteMap = _spriteMapLoader.GetContent("assets/UI/title_menu_buttons.json");

            var nineSlice = new NineSlice(_menuButtons, new Dictionary <Segment, Rectangle>
            {
                { Segment.TopLeft, new Rectangle(1, 189, 8, 9) },
                { Segment.Top, new Rectangle(10, 189, 1, 9) },
                { Segment.TopRight, new Rectangle(12, 189, 8, 9) },
                { Segment.Right, new Rectangle(12, 199, 8, 1) },
                { Segment.BottomRight, new Rectangle(12, 201, 8, 8) },
                { Segment.Bottom, new Rectangle(10, 201, 1, 8) },
                { Segment.BottomLeft, new Rectangle(1, 201, 8, 8) },
                { Segment.Left, new Rectangle(1, 199, 8, 1) },
                { Segment.Center, new Rectangle(10, 199, 1, 1) }
            });

            _panel = new Panel(nineSlice,
                               new Rectangle(
                                   (int)(_viewPortManager.ViewPort.Center().X - 250),
                                   (int)(_viewPortManager.ViewPort.Center().Y - 250), 500,
                                   500), _buttonScale);

            BackButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Back_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("Back_On"),
                _panel.BottomLeft().Add(0, 10), _buttonScale);

            _panel.AddChild(BackButton);

            _userInterface.AddWidget(_panel);
        }
        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();
        }
        private void SetupUserInterface()
        {
            var mainMenuSpriteMap = _spriteMapLoader.GetContent("assets/UI/title_menu_buttons.json");
            var interfaceFont     = _contentChest.Get <SpriteFont>("Fonts/InterfaceFont");
            var inputBoxFont      = _contentChest.Get <SpriteFont>("Fonts/InputBoxFont");

            var portraitTexture = _contentChest.Get <Texture2D>("portrait_background");
            var portraitImage   = new Sprite(portraitTexture);

            var nineSlice = new NineSlice(_menuButtons, new Dictionary <Segment, Rectangle>
            {
                { Segment.TopLeft, new Rectangle(1, 189, 8, 9) },
                { Segment.Top, new Rectangle(10, 189, 1, 9) },
                { Segment.TopRight, new Rectangle(12, 189, 8, 9) },
                { Segment.Right, new Rectangle(12, 199, 8, 1) },
                { Segment.BottomRight, new Rectangle(12, 201, 8, 8) },
                { Segment.Bottom, new Rectangle(10, 201, 1, 8) },
                { Segment.BottomLeft, new Rectangle(1, 201, 8, 8) },
                { Segment.Left, new Rectangle(1, 199, 8, 1) },
                { Segment.Center, new Rectangle(10, 199, 1, 1) }
            });

            var panelWidth = (int)(30 + 200 + 30 + portraitImage.Texture.Width * _buttonScale + 30);

            _panel = new Panel(nineSlice,
                               new Rectangle(
                                   (int)(_viewPortPortManager.ViewPort.Center().X - panelWidth / 2f),
                                   (int)(_viewPortPortManager.ViewPort.Center().Y - (500 + 30 + 22 * _buttonScale) / 2f), panelWidth,
                                   500), _buttonScale);

            // Back Button
            BackButton = new TexturedButton(
                mainMenuSpriteMap.CreateSpriteFromRegion("Back_Off"),
                mainMenuSpriteMap.CreateSpriteFromRegion("Back_On"),
                new Vector2(_panel.BottomLeft().X,
                            _panel.BottomLeft().Y + 10), _buttonScale);

            // Done Button
            var doneOffSprite = mainMenuSpriteMap.CreateSpriteFromRegion("Done_Off");

            DoneButton = new TexturedButton(doneOffSprite,
                                            mainMenuSpriteMap.CreateSpriteFromRegion("Done_On"),
                                            new Vector2(_panel.BottomRight().X - doneOffSprite.Source.Width * _buttonScale,
                                                        _panel.BottomLeft().Y + 10), _buttonScale);

            // Name
            var nameSectionPosition = new Vector2(_panel.Left() + 30,
                                                  _panel.Top() + 30);
            var nameTextBoxTitle = new TextBlock("Name", nameSectionPosition, interfaceFont, Color.White, Color.Black);

            NameTextBox = new TextBox(_contentChest, _keyboardDispatcher,
                                      nameSectionPosition + new Vector2(0, interfaceFont.MeasureString("Name").Y + 10),
                                      inputBoxFont, 200)
            {
                Value = _playerMaker.Name
            };
            NameTextBox.Changed += OnPlayerNameSet;

            // Pronouns
            var pronounSectionPosition = new Vector2(_panel.Left() + 30, NameTextBox.Bounds.Bottom + 10);
            var pronounTextBoxTitle    =
                new TextBlock("Pronouns", pronounSectionPosition, interfaceFont, Color.White, Color.Black);

            PronounDropDown = new DropDownBox(_contentChest, inputBoxFont,
                                              pronounSectionPosition + new Vector2(0, interfaceFont.MeasureString("Pronouns").Y + 10),
                                              _optionsManager.PronounOptions.Pronouns.Select(x =>
                                                                                             $"{x.Subjective}/{x.Objective}").ToArray(), 200);
            PronounDropDown.Hover        += OnPronounSelect;
            PronounDropDown.SelectedIndex = _playerMaker.Pronouns;

            var characterPanel = new Image(portraitImage,
                                           new Vector2(
                                               PronounDropDown.Bounds.Right + 30 +
                                               (_panel.Right() - 30 - (PronounDropDown.Bounds.Right + 30)) / 2f -
                                               portraitImage.Center.X * _buttonScale,
                                               nameTextBoxTitle.Top()), _buttonScale);

            // Character Preview
            var characterPreview = new CharacterPreview(_characterRenderer, characterPanel.Center());

            // Hair
            var hairText = new TextBlock("Hair Style",
                                         new Vector2(PronounDropDown.Left(), PronounDropDown.BottomLeft().Y + 10), interfaceFont, Color.White,
                                         Color.Black);

            PlayerHairDropDown = new DropDownBox(_contentChest, inputBoxFont,
                                                 new Vector2(hairText.Left(), hairText.BottomLeft().Y + 10),
                                                 _hair.Select(x => x.Name).ToArray(), 200);
            PlayerHairDropDown.Hover        += (newIndex) => { characterPreview.Hair = _hair[newIndex]; };
            PlayerHairDropDown.SelectedIndex = _playerMaker.Hair;

            // Head
            var headText = new TextBlock("Head Shape",
                                         PlayerHairDropDown.BottomLeft().Add(0, 10), interfaceFont, Color.White,
                                         Color.Black);
            var horizontalSelector = new HorizontalSelector(headText.BottomLeft().Add(0, 10),
                                                            _heads.Select(x => x.Name).ToArray(), 200,
                                                            mainMenuSpriteMap.CreateSpriteFromRegion("Arrow_Left"),
                                                            mainMenuSpriteMap.CreateSpriteFromRegion("Arrow_Right"),
                                                            interfaceFont, _buttonScale);

            horizontalSelector.SelectionChanged += (newIndex) => { characterPreview.Head = _heads[newIndex]; };
            horizontalSelector.SelectedIndex     = _playerMaker.Head;

            _panel.AddChild(pronounTextBoxTitle);
            _panel.AddChild(nameTextBoxTitle);
            _panel.AddChild(NameTextBox);
            _panel.AddChild(characterPanel);
            _panel.AddChild(BackButton);
            _panel.AddChild(DoneButton);
            _panel.AddChild(hairText);
            _panel.AddChild(headText);
            _panel.AddChild(horizontalSelector);
            _panel.AddChild(characterPreview);

            _panel.AddChild(PlayerHairDropDown);
            _panel.AddChild(PronounDropDown);

            _userInterface.AddWidget(_panel);

            DoneButton.OnClick += () =>
            {
                Console.WriteLine("Saving Settings");
                _playerMaker.SetHair(PlayerHairDropDown.SelectedIndex);
                _playerMaker.SetName(NameTextBox.GetValue());
                _playerMaker.SetPronouns(PronounDropDown.SelectedIndex);
            };
        }
Exemple #5
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);
        }