Пример #1
0
    public FadingWindow(IServiceLocator services) 
      : base(services)
    {
      Title = "FadingWindow";

      Width = 200;
      Height = 100;

      Content = new TextBlock
      {
        Margin = new Vector4F(8),
        Text = "The 'Opacity' of this window is animated.",
        WrapText = true,
      };

      LoadingAnimation = new SingleFromToByAnimation
      {
        TargetProperty = "Opacity",           // Transition the property UIControl.Opacity 
        From = 0,                             // from 0 to its actual value
        Duration = TimeSpan.FromSeconds(0.3), // over a duration of 0.3 seconds.
      };

      ClosingAnimation = new SingleFromToByAnimation
      {
        TargetProperty = "Opacity",           // Transition the property UIControl.Opacity
        To = 0,                               // from its current value to 0
        Duration = TimeSpan.FromSeconds(0.3), // over a duration 0.3 seconds.
      };
    }
Пример #2
0
        protected override void OnLoad()
        {
            // size controls
            {
                var widthL = new TextBlock { Text = "Width:", VerticalAlignment = VerticalAlignment.Center };
                var widthTB = new TextBox { Text = "", VerticalAlignment = VerticalAlignment.Center };
                var widthSP = new StackPanel { Orientation = Orientation.Horizontal,
                    Margin = new Vector4F(4),
                    Padding = new Vector4F(4),
                };
                widthSP.Children.Add(widthL);
                widthSP.Children.Add(widthTB);

                var sizeStack = new StackPanel() { Orientation = Orientation.Vertical,
                    Margin = new Vector4F(4),
                    Padding = new Vector4F(4),
                };
                sizeStack.Children.Add(widthSP);
                
                var sizeGroup = new GroupBox()
                {
                    Title = "Size",
                    Content = sizeStack,
                    Margin = new Vector4F(4),
                    Padding = new Vector4F(4),
                };

                this.Content = sizeGroup;
            }

            base.OnLoad();
        }
Пример #3
0
    public ScalingWindow(IServiceLocator services) 
      : base(services)
    {
      Title = "ScalingWindow";

      Width = 200;
      Height = 100;

      Content = new TextBlock
      {
        Margin = new Vector4F(8),
        Text = "The 'RenderScale' of this window is animated.",
        WrapText = true,
      };

      // Set the center of the scale transformation to the center of the window. 
      RenderTransformOrigin = new Vector2F(0.5f, 0.5f);

      LoadingAnimation = new Vector2FFromToByAnimation
      {
        TargetProperty = "RenderScale",       // Animate the property UIControl.RenderScale 
        From = new Vector2F(0, 0),            // from (0, 0) to its actual value (1, 1)
        Duration = TimeSpan.FromSeconds(0.3), // over 0.3 seconds.
        EasingFunction = new ElasticEase { Mode = EasingMode.EaseOut, Oscillations = 1 },
      };

      ClosingAnimation = new Vector2FFromToByAnimation
      {
        TargetProperty = "RenderScale",       // Animate the property UIControl.RenderScale
        To = new Vector2F(0, 0),              // from its current value to (0, 0)
        Duration = TimeSpan.FromSeconds(0.3), // over 0.3 seconds.
        EasingFunction = new HermiteEase { Mode = EasingMode.EaseIn },
      };
    }
Пример #4
0
 private static TextBlock CreateTextBoxShowingCurrentValue(float startValue)
 {
     var textBlock = new TextBlock
                         {
                             HorizontalAlignment = HorizontalAlignment.Center,
                             VerticalAlignment = VerticalAlignment.Center
                         };
     textBlock.Text = startValue.ToString();
     return textBlock;
 }
Пример #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
    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;
    }
Пример #7
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 },
        },
      };
    }
