Example #1
0
        /// <summary>
        /// Creates the visual elements of the game and adds them to game Components.
        /// </summary>
        private void PopulateGame()
        {
            int drawOrder = 0;

            // Create the background Canvas and add it to game Components
            meshCanvas = new MeshCanvas(
                this,
                controller,
                @"Content\ApplicationBackground.jpg",
                graphics.PreferredBackBufferWidth * 2,
                graphics.PreferredBackBufferHeight * 2);
            meshCanvas.Name = "meshCanvas";
            meshCanvas.DrawOrder = drawOrder++;
            meshCanvas.AutoScaleTexture = false;
            meshCanvas.SpriteBlendState = BlendState.NonPremultiplied;

            Components.Add(meshCanvas);

            // Created the UIElement that encapsulates the cloth simulation component.
            textiles = new Textiles(this, controller);

            // Once we created the textiles, we can enable the tap gesture.
            touchTarget.TouchTapGesture += OnTouchTapGesture;

            textiles.DrawOrder = drawOrder++;

            // Create the HUD Container and add it to game Components
            hudContainer = new UIContainer(
                this,
                controller,
                @"Content\Transparent256x256.png",
                null,
                256,
                256,
                null);
            hudContainer.Name = "hudContainer";
            hudContainer.Center = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f,
                                    graphics.GraphicsDevice.Viewport.Height / 2f);
            hudContainer.DrawOrder = drawOrder++;
            hudContainer.LayerDepth = 1.0f;
            hudContainer.SpriteBlendState = BlendState.NonPremultiplied;
            hudContainer.Active = false;

            Components.Add(hudContainer);

            // Create and position listbox and add it to the hudCanvas.
            Vector2 position = new Vector2(0f, 0f);
            listbox = new UI.ListBox(
                hudContainer,
                position,
                3 * UI.ListBox.ItemWidth,
                UI.ListBox.ItemHeight,
                textiles);
            listbox.Name = "listbox";
            listbox.AutoScaleTexture = false;
        }
Example #2
0
        /// <summary>
        /// Create a ListBoxItem with the specified parameters.
        /// </summary>
        /// <param name="icon">Icon texture for this item.</param>
        /// <param name="theme">Textile theme represented by this item.</param>
        /// <param name="horizontalSize">Item's horizontal size as a fraction of the listbox viewport width.</param>
        /// <param name="verticalSize">Item's vertical size as a fraction of the listbox viewport height./param>
        public ListBoxItem(Texture2D icon, Textiles.Theme theme, float horizontalSize, float verticalSize)
            : base(null, horizontalSize, verticalSize)
        {
            Icon = icon;
            Theme = theme;
            viewState = ViewStates.Minimized;

            // Default animations steps based on the default Game.TargetElapsedType of 1/60 of a second.
            animationSteps = Convert.ToInt32(animationDuration/targetElapsedMilliSeconds);

            scaleStep = new Vector2((float)(maxItemWidth - minItemWidth)/maxItemWidth ,
                                    (float)(maxItemHeight - minItemHeight)/maxItemHeight);

            scaleStep /= (float) animationSteps;
        }
 /// <summary>
 /// Creates a TextilesStatemachine.
 /// </summary>
 /// <param name="controller">The UIController for this state machine.</param>
 /// <param name="textiles">The UIElement encapsulating this state machine.</param>
 public TextilesStateMachine(UIController controller, Textiles textiles)
     : base(controller, 0, 0)
 {
     this.textiles = textiles;
 }
Example #4
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (disposing)
                {
                    IDisposable graphicsDispose = graphics as IDisposable;
                    if (graphicsDispose != null)
                    {
                        graphicsDispose.Dispose();
                    }

                    if (touchTarget != null)
                    {
                        touchTarget.Dispose();
                        touchTarget = null;
                    }
                    if (textiles != null)
                    {
                        textiles.Dispose();
                        textiles = null;
                    }
                    if (hudContainer != null)
                    {
                        hudContainer.Dispose();
                        hudContainer = null;
                    }
                    if (listbox != null)
                    {
                        listbox.Dispose();
                        listbox = null;
                    }
                    if (meshCanvas != null)
                    {
                        meshCanvas.Dispose();
                        meshCanvas = null;
                    }
                }
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Example #5
0
        /// <summary>
        /// Creates a Listbox UIElement that may or may not have a parent UIElement.
        /// </summary>
        /// <param name="game">XNA Game that contains this ListBox</param>
        /// <param name="contoller">UIController to associate with the ListBoxStateMachine.</param>
        /// <param name="x">X-coordinate of elements position (relative or screen).</param>
        /// <param name="y">Y-coordinate of elements position (relative or screen).</param>
        /// <param name="width">Width of the ListBox in pixels.</param>
        /// <param name="height">Height of the ListBox in pixels.</param>
        /// <param name="parent">UIElement that contains the Listbox.</param>
        /// <param name="textiles">Textiles UIElement controlled by this list box</param>
        public ListBox(Game game, UIController contoller, float x, float y, int width, int height,
                       UIElement parent, Textiles textiles)
            : base(game, contoller, new Vector2(x, y), width, height, parent)
        {
            listBoxStateMachine = new ListBoxStateMachine(Controller, (int)width, (int)height)
                                      {
                                          SelectionMode = SelectionMode.Single,
                                          Orientation = Orientation.Horizontal,
                                          HorizontalElasticity = 0.0f,
                                          VerticalElasticity = 0.0f,
                                          HorizontalViewportSize = 1f,
                                          VerticalViewportSize = 1f,
                                      };

            StateMachine = listBoxStateMachine;
            StateMachine.Tag = this;

            this.textiles = textiles;

            listBoxStateMachine.ItemStateChanged += OnItemStateChanged;

            iconScale = new Vector2((float)iconWidth / itemWidth, (float)iconHeight / itemHeight);

            UIContainer container = parent as UIContainer;
            if (container != null)
            {
                // Create the scrollbar and position it below the listbox.
                int offset = Convert.ToInt32(Top - parent.Top + Height);
                Vector2 position = UIElement.CenterHorizontal(offset, scrollBarBackgroundHeight, container);

                ScrollBar = new ScrollBar(parent, position, width, listBoxStateMachine,
                                          listBoxStateMachine.HorizontalScrollBarStateMachine);

                // Create the Maximze/Minimize button and position it above the listbox.
                offset = Convert.ToInt32(Top - parent.Top - buttonHeight);
                position = UIElement.CenterHorizontal(offset, (float) buttonHeight, Parent);
                minMaxButton = new Button(parent, position, buttonWidth, buttonHeight);
                minMaxButton.Name = "button";
                minMaxButton.AutoScaleTexture = false;
            }
            else
            {
                throw new InvalidOperationException(Properties.Resources.ListBoxShouldBeInUIContainer);
            }
        }
Example #6
0
 /// <summary>
 /// Create a ListBox UIElement contained within another UIElement
 /// </summary>
 /// <param name="parent">UIElement that contains the Listbox (required).</param>
 /// <param name="position">Position relative to parent's center (-0.5f .. 0.5f) </param>
 /// <param name="width">Width of the ListBox in pixels.</param>
 /// <param name="height">Height of the ListBox in pixels.</param>
 /// <param name="textiles">Textiles UIElement controlled by this list box</param>
 public ListBox(UIElement parent, Vector2 position, int width, int height, Textiles textiles)
     : this(parent.Game, parent.Controller, position.X, position.Y, width, height, parent, textiles)
 {
     // Empty.
 }