/// <summary> /// The Initialize. /// </summary> /// <param name="station">The station<see cref="VehicleStation"/>.</param> /// <param name="building">The building<see cref="Building"/>.</param> /// <param name="recipe">The recipe<see cref="Recipe"/>.</param> /// <param name="count">The count<see cref="float"/>.</param> /// <param name="item">The item<see cref="Item"/>.</param> public void Initialize(VehicleStation station, Building building, Recipe recipe, float count, Item item = null) { this._station = station; this._building = building; this._count = Mathf.Ceil(count * 10) / 10; this._recipe = recipe; this._item = item; base.transform.Find <Image>("Thumb").sprite = this.GetThumbIcon(); Image image = base.transform.Find <Image>("ItemImage"); if (this._recipe != null) { _item = this._recipe.OutputItems[0].Item; } if (_item != null) { image.sprite = GetItemIcon(); image.gameObject.SetActive(true); } else { image.gameObject.SetActive(false); } this._settingsCog = base.transform.Find <Button>("ConnectionCog"); this._valueText = base.transform.Find <Text>("ValueContainer/Value"); this._valueText.text = _count.ToString("N1"); this._valueText.transform.parent.gameObject.SetActive(true); // VoxelTycoon.UI.ContextMenu.For(this._settingsCog, PickerBehavior.OverlayToRight, new Action<VoxelTycoon.UI.ContextMenu>(this.SetupContextMenu)); this.SetSettingsCogVisibility(false); Tooltip.For(this, null, BuildingHelper.GetBuildingName(_building), GetTooltipText, 0); }
/** Returns total demands for selected station and its connected stations */ public Dictionary <Item, int> GetCombinedStationsDemands(VehicleStation station, Dictionary <Item, int> demandsList = null, Dictionary <Item, int> unservicedDemands = null) { Dictionary <Item, int> result = demandsList ?? new Dictionary <Item, int>(); DemandHelper.GetNodesDemands(GetDemandNodes(station), result, unservicedDemands); return(result); }
public IEnumerable <IStorageNetworkNode> GetCombinedStationDemandNodesEnum(VehicleStation station, bool additionalDemands = true) { foreach (IStorageNetworkNode node in GetDemandNodes(station, additionalDemands)) { yield return(node); } }
public ImmutableUniqueList <IStorageNetworkNode>?GetAdditionalDemands(VehicleStation station) { if (_additionalDemands.TryGetValue(station, out UniqueList <IStorageNetworkNode> demands)) { return(demands.ToImmutableUniqueList()); } return(null); }
public ImmutableUniqueList <VehicleStation>?GetConnectedStations(VehicleStation station) { if (_connectedStations.TryGetValue(station, out UniqueList <VehicleStation> stations)) { return(stations.ToImmutableUniqueList()); } return(null); }
public static List <IStorageNetworkNode> GetBasicStationDemand(VehicleStation station) { List <IStorageNetworkNode> targetNodes = new List <IStorageNetworkNode>(); List <IStorageNetworkNode> sourceNodes = new List <IStorageNetworkNode>(); station.GetConnectedNodes(targetNodes, sourceNodes); return(targetNodes); }
private UniqueList <IStorageNetworkNode> GetOrCreateDemandsList(VehicleStation station) { if (!_additionalDemands.TryGetValue(station, out UniqueList <IStorageNetworkNode> demandList)) { demandList = new UniqueList <IStorageNetworkNode>(); _additionalDemands.Add(station, demandList); } return(demandList); }
private UniqueList <VehicleStation> GetOrCreateConnectedStationsList(VehicleStation station) { if (!_connectedStations.TryGetValue(station, out UniqueList <VehicleStation> stationList)) { stationList = new UniqueList <VehicleStation>(); _connectedStations.Add(station, stationList); } return(stationList); }
public static Dictionary <Item, int> GetStationDemands(VehicleStation station, Dictionary <Item, int> demandsList = null, Dictionary <Item, int> unservicedDemands = null, bool additionalDemands = true) { Dictionary <Item, int> result = demandsList ?? new Dictionary <Item, int>(); foreach (IStorageNetworkNode node in GetStationDemandNodes(station, additionalDemands)) { GetNodeDemands(node, result, unservicedDemands); } return(result); }
public IEnumerable <IStorageNetworkNode> GetAdditionalDemandsEnum(VehicleStation station) { if (_additionalDemands.TryGetValue(station, out UniqueList <IStorageNetworkNode> demands)) { for (int i = 0; i < demands.Count; i++) { yield return(demands[i]); } } yield break; }
internal void Read(StateBinaryReader reader) { _connectedBuildings.Clear(); _additionalDemands.Clear(); _connectedStations.Clear(); if (ScheduleStopwatch.GetSchemaVersion(typeof(StationDemandManager)) >= 3) { int count = reader.ReadInt(); for (int i = 0; i < count; i++) { VehicleStation station = reader.ReadBuilding <VehicleStation>(); UniqueList <IStorageNetworkNode> demandList = null; int countList = reader.ReadInt(); if (countList > 0 && station != null) { demandList = GetOrCreateDemandsList(station); } for (int j = 0; j < countList; j++) { IStorageNetworkNode node = reader.ReadBuilding <Building>() as IStorageNetworkNode; if (demandList != null && node != null) { demandList.Add(node); _connectedBuildings.Add(node.Building); } } } count = reader.ReadInt(); for (int i = 0; i < count; i++) { VehicleStation station = reader.ReadBuilding <VehicleStation>(); UniqueList <VehicleStation> stationList = null; int countList = reader.ReadInt(); if (countList > 0 && station != null) { stationList = GetOrCreateConnectedStationsList(station); } for (int j = 0; j < countList; j++) { VehicleStation connStation = reader.ReadBuilding <VehicleStation>(); if (stationList != null && connStation != null) { stationList.Add(connStation); _connectedBuildings.Add(connStation); } } } } }
private HashSet <IStorageNetworkNode> GetDemandNodes(VehicleStation station, bool additionalDemands = true) { if (!_demandNodesCache.TryGetValue((station, additionalDemands), out HashSet <IStorageNetworkNode> result)) { result = new HashSet <IStorageNetworkNode>(DemandHelper.GetStationDemandNodes(station, additionalDemands)); foreach (VehicleStation addStation in GetConnectedStationsEnum(station)) { result.UnionWith(DemandHelper.GetStationDemandNodes(addStation, false, false)); } _demandNodesCache.Add((station, additionalDemands), result); } return(result); }
public bool RemoveConnectedStation(VehicleStation station, VehicleStation stationToRemove) { if (_connectedStations.TryGetValue(station, out UniqueList <VehicleStation> list)) { bool result = list.QuickRemove(stationToRemove); if (result) { OnConnectedStationChange(station); } return(result); } return(false); }
public void Initialize(VehicleStation station, VehicleStation connectedStation) { this._station = station; this._connectedStation = connectedStation; base.transform.Find <Image>("Thumb").sprite = this.GetThumbIcon(); base.transform.GetComponent <Button>().onClick.AddListener(delegate() { GameCameraViewHelper.TryGoTo(this._connectedStation, 70f); }); this._settingsCog = base.transform.Find <Button>("ConnectionCog"); VoxelTycoon.UI.ContextMenu.For(this._settingsCog, PickerBehavior.OverlayToRight, new Action <VoxelTycoon.UI.ContextMenu>(this.SetupContextMenu)); this.SetSettingsCogVisibility(true); Tooltip.For(this, null, BuildingHelper.GetBuildingName(connectedStation), "", 0); }
public void Initialize(VehicleStation station) { this._station = station; Locale locale = LazyManager <LocaleManager> .Current.Locale; this._demandBuildingNodesGrid = base.transform.Find <ScrollRect>("Head/DemandBuildingNodes/ScrollView").content; Transform buttonCont = Instantiate <Transform>(GetAddButtonTemplate(), this._demandBuildingNodesGrid); buttonCont.name = "AddDemandButton"; _addDemandButton = buttonCont.Find <Button>("Button"); _addDemandButton.onClick.AddListener(delegate() { UIManager.Current.SetTool(new DemandPickerTool() { OnBuildingPicked = OnDemandPicked, DisabledNodes = new HashSet <IStorageNetworkNode>(LazyManager <StationDemandManager> .Current.GetCombinedStationDemandNodesEnum(station, true)) }, false); }); Tooltip.For(_addDemandButton, locale.GetString("schedule_stopwatch/add_new_demand_tooltip")); this._connectedStationsGrid = base.transform.Find <ScrollRect>("Head/ConnectedStations/ScrollView").content; Transform stationButtonCont = Instantiate <Transform>(GetAddButtonTemplate(), this._connectedStationsGrid); stationButtonCont.name = "AddStationButton"; _addStationButton = stationButtonCont.Find <Button>("Button"); _addStationButton.onClick.AddListener(delegate() { UIManager.Current.SetTool(new StationPickerTool() { OnStationPicked = OnStationPicked, DisabledStations = LazyManager <StationDemandManager> .Current.GetConnectedStationsHashset(station, true) }, false); }); Tooltip.For(_addStationButton, locale.GetString("schedule_stopwatch/connect_station_tooltip")); Transform bodyContent = base.transform.Find("Body/WindowScrollView").GetComponent <ScrollRect>().content; _demandedContainer = bodyContent.Find("DemandedItems"); Tooltip.For(_demandedContainer.Find("Label"), locale.GetString("schedule_stopwatch/demanded_items_tooltip")); _demandedItemsContainer = _demandedContainer.Find("Content"); _productionNeededContainer = bodyContent.Find("NeededItems"); Tooltip.For(_productionNeededContainer.Find("Label"), locale.GetString("schedule_stopwatch/needed_items_tooltip")); _productionNeededItemsContainer = _productionNeededContainer.Find("Content"); _factoriesContainer = bodyContent.Find("NeededFactories"); Tooltip.For(_factoriesContainer.Find("Label"), locale.GetString("schedule_stopwatch/needed_factories_tooltip")); _factoriesItemsContainer = _factoriesContainer.Find <ScrollRect>("ScrollView").content; }
private void ToggleDefaultTint(bool on) { ImmutableList <VehicleStation> allStations = LazyManager <BuildingManager> .Current.GetAll <VehicleStation>(); for (int i = 0; i < allStations.Count; i++) { VehicleStation station = allStations[i]; if (DisabledStations?.Contains(station) == true) { continue; } LazyManager <BuildingTintManager> .Current.SetDefaultColor(station, on?new Color?(GameColors.WhiteModeCompanyTintColor) : null); station.SetTint(null); } }
public HashSet <VehicleStation> GetConnectedStationsHashset(VehicleStation station, bool includeOwnStation = true) { HashSet <VehicleStation> result = new HashSet <VehicleStation>(); if (includeOwnStation) { result.Add(station); } if (_connectedStations.TryGetValue(station, out UniqueList <VehicleStation> stations)) { for (int i = 0; i < stations.Count; i++) { result.Add(stations[i]); } } return(result); }
public IEnumerable <VehicleStation> GetConnectedStationsEnum(VehicleStation station, bool includeOwnStation = false) { if (includeOwnStation) { yield return(station); } if (_connectedStations.TryGetValue(station, out UniqueList <VehicleStation> stations)) { for (int i = stations.Count - 1; i >= 0; i--) { VehicleStation connectedStation = stations[i]; if (ReferenceEquals(connectedStation, null) || !connectedStation.IsBuilt) { stations.QuickRemoveAt(i); continue; } yield return(connectedStation); } } }
public bool AddConnectedStation(VehicleStation station, VehicleStation stationToAdd) { if (stationToAdd != station) { _connectedBuildings.Add(stationToAdd); bool result = GetOrCreateConnectedStationsList(station).Add(stationToAdd); if (result) { if (_additionalDemands.TryGetValue(station, out UniqueList <IStorageNetworkNode> additionalDemands)) { //remove demands of added station from additional demands of own station foreach (IStorageNetworkNode node in DemandHelper.GetStationDemandNodes(stationToAdd, false)) { additionalDemands.QuickRemove(node); } } OnConnectedStationChange(station); } return(result); } return(false); }
public static IEnumerable <IStorageNetworkNode> GetStationDemandNodes(VehicleStation station, bool additionalDemands = true, bool includeDisabled = false) { List <IStorageNetworkNode> targetNodes = new List <IStorageNetworkNode>(); List <IStorageNetworkNode> sourceNodes = new List <IStorageNetworkNode>(); station.GetConnectedNodes(targetNodes, sourceNodes); StorageNetworkManager manager = LazyManager <StorageNetworkManager> .Current; foreach (IStorageNetworkNode node in targetNodes) { if (includeDisabled || manager.GetIsEnabled(station, node) && (node is Store || node is Lab)) { yield return(node); } } if (additionalDemands) { foreach (IStorageNetworkNode node in LazyManager <StationDemandManager> .Current.GetAdditionalDemandsEnum(station)) { yield return(node); } } yield break; }
public static HashSet <IStorageNetworkNode> GetStationDemandNodesHashSet(VehicleStation station, bool additionalDemands = true, bool includeDisabled = false) { return(new HashSet <IStorageNetworkNode>(GetStationDemandNodes(station, additionalDemands, includeDisabled))); }
private void OnStationPicked(VehicleStation station) { StationDemandManager manager = LazyManager <StationDemandManager> .Current; manager.AddConnectedStation(_station, station); }
/// <summary> /// The GetEstimatatedNeededItems. /// </summary> /// <param name="station">The station<see cref="VehicleStation"/>.</param> /// <param name="transfers">The transfers<see cref="IReadOnlyDictionary{Item, TransferData}"/>.</param> /// <param name="neededItemsPerItem">The neededItemsPerItem<see cref="Dictionary{Item, Dictionary{Item, float}}"/>.</param> /// <param name="demands">The demands<see cref="Dictionary{Item, int}"/>.</param> /// <returns>The <see cref="Dictionary{Item, float}"/>.</returns> public Dictionary <Item, float> GetEstimatatedNeededItems(VehicleStation station, IReadOnlyDictionary <Item, TransferData> transfers, out Dictionary <Item, Dictionary <Item, float> > neededItemsPerItem, out Dictionary <Item, int> demands, Dictionary <Recipe, float> recipesNeeded = null) { Dictionary <Item, float> neededItems = new Dictionary <Item, float>(); neededItemsPerItem = new Dictionary <Item, Dictionary <Item, float> >(); demands = null; if (transfers.Count == 0) { return(neededItems); } List <Item> finalItems = new List <Item>(); foreach (KeyValuePair <Item, TransferData> pair in transfers) { if (pair.Value.unload > 0) { finalItems.Add(pair.Key); } } RecipeHelper helper = LazyManager <RecipeHelper> .Current; Settings settings = Settings.Current; Dictionary <Item, int> itemsForCalculation = new Dictionary <Item, int>(); Dictionary <Item, int> unservicedDemands = settings.CalculateUnservicedDemands ? null : new Dictionary <Item, int>(); RecipeHelper.AddItems(itemsForCalculation, transfers, TransferDirection.loading); if (station != null) { demands = new Dictionary <Item, int>(); LazyManager <StationDemandManager> .Current.GetCombinedStationsDemands(station, demands, unservicedDemands); if (demands.Count > 0) { RecipeHelper.AddItems(itemsForCalculation, demands); } } foreach (KeyValuePair <Item, int> pair in itemsForCalculation) { Dictionary <Item, float> subNeededItems = neededItemsPerItem[pair.Key] = new Dictionary <Item, float>(); List <RecipeItem> ingredients = null; bool isUnserviced = unservicedDemands != null && unservicedDemands.TryGetValue(pair.Key, out int unservicedCount) && unservicedCount == pair.Value; if (!isUnserviced && (!transfers.TryGetValue(pair.Key, out TransferData transfData) || transfData.unload == 0)) { //calculate ingredients only for items that are not unloaded at the station ingredients = helper.GetIngredients(pair.Key, finalItems, pair.Value, recipesNeeded); } if (ingredients != null && ingredients.Count > 0) { AddIngredients(ingredients, neededItems); AddIngredients(ingredients, subNeededItems); } else { //no ingredients = raw item / item is transferred (unloaded and loaded) / unserviced demand, we add it to needed items if (!neededItems.TryGetValue(pair.Key, out float count)) { count = 0; } neededItems[pair.Key] = count + pair.Value; subNeededItems[pair.Key] = pair.Value; } } return(neededItems); }
public static void GetStationDemandNodesHashSet(HashSet <IStorageNetworkNode> demandNodes, VehicleStation station, bool additionalDemands = true, bool includeDisabled = false) { foreach (IStorageNetworkNode node in GetStationDemandNodes(station, additionalDemands, includeDisabled)) { demandNodes.Add(node); } }
private bool CanPick(VehicleStation station) { return(DisabledStations?.Contains(station) == false); }
public void OnConnectedStationChange(VehicleStation station) { _demandNodesCache.Remove((station, true)); _demandNodesCache.Remove((station, false)); ConnectedStationChange?.Invoke(station.Location); }
public bool OnUpdate() { bool key = LazyManager <InputManager> .Current.GetKey(LazyManager <VoxelTycoon.Settings> .Current.MultipleModeKey); if (this._deactivate && !key) { return(true); } VehicleStation station = null; if (!InputHelper.OverUI) { station = ObjectRaycaster.Get <VehicleStation>(); } if (station != null) { if (this._station != station) { if (this._station != null) { this._station.SetTint(null); } this._station = station; this._canPick = this.CanPick(station); if (_canPick) { this._tooltip.Background = new PanelColor(ReadyToPickTooltipColor, 0f); this._tooltip.Text = LazyManager <LocaleManager> .Current.Locale.GetString("schedule_stopwatch/add_connected_station"); } else { this._tooltip.Background = new PanelColor(WrongReadyToPickHighlightColor, 0f); this._tooltip.Text = LazyManager <LocaleManager> .Current.Locale.GetString("schedule_stopwatch/already_added"); station.SetTint(new Color?(WrongReadyToPickHighlightColor)); } } if (_canPick) { UIManager.Current.SetCursor(Cursors.Pointer); if (InputHelper.WorldMouseDown) { this.OnStationPicked?.Invoke(station); Manager <SoundManager> .Current.PlayOnce(R.Audio.Click, null); if (!key) { return(true); } this._deactivate = true; } } } else { if (this._station != null) { this._station.SetTint(null); this._station = null; } this._tooltip.Background = new PanelColor(PickingTooltipColor, 0f); this._tooltip.Text = LazyManager <LocaleManager> .Current.Locale.GetString("schedule_stopwatch/pick_station"); } this._tooltip.RectTransform.anchoredPosition = (new Vector2(Input.mousePosition.x, Input.mousePosition.y) + new Vector2(-10f, -16f)) / UIManager.Current.Scale; this._tooltip.ClampPositionToScreen(); return(InputHelper.MouseDown && !key); }
public void OnDemandChange(VehicleStation station) { _demandNodesCache.Remove((station, true)); _demandNodesCache.Remove((station, false)); DemandChange?.Invoke(station); }
public (IReadOnlyDictionary <Item, TransferData> tranfers, bool incompleteTransfers, bool estimatedTransfers) GetTransfers(VehicleStation station) { TaskTransfers transfersSum = new TaskTransfers(); bool incompleteTransfers = false; bool estimatedTransfers = false; foreach (VehicleStation connStation in LazyManager <StationDemandManager> .Current.GetConnectedStationsEnum(station, true)) { ImmutableList <Vehicle> vehicles = LazyManager <VehicleStationLocationManager> .Current.GetServicedVehicles(connStation.Location); Manager <VehicleScheduleDataManager> .Current.GetStationTaskTransfersSum(vehicles, connStation.Location, out bool incomplTransf, out bool isEstimated, transfersSum); incompleteTransfers |= incomplTransf; estimatedTransfers |= isEstimated; } return(transfersSum.Transfers, incompleteTransfers, estimatedTransfers); }
public static bool IsInBasicDemand(VehicleStation station, IStorageNetworkNode node) { return(GetBasicStationDemand(station).Contains(node)); }