Exemple #1
0
 public MuseumStoryLayout(IEmbeddedResources embeddedResources, IWorldTreeService worldTreeService)
 {
     this.worldTreeService = worldTreeService;
     floorModel            = embeddedResources.PlaneModel(PlaneModelSourcePlane.Xy, PlaneModelSourceNormalDirection.Positive,
                                                          globalRadius, globalRadius, 1, 1);
     ceilingModel = embeddedResources.PlaneModel(PlaneModelSourcePlane.Xy, PlaneModelSourceNormalDirection.Negative,
                                                 globalRadius, globalRadius, 1, 1);
     exitWallModel = embeddedResources.PlaneModel(PlaneModelSourcePlane.Xz, PlaneModelSourceNormalDirection.Negative,
                                                  exitHalfLength, ceilingHalfHeight, 1, 1);
     corridorWallModel = embeddedResources.PlaneModel(PlaneModelSourcePlane.Xz, PlaneModelSourceNormalDirection.Negative,
                                                      corridorHalfWidth, ceilingHalfHeight, 1, 1);
     frustumModel  = embeddedResources.SimpleFrustumModel();
     floorMaterial = StandardMaterial.New()
                     .SetDiffuseMap(embeddedResources.Image("Textures/museum_floor.jpg"))
                     .SetNoSpecular(true)
                     .FromGlobalCache();
     ceilingMaterial = StandardMaterial.New()
                       .SetDiffuseMap(embeddedResources.Image("Textures/museum_ceiling.jpg"))
                       .SetNoSpecular(true)
                       .FromGlobalCache();
     wallMaterial = StandardMaterial.New()
                    .SetDiffuseMap(embeddedResources.Image("Textures/museum_wall.jpg"))
                    .SetNoSpecular(true)
                    .FromGlobalCache();
     frustumMaterial = StandardMaterial.New()
                       .SetDiffuseColor(Color4.Green)
                       .SetIgnoreLighting(true)
                       .FromGlobalCache();
 }
        protected StoryFlowchartNodeGizmoComponent(IEmbeddedResources embeddedResources, IViewService viewService)
        {
            this.viewService = viewService;

            GlobalRectangle = new AaRectangle2(Vector2.Zero, 1, 1);

            var squareModel = embeddedResources.SimplePlaneXyModel();

            var material = StandardMaterial.New(this)
                           .SetDiffuseColor(x => x.DiffuseColorToUse())
                           .SetDiffuseMap(x => x.DiffuseMapToUse())
                           .SetIgnoreLighting(true)
                           .SetHighlightEffect(x =>
                                               x.viewService.SelectedNode == ReferencedNode ? HighlightEffect.RainbowBorder :
                                               x.viewService.ClosestStoryNode == ReferencedNode ? HighlightEffect.Pulsating :
                                               HighlightEffect.None);

            visualElement = new ModelVisualElement <StoryFlowchartNodeGizmoComponent>(this)
                            .SetModel(squareModel)
                            .SetMaterial(material)
                            .SetTransform(x => Transform.Translation(new Vector3(x.GlobalRectangle.Center, x.Depth * 0.1f)))
                            .SetNonUniformScale(x => new Vector3(x.GlobalRectangle.HalfWidth, -/*todo: correct text-coords*/ x.GlobalRectangle.HalfHeight, 1));

            hittable = new RectangleHittable <StoryFlowchartNodeGizmoComponent>(this,
                                                                                Transform.Identity,
                                                                                x => new AaRectangle2(Vector2.Zero, x.GlobalRectangle.HalfWidth, x.GlobalRectangle.HalfHeight),
                                                                                x => - x.Depth);
        }
        protected StoryFlowchartEdgeGizmoComponent(IEmbeddedResources embeddedResources)
        {
            var lineModel = embeddedResources.LineModel();

            Material = StandardMaterial.New()
                       .SetDiffuseColor(new Color4(0f, 0.5f, 0f))
                       .SetIgnoreLighting(true)
                       .FromGlobalCache();

            RenderState = StandardRenderState.New()
                          .SetLineWidth(3)
                          .FromGlobalCache();

            visualElements = new IVisualElement[]
            {
                new ModelVisualElement <StoryFlowchartEdgeGizmoComponent>(this)
                .SetModel(lineModel)
                .SetMaterial(x => x.Material)
                .SetTransform(x => GetTransformForLine(x.FirstPoint, x.MiddlePoint)),
                new ModelVisualElement <StoryFlowchartEdgeGizmoComponent>(this)
                .SetModel(lineModel)
                .SetMaterial(x => x.Material)
                .SetTransform(x => GetTransformForLine(x.MiddlePoint, x.LastPoint))
            };
        }
 public SphereStoryLayout(IEmbeddedResources embeddedResources)
 {
     frustumModel    = embeddedResources.SimpleFrustumModel();
     frustumMaterial = StandardMaterial.New()
                       .SetDiffuseColor(Color4.Green)
                       .SetIgnoreLighting(true)
                       .FromGlobalCache();
 }
 public DirtyHackService(IWorldTreeService worldTreeService, IAppModeService appModeService,
                         IReadOnlyList <IStoryLayout> storyLayouts, IEmbeddedResources embeddedResources)
 {
     this.worldTreeService  = worldTreeService;
     this.appModeService    = appModeService;
     this.storyLayouts      = storyLayouts;
     this.embeddedResources = embeddedResources;
 }
