public SceneTreeGui(IEventRoutingService eventRoutingService, IWorldTreeService worldTreeService, IViewService viewService, IPresentationGuiCommands commands, ICommonGuiObjects commonGuiObjects) { itemIndex = new Dictionary <ISceneNode, TreeItem>(); this.worldTreeService = worldTreeService; this.viewService = viewService; this.commands = commands; eyeIcon = Icon.FromResource("Clarity.Ext.Gui.EtoForms.Resources.eye_icon.ico"); sceneIcon = Icon.FromResource("Clarity.Ext.Gui.EtoForms.Resources.scene_icon.ico"); viewIcon = Icon.FromResource("Clarity.Ext.Gui.EtoForms.Resources.view_icon.ico"); layoutIcon = Icon.FromResource("Clarity.Ext.Gui.EtoForms.Resources.layout_icon.ico"); entityIcon = Icon.FromResource("Clarity.Ext.Gui.EtoForms.Resources.entity_icon.ico"); whiteIcon = Icon.FromResource("Clarity.Ext.Gui.EtoForms.Resources.white_icon.ico"); rootItem = new TreeItem { Text = "GuiRoot", Expanded = true }; treeView = new TreeView { Width = 250, DataStore = rootItem, ContextMenu = commonGuiObjects.SelectionContextMenu }; //RebuildFromRoot(); eventRoutingService.RegisterServiceDependency(typeof(ISceneTreeGui), typeof(IWorldTreeService)); eventRoutingService.Subscribe <IWorldTreeUpdatedEvent>(typeof(ISceneTreeGui), nameof(OnWorldUpdated), OnWorldUpdated); eventRoutingService.Subscribe <IAppModeChangedEvent>(typeof(ISceneTreeGui), nameof(OnAppModeChanged), OnAppModeChanged); treeView.SelectionChanged += OnSelectionChanged; treeView.NodeMouseClick += OnNodeMouseClick; treeView.MouseDoubleClick += OnNodeMouseDoubleClick; viewService.Update += OnViewServiceUpdate; }
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); } }) }