Example #1
0
        public static AnimatedKeyframeViewModel FromSave(NamedEventSave save)
        {
            AnimatedKeyframeViewModel toReturn = new AnimatedKeyframeViewModel();

            toReturn.EventName = save.Name;
            toReturn.Time      = save.Time;

            return(toReturn);
        }
Example #2
0
        public static AnimatedKeyframeViewModel FromSave(AnimationReferenceSave save)
        {
            AnimatedKeyframeViewModel toReturn = new AnimatedKeyframeViewModel();

            toReturn.AnimationName = save.Name;
            toReturn.Time          = save.Time;
            // There's no easing/interpolation supported for animation references

            return(toReturn);
        }
Example #3
0
        public static AnimatedKeyframeViewModel FromSave(AnimatedStateSave save)
        {
            AnimatedKeyframeViewModel toReturn = new AnimatedKeyframeViewModel();

            toReturn.StateName         = save.StateName;
            toReturn.Time              = save.Time;
            toReturn.InterpolationType = save.InterpolationType;
            toReturn.Easing            = save.Easing;

            return(toReturn);
        }
Example #4
0
        private static double GetLinearRatio(double value, AnimatedKeyframeViewModel stateVmBefore, AnimatedKeyframeViewModel stateVmAfter)
        {
            double valueBefore = stateVmBefore.Time;
            double valueAfter  = stateVmAfter.Time;

            double range  = valueAfter - valueBefore;
            double timeIn = value - valueBefore;

            double ratio = 0;

            if (valueAfter != valueBefore)
            {
                ratio = timeIn / range;
            }
            return(ratio);
        }
Example #5
0
        public static AnimationViewModel FromSave(AnimationSave save, ElementSave element, ElementAnimationsSave allAnimationSaves = null)
        {
            AnimationViewModel toReturn = new AnimationViewModel();

            toReturn.Name   = save.Name;
            toReturn.mLoops = save.Loops;
            foreach (var stateSave in save.States)
            {
                var foundState = element.AllStates.FirstOrDefault(item => item.Name == stateSave.StateName);

                var newAnimatedStateViewModel = AnimatedKeyframeViewModel.FromSave(stateSave);

                newAnimatedStateViewModel.HasValidState = foundState != null;

                toReturn.Keyframes.Add(newAnimatedStateViewModel);
            }

            foreach (var animationReference in save.Animations)
            {
                AnimationSave         animationSave        = null;
                ElementSave           subAnimationElement  = null;
                ElementAnimationsSave subAnimationSiblings = null;

                if (string.IsNullOrEmpty(animationReference.SourceObject))
                {
                    if (allAnimationSaves == null)
                    {
                        allAnimationSaves = AnimationCollectionViewModelManager.Self.GetElementAnimationsSave(element);
                    }

                    animationSave        = allAnimationSaves.Animations.FirstOrDefault(item => item.Name == animationReference.RootName);
                    subAnimationElement  = element;
                    subAnimationSiblings = allAnimationSaves;
                }
                else
                {
                    var instance = element.Instances.FirstOrDefault(item => item.Name == animationReference.SourceObject);

                    if (instance != null)
                    {
                        ElementSave instanceElement = Gum.Managers.ObjectFinder.Self.GetElementSave(instance);
                        subAnimationElement = instanceElement;

                        if (instanceElement != null)
                        {
                            var allAnimations = AnimationCollectionViewModelManager.Self.GetElementAnimationsSave(instanceElement);

                            animationSave        = allAnimations.Animations.FirstOrDefault(item => item.Name == animationReference.RootName);
                            subAnimationElement  = instanceElement;
                            subAnimationSiblings = allAnimations;
                        }
                    }
                }
                var newVm = AnimatedKeyframeViewModel.FromSave(animationReference);

                if (animationSave != null)
                {
                    newVm.SubAnimationViewModel = AnimationViewModel.FromSave(animationSave, subAnimationElement, subAnimationSiblings);
                }


                newVm.HasValidState = animationReference != null;

                toReturn.Keyframes.Add(newVm);
            }

            toReturn.SortList();

            return(toReturn);
        }
        public static AnimatedKeyframeViewModel FromSave(AnimationReferenceSave save)
        {
            AnimatedKeyframeViewModel toReturn = new AnimatedKeyframeViewModel();

            toReturn.AnimationName = save.Name;
            toReturn.Time = save.Time;
            // There's no easing/interpolation supported for animation references

            return toReturn;
        }
        public static AnimatedKeyframeViewModel FromSave(AnimatedStateSave save)
        {
            AnimatedKeyframeViewModel toReturn = new AnimatedKeyframeViewModel();

            toReturn.StateName = save.StateName;
            toReturn.Time = save.Time;
            toReturn.InterpolationType = save.InterpolationType;
            toReturn.Easing = save.Easing;

            return toReturn;
        }
