Exemple #1
0
        private void InitializeSamples()
        {
            // Automatically find all samples using reflection. Samples are derived from
            // GameComponent and have a SampleAttribute.
#if NETFX_CORE
            _samples = GetType().GetTypeInfo()
                       .Assembly
                       .DefinedTypes
                       .Where(ti => ti.IsSubclassOf(typeof(GameComponent)) &&
                              SampleAttribute.GetSampleAttribute(ti.AsType()) != null)
                       .Select(ti => ti.AsType())
                       .ToList();
#else
            _samples = Assembly.GetCallingAssembly()
                       .GetTypes()
                       .Where(t => typeof(GameComponent).IsAssignableFrom(t) &&
                              SampleAttribute.GetSampleAttribute(t) != null)
                       .ToList();
#endif

            _samples.Sort(CompareSamples);

            if (_samples.Count == 0)
            {
                throw new Exception("No samples found.");
            }

            // Set _nextSampleIndex to immediately start a specific sample.
            _nextSampleIndex = _samples.IndexOf(_initialSample);
        }
Exemple #2
0
    private void UpdateHelp()
    {
      string name = null;
      SampleCategory category = SampleCategory.Unsorted;
      string summary = null;
      string description = null;
      if (_sample != null)
      {
        var sampleType = _sample.GetType();
        var sampleAttribute = SampleAttribute.GetSampleAttribute(sampleType);
        if (sampleAttribute != null)
        {
          name = sampleType.Name;
          category = sampleAttribute.Category;
          summary = sampleAttribute.Summary;
          description = sampleAttribute.Description;
        }
      }

      // Create help text for the sample.
      string helpText =
        "Sample: " + (string.IsNullOrEmpty(name) ? "No sample selected" : name) +
        "\nCategory: " + category +
        "\n" +
        "\nDescription:" +
        "\n--------------" +
        "\n" + (string.IsNullOrEmpty(summary) ? "-" : summary);

      if (!string.IsNullOrEmpty(description))
        helpText += "\n\n" + description;

      // General controls.
      helpText +=
        "\n\nControls:" +
        "\n-----------" +
        "\nGeneral" +
        "\n  Press <Esc> or <Back> to show menu." +
        "\n  Press <F1> or <Left Stick> to show help." +
        "\n  Press <F3> to show profiling data (and also reset the data)." +
        "\n  Press <F4> to show options." +
        "\n  Press <F7> to hide GUI." +
        "\n  Press <PageUp/Down> or <DPad Left/Right> to switch samples." +
        "\n  Press <Keyboard End> or <Left Shoulder>+<Right Shoulder> to restart sample." +
        "\n  Press <P> to pause/resume physics and particle simulation." +
        "\n  Press <T> to single step physics and particle simulation when simulation is paused.";

      // Controls of sample.
      if (_sample != null)
        foreach (var controlsAttribute in ControlsAttribute.GetControlsAttribute(_sample.GetType()))
          helpText += "\n\n" + controlsAttribute.Description;

      // Controls of game objects.
      foreach (var gameObject in _gameObjectService.Objects)
        foreach (var controlsAttribute in ControlsAttribute.GetControlsAttribute(gameObject.GetType()))
          helpText += "\n\n" + controlsAttribute.Description;

      _titleTextBlock.Text = (_sample != null) ? category + " - " + name : name;
      _helpTextBlock.Text = helpText;
    }
Exemple #3
0
    private static int CompareSamples(Type sampleA, Type sampleB)
    {
      var sampleAttributeA = SampleAttribute.GetSampleAttribute(sampleA);
      var sampleAttributeB = SampleAttribute.GetSampleAttribute(sampleB);

      // Sort by category...
      var categoryA = sampleAttributeA.Category;
      var categoryB = sampleAttributeB.Category;
      if (categoryA < categoryB)
        return -1;
      if (categoryA > categoryB)
        return +1;

      // ...then by sample order.
      int orderA = sampleAttributeA.Order;
      int orderB = sampleAttributeB.Order;
      return orderA - orderB;
    }
Exemple #4
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);
                }
            }
        }