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(); }
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; } } } } }
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); } } }
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; } }
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); }
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); } } } }
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; } } } }
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); } } }
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; } } } }
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; } } } }