private void OnNodeChanged(IStorageNetworkNode node)
 {
     if (node == (IStorageNetworkNode)_station)
     {
         InvalidateDemandBuildings();
         Invalidate();
     }
 }
Example #2
0
        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);
                        }
                    }
                }
            }
        }
 public void Initialize(VehicleStation station, IStorageNetworkNode connectedNode, bool deletable)
 {
     this._station       = station;
     this._connectedNode = connectedNode;
     this._deletable     = deletable;
     base.transform.Find <Image>("Thumb").sprite = this.GetThumbIcon();
     base.transform.GetComponent <Button>().onClick.AddListener(delegate()
     {
         GameCameraViewHelper.TryGoTo(this._connectedNode.Building, 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(deletable);
     Tooltip.For(this, null, BuildingHelper.GetBuildingName(connectedNode.Building), GetTooltipText, 0);
 }
Example #4
0
 public static void GetNodeDemands(IStorageNetworkNode node, Dictionary <Item, int> demands, Dictionary <Item, int> unservicedDemands = null)
 {
     if (node.Building is Store store)
     {
         AddCityDemand(store.Demand, demands);
         if (unservicedDemands != null && store.Demand.DeliveredCounter.Lifetime == 0)
         {
             //unserviced demand
             AddCityDemand(store.Demand, unservicedDemands);
         }
     }
     if (node.Building is Lab lab && lab.IsEnabled && lab.Research != null && !LazyManager <ResearchManager> .Current.IsCompleted(lab.Research))
     {
         AddLab(lab, demands);
     }
 }
Example #5
0
 public bool RemoveDemand(VehicleStationLocation location, IStorageNetworkNode demand)
 {
     if (location.IsDead)
     {
         return(false);
     }
     if (_additionalDemands.TryGetValue(location.VehicleStation, out UniqueList <IStorageNetworkNode> list))
     {
         bool result = list.QuickRemove(demand);
         if (result)
         {
             OnDemandChange(location.VehicleStation);
         }
         return(result);
     }
     return(false);
 }
Example #6
0
 public void OnNodeChange(IStorageNetworkNode node)
 {
     if (node.Building is VehicleStation station)
     {
         OnDemandChange(station);
         foreach (KeyValuePair <VehicleStation, UniqueList <VehicleStation> > pair in _connectedStations)
         {
             if (pair.Key == station)
             {
                 continue;
             }
             if (pair.Value.Contains(station))
             {
                 OnDemandChange(pair.Key);
             }
         }
     }
 }
Example #7
0
        public bool AddDemand(VehicleStationLocation location, IStorageNetworkNode demand)
        {
            if (demand is Store || demand is Lab)
            {
                if (DemandHelper.IsInBasicDemand(location.VehicleStation, demand))
                {
                    return(false);
                }
                _connectedBuildings.Add(demand.Building);
                bool result = GetOrCreateDemandsList(location.VehicleStation).Add(demand);
                if (result)
                {
                    OnDemandChange(location.VehicleStation);
                }
                return(result);
            }

            throw new ArgumentException("Only Store and Lab can be added as a station demand", nameof(demand));
        }
Example #8
0
 public static bool IsInBasicDemand(VehicleStation station, IStorageNetworkNode node)
 {
     return(GetBasicStationDemand(station).Contains(node));
 }