Пример #1
0
    public DialogDemoWindow()
    {
      Title = "Dialog Demo";
      ClipContent = true;

      var button0 = new Button
      {
        Content = new TextBlock { Text = "Open dialog with layout from code", WrapText = true },
        Margin = new Vector4F(4),
      };
      button0.Click += OpenDialogFromCode;

      var button1 = new Button
      {
        Content = new TextBlock { Text = "Open dialog with layout from XML", WrapText = true },
        Margin = new Vector4F(4),
      };
      button1.Click += OpenDialogFromXml;

      var stackPanel = new StackPanel { Margin = new Vector4F(4) };
      stackPanel.Children.Add(button0);
      stackPanel.Children.Add(button1);

      Content = stackPanel;
    }
Пример #2
0
    public GameMenuWindow()
    {
      // Center the window on the screen.
      HorizontalAlignment = HorizontalAlignment.Center;
      VerticalAlignment = VerticalAlignment.Center;

      Title = "Game Paused";

      // Optional: If we want to hide the window close button, we can simply set its style to null.
      CloseButtonStyle = null;

      var resumeButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Resume" },

        // The Resume button is the "Default button" as well as the "Cancel button". (If the
        // user presses A or START and no one else handles the button presses then the default
        // button is invoked. If the user presses B or BACK and no one else handles the button 
        // presses then the Cancel button is invoked.)
        IsDefault = true,
        IsCancel = true,
      };
      resumeButton.Click += (s, e) => Close();

      var optionsButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Options" },
      };
      optionsButton.Click += (s, e) => new OptionsWindow().Show(this);

      var endGameButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Back to main menu" },
      };
      endGameButton.Click += (s, e) => DialogResult = false;

      var stackPanel = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center,
      };
      stackPanel.Children.Add(resumeButton);
      stackPanel.Children.Add(optionsButton);
      stackPanel.Children.Add(endGameButton);

      Content = stackPanel;
    }
 protected Button CreateButton(MethodInfo methodInfo, object[] args)
 {
     var button = new Button
                      {
                          HorizontalAlignment = HorizontalAlignment.Stretch,
                          VerticalAlignment = VerticalAlignment.Stretch
                      };
     button.Content = new TextBlock {Text = methodInfo.Name};
     button.Click += (x, y) => methodInfo.Invoke(CommandHost, args.ToArray());
     return button;
 }
Пример #4
0
        public PauseWindow()
        {
            HorizontalAlignment = DigitalRune.Game.UI.HorizontalAlignment.Center;
            VerticalAlignment = DigitalRune.Game.UI.VerticalAlignment.Center;

            Title = "Game Paused";

            CloseButtonStyle = null;

            var resumeButton = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Content = new TextBlock {  Text = "Resume" },
                IsDefault = true,
                IsCancel = true,
            };
            resumeButton.Click += (s, e) => Close();

            var optionsButton = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Content = new TextBlock { Text = "Options" },
            };
            optionsButton.Click += (s, e) => new OptionsWindow().Show(this);

            var endGameButton = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Content = new TextBlock { Text = "Back to Main Menu" },
            };
            endGameButton.Click += (s, e) => DialogResult = false;

            var stackPanel = new StackPanel
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
            };

            stackPanel.Children.Add(resumeButton);
            stackPanel.Children.Add(optionsButton);
            stackPanel.Children.Add(endGameButton);

            Content = stackPanel;
        }
Пример #5
0
    private void OpenDialogFromCode(object sender, EventArgs eventArgs)
    {
      // ----- Create dialog.
      var text = new TextBlock
      {
        Text = "This layout was defined in code.",
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Center,
      };

      var button = new Button
      {
        Content = new TextBlock { Text = "Ok" },
        IsCancel = true,       // Cancel buttons are clicked when the user presses ESC (or BACK or B on the gamepad).
        IsDefault = true,      // Default buttons are clicked when the user presses ENTER or SPACE (or START or A on the gamepad).
        Margin = new Vector4F(4),
        Width = 60,
        HorizontalAlignment = HorizontalAlignment.Center,
      };

      var stackPanel = new StackPanel { Margin = new Vector4F(4) };
      stackPanel.Children.Add(text);
      stackPanel.Children.Add(button);

      var window = new Window
      {
        CanResize = false,
        IsModal = true,             // Modal dialogs consume all input until the window is closed.
        Content = stackPanel,
        MinHeight = 0,
        Title = "A modal dialog from code",
      };

      button.Click += (s, e) => window.Close();

      // ----- Show the window in the center of the screen.
      // First, we need to open the window. 
      window.Show(this);

      // The window is now part of the visual tree of controls and can be measured. (The 
      // window does not have a fixed size. Window.Width and Window.Height are NaN. The 
      // size is calculated automatically depending on its content.)
      window.Measure(new Vector2F(float.PositiveInfinity));

      // Measure computes DesiredWidth and DesiredHeight. With this info we can center the 
      // window on the screen.
      window.X = Screen.ActualWidth / 2 - window.DesiredWidth / 2;
      window.Y = Screen.ActualHeight / 2 - window.DesiredHeight / 2;
    }
Пример #6
0
        /// <summary> Constructor.</summary>
        ///
        /// <param name="game">    The game.</param>
        /// <param name="allyWin"> true to ally window.</param>
        public EndLevelComponent(Game game, bool allyWin)
            : base(game)
        {
            var content = ServiceLocator.Current.GetInstance<ContentManager>();
            var theme = content.Load<Theme>("UI/UITheme");
            var renderer = new UIRenderer(this.Game, theme);

            _endLevelUI = new UIScreen("EndLevelUI", renderer);

            var uiService = ServiceLocator.Current.GetInstance<IUIService>();
            uiService.Screens.Add(_endLevelUI);

            _returnToMenu = new Button
            {
                Margin = new Vector4F(10),
                Width = 300,
                Height = 60,
                Y = 480,
                X = 200,
                Content = new TextBlock { Text = "Return to Menu", }
            };
            _returnToMenu.Click += (s, e) => EndToMenu();

            _background = new Image
            {
                Texture = content.Load<Texture2D>("UI/background"),
            };

            _endLevelUI.Children.Add(_background);
            _endLevelUI.Children.Add(_returnToMenu);

            if (GameSettings.LevelNumber == 1)
            {
                GameSettings.LevelNumber = 0;
                LoadCredits();
            }
            else if(allyWin)
            {
                GameSettings.LevelNumber++;
                AllyWin();
            }
            else
            {
                EnemyWin();
            }

            MediaPlayer.Play(_backgroundMusic);
            MediaPlayer.IsRepeating = true;
        }
Пример #7
0
    public MainMenuWindow()
    {
      // The window fill the whole screen.
      HorizontalAlignment = HorizontalAlignment.Stretch;
      VerticalAlignment = VerticalAlignment.Stretch;

      // The window itself (borders, title, background) should be invisible. Therefore, we have
      // added the "InvisibleWindow" style in the Theme.Xml.
      Style = "InvisibleWindow";

      var playButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Play" },
      };
      playButton.Click += (s, e) => DialogResult = true;

      var optionsButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Options" },
      };
      optionsButton.Click += (s, e) => new OptionsWindow().Show(this);

      var exitButton = new Button
      {
        Margin = new Vector4F(10),
        Width = 200,
        Height = 60,
        Content = new TextBlock { Text = "Exit" },
      };
      exitButton.Click += (s, e) => DialogResult = false;

      var stackPanel = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center,
      };
      stackPanel.Children.Add(playButton);
      stackPanel.Children.Add(optionsButton);
      stackPanel.Children.Add(exitButton);

      Content = stackPanel;
    }
Пример #8
0
        public void Init()
        {
            _layout = new Canvas()
            {
                HorizontalAlignment = DigitalRune.Game.UI.HorizontalAlignment.Stretch,
                VerticalAlignment = DigitalRune.Game.UI.VerticalAlignment.Stretch
            };

            _background = new Image()
            {
                HorizontalAlignment = DigitalRune.Game.UI.HorizontalAlignment.Stretch,
                VerticalAlignment = DigitalRune.Game.UI.VerticalAlignment.Stretch,
                Texture = _content.GetContent<Texture2D>("UI/StartScreenBG")
            };

            _menuItems = new SpacedStackPanel()
            {
                HorizontalAlignment = DigitalRune.Game.UI.HorizontalAlignment.Center,
                VerticalAlignment = DigitalRune.Game.UI.VerticalAlignment.Center

            };

            _newGameButton = new Button()
            {
                Width = 160,
                Height = 30,
                Content = new TextBlock() {
                    Text = "New Game"
                }
            };

            _exitButton = new Button()
            {
                Width = 160,
                Height = 30,
                Content = new TextBlock() {
                    Text = "Exit"
                }
            };

            _menuItems.Children.Add(_newGameButton);
            _menuItems.Children.Add(_exitButton);

            _layout.Children.Add(_background);
            _layout.Children.Add(_menuItems);
            this.Content = _layout;
        }
