예제 #1
0
        /// <summary>
        /// This is called when the focus has moved to scroll the grid.
        /// </summary>
        private void Scroll()
        {
            if (scrolling)
            {
                // Without a twitch...
                //scrollOffset = grid[ focusIndex.X, focusIndex.Y ].Position;

                // Create a twitch to scroll the grid.
                TwitchManager.GetVector3    get    = delegate(Object param) { return(scrollOffset); };
                TwitchManager.SetVector3    set    = delegate(Vector3 value, Object param) { scrollOffset = value; };
                TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(get, set, grid[focusIndex.X, focusIndex.Y].Position, 0.15f, TwitchCurve.Shape.Linear, null);
                twitch.Start();
            }
        }
예제 #2
0
        public override void LayoutItems(ArrayList items)
        {
            float neededCircumference;

            // calc needed circumference
            //
            CalcLayoutInfoFromItems(out neededCircumference, out this.maxItemRadius, items, 1);

            // calc radius of the pie
            //
            float radius = neededCircumference / MathHelper.TwoPi;
            float spacingCircumference = 0.0f; // spacing between items on the circumference

            if (radius < this.maxItemRadius * 2.0f)
            {
                // radius is too small, must increase
                // this is assuming the center composed item is the same size as the other items
                radius = this.maxItemRadius * 2.0f;
                // and provide the extra spacing between items on the circumference
                float newCircumference = MathHelper.TwoPi * radius;
                spacingCircumference = (newCircumference - neededCircumference) / items.Count;
                neededCircumference  = newCircumference;
            }

            this.maxOrbit = radius;
            // layout items into position on the circumference
            //
            float headingArcLength = 0.0f;

            for (int indexItem = 0; indexItem < items.Count; indexItem++)
            {
                OrbitalSelector.ItemData itemData = items[indexItem] as OrbitalSelector.ItemData;
                IBounding  boundingItem           = itemData.item as IBounding;
                ITransform transformItem          = itemData.item as ITransform;

                // skip the first one so it is top dead center
                if (indexItem != 0)
                {
                    // update angle along arc
                    headingArcLength += boundingItem.BoundingSphere.Radius;
                }

                // create a vector to the current heading
                float   headingAngle = headingArcLength / radius;
                Vector3 heading      = new Vector3((float)(Math.Sin(headingAngle) * radius), (float)(Math.Cos(headingAngle) * radius), 0.0f);

                // set position by animations
                // transformItem.Local = Matrix.CreateTranslation(heading);
                TwitchManager.GetVector3 get = delegate(Object param)
                {
                    return(Vector3.Zero);
                };
                TwitchManager.SetVector3 set = delegate(Vector3 value, Object param)
                {
                    ITransform transformObject = param as ITransform;
                    if (transformObject != null)
                    {
                        transformObject.Local.Translation = value;
                        transformObject.Compose();
                    }
                };
                TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(
                    get,
                    set,
                    heading,
                    0.2f,
                    TwitchCurve.Shape.EaseOut,
                    transformItem);
                twitch.Play();

                // update angle along arc
                headingArcLength += boundingItem.BoundingSphere.Radius + spacingCircumference;
            }
        }
