Exemplo n.º 1
0
        private void CommitCurrentState()
        {
            var nextTransition  = _playStateTransition ? GetTransition(_currentState, _requestedCurrentState) : null;
            var commonBaseState = FindCommonBaseState(_currentState, _requestedCurrentState);
// ReSharper disable once UnusedVariable.Compiler
            StateChangeEvent e;
            var oldState = _currentState ?? string.Empty;
// ReSharper disable once UnusedVariable
            var destination = GetState(_requestedCurrentState, true);

            // Stop any transition that may still be playing
// ReSharper disable once UnusedVariable.Compiler
            float prevTransitionFraction;

            if (null != _currentTransition)
            {
                /*if (_currentTransition.AutoReverse &&
                 *  transitionFromState == _requestedCurrentState &&
                 *  transitionToState == _currentState)
                 * {
                 *  if (_currentTransition.Effect.Duration == 0)
                 *      prevTransitionFraction = 0;
                 *  else
                 *      prevTransitionFraction =
                 *          _currentTransition.Effect.playheadTime /
                 *          getTotalDuration(_currentTransition.Effect);
                 * }
                 * _currentTransition.Effect.end();*/
            }

            // Initialize the state we are going to.
            InitializeState(_requestedCurrentState);

            // Capture transition start values

            /*if (null != nextTransition)
             *  nextTransition.Effect.captureStartValues();*/

            // Dispatch currentStateChanging event
            if (HasEventListener(StateChangeEvent.CURRENT_STATE_CHANGING))
            {
                StateChangeEvent sce = new StateChangeEvent(StateChangeEvent.CURRENT_STATE_CHANGING)
                {
                    OldState = oldState,
                    NewState = _requestedCurrentState ?? ""
                };
                DispatchEvent(sce);
            }

            // If we're leaving the base state, send an exitState event
            if (IsBaseState(_currentState) && HasEventListener(FrameworkEvent.EXIT_STATE))
            {
                DispatchEvent(new FrameworkEvent(FrameworkEvent.EXIT_STATE));
            }

            // Remove the existing state
            RemoveState(_currentState, commonBaseState);
            _currentState = _requestedCurrentState;

            // Check for state specific styles
            StateChanged(oldState, _currentState, true);

            // If we're going back to the base state, dispatch an
            // enter state event, otherwise apply the state.
            if (IsBaseState(CurrentState))
            {
                if (HasEventListener(FrameworkEvent.ENTER_STATE))
                {
                    DispatchEvent(new FrameworkEvent(FrameworkEvent.ENTER_STATE));
                }
            }
            else
            {
                ApplyState(_currentState, commonBaseState);
            }

            // Dispatch currentStateChange
            if (HasEventListener(StateChangeEvent.CURRENT_STATE_CHANGE))
            {
                StateChangeEvent sce = new StateChangeEvent(StateChangeEvent.CURRENT_STATE_CHANGE)
                {
                    OldState = oldState,
                    NewState = _currentState ?? string.Empty
                };
                DispatchEvent(sce);
            }

            if (null != nextTransition)
            {
                // Force a validation before playing the transition effect
                InvalidationManager.Instance.ValidateNow();
                _currentTransition   = nextTransition;
                _transitionFromState = oldState;
                _transitionToState   = _currentState;

                /*nextTransition.Effect.addEventListener(EffectEvent.EFFECT_END,
                 *  transition_effectEndHandler);
                 * nextTransition.effect.play();
                 * if (null != prevTransitionFractionion &&
                 *  nextTransition.Effect.duration != 0)
                 *  nextTransition.Effect.playheadTime = (1 - prevTransitionFraction) *
                 *      getTotalDuration(nextTransition.Effect);*/
            }
        }
Exemplo n.º 2
0
        private void CommitCurrentState()
        {
            var nextTransition = _playStateTransition ? GetTransition(_currentState, _requestedCurrentState) : null;
            var commonBaseState = FindCommonBaseState(_currentState, _requestedCurrentState);
// ReSharper disable once UnusedVariable.Compiler
            StateChangeEvent e;
            var oldState = _currentState ?? string.Empty;
// ReSharper disable once UnusedVariable
            var destination = GetState(_requestedCurrentState, true);

            // Stop any transition that may still be playing
// ReSharper disable once UnusedVariable.Compiler
            float prevTransitionFraction;
            if (null != _currentTransition)
            {
                /*if (_currentTransition.AutoReverse &&
                    transitionFromState == _requestedCurrentState &&
                    transitionToState == _currentState)
                {
                    if (_currentTransition.Effect.Duration == 0)
                        prevTransitionFraction = 0;
                    else
                        prevTransitionFraction = 
                            _currentTransition.Effect.playheadTime /
                            getTotalDuration(_currentTransition.Effect);
                }
                _currentTransition.Effect.end();*/
            }

            // Initialize the state we are going to.
            InitializeState(_requestedCurrentState);

            // Capture transition start values
            /*if (null != nextTransition)
                nextTransition.Effect.captureStartValues();*/

            // Dispatch currentStateChanging event
            if (HasEventListener(StateChangeEvent.CURRENT_STATE_CHANGING)) 
            {
                StateChangeEvent sce = new StateChangeEvent(StateChangeEvent.CURRENT_STATE_CHANGING)
                {
                    OldState = oldState,
                    NewState = _requestedCurrentState ?? ""
                };
                DispatchEvent(sce);
            }
        
            // If we're leaving the base state, send an exitState event
            if (IsBaseState(_currentState) && HasEventListener(FrameworkEvent.EXIT_STATE))
                DispatchEvent(new FrameworkEvent(FrameworkEvent.EXIT_STATE));

            // Remove the existing state
            RemoveState(_currentState, commonBaseState);
            _currentState = _requestedCurrentState;

            // Check for state specific styles
            StateChanged(oldState, _currentState, true);

            // If we're going back to the base state, dispatch an
            // enter state event, otherwise apply the state.
            if (IsBaseState(CurrentState)) 
            {
                if (HasEventListener(FrameworkEvent.ENTER_STATE))
                    DispatchEvent(new FrameworkEvent(FrameworkEvent.ENTER_STATE)); 
            }
            else
                ApplyState(_currentState, commonBaseState);

            // Dispatch currentStateChange
            if (HasEventListener(StateChangeEvent.CURRENT_STATE_CHANGE))
            {
                StateChangeEvent sce = new StateChangeEvent(StateChangeEvent.CURRENT_STATE_CHANGE)
                {
                    OldState = oldState,
                    NewState = _currentState ?? string.Empty
                };
                DispatchEvent(sce);
            }
        
            if (null != nextTransition)
            {
                // Force a validation before playing the transition effect
                InvalidationManager.Instance.ValidateNow();
                _currentTransition = nextTransition;
                _transitionFromState = oldState;
                _transitionToState = _currentState;
                /*nextTransition.Effect.addEventListener(EffectEvent.EFFECT_END, 
                    transition_effectEndHandler);
                nextTransition.effect.play();
                if (null != prevTransitionFractionion && 
                    nextTransition.Effect.duration != 0)
                    nextTransition.Effect.playheadTime = (1 - prevTransitionFraction) * 
                        getTotalDuration(nextTransition.Effect);*/
            }
        }