Exemple #1
0
        public static void Init()
        {
            if (!TryLoadData(out _lineData))
            {
                Utils.Log((object)"Loading default transport line data.");
                NetManager       instance1 = Singleton <NetManager> .instance;
                TransportManager instance2 = Singleton <TransportManager> .instance;
                int length = instance2.m_lines.m_buffer.Length;
                for (ushort index = 0; index < length; ++index)
                {
                    if (instance2.m_lines.m_buffer[index].Complete)
                    {
                        _lineData[index].TargetVehicleCount = TransportLineDetour.CountLineActiveVehicles(index, out int _);
                    }
                    else
                    {
                        _lineData[index].TargetVehicleCount =
                            OptionsWrapper <Settings> .Options.DefaultVehicleCount;
                    }
                    _lineData[index].BudgetControl = OptionsWrapper <Settings> .Options.BudgetControl;
                    _lineData[index].Depot         = DepotUtil.GetClosestDepot((ushort)index,
                                                                               instance1.m_nodes.m_buffer[(int)instance2.m_lines.m_buffer[index].GetStop(0)].m_position);
                    _lineData[index].Unbunching = OptionsWrapper <Settings> .Options.Unbunching;
                }
            }
            SerializableDataExtension.instance.EventSaveData +=
                new SerializableDataExtension.SaveDataEventHandler(OnSaveData);

            _init = true;
        }
Exemple #2
0
        private static void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            try
            {
                SerializableDataExtension.WriteString(_dataVersion, data);
                for (ushort lineID = 0; (int)lineID < 256; ++lineID)
                {
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(GetTargetVehicleCount(lineID)), data);
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(Mathf.Max(
                                                  GetNextSpawnTime(lineID) - SimHelper.SimulationTime, 0.0f)),
                        data);
                    SerializableDataExtension.AddToData(
                        BitConverter.GetBytes(GetBudgetControlState(lineID)), data);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(GetDepot(lineID)), data);
                    int num = 0;
                    HashSet <string> prefabs = GetPrefabs(lineID);
                    if (prefabs != null)
                    {
                        num = prefabs.Count;
                    }
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(num), data);
                    if (num > 0)
                    {
                        foreach (string s in prefabs)
                        {
                            SerializableDataExtension.WriteString(s, data);
                        }
                    }
                    string[] enqueuedVehicles = GetEnqueuedVehicles(lineID);
                    SerializableDataExtension.AddToData(BitConverter.GetBytes(enqueuedVehicles.Length), data);
                    if (enqueuedVehicles.Length != 0)
                    {
                        foreach (string s in enqueuedVehicles)
                        {
                            SerializableDataExtension.WriteString(s, data);
                        }
                    }
                    SerializableDataExtension.WriteBool(GetUnbunchingState(lineID), data);
                }
                SerializableDataExtension.instance.SerializableData.SaveData(_dataID, data.ToArray());
            }
            catch (Exception ex)
            {
                string msg = "Error while saving transport line data! " + ex.Message + " " + (object)ex.InnerException;
                Utils.LogError((object)msg);
                CODebugBase <LogChannel> .Log(LogChannel.Modding, msg, ErrorLevel.Error);
            }
        }
 private void Init()
 {
     this._publicTransportVehicleWorldInfoPanel = GameObject.Find("(Library) PublicTransportVehicleWorldInfoPanel").GetComponent <PublicTransportVehicleWorldInfoPanel>();
     if (!((UnityEngine.Object) this._publicTransportVehicleWorldInfoPanel != (UnityEngine.Object)null))
     {
         return;
     }
     this._status                = this._publicTransportVehicleWorldInfoPanel.Find <UILabel>("Status");
     this._target                = this._publicTransportVehicleWorldInfoPanel.Find <UIButton>("Target");
     this._target.eventClick    += new MouseEventHandler(this.OnTargetClick);
     this._distance              = this._publicTransportVehicleWorldInfoPanel.Find <UILabel>("Distance");
     this._distanceTraveled      = Utils.GetPrivate <UIProgressBar>((object)this._publicTransportVehicleWorldInfoPanel, "m_DistanceTraveled");
     this._distanceProgress      = Utils.GetPrivate <UILabel>((object)this._publicTransportVehicleWorldInfoPanel, "m_DistanceProgress");
     this._cachedCurrentProgress = this._publicTransportVehicleWorldInfoPanel.GetType().GetField("m_cachedCurrentProgress", BindingFlags.Instance | BindingFlags.NonPublic);
     this._cachedTotalProgress   = this._publicTransportVehicleWorldInfoPanel.GetType().GetField("m_cachedTotalProgress", BindingFlags.Instance | BindingFlags.NonPublic);
     this._cachedProgressVehicle = this._publicTransportVehicleWorldInfoPanel.GetType().GetField("m_cachedProgressVehicle", BindingFlags.Instance | BindingFlags.NonPublic);
     this.AddPanelControls();
     this._initialized = true;
 }