Exemple #6
0
 public DragAlongAxisGizmoComponent(IEmbeddedResources embeddedResources)
 {
     model         = embeddedResources.LineModel();
     visualElement = new ModelVisualElement <DragAlongAxisGizmoComponent>(this)
                     .SetModel(model)
                     .SetMaterial(x => x.material)
                     .SetTransform(x => x.transform);
     hittable = new LineHittable <DragAlongAxisGizmoComponent>(this, x => x.GetGlobalLine(), PixelLineWidth);
 }
 protected SpherePackingComponent(IEmbeddedResources embeddedResources, IViewService viewService, Lazy <IAppModeService> appModeServiceLazy)
 {
     this.embeddedResources  = embeddedResources;
     this.viewService        = viewService;
     this.appModeServiceLazy = appModeServiceLazy;
     Radius = 0.05f;
     Color  = Color4.Red;
     selectInteractionELement = new SelectOnClickInteractionElement(this, viewService);
     hittable = new SphereHittable <SpherePackingComponent>(this, x => x.LocalBoundingSphere * x.Node.GlobalTransform);
 }
        protected UserQuerySceneComponent(IUserQueryService queryService, IEmbeddedResources embeddedResources, IRtImageBuilder textImageBuilder)
        {
            this.queryService     = queryService;
            this.textImageBuilder = textImageBuilder;
            planeModel            = embeddedResources.SimplePlaneXyModel();

            optionRects    = new List <AaRectangle2>();
            visualElements = new List <IVisualElement>();
            hittable       = new RectangleHittable <UserQuerySceneComponent>(this,
                                                                             Transform.Identity, x => new AaRectangle2(Vector2.Zero, 1f, 1f), x => 0);
        }
        protected ImageRectangleComponent(IEmbeddedResources embeddedResources)
        {
            var material = StandardMaterial.New(this)
                           .SetDiffuseMap(x => x.Image)
                           .SetIgnoreLighting(true);

            visualElement = new ModelVisualElement <ImageRectangleComponent>(this)
                            .SetModel(embeddedResources.SimplePlaneXyModel())
                            .SetMaterial(material)
                            .SetTransform(x => Transform.Translation(new Vector3(x.Rectangle.Center, 0)))
                            .SetNonUniformScale(x => new Vector3(x.Rectangle.HalfWidth, x.Rectangle.HalfHeight, 1));
        }
Exemple #10
0
 public OrbitStoryLayout(IEmbeddedResources embeddedResources)
 {
     frustumModel    = embeddedResources.SimpleFrustumModel();
     circleModel     = embeddedResources.CircleModel(256);
     frustumMaterial = StandardMaterial.New()
                       .SetDiffuseColor(Color4.Green)
                       .SetIgnoreLighting(true)
                       .FromGlobalCache();
     circleMaterial = StandardMaterial.New()
                      .SetDiffuseColor(Color4.Yellow)
                      .SetIgnoreLighting(true)
                      .FromGlobalCache();
 }
        protected FluidSimulationComponent(IEmbeddedResources embeddedResources)
        {
            this.embeddedResources = embeddedResources;
            //var size = new IntSize3(20, 20, 1);
            //var cellSize = 0.40f;
            //var particleRadius = 0.25f;
            fluidSimulation = new FluidSimulation(1f, 1f, 0.25f);

            visualElements   = new List <IVisualElement>();
            interactionElems = new IInteractionElement[]
            {
                //new SelectOnClickInteractionElement(this, viewService),
                new ActionOnEventInteractionElement(
                    args => args is IMouseEvent m && m.IsRightClickEvent() && m.KeyModifiers == KeyModifiers.None,
                    () =>
                {
                    if (simulationRunning)
                    {
                        fluidSimulation.Stop();
                    }
                    else
                    {
                        if (firstTime)
                        {
                            fluidSimulation.Reset(CreateConfig());
                            Reset();
                            firstTime = false;
                        }
                        prevFrame = nextFrame = null;
                        fluidSimulation.Run(simulationTimestamp + 5);
                    }
                    simulationRunning = !simulationRunning;
                }),
                new ActionOnEventInteractionElement(
                    args => args is IMouseEvent m && m.IsRightClickEvent() && m.KeyModifiers == KeyModifiers.Shift,
                    () =>
                {
                    Reset();
                }),
            };

            hittable = new SphereHittable <FluidSimulationComponent>(this, c => c.model.BoundingSphere * c.Node.GlobalTransform);

            Width         = 20;
            Height        = 20;
            CellSize      = 0.8f;
            LevelSetScale = 16;
            SurfaceType   = FluidSurfaceType.Hybrid;
            Reset();
        }
 protected ResizeRectangleGizmoComponent(IInputHandler inputHandler, IEmbeddedResources embeddedResources, IUndoRedoService undoRedo)
 {
     visualElement = ModelVisualElement.New()
                     .SetModel(embeddedResources.CubeModel())
                     .SetMaterial(StandardMaterial.New()
                                  .SetNoSpecular(true)
                                  .FromGlobalCache())
                     .SetTransform(Transform.Scaling(0.025f));
     interactionElement = new ResizeRectangleInteractionElement <ResizeRectangleGizmoComponent>(
         this, x => x.GetRectAspect(), x => x.GetChildSpace(), x => x.Place, inputHandler, undoRedo);
     hittable = new SphereHittable <ResizeRectangleGizmoComponent>(this, x =>
     {
         var globalTransform = Node.GlobalTransform;
         return(new Sphere(globalTransform.Offset, 0.025f * globalTransform.Scale));
     });
 }