Пример #9
0
    public RenderTransformWindow()
    {
      Title = "RenderTransform Demo";

      // Ensure that the child controls are drawn outside the window.
      ClipContent = true;

      var textBlock = new TextBlock
      {
        X = 10,
        Y = 10,
        Text = "All controls can be scaled, rotated and translated:"
      };

      _checkBox = new CheckBox
      {
        X = 10,
        Y = 30,
        Content = new TextBlock { Text = "Enable RenderTransform" },
      };

      _button = new Button
      {
        X = 100,
        Y = 150,
        Content = new TextBlock { Text = "Button with\nRenderTransform" },
      };

      var canvas = new Canvas
      {
        Width = 315,
        Height = 250,
      };
      canvas.Children.Add(textBlock);
      canvas.Children.Add(_checkBox);
      canvas.Children.Add(_button);

      Content = canvas;
    }
Пример #10
0
        /// <summary> Initializes the component. Override this method to load any non-
        ///           graphics resources and query for any required services.</summary>
        public override void Initialize()
        {
            var content = ServiceLocator.Current.GetInstance<ContentManager>();
            var theme = content.Load<Theme>("UI/UITheme");
            var renderer = new UIRenderer(this.Game, theme);

            _menuUI = new UIScreen("MenuUI", renderer);

            var uiService = ServiceLocator.Current.GetInstance<IUIService>();
            uiService.Screens.Add(_menuUI);

            _startGame = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Y = 330,
                X = 200,
                Content = new TextBlock { Text = "Start Game" },
            };
            _startGame.Click += (s, e) => MenuToGame();

            /*_about = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                Y = 405,
                X = 200,
                Content = new TextBlock { Text = "About Us" },
            };*/

            var Game = ServiceLocator.Current.GetInstance<Game>();
            _exit = new Button
            {
                Margin = new Vector4F(10),
                Width = 200,
                Height = 60,
                X = 200,
                Y = 405,
                Content = new TextBlock { Text = "Exit" },
            };
            _exit.Click += (s, e) => Game.Exit();

            _gameLogo = new Image
            {
                Texture = content.Load<Texture2D>("UI/goldcrestlogo"),
                HorizontalAlignment = HorizontalAlignment.Center,
                Y = 100,
            };

            _background = new Image
            {
                Texture = content.Load<Texture2D>("UI/background"),
            };

            _menuPic = new Image
            {
                Texture = content.Load<Texture2D>("UI/menupic"),
                X = 550,
                Y = 300,
            };

            _menuUI.Children.Add(_background);
            _menuUI.Children.Add(_menuPic);
            _menuUI.Children.Add(_gameLogo);
            _menuUI.Children.Add(_startGame);
            //_menuUI.Children.Add(_about);
            _menuUI.Children.Add(_exit);

            backgroundMusic = content.Load<Song>("SoundFX/Menu_loop");
            MediaPlayer.Play(backgroundMusic);
            MediaPlayer.IsRepeating = true;

            base.Initialize();
        }
Пример #11
0
        private void AddWindowComponents()
        {
            var menuWindow = new Window
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            _screen.Children.Add(menuWindow);

            var stackPanel = new StackPanel
            {
                Orientation = Orientation.Vertical,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment = VerticalAlignment.Center,
                Margin = new Vector4F(150, 0, 0, 0),
            };
            menuWindow.Content = stackPanel;

            var startButton = new Button
            {
                Name = "StartButton",
                Content = new TextBlock { Text = "Start" },
                FocusWhenMouseOver = true,
            };
            startButton.Click += OnStartButtonClicked;

            stackPanel.Children.Add(startButton);

            startButton.Focus();

            _game.ResetElapsedTime();
        }
Пример #12
0
    //--------------------------------------------------------------
    #region Methods
    //--------------------------------------------------------------

    /// <inheritdoc/>
    protected override void OnLoad()
    {
      base.OnLoad();

      // Create icon.
      var iconStyle = IconStyle;
      if (!string.IsNullOrEmpty(iconStyle))
      {
        _icon = new Image
        {
          Name = "WindowIcon",
          Style = iconStyle,
          Texture = Icon,
          SourceRectangle = IconSourceRectangle,
        };
        VisualChildren.Add(_icon);

        // Connect Icon property with Image.Texture.
        GameProperty<Texture2D> icon = Properties.Get<Texture2D>(IconPropertyId);
        GameProperty<Texture2D> imageTexture = _icon.Properties.Get<Texture2D>(Image.TexturePropertyId);
        icon.Changed += imageTexture.Change;

#if !WINDOWS_UWP
        // Connect IconSourceRectangle property with Image.SourceRectangle.
        GameProperty<Rectangle?> iconSourceRectangle = Properties.Get<Rectangle?>(IconSourceRectanglePropertyId);
        GameProperty<Rectangle?> imageSourceRectangle = _icon.Properties.Get<Rectangle?>(Image.SourceRectanglePropertyId);
        iconSourceRectangle.Changed += imageSourceRectangle.Change;
#else
        // Connect IconSourceRectangle property with Image.SourceRectangle.
        GameProperty<Rectangle> iconSourceRectangle = Properties.Get<Rectangle>(IconSourceRectanglePropertyId);
        GameProperty<Rectangle> imageSourceRectangle = _icon.Properties.Get<Rectangle>(Image.SourceRectanglePropertyId);
        iconSourceRectangle.Changed += imageSourceRectangle.Change;
#endif
      }

      // Create text block for title.
      var titleTextBlockStyle = TitleTextBlockStyle;
      if (!string.IsNullOrEmpty(titleTextBlockStyle))
      {
        _caption = new TextBlock
        {
          Name = "WindowTitle",
          Style = titleTextBlockStyle,
          Text = Title,
        };
        VisualChildren.Add(_caption);

        // Connect Title property with TextBlock.Text.
        GameProperty<string> title = Properties.Get<string>(TitlePropertyId);
        GameProperty<string> captionText = _caption.Properties.Get<string>(TextBlock.TextPropertyId);
        title.Changed += captionText.Change;
      }

      // Create Close button.
      var closeButtonStyle = CloseButtonStyle;
      if (!string.IsNullOrEmpty(closeButtonStyle))
      {
        _closeButton = new Button
        {
          Name = "CloseButton",
          Style = closeButtonStyle,
          Focusable = false,
        };
        VisualChildren.Add(_closeButton);

        _closeButton.Click += OnCloseButtonClick;
      }
    }
Пример #13
0
        /// <summary> Enemy win.</summary>
        private void EnemyWin()
        {
            _backgroundMusic = content.Load<Song>("SoundFX/enemy_win");
            _nextLevel = new Button
            {
                Margin = new Vector4F(10),
                Width = 300,
                Height = 60,
                Y = 360,
                X = 200,
                Content = new TextBlock { Text = "Try Again?", }
            };
            _nextLevel.Click += (s, e) => ReturnToGame();

            _display = new TextBlock
            {
                Text = "YOU LOSE!",
                HorizontalAlignment = HorizontalAlignment.Center,
                Y = 100,
            };

            _endLevelUI.Children.Add(_display);
            _endLevelUI.Children.Add(_nextLevel);
        }
Пример #14
0
        /// <summary> Ally win.</summary>
        private void AllyWin()
        {
            _backgroundMusic = content.Load<Song>("SoundFX/end_level");
            _nextLevel = new Button
            {
                Margin = new Vector4F(10),
                Width = 300,
                Height = 60,
                Y = 360,
                X = 200,
                Content = new TextBlock { Text = "Continue", }
            };
            _nextLevel.Click += (s, e) => ReturnToGame();

            _saveGame = new Button
            {
                Margin = new Vector4F(10),
                Width = 300,
                Height = 60,
                Y = 420,
                X = 200,
                Content = new TextBlock { Text = "Save Game", }
            };
            _saveGame.Click += (s, e) => SaveLoadGame.InitiateSave(GameSettings.LevelNumber);

            _display = new TextBlock
            {
                Text = "YOU WIN!",
                HorizontalAlignment = HorizontalAlignment.Center,
                Y = 100,
            };

            _endLevelUI.Children.Add(_display);
            _endLevelUI.Children.Add(_nextLevel);
            _endLevelUI.Children.Add(_saveGame);
        }
