Ejemplo n.º 1
0
        public WeatherDisplay(Vector2 position)
        {
            weatherList             = new List <WeatherMetadata>();
            displayingWeatherList   = new List <WeatherMetadata>();
            incomingWeatherPointers = new Queue <IncomingWeatherPointer>();

            currentWeatherFrame        = new Sprite("Interface/InGame/HUD/Blue/WeatherDisplay/Frame", position: position, layerDepth: DepthParameter.HUDForeground);
            currentWeatherFrameContent = new Sprite("Interface/InGame/HUD/Blue/WeatherDisplay/Weather", position: position, layerDepth: 0.99f)
            {
                Pivot = new Vector2(12, 11),
            };
            currentWeatherFrameContent.SetTransparency(0);

            weatherRouletteColored   = new Sprite(24 * 7, 22, position: position, layerDepth: 0.99f);
            weatherRouletteGrayscale = new Sprite(24 * 7, 22, position: position, layerDepth: 0.98f);

            weatherRouletteColored.SourceRectangle = weatherRouletteGrayscale.SourceRectangle = weatherRouletteRectangle = new Rectangle(0, 0, 24 * 5 - 2, 22);
            weatherRouletteColored.Pivot           = weatherRouletteGrayscale.Pivot = new Vector2(36, 11);

            weatherTexture = AssetHandler.Instance.RequestTexture("Interface/InGame/HUD/Blue/WeatherDisplay/Weather");
            animationState = WeatherDisplayAnimationState.Idle;
        }
Ejemplo n.º 2
0
        private void UpdateAnimation(GameTime gameTime)
        {
            switch (animationState)
            {
            //First step, change the color of the grayscale layer from 0 - 1
            case WeatherDisplayAnimationState.ColorFadeIn:
                colorFadeAnimationTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                weatherRouletteColored.SetTransparency(colorFadeAnimationTime);
                if (colorFadeAnimationTime > 1)
                {
                    animationState = WeatherDisplayAnimationState.Moving;
                    currentWeatherFrameContent.SetTransparency(0);
                }
                break;

            //Second step, while there is weather, shift to the left
            case WeatherDisplayAnimationState.Moving:
                float tmpOffset = currentOffset;

                movingAnimationTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                currentOffset        = (float)(24 * (1 + Math.Cos(movingAnimationTime * 2 * MathHelper.Pi)) / 2);

                if (tmpOffset < currentOffset)
                {
                    currentOffset       = 0;
                    movingAnimationTime = 0;

                    if (weatherList.Count != 0)
                    {
                        animationState = WeatherDisplayAnimationState.Idle;
                    }
                    else
                    {
                        animationState         = WeatherDisplayAnimationState.ColorFadeOut;
                        colorFadeAnimationTime = 1;
                    }
                }

                weatherRouletteColored.SourceRectangle       =
                    weatherRouletteGrayscale.SourceRectangle =
                        new Rectangle((int)(weatherRouletteRectangle.X + 24 - currentOffset), weatherRouletteRectangle.Y, weatherRouletteRectangle.Width, weatherRouletteRectangle.Height);
                break;

            //Third step, change back the color of the grayscale mask from 1 to 0.
            case WeatherDisplayAnimationState.ColorFadeOut:
                if (displayingWeatherList.Count >= 4)
                {
                    currentWeatherFrameContent.SourceRectangle = WeatherIconPresets[ActiveWeather.Weather];
                }

                currentWeatherFrameContent.SetTransparency(1);
                colorFadeAnimationTime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                weatherRouletteColored.SetTransparency(colorFadeAnimationTime);
                if (colorFadeAnimationTime < 0)
                {
                    animationState = WeatherDisplayAnimationState.Idle;
                }
                break;

            //Forth and last step. Keep waiting for a new element on WeatherList to re-start the animation sequence
            default:
                if (weatherList.Count == 0)
                {
                    return;
                }

                AppendWeather();

                if (weatherRouletteColored.Color.A > 0)
                {
                    animationState = WeatherDisplayAnimationState.Moving;
                }
                else
                {
                    animationState = WeatherDisplayAnimationState.ColorFadeIn;
                }
                return;
            }
        }