public ISceneNode StoryNode()
        {
            var node = objectFactory.Create <SceneNode>();

            node.Name = "StoryNode" + counter++;
            node.Components.Add(PresentationComponent.Create());
            node.Components.Add(objectFactory.Create <StoryComponent>());
            return(node);
        }
        public ISceneNode MovieRectangleNode(IMovie movie)
        {
            var node = objectFactory.Create <SceneNode>();

            node.Name = "Movie";
            node.Components.Add(PresentationComponent.Create());
            var rectComponent      = objectFactory.Create <RectangleComponent>();
            var movieRectComponent = objectFactory.Create <MovieRectangleComponent>();

            movieRectComponent.Movie = movie;
            node.Components.Add(rectComponent);
            node.Components.Add(movieRectComponent);
            return(node);
        }
        public ISceneNode ImageRectangleNode(IImage image)
        {
            var node = objectFactory.Create <SceneNode>();

            node.Name = "Image";
            node.Components.Add(PresentationComponent.Create());
            var rectComponent      = objectFactory.Create <RectangleComponent>();
            var imageRectComponent = objectFactory.Create <ImageRectangleComponent>();

            imageRectComponent.Image = image;
            node.Components.Add(rectComponent);
            node.Components.Add(imageRectComponent);
            return(node);
        }
        public ISceneNode ColorRectangleNode(Color4 color)
        {
            var node = objectFactory.Create <SceneNode>();

            node.Name = "Color Rectangle";
            node.Components.Add(PresentationComponent.Create());
            var rectComponent      = objectFactory.Create <RectangleComponent>();
            var colorRectComponent = objectFactory.Create <ColorRectangleComponent>();

            colorRectComponent.Color = color;
            node.Components.Add(rectComponent);
            node.Components.Add(colorRectComponent);
            return(node);
        }
        public ISceneNode RichTextRectangle(IRichText text)
        {
            var node = objectFactory.Create <SceneNode>();

            node.Name = "Text Entity";
            node.Components.Add(PresentationComponent.Create());
            var rectComponent = objectFactory.Create <RectangleComponent>();

            rectComponent.DragByBorders = true;
            var richTextComponent = objectFactory.Create <RichTextComponent>();

            richTextComponent.TextBox.Text = text;
            node.Components.Add(rectComponent);
            node.Components.Add(richTextComponent);
            return(node);
        }
        public ISceneNode WorldRoot(bool withStoryComponent)
        {
            var node = objectFactory.Create <SceneNode>();

            node.Name = "World";

            if (withStoryComponent)
            {
                node.Components.Add(PresentationRootComponent.Create(Guid.NewGuid()));
                node.Components.Add(AmFactory.Create <StoryServiceRootComponent>());
                var storyComponent = objectFactory.Create <StoryComponent>();
                storyComponent.StartLayoutType = typeof(SphereStoryLayout);
                node.Components.Add(storyComponent);
            }
            else
            {
                node.Components.Add(PresentationComponent.Create());
            }
            return(node);
        }