Пример #15
0
    public EasingWindow(IServiceLocator services) 
      : base(services)
    {
      _inputService = services.GetInstance<IInputService>();
      _animationService = services.GetInstance<IAnimationService>();

      Title = "EasingWindow";

      StackPanel stackPanel = new StackPanel { Margin = new Vector4F(8) };
      Content = stackPanel;

      TextBlock textBlock = new TextBlock
      {
        Text = "Test different Easing Functions in this window.",
        Margin = new Vector4F(0, 0, 0, 8),
      };
      stackPanel.Children.Add(textBlock);

      StackPanel horizontalPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal,
        Margin = new Vector4F(0, 0, 0, 8)
      };
      stackPanel.Children.Add(horizontalPanel);

      textBlock = new TextBlock
      {
        Text = "Easing Function:",
        Width = 80,
        Margin = new Vector4F(0, 0, 8, 0),
      };
      horizontalPanel.Children.Add(textBlock);

      _functionDropDown = new DropDownButton
      {
        Width = 100,

        // The DropDownButton automatically converts the items to string (using ToString) and 
        // displays this string. This is not helpful for this sort of items. We want to display
        // the type name of the items instead. The following is a callback which creates a
        // TextBlock for each item. It is called when the drop-down list is opened.
        CreateControlForItem = item => new TextBlock { Text = item.GetType().Name },
      };
      horizontalPanel.Children.Add(_functionDropDown);

      _functionDropDown.Items.Add(new BackEase());
      _functionDropDown.Items.Add(new BounceEase());
      _functionDropDown.Items.Add(new CircleEase());
      _functionDropDown.Items.Add(new CubicEase());
      _functionDropDown.Items.Add(new ElasticEase());
      _functionDropDown.Items.Add(new ExponentialEase());
      _functionDropDown.Items.Add(new LogarithmicEase());
      _functionDropDown.Items.Add(new HermiteEase());
      _functionDropDown.Items.Add(new PowerEase());
      _functionDropDown.Items.Add(new QuadraticEase());
      _functionDropDown.Items.Add(new QuinticEase());
      _functionDropDown.Items.Add(new SineEase());
      _functionDropDown.SelectedIndex = 0;

      horizontalPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal,
        Margin = new Vector4F(0, 0, 0, 8)
      };
      stackPanel.Children.Add(horizontalPanel);

      textBlock = new TextBlock
      {
        Text = "Easing Mode:",
        Width = 80,
        Margin = new Vector4F(0, 0, 8, 0),
      };
      horizontalPanel.Children.Add(textBlock);

      _modeDropDown = new DropDownButton
      {
        Width = 100,
      };
      horizontalPanel.Children.Add(_modeDropDown);

      _modeDropDown.Items.Add(EasingMode.EaseIn);
      _modeDropDown.Items.Add(EasingMode.EaseOut);
      _modeDropDown.Items.Add(EasingMode.EaseInOut);
      _modeDropDown.SelectedIndex = 0;

      _slider = new Slider
      {
        Margin = new Vector4F(0, 16, 0, 0),
        SmallChange = 0.01f,
        LargeChange = 0.1f,
        Minimum = -0.5f,
        Maximum = 1.5f,
        Width = 250,
        HorizontalAlignment = HorizontalAlignment.Center,
      };
      stackPanel.Children.Add(_slider);

      // Display the current value of the slider.
      var valueLabel = new TextBlock
      {
        Text = _slider.Value.ToString("F2"),
        HorizontalAlignment = HorizontalAlignment.Center,
        Margin = new Vector4F(0, 0, 0, 8),
      };
      stackPanel.Children.Add(valueLabel);

      // Update the text every time the slider value changes.
      var valueProperty = _slider.Properties.Get<float>("Value");
      valueProperty.Changed += (s, e) => valueLabel.Text = e.NewValue.ToString("F2");

      Button button = new Button
      {
        Content = new TextBlock { Text = "Animate" },
        HorizontalAlignment = HorizontalAlignment.Center,
        Margin = new Vector4F(0, 0, 0, 8),
      };
      button.Click += OnButtonClicked;
      stackPanel.Children.Add(button);

      textBlock = new TextBlock
      {
        Text = "(Press the Animate button to animate the slider\n"
                + "value using the selected EasingFunction.\n"
                + "The slider goes from -0.5 to 1.5. The animation\n"
                + "animates the value to 0 or to 1.)",
      };
      stackPanel.Children.Add(textBlock);

      // When the window is loaded, the window appears under the mouse cursor and flies to
      // its position.
      Vector2F mousePosition = _inputService.MousePosition;

      // The loading animation is a timeline group of three animations:
      // - One animations animates the RenderScale from (0, 0) to its current value.
      // - The other animations animate the X and Y positions from the mouse position 
      //   to current values.
      // The base class AnimatedWindow will apply this timeline group on this window 
      // when the window is loaded.
      TimelineGroup timelineGroup = new TimelineGroup
      {
        new Vector2FFromToByAnimation
        {
          TargetProperty = "RenderScale",
          From = new Vector2F(0, 0),
          Duration = TimeSpan.FromSeconds(0.3),
          EasingFunction = new HermiteEase { Mode = EasingMode.EaseOut },
        },
        new SingleFromToByAnimation
        {
          TargetProperty = "X",     
          From = mousePosition.X, 
          Duration = TimeSpan.FromSeconds(0.3),
        },        
        new SingleFromToByAnimation
        {
          TargetProperty = "Y",     
          From = mousePosition.Y, 
          Duration = TimeSpan.FromSeconds(0.3),
          EasingFunction = new QuadraticEase { Mode = EasingMode.EaseIn },
        },
      };
      // The default FillBehavior is "Hold". But this animation can be removed when it is finished. 
      // It should not "Hold" the animation value. If FillBehavior is set to Hold, we cannot
      // drag the window with the mouse because the animation overrides the value.
      timelineGroup.FillBehavior = FillBehavior.Stop;
      LoadingAnimation = timelineGroup;

      // The closing animation is a timeline group of three animations:
      // - One animations animates the RenderScale to (0, 0).
      // - The other animations animate the X and Y positions to the mouse position.
      // The base class AnimatedWindow will apply this timeline group on this window 
      // when the window is loaded.
      ClosingAnimation = new TimelineGroup
      {
        new Vector2FFromToByAnimation
        {
          TargetProperty = "RenderScale",
          To = new Vector2F(0, 0),
          Duration = TimeSpan.FromSeconds(0.3),
          EasingFunction = new HermiteEase { Mode = EasingMode.EaseIn },
        },
        new SingleFromToByAnimation
        {
          TargetProperty = "X",
          To = mousePosition.X,
          Duration = TimeSpan.FromSeconds(0.3),
        },        
        new SingleFromToByAnimation
        {
          TargetProperty = "Y",
          To = mousePosition.Y,
          Duration = TimeSpan.FromSeconds(0.3),
          EasingFunction = new QuadraticEase { Mode = EasingMode.EaseOut },
        },
      };
    }
Пример #16
0
    /// <summary>
    /// Called when "SubMenu" state is entered.
    /// </summary>
    private void OnEnterSubMenuScreen(object sender, StateEventArgs eventArgs)
    {
      // Similar to OnEnterMenuScreen.
      _subMenuWindow = new Window
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };
      _uiScreen.Children.Add(_subMenuWindow);

      var stackPanel = new StackPanel
      {
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Bottom,
        Margin = new Vector4F(150, 0, 0, 200)
      };
      _subMenuWindow.Content = stackPanel;

      var button1 = new Button
      {
        Name = "Item1Button",
        Content = new TextBlock { Text = "Item 1" },
        FocusWhenMouseOver = true,
      };
      var button2 = new Button
      {
        Name = "Item2Button",
        Content = new TextBlock { Text = "Item 2" },
        FocusWhenMouseOver = true,
      };
      var button3 = new Button
      {
        Name = "Item3Button",
        Content = new TextBlock { Text = "Item 3" },
        FocusWhenMouseOver = true,
      };
      var backButton = new Button
      {
        Name = "BackButton",
        Content = new TextBlock { Text = "Back" },
        FocusWhenMouseOver = true,
      };
      backButton.Click += OnBackButtonClicked;

      stackPanel.Children.Add(button1);
      stackPanel.Children.Add(button2);
      stackPanel.Children.Add(button3);
      stackPanel.Children.Add(backButton);

      button1.Focus();

      // Fade-in the buttons from the right.
      AnimateFrom(stackPanel.Children, 0, new Vector2F(300, 0));
    }
Пример #17
0
    /// <inheritdoc/>
    protected override void OnUnload()
    {
      // Remove thumb and buttons.
      VisualChildren.Remove(_thumb);
      _thumb = null;

      if (_decrementButton != null)
      {
        var click = _decrementButton.Events.Get<EventArgs>(ButtonBase.ClickEventId);
        click.Event -= OnDecrementButtonClick;
        VisualChildren.Remove(_decrementButton);
        _decrementButton = null;
      }

      if (_incrementButton != null)
      {
        var click = _incrementButton.Events.Get<EventArgs>(ButtonBase.ClickEventId);
        click.Event += OnIncrementButtonClick;
        VisualChildren.Remove(_incrementButton);
        _incrementButton = null;
      }

      base.OnUnload();
    }
Пример #18
0
    private void CreateMenuWindow()
    {
      if (_menuWindow != null)
        return;

      // Window
      //   StackPanel (vertical)
      //     StackPanel (horizontal)
      //       Buttons
      //     TextBlock 
      //     TabControl
      //       TabItem                      * per category
      //         ScrollViewer
      //           StackPanel (vertical)
      //             StackPanel (vertical)  * per sample
      //               Button
      //               TextBlock

      _menuWindow = new Window
      {
        Name = "MenuWindow",
        Title = "Sample Browser",
        X = 50,
        Y = 50,
        IsVisible = false,
        HideOnClose = true
      };
      _menuWindow.Closed += OnWindowClosed;

      var panel = new StackPanel
      {
        Margin = new Vector4F(10),
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch
      };
      _menuWindow.Content = panel;

      var buttonsPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal
      };
      panel.Children.Add(buttonsPanel);

      AddButton(buttonsPanel, "Resume (Esc)", CloseWindows);
      AddButton(buttonsPanel, "Help (F1)", ShowHelpWindow);
      AddButton(buttonsPanel, "Profile (F3)", ShowProfilerWindow);
      AddButton(buttonsPanel, "Options (F4)", ShowOptionsWindow);
#if !NETFX_CORE && !IOS
      AddButton(buttonsPanel, "Exit (Alt-F4)", _game.Exit);