예제 #3
0
        public override void LayoutItems(ArrayList items)
        {
            float neededCircumference;
            int   rows;
            int   cols;

            // calc needed circumference
            //
            CalcLayoutInfoFromItems(out this.maxItemRadius, out rows, out cols, items);

            float itemWidth = this.maxItemRadius * 2.0f * (float)Math.Sin(Math.PI * 0.25) + 0.1f;

            this.maxOrbit            = this.maxItemRadius * (float)rows / 2.0f;
            this.maxInterItemSpacing = this.maxItemRadius * 2.0f;
            for (int indexItem = 0; indexItem < items.Count; indexItem++)
            {
                OrbitalSelector.ItemData itemData = items[indexItem] as OrbitalSelector.ItemData;
                IBounding  boundingItem           = itemData.item as IBounding;
                ITransform transformItem          = itemData.item as ITransform;

                int col = (indexItem % cols) - (cols / 2);
                int row = (indexItem / cols) - (rows / 2);

                Vector3 position = new Vector3((float)col * itemWidth, (float)row * -itemWidth, 0.0f);
                Debug.Print("[{0}][{1}] ({2,8:F},{3,8:F})", col, row, position.X, position.Y);
                this.maxOrbit = MathHelper.Max(this.maxOrbit, Math.Abs(position.X));

                // set position by animations
                // transformItem.Local = Matrix.CreateTranslation(heading);
                TwitchManager.GetVector3 get = delegate(Object param)
                {
                    return(Vector3.Zero);
                };
                TwitchManager.SetVector3 set = delegate(Vector3 value, Object param)
                {
                    ITransform transformObject = param as ITransform;
                    if (transformObject != null)
                    {
                        transformObject.Local.Translation = value;
                        transformObject.Compose();
                    }
                };
                TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(
                    get,
                    set,
                    position,
                    0.2f,
                    TwitchCurve.Shape.EaseOut,
                    transformItem);
                twitch.Play();
            }

/*
 *          // layout items into position on a grid starting top left
 *          //
 *          int ring = 1;
 *          int cols = 3; // first ring is 3x3
 *          int colEnd = (cols / 2);
 *          int col = -(colEnd);
 *          int row = -(colEnd);
 *          int colInc = 1;
 *          int rowInc = 0;
 *
 *          float itemWidth = this.maxItemRadius * 2.0f;
 *
 *          for (int indexItem = 0; indexItem < items.Count; indexItem++)
 *          {
 *              OrbitalSelector.ItemData itemData = items[indexItem] as OrbitalSelector.ItemData;
 *              IBounding boundingItem = itemData.item as IBounding;
 *              ITransform transformItem = itemData.item as ITransform;
 *
 *
 *              Vector3 position = new Vector3((float)col * itemWidth, (float)row * -itemWidth, 0.0f);
 *              Debug.Print("[{0}][{1}] ({2,8:F},{3,8:F})", col, row, position.X, position.Y);
 *
 *              col += colInc;
 *              row += rowInc;
 *              // reached right
 *              if (col > colEnd)
 *              {
 *                  col = colEnd;
 *                  colInc = 0;
 *                  rowInc = 1;
 *                  row += rowInc;
 *              }
 *              // reached bottom
 *              if (row > colEnd)
 *              {
 *                  row = colEnd;
 *                  colInc = -1;
 *                  rowInc = 0;
 *                  col += colInc;
 *              }
 *              // reached left
 *              if (col < -colEnd)
 *              {
 *                  col = -colEnd;
 *                  colInc = 0;
 *                  rowInc = -1;
 *                  row += rowInc;
 *              }
 *              // reached top
 *              if (col == -colEnd && row == -colEnd)
 *              {
 *                  cols += 2;
 *                  colEnd = (cols / 2);
 *                  col = -(colEnd);
 *                  row = -(colEnd);
 *                  colInc = 1;
 *                  rowInc = 0;
 *              }
 *
 *              // set position by animations
 *              // transformItem.Local = Matrix.CreateTranslation(heading);
 *              TwitchManager.GetVector3 get = delegate(Object param)
 *                      {
 *                          return Vector3.Zero;
 *                      };
 *              TwitchManager.SetVector3 set = delegate(Vector3 value, Object param)
 *                      {
 *                          ITransform transformObject = param as ITransform;
 *                          if (transformObject != null)
 *                          {
 *                              transformObject.Local.Translation = value;
 *                              transformObject.Compose();
 *                          }
 *                      };
 *              TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(
 *                      get,
 *                      set,
 *                      position,
 *                      0.2f,
 *                      TwitchCurve.Shape.EaseOut,
 *                      transformItem);
 *              twitch.Play();
 *          }
 *          this.maxOrbit = colEnd * itemWidth;
 */
        }