Exemple #13
0
        public SimpleStoryLayout(IKeyboardInputProvider keyboardInputProvider, IEmbeddedResources embeddedResources)
        {
            this.keyboardInputProvider = keyboardInputProvider;

            planeModel     = embeddedResources.SimplePlaneXyModel();
            planeMaterials = new[]
            {
                new Color4(120, 222, 44),
                new Color4(222, 120, 44),
                new Color4(44, 120, 222),
                new Color4(222, 44, 120),
                new Color4(64, 222, 160),
                new Color4(120, 44, 222),
            }.Select(x => StandardMaterial.New(x).FromGlobalCache())
            .Select(x => (IStandardMaterial)x)
            .ToArray();
        }
        protected CirclePackingAutoComponent(IEmbeddedResources embeddedResources, IViewService viewService, ICoroutineService coroutineService)
        {
            this.embeddedResources = embeddedResources;
            this.coroutineService  = coroutineService;

            solver = new CirclePackingSolver();
            Reset();

            borderModel = new ExplicitModel(ResourceVolatility.Stable)
            {
                IndexSubranges = new ExplicitModelIndexSubrange[1],
                Topology       = ExplicitModelPrimitiveTopology.LineStrip
            };
            backgroundVisualElement = ModelVisualElement.New(this)
                                      .SetModel(embeddedResources.SimplePlaneXyModel())
                                      .SetMaterial(StandardMaterial.New()
                                                   .SetIgnoreLighting(true)
                                                   .SetDiffuseColor(Color4.Black)
                                                   .FromGlobalCache())
                                      .SetRenderState(StandardRenderState.New()
                                                      .SetZOffset(-GraphicsHelper.MinZOffset))
                                      .SetTransform(x => Transform.Translation(new Vector3(x.border.BoundingRect.Center, 0)))
                                      .SetNonUniformScale(x => new Vector3(
                                                              x.border.BoundingRect.HalfWidth,
                                                              x.border.BoundingRect.HalfHeight,
                                                              1));
            borderVisualElement = ModelVisualElement.New(this)
                                  .SetModel(x => x.GetRelevantBorderModel())
                                  .SetMaterial(StandardMaterial.New()
                                               .SetDiffuseColor(Color4.Yellow)
                                               .SetIgnoreLighting(true)
                                               .FromGlobalCache());
            circleVisualElements           = new List <IVisualElement>();
            selectOnClickInterationElement = new SelectOnClickInteractionElement(this, viewService);
            // todo: make precise
            hittable = new RectangleHittable <CirclePackingAutoComponent>(this, Transform.Identity,
                                                                          x => x.border.BoundingRect,
                                                                          x => 0);
        }
        public NestedSpheresStoryLayout(IEmbeddedResources embeddedResources, ICoroutineService coroutineService, Lazy <IViewService> viewServiceLazy)
        {
            this.coroutineService = coroutineService;
            this.viewServiceLazy  = viewServiceLazy;
            focusVisualEffect     = new FocusVisualEffect();

            mainModel       = embeddedResources.SphereModel(64, true);
            lineModel       = embeddedResources.LineModel();
            sphereMaterials = new IMaterial[]
            {
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1.0f, 0.5f, 0.5f) * 1.0f, 0.5f)).FromGlobalCache(),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0.5f, 1.0f, 0.5f) * 1.0f, 0.5f)).FromGlobalCache(),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0.5f, 0.5f, 1.0f) * 1.0f, 0.5f)).FromGlobalCache(),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1.0f, 1.0f, 0.5f) * 1.0f, 0.5f)).FromGlobalCache(),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1.0f, 0.5f, 1.0f) * 1.0f, 0.5f)).FromGlobalCache(),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0.5f, 1.0f, 1.0f) * 1.0f, 0.5f)).FromGlobalCache(),
            };
            sphereRenderState = StandardRenderState.New().SetCullFace(CullFace.Back).FromGlobalCache();

            lineMaterial         = StandardMaterial.New().SetDiffuseColor(Color4.Red).FromGlobalCache();
            lineMaterialExternal = StandardMaterial.New().SetDiffuseColor(0.7f * Color4.Red);
            lineRenderState      = StandardRenderState.New().SetLineWidth(3).FromGlobalCache();
        }
 public NestedCirclesStoryLayout(IEmbeddedResources embeddedResources, ICoroutineService coroutineService)
 {
     this.coroutineService = coroutineService;
     planeModel            = embeddedResources.SimplePlaneXyModel();
     circleModel           = embeddedResources.CircleModel(64);
     lineModel             = embeddedResources.LineModel();
     circleMaterials       = new IMaterial[]
     {
         StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 0f, 0f) * 0.5f, 1.0f)).SetIgnoreLighting(true).FromGlobalCache(),
         StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 1f, 0f) * 0.5f, 1.0f)).SetIgnoreLighting(true).FromGlobalCache(),
         StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 0f, 1f) * 0.5f, 1.0f)).SetIgnoreLighting(true).FromGlobalCache(),
         StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 1f, 0f) * 0.5f, 1.0f)).SetIgnoreLighting(true).FromGlobalCache(),
         StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 0f, 1f) * 0.5f, 1.0f)).SetIgnoreLighting(true).FromGlobalCache(),
         StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 1f, 1f) * 0.5f, 1.0f)).SetIgnoreLighting(true).FromGlobalCache()
     };
     lineMaterial         = StandardMaterial.New().SetDiffuseColor(Color4.Blue).FromGlobalCache();
     lineMaterialExternal = StandardMaterial.New().SetDiffuseColor(0.7f * Color4.White).FromGlobalCache();
     circleRenderState    = StandardRenderState.New()
                            .SetLineWidth(2)
                            .SetCullFace(CullFace.Front)
                            .FromGlobalCache();
     lineRenderState = StandardRenderState.New().SetLineWidth(3).FromGlobalCache();
 }
        public BuildingStoryLayout(ICoroutineService coroutineService, IEmbeddedResources embeddedResources,
                                   IInputService inputService, Lazy <INavigationService> navigationServiceLazy)
        {
            this.embeddedResources     = embeddedResources;
            this.inputService          = inputService;
            this.navigationServiceLazy = navigationServiceLazy;
            this.coroutineService      = coroutineService;
            planeModel     = embeddedResources.SimplePlaneXzModel();
            lineModel      = embeddedResources.LineModel();
            frustumModel   = embeddedResources.SimpleFrustumModel();
            colorMaterials = new IMaterial[]
            {
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 0f, 0f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 1f, 0f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 0f, 1f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 1f, 0f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1f, 0f, 1f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
                StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0f, 1f, 1f) * 0.8f, 1.0f)).SetIgnoreLighting(true),
            };
            frustumMaterial = StandardMaterial.New()
                              .SetDiffuseColor(new Color4(0f, 1f, 0f))
                              .SetIgnoreLighting(true)
                              .FromGlobalCache();
            lineMaterial = StandardMaterial.New()
                           .SetDiffuseColor(Color4.White)
                           .SetIgnoreLighting(true)
                           .FromGlobalCache();
            currentLineMaterial = StandardMaterial.New()
                                  .SetDiffuseColor(Color4.Red)
                                  .SetIgnoreLighting(true)
                                  .FromGlobalCache();
            lineRenderState = StandardRenderState.New().SetLineWidth(3).FromGlobalCache();

            var mirrorSampler = new ImageSampler
            {
                AddressModeU = ImageSamplerAddressMode.Mirror,
                AddressModeV = ImageSamplerAddressMode.Mirror,
                AddressModeW = ImageSamplerAddressMode.Mirror,
            }.FromGlobalCache();

            floorMaterial = StandardMaterial.New()
                            .SetDiffuseMap(embeddedResources.Image("Textures/museum_floor.jpg"))
                            .SetNoSpecular(true)
                            .SetSampler(mirrorSampler)
                            .FromGlobalCache();
            ceilingMaterial = StandardMaterial.New()
                              .SetDiffuseMap(embeddedResources.Image("Textures/museum_ceiling.jpg"))
                              .SetNoSpecular(true)
                              .SetSampler(mirrorSampler)
                              .FromGlobalCache();
            wallMaterial = StandardMaterial.New()
                           .SetDiffuseMap(embeddedResources.Image("Textures/museum_wall.jpg"))
                           .SetDiffuseColor(new Color4(92, 82, 72))
                           //.SetNoSpecular(true)
                           .SetNormalMap(embeddedResources.Image("Textures/museum_wall_2_norm.jpg"))
                           .FromGlobalCache();
            rawWallMaterial = StandardMaterial.New()
                              .SetDiffuseColor(Color4.Green)
                              .SetIgnoreLighting(true)
                              .FromGlobalCache();
        }