#endif

      var label = new TextBlock
      {
        Text = "Select Sample:",
        Margin = new Vector4F(2, 10, 0, 0)
      };
      panel.Children.Add(label);

      var tabControl = new TabControl
      {
        Margin = new Vector4F(0, 3, 0, 0),
        Width = 580,
#if WINDOWS_PHONE || ANDROID || IOS
        Height = 300
#else
        Height = 400
#endif
      };
      panel.Children.Add(tabControl);

      // Each tab shows a sample category (Base, Mathematics, Geometry, ...).
      var samplesByCategory = _samples.GroupBy(t => SampleAttribute.GetSampleAttribute(t).Category);
      int category = -1;
      foreach (var grouping in samplesByCategory)
      {
        category++;

        var tabItem = new TabItem
        {
          Content = new TextBlock { Text = grouping.Key.ToString() },
        };
        tabControl.Items.Add(tabItem);

        var scrollViewer = new ScrollViewer
        {
          HorizontalAlignment = HorizontalAlignment.Stretch,
          VerticalAlignment = VerticalAlignment.Stretch,
          HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled
        };
        tabItem.TabPage = scrollViewer;

        var itemsPanel = new StackPanel
        {
          Orientation = Orientation.Vertical,
          Margin = new Vector4F(5),
          HorizontalAlignment = HorizontalAlignment.Stretch,
          VerticalAlignment = VerticalAlignment.Stretch
        };
        scrollViewer.Content = itemsPanel;

        foreach (Type sample in grouping)
        {
          var item = new StackPanel
          {
            Orientation = Orientation.Vertical
          };
          itemsPanel.Children.Add(item);

          string title = sample.Name;
          var button = new Button
          {
            Content = new TextBlock { Text = title },
            Width = 200,
#if WINDOWS_PHONE || ANDROID || IOS
            Padding = new Vector4F(10),
#else
            Padding = new Vector4F(0, 5, 0, 5),
#endif
          };
          int sampleIndex = _samples.IndexOf(sample);
          button.Click += (s, e) =>
                          {
                            _nextSampleIndex = sampleIndex;
                            CloseWindows();
                          };
          item.Children.Add(button);

          string summary = SampleAttribute.GetSampleAttribute(sample).Summary;
          summary = summary.Replace("\r\n", " ");
          var summaryTextBlock = new TextBlock
          {
            Margin = new Vector4F(0, 3, 0, 12),
            Text = summary,
            WrapText = true
          };
          item.Children.Add(summaryTextBlock);
        }
      }
    }
Пример #19
0
    protected override void OnLoad()
    {
      base.OnLoad();

      var screen = Screen;

      var panel = new Canvas
      {
        Margin = new Vector4F(8),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };
      Content = panel;

      panel.Children.Add(new TextBlock
      {
        Text = "The GUI can be used in the 3D game! :-)",
      });

      panel.Children.Add(new TextBlock
      {
        Y = 32,
        Text = "Red: ",
      });

      var slider = new Slider
      {
        X = 52,
        Y = 32,
        Width = 200,
        Minimum = 0,
        Maximum = 255,
        Value = screen.Background.R,
      };
      panel.Children.Add(slider);
      GameProperty<float> sliderValue = slider.Properties.Get<float>("Value");
      sliderValue.Changed += (s, e) =>
      {
        Color color = screen.Background;
        color.R = (byte)e.NewValue;
        screen.Background = color;
      };

      panel.Children.Add(new TextBlock
      {
        X = 0,
        Y = 56,
        Text = "Green: ",
      });
      slider = new Slider
      {
        X = 52,
        Y = 56,
        Width = 200,
        Minimum = 0,
        Maximum = 255,
        Value = screen.Background.G,
      };
      panel.Children.Add(slider);
      sliderValue = slider.Properties.Get<float>("Value");
      sliderValue.Changed += (s, e) =>
      {
        Color color = screen.Background;
        color.G = (byte)e.NewValue;
        screen.Background = color;
      };

      panel.Children.Add(new TextBlock
      {
        X = 0,
        Y = 80,
        Text = "Blue: ",
      });
      slider = new Slider
      {
        X = 52,
        Y = 80,
        Width = 200,
        Minimum = 0,
        Maximum = 255,
        Value = screen.Background.B,
      };
      panel.Children.Add(slider);
      sliderValue = slider.Properties.Get<float>("Value");
      sliderValue.Changed += (s, e) =>
      {
        Color color = screen.Background;
        color.B = (byte)e.NewValue;
        screen.Background = color;
      };

      var button = new Button
      {
        X = 60,
        Y = 110,
        Width = 120,
        ToolTip = "Drop a new box",
        Content = new TextBlock { Text = "Drop" },
      };
      button.Click += (s, e) =>
      {
        // Create a new DynamicObject.
        var gameObjectService = _services.GetInstance<IGameObjectService>();
        gameObjectService.Objects.Add(new DynamicObject(_services, 1));
      };
      panel.Children.Add(button);
    }
Пример #20
0
    // Create a window which shows all controls.
    public WpWindow()
    {
      CanDrag = false;
      CanResize = false;
      HorizontalAlignment = HorizontalAlignment.Stretch;
      VerticalAlignment = VerticalAlignment.Stretch;

      Title = "DigitalRune Game UI Sample";

      // We handle the Closed event.
      Closed += OnClosed;

      var applicationTitle = new TextBlock
      {
        Text = "DIGITALRUNE GUI SAMPLE",
        Margin = new Vector4F(12, 0, 0, 0),
      };

      var pageTitle = new TextBlock
      {
        Text = "controls",
        Style = "TextBlockTitle",
        Margin = new Vector4F(9, -7, 0, 0),
      };

      var titlePanel = new StackPanel
      {
        Margin = new Vector4F(12, 24, 8, 8),
      };
      titlePanel.Children.Add(applicationTitle);
      titlePanel.Children.Add(pageTitle);

      var textBlock = new TextBlock
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        WrapText = true,
        Text = "This is a window with a lot of controls.\n" +
               "All controls are within a scroll viewer.\n" +
               "Tap-and-hold in window area to display the context menu of the window.",
        Style = "TextBlockSubtle"
      };

      var buttonEnabled = new Button
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "Button" },
      };

      var buttonDisabled = new Button
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "Button (Disabled)" },
        IsEnabled = false,
      };

      var checkBoxEnabled = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox" },
      };

      var checkBoxEnabledChecked = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox" },
        IsChecked = true,
      };

      var checkBoxDisabled = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox (Disabled)" },
        IsEnabled = false,
      };

      var checkBoxDisabledChecked = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox (Disabled)" },
        IsEnabled = false,
        IsChecked = true,
      };

      var checkBoxLotsOfText = new CheckBox
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "CheckBox with a lot of text that does not fit into a single line." },
      };

      var radioButton0 = new RadioButton
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "RadioButton" },
      };

      var radioButton1 = new RadioButton
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "RadioButton with a lot of text that does not fit into a single line." },
        IsChecked = true
      };

      var radioButton2 = new RadioButton
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "RadioButton" },
        IsEnabled = false,
      };

      var radioButton3 = new RadioButton
      {
        Margin = new Vector4F(0, 10, 0, 10),
        Content = new TextBlock { Text = "RadioButton (Disabled)" },
        IsEnabled = false,
        IsChecked = true,
        GroupName = "OtherGroup",   // Put in another group, so that the IsChecked state is not removed when the user clicks another radio button.
      };

      var dropDownButton = new DropDownButton
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Title = "DROPDOWN ITEMS",
        SelectedIndex = 0,
      };
      // Add drop down items - each items is a string. Per default, the DropDownButton 
      // calls ToString() for each item and displays it in a text block.
      for (int i = 0; i < 30; i++)
        dropDownButton.Items.Add("DropDownItem " + i);

      var dropDownButtonDisabled = new DropDownButton
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Title = "DROPDOWN ITEMS",
        IsEnabled = false,
        SelectedIndex = 0,
      };
      // Add drop down items - each items is a string. Per default, the DropDownButton 
      // calls ToString() for each item and displays it in a text block.
      for (int i = 0; i < 30; i++)
        dropDownButtonDisabled.Items.Add("DropDownItem " + i + "(Disabled)");

      var textBoxEnabled = new TextBox
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        GuideTitle = "GUIDE TITLE",
        GuideDescription = "Guide description:",
        Text = "TextBox (Enabled)"
      };

      var textBoxDisabled = new TextBox
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Text = "TextBox (Disabled)",
        IsEnabled = false,
      };

      var slider = new Slider
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 24, 0, 24),
        Value = 33
      };

      var progressBar = new ProgressBar
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        Value = 66,
      };

      var progressBarIndeterminate = new ProgressBar
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(0, 10, 0, 10),
        IsIndeterminate = true,
      };

      var stackPanel = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        Margin = new Vector4F(0, 0, 8, 0),
      };
      stackPanel.Children.Add(textBlock);
      stackPanel.Children.Add(buttonEnabled);
      stackPanel.Children.Add(buttonDisabled);
      stackPanel.Children.Add(checkBoxEnabled);
      stackPanel.Children.Add(checkBoxEnabledChecked);
      stackPanel.Children.Add(checkBoxDisabled);
      stackPanel.Children.Add(checkBoxDisabledChecked);
      stackPanel.Children.Add(checkBoxLotsOfText);
      stackPanel.Children.Add(radioButton0);
      stackPanel.Children.Add(radioButton1);
      stackPanel.Children.Add(radioButton2);
      stackPanel.Children.Add(radioButton3);
      stackPanel.Children.Add(dropDownButton);
      stackPanel.Children.Add(dropDownButtonDisabled);
      stackPanel.Children.Add(textBoxEnabled);
      stackPanel.Children.Add(textBoxDisabled);
      stackPanel.Children.Add(slider);
      stackPanel.Children.Add(progressBar);
      stackPanel.Children.Add(progressBarIndeterminate);

      var scrollViewer = new ScrollViewer
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        Content = stackPanel,
        HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
        Margin = new Vector4F(24, 0, 8, 0)
      };

      var layoutRoot = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        Margin = new Vector4F(0, 0, 0, 0),
      };
      layoutRoot.Children.Add(titlePanel);
      layoutRoot.Children.Add(scrollViewer);

      Content = layoutRoot;

      // Add a context menu
      MenuItem item0 = new MenuItem { Content = new TextBlock { Text = "Item 0" }, };
      MenuItem item1 = new MenuItem { Content = new TextBlock { Text = "Item 1" }, };
      MenuItem item2 = new MenuItem { Content = new TextBlock { Text = "Item 2" }, };
      MenuItem item3 = new MenuItem { Content = new TextBlock { Text = "Item 3" }, };
      MenuItem item4 = new MenuItem { Content = new TextBlock { Text = "Item 4" }, };

      ContextMenu = new ContextMenu();
      ContextMenu.Items.Add(item0);
      ContextMenu.Items.Add(item1);
      ContextMenu.Items.Add(item2);
      ContextMenu.Items.Add(item3);
      ContextMenu.Items.Add(item4);
    }