Exemple #4
0
        public override void Update()
        {
            base.Update();
            if (!this.isVisible || (int)this.StopID == 0)
            {
                return;
            }
            string name = Singleton <InstanceManager> .instance.GetName(this._instanceID);

            if (this._cachedName != name)
            {
                this._cachedName = name;
                Utils.Truncate(this._stopName, GenerateStopName(name, this._instanceID.NetNode, this.StopIndex));
            }
            if ((double)this._delta >= 1.0)
            {
                this._delta = 0.0f;
                byte max;
                this._stopCount.text = PanelExtenderLine.CountWaitingPassengers(this.StopID, this.NextStopID, out max).ToString();
            }
            this._delta = this._delta + Singleton <SimulationManager> .instance.m_simulationTimeDelta;
        }
        private void AddPanelControls()
        {
            UILabel uiLabel1 = Utils.GetPrivate <UILabel>((object)this._publicTransportVehicleWorldInfoPanel, "m_Type");
            int     num1     = 132;

            uiLabel1.anchor = (UIAnchorStyle)num1;
            UIPanel    parent     = (UIPanel)uiLabel1.parent;
            RectOffset rectOffset = new RectOffset(0, 10, 0, 0);

            parent.autoLayoutPadding = rectOffset;
            double num2 = 25.0;

            parent.height = (float)num2;
            int num3 = 1;

            parent.useCenter = num3 != 0;
            UIButton button1 = UIUtils.CreateButton((UIComponent)parent);

            button1.name        = "EditType";
            button1.autoSize    = true;
            button1.anchor      = UIAnchorStyle.Left | UIAnchorStyle.Right | UIAnchorStyle.CenterVertical;
            button1.textPadding = new RectOffset(10, 10, 4, 2);
            button1.text        = Localization.Get("VEHICLE_PANEL_EDIT_TYPE");
            button1.tooltip     = string.Format(Localization.Get("VEHICLE_PANEL_EDIT_TYPE_TOOLTIP"));
            button1.textScale   = 0.75f;
            button1.eventClick += new MouseEventHandler(this.OnEditTypeClick);
            button1.isVisible   = !OptionsWrapper <Settings> .Options.HideVehicleEditor;
            this._editType      = button1;
            UILabel uiLabel2 = Utils.GetPrivate <UILabel>((object)this._publicTransportVehicleWorldInfoPanel, "m_Passengers");
            UIPanel uiPanel1 = this._publicTransportVehicleWorldInfoPanel.component.Find <UIPanel>("Panel");
            UIPanel uiPanel2 = uiPanel1.AddUIComponent <UIPanel>();

            uiPanel2.autoLayout          = true;
            uiPanel2.autoLayoutDirection = LayoutDirection.Horizontal;
            uiPanel2.autoLayoutPadding   = new RectOffset(0, 0, 0, 0);
            uiPanel2.height      = uiLabel2.parent.height;
            uiPanel2.width       = uiLabel2.parent.width;
            uiPanel2.zOrder      = 4;
            this._passengerPanel = uiPanel2;
            UILabel uiLabel3 = uiPanel2.AddUIComponent <UILabel>();

            uiLabel3.name          = "LastStopExchange";
            uiLabel3.font          = uiLabel2.font;
            uiLabel3.textColor     = uiLabel2.textColor;
            uiLabel3.textScale     = uiLabel2.textScale;
            uiLabel3.processMarkup = true;
            this._lastStopExchange = uiLabel3;
            UIPanel uiPanel3 = uiPanel1.AddUIComponent <UIPanel>();

            uiPanel3.name                = "PassengerStats";
            uiPanel3.anchor              = UIAnchorStyle.Top | UIAnchorStyle.Left | UIAnchorStyle.Right;
            uiPanel3.autoLayout          = true;
            uiPanel3.autoLayoutDirection = LayoutDirection.Vertical;
            uiPanel3.autoLayoutPadding   = new RectOffset(0, 0, 0, 0);
            uiPanel3.autoLayoutStart     = LayoutStart.TopLeft;
            uiPanel3.size                = new Vector2(349f, 60f);
            uiPanel3.zOrder              = 5;
            this._statsPanel             = uiPanel3;
            UILabel label1;
            UILabel label2;
            UILabel label3;
            UILabel label4;

            PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel3, out label1, out label2, out label3, out label4, true);
            label2.text    = Localization.Get("CURRENT_WEEK");
            label3.text    = Localization.Get("LAST_WEEK");
            label4.text    = Localization.Get("AVERAGE");
            label4.tooltip = string.Format(Localization.Get("AVERAGE_TOOLTIP"), (object)OptionsWrapper <Settings> .Options.StatisticWeeks);
            PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel3, out label1, out this._passengersCurrentWeek, out this._passengersLastWeek, out this._passengersAverage, false);
            label1.text = Localization.Get("VEHICLE_PANEL_PASSENGERS");
            PublicTransportStopWorldInfoPanel.CreateStatisticRow((UIComponent)uiPanel3, out label1, out this._earningsCurrentWeek, out this._earningsLastWeek, out this._earningsAverage, false);
            label1.text    = Localization.Get("VEHICLE_PANEL_EARNINGS");
            label1.tooltip = Localization.Get("VEHICLE_PANEL_EARNINGS_TOOLTIP");
            UIPanel uiPanel4 = uiPanel1.AddUIComponent <UIPanel>();

            uiPanel4.name                = "Buttons";
            uiPanel4.anchor              = UIAnchorStyle.Top | UIAnchorStyle.Left | UIAnchorStyle.Right;
            uiPanel4.autoLayout          = true;
            uiPanel4.autoLayoutDirection = LayoutDirection.Horizontal;
            uiPanel4.autoLayoutPadding   = new RectOffset(0, 5, 0, 0);
            uiPanel4.autoLayoutStart     = LayoutStart.TopLeft;
            uiPanel4.size                = new Vector2(345f, 32f);
            this._buttonPanel            = uiPanel4;
            UIButton button2 = UIUtils.CreateButton((UIComponent)uiPanel4);

            button2.name        = "PreviousVehicle";
            button2.textPadding = new RectOffset(10, 10, 4, 0);
            button2.text        = Localization.Get("VEHICLE_PANEL_PREVIOUS");
            button2.tooltip     = Localization.Get("VEHICLE_PANEL_PREVIOUS_TOOLTIP");
            button2.textScale   = 0.75f;
            button2.size        = new Vector2(110f, 32f);
            button2.wordWrap    = true;
            button2.eventClick += new MouseEventHandler(this.OnChangeVehicleClick);
            UIButton button3 = UIUtils.CreateButton((UIComponent)uiPanel4);

            button3.name             = "RemoveVehicle";
            button3.textPadding      = new RectOffset(10, 10, 4, 0);
            button3.text             = Localization.Get("VEHICLE_PANEL_REMOVE_VEHICLE");
            button3.textScale        = 0.75f;
            button3.size             = new Vector2(100f, 32f);
            button3.wordWrap         = true;
            button3.hoveredTextColor = (Color32)Color.red;
            button3.focusedTextColor = (Color32)Color.red;
            button3.pressedTextColor = (Color32)Color.red;
            button3.eventClick      += new MouseEventHandler(this.OnRemoveVehicleClick);
            UIButton button4 = UIUtils.CreateButton((UIComponent)uiPanel4);

            button4.name        = "NextVehicle";
            button4.textPadding = new RectOffset(10, 10, 4, 0);
            button4.text        = Localization.Get("VEHICLE_PANEL_NEXT");
            button4.tooltip     = Localization.Get("VEHICLE_PANEL_NEXT_TOOLTIP");
            button4.textScale   = 0.75f;
            button4.size        = new Vector2(110f, 32f);
            button4.wordWrap    = true;
            button4.eventClick += new MouseEventHandler(this.OnChangeVehicleClick);
        }