Пример #8
0
    public RotatingWindow(IServiceLocator services) 
      : base(services)
    {
      Title = "RotatingWindow";

      Width = 250;
      Height = 100;

      Content = new TextBlock
      {
        Margin = new Vector4F(8),
        Text = "The 'RenderScale' and the 'RenderRotation' of this window are animated.",
        WrapText = true,
      };

      // Set the center of the scale and rotation transformations to the center of the window. 
      RenderTransformOrigin = new Vector2F(0.5f, 0.5f);

      // The loading animation is a timeline group of two animations. 
      // One animations animates the RenderScale from (0, 0) to its current value.
      // The other animation animates the RenderRotation from 10 to its current value.
      // The base class AnimatedWindow will apply this timeline group on this window 
      // when the window is loaded.
      LoadingAnimation = new TimelineGroup
      {
        new Vector2FFromToByAnimation
        {
          TargetProperty = "RenderScale",
          From = new Vector2F(0, 0),
          Duration = TimeSpan.FromSeconds(0.8),
          EasingFunction = new HermiteEase { Mode = EasingMode.EaseOut },
        },
        new SingleFromToByAnimation
        {
          TargetProperty = "RenderRotation",
          From = 10,
          Duration = TimeSpan.FromSeconds(0.8),
          EasingFunction = new HermiteEase { Mode = EasingMode.EaseOut },
        }
      };

      // The closing animation is a timeline group of two animations. 
      // One animations animates the RenderScale from its current value to (0, 0).
      // The other animation animates the RenderRotation its current value to 10.
      // 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.8),
          EasingFunction = new HermiteEase { Mode = EasingMode.EaseIn },
        },
        new SingleFromToByAnimation
        {
          TargetProperty = "RenderRotation",
          To = 10,
          Duration = TimeSpan.FromSeconds(0.8),
          EasingFunction = new HermiteEase { Mode = EasingMode.EaseIn },
        }
      };
    }
Пример #9
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();
    }
Пример #10
0
    /// <inheritdoc/>
    protected override void OnUnload()
    {
      if (_titleTextBlock != null)
      {
        // Disconnect Title and TextBlock.Text.
        var title = Properties.Get<string>(TitlePropertyId);
        var text = _titleTextBlock.Properties.Get<string>(TextBlock.TextPropertyId);
        title.Changed -= text.Change;

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

      base.OnUnload();
    }
Пример #11
0
    //--------------------------------------------------------------
    #region Methods
    //--------------------------------------------------------------

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

      // _panel and _scrollViewer are only initialized once and reused. They are not destroyed
      // in Unload().
      if (_itemsPanel != null)
        return;

      string scrollViewerStyle = ContentStyle;
      if (string.IsNullOrEmpty(scrollViewerStyle))
        scrollViewerStyle = "ScrollViewer";

      _itemsPanel = new StackPanel
      {
        HorizontalAlignment = HorizontalAlignment.Stretch,
        Orientation = Orientation.Vertical,
      };

      _scrollViewer = new ScrollViewer
      {
        Style = scrollViewerStyle,
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
        HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
        VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
        Content = _itemsPanel,
      };

      if (GlobalSettings.PlatformID == PlatformID.WindowsPhone7 
          || GlobalSettings.PlatformID == PlatformID.WindowsPhone8)
      {
        // On Windows Phone the DropDown fills the whole screen and a title is displayed on top.
        var titleTextBlockStyle = TitleTextBlockStyle;
        if (!string.IsNullOrEmpty(titleTextBlockStyle))
        {
          var title = new TextBlock
          {
            Style = titleTextBlockStyle,
            Text = Owner.Title,
          };

          // Connect DropDownButton.Title with title.Text.
          var titleProperty = Owner.Properties.Get<string>(DropDownButton.TitlePropertyId);
          var textProperty = title.Properties.Get<string>(TextBlock.TextPropertyId);
          titleProperty.Changed += textProperty.Change;

          var outerPanel = new StackPanel
          {
            HorizontalAlignment = HorizontalAlignment.Stretch,
            VerticalAlignment = VerticalAlignment.Stretch,
            Orientation = Orientation.Vertical,
          };
          outerPanel.Children.Add(title);
          outerPanel.Children.Add(_scrollViewer);
          Content = outerPanel;

          // The ContentStyle should be applied to the scroll viewer - not the outer panel:
          outerPanel.Style = "StackPanel";
          _scrollViewer.Style = ContentStyle;
        }
        else
        {
          Content = _scrollViewer;
        }
      }
      else
      {
        Content = _scrollViewer;
      }
    }
