/// <inheritdoc/> protected override bool CanInsertItem(IObjectNode collection, NodeIndex index, object newItem) { if (collection.Type != typeof(EntityComponentCollection)) { return(base.CanInsertItem(collection, index, newItem)); } if (newItem == null) { return(false); } var componentType = newItem.GetType(); if (!EntityComponentAttributes.Get(componentType).AllowMultipleComponents) { // Cannot insert components that disallow multiple components var components = (EntityComponentCollection)collection.Retrieve(); if (components.Any(x => x.GetType() == componentType)) { return(false); } } return(base.CanInsertItem(collection, index, newItem)); }
/// <inheritdoc/> protected override bool CanReplaceItem(IObjectNode collection, NodeIndex index, object newItem) { if (collection.Type != typeof(EntityComponentCollection)) { return(base.CanReplaceItem(collection, index, newItem)); } if (newItem == null) { return(false); } var componentType = newItem.GetType(); // Cannot replace the transform component by another type of component if (collection.IndexedTarget(index).Type == typeof(TransformComponent) && componentType != typeof(TransformComponent)) { return(false); } if (!EntityComponentAttributes.Get(componentType).AllowMultipleComponents) { // Cannot replace components that disallow multiple components, unless it is that specific component we're replacing var components = (EntityComponentCollection)collection.Retrieve(); if (components.Where((x, i) => x.GetType() == componentType && i != index.Int).Any()) { return(false); } } return(base.CanReplaceItem(collection, index, newItem)); }
internal IObjectNode SetTarget(IObjectNode targetNode) { if (targetNode != null) { var targetValue = targetNode.Retrieve(); if (targetValue != null && !type.IsInstanceOfType(targetValue)) { throw new InvalidOperationException(@"The type of the retrieved node content does not match the type of this reference"); } if (targetValue != null && !type.IsInstanceOfType(targetValue)) { throw new InvalidOperationException("TargetNode type does not match the reference type."); } TargetNode = targetNode; TargetGuid = targetNode.Guid; } else { TargetNode = null; TargetGuid = Guid.Empty; } return(targetNode); }
private static void ClearMaterialList(IObjectNode materials) { var indices = materials.Indices.ToList(); foreach (var index in indices) { var item = materials.Retrieve(index); materials.Remove(item, index); } }
private void CheckAndProcessIdentifiableItem([NotNull] IObjectNode collection, NodeIndex index) { var identifiable = collection.Retrieve(index) as IIdentifiable; if (identifiable == null) { return; } ProcessIdentifiableItems(identifiable, collection, index); }
private void SetMaterialEnabled(IObjectNode materialNode, Index index, bool value) { if (value) { var material = GetMaterial(materialNode, index); materialNode.Add(material, index); } else { var material = materialNode.Retrieve(index); materialNode.Remove(material, index); } }
private object GetMaterial(IObjectNode materialNode, Index index) { if (materialNode.Indices.Contains(index)) { return(materialNode.Retrieve(index)); } var model = GetReferencedModel(); if (model == null) { return(null); } // During specific operations such as changes of the referenced model, this getter can be used while we're not currently in sync with the collection // of the model. In this case, return null. if (model.Materials.Count <= index.Int) { return(null); } return(model?.Materials[index.Int].MaterialInstance.Material); }
public async Task <bool> Initialize() { SelectedBlocks.CollectionChanged += SelectedBlocks_CollectionChanged; parameters = GraphViewModel.Create(ServiceProvider, new[] { new SinglePropertyProvider(parametersNode) }); using (var transaction = editor.UndoRedoService.CreateTransaction()) { // Add existing blocks and links blocksNode.ItemChanged += BlocksContentChanged; foreach (var block in (IEnumerable <Block>)blocksNode.Retrieve()) { await AddBlockViewModel(block); } linksNode.ItemChanged += LinksContentChanged; foreach (var link in (IEnumerable <Link>)linksNode.Retrieve()) { AddLinkViewModel(link); } editor.UndoRedoService.SetName(transaction, "Update graph asset"); } // Forward global diagnostics to blocks/links editor.Diagnostics.CollectionChanged += Diagnostics_CollectionChanged; DeleteSelectionCommand = new AnonymousCommand(ServiceProvider, DeleteSelection); ContextMenuOpeningCommand = new AnonymousCommand <System.Windows.Point>(ServiceProvider, ContextMenuOpening); RunBlockTemplateCommand = new AnonymousCommand <ITemplateDescriptionViewModel>(ServiceProvider, RunBlockTemplate); AddNewParameterCommand = new AnonymousCommand(ServiceProvider, AddNewParameter); RemoveSelectedParametersCommand = new AnonymousCommand(ServiceProvider, RemoveSelectedParameters); return(true); }
/// <inheritdoc/> protected override bool ShouldVisitTargetItem(IObjectNode collectionNode, NodeIndex index) { return(base.ShouldVisitTargetItem(collectionNode, index) && !PropertyGraphDefinition.IsTargetItemObjectReference(collectionNode, index, collectionNode.Retrieve(index))); }
public override bool IsTargetItemObjectReference(IObjectNode collection, Index itemIndex, object value) { return(collection.Retrieve() is List <MyReferenceable>); }
/// <summary> /// Getter for the virtual node's value. /// </summary> /// <param name="propertyContainerNode">The node containing the property.</param> /// <param name="propertyIndex">The index of the property in the node.</param> /// <returns></returns> private static object Getter([NotNull] IObjectNode propertyContainerNode, NodeIndex propertyIndex) { return(propertyContainerNode.Retrieve(propertyIndex)); }
public override TContentType GetNodeValue() { var value = (TContentType)Node.Retrieve(); return(value); }
public sealed override Task <bool> Initialize() { // Add a block that represents entry points var entryPointOutputs = new[] { nameof(GraphicsCompositorAsset.Game), nameof(GraphicsCompositorAsset.SingleView), nameof(GraphicsCompositorAsset.Editor) }; var entryPoint = new EntryPointBlockViewModel(this, graphicsCompositorNode, entryPointOutputs); entryPoint.Initialize(); entryPoint.UpdateSlots(); Blocks.Add(entryPoint); // Add blocks sharedRenderersNode.ItemChanged += SharedRenderersChanged; foreach (var sharedRendererNode in sharedRenderersNode.ItemReferences) { var sharedRenderer = (ISharedRenderer)sharedRendererNode.TargetNode.Retrieve(); AddSharedRendererViewModel(sharedRenderer); } // Now that we have all blocks with all slots, we can update all links foreach (var block in Blocks) { foreach (var slot in block.OutputSlots.Cast <GraphicsCompositorSlotViewModel>()) { slot.UpdateLink(); } } // TODO: Relayout the graph? // Add render stages renderStagesNode.ItemChanged += RenderStagesChanged; foreach (var renderStage in (IEnumerable <RenderStage>)renderStagesNode.Retrieve()) { RenderStages.Add(new RenderStageViewModel(this, renderStage)); } // Add render features renderFeaturesNode.ItemChanged += RenderFeaturesChanged; foreach (var renderFeature in (IEnumerable <RenderFeature>)renderFeaturesNode.Retrieve()) { RenderFeatures.Add(new RenderFeatureViewModel(this, renderFeature)); } // Add camera slots cameraSlotsNode.ItemChanged += CamerasSlotsChanged; foreach (var cameraSlot in (IEnumerable <SceneCameraSlot>)cameraSlotsNode.Retrieve()) { CameraSlots.Add(new GraphicsCompositorCameraSlotsViewModel(this, cameraSlot)); } // Update property grid on selected events SelectedRenderStages.CollectionChanged += SelectionChanged; SelectedRenderFeatures.CollectionChanged += SelectionChanged; SelectedCameraSlots.CollectionChanged += SelectionChanged; SelectedSharedRenderers.CollectionChanged += SelectionChanged; SelectedRendererLinks.CollectionChanged += SelectionChanged; // Make selection scope exclusives ServiceProvider.Get <SelectionService>().RegisterSelectionScope(id => RenderStages.FirstOrDefault(x => x.Id == id), obj => (obj as RenderStageViewModel)?.Id, SelectedRenderStages); ServiceProvider.Get <SelectionService>().RegisterSelectionScope(id => RenderFeatures.FirstOrDefault(x => x.Id == id), obj => (obj as RenderFeatureViewModel)?.Id, SelectedRenderFeatures); ServiceProvider.Get <SelectionService>().RegisterSelectionScope(id => CameraSlots.FirstOrDefault(x => x.Id == id), obj => (obj as GraphicsCompositorCameraSlotsViewModel)?.Id, SelectedCameraSlots); ServiceProvider.Get <SelectionService>().RegisterSelectionScope(id => Blocks.OfType <GraphicsCompositorBlockViewModel>().FirstOrDefault(x => x.Id == id), obj => (obj as GraphicsCompositorBlockViewModel)?.Id, SelectedSharedRenderers); // Update available types for factories UpdateAvailableTypes(); AssemblyRegistry.AssemblyRegistered += AssembliesUpdated; AssemblyRegistry.AssemblyUnregistered += AssembliesUpdated; return(Task.FromResult(true)); }