Example #8
0
        private void AddStateButton_Click(object sender, RoutedEventArgs e)
        {
            if(ViewModel == null)
            {
                throw new NullReferenceException("The ViewModel for this is invalid - set the DataContext on this view before showing it.");
            }

            string whyIsntValid = GetWhyAddingTimedStateIsInvalid();

            if(!string.IsNullOrEmpty(whyIsntValid))
            {
                MessageBox.Show(whyIsntValid);

            }
            else
            {
                ListBoxMessageBox lbmb = new ListBoxMessageBox();
                lbmb.RequiresSelection = true;
                lbmb.Message = "Select a state";

                foreach (var state in SelectedState.Self.SelectedElement.AllStates)
                {
                    lbmb.Items.Add(state.Name);
                }

                var dialogResult = lbmb.ShowDialog();

                if (dialogResult.HasValue && dialogResult.Value)
                {
                    var item = lbmb.SelectedItem;

                    var newVm = new AnimatedKeyframeViewModel() { StateName = (string)item,
                        // User just selected the state, so it better be valid!
                        HasValidState = true,
                        InterpolationType = FlatRedBall.Glue.StateInterpolation.InterpolationType.Linear,
                        Easing = FlatRedBall.Glue.StateInterpolation.Easing.Out

                    };

                    if(ViewModel.SelectedAnimation.SelectedKeyframe != null)
                    {
                        // put this after the current animation
                        newVm.Time = ViewModel.SelectedAnimation.SelectedKeyframe.Time + 1f;
                    }
                    else if(ViewModel.SelectedAnimation.Keyframes.Count != 0)
                    {
                        newVm.Time = ViewModel.SelectedAnimation.Keyframes.Last().Time + 1f;
                    }

                    ViewModel.SelectedAnimation.Keyframes.Add(newVm);

                    ViewModel.SelectedAnimation.Keyframes.BubbleSort();
                }
            }
        }
Example #9
0
        private void AddSubAnimationButton_Click(object sender, RoutedEventArgs e)
        {
            SubAnimationSelectionWindow window = new SubAnimationSelectionWindow();
            var result = window.ShowDialog();

            if (result.HasValue && result.Value && window.SelectedAnimation != null)
            {
                var selectedAnimation = window.SelectedAnimation;

                AnimatedKeyframeViewModel newVm = new AnimatedKeyframeViewModel();
                if (selectedAnimation.ContainingInstance != null)
                {
                    newVm.AnimationName = selectedAnimation.ContainingInstance.Name + "." + selectedAnimation.Name;
                }
                else
                {
                    newVm.AnimationName = selectedAnimation.Name;
                }

                newVm.SubAnimationViewModel = selectedAnimation;

                newVm.HasValidState = true;

                if (ViewModel.SelectedAnimation.SelectedKeyframe != null)
                {
                    // put this after the current animation
                    newVm.Time = ViewModel.SelectedAnimation.SelectedKeyframe.Time + 1f;
                }
                else if (ViewModel.SelectedAnimation.Keyframes.Count != 0)
                {
                    newVm.Time = ViewModel.SelectedAnimation.Keyframes.Last().Time + 1f;
                }

                ViewModel.SelectedAnimation.Keyframes.Add(newVm);

                ViewModel.SelectedAnimation.Keyframes.BubbleSort();
            }
        }