private StationWindowLogisticTabBuildingCountItem GetBuildingCountItem(List <StationWindowLogisticTabBuildingCountItem> items, int index, Transform parent) { if (index < items.Count) { return(items[index]); } if (_buildingCountItemsTemplate == null) { CreateBuildingCountItemTemplate(); } StationWindowLogisticTabBuildingCountItem result = Instantiate(_buildingCountItemsTemplate, parent); return(result); }
private void InvalidateNeededFactories() { List <StationWindowLogisticTabBuildingCountItem> items = new(); _factoriesItemsContainer.GetComponentsInChildren(true, items); int count = 0; //mines IReadOnlyDictionary <Item, TransferData> transfers = LastTransfers; RecipeHelper helper = LazyManager <RecipeHelper> .Current; foreach (KeyValuePair <Item, float> itemAmount in NeededItems) { if (itemAmount.Value < 0.1 || (transfers.TryGetValue(itemAmount.Key, out TransferData data) && data.unload > 0)) { continue; } (int?itemPerMonth, Mine mine) = helper.GetMinedItemsPerMineAndMonth(itemAmount.Key); if (itemPerMonth.HasValue) { StationWindowLogisticTabBuildingCountItem item = GetBuildingCountItem(items, count, _factoriesItemsContainer); item.Initialize(_station, mine, null, itemAmount.Value / itemPerMonth.Value, itemAmount.Key); item.gameObject.SetActive(true); count++; } } Dictionary <(Device device, Recipe recipe), float> factoriesNeeded = FactoriesNeeded; //devices foreach (KeyValuePair <(Device device, Recipe recipe), float> deviceAmount in (from f in factoriesNeeded orderby f.Key.device.DisplayName.ToString(), f.Key.recipe.DisplayName.ToString() select f)) { if (deviceAmount.Value > 0.01) { StationWindowLogisticTabBuildingCountItem item = GetBuildingCountItem(items, count, _factoriesItemsContainer); item.Initialize(_station, deviceAmount.Key.device, deviceAmount.Key.recipe, deviceAmount.Value); item.gameObject.SetActive(true); count++; } } _factoriesContainer.gameObject.SetActive(count > 0); for (; count < items.Count; count++) { items[count].gameObject.SetActive(false); } }