Пример #12
0
 /// <summary>
 /// Called when "Game" state is exited.
 /// </summary>
 private void OnExitGameScreen(object sender, StateEventArgs eventArgs)
 {
   // Clean up.
   _uiScreen.Children.Remove(_gameTextBlock);
   _gameTextBlock = null;
 }
Пример #13
0
        /// <summary> Loads the credits.</summary>
        private void LoadCredits()
        {
            _backgroundMusic = content.Load<Song>("SoundFX/end_level");
            _gameOver = new TextBlock
            {
                Font = "stattext",
                Text = "Thanks for playing! This has been another HATtrick Games production from \n the awesome people, Hamish Carrier, Arran Ford and Timothy Veletta. \n Remember this game is licensed under the BEER-WARE license, \n so if you like what we do, feel free to buy us a beer in return.",
                Width = 500,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
            };

            _endLevelUI.Children.Add(_gameOver);
        }
Пример #14
0
    /// <summary>
    /// Called when "Start" state is exited.
    /// </summary>
    private void OnExitStartScreen(object sender, StateEventArgs eventArgs)
    {
      // Clean up.
      _exitAnimationController.Stop();
      _exitAnimationController.Recycle();
      _exitAnimationIsPlaying = false;

      _uiScreen.Children.Remove(_startTextBlock);
      _startTextBlock = null;
    }
Пример #15
0
 /// <summary>
 /// Called when "Game" state is entered.
 /// </summary>
 private void OnEnterGameScreen(object sender, StateEventArgs eventArgs)
 {
   // Show a dummy text.
   _gameTextBlock = new TextBlock
   {
     Text = "Game is running. (Press Back button to return to menu.)",
     HorizontalAlignment = HorizontalAlignment.Center,
     VerticalAlignment = VerticalAlignment.Center,
   };
   _uiScreen.Children.Add(_gameTextBlock);
 }
Пример #16
0
    private AnimationController _exitAnimationController; // Controls the fade-out animation.


    /// <summary>
    /// Called when "Start" state is entered.
    /// </summary>
    private void OnEnterStartScreen(object sender, StateEventArgs eventArgs)
    {
      // Show the "Press Start button" text centered on the screen.
      _startTextBlock = new TextBlock
      {
        Name = "StartTextBlock",
        Text = "Press Start button",
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center,
      };
      _uiScreen.Children.Add(_startTextBlock);

      // The text should pulse to indicate that a user interaction is required.
      // To achieve this we can animate the opacity of the TextBlock.
      var opacityAnimation = new SingleFromToByAnimation
      {
        From = 1,                             // Animate from opaque (Opacity == 1)
        To = 0.25f,                           // to nearly transparent (Opacity == 0.25)
        Duration = TimeSpan.FromSeconds(0.5), // over a duration of 0.5 seconds.
        EasingFunction = new SineEase { Mode = EasingMode.EaseInOut }
      };

      // A SingleFromToByAnimation plays only once, but the animation should be 
      // played back-and-forth until the user presses a button.
      // We need wrap the SingleFromToByAnimation in an AnimationClip or TimelineClip.
      // Animation clips can be used to cut and loop other animations.
      var loopingOpacityAnimation = new AnimationClip<float>(opacityAnimation)
      {
        LoopBehavior = LoopBehavior.Oscillate,  // Play back-and-forth.
        Duration = TimeSpan.MaxValue            // Loop forever.
      };

      // We want to apply the animation to the "Opacity" property of the TextBlock.
      // All "game object properties" of a UIControl can be made "animatable".      
      // First, get a handle to the "Opacity" property.
      var opacityProperty = _startTextBlock.Properties.Get<float>(TextBlock.OpacityPropertyId);

      // Then cast the "Opacity" property to an IAnimatableProperty. 
      var animatableOpacityProperty = opacityProperty.AsAnimatable();

      // Start the pulse animation.
      var animationController = AnimationService.StartAnimation(loopingOpacityAnimation, animatableOpacityProperty);

      // Enable "automatic recycling". This step is optional. It ensures that the
      // associated resources are recycled when either the animation is stopped or
      // the target object (the TextBlock) is garbage collected.
      // (The associated resources will be reused by future animations, which will
      // reduce the number of required memory allocations at runtime.)
      animationController.AutoRecycle();
    }
