示例#1
0
        private void HandleViewAnimationsClick(object sender, EventArgs e)
        {
            if (mMainWindow == null || mMainWindow.IsVisible == false)
            {
                SettingsManager.Self.LoadOrCreateSettings();

                mMainWindow = new StateAnimationPlugin.Views.MainWindow();

                var settings = SettingsManager.Self.GlobalSettings;

                mMainWindow.FirstRowWidth  = new GridLength((double)settings.FirstToSecondColumnRatio, GridUnitType.Star);
                mMainWindow.SecondRowWidth = new GridLength(1, GridUnitType.Star);
                // This fixes an issue where embedded wpf text boxes don't get input, as explained here:
                // http://stackoverflow.com/questions/835878/wpf-textbox-not-accepting-input-when-in-elementhost-in-window-forms
                //ElementHost.EnableModelessKeyboardInterop(mMainWindow);
                //mMainWindow.Show();
                //mMainWindow.Closed += (not, used) => Gum.ToolStates.SelectedState.Self.CustomCurrentStateSave = null;
                mMainWindow.AddStateKeyframeClicked += HandleAddStateKeyframe;
                mMainWindow.AnimationColumnsResized += HandleAnimationColumnsResized;
            }

            GumCommands.Self.GuiCommands.AddControl(mMainWindow, "Animations",
                                                    TabLocation.RightBottom);

            GumCommands.Self.GuiCommands.ShowControl(mMainWindow);

            // forces a refresh:
            mCurrentViewModel = new ElementAnimationsViewModel();

            RefreshViewModel();
        }
示例#2
0
        private void CreateViewModel()
        {
            ElementSave currentlyReferencedElement = null;

            if (mCurrentViewModel != null)
            {
                currentlyReferencedElement = mCurrentViewModel.Element;
            }

            if (currentlyReferencedElement != SelectedState.Self.SelectedElement)
            {
                mCurrentViewModel = AnimationCollectionViewModelManager.Self.CurrentAnimationCollectionViewModel;

                if (mCurrentViewModel != null)
                {
                    mCurrentViewModel.PropertyChanged += HandlePropertyChanged;
                    mCurrentViewModel.AnyChange       += HandleDataChange;

                    foreach (var item in mCurrentViewModel.Animations)
                    {
                        foreach (var keyframe in item.Keyframes)
                        {
                            keyframe.AvailableStates  = this.AvailableStates;
                            keyframe.PropertyChanged += HandleAnimatedKeyframePropertyChanged;
                        }
                    }
                }
            }
        }
示例#3
0
        public void HandleRename(ElementSave elementSave, string oldName, ElementAnimationsViewModel viewModel)
        {
            // save the new:
            bool succeeded = false;

            try
            {
                AnimationCollectionViewModelManager.Self.Save(viewModel);
                succeeded = true;
            }
            catch
            {
                succeeded = false;
            }

            if (succeeded)
            {
                var oldFileName = AnimationCollectionViewModelManager.Self.GetAbsoluteAnimationFileNameFor(oldName);

                if (System.IO.File.Exists(oldFileName))
                {
                    System.IO.File.Delete(oldFileName);
                }
            }
        }
示例#4
0
        private void RefreshViewModel()
        {
            ElementSave currentlyReferencedElement = null;

            if (mCurrentViewModel != null)
            {
                currentlyReferencedElement = mCurrentViewModel.Element;
            }

            if (currentlyReferencedElement != SelectedState.Self.SelectedElement)
            {
                mCurrentViewModel = AnimationCollectionViewModelManager.Self.CurrentAnimationCollectionViewModel;



                if (mCurrentViewModel != null)
                {
                    mCurrentViewModel.PropertyChanged += HandlePropertyChanged;
                    mCurrentViewModel.AnyChange       += HandleDataChange;
                }
            }
            if (mMainWindow != null)
            {
                mMainWindow.DataContext = mCurrentViewModel;
            }
        }