Exemple #18
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);
                    }
                })
            }
Exemple #19
0
        public PropsGui(IViewService viewService, IUndoRedoService undoRedo, IAssetService assetService, IWorldTreeService worldTreeService,
                        IReadOnlyList <IStoryLayout> storyLayouts, IStoryService storyService, IEmbeddedResources embeddedResources, IWindowQueryService windowQueryService,
                        IMovieUrlLoader movieUrlLoader)
        {
            this.viewService = viewService;

            PropsPanel = new Panel
            {
                Content = new TableLayout(),
                Width   = 250,
                Height  = 300
            };

            groups = new IPropsGuiGroup[]
            {
                new PropsGuiGroupCommon(undoRedo),
                new PropsGuiGroupFluidSimulation(undoRedo),
                new PropsGuiGroupStoryComponent(undoRedo, storyLayouts, worldTreeService, storyService),
                new PropsGuiGroupMovieRectangle(undoRedo, assetService, windowQueryService, movieUrlLoader),
                new PropsGuiGroupHighlightOnMouse(undoRedo),
                new PropsGuiGroupComponents(undoRedo),
            };

            viewService.Update += OnViewServiceUpdate;
        }
        public FluentGuiService(IViewService viewService, IRenderLoopDispatcher renderLoopDispatcher,
                                IAssetService assetService, IUndoRedoService undoRedo, IEmbeddedResources embeddedResources,
                                IReadOnlyList <IStoryLayout> storyLayouts,
                                // todo: refactor away from using these services
                                IStoryService storyService, IWorldTreeService worldTreeService)
        {
            this.viewService  = viewService;
            this.assetService = assetService;
            this.undoRedo     = undoRedo;

            var mainPanel = new FluentPanel <ISceneNode>(() => selectedSceneNode, x => x != null)
            {
                Width = 300
            };
            var builder = mainPanel.Build().Table();

            {
                var mainGroupBox = builder.Row().GroupBox("common", x => x, x => true).Table();
                mainGroupBox.Row().Label(x => x.Id.ToString());
                mainGroupBox.Row().TextBox(x => x.Name);
            }
            {
                var sceneGroupBox = builder.Row().GroupBox("Scene", x => x.AmParent as IScene, x => x != null).Table();
                var colorRow      = sceneGroupBox.Row();
                colorRow.Label("Bgnd Color");
                colorRow.ColorPicker(x => x.BackgroundColor);
                var skyboxRow = sceneGroupBox.Row();
                skyboxRow.Label("Skybox");
                skyboxRow.DropDown(x => x.Skybox, new Dictionary <string, ISkybox>
                {
                    { "None", null },
                    { "Storm", embeddedResources.Skybox("Skyboxes/storm.skybox") },
                    { "Stars", embeddedResources.Skybox("Skyboxes/stars.skybox") }
                });
            }
            {
                var storyRootGroupBox = builder.Row().GroupBox("Story Root", x => x.SearchComponent <IStoryComponent>(), x => x != null && x.IsLayoutRoot).Table();
                var layoutTypeRow     = storyRootGroupBox.Row();
                layoutTypeRow.Label("LayoutType");
                layoutTypeRow.DropDown(x => x.StartLayoutType, storyLayouts.ToDictionary(x => x.UserFriendlyName, x => x.Type));
                var auxRow12 = storyRootGroupBox.Row();
                auxRow12.CheckBox("Aux 1", x => x.ShowAux1);
                auxRow12.CheckBox("Aux 2", x => x.ShowAux2);
                var auxRow34 = storyRootGroupBox.Row();
                auxRow34.CheckBox("Aux 3", x => x.ShowAux3);
                auxRow34.CheckBox("Aux 4", x => x.ShowAux4);
            }
            {
                var storyNodeGroupBox = builder.Row().GroupBox("Story Node", x => x.SearchComponent <IStoryComponent>(), x => x != null).Table();
                var firstRow          = storyNodeGroupBox.Row();
                firstRow.CheckBox("Instant transition", x => x.InstantTransition);
                firstRow.CheckBox("Skip", x => x.SkipOrder);
                for (var i = 0; i < 4; i++)
                {
                    var iLoc = i;
                    var row  = storyNodeGroupBox.Row();
                    row.Label(x => storyService.GlobalGraph.Next.TryGetValue(x.Node.Id, out var nextList) && iLoc < nextList.Count
                        ? worldTreeService.GetById(nextList[iLoc]).Name
                        : "-");
                    row.Button("X", x => storyService.RemoveEdge(x.Node.Id, storyService.GlobalGraph.Next[x.Node.Id][iLoc]));
                }
            }
            {
                var modelComponentBuilder = builder.Row().GroupBox("Model", x => x.SearchComponent <IModelComponent>(), x => x != null).Table();
                var colorRow = modelComponentBuilder.Row();
                colorRow.CheckBox("SingleColor", x => x.SingleColor);
                colorRow.ColorPicker(x => x.Color);
                var textureRow = modelComponentBuilder.Row();
                textureRow.Label("Image");
                textureRow.Button("Load", OnLoadTextureClicked);
                var checkBoxRow1 = modelComponentBuilder.Row();
                checkBoxRow1.CheckBox("Ignore Lighting", x => x.IgnoreLighting);
                checkBoxRow1.CheckBox("No Specular", x => x.NoSpecular);
                var checkBoxRow2 = modelComponentBuilder.Row();
                checkBoxRow2.CheckBox("Don't cull", x => x.DontCull);
                checkBoxRow2.CheckBox("Ortho", x => x.Ortho);
                modelComponentBuilder.Row().Button("Export", OnExportClick);
            }
            {
                var spherePackingComponentBuilder = builder.Row().GroupBox("Sphere Packing", x => x.SearchComponent <SpherePackingComponent>(), x => x != null).Table();
                var row = spherePackingComponentBuilder.Row();
                row.Label("Radius");
                row.TextBox(x => x.Radius);
                row = spherePackingComponentBuilder.Row();
                row.Label("Color");
                row.ColorPicker(x => x.Color);
            }
            {
                var rectGroupBox  = builder.Row().GroupBox("Rectangle", x => x, x => x.HasComponent <IRectangleComponent>()).Table();
                var commonRectRow = rectGroupBox.Row().Panel(x => x.SearchComponent <IRectangleComponent>(), x => x != null).Table().Row();
                commonRectRow.CheckBox("DragBorders", x => x.DragByBorders);
                var colorRow = rectGroupBox.Row().Panel(x => x.SearchComponent <ColorRectangleComponent>(), x => x != null).Table().Row();
                colorRow.Label("Color");
                colorRow.ColorPicker(x => x.Color);
                // todo: change image
            }
            {
                var viewModel    = new RichTextViewModel(() => selectedSceneNode.SearchComponent <IRichTextComponent>());
                var textGroupBox = builder.Row().GroupBox("Rich Text", x => viewModel, x => x.Valid).Table();
                var bgndModeRow  = textGroupBox.Row();
                bgndModeRow.Label("Bgnd Mode");
                bgndModeRow.DropDown(x => x.BackgroundMode, new Dictionary <string, RtTransparencyMode>
                {
                    ["Opaque"] = RtTransparencyMode.Opaque,
                    ["Native"] = RtTransparencyMode.Native,
                    ["White is transparent"] = RtTransparencyMode.WhiteIsTransparent,
                    ["Black is transparent"] = RtTransparencyMode.BlackIsTransparent,
                });
                var bgndColorRow = textGroupBox.Row();
                bgndColorRow.Label("Bgnd Color");
                bgndColorRow.ColorPicker(x => x.BackgroundColor);
                var bgndOpacityRow = textGroupBox.Row();
                bgndOpacityRow.Label("Bgnd Opacity");
                bgndOpacityRow.Slider(x => x.BackgroundOpacity, 0, 1, 256);

                var alignmentRow = textGroupBox.Row();
                alignmentRow.Label("Alignment");
                alignmentRow.DropDown(x => x.Alignment, new Dictionary <string, RtParagraphAlignment>
                {
                    ["Left"]    = RtParagraphAlignment.Left,
                    ["Center"]  = RtParagraphAlignment.Center,
                    ["Right"]   = RtParagraphAlignment.Right,
                    ["Justify"] = RtParagraphAlignment.Justify,
                });
                var directionRow = textGroupBox.Row();
                directionRow.Label("Direction");
                directionRow.DropDown(x => x.Direction, new Dictionary <string, RtParagraphDirection>
                {
                    ["LeftToRight"] = RtParagraphDirection.LeftToRight,
                    ["RightToLeft"] = RtParagraphDirection.RightToLeft,
                });
                var tabsRow = textGroupBox.Row();
                tabsRow.Label("Tabs");
                tabsRow.NumericUpDown(x => x.Tabs, 0, 16);
                var marginUpRow = textGroupBox.Row();
                marginUpRow.Label("MarginUp");
                marginUpRow.NumericUpDown(x => x.MarginUp, 0, 1000);

                var fontRow = textGroupBox.Row();
                fontRow.Label("Font");
                fontRow.DropDown(x => x.FontFamily, Fonts.AvailableFontFamilies
                                 .Select(x => x.Name)
                                 .OrderBy(r => r)
                                 .ToDictionary(x => x));
                var sizeRow = textGroupBox.Row();
                sizeRow.Label("Size");
                sizeRow.NumericUpDown(x => x.Size, 1, 200);
                var colorRow = textGroupBox.Row();
                colorRow.Label("Color");
                colorRow.ColorPicker(x => x.Color);
                var decorationRow1 = textGroupBox.Row();
                decorationRow1.CheckBox("Bold", x => x.Bold);
                decorationRow1.CheckBox("Italic", x => x.Italic);
                var decorationRow2 = textGroupBox.Row();
                decorationRow2.CheckBox("Underline", x => x.Underline);
                decorationRow2.CheckBox("Strikethrough", x => x.Strikethrough);
                var highlightGroupRow = textGroupBox.Row();
                highlightGroupRow.Label("Highlight Group");
                highlightGroupRow.TextBox(x => x.HighlightGroup);

                var formulaRow = textGroupBox.Row();
                formulaRow.Button("Insert Formula", vm => vm.InsertFormula());
            }
            {
                var highlightOnMouseGroupBox = builder.Row().GroupBox("Highlight on Mouse", x => x.SearchComponent <HighlightOnMouseComponent>(), x => x != null).Table();
                var row = highlightOnMouseGroupBox.Row();
                row.Label("Group Name");
                row.TextBox(x => x.GroupName, x => x ?? "", x => string.IsNullOrEmpty(x) ? null : x);
            }
            {
                var circlePackingGroupBox = builder.Row().GroupBox("Circle Packing", x => x.SearchComponent <ICirclePackingComponent>(), x => x != null).Table();
                var shapeRow = circlePackingGroupBox.Row();
                shapeRow.Label("Shape");
                shapeRow.DropDown(x => x.ShapeName, new[] { "Square", "Circle", "Ellipse" }.ToDictionary(x => x));
                var radiusRow = circlePackingGroupBox.Row();
                radiusRow.Label("Radius");
                radiusRow.TextBox(x => x.CircleRadius);
                var maxCircles = circlePackingGroupBox.Row();
                maxCircles.Label("Max Circles");
                maxCircles.TextBox(x => x.MaxInitialCircles);
                var movementRateRow = circlePackingGroupBox.Row();
                movementRateRow.Label("Smoothness");
                movementRateRow.Slider(x => x.MovementRate, 0, 1, 32);
                var quakeRow = circlePackingGroupBox.Row();
                quakeRow.Label("Quake");
                quakeRow.Slider(x => x.RandomFactor, 0, 1, 32);
                var areaRow = circlePackingGroupBox.Row();
                areaRow.Label("Area");
                areaRow.Label(x => x.Area.ToString(CultureInfo.InvariantCulture));
                var numCirclesRow = circlePackingGroupBox.Row();
                numCirclesRow.Label(x => "Num Circles: " + x.CurrentNumCircles);
                numCirclesRow.Label(x => "Uppber Bound: " + x.MaxCircles);
                var iterPerBreakRow = circlePackingGroupBox.Row();
                iterPerBreakRow.Label("Iteractions per Display");
                iterPerBreakRow.TextBox(x => x.NumIterationPerBreak);
                var batchSizeRow = circlePackingGroupBox.Row();
                batchSizeRow.Label("Batch Size");
                batchSizeRow.TextBox(x => x.BatchSize);
                var resetRow = circlePackingGroupBox.Row();
                resetRow.Label("");
                resetRow.Button("Reset Circles", x => x.ResetPacker());
                var optimizeStepRow = circlePackingGroupBox.Row();
                optimizeStepRow.Label("");
                optimizeStepRow.Button("Optimize Step", x => x.OptimizeStep());
                var runOptimizeRow = circlePackingGroupBox.Row();
                runOptimizeRow.Label("");
                runOptimizeRow.Button("Run Optimization", x => x.RunOptimization());
                var stopOptimizeRow = circlePackingGroupBox.Row();
                stopOptimizeRow.Label("");
                stopOptimizeRow.Button("Stop Optimization", x => x.StopOptimization());
                var deleteCircleRow = circlePackingGroupBox.Row();
                deleteCircleRow.Label("");
                deleteCircleRow.Button("Delete Circle", x => x.DeleteCircle());
                var fillHodeRow = circlePackingGroupBox.Row();
                fillHodeRow.Button("Fill Hole (E)", x => x.TryFillHole(true));
                fillHodeRow.Button("Fill Hole (N)", x => x.TryFillHole(false));
            }
            {
                var circlePackingGroupBox = builder.Row().GroupBox("Circle Packing", x => x.SearchComponent <ICirclePackingAutoComponent>(), x => x != null).Table();
                var shapeRow = circlePackingGroupBox.Row();
                shapeRow.Label("Shape");
                shapeRow.DropDown(x => x.ShapeName, new[] { "Square", "Circle", "Ellipse" }.ToDictionary(x => x));
                var radiusRow = circlePackingGroupBox.Row();
                radiusRow.Label("Radius");
                radiusRow.TextBox(x => x.CircleRadius);
                var numCirclesRow = circlePackingGroupBox.Row();
                numCirclesRow.Label(x => "Num Circles: " + x.NumCircles);
                //numCirclesRow.Label(x => "Uppber Bound: " + x.MaxCircles);
                var attemptsPerDisplayRow = circlePackingGroupBox.Row();
                attemptsPerDisplayRow.Label("Attempts per Display");
                attemptsPerDisplayRow.TextBox(x => x.AttemptsPerRefresh);
                var statsRow = circlePackingGroupBox.Row();
                statsRow.Label(x => $"Seconds: {x.SecondsSinceLastSuccess:F} Attempts: {x.AttemptsSinceLastSuccess}");
                var resetRow = circlePackingGroupBox.Row();
                resetRow.Label("");
                resetRow.Button("Reset", x => x.Reset());
                var runOptimizeRow = circlePackingGroupBox.Row();
                runOptimizeRow.Label("");
                runOptimizeRow.Button("Run", x => x.Run());
                var stopOptimizeRow = circlePackingGroupBox.Row();
                stopOptimizeRow.Label("");
                stopOptimizeRow.Button("Stop", x => x.Stop());
                var deleteCircleRow = circlePackingGroupBox.Row();
            }
            {
                var componentsBuilder = builder.Row().GroupBox("Components", x => x, x => x != null).Table();
                // todo: to ArrayTable
                var componentsCache       = (IEnumerable <ISceneNodeComponent>)null;
                var componentsStringCache = "";
                componentsBuilder.Row().Label(n =>
                {
                    if (n.Components != componentsCache)
                    {
                        componentsCache       = n.Components;
                        componentsStringCache = string.Join("\n", n.Components.Select(c => c.AmInterface.Name));
                    }
                    return(componentsStringCache);
                });

                var newComponentViewModel    = new NewComponentViewModel(() => selectedSceneNode);
                var newComponentPanelBuilder = componentsBuilder.Row().Panel(x => newComponentViewModel, x => true).Table();
                var newComponentRow          = newComponentPanelBuilder.Row();
                newComponentRow.DropDown(x => x.ComponentType, new Dictionary <string, Type>
                {
                    ["Rotate Once"]        = typeof(RotateOnceComponent),
                    ["Highlight on Mouse"] = typeof(HighlightOnMouseComponent),
                    ["Warp Scrolling"]     = typeof(WarpScrollComponent),
                });
                newComponentRow.Button("Add", x =>
                {
                    componentsCache = null;
                    ISceneNodeComponent component;
                    if (x.ComponentType == typeof(RotateOnceComponent))
                    {
                        component = AmFactory.Create <RotateOnceComponent>();
                    }
                    else if (x.ComponentType == typeof(HighlightOnMouseComponent))
                    {
                        component = AmFactory.Create <HighlightOnMouseComponent>();
                    }
                    else if (x.ComponentType == typeof(WarpScrollComponent))
                    {
                        component = AmFactory.Create <WarpScrollComponent>();
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException();
                    }
                    newComponentViewModel.GetNode().Components.Add(component);
                    undoRedo.OnChange();
                });
            }
            builder.Row().Panel(x => x, x => true);

            rootControl = mainPanel;
            renderLoopDispatcher.AfterUpdate += Update;
        }
