public MenuWorld( I2DRenderUtilities twodRenderUtilities, IAssetManagerProvider assetManagerProvider, IBackgroundCubeEntityFactory backgroundCubeEntityFactory, ISkin skin) { this.m_2DRenderUtilities = twodRenderUtilities; this.AssetManager = assetManagerProvider.GetAssetManager(); this.m_BackgroundCubeEntityFactory = backgroundCubeEntityFactory; this.m_TitleFont = this.AssetManager.Get<FontAsset>("font.Title"); this.m_PlayerModel = this.AssetManager.Get<ModelAsset>("model.Character"); this.m_PlayerModelTexture = this.AssetManager.Get<TextureAsset>("model.CharacterTex"); this.Entities = new List<IEntity>(); this.m_CanvasEntity = new CanvasEntity(skin) { Canvas = new Canvas() }; this.m_CanvasEntity.Canvas.SetChild(this.m_TitleMenu = new TitleMenu()); // Don't add the canvas to the entities list; that way we can explicitly // order it's depth. }
private void LoadUserInterface(IGameContext gameContext) { var document = new XmlDocument(); document.LoadXml(_userInterfaceAsset.UserInterfaceData); var childNodes = document.DocumentElement?.ChildNodes; if (childNodes == null) { return; } foreach (var element in childNodes.OfType <XmlElement>()) { if (element.Name == "canvas") { if (_canvasEntity == null) { var root = ProcessElement(element); if (root is Canvas) { _canvasEntity = _kernel.Get <CanvasEntity>(_hierarchy.Lookup(gameContext.World)); _canvasEntity.Canvas = (Canvas)root; _canvasEntity.CanvasesEnabled = Enabled; } } else { throw new InvalidOperationException("User interface file declares more than one canvas."); } } else if (element.Name == "fragment") { _availableFragments[element.GetAttribute("name")] = element; } } }
public MultiplayerWorld(ISkin skin) { this.Entities = new List<IEntity>(); this.m_ServersListView = new ListView(); this.m_ServersListView.AddChild(new ServerListItem { Text = "Loading servers...", Valid = false }); this.m_ServersListView.SelectedItemChanged += this.ServersListViewOnSelectedItemChanged; var backButton = new Button { Text = "Back" }; backButton.Click += (sender, args) => this.m_GameContext.SwitchWorld<TitleWorld>(); var buttonContainer = new HorizontalContainer(); buttonContainer.AddChild(new EmptyContainer(), "*"); buttonContainer.AddChild(backButton, "100"); buttonContainer.AddChild(new EmptyContainer(), "*"); var verticalContainer = new VerticalContainer(); verticalContainer.AddChild(new EmptyContainer(), "*"); verticalContainer.AddChild(this.m_ServersListView, "370"); verticalContainer.AddChild(new EmptyContainer(), "10"); verticalContainer.AddChild(buttonContainer, "24"); verticalContainer.AddChild(new EmptyContainer(), "*"); var horizontalContainer = new HorizontalContainer(); horizontalContainer.AddChild(new EmptyContainer(), "*"); horizontalContainer.AddChild(verticalContainer, "300"); horizontalContainer.AddChild(new EmptyContainer(), "*"); var canvas = new Canvas(); canvas.SetChild(horizontalContainer); this.m_CanvasEntity = new CanvasEntity(skin, canvas); this.m_QueryServersThread = new Thread(this.QueryServers) { Name = "Query Servers", IsBackground = true }; this.m_QueryServersThread.Start(); }
public AssetManagerLayout( IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, IAssetLoader[] loaders, CanvasEntity canvasEntity) { this.m_CanvasEntity = canvasEntity; var toolbarContainer = new HorizontalContainer(); toolbarContainer.AddChild(new SingleContainer(), "*"); toolbarContainer.AddChild(this.Bake = new Button { Text = "Bake" }, "50"); toolbarContainer.AddChild(this.MarkDirty = new Button { Text = "Mark Dirty" }, "80"); var assetContainer = new VerticalContainer(); assetContainer.AddChild(toolbarContainer, "20"); assetContainer.AddChild(this.EditorContainer = new SingleContainer(), "*"); var contentContainer = new HorizontalContainer(); contentContainer.AddChild(this.AssetTree = new TreeView(), "210"); contentContainer.AddChild(assetContainer, "*"); var menuContainer = new VerticalContainer(); menuContainer.AddChild(this.MainMenu = new MainMenu(assetManagerProvider, renderUtilities), "24"); menuContainer.AddChild(contentContainer, "*"); menuContainer.AddChild(this.Status = new Label { Text = "..." }, "24"); this.SetChild(menuContainer); var exitItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = "Exit" }; var bakeAllItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = "Bake All" }; var assetManagerMenuItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = "Asset Manager" }; exitItem.Click += (sender, e) => { if (this.ExitClick != null) this.ExitClick(sender, e); }; bakeAllItem.Click += (sender, e) => { if (this.BakeAllClick != null) this.BakeAllClick(sender, e); (bakeAllItem.Parent as MenuItem).Active = false; }; assetManagerMenuItem.AddChild(bakeAllItem); assetManagerMenuItem.AddChild(exitItem); this.MainMenu.AddChild(assetManagerMenuItem); var newAssetMenuItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = "Create New..." }; foreach (var loader in loaders.Where(x => x.CanNew())) { var createNewMenuItem = new MenuItem(assetManagerProvider, renderUtilities) { Text = loader.GetType().Name }; createNewMenuItem.Click += (sender, e) => { if (this.PromptWindow == null) { this.PromptForCreation(loader.GetType().Name, (_, _2) => { if (this.CreateNameEntered != null) this.CreateNameEntered(this, new CreateEventArgs(loader)); }); } }; newAssetMenuItem.AddChild(createNewMenuItem); } this.MainMenu.AddChild(newAssetMenuItem); }
public AssetManagerWorld( IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, ISkin skin, IAssetLoader[] loaders) { this.Entities = new List<IEntity>(); this.m_Skin = skin; this.m_Start = DateTime.Now; // Add the asset manager layout. var entity = new CanvasEntity(this.m_Skin); this.m_Layout = new AssetManagerLayout(assetManagerProvider, renderUtilities, loaders, entity); entity.Canvas = this.m_Layout; this.Entities.Add(entity); this.m_Layout.MarkDirty.Click += (sender, e) => { foreach (var asset in this.AssetManager.GetAll()) this.AssetManager.Dirty(asset.Name); }; this.m_Layout.Bake.Click += (sender, e) => { if (this.m_CurrentEditor != null) this.m_CurrentEditor.Bake(this.AssetManager); var item = this.m_Layout.AssetTree.SelectedItem as AssetTreeItem; if (item == null) return; this.AssetManager.Bake(item.Asset); }; this.m_Layout.AssetTree.SelectedItemChanged += (sender, e) => { if (this.m_CurrentEditor != null) this.m_CurrentEditor.FinishLayout(this.m_Layout.EditorContainer, this.AssetManager); var item = this.m_Layout.AssetTree.SelectedItem as AssetTreeItem; if (item != null && m_Editors.ContainsKey(item.Asset.GetType())) { this.m_CurrentEditor = m_Editors[item.Asset.GetType()]; this.m_CurrentEditor.SetAsset(item.Asset); this.m_CurrentEditor.BuildLayout(this.m_Layout.EditorContainer, this.AssetManager); } else { this.m_CurrentEditor = null; this.m_Layout.EditorContainer.SetChild( new Label { Text = "No editor for " + (item == null ? "folders" : item.Asset.GetType().Name) }); } }; this.m_Layout.ExitClick += (sender, e) => { Environment.Exit(0); }; this.m_Layout.BakeAllClick += (sender, e) => { foreach (var asset in this.AssetManager.GetAll()) this.AssetManager.Bake(asset); }; this.m_Layout.CreateNameEntered += (sender, e) => { var asset = e.Loader.GetNew(this.AssetManager, this.m_Layout.PromptName.Text); assetManagerProvider.GetAssetManager(false).Bake(asset); this.m_Layout.AssetTree.AddChild(new AssetTreeItem { Text = this.m_Layout.PromptName.Text, Asset = asset }); }; }