예제 #1
0
 public FlatRedBall.Glue.StateInterpolation.Tweener InterpolateTo(Pirates.GumRuntimes.ColoredRectangleRuntime.VariableState fromState, Pirates.GumRuntimes.ColoredRectangleRuntime.VariableState toState, double secondsToTake, FlatRedBall.Glue.StateInterpolation.InterpolationType interpolationType, FlatRedBall.Glue.StateInterpolation.Easing easing, object owner = null)
 {
     FlatRedBall.Glue.StateInterpolation.Tweener tweener = new FlatRedBall.Glue.StateInterpolation.Tweener(from: 0, to: 1, duration: (float)secondsToTake, type: interpolationType, easing: easing);
     if (owner == null)
     {
         tweener.Owner = this;
     }
     else
     {
         tweener.Owner = owner;
     }
     tweener.PositionChanged = newPosition => this.InterpolateBetween(fromState, toState, newPosition);
     tweener.Start();
     StateInterpolationPlugin.TweenerManager.Self.Add(tweener);
     return(tweener);
 }
예제 #2
0
        public void InterpolateBetween(VariableState firstState, VariableState secondState, float interpolationValue)
        {
                #if DEBUG
            if (float.IsNaN(interpolationValue))
            {
                throw new System.Exception("interpolationValue cannot be NaN");
            }
                #endif
            bool  setBackgroundRectangleAlphaFirstValue   = false;
            bool  setBackgroundRectangleAlphaSecondValue  = false;
            int   BackgroundRectangleAlphaFirstValue      = 0;
            int   BackgroundRectangleAlphaSecondValue     = 0;
            bool  setBackgroundRectangleHeightFirstValue  = false;
            bool  setBackgroundRectangleHeightSecondValue = false;
            float BackgroundRectangleHeightFirstValue     = 0;
            float BackgroundRectangleHeightSecondValue    = 0;
            bool  setBackgroundRectangleCurrentVariableStateFirstValue  = false;
            bool  setBackgroundRectangleCurrentVariableStateSecondValue = false;
            Pirates.GumRuntimes.ColoredRectangleRuntime.VariableState BackgroundRectangleCurrentVariableStateFirstValue  = Pirates.GumRuntimes.ColoredRectangleRuntime.VariableState.Default;
            Pirates.GumRuntimes.ColoredRectangleRuntime.VariableState BackgroundRectangleCurrentVariableStateSecondValue = Pirates.GumRuntimes.ColoredRectangleRuntime.VariableState.Default;
            bool  setBackgroundRectangleWidthFirstValue  = false;
            bool  setBackgroundRectangleWidthSecondValue = false;
            float BackgroundRectangleWidthFirstValue     = 0;
            float BackgroundRectangleWidthSecondValue    = 0;
            bool  setBackgroundRectangleXFirstValue      = false;
            bool  setBackgroundRectangleXSecondValue     = false;
            float BackgroundRectangleXFirstValue         = 0;
            float BackgroundRectangleXSecondValue        = 0;
            bool  setBackgroundRectangleYFirstValue      = false;
            bool  setBackgroundRectangleYSecondValue     = false;
            float BackgroundRectangleYFirstValue         = 0;
            float BackgroundRectangleYSecondValue        = 0;
            bool  setHeightFirstValue            = false;
            bool  setHeightSecondValue           = false;
            float HeightFirstValue               = 0;
            float HeightSecondValue              = 0;
            bool  setItemSpriteHeightFirstValue  = false;
            bool  setItemSpriteHeightSecondValue = false;
            float ItemSpriteHeightFirstValue     = 0;
            float ItemSpriteHeightSecondValue    = 0;
            bool  setItemSpriteWidthFirstValue   = false;
            bool  setItemSpriteWidthSecondValue  = false;
            float ItemSpriteWidthFirstValue      = 0;
            float ItemSpriteWidthSecondValue     = 0;
            bool  setItemSpriteXFirstValue       = false;
            bool  setItemSpriteXSecondValue      = false;
            float ItemSpriteXFirstValue          = 0;
            float ItemSpriteXSecondValue         = 0;
            bool  setItemSpriteYFirstValue       = false;
            bool  setItemSpriteYSecondValue      = false;
            float ItemSpriteYFirstValue          = 0;
            float ItemSpriteYSecondValue         = 0;
            bool  setWidthFirstValue             = false;
            bool  setWidthSecondValue            = false;
            float WidthFirstValue  = 0;
            float WidthSecondValue = 0;
            bool  setBackgroundRectangleBlueFirstValue   = false;
            bool  setBackgroundRectangleBlueSecondValue  = false;
            int   BackgroundRectangleBlueFirstValue      = 0;
            int   BackgroundRectangleBlueSecondValue     = 0;
            bool  setBackgroundRectangleGreenFirstValue  = false;
            bool  setBackgroundRectangleGreenSecondValue = false;
            int   BackgroundRectangleGreenFirstValue     = 0;
            int   BackgroundRectangleGreenSecondValue    = 0;
            switch (firstState)
            {
            case  VariableState.Default:
                setBackgroundRectangleAlphaFirstValue  = true;
                BackgroundRectangleAlphaFirstValue     = 128;
                setBackgroundRectangleHeightFirstValue = true;
                BackgroundRectangleHeightFirstValue    = 100f;
                if (interpolationValue < 1)
                {
                    this.BackgroundRectangle.HeightUnits = Gum.DataTypes.DimensionUnitType.PercentageOfOtherDimension;
                }
                setBackgroundRectangleCurrentVariableStateFirstValue = true;
                BackgroundRectangleCurrentVariableStateFirstValue    = Pirates.GumRuntimes.ColoredRectangleRuntime.VariableState.Default;
                setBackgroundRectangleWidthFirstValue = true;
                BackgroundRectangleWidthFirstValue    = 90f;
                if (interpolationValue < 1)
                {
                    this.BackgroundRectangle.WidthUnits = Gum.DataTypes.DimensionUnitType.Percentage;
                }
                setBackgroundRectangleXFirstValue = true;
                BackgroundRectangleXFirstValue    = 5f;
                if (interpolationValue < 1)
                {
                    this.BackgroundRectangle.XUnits = Gum.Converters.GeneralUnitType.Percentage;
                }
                setBackgroundRectangleYFirstValue = true;
                BackgroundRectangleYFirstValue    = 5f;
                if (interpolationValue < 1)
                {
                    this.BackgroundRectangle.YUnits = Gum.Converters.GeneralUnitType.Percentage;
                }
                setHeightFirstValue = true;
                HeightFirstValue    = 60f;
                if (interpolationValue < 1)
                {
                    this.HeightUnits = Gum.DataTypes.DimensionUnitType.Absolute;
                }
                setItemSpriteHeightFirstValue = true;
                ItemSpriteHeightFirstValue    = 100f;
                if (interpolationValue < 1)
                {
                    this.ItemSprite.HeightUnits = Gum.DataTypes.DimensionUnitType.PercentageOfOtherDimension;
                }
                setItemSpriteWidthFirstValue = true;
                ItemSpriteWidthFirstValue    = 90f;
                if (interpolationValue < 1)
                {
                    this.ItemSprite.WidthUnits = Gum.DataTypes.DimensionUnitType.Percentage;
                }
                setItemSpriteXFirstValue = true;
                ItemSpriteXFirstValue    = 5f;
                if (interpolationValue < 1)
                {
                    this.ItemSprite.XUnits = Gum.Converters.GeneralUnitType.Percentage;
                }
                setItemSpriteYFirstValue = true;
                ItemSpriteYFirstValue    = 5f;
                if (interpolationValue < 1)
                {
                    this.ItemSprite.YUnits = Gum.Converters.GeneralUnitType.Percentage;
                }
                setWidthFirstValue = true;
                WidthFirstValue    = 60f;
                if (interpolationValue < 1)
                {
                    this.WidthUnits = Gum.DataTypes.DimensionUnitType.Absolute;
                }
                if (interpolationValue < 1)
                {
                    this.XUnits = Gum.Converters.GeneralUnitType.PixelsFromSmall;
                }
                if (interpolationValue < 1)
                {
                    this.YUnits = Gum.Converters.GeneralUnitType.PixelsFromSmall;
                }
                break;

            case  VariableState.Selected:
                setBackgroundRectangleAlphaFirstValue = true;
                BackgroundRectangleAlphaFirstValue    = 255;
                setBackgroundRectangleBlueFirstValue  = true;
                BackgroundRectangleBlueFirstValue     = 0;
                setBackgroundRectangleGreenFirstValue = true;
                BackgroundRectangleGreenFirstValue    = 0;
                break;
            }
            switch (secondState)
            {
            case  VariableState.Default:
                setBackgroundRectangleAlphaSecondValue  = true;
                BackgroundRectangleAlphaSecondValue     = 128;
                setBackgroundRectangleHeightSecondValue = true;
                BackgroundRectangleHeightSecondValue    = 100f;
                if (interpolationValue >= 1)
                {
                    this.BackgroundRectangle.HeightUnits = Gum.DataTypes.DimensionUnitType.PercentageOfOtherDimension;
                }
                setBackgroundRectangleCurrentVariableStateSecondValue = true;
                BackgroundRectangleCurrentVariableStateSecondValue    = Pirates.GumRuntimes.ColoredRectangleRuntime.VariableState.Default;
                setBackgroundRectangleWidthSecondValue = true;
                BackgroundRectangleWidthSecondValue    = 90f;
                if (interpolationValue >= 1)
                {
                    this.BackgroundRectangle.WidthUnits = Gum.DataTypes.DimensionUnitType.Percentage;
                }
                setBackgroundRectangleXSecondValue = true;
                BackgroundRectangleXSecondValue    = 5f;
                if (interpolationValue >= 1)
                {
                    this.BackgroundRectangle.XUnits = Gum.Converters.GeneralUnitType.Percentage;
                }
                setBackgroundRectangleYSecondValue = true;
                BackgroundRectangleYSecondValue    = 5f;
                if (interpolationValue >= 1)
                {
                    this.BackgroundRectangle.YUnits = Gum.Converters.GeneralUnitType.Percentage;
                }
                setHeightSecondValue = true;
                HeightSecondValue    = 60f;
                if (interpolationValue >= 1)
                {
                    this.HeightUnits = Gum.DataTypes.DimensionUnitType.Absolute;
                }
                setItemSpriteHeightSecondValue = true;
                ItemSpriteHeightSecondValue    = 100f;
                if (interpolationValue >= 1)
                {
                    this.ItemSprite.HeightUnits = Gum.DataTypes.DimensionUnitType.PercentageOfOtherDimension;
                }
                setItemSpriteWidthSecondValue = true;
                ItemSpriteWidthSecondValue    = 90f;
                if (interpolationValue >= 1)
                {
                    this.ItemSprite.WidthUnits = Gum.DataTypes.DimensionUnitType.Percentage;
                }
                setItemSpriteXSecondValue = true;
                ItemSpriteXSecondValue    = 5f;
                if (interpolationValue >= 1)
                {
                    this.ItemSprite.XUnits = Gum.Converters.GeneralUnitType.Percentage;
                }
                setItemSpriteYSecondValue = true;
                ItemSpriteYSecondValue    = 5f;
                if (interpolationValue >= 1)
                {
                    this.ItemSprite.YUnits = Gum.Converters.GeneralUnitType.Percentage;
                }
                setWidthSecondValue = true;
                WidthSecondValue    = 60f;
                if (interpolationValue >= 1)
                {
                    this.WidthUnits = Gum.DataTypes.DimensionUnitType.Absolute;
                }
                if (interpolationValue >= 1)
                {
                    this.XUnits = Gum.Converters.GeneralUnitType.PixelsFromSmall;
                }
                if (interpolationValue >= 1)
                {
                    this.YUnits = Gum.Converters.GeneralUnitType.PixelsFromSmall;
                }
                break;

            case  VariableState.Selected:
                setBackgroundRectangleAlphaSecondValue = true;
                BackgroundRectangleAlphaSecondValue    = 255;
                setBackgroundRectangleBlueSecondValue  = true;
                BackgroundRectangleBlueSecondValue     = 0;
                setBackgroundRectangleGreenSecondValue = true;
                BackgroundRectangleGreenSecondValue    = 0;
                break;
            }
            if (setBackgroundRectangleAlphaFirstValue && setBackgroundRectangleAlphaSecondValue)
            {
                BackgroundRectangle.Alpha = FlatRedBall.Math.MathFunctions.RoundToInt(BackgroundRectangleAlphaFirstValue * (1 - interpolationValue) + BackgroundRectangleAlphaSecondValue * interpolationValue);
            }
            if (setBackgroundRectangleHeightFirstValue && setBackgroundRectangleHeightSecondValue)
            {
                BackgroundRectangle.Height = BackgroundRectangleHeightFirstValue * (1 - interpolationValue) + BackgroundRectangleHeightSecondValue * interpolationValue;
            }
            if (setBackgroundRectangleCurrentVariableStateFirstValue && setBackgroundRectangleCurrentVariableStateSecondValue)
            {
                BackgroundRectangle.InterpolateBetween(BackgroundRectangleCurrentVariableStateFirstValue, BackgroundRectangleCurrentVariableStateSecondValue, interpolationValue);
            }
            if (setBackgroundRectangleWidthFirstValue && setBackgroundRectangleWidthSecondValue)
            {
                BackgroundRectangle.Width = BackgroundRectangleWidthFirstValue * (1 - interpolationValue) + BackgroundRectangleWidthSecondValue * interpolationValue;
            }
            if (setBackgroundRectangleXFirstValue && setBackgroundRectangleXSecondValue)
            {
                BackgroundRectangle.X = BackgroundRectangleXFirstValue * (1 - interpolationValue) + BackgroundRectangleXSecondValue * interpolationValue;
            }
            if (setBackgroundRectangleYFirstValue && setBackgroundRectangleYSecondValue)
            {
                BackgroundRectangle.Y = BackgroundRectangleYFirstValue * (1 - interpolationValue) + BackgroundRectangleYSecondValue * interpolationValue;
            }
            if (setHeightFirstValue && setHeightSecondValue)
            {
                Height = HeightFirstValue * (1 - interpolationValue) + HeightSecondValue * interpolationValue;
            }
            if (setItemSpriteHeightFirstValue && setItemSpriteHeightSecondValue)
            {
                ItemSprite.Height = ItemSpriteHeightFirstValue * (1 - interpolationValue) + ItemSpriteHeightSecondValue * interpolationValue;
            }
            if (setItemSpriteWidthFirstValue && setItemSpriteWidthSecondValue)
            {
                ItemSprite.Width = ItemSpriteWidthFirstValue * (1 - interpolationValue) + ItemSpriteWidthSecondValue * interpolationValue;
            }
            if (setItemSpriteXFirstValue && setItemSpriteXSecondValue)
            {
                ItemSprite.X = ItemSpriteXFirstValue * (1 - interpolationValue) + ItemSpriteXSecondValue * interpolationValue;
            }
            if (setItemSpriteYFirstValue && setItemSpriteYSecondValue)
            {
                ItemSprite.Y = ItemSpriteYFirstValue * (1 - interpolationValue) + ItemSpriteYSecondValue * interpolationValue;
            }
            if (setWidthFirstValue && setWidthSecondValue)
            {
                Width = WidthFirstValue * (1 - interpolationValue) + WidthSecondValue * interpolationValue;
            }
            if (setBackgroundRectangleBlueFirstValue && setBackgroundRectangleBlueSecondValue)
            {
                BackgroundRectangle.Blue = FlatRedBall.Math.MathFunctions.RoundToInt(BackgroundRectangleBlueFirstValue * (1 - interpolationValue) + BackgroundRectangleBlueSecondValue * interpolationValue);
            }
            if (setBackgroundRectangleGreenFirstValue && setBackgroundRectangleGreenSecondValue)
            {
                BackgroundRectangle.Green = FlatRedBall.Math.MathFunctions.RoundToInt(BackgroundRectangleGreenFirstValue * (1 - interpolationValue) + BackgroundRectangleGreenSecondValue * interpolationValue);
            }
            if (interpolationValue < 1)
            {
                mCurrentVariableState = firstState;
            }
            else
            {
                mCurrentVariableState = secondState;
            }
        }