public void RebuildInventoryView(int maxSlots, List <Entity> entities) { int currX = 0; int currY = 0; const int spacing = 50; const int xOffset = 12; const int yOffset = 5; _inventoryContainer.components.Clear(); foreach (Entity entity in entities) { var slot = new InventorySlotUi(entity, _resourceManager) { Position = new Point(currX * spacing + xOffset, currY * spacing + yOffset) }; slot.Clicked += SlotClicked; _inventoryContainer.components.Add(slot); currX++; if (currX < 5) { continue; } currX = 0; currY++; } for (int i = 0; i < (maxSlots - entities.Count); i++) { var slot = new InventorySlotUi(null, _resourceManager) { Position = new Point(currX * spacing + xOffset, currY * spacing + yOffset) }; slot.Clicked += SlotClicked; _inventoryContainer.components.Add(slot); currX++; if (currX < 5) { continue; } currX = 0; currY++; } _inventoryContainer.ResetScrollbars(); }
private void BuildTileList(string searchStr = null) { _tileList.Container.DisposeAllChildren(); _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 Color4(211, 211, 211, 255); } var maxWidth = 0; Control lastControl = _tileList.Container; foreach (var entry in tileDefs) { var tileLabel = new Label(entry, "CALIBRI"); tileLabel.Parent = lastControl; if (!(lastControl is Label)) // if first loop { tileLabel.LocalPosition = new Vector2i(5, 0); } else { tileLabel.LocalPosition = new Vector2i(0, 5); } lastControl = tileLabel; tileLabel.Alignment = Align.Bottom; tileLabel.BackgroundColor = Color4.Gray; tileLabel.DrawBackground = true; tileLabel.DrawBorder = true; tileLabel.Update(0); tileLabel.DoLayout(); tileLabel.Clicked += TileLabelClicked; if (tileLabel.ClientArea.Width > maxWidth) { maxWidth = tileLabel.ClientArea.Width; } } foreach (var curr in _tileList.Container.Children.Where(curr => curr.GetType() == typeof(Label))) { ((Label)curr).FixedWidth = maxWidth; } }
private void BuildEntityList(string searchStr = null) { _entityList.Container.DisposeAllChildren(); _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 Color(211, 211, 211, 255); } var maxWidth = 0; Control lastControl = _entityList.Container; foreach (var newButton in templates.Select(entry => new EntitySpawnSelectButton(entry.Value, entry.Key))) { lastControl.AddControl(newButton); lastControl = newButton; newButton.FixedWidth = _entityList.Width; newButton.Alignment = ControlAlignments.Bottom; newButton.DoLayout(); newButton.Clicked += NewButtonClicked; if (newButton.ClientArea.Width > maxWidth) { maxWidth = newButton.ClientArea.Width; } } }