예제 #4
0
        }   // end of TexturePicker InitFileList()

        public void Update()
        {
            if (active)
            {
                GamePadInput pad = GamePadInput.GetGamePad1();

                // Switch active grid?
                bool changed = false;
                if (pad.LeftStickLeft.WasPressed || pad.DPadLeft.WasPressed)
                {
                    activeGrid = (activeGrid + 3) % 4;
                    changed    = true;
                    Foley.PlayProgrammingClick();
                }
                if (pad.LeftStickRight.WasPressed || pad.DPadRight.WasPressed)
                {
                    activeGrid = (activeGrid + 1) % 4;
                    changed    = true;
                    Foley.PlayProgrammingClick();
                }

                if (changed)
                {
                    Vector3 newPosition                = new Vector3(-2.25f + 1.5f * activeGrid, 0.0f, 0.0f);
                    TwitchManager.GetVector3    get    = delegate(Object param) { return(selectionPlate.Position); };
                    TwitchManager.SetVector3    set    = delegate(Vector3 value, Object param) { selectionPlate.Position = value; };
                    TwitchManager.Vector3Twitch twitch = new TwitchManager.Vector3Twitch(get, set, newPosition, 0.25f, TwitchCurve.Shape.OvershootOut);
                    twitch.Start();

                    grid0.Active = false;
                    grid1.Active = false;
                    grid2.Active = false;
                    grid3.Active = false;

                    switch (activeGrid)
                    {
                    case 0: grid0.Active = true; break;

                    case 1: grid1.Active = true; break;

                    case 2: grid2.Active = true; break;

                    case 3: grid3.Active = true; break;
                    }

                    changed = false;
                }

                backPlate.Update();
                selectionPlate.Update();
                grid0.Update(ref worldGrid);
                grid1.Update(ref worldGrid);
                grid2.Update(ref worldGrid);
                grid3.Update(ref worldGrid);

                // See if any of the grids have changed which texture is in focus.
                // If so, change what the terrain sees.
                if (grid0.SelectionIndex.Y != curFocusIndex0)
                {
                    curFocusIndex0 = grid0.SelectionIndex.Y;
                    InGame.inGame.Terrain.ChangeTerrainTexture(0, files[curFocusIndex0]);
                    InGame.inGame.IsLevelDirty = true;
                }
                if (grid1.SelectionIndex.Y != curFocusIndex1)
                {
                    curFocusIndex1 = grid1.SelectionIndex.Y;
                    InGame.inGame.Terrain.ChangeTerrainTexture(1, files[curFocusIndex1]);
                    InGame.inGame.IsLevelDirty = true;
                }
                if (grid2.SelectionIndex.Y != curFocusIndex2)
                {
                    curFocusIndex2 = grid2.SelectionIndex.Y;
                    InGame.inGame.Terrain.ChangeTerrainTexture(2, files[curFocusIndex2]);
                    InGame.inGame.IsLevelDirty = true;
                }
                if (grid3.SelectionIndex.Y != curFocusIndex3)
                {
                    curFocusIndex3 = grid3.SelectionIndex.Y;
                    InGame.inGame.Terrain.ChangeTerrainTexture(3, files[curFocusIndex3]);
                    InGame.inGame.IsLevelDirty = true;
                }

                float outerRowAlpha = 0.3f;
                float innerRowAlpha = 0.7f;

                // Update the alpha values of the visible tiles.
                for (int i = 0; i < grid0.ActualDimensions.Y; i++)
                {
                    UIGrid2DTextureElement e = null;

                    e = grid0.Get(0, i) as UIGrid2DTextureElement;
                    if (e != null)
                    {
                        int delta = Math.Abs(i - grid0.SelectionIndex.Y);
                        if (delta < 2)
                        {
                            e.Alpha = 1.0f;
                        }
                        else if (delta < 3)
                        {
                            e.Alpha = innerRowAlpha;
                        }
                        else
                        {
                            e.Alpha = outerRowAlpha;
                        }
                    }

                    e = grid1.Get(0, i) as UIGrid2DTextureElement;
                    if (e != null)
                    {
                        int delta = Math.Abs(i - grid1.SelectionIndex.Y);
                        if (delta < 2)
                        {
                            e.Alpha = 1.0f;
                        }
                        else if (delta < 3)
                        {
                            e.Alpha = innerRowAlpha;
                        }
                        else
                        {
                            e.Alpha = outerRowAlpha;
                        }
                    }
                    e = grid2.Get(0, i) as UIGrid2DTextureElement;
                    if (e != null)
                    {
                        int delta = Math.Abs(i - grid2.SelectionIndex.Y);
                        if (delta < 2)
                        {
                            e.Alpha = 1.0f;
                        }
                        else if (delta < 3)
                        {
                            e.Alpha = innerRowAlpha;
                        }
                        else
                        {
                            e.Alpha = outerRowAlpha;
                        }
                    }
                    e = grid3.Get(0, i) as UIGrid2DTextureElement;
                    if (e != null)
                    {
                        int delta = Math.Abs(i - grid3.SelectionIndex.Y);
                        if (delta < 2)
                        {
                            e.Alpha = 1.0f;
                        }
                        else if (delta < 3)
                        {
                            e.Alpha = innerRowAlpha;
                        }
                        else
                        {
                            e.Alpha = outerRowAlpha;
                        }
                    }
                }
            }
        }   // end of TexturePicker Update()