Exemple #21
0
        protected MovieRectangleComponent(Lazy <IMoviePlayer> moviePlayerLazy, Lazy <IAppModeService> appModeServiceLazy,
                                          IEmbeddedResources embeddedResources, IViewService viewService)
        {
            this.moviePlayerLazy    = moviePlayerLazy;
            this.appModeServiceLazy = appModeServiceLazy;

            var model        = embeddedResources.SimplePlaneXyModel();
            var mainMaterial = StandardMaterial.New(this)
                               .SetDiffuseColor(x => x.moviePlayback?.FrameImage != null ? Color4.White : Color4.Black)
                               .SetDiffuseMap(x => x.moviePlayback?.FrameImage)
                               .SetIgnoreLighting(true);

            visualElem = new ModelVisualElement <MovieRectangleComponent>(this)
                         .SetModel(model)
                         .SetMaterial(mainMaterial)
                         .SetTransform(x => Transform.Translation(new Vector3(x.Rectangle.Center, 0)))
                         .SetNonUniformScale(x => new Vector3(x.Rectangle.HalfWidth, x.Rectangle.HalfHeight, 1));

            progressBar = new ModelVisualElement <MovieRectangleComponent>(this)
                          .SetModel(model)
                          .SetMaterial(StandardMaterial.New()
                                       .SetDiffuseColor(Color4.Red)
                                       .SetIgnoreLighting(true)
                                       .FromGlobalCache())
                          .SetRenderState(StandardRenderState.New()
                                          .SetZOffset(GraphicsHelper.MinZOffset)
                                          .FromGlobalCache())
                          .SetTransform(x => Transform.Translation(new Vector3(
                                                                       x.Rectangle.MinX + x.Rectangle.HalfWidth * MovieRelativeLocation(),
                                                                       x.Rectangle.MinY + x.Rectangle.HalfHeight / BarHeightFactor, 0)))
                          .SetNonUniformScale(x => new Vector3(
                                                  x.Rectangle.HalfWidth * MovieRelativeLocation(),
                                                  x.Rectangle.HalfHeight / BarHeightFactor, 1))
                          .SetHide(x => !x.showMovieGui);

            var movieButtonTextures = AllButtonTextureNames
                                      .Select(x => embeddedResources.Image(GetMovieButtonTextureFileName(x.ToString())))
                                      .ToArray();

            movieButtonsMaterials = AllButtonTextureNames.Select(x =>
                                                                 StandardMaterial.New()
                                                                 .SetDiffuseMap(movieButtonTextures[(int)x])
                                                                 .SetIgnoreLighting(true))
                                    .Cast <IStandardMaterial>()
                                    .ToArray();

            movieButtonVisualElems = AllMovieButtons.Select(b => new ModelVisualElement <MovieRectangleComponent>(this)
                                                            .SetModel(model)
                                                            .SetMaterial(x => x.movieButtonsMaterials[(int)GetButtonTextureName(b)])
                                                            .SetRenderState(StandardRenderState.New()
                                                                            .SetZOffset(GraphicsHelper.MinZOffset)
                                                                            .FromGlobalCache())
                                                            .SetTransform(x => GetMovieButtonTransform((int)b, x.Rectangle))
                                                            .SetHide(x => !x.showMovieGui));

            movieSpeedTextures = StandardMoviePlayback.MovieSpeeds.Select(x =>
                                                                          embeddedResources.Image(GetMovieSpeedTextureFileName(x))).ToArray();

            movieSpeedVisualElem = new ModelVisualElement <MovieRectangleComponent>(this)
                                   .SetModel(model)
                                   .SetMaterial(StandardMaterial.New(this)
                                                .SetDiffuseMap(x => x.movieSpeedTextures[GetSpeedIndex(moviePlayback.GetVideoSpeed())]))
                                   .SetRenderState(StandardRenderState.New()
                                                   .SetZOffset(GraphicsHelper.MinZOffset))
                                   .SetTransform(x => GetMovieSpeedTransform(x.Rectangle))
                                   .SetHide(x => !x.showMovieGui);

            presentationInteractionElems = new IInteractionElement[]
            {
                new MoviePlaybackInteractionElement <MovieRectangleComponent>(this, x => x.moviePlayback),
                new LambdaInteractionElement(args =>
                {
                    if (!(args is MouseEvent mouseArgs))
                    {
                        return(true);
                    }
                    lastMouseEventTime = lastUpdateTime;

                    if (!mouseArgs.IsLeftClickEvent())
                    {
                        return(true);
                    }
                    if (!TryGetButton(mouseArgs, out var button))
                    {
                        return(true);
                    }
                    switch (button)
                    {
                    case MovieButton.Start:
                        moviePlayback.GoToStart();
                        break;

                    case MovieButton.FBwrd:
                        moviePlayback.PlaySlower();
                        break;

                    case MovieButton.Bwrd:
                        moviePlayback.ReverseDirection();
                        break;

                    case MovieButton.Play:
                        moviePlayback.UpdatePlayStatus();
                        break;

                    case MovieButton.FFrwd:
                        moviePlayback.PlayFaster();
                        break;

                    case MovieButton.End:
                        moviePlayback.GoToEnd();
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    // Process button click
                    return(true);
                })
            };

            hittable = new RectangleHittable <MovieRectangleComponent>(this, Transform.Identity,
                                                                       c => c.GetHittableRectangle(), c => 0);

            visualElems = new List <IVisualElement> {
                visualElem
            };
        }
 public EmbeddedResourceSource(IEmbeddedResources embeddedResources, EmbeddedResourceType resourceType, string path)
 {
     this.embeddedResources = embeddedResources;
     ResourceType           = resourceType;
     Path = path;
 }