Пример #21
0
    public UIAnimationSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      // Add a DelegateGraphicsScreen as the first graphics screen to the graphics
      // service. This lets us do the rendering in the Render method of this class.
      _graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      // Load a UI theme, which defines the appearance and default values of UI controls.
      Theme theme = ContentManager.Load<Theme>("UI Themes/BlendBlue/Theme");

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer.
      _uiScreen = new UIScreen("SampleUIScreen", renderer);
      UIService.Screens.Add(_uiScreen);

      // ----- Add buttons.
      Button button0 = new Button
      {
        Name = "Button0",
        Content = new TextBlock { Text = "Animate Buttons" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      button0.Click += (s, e) => PlayStartAnimation();

      Button button1 = new Button
      {
        Name = "Button1",
        Content = new TextBlock { Text = "Open FadingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button1.Click += (s, e) => new FadingWindow(Services).Show(_uiScreen);

      Button button2 = new Button
      {
        Name = "Button2",
        Content = new TextBlock { Text = "Open ScalingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button2.Click += (s, e) => new ScalingWindow(Services).Show(_uiScreen);

      Button button3 = new Button
      {
        Name = "Button3",
        Content = new TextBlock { Text = "Open RotatingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button3.Click += (s, e) => new RotatingWindow(Services).Show(_uiScreen);

      Button button4 = new Button
      {
        Name = "Button4",
        Content = new TextBlock { Text = "Open EasingWindow" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button4.Click += (s, e) => new EasingWindow(Services).Show(_uiScreen);

      Button button5 = new Button
      {
        Name = "Button5",
        Content = new TextBlock { Text = "Close All Windows" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button5.Click += (s, e) => CloseWindows();

      Button button6 = new Button
      {
        Name = "Button6",
        Content = new TextBlock { Text = "Exit" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button6.Click += (s, e) => Exit();

      _buttonStackPanel = new StackPanel { Margin = new Vector4F(40) };
      _buttonStackPanel.Children.Add(button0);
      _buttonStackPanel.Children.Add(button1);
      _buttonStackPanel.Children.Add(button2);
      _buttonStackPanel.Children.Add(button3);
      _buttonStackPanel.Children.Add(button4);
      _buttonStackPanel.Children.Add(button5);
      _buttonStackPanel.Children.Add(button6);
      _uiScreen.Children.Add(_buttonStackPanel);

      // Optional: If we want to allow the user to use buttons in the screen with 
      // keyboard or game pad, we have to make it a focus scope. Normally, only 
      // windows are focus scopes.
      _uiScreen.IsFocusScope = true;
      _uiScreen.Focus();

      PlayStartAnimation();
    }
Пример #22
0
        /// <summary>
        /// Load content for this game component
        /// </summary>
        protected override void LoadContent()
        {
            // TODO: Add your initialization code here
            var content = new ContentManager(Game.Services, "NeoforceTheme");
            Theme theme;
            theme = content.Load<Theme>("ThemeRed");

            // Create a UI renderer, which uses the theme info to renderer UI controls.
            var renderer = new UIRenderer(Game, theme);

            // Create a UIScreen and add it to the UI service. The screen is the root of
            // the tree of UI controls. Each screen can have its own renderer.
            _screen = new UIScreen("Default", renderer)
            {
                // Make the screen transparent.
                Background = new Color(0, 0, 0, 0),

            };
            var test = new Canvas()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };

            var maprender = new UIControls.GalaxyMapControl(Game.Services)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
            };
            var minimap = new UIControls.MinimapControl(Game.Services);
            var miniMapWindow = new MiniMapWindow()
            {
                Height = 200,
                Width = 200,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Bottom,
                Name = "MiniMap"
            };
            var controlButtonPanel = new StackPanel()
            {
                Orientation = Orientation.Horizontal,
                VerticalAlignment = VerticalAlignment.Bottom,
                HorizontalAlignment = HorizontalAlignment.Left
            };
            var testButton = new Button()
            {
                Height = 40,
                Width = 200
            };
            controlButtonPanel.Children.Add(testButton);
            miniMapWindow.Content = minimap;
            test.Children.Add(maprender);
            test.Children.Add(controlButtonPanel);
            test.Children.Add(miniMapWindow);

            var mainTabPanel = new TabControl
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch
            };

            var systemMap = new UIControls.SystemMapControl(Game.Services)
            {
                Opacity = 5,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                ViewData = new SystemMapViewModel() { Rings = new[]
                                                                  {
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 1", Scale = 1},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 1 - Moon", Scale = 0.4f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 2", Scale = 0.5f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3", Scale = 0.7f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3 - Moon 1", Scale = 0.3f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 3 - Moon 2", Scale = 0.3f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 4", Scale = 0.2f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 5", Scale = 0.9f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 6", Scale = 0.6f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 7", Scale = 0.3f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 8", Scale = 0.5f},
                                                                                                                   }},
                                                                      new SystemMapRingViewModel() { Planets = new[]
                                                                                                                   {
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9", Scale = 0.8f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 1", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 2", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 3", Scale = 0.2f},
                                                                                                                       new SystemMapPlanetViewModel() { Name = "Planet 9 - Moon 4", Scale = 0.3f},
                                                                                                                   }}
                                                                  }}
            };

            var planetMap = new PlanetMapControl(Game.Services)
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment = VerticalAlignment.Stretch,
                ViewData = new PlanetMapViewModel()
                               {
                                   Name = "Earth",
                                   BuildingCells = new[,]
                                                       {
                                                           { new BuildingCellViewModel(), new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy }, new BuildingCellViewModel() },
                                                           { new BuildingCellViewModel(), new BuildingCellViewModel(), new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy } },
                                                           { new BuildingCellViewModel { Type = CellMultiplier.ExtraEnergy }, new BuildingCellViewModel(), new BuildingCellViewModel() }
                                                       }
                               }
            };

            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "Star map" }, TabPage = test });
            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "System map" }, TabPage = systemMap });
            mainTabPanel.Items.Add(new TabItem() { Content = new TextBlock() { Text = "Planet map" }, TabPage = planetMap });

            _console = new ConsoleWindow(_consoleManager);

            StartMenuScreen start = new StartMenuScreen(Game.Services);
            start.Init();
            _screen.Children.Add(start);

            //_screen.Children.Add(mainTabPanel);
            //_screen.Children.Add(_console);
            //_screen.Children.Add(miniMapWindow);
            //_screen.Children.Add(maprender);

            // Add the screen to the UI service.
            _uiService.Screens.Add(_screen);

            base.LoadContent();
        }
