Example #1
0
 public override async Task Invoke(object parameter)
 {
     using (var transaction = UndoRedoService?.CreateTransaction())
     {
         firstCommand?.NodeCommand.StartCombinedInvoke();
         foreach (var command in commands)
         {
             await command.Invoke(parameter);
         }
         firstCommand?.NodeCommand.EndCombinedInvoke();
         UndoRedoService?.SetName(transaction, ActionName);
     }
 }
        public override async Task Invoke(object parameter)
        {
            using (var transaction = UndoRedoService?.CreateTransaction())
            {
                var modelNode = NodePath.GetNode();
                if (modelNode == null)
                {
                    throw new InvalidOperationException("Unable to retrieve the node on which to apply the redo operation.");
                }

                await NodeCommand.Execute(modelNode, Index, parameter);

                UndoRedoService?.SetName(transaction, ActionName);
            }
        }
Example #3
0
        public async Task AddDependency(PickablePackageViewModel pickablePackageViewModel)
        {
            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var dependency = pickablePackageViewModel.DependencyRange;

                // Check if package isn't a dependency yet
                if (Package.Container.DirectDependencies.Any(x => x.Name == dependency.Name))
                {
                    return;
                }

                var reference = new DirectDependencyReferenceViewModel(dependency, this, Dependencies, true);
                UndoRedoService.SetName(transaction, $"Add dependency to package '{reference.Name}'");

                // Update dependencies with NuGet
                if (Package.Container is SolutionProject project2)
                {
                    var log = new LoggerResult();
                    await VSProjectHelper.RestoreNugetPackages(log, project2.FullPath);

                    PackageSession.UpdateDependencies(project2, false, true);

                    // If the package is not part of session yet, make sure it gets added at this point
                    foreach (var projectDependency in project2.FlattenedDependencies)
                    {
                        if (projectDependency.Package == null && projectDependency.Type == DependencyType.Package)
                        {
                            var packageFile = PackageStore.Instance.GetPackageFileName(projectDependency.Name, new PackageVersionRange(projectDependency.Version));
                            if (packageFile != null && File.Exists(packageFile))
                            {
                                var dependencyPackageViewModel = await Session.AddExistingProject(packageFile);

                                projectDependency.Package = dependencyPackageViewModel.Package;
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        public void UpdateProperties(Guid elementId, IReadOnlyDictionary <string, object> changes)
        {
            var partId  = new AbsoluteId(Asset.Id, elementId);
            var element = (UIElementViewModel)FindPartViewModel(partId);

            if (element == null)
            {
                return;
            }

            var node = NodeContainer.GetNode(element.AssetSideUIElement);

            if (node == null)
            {
                return;
            }

            using (var transaction = UndoRedoService.CreateTransaction())
            {
                foreach (var kv in changes)
                {
                    var propertyName  = kv.Key;
                    var propertyValue = kv.Value;

                    var member = node.TryGetChild(propertyName);
                    if (member == null)
                    {
                        continue;
                    }

                    // Update properties only when they actually changed
                    var currentValue = member.Retrieve();
                    if (currentValue != propertyValue)
                    {
                        member.Update(propertyValue);
                    }
                }
                UndoRedoService.SetName(transaction, $"Update {element.ElementType.Name}");
            }
        }
Example #5
0
        private void PlatformFiltersNodeChanging(object sender, ItemChangeEventArgs e)
        {
            if (e.ChangeType == ContentChangeType.CollectionUpdate)
            {
                var index = e.Index.Int;
                using (var transaction = UndoRedoService.CreateTransaction())
                {
                    foreach (var platformOverride in Asset.Overrides)
                    {
                        var node       = Session.AssetNodeContainer.GetNode(platformOverride);
                        var filterNode = node[nameof(ConfigurationOverride.SpecificFilter)];

                        if (platformOverride.SpecificFilter == index)
                        {
                            // This is a hack to force refreshing the display of the filter in override. We clear and reset it before and after the name change.
                            filterNode.Update(-1);
                            filterNode.Update(index);
                        }
                    }
                    UndoRedoService.SetName(transaction, "Force filter refresh");
                }
            }
        }
Example #6
0
        private async Task GeneratePrecompiledFont()
        {
            var font          = (SpriteFontAsset)AssetItem.Asset;
            var dialogService = ServiceProvider.Get <IDialogService>();

            // Dynamic font cannot be precompiled
            if (font.FontType is RuntimeRasterizedSpriteFontType)
            {
                // Note: Markdown (**, _) are used to format the text.
                await dialogService.MessageBox(Tr._p("Message", "**Only static fonts can be precompiled.**\r\n\r\nClear the _Is Dynamic_ property on this font and try again."), MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }
            // Compute unique name
            var precompiledName = NamingHelper.ComputeNewName($"{AssetItem.Location.GetFileNameWithoutExtension()} (Precompiled)", Directory.Assets, x => x.Name);

            // Ask location for generated texture
            var folderDialog = dialogService.CreateFolderOpenModalDialog();

            folderDialog.InitialDirectory = (Session.CurrentProject?.Package?.RootDirectory ?? Session.SolutionPath.GetFullDirectory()).ToWindowsPath() + "\\Resources";
            var dialogResult = await folderDialog.ShowModal();

            if (dialogResult != DialogResult.Ok)
            {
                return;
            }

            bool srgb;
            var  gameSettings = Session.CurrentProject?.Package.GetGameSettingsAsset();

            if (gameSettings == null)
            {
                var buttons = DialogHelper.CreateButtons(new[] { ColorSpace.Linear.ToString(), ColorSpace.Gamma.ToString(), Tr._p("Button", "Cancel") }, 1, 3);
                var result  = await dialogService.MessageBox(Tr._p("Message", "Which color space do you want to use?"), buttons, MessageBoxImage.Question);

                // Close without clicking a button or Cancel
                if (result == 0 || result == 3)
                {
                    return;
                }
                srgb = result == 2;
            }
            else
            {
                srgb = gameSettings.GetOrCreate <RenderingSettings>().ColorSpace == ColorSpace.Linear;
            }

            var precompiledFontAsset = (font.FontType is SignedDistanceFieldSpriteFontType) ?
                                       font.GeneratePrecompiledSDFSpriteFont(AssetItem, UFile.Combine(folderDialog.Directory, precompiledName)) :
                                       font.GeneratePrecompiledSpriteFont(AssetItem, UFile.Combine(folderDialog.Directory, precompiledName), srgb);

            // NOTE: following code could be factorized with AssetFactoryViewModel
            var            defaultLocation = UFile.Combine(Directory.Path, precompiledName);
            var            assetItem       = new AssetItem(defaultLocation, precompiledFontAsset);
            AssetViewModel assetViewModel;

            using (var transaction = UndoRedoService.CreateTransaction())
            {
                // FIXME: do we need to delete the generated file upon undo?
                assetViewModel = Directory.Package.CreateAsset(Directory, assetItem, true, null);
                UndoRedoService.SetName(transaction, $"Create Asset '{precompiledName}'");
            }

            Session.CheckConsistency();
            if (assetViewModel != null)
            {
                Session.ActiveAssetView.SelectAssetCommand.Execute(assetViewModel);
            }
        }
Example #7
0
        private void PlatformFiltersNodeChanged(object sender, ItemChangeEventArgs e)
        {
            var index = e.Index.Int;

            ITransaction transaction = null;

            try
            {
                if (e.ChangeType == ContentChangeType.CollectionUpdate)
                {
                    transaction = UndoRedoService.CreateTransaction();
                }

                foreach (var platformOverride in Asset.Overrides)
                {
                    var node       = Session.AssetNodeContainer.GetNode(platformOverride);
                    var filterNode = node[nameof(ConfigurationOverride.SpecificFilter)];

                    switch (e.ChangeType)
                    {
                    case ContentChangeType.CollectionUpdate:
                    {
                        // This is a hack to force refreshing the display of the filter in override. We clear and reset it before and after the name change.
                        if (platformOverride.SpecificFilter == index)
                        {
                            filterNode.Update(-1);
                            filterNode.Update(index);
                        }
                        break;
                    }

                    case ContentChangeType.CollectionAdd:
                    {
                        var filterIndex = (int)filterNode.Retrieve();
                        if (filterIndex >= index)
                        {
                            filterNode.Update(filterIndex + 1);
                        }
                        break;
                    }

                    case ContentChangeType.CollectionRemove:
                    {
                        var filterIndex = (int)filterNode.Retrieve();
                        if (filterIndex > index)
                        {
                            filterNode.Update(filterIndex - 1);
                        }
                        else if (filterIndex == index)
                        {
                            filterNode.Update(-1);
                        }
                        break;
                    }
                    }
                }
            }
            finally
            {
                if (transaction != null)
                {
                    UndoRedoService.SetName(transaction, "Force filter refresh");
                    transaction.Complete();
                }
            }
        }