Пример #17
0
 /// <summary>
 /// Called when "Loading" state is exited.
 /// </summary>
 private void OnExitLoadingScreen(object sender, StateEventArgs eventArgs)
 {
   // Clean up.
   _uiScreen.Children.Remove(_loadingTextBlock);
   _loadingTextBlock = null;
 }
Пример #18
0
    private volatile bool _allAssetsLoaded; // Will be set to true, when the background thread is finished.


    /// <summary>
    /// Called when "Loading" state is entered.
    /// </summary>
    private void OnEnterLoadingScreen(object sender, StateEventArgs eventArgs)
    {
      // Show the text "Loading..." centered on the screen.
      _loadingTextBlock = new TextBlock
      {
        Name = "LoadingTextBlock",    // Control names are optional - but very helpful for debugging!
        Text = "Loading...",
        HorizontalAlignment = HorizontalAlignment.Center,
        VerticalAlignment = VerticalAlignment.Center,
      };
      _uiScreen.Children.Add(_loadingTextBlock);

      // Start loading assets in the background.
      Parallel.StartBackground(LoadAssets);
    }
Пример #19
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);
        }
Пример #20
0
    private void InitializeGui()
    {
      // Add the GuiGraphicsScreen to the graphics service.
      _guiGraphicsScreen = new GuiGraphicsScreen(_services);
      _graphicsService.Screens.Add(_guiGraphicsScreen);

      // ----- Title (top left)
      _titleTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.White,
        Text = "No sample selected",
        X = 10,
        Y = 10,
      };
      _guiGraphicsScreen.UIScreen.Children.Add(_titleTextBlock);

      // ----- Info (bottom left)
      _infoPanel = new StackPanel
      {
        Margin = new Vector4F(10),
        HorizontalAlignment = HorizontalAlignment.Left,
        VerticalAlignment = VerticalAlignment.Bottom,
      };
      _guiGraphicsScreen.UIScreen.Children.Add(_infoPanel);
      _controllerTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.White,
        Text = "Controller disconnected. Press <Start> to use controller.",
      };
      _infoPanel.Children.Add(_controllerTextBlock);

#if XBOX
      _buttonsPanel = new StackPanel(); // Not used.
      var infoTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.White,
        Text = "Press <Left Stick> to show/hide help.",
      };
      _infoPanel.Children.Add(infoTextBlock);
      infoTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.White,
        Text = "Press <Back> to show/hide menu.",
      };
      _infoPanel.Children.Add(infoTextBlock);
#else
      // ----- Buttons (bottom right)
      _buttonsPanel = new StackPanel
      {
        Background = new Color(0, 0, 0, 64),
        Padding = new Vector4F(10),
        HorizontalAlignment = HorizontalAlignment.Right,
        VerticalAlignment = VerticalAlignment.Bottom,
      };
      _guiGraphicsScreen.UIScreen.Children.Add(_buttonsPanel);
      AddButton(_buttonsPanel, "Previous (PgUp)", LoadPreviousSample);
      AddButton(_buttonsPanel, "Next (PgDn)", LoadNextSample);
      AddButton(_buttonsPanel, "Menu (Esc)", ShowMenuWindow);
      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
