<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Myre.StateManagement
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class Screen
    {
        TransitionState transitionState;

        /// <summary>
        /// Gets the <see cref="ScreenManager"/> which this screen was last pushed onto.
        /// </summary>
        /// <value>The manager.</value>
        public ScreenManager Manager { get; internal set; }

        /// <summary>
        /// Updates the screen.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public virtual void Update(GameTime gameTime)
        {
        }

        /// <summary>
        /// Draws this instance.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public virtual void Draw(GameTime gameTime)
        {
        }

        /// <summary>
        /// Prepares the draw.
        /// </summary>
        public virtual void PrepareDraw()
        {
        }

        /// <summary>
        /// Gets or sets the transition on time.
        /// </summary>
        /// <value>The transition on.</value>
        public TimeSpan TransitionOn
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the transition off time.
        /// </summary>
        /// <value>The transition off.</value>
        public TimeSpan TransitionOff
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or transition progress.
        /// 0 is hidden, and 1 is shown.
        /// </summary>
        /// <value>The transition progress.</value>
        public float TransitionProgress
        {
            get;
            internal set;
        }

        /// <summary>
        /// Gets the state of the transition.
        /// </summary>
        /// <value>The state of the transition.</value>
        public TransitionState TransitionState
        {
            get { return transitionState; }
            internal set
            {
                if (transitionState != value)
                {
                    transitionState = value;
                    if (transitionState == TransitionState.Hidden)
                        OnHidden();
                    else
                        OnShown();
                }
            }
        }

        /// <summary>
        /// Called when the screen becomes visible.
        /// </summary>
        public virtual void OnShown()
        {
        }

        /// <summary>
        /// Called when the screen becomes hidden.
        /// </summary>
        public virtual void OnHidden()
        {
        }
    }
}<commit_msg>Started screens in the Hidden state when they're constructed Updated transition events, there are now 4 - one for each state -> BeginTransitionOn   -> Used to begin transition events and probably construct some events that live as long as the screen is visible -> OnShown   -> Screen is totally visible, stop transitioning -> BeginTransitionOff   -> Begin transitioning screen off -> OnHidden   -> Screen is fully hidden, stop transitioning and dispose of any objects no longer needed This solves the bug of OnShown and OnHidden being called twice, once for each of the above 2 events<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Myre.StateManagement
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class Screen
    {
        TransitionState transitionState = TransitionState.Hidden;

        /// <summary>
        /// Gets the <see cref="ScreenManager"/> which this screen was last pushed onto.
        /// </summary>
        /// <value>The manager.</value>
        public ScreenManager Manager { get; internal set; }

        /// <summary>
        /// Updates the screen.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public virtual void Update(GameTime gameTime)
        {
        }

        /// <summary>
        /// Draws this instance.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public virtual void Draw(GameTime gameTime)
        {
        }

        /// <summary>
        /// Prepares the draw.
        /// </summary>
        public virtual void PrepareDraw()
        {
        }

        /// <summary>
        /// Gets or sets the transition on time.
        /// </summary>
        /// <value>The transition on.</value>
        public TimeSpan TransitionOn
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the transition off time.
        /// </summary>
        /// <value>The transition off.</value>
        public TimeSpan TransitionOff
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or transition progress.
        /// 0 is hidden, and 1 is shown.
        /// </summary>
        /// <value>The transition progress.</value>
        public float TransitionProgress
        {
            get;
            internal set;
        }

        /// <summary>
        /// Gets the state of the transition.
        /// </summary>
        /// <value>The state of the transition.</value>
        public TransitionState TransitionState
        {
            get { return transitionState; }
            internal set
            {
                if (transitionState == value)
                    return;

                transitionState = value;
                switch (transitionState)
                {
                    case TransitionState.Hidden:
                        OnHidden();
                        break;
                    case TransitionState.On:
                        BeginTransitionOn();
                        break;
                    case TransitionState.Off:
                        BeginTransitionOff();
                        break;
                    case TransitionState.Shown:
                        OnShown();
                        break;
                }
            }
        }

        /// <summary>
        /// Called when the screen begins transitioning on
        /// </summary>
        protected virtual void BeginTransitionOn()
        {
        }

        /// <summary>
        /// Called when the screen begins transitioning off
        /// </summary>
        protected virtual void BeginTransitionOff()
        {
        }

        /// <summary>
        /// Called when the screen state changes to visible.
        /// </summary>
        protected virtual void OnShown()
        {
        }

        /// <summary>
        /// Called when the screen state changes to hidden.
        /// </summary>
        protected virtual void OnHidden()
        {
        }
    }
}
{'fraction_non_alphanumeric': 0.10596603280592248, 'fraction_numerical': 0.0008709536942952533, 'mean_word_length': 1.2494286647078028, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6941219', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1564, 'n_words': 509}