Beispiel #1
0
        private static Frame InitializeGameSettingsFrame(this Frame frame, GameSettingsService factory, AtomicReference <Func <GameSettings> > gameSettingsProvider)
        {
            var container       = new GameSettingsComponentContainer();
            var playerNumberBox = factory.PlayerNumberTextBox();

            playerNumberBox.InputValidator = ch =>
            {
                int number = ch.AsNumber();
                return(number >= 2 && number <= 4);
            };
            playerNumberBox.TextEnter += (s, e) =>
            {
                int difference = e.NewText.First().AsNumber() - e.OldText.First().AsNumber();
                container.UpdatePlayerNameTextBoxes(factory, difference);
            };
            container.Add(factory.PlayerNumberLabel());
            container.Add(playerNumberBox);
            container.AddPlayerNameTextBox(factory, 2);

            frame.Components           = container;
            gameSettingsProvider.Value = () => new GameSettings {
                Players = container.GetPlayersMetadata()
            };

            return(frame);
        }
Beispiel #2
0
        public static void InitializeComponents(this PageControl pageControl, GameWindow window, AtomicReference <NextController> mainMenuResult, AtomicReference <Func <GameSettings> > gameSettingsProvider)
        {
            var factory = new NavigationButtonsFactory
            {
                ExpectedItems  = 3,
                FontSize       = 24,
                IdleColor      = backgroundColor,
                HighlightColor = highlightColor,
                TextColor      = textColor,
                WindowHeight   = window.Size.Y,
                Width          = navigationPanelLenght
            };

            var settingsFactory = new GameSettingsService
            {
                BackgroundColor = backgroundColor,
                ComponentColor  = componentColor,
                HighlightColor  = highlightColor,
                LeftMargin      = menuOptionsLeftMargin,
                SizeFactor      = frameSizeFactor,
                WindowSize      = window.Size,
                TextColor       = textColor,
                ComponentHeight = 40,
                ComponentMargin = 6,
                Font            = FontExtensions.Font,
                FontSize        = 24,
                TextPosition    = new Vector2f(8, 4)
            };

            var mainView      = new ComponentContainer();
            var newGameView   = new ComponentContainer();
            var optionsView   = new ComponentContainer();
            var settingsFrame = settingsFactory.NewFrame();

            pageControl.Bus.Subscribe(window);

            mainView.Add(factory.New(0, "NEW GAME", (s, e) => pageControl.Set(newGameView)));
            mainView.Add(factory.New(1, "OPTIONS", (s, e) => pageControl.Set(optionsView)));
            mainView.Add(factory.New(2, "EXIT", (s, e) => mainMenuResult.Value = NextController.Exit));

            newGameView.Add(factory.New(0, "START", (s, e) => mainMenuResult.Value = NextController.Game));
            newGameView.Add(factory.New(2, "BACK", (s, e) => pageControl.Set(mainView)));
            newGameView.Add(settingsFrame.InitializeGameSettingsFrame(settingsFactory, gameSettingsProvider));

            optionsView.Add(factory.New(2, "BACK", (s, e) => pageControl.Set(mainView)));

            pageControl.Add(mainView);
            pageControl.Add(newGameView);
            pageControl.Add(optionsView);
            pageControl.Set(mainView);
        }