private void BuildTileList(string searchStr = null) { int maxWidth = 0; int yOffset = 5; _tileList.components.Clear(); _tileList.ResetScrollbars(); Type type = typeof(Tile); List <Assembly> asses = AppDomain.CurrentDomain.GetAssemblies().ToList(); List <Type> types = asses.SelectMany(t => t.GetTypes()).Where(p => type.IsAssignableFrom(p) && !p.IsAbstract).ToList(); IEnumerable <string> rawNames = from a in types select a.Name; if (types.Count > 255) { throw new ArgumentOutOfRangeException("types.Count", "Can not load more than 255 types of tiles."); } List <string> typeNames = (searchStr == null) ? rawNames.ToList() : rawNames.Where(x => x.ToLower().Contains(searchStr.ToLower())).ToList(); if (searchStr != null) { _clearLabel.BackgroundColor = Color.LightGray; } foreach (string entry in typeNames) { var tileLabel = new Label(entry, "CALIBRI", _resourceManager); _tileList.components.Add(tileLabel); tileLabel.Position = new Point(5, yOffset); tileLabel.DrawBackground = true; tileLabel.DrawBorder = true; tileLabel.Update(0); yOffset += 5 + tileLabel.ClientArea.Height; tileLabel.Clicked += TileLabelClicked; if (tileLabel.ClientArea.Width > maxWidth) { maxWidth = tileLabel.ClientArea.Width; } } foreach (GuiComponent curr in _tileList.components.Where(curr => curr.GetType() == typeof(Label))) { ((Label)curr).FixedWidth = maxWidth; } }
private void BuildEntityList(string searchStr = null) { int maxWidth = 0; int yOffset = 5; _entityList.components.Clear(); _entityList.ResetScrollbars(); List <KeyValuePair <string, EntityTemplate> > templates = (searchStr == null) ? IoCManager.Resolve <IEntityManagerContainer>() .EntityManager.EntityTemplateDatabase. Templates.ToList() : IoCManager.Resolve <IEntityManagerContainer>() .EntityManager.EntityTemplateDatabase. Templates.Where( x => x.Value.Name.ToLower().Contains( searchStr.ToLower())).ToList(); if (searchStr != null) { _clearLabel.BackgroundColor = new SFML.Graphics.Color(211, 211, 211); } foreach ( EntitySpawnSelectButton newButton in templates.Select(entry => new EntitySpawnSelectButton(entry.Value, entry.Key, _resourceManager))) { _entityList.components.Add(newButton); newButton.Position = new Vector2i(5, yOffset); newButton.Update(0); yOffset += 5 + newButton.ClientArea.Height; newButton.Clicked += NewButtonClicked; if (newButton.ClientArea.Width > maxWidth) { maxWidth = newButton.ClientArea.Width; } } foreach ( GuiComponent curr in _entityList.components.Where(curr => curr.GetType() == typeof(EntitySpawnSelectButton))) { ((EntitySpawnSelectButton)curr).fixed_width = maxWidth; } }
private void BuildTileList(string searchStr = null) { int maxWidth = 0; int yOffset = 5; _tileList.components.Clear(); _tileList.ResetScrollbars(); var tileDefs = IoCManager.Resolve <ITileDefinitionManager>().Select(td => td.Name); if (!string.IsNullOrEmpty(searchStr)) { tileDefs = tileDefs.Where(s => s.IndexOf(searchStr, StringComparison.InvariantCultureIgnoreCase) >= 0); _clearLabel.BackgroundColor = new SFML.Graphics.Color(211, 211, 211); } foreach (string entry in tileDefs) { var tileLabel = new Label(entry, "CALIBRI", _resourceManager); _tileList.components.Add(tileLabel); tileLabel.Position = new Vector2i(5, yOffset); tileLabel.DrawBackground = true; tileLabel.DrawBorder = true; tileLabel.Update(0); yOffset += 5 + tileLabel.ClientArea.Height; tileLabel.Clicked += TileLabelClicked; if (tileLabel.ClientArea.Width > maxWidth) { maxWidth = tileLabel.ClientArea.Width; } } foreach (GuiComponent curr in _tileList.components.Where(curr => curr.GetType() == typeof(Label))) { ((Label)curr).FixedWidth = maxWidth; } }