示例#5
0
文件: MainPlugin.cs 项目: derKosi/Gum
        private void HandleViewAnimationsClick(object sender, EventArgs e)
        {
            if (SelectedState.Self.SelectedScreen == null && SelectedState.Self.SelectedElement == null)
            {
                MessageBox.Show("You need to select a Screen or Component first");
            }
            else
            {
                if (mMainWindow == null || mMainWindow.IsVisible == false)
                {
                    mMainWindow = new MainWindow();
                    // This fixes an issue where embedded wpf text boxes don't get input, as explained here:
                    // http://stackoverflow.com/questions/835878/wpf-textbox-not-accepting-input-when-in-elementhost-in-window-forms
                    ElementHost.EnableModelessKeyboardInterop(mMainWindow);
                    mMainWindow.Show();
                }
                else
                {
                    mMainWindow.Focus();
                }

                // forces a refresh:
                mCurrentViewModel = new ElementAnimationsViewModel();

                RefreshViewModel();
            }
        }
        public void Save(ElementAnimationsViewModel viewModel)
        {
            var currentElement = SelectedState.Self.SelectedElement;

            var fileName = GetAbsoluteAnimationFileNameFor(currentElement);

            var save = viewModel.ToSave();

            FileManager.XmlSerialize(save, fileName);
        }
示例#7
0
 public void HandleRename(StateSaveCategory category, string oldName, ElementAnimationsViewModel viewModel)
 {
     foreach (var animation in viewModel.Animations)
     {
         foreach (var keyframe in animation.Keyframes)
         {
             if (keyframe.StateName != null && keyframe.StateName.StartsWith(oldName + "/"))
             {
                 keyframe.StateName = category.Name + "/" + FileManager.RemovePath(keyframe.StateName);
             }
         }
     }
 }
示例#8
0
 public void HandleRename(StateSave stateSave, string oldName, ElementAnimationsViewModel viewModel)
 {
     foreach (var animation in viewModel.Animations)
     {
         foreach (var keyframe in animation.Keyframes)
         {
             if (keyframe.StateName == oldName)
             {
                 keyframe.StateName = stateSave.Name;
             }
         }
     }
 }
示例#9
0
        public void HandleRename(ElementSave elementSave, string oldName, ElementAnimationsViewModel viewModel)
        {
            if (elementSave == viewModel?.Element)
            {
                // save the new:
                bool succeeded = false;
                try
                {
                    AnimationCollectionViewModelManager.Self.Save(viewModel);
                    succeeded = true;
                }
                catch
                {
                    succeeded = false;
                }

                if (succeeded)
                {
                    var oldFileName = AnimationCollectionViewModelManager.Self.GetAbsoluteAnimationFileNameFor(oldName);

                    if (System.IO.File.Exists(oldFileName))
                    {
                        System.IO.File.Delete(oldFileName);
                    }
                }
            }
            else // renaming an element that is not currently selected. See if it has an animation, and if so move it
            {
                var projectDirectory = FileManager.GetDirectory(ProjectManager.Self.GumProjectSave.FullFileName);

                var oldFile = new FilePath(projectDirectory + elementSave.Subfolder + "/" + oldName + "Animations.ganx");

                if (oldFile.Exists())
                {
                    var newFile = new FilePath(projectDirectory + elementSave.Subfolder + "/" + elementSave.Name + "Animations.ganx");

                    var newDirectory = newFile.GetDirectoryContainingThis();

                    if (System.IO.Directory.Exists(newDirectory.FullPath) == false)
                    {
                        System.IO.Directory.CreateDirectory(newDirectory.FullPath);
                    }

                    System.IO.File.Move(oldFile.FullPath, newFile.FullPath);
                }
            }
        }
示例#10
0
        public void HandleRename(InstanceSave instanceSave, string oldName, ElementAnimationsViewModel viewModel)
        {
            var whatToLookFor = $"{oldName}.";

            foreach (var animation in viewModel.Animations)
            {
                foreach (var keyframe in animation.Keyframes)
                {
                    if (keyframe.AnimationName != null && keyframe.AnimationName.StartsWith(whatToLookFor))
                    {
                        var variable =
                            keyframe.AnimationName.Substring(whatToLookFor.Length);

                        keyframe.AnimationName =
                            instanceSave.Name + "." + variable;
                    }
                }
            }
        }
示例#11
0
        public void HandleRename(StateSave stateSave, string oldName, ElementAnimationsViewModel viewModel)
        {
            var parentCategory = SelectedState.Self.SelectedElement?.Categories.First(item => item.States.Contains(stateSave));

            string prefix = "";

            if (parentCategory != null)
            {
                prefix = parentCategory + "/";
            }

            oldName = prefix + oldName;

            foreach (var animation in viewModel.Animations)
            {
                foreach (var keyframe in animation.Keyframes)
                {
                    if (keyframe.StateName == oldName)
                    {
                        keyframe.StateName = prefix + stateSave.Name;
                    }
                }
            }
        }