Example #7
0
        public DefaultMainForm(IUndoRedoService undoRedoService, IToolFactory toolFactory, IToolService toolService,
                               RenderControl renderControl, IAppModesCommands appModesCommands,
                               ISaveLoadGuiCommands saveLoadGuiCommands, ISceneTreeGui sceneTreeGui, /*IPropsGui propsGui,*/ IFluentGuiService fluentGuiService,
                               IAmDiBasedObjectFactory objectFactory, IAssetService assetService, IEmbeddedResources embeddedResources,
                               IResourceExplorerGui resourceExplorerGui, IReadOnlyList <IToolMenuItem> toolMenuItems, IStoryGraphGui storyGraphGui,
                               IReadOnlyList <IAssetLoader> assetLoaders, IViewService viewService, ICommonGuiObjects commonGuiObjects,
                               ISceneNodeContextMenuBuilder sceneNodeContextMenuBuilder)
        {
            this.storyGraphGui = storyGraphGui;
            ClientSize         = new Size(1280, 720);
            Title = "Clarity Worlds";

            var assetOpenFileDialog = new OpenFileDialog();

            assetOpenFileDialog.Filters.Add(new FileDialogFilter("All Assets", assetLoaders.SelectMany(x => x.FileExtensions).Distinct().ToArray()));
            foreach (var assetLoader in assetLoaders)
            {
                assetOpenFileDialog.Filters.Add(new FileDialogFilter(assetLoader.AssetTypeString,
                                                                     assetLoader.FileExtensions.ToArray()));
            }

            var toolCommands = new Command[]
            {
                new ToolCommand("Cube", toolService, () =>
                {
                    var entity  = objectFactory.Create <SceneNode>();
                    entity.Name = "NewCube";
                    entity.Components.Add(PresentationComponent.Create());
                    var modelComponent   = objectFactory.Create <ModelComponent>();
                    modelComponent.Model = embeddedResources.CubeModel();
                    modelComponent.Color = GetRandomSaturatedColor();
                    entity.Components.Add(modelComponent);
                    return(toolFactory.MoveEntity(entity, true));
                }),
                new ToolCommand("Sphere", toolService, () =>
                {
                    var entity  = objectFactory.Create <SceneNode>();
                    entity.Name = "NewSphere";
                    entity.Components.Add(PresentationComponent.Create());
                    var modelComponent   = objectFactory.Create <ModelComponent>();
                    modelComponent.Model = embeddedResources.SphereModel(64);
                    modelComponent.Color = GetRandomSaturatedColor();
                    entity.Components.Add(modelComponent);
                    return(toolFactory.MoveEntity(entity, true));
                }),
                new ToolCommand("Rectangle", toolService, toolFactory.AddRectangle),
                new ToolCommand("Text", toolService, toolFactory.AddText),
                new ToolCommand("Asset", toolService, () =>
                {
                    assetOpenFileDialog.ShowDialog(this);
                    var loadPath = assetOpenFileDialog.FileName;
                    if (loadPath == null)
                    {
                        return(null);
                    }
                    var loadInfo = new AssetLoadInfo
                    {
                        FileSystem    = ActualFileSystem.Singleton,
                        LoadPath      = loadPath,
                        ReferencePath = loadPath,
                        StorageType   = AssetStorageType.CopyLocal
                    };
                    var assetLoadResult = assetService.Load(loadInfo);
                    if (!assetLoadResult.Successful)
                    {
                        MessageBox.Show(assetLoadResult.Message);
                        return(null);
                    }

                    var asset = assetLoadResult.Asset;
                    IResource resource;
                    if (asset.Resource == null)
                    {
                        MessageBox.Show($"The asset contains no resource.");
                        return(null);
                    }
                    if (asset.Resource is ResourcePack pack)
                    {
                        resource = pack.MainSubresource;
                        if (resource == null)
                        {
                            MessageBox.Show($"The asset is a pack with no main subresource.");
                            return(null);
                        }
                    }
                    else
                    {
                        resource = asset.Resource;
                    }

                    switch (resource)
                    {
                    case IImage image:
                        return(toolFactory.AddImage(image));

                    case IMovie movie:
                        return(toolFactory.AddMovie(movie));

                    case IFlexibleModel fModel:
                        {
                            var entity  = AmFactory.Create <SceneNode>();
                            entity.Name = "NewModel";
                            entity.Components.Add(PresentationComponent.Create());
                            var modelComponent   = AmFactory.Create <ModelComponent>();
                            modelComponent.Model = fModel;
                            modelComponent.Color = GetRandomSaturatedColor();
                            entity.Components.Add(modelComponent);
                            return(toolFactory.MoveEntity(entity, true));
                        }

                    case SpherePackingResult spherePackingResult:
                        {
                            var entity  = AmFactory.Create <SceneNode>();
                            entity.Name = "NewModel";
                            entity.Components.Add(PresentationComponent.Create());
                            var modelComponent = AmFactory.Create <SpherePackingComponent>();
                            modelComponent.SpherePackingResult = spherePackingResult;
                            modelComponent.Color = GetRandomSaturatedColor();
                            entity.Components.Add(modelComponent);
                            return(toolFactory.MoveEntity(entity, true));
                        }

                    default:
                        MessageBox.Show($"Unable to instantiate an asset of type '{resource.GetType().Name}'.");
                        return(null);
                    }
                })
            }