Пример #23
0
    public AllControlsWindow(ContentManager content, IUIRenderer renderer)
    {
      Title = "All Controls (This window has a context menu!)";
      CanResize = false;

      // The window content is set to a horizontal stack panel that contains two vertical
      // stack panels. The controls are added to the vertical panels.

      // ----- Button with text content
      var button0 = new Button
      {
        Content = new TextBlock { Text = "Button" },
        Margin = new Vector4F(4),
      };

      // ----- Button with mixed content
      // The content of a button is usually a text block but can be any UI control.
      // Let's try a button with image + text.
      var buttonContentPanel = new StackPanel { Orientation = Orientation.Horizontal };
      buttonContentPanel.Children.Add(new Image
      {
        Width = 16,
        Height = 16,
        Texture = content.Load<Texture2D>("Icon")
      });

      buttonContentPanel.Children.Add(new TextBlock
      {
        Margin = new Vector4F(4, 0, 0, 0),
        Text = "Button with image",
        VerticalAlignment = VerticalAlignment.Center,
      });

      var button1 = new Button
      {
        Content = buttonContentPanel,
        Margin = new Vector4F(4),
      };

      // ----- Drop-down button
      var dropDown = new DropDownButton
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(4),
        MaxDropDownHeight = 250,
      };
      for (int i = 0; i < 20; i++)
      {
        dropDown.Items.Add("DropDownItem " + i);
      }
      dropDown.SelectedIndex = 0;

      // ----- Check box
      var checkBox = new CheckBox
      {
        Margin = new Vector4F(4),
        Content = new TextBlock { Text = "CheckBox" },
      };

      // ----- Group of radio buttons
      var radioButton0 = new RadioButton
      {
        Margin = new Vector4F(4, 8, 4, 4),
        Content = new TextBlock { Text = "RadioButton0" },
      };

      var radioButton1 = new RadioButton
      {
        Margin = new Vector4F(4, 2, 4, 2),
        Content = new TextBlock { Text = "RadioButton1" },
      };

      var radioButton2 = new RadioButton
      {
        Margin = new Vector4F(4, 2, 4, 4),
        Content = new TextBlock { Text = "RadioButton1" },
      };

      // ----- Progress bar with value
      var progressBar0 = new ProgressBar
      {
        IsIndeterminate = false,
        Value = 75,
        Margin = new Vector4F(4, 8, 4, 4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Cursor = renderer.GetCursor("Wait"),
      };

      // ----- Progress bar without value (indeterminate)
      var progressBar1 = new ProgressBar
      {
        IsIndeterminate = true,
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Cursor = renderer.GetCursor("Wait"),
      };

      // ----- Slider connected with a text box.
      var slider = new Slider
      {
        Value = 60,
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      var sliderValue = new TextBlock
      {
        Margin = new Vector4F(4, 0, 4, 4),
        Text = "(Value = 60)",
        HorizontalAlignment = HorizontalAlignment.Right
      };

      // To connect the slider with the text box, we need to get the "Value" property.
      var valueProperty = slider.Properties.Get<float>("Value");
      // This property is a GameObjectProperty<float>. We can attach an event handler to 
      // the Changed event of the property.
      valueProperty.Changed += (s, e) => sliderValue.Text = "(Value = " + (int)e.NewValue + ")";

      // ----- Scroll bar
      var scrollBar = new ScrollBar
      {
        Style = "ScrollBarHorizontal",
        SmallChange = 1,
        LargeChange = 10,
        Value = 45,
        ViewportSize = 0.3f,
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      // Add the controls to the first vertical stack panel.
      var stackPanel0 = new StackPanel
      {
        Margin = new Vector4F(4),
      };
      stackPanel0.Children.Add(button0);
      stackPanel0.Children.Add(button1);
      stackPanel0.Children.Add(dropDown);
      stackPanel0.Children.Add(checkBox);
      stackPanel0.Children.Add(radioButton0);
      stackPanel0.Children.Add(radioButton1);
      stackPanel0.Children.Add(radioButton2);
      stackPanel0.Children.Add(progressBar0);
      stackPanel0.Children.Add(progressBar1);
      stackPanel0.Children.Add(slider);
      stackPanel0.Children.Add(sliderValue);
      stackPanel0.Children.Add(scrollBar);

      // ----- Group box
      var groupBox = new GroupBox
      {
        Title = "GroupBox",
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(4),
        Content = new TextBlock
        {
          Margin = new Vector4F(4),
          Text = "GroupBox Content"
        }
      };

      // ----- Tab control with 3 tab items
      var tabItem0 = new TabItem
      {
        TabPage = new TextBlock { Margin = new Vector4F(4), Text = "Page 0" },
        Content = new TextBlock { Text = "Item 0" },
      };
      var tabItem1 = new TabItem
      {
        TabPage = new TextBlock { Margin = new Vector4F(4), Text = "Page 1" },
        Content = new TextBlock { Text = "Item 1" },
      };
      var tabItem2 = new TabItem
      {
        TabPage = new TextBlock { Margin = new Vector4F(4), Text = "Page 2" },
        Content = new TextBlock { Text = "Item 2" },
      };
      var tabControl = new TabControl
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Margin = new Vector4F(4),
      };
      tabControl.Items.Add(tabItem0);
      tabControl.Items.Add(tabItem1);
      tabControl.Items.Add(tabItem2);

      // ----- Scroll viewer showing an image
      var image = new Image
      {
        Texture = content.Load<Texture2D>("Sky"),
      };

      var scrollViewer = new ScrollViewer
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        MinHeight = 100,
        HorizontalOffset = 200,
        VerticalOffset = 200,
        Height = 200,
      };
      scrollViewer.Content = image;

      // ----- Text box
      var textBox0 = new TextBox
      {
        Margin = new Vector4F(4),
        Text = "The quick brown fox jumps over the lazy dog.",
        MaxLines = 1,
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      // ----- Password box
      var textBox1 = new TextBox
      {
        Margin = new Vector4F(4),
        Text = "Secret password!",
        MaxLines = 1,
        IsPassword = true,
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      // ----- Multi-line text box
      var textBox2 = new TextBox
      {
        Margin = new Vector4F(4),
        Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eleifend, nulla semper vestibulum congue, lectus lectus aliquam magna, lobortis luctus sem magna sit amet elit. Integer at neque nec mi dapibus tincidunt. Maecenas elit quam, varius luctus rutrum ut, congue quis libero. In hac habitasse platea dictumst. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Phasellus eu ante eros. Etiam odio lectus, sagittis non dictum eu, faucibus vitae magna. Maecenas mi lorem, semper vel condimentum sit amet, vehicula quis nulla. Cras suscipit scelerisque orci, ac ullamcorper lorem egestas sed. Nulla facilisi. Nam justo enim, mollis nec condimentum non, consectetur vel purus. Curabitur ac diam vitae justo ultricies auctor.\n"
             + "Pellentesque interdum vehicula nisi sed congue. Etiam eget magna nec metus suscipit tincidunt et in lectus. Praesent sapien tortor, congue et semper eu, mattis ac lorem. Duis id est et justo tempus consectetur. Aliquam rutrum ullamcorper augue non varius. Fusce ornare lectus et ipsum lobortis ut venenatis tellus sodales. Proin venenatis scelerisque dui eu viverra. Pellentesque vitae risus eget tellus vehicula molestie et quis ante. Nulla imperdiet rhoncus ante, eu tristique ante euismod id. Sed varius varius hendrerit. Praesent massa tortor, gravida suscipit lacinia non, suscipit a ipsum. Integer vulputate, felis vitae consectetur bibendum, ante velit tincidunt nunc, in convallis erat dolor eu purus.",
        MinLines = 5,
        MaxLines = 5,
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };

      // ----- Console (command prompt)
      var console = new Console
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        MinHeight = 100,
      };

      // Add the controls to the second vertical stack panel.
      var stackPanel1 = new StackPanel
      {
        Width = 250,
        Margin = new Vector4F(4),
      };
      stackPanel1.Children.Add(groupBox);
      stackPanel1.Children.Add(tabControl);
      stackPanel1.Children.Add(scrollViewer);
      stackPanel1.Children.Add(textBox0);
      stackPanel1.Children.Add(textBox1);
      stackPanel1.Children.Add(textBox2);
      stackPanel1.Children.Add(console);

      // Add the two vertical stack panel into a horizontal stack panel.
      var stackPanelHorizontal = new StackPanel
      {
        Orientation = Orientation.Horizontal
      };
      stackPanelHorizontal.Children.Add(stackPanel0);
      stackPanelHorizontal.Children.Add(stackPanel1);

      Content = stackPanelHorizontal;

      // ----- Add a context menu to the window. (Each UI control can have its own context menu.)
      ContextMenu = new ContextMenu();

      // Add menu items.
      for (int i = 0; i < 10; i++)
      {
        var menuItem = new MenuItem
        {
          Content = new TextBlock { Text = "MenuItem" + i },
        };
        ContextMenu.Items.Add(menuItem);
      }
    }
Пример #24
0
    /// <inheritdoc/>
    protected override void OnUnload()
    {
      // Clean up and remove controls for icon, title and close button.
      if (_icon != null)
      {
        var icon = Properties.Get<Texture2D>(IconPropertyId);
        var imageTexture = _icon.Properties.Get<Texture2D>(Image.TexturePropertyId);
        icon.Changed -= imageTexture.Change;

#if !WINDOWS_UWP
        var iconSourceRectangle = Properties.Get<Rectangle?>(IconSourceRectanglePropertyId);
        var imageSourceRectangle = _icon.Properties.Get<Rectangle?>(Image.SourceRectanglePropertyId);
        iconSourceRectangle.Changed -= imageSourceRectangle.Change;
#else
        var iconSourceRectangle = Properties.Get<Rectangle>(IconSourceRectanglePropertyId);
        var imageSourceRectangle = _icon.Properties.Get<Rectangle>(Image.SourceRectanglePropertyId);
        iconSourceRectangle.Changed -= imageSourceRectangle.Change;
#endif

        VisualChildren.Remove(_icon);
        _icon = null;
      }

      if (_caption != null)
      {
        var title = Properties.Get<string>(TitlePropertyId);
        var captionText = _caption.Properties.Get<string>(TextBlock.TextPropertyId);
        title.Changed -= captionText.Change;

        VisualChildren.Remove(_caption);
        _caption = null;
      }

      if (_closeButton != null)
      {
        _closeButton.Click -= OnCloseButtonClick;
        VisualChildren.Remove(_closeButton);
        _closeButton = null;
      }

      if (_setSpecialCursor && UIService != null)
      {
        UIService.Cursor = null;
        _setSpecialCursor = false;
      }

      Owner = null;
      IsActive = false;
      base.OnUnload();
    }
Пример #25
0
    private void AddButton(StackPanel panel, string text, Action clickHandler)
    {
      var button = new Button
      {
        Content = new TextBlock { Text = text },
        HorizontalAlignment = HorizontalAlignment.Stretch,
        MinWidth = 100
      };

      if (panel.Children.Count > 0)
        button.Margin = (panel.Orientation == Orientation.Horizontal) ? new Vector4F(3, 0, 0, 0) : new Vector4F(0, 3, 0, 0);

#if WINDOWS_PHONE || ANDROID || IOS
      button.Padding = new Vector4F(15);
#endif

      if (clickHandler != null)
        button.Click += (s, e) => clickHandler();

      panel.Children.Add(button);
    }
Пример #26
0
    /// <summary>
    /// Called when "Menu" state is entered.
    /// </summary>
    private void OnEnterMenuScreen(object sender, StateEventArgs eventArgs)
    {
      // Show a main menu consisting of several buttons.

      // The user should be able to select individual buttons by using the 
      // D-pad on the gamepad or the arrow keys. Therefore we need to create
      // a Window. A Window manages the currently selected ("focused") control 
      // and automatically handles focus movement.
      // In this example the Window is invisible (no chrome) and stretches across 
      // the entire screen.
      _menuWindow = new Window
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };
      _uiScreen.Children.Add(_menuWindow);

      // The content of the Window is a vertical StackPanel containing several buttons.
      var stackPanel = new StackPanel
      {
        Orientation = Orientation.Vertical,
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Bottom,
        Margin = new Vector4F(150, 0, 0, 200)
      };
      _menuWindow.Content = stackPanel;

      // The "Start" button starts the "Game" state.
      var startButton = new Button
      {
        Name = "StartButton",
        Content = new TextBlock { Text = "Start" },
        FocusWhenMouseOver = true,
      };
      startButton.Click += OnStartButtonClicked;

      // The buttons "Sub menu 1" and "Sub menu 2" show a dummy sub-menu.
      var subMenu1Button = new Button
      {
        Name = "SubMenu1Button",
        Content = new TextBlock { Text = "Sub-menu 1" },
        FocusWhenMouseOver = true,
      };
      subMenu1Button.Click += OnSubMenuButtonClicked;

      var subMenu2Button = new Button
      {
        Name = "SubMenu2Button",
        Content = new TextBlock { Text = "Sub-menu 2" },
        FocusWhenMouseOver = true,
      };
      subMenu2Button.Click += OnSubMenuButtonClicked;

      // The "Exit" button closes the application.
      var exitButton = new Button
      {
        Name = "ExitButton",
        Content = new TextBlock { Text = "Exit" },
        FocusWhenMouseOver = true,
      };
      exitButton.Click += OnExitButtonClicked;

      stackPanel.Children.Add(startButton);
      stackPanel.Children.Add(subMenu1Button);
      stackPanel.Children.Add(subMenu2Button);
      stackPanel.Children.Add(exitButton);

      // By default, the first button should be selected.
      startButton.Focus();

      // Slide the buttons in from the left (off screen) to make things more dynamic.
      AnimateFrom(stackPanel.Children, 0, new Vector2F(-300, 0));

      // The first time initialization of the GUI can take a short time. If we reset the elapsed 
      // time of the XNA game timer, the animation will start a lot smoother. 
      // (This works only if the XNA game uses a variable time step.)
      Game.ResetElapsedTime();
    }
