private void BuildEntityList(string searchStr = null) { int maxWidth = 0; int yOffset = 5; _entityList.components.Clear(); _entityList.ResetScrollbars(); var manager = IoCManager.Resolve <IPrototypeManager>(); IEnumerable <KeyValuePair <string, EntityPrototype> > templates; if (searchStr == null) { templates = manager.EnumeratePrototypes <EntityPrototype>() .Select(p => new KeyValuePair <string, EntityPrototype>(p.ID, p)); } else { var searchStrLower = searchStr.ToLower(); templates = manager.EnumeratePrototypes <EntityPrototype>() .Where(p => p.ID.ToLower().Contains(searchStrLower)) .Select(p => new KeyValuePair <string, EntityPrototype>(p.ID, p)); } 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, _resourceCache))) { _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; } }