Exemple #6
0
        public static bool TryLoadData(out LineData[] data)
        {
            data = new LineData[256];
            byte[] data1 = SerializableDataExtension.instance.SerializableData.LoadData(_dataID);
            if (data1 == null)
            {
                return(false);
            }
            int    index1 = 0;
            ushort lineID = 0;
            string empty  = string.Empty;

            try
            {
                Utils.Log((object)"Try to load transport line data.");
                string str = SerializableDataExtension.ReadString(data1, ref index1);
                if (string.IsNullOrEmpty(str) || str.Length != 4)
                {
                    Utils.LogWarning((object)"Unknown data found.");
                    return(false);
                }
                Utils.Log((object)("Found transport line data version: " + str));
                NetManager       instance1 = Singleton <NetManager> .instance;
                TransportManager instance2 = Singleton <TransportManager> .instance;
                while (index1 < data1.Length)
                {
                    if (instance2.m_lines.m_buffer[(int)lineID].Complete)
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        data[(int)lineID].TargetVehicleCount = int32;
                    }
                    index1 += 4;
                    float num = Mathf.Min(BitConverter.ToSingle(data1, index1),
                                          (float)OptionsWrapper <Settings> .Options.SpawnTimeInterval);
                    if ((double)num > 0.0)
                    {
                        data[(int)lineID].NextSpawnTime = SimHelper.SimulationTime + num;
                    }
                    index1 += 4;
                    bool boolean = BitConverter.ToBoolean(data1, index1);
                    data[(int)lineID].BudgetControl = boolean;
                    ++index1;
                    ushort uint16 = BitConverter.ToUInt16(data1, index1);
                    data[(int)lineID].Depot = (int)uint16 != 0
                        ? uint16
                        : DepotUtil.GetClosestDepot(lineID,
                                                    instance1.m_nodes.m_buffer[(int)instance2.m_lines.m_buffer[(int)lineID].GetStop(0)]
                                                    .m_position);
                    index1 += 2;
                    if (str == "v001")
                    {
                        string name = SerializableDataExtension.ReadString(data1, ref index1);
                        if (name != "Random")
                        {
                            if (data[(int)lineID].Prefabs == null)
                            {
                                data[(int)lineID].Prefabs = new HashSet <string>();
                            }
                            if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) !=
                                (UnityEngine.Object)null)
                            {
                                data[(int)lineID].Prefabs.Add(name);
                            }
                        }
                    }
                    else
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        index1 += 4;
                        for (int index2 = 0; index2 < int32; ++index2)
                        {
                            string name = SerializableDataExtension.ReadString(data1, ref index1);
                            if (data[(int)lineID].Prefabs == null)
                            {
                                data[(int)lineID].Prefabs = new HashSet <string>();
                            }
                            if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) !=
                                (UnityEngine.Object)null)
                            {
                                data[(int)lineID].Prefabs.Add(name);
                            }
                        }
                    }
                    if (str != "v001")
                    {
                        int int32 = BitConverter.ToInt32(data1, index1);
                        index1 += 4;
                        for (int index2 = 0; index2 < int32; ++index2)
                        {
                            string name = SerializableDataExtension.ReadString(data1, ref index1);
                            if (!boolean)
                            {
                                if (data[(int)lineID].QueuedVehicles == null)
                                {
                                    data[(int)lineID].QueuedVehicles = new Queue <string>();
                                }
                                if ((UnityEngine.Object)PrefabCollection <VehicleInfo> .FindLoaded(name) !=
                                    (UnityEngine.Object)null)
                                {
                                    lock (data[(int)lineID].QueuedVehicles)
                                        data[(int)lineID].QueuedVehicles.Enqueue(name);
                                }
                            }
                        }
                    }
                    if (str == "v003")
                    {
                        ++index1;
                    }
                    data[(int)lineID].Unbunching = str != "v004"
                        ? OptionsWrapper <Settings> .Options.Unbunching
                        : SerializableDataExtension.ReadBool(data1, ref index1);
                    ++lineID;
                }
                return(true);
            }
            catch (Exception ex)
            {
                Utils.LogWarning((object)("Could not load transport line data. " + ex.Message));
                data = new LineData[256];
                return(false);
            }
        }