Пример #27
0
        /// <summary> Called when the game object should load its content.</summary>
        protected override void OnLoad()
        {
            var content = ServiceLocator.Current.GetInstance<ContentManager>();

            _endTurnButton = new Image { Texture = content.Load<Texture2D>("UI/endturnbutton"), };
            _endMovementButton = new Image { Texture = content.Load<Texture2D>("UI/endmovementbutton"), };

            _healthBars = new List<Image>(TurnManagerObject.characterList.Count);
            _healthAmounts = new List<Image>(_healthBars.Count);
            _turnListBoxes = new List<Image>();
            _turnListImages = new List<Image>();
            _turnListHealth = new List<Image>();
            for (int i = 0; i < TurnManagerObject.characterList.Count;  i++)
            {
                _healthBars.Add(new Image { Texture = content.Load<Texture2D>("UI/Healthbar") });
                _healthAmounts.Add(new Image { Texture = content.Load<Texture2D>("UI/health") });

                _turnListBoxes.Add(new Image { Texture = content.Load<Texture2D>("UI/turnlistbox"),});
                _turnListImages.Add(new Image {
                    Texture = content.Load<Texture2D>("Placeholder"),
                    X = 1,
                    Width = 50, Height = 50,
                });
                _turnListHealth.Add(new Image { Texture = content.Load<Texture2D>("UI/turnlisthealth"), X = 1 });
            }

            _statsBox = new Image
            {
                Texture = content.Load<Texture2D>("UI/characterbox"),
                X = 100,
                Y = 630,
            };

            _turnButton = new Button
            {
                Margin = new Vector4F(10),
                X = 1010,
                Y = 630,
                Content = _endTurnButton,
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment = VerticalAlignment.Bottom,
            };
            _turnButton.Click += (s, e) => EndButtonClicked = true;

            _currentCharacterImage = new Image
            {
                Width = 80,
                Height = 80,
                Texture = null,
                X = 20,
                Y = 630,
            };

            _hudOverlay = new Image
            {
                Texture = content.Load<Texture2D>("UI/UIOverlay"),
            };

            _health = new TextBlock
            {
                Font = "stattext",
                Text = "100",
                X = 130,
                Y = 640,
            };

            _damage = new TextBlock
            {
                Font = "stattext",
                Text = "100",
                X = 130,
                Y = 662,
            };

            _range= new TextBlock
            {
                Font = "stattext",
                Text = "100",
                X = 130,
                Y = 684,
            };

            _armor = new TextBlock
            {
                Font = "stattext",
                Text = "100",
                X = 215,
                Y = 640,
            };

            _armorDamage = new TextBlock
            {
                Font = "stattext",
                Text = "100",
                X = 215,
                Y = 662,
            };

            _movement = new TextBlock
            {
                Font = "stattext",
                Text = "100",
                X = 215,
                Y = 684,
            };

            _gameLog = new TextBox
            {
                HorizontalAlignment = DigitalRune.Game.UI.HorizontalAlignment.Center,
                Width = 700,
                Height = 78,
                Background = new Microsoft.Xna.Framework.Color(0.0f, 0.0f, 0.0f, 0.5f),
                Y = 630,
                MinLines = 3,
                MaxLines = 3,
                IsReadOnly = true,
                Font = "Consolas",
            };

            foreach (Image bar in _healthBars) Children.Add(bar);
            foreach (Image bar in _healthAmounts) Children.Add(bar);

            Children.Add(_hudOverlay);

            foreach (Image bar in _turnListBoxes) Children.Add(bar);
            foreach (Image bar in _turnListImages) Children.Add(bar);
            foreach (Image bar in _turnListHealth) Children.Add(bar);

            Children.Add(_currentCharacterImage);
            Children.Add(_turnButton);
            Children.Add(_statsBox);

            Children.Add(_health);
            Children.Add(_damage);
            Children.Add(_range);
            Children.Add(_armor);
            Children.Add(_armorDamage);
            Children.Add(_movement);

            Children.Add(_gameLog);

            base.OnLoad();
        }