#endif

      // ----- FPS Counter (top right)
      _fpsPanel = new StackPanel
      {
        Margin = new Vector4F(10),
        HorizontalAlignment = HorizontalAlignment.Right,
        VerticalAlignment = VerticalAlignment.Top,
      };
      _guiGraphicsScreen.UIScreen.Children.Add(_fpsPanel);
      _updateFpsTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.Yellow,
        HorizontalAlignment = HorizontalAlignment.Right,
        Text = "Update",
      };
      _fpsPanel.Children.Add(_updateFpsTextBlock);
      _drawFpsTextBlock = new TextBlock
      {
        Font = "DejaVuSans",
        Foreground = Color.Yellow,
        HorizontalAlignment = HorizontalAlignment.Right,
        Text = "Draw",
      };
      _fpsPanel.Children.Add(_drawFpsTextBlock);

      // Create windows. (Hidden at start.)
      CreateMenuWindow();
      CreateProfilerWindow();
      CreateOptionsWindow();
      CreateHelpWindow();
    }
Пример #21
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);
        }
Пример #22
0
    private void CreateProfilerWindow()
    {
      if (_profilerWindow != null)
        return;

      // Window
      //   ScrollViewer
      //     TextView

      _profilerTextBlock = new TextBlock
      {
        // Text is set in UpdateHelpText().
        Font = "Console",
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };

      var scrollViewer = new ScrollViewer
      {
        Content = _profilerTextBlock,
        HorizontalAlignment = HorizontalAlignment.Stretch,
        VerticalAlignment = VerticalAlignment.Stretch,
      };

      _profilerWindow = new Window
      {
        Name = "ProfilerWindow",
        Title = "Profile",
        Content = scrollViewer,
        X = 50,
        Y = 50,
        Width = 640,
        Height = 480,
        CanResize = true,
        HideOnClose = true,
        IsVisible = false,
      };
      _profilerWindow.Closed += OnWindowClosed;
    }
Пример #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
    //--------------------------------------------------------------
    #region Methods
    //--------------------------------------------------------------

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

      // Create TextBlock for title
      var titleTextBlockStyle = TitleTextBlockStyle;
      if (!string.IsNullOrEmpty(titleTextBlockStyle))   // No title if no style is specified.
      {
        _titleTextBlock = new TextBlock
        {
          Name = "GroupBoxTitle",
          Style = titleTextBlockStyle,
          Text = Title,
        };
        VisualChildren.Add(_titleTextBlock);

        // Connect Title with TextBlock.Text.
        var title = Properties.Get<string>(TitlePropertyId);
        var text = _titleTextBlock.Properties.Get<string>(TextBlock.TextPropertyId);
        title.Changed += text.Change;
      }
    }
Пример #25
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);
        }
      }
    }
Пример #26
0
 private static Action<float> SetTextBoxValue(TextBlock textBlock)
 {
     return x=>textBlock.Text = x.ToString();
 }
Пример #27
0
    private void CreateHelpWindow()
    {
      if (_helpWindow != null)
        return;

      // Window
      //   ScrollViewer
      //     TextBlock

      _helpTextBlock = new TextBlock(); // Text is set in UpdateHelpText().

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

      _helpWindow = new Window
      {
        Name = "HelpWindow",
        Title = "HELP",
        Content = scrollViewer,
        X = 50,
        Y = 50,
        Width = 640,
        Height = 480,
        CanResize = true,
        HideOnClose = true,
        IsVisible = false,
      };
      _helpWindow.Closed += OnWindowClosed;
    }
Пример #28
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);
    }
Пример #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
        /// <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();
        }