Beispiel #1
0
 private void EnsureCitizenUnits()
 {
     Vehicle[] buffer = Singleton <VehicleManager> .instance.m_vehicles.m_buffer;
     for (int index = 0; index < buffer.Length; ++index)
     {
         if (buffer[index].m_flags != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive))
         {
             VehicleInfo info = buffer[index].Info;
             if (!((UnityEngine.Object)info == (UnityEngine.Object)null) && info.m_prefabDataIndex == this.PrefabDataIndex)
             {
                 PrefabData.EnsureCitizenUnits((ushort)index, ref buffer[index], this.Capacity);
             }
         }
     }
 }
Beispiel #2
0
        public void AddItem(PrefabData data, ushort vehicleID = 0)
        {
            VehicleListBoxRow[] vehicleListBoxRowArray = new VehicleListBoxRow[this._items.Length + 1];
            Array.Copy((Array)this._items, (Array)vehicleListBoxRowArray, this._items.Length);
            VehicleListBoxRow vehicleListBoxRow = this._scrollablePanel.AddUIComponent <VehicleListBoxRow>();

            if ((UnityEngine.Object) this.Font != (UnityEngine.Object)null)
            {
                vehicleListBoxRow.Font = this.Font;
            }
            vehicleListBoxRow.Prefab                   = data;
            vehicleListBoxRow.VehicleID                = vehicleID;
            vehicleListBoxRow.eventMouseDown          += new MouseEventHandler(this.OnMouseDown);
            vehicleListBoxRowArray[this._items.Length] = vehicleListBoxRow;
            this._items = vehicleListBoxRowArray;
        }
        private void OnApplyButtonClick(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (this._selectedIndex <= -1)
            {
                return;
            }
            UITextField uiTextField1 = this._rightSidePanel.Find <UITextField>("Capacity");
            UITextField uiTextField2 = this._rightSidePanel.Find <UITextField>("MaintenanceCost");
            UITextField uiTextField4 = this._rightSidePanel.Find <UITextField>("MaxSpeed");
            UICheckBox  uiCheckBox   = this._rightSidePanel.Find <UICheckBox>("EngineOnBothEnds");
            PrefabData  prefab       = GetPrefabs()[this._selectedIndex];
            int         capacity     = Utils.ToInt32(uiTextField1.text) / prefab.CarCount;
            int         int32_1      = Utils.ToInt32(uiTextField2.text);
            int         int32_3      = Utils.ToInt32(uiTextField4.text);
            bool        isChecked    = uiCheckBox.isChecked;

            prefab.SetValues(capacity, int32_1, int32_3, isChecked);
            this.UpdateBindings();
        }
        private void Update()
        {
            if (!this._initialized)
            {
                this._cityServiceWorldInfoPanel = GameObject.Find("(Library) CityServiceWorldInfoPanel").GetComponent <CityServiceWorldInfoPanel>();
                if (!((UnityEngine.Object) this._cityServiceWorldInfoPanel != (UnityEngine.Object)null))
                {
                    return;
                }
                this.CreateStopsPanel();
                this._initialized = true;
            }
            else
            {
                if (!this._initialized || !this._cityServiceWorldInfoPanel.component.isVisible)
                {
                    return;
                }
                BuildingManager      instance1  = Singleton <BuildingManager> .instance;
                ushort               building   = Utils.GetPrivate <InstanceID>((object)this._cityServiceWorldInfoPanel, "m_InstanceID").Building;
                ItemClass.SubService subService = instance1.m_buildings.m_buffer[(int)building].Info.GetSubService();
                ItemClass.Service    service    = instance1.m_buildings.m_buffer[(int)building].Info.GetService();
                ItemClass.Level      level      = instance1.m_buildings.m_buffer[(int)building].Info.GetClassLevel();

                switch (subService)
                {
                case ItemClass.SubService.PublicTransportBus:
                case ItemClass.SubService.PublicTransportMetro:
                case ItemClass.SubService.PublicTransportTrain:
                case ItemClass.SubService.PublicTransportShip:
                case ItemClass.SubService.PublicTransportPlane:
                case ItemClass.SubService.PublicTransportMonorail:
                    this._vehicleListBox.Hide(); //TODO(earalov): display depot's vehicles? Also, maybe it makes sense to display list of lines served by depot?
                    this._stopsListBox.Show();
                    ushort[] numArray = PanelExtenderCityService.GetStationStops(building);
                    BuildingInfo.SubInfo[] subBuildings = instance1.m_buildings.m_buffer[(int)building].Info.m_subBuildings;
                    if (subBuildings != null && subBuildings.Length != 0)
                    {
                        Vector3 position = instance1.m_buildings.m_buffer[(int)building].m_position;
                        building = instance1.FindBuilding(position, 100f, ItemClass.Service.PublicTransport, ItemClass.SubService.None, Building.Flags.Untouchable, Building.Flags.None);
                        if ((int)building != 0)
                        {
                            ushort[] stationStops = PanelExtenderCityService.GetStationStops(building);
                            if (stationStops.Length != 0)
                            {
                                numArray = ((IEnumerable <ushort>)numArray).Concat <ushort>((IEnumerable <ushort>)stationStops).ToArray <ushort>();
                            }
                        }
                    }
                    int length = numArray.Length;
                    if (length > 0)
                    {
                        this._titleLabel.text = Localization.Get("CITY_SERVICE_PANEL_TITLE_STATION_STOPS");
                        this._listBoxPanel.relativePosition = new Vector3(this._listBoxPanel.parent.width + 1f, 0.0f);
                        this._listBoxPanel.Show();
                        if ((int)this._cachedBuildingID != (int)building || this._cachedStopCount != length)
                        {
                            this._stopsListBox.ClearItems();
                            for (int index = 0; index < length; ++index)
                            {
                                this._stopsListBox.AddItem(numArray[index], -1);
                            }
                        }
                    }
                    else
                    {
                        this._listBoxPanel.Hide();
                    }
                    this._cachedStopCount = length;
                    break;

                case ItemClass.SubService.PublicTransportTaxi:
                case ItemClass.SubService.PublicTransportCableCar:
                    this._vehicleListBox.Show();
                    this._stopsListBox.Hide();
                    UIPanel uiPanel = this._cityServiceWorldInfoPanel.Find <UIPanel>("SvsVehicleTypes");
                    if ((UnityEngine.Object)uiPanel != (UnityEngine.Object)null)
                    {
                        this._listBoxPanel.relativePosition = new Vector3((float)((double)this._listBoxPanel.parent.width + (double)uiPanel.width + 2.0), 0.0f);
                    }
                    List <ushort> depotVehicles = PanelExtenderCityService.GetDepotVehicles(building);
                    int           count         = depotVehicles.Count;
                    if (count > 0)
                    {
                        this._titleLabel.text = Localization.Get("CITY_SERVICE_PANEL_TITLE_DEPOT_VEHICLES");
                        this._listBoxPanel.Show();
                        if ((int)this._cachedBuildingID != (int)building || this._cachedVehicleCount != count)
                        {
                            this._vehicleListBox.ClearItems();
                            PrefabData[]   prefabs   = VehiclePrefabs.instance.GetPrefabs(service, subService, level);
                            VehicleManager instance2 = Singleton <VehicleManager> .instance;
                            foreach (ushort vehicleID in depotVehicles)
                            {
                                VehicleInfo info = instance2.m_vehicles.m_buffer[(int)vehicleID].Info;
                                for (int index = 0; index < prefabs.Length; ++index)
                                {
                                    PrefabData data = prefabs[index];
                                    if (info.name == data.ObjectName)
                                    {
                                        this._vehicleListBox.AddItem(data, vehicleID);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this._listBoxPanel.Hide();
                    }
                    this._cachedVehicleCount = count;
                    break;

                default:
                    this._listBoxPanel.Hide();
                    break;
                }
                this._cachedBuildingID = building;
            }
        }
        private void UpdateBindings()
        {
            ushort vehicleID = 0;
            ushort lineId    = this.GetLineID(out vehicleID);

            if ((int)lineId == 0)
            {
                this._passengerPanel.Hide();
                this._statsPanel.Hide();
                this._buttonPanel.Hide();
                this._publicTransportVehicleWorldInfoPanel.component.height = 229f;
            }
            else
            {
                this._publicTransportVehicleWorldInfoPanel.component.height = 332f;
                this._editType.isVisible = !OptionsWrapper <Settings> .Options.HideVehicleEditor;
                ItemClass            itemClass  = Singleton <TransportManager> .instance.m_lines.m_buffer[(int)lineId].Info.m_class;
                ItemClass.SubService subService = itemClass.m_subService;
                ItemClass.Service    service    = itemClass.m_service;
                ItemClass.Level      level      = itemClass.m_level;

                switch (subService)
                {
                case ItemClass.SubService.PublicTransportBus:
                case ItemClass.SubService.PublicTransportTours:
                case ItemClass.SubService.PublicTransportMetro:
                case ItemClass.SubService.PublicTransportTrain:
                case ItemClass.SubService.PublicTransportTram:
                case ItemClass.SubService.PublicTransportShip:
                case ItemClass.SubService.PublicTransportPlane:
                case ItemClass.SubService.PublicTransportMonorail:
                case ItemClass.SubService.PublicTransportCableCar:
                case ItemClass.SubService.PublicTransportTrolleybus:
                    this._passengerPanel.Show();
                    if ((int)vehicleID != 0)
                    {
                        this._lastStopExchange.text = string.Format(Localization.Get("VEHICLE_PANEL_LAST_STOP_EXCHANGE"),
                                                                    (object)CachedVehicleData.m_cachedVehicleData[(int)vehicleID].LastStopGonePassengers,
                                                                    (object)CachedVehicleData.m_cachedVehicleData[(int)vehicleID].LastStopNewPassengers);
                    }
                    break;

                case ItemClass.SubService.None:
                    if (service == ItemClass.Service.Disaster && level == ItemClass.Level.Level4)
                    {
                        this._passengerPanel.Show();
                        if ((int)vehicleID != 0)
                        {
                            this._lastStopExchange.text = string.Format(Localization.Get("VEHICLE_PANEL_LAST_STOP_EXCHANGE"),
                                                                        (object)CachedVehicleData.m_cachedVehicleData[(int)vehicleID].LastStopGonePassengers,
                                                                        (object)CachedVehicleData.m_cachedVehicleData[(int)vehicleID].LastStopNewPassengers);
                        }
                    }
                    else
                    {
                        this._passengerPanel.Hide();
                    }
                    break;

                default:
                    this._passengerPanel.Hide();
                    break;
                }
                this._distanceTraveled.parent.Show();
                this._distanceProgress.parent.Show();
                VehicleManager vm = Singleton <VehicleManager> .instance;
                if ((vm.m_vehicles.m_buffer[(int)vehicleID].m_flags & Vehicle.Flags.Stopped) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive))
                {
                    if (CachedVehicleData.m_cachedVehicleData[(int)vehicleID].IsUnbunchingInProgress)
                    {
                        this._status.text = Localization.Get("VEHICLE_PANEL_STATUS_UNBUNCHING");
                    }
                    this._distance.text = this._status.text;
                    float num = (float)vm.m_vehicles.m_buffer[(int)vehicleID].m_waitCounter / 12f;
                    int   p   = Mathf.RoundToInt(num * 100f);
                    this._distanceTraveled.value         = num;
                    this._distanceTraveled.progressColor = (Color32)Color.green;
                    this._distanceProgress.text          = LocaleFormatter.FormatPercentage(p);
                }
                else
                {
                    bool   flag = true;
                    string text = Localization.Get("VEHICLE_PANEL_STATUS_NEXT_STOP");
                    if (subService == ItemClass.SubService.PublicTransportShip)
                    {
                        this.UpdateProgress();
                    }
                    else if (subService == ItemClass.SubService.PublicTransportPlane)
                    {
                        if ((vm.m_vehicles.m_buffer[(int)vehicleID].m_flags & Vehicle.Flags.Landing) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive) || (vm.m_vehicles.m_buffer[(int)vehicleID].m_flags & Vehicle.Flags.TakingOff) != ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive) || (vm.m_vehicles.m_buffer[(int)vehicleID].m_flags & Vehicle.Flags.Flying) == ~(Vehicle.Flags.Created | Vehicle.Flags.Deleted | Vehicle.Flags.Spawned | Vehicle.Flags.Inverted | Vehicle.Flags.TransferToTarget | Vehicle.Flags.TransferToSource | Vehicle.Flags.Emergency1 | Vehicle.Flags.Emergency2 | Vehicle.Flags.WaitingPath | Vehicle.Flags.Stopped | Vehicle.Flags.Leaving | Vehicle.Flags.Arriving | Vehicle.Flags.Reversed | Vehicle.Flags.TakingOff | Vehicle.Flags.Flying | Vehicle.Flags.Landing | Vehicle.Flags.WaitingSpace | Vehicle.Flags.WaitingCargo | Vehicle.Flags.GoingBack | Vehicle.Flags.WaitingTarget | Vehicle.Flags.Importing | Vehicle.Flags.Exporting | Vehicle.Flags.Parking | Vehicle.Flags.CustomName | Vehicle.Flags.OnGravel | Vehicle.Flags.WaitingLoading | Vehicle.Flags.Congestion | Vehicle.Flags.DummyTraffic | Vehicle.Flags.Underground | Vehicle.Flags.Transition | Vehicle.Flags.InsideBuilding | Vehicle.Flags.LeftHandDrive))
                        {
                            text = this._status.text;
                            flag = false;
                        }
                        this.UpdateProgress();
                    }
                    this._status.text = text;
                    if (flag)
                    {
                        ushort     targetBuilding = vm.m_vehicles.m_buffer[(int)vehicleID].m_targetBuilding;
                        InstanceID id             = new InstanceID();
                        id.NetNode = targetBuilding;
                        string name = Singleton <InstanceManager> .instance.GetName(id);

                        this._target.objectUserData = (object)id;
                        this._target.text           = name == null?string.Format(Localization.Get("STOP_LIST_BOX_ROW_STOP"), (object)(TransportLineUtil.GetStopIndex(lineId, targetBuilding) + 1)) : name;

                        this._target.Enable();
                        this._target.Show();
                    }
                    this._distance.text = ColossalFramework.Globalization.Locale.Get(this._distance.localeID);
                    this._distanceTraveled.progressColor = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
                }
                this._statsPanel.Show();
                this._passengersCurrentWeek.text = CachedVehicleData.m_cachedVehicleData[(int)vehicleID].PassengersThisWeek.ToString();
                this._passengersLastWeek.text    = CachedVehicleData.m_cachedVehicleData[(int)vehicleID].PassengersLastWeek.ToString();
                this._passengersAverage.text     = CachedVehicleData.m_cachedVehicleData[(int)vehicleID].PassengersAverage.ToString();
                PrefabData prefabData          = Array.Find(VehiclePrefabs.instance.GetPrefabs(service, subService, level), item => item.PrefabDataIndex == vm.m_vehicles.m_buffer[(int)vehicleID].Info.m_prefabDataIndex);
                int        num1                = CachedVehicleData.m_cachedVehicleData[(int)vehicleID].IncomeThisWeek - prefabData.MaintenanceCost;
                UILabel    earningsCurrentWeek = this._earningsCurrentWeek;
                float      num2                = (float)num1 * 0.01f;
                string     str1                = num2.ToString(ColossalFramework.Globalization.Locale.Get("MONEY_FORMAT"), (IFormatProvider)LocaleManager.cultureInfo);
                earningsCurrentWeek.text            = str1;
                this._earningsCurrentWeek.textColor = (Color32)this.GetColor((float)num1);
                int     incomeLastWeek   = CachedVehicleData.m_cachedVehicleData[(int)vehicleID].IncomeLastWeek;
                UILabel earningsLastWeek = this._earningsLastWeek;
                num2 = (float)incomeLastWeek * 0.01f;
                string str2 = num2.ToString(ColossalFramework.Globalization.Locale.Get("MONEY_FORMAT"), (IFormatProvider)LocaleManager.cultureInfo);
                earningsLastWeek.text            = str2;
                this._earningsLastWeek.textColor = (Color32)this.GetColor((float)incomeLastWeek);
                int     incomeAverage   = CachedVehicleData.m_cachedVehicleData[(int)vehicleID].IncomeAverage;
                UILabel earningsAverage = this._earningsAverage;
                num2 = (float)incomeAverage * 0.01f;
                string str3 = num2.ToString(ColossalFramework.Globalization.Locale.Get("MONEY_FORMAT"), (IFormatProvider)LocaleManager.cultureInfo);
                earningsAverage.text            = str3;
                this._earningsAverage.textColor = (Color32)this.GetColor((float)incomeAverage);
                this._buttonPanel.Show();
            }
        }