Пример #28
0
    private void CreateGui()
    {
      // Remove old screen.
      if (_uiScreen != null)
        UIService.Screens.Remove(_uiScreen);

      // Load a UI theme, which defines the appearance and default values of UI controls.
      string themeName;
      if (_themeNumber == 0)
        themeName = "UI Themes/BlendBlue/Theme";
      else
        themeName = "UI Themes/Aero/Theme";

      Theme theme = ContentManager.Load<Theme>(themeName);

      // Create a UI renderer, which uses the theme info to renderer UI controls.
      UIRenderer renderer = new UIRenderer(Game, theme);

      // Create a UIScreen and add it to the UI service. The screen is the root of the 
      // tree of UI controls. Each screen can have its own renderer.
      _uiScreen = new UIScreen("SampleUIScreen", renderer);
      UIService.Screens.Add(_uiScreen);

      // Add a text block that displays the frame rate.
      _uiScreen.Children.Add(new FpsTextBlock
      {
        HorizontalAlignment = HorizontalAlignment.Right,
        VerticalAlignment = VerticalAlignment.Top,
        Margin = new Vector4F(40),
      });

      // Add a text label.
      var textBlock = new TextBlock
      {
        Text = "Press button to open window: ",
        Margin = new Vector4F(4)
      };

      // Add buttons that open samples.
      var button0 = new Button
      {
        Content = new TextBlock { Text = "Sample #1: Controls" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      button0.Click += (s, e) =>
      {
        var allControlsWindow = new AllControlsWindow(ContentManager, renderer);
        allControlsWindow.Show(_uiScreen);
      };

      var button1 = new Button
      {
        Content = new TextBlock { Text = "Sample #2: ScrollViewer" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button1.Click += (s, e) =>
      {
        var resizableWindow = new ResizableWindow(ContentManager);
        resizableWindow.Show(_uiScreen);
      };

      var button2 = new Button
      {
        Content = new TextBlock { Text = "Sample #3: Transformations" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button2.Click += (s, e) =>
      {
        var renderTransformWindow = new RenderTransformWindow();
        renderTransformWindow.Show(_uiScreen);
      };

      var button3 = new Button
      {
        Content = new TextBlock { Text = "Sample #4: Dialogs" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button3.Click += (s, e) =>
      {
        var dialogDemoWindow = new DialogDemoWindow();
        dialogDemoWindow.Show(_uiScreen);
      };

      var button4 = new Button
      {
        Content = new TextBlock { Text = "Sample #5: Console" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button4.Click += (s, e) =>
      {
        var consoleWindow = new ConsoleWindow();
        consoleWindow.Show(_uiScreen);
      };

      var button5 = new Button
      {
        Content = new TextBlock { Text = "Switch UI Theme" },
        Margin = new Vector4F(4),
        Padding = new Vector4F(6),
        HorizontalAlignment = HorizontalAlignment.Stretch
      };
      button5.Click += (s, e) =>
      {
        // Set a flag. In the next Update() we will load a new theme.
        // Note: We should not load the theme here because the UI is currently updated.
        _changeTheme = true;
      };

      var stackPanel = new StackPanel { Margin = new Vector4F(40) };
      stackPanel.Children.Add(textBlock);
      stackPanel.Children.Add(button0);
      stackPanel.Children.Add(button1);
      stackPanel.Children.Add(button2);
      stackPanel.Children.Add(button3);
      stackPanel.Children.Add(button4);
      stackPanel.Children.Add(button5);
      _uiScreen.Children.Add(stackPanel);

      // Optional: If we want to allow the user to use buttons in the screen with 
      // keyboard or game pad, we have to make it a focus scope. Normally, only 
      // windows are focus scopes.
      _uiScreen.IsFocusScope = true;
      _uiScreen.Focus();
    }
Пример #29
0
    public OptionsWindow()
    {
      Title = "Options (Switch tabs with LB and RB)";
      CanResize = false;
      CanDrag = false;
      HorizontalAlignment = HorizontalAlignment.Center;
      VerticalAlignment = VerticalAlignment.Center;

      var nameTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Your name:",
      };

      var nameTextBox = new TextBox
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Text = "Player1",
      };

      var passwordTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Your password:"******"Difficulty:",
      };

      var easyRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Easy" },
        GroupName = "Difficulty",
      };

      var normalRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Normal" },
        GroupName = "Difficulty",
        IsChecked = true,
      };

      var hardRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Hard" },
        GroupName = "Difficulty",
      };

      var modeTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Mode:",
      };

      var simulationRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Simulation" },
        GroupName = "Mode",
      };

      var arcadeRadioButton = new RadioButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Content = new TextBlock { Text = "Arcade" },
        GroupName = "Mode",
        IsChecked = true,
      };

      var generalPanel = new StackPanel
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      generalPanel.Children.Add(nameTextBlock);
      generalPanel.Children.Add(nameTextBox);
      generalPanel.Children.Add(passwordTextBlock);
      generalPanel.Children.Add(passwordTextBox);
      generalPanel.Children.Add(difficultyTextBlock);
      generalPanel.Children.Add(easyRadioButton);
      generalPanel.Children.Add(normalRadioButton);
      generalPanel.Children.Add(hardRadioButton);
      generalPanel.Children.Add(modeTextBlock);
      generalPanel.Children.Add(simulationRadioButton);
      generalPanel.Children.Add(arcadeRadioButton);

      var generalTab = new TabItem
      {
        TabPage = generalPanel,
        Content = new TextBlock { Text = "General" },
      };

      var resolutionTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Resolution:",
      };

      var resolutionDropDownButton = new DropDownButton
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        MaxDropDownHeight = 400,
      };
      resolutionDropDownButton.Items.Add("640 x 400");
      resolutionDropDownButton.Items.Add("800 x 480");
      resolutionDropDownButton.Items.Add("1024 x 768");
      resolutionDropDownButton.Items.Add("1280 x 720");
      resolutionDropDownButton.Items.Add("1920 x 1080");
      resolutionDropDownButton.Items.Add("1920 x 1200");
      resolutionDropDownButton.SelectedIndex = 3;

      var qualityTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
        Text = "Quality:",
      };

      var qualityValueTextBlock = new TextBlock
      {
        Margin = new Vector4F(4),
      };

      var qualityTextPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal,
      };
      qualityTextPanel.Children.Add(qualityTextBlock);
      qualityTextPanel.Children.Add(qualityValueTextBlock);

      var qualitySlider = new Slider
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Minimum = 0,
        Maximum = 10,
        SmallChange = 1,        // This value is used when the user presses LEFT/RIGHT to move the slider.
        LargeChange = 1,        // This value is used when the user presses the slider (not the thumb).
      };

      // Each game object property (e.g. Slider.Minimum/Maximum/Margin/Value/...) has a Changing
      // and a Changed event. To use it, we have to get the property:
      GameProperty<float> sliderValueProperty = qualitySlider.Properties.Get<float>("Value");

      // We can use the Changing event to coerce the property value. For example: A normal slider
      // can have any values when dragged with the mouse. We can coerce the value to only allow
      // integer values!
      sliderValueProperty.Changing += (s, e) => e.CoercedValue = (float)Math.Round(e.CoercedValue);

      // We can use the Changed event to update dependent values. Here, we update the text block
      // text whenever the slider value changes.
      sliderValueProperty.Changed += (s, e) => qualityValueTextBlock.Text = qualitySlider.Value.ToString();

      // Initialize the slider value. This raises the Changing and Changed events, and the 
      // qualityValueTextBlock is updated too.
      qualitySlider.Value = 4;

      var graphicsPanel = new StackPanel
      {
        Margin = new Vector4F(4),
        HorizontalAlignment = HorizontalAlignment.Stretch,
      };
      graphicsPanel.Children.Add(resolutionTextBlock);
      graphicsPanel.Children.Add(resolutionDropDownButton);
      graphicsPanel.Children.Add(qualityTextPanel);
      graphicsPanel.Children.Add(qualitySlider);

      var graphicsTab = new TabItem
      {
        TabPage = graphicsPanel,
        Content = new TextBlock { Text = "Graphics" },
      };

      var tabControl = new TabControl
      {
        Width = 300,
        Height = 300,
        Margin = new Vector4F(4)
      };
      tabControl.Items.Add(generalTab);
      tabControl.Items.Add(graphicsTab);

      var okButton = new Button
      {
        Width = 100,
        Margin = new Vector4F(4),
        Content = new TextBlock { Text = "OK (START)" },
        IsDefault = true,
      };
      okButton.Click += OnOK;

      var cancelButton = new Button
      {
        Width = 100,
        Margin = new Vector4F(4),
        Content = new TextBlock { Text = "Cancel (BACK)" },
        IsCancel = true,
      };
      cancelButton.Click += OnCancel;

      var buttonPanel = new StackPanel
      {
        Orientation = Orientation.Horizontal,
        HorizontalAlignment = HorizontalAlignment.Center,
      };
      buttonPanel.Children.Add(okButton);
      buttonPanel.Children.Add(cancelButton);

      var mainPanel = new StackPanel
      {
        Margin = new Vector4F(4)
      };
      mainPanel.Children.Add(tabControl);
      mainPanel.Children.Add(buttonPanel);

      Content = mainPanel;
    }
Пример #30
0
    //--------------------------------------------------------------
    #region Methods
    //--------------------------------------------------------------

    /// <inheritdoc/>
    protected override void OnLoad()
    {
      base.OnLoad();

      // Create decrement button.
      var decrementButtonStyle = DecrementButtonStyle;
      if (!string.IsNullOrEmpty(decrementButtonStyle))
      {
        _decrementButton = new Button
        {
          Name = "DecrementButton",
          Style = decrementButtonStyle,
          Focusable = false,          // Unlike normal buttons these arrow button can not be focused!
          IsRepeatButton = true,
        };
        VisualChildren.Add(_decrementButton);

        var click = _decrementButton.Events.Get<EventArgs>(ButtonBase.ClickEventId);
        click.Event += OnDecrementButtonClick;
      }

      // Create increment button.
      var incrementButtonStyle = IncrementButtonStyle;
      if (!string.IsNullOrEmpty(incrementButtonStyle))
      {
        _incrementButton = new Button
        {
          Name = "RightDownButton",
          Style = incrementButtonStyle,
          Focusable = false,          // Unlike normal buttons these arrow button can not be focused!
          IsRepeatButton = true,
        };
        VisualChildren.Add(_incrementButton);

        var click = _incrementButton.Events.Get<EventArgs>(ButtonBase.ClickEventId);
        click.Event += OnIncrementButtonClick;
      }

      // Create thumb.
      var thumbStyle = ThumbStyle;
      if (!string.IsNullOrEmpty(thumbStyle))
      {
        _thumb = new Thumb
        {
          Name = "ScrollBarThumb",
          Style = thumbStyle,
        };
        VisualChildren.Add(_thumb);
      }
    }