public void OnSettingsUI(UIHelperBase helper)
        {
            try
            {
                UICheckBox   checkBox;
                UIHelperBase group = helper.AddGroup(Name);

                checkBox = (UICheckBox)group.AddCheckbox("Disable debug messages logging", DebugUtils.hideDebugMessages.value, (b) =>
                {
                    DebugUtils.hideDebugMessages.value = b;
                });
                checkBox.tooltip = "If checked, debug messages won't be logged.";

                group.AddSpace(10);

                checkBox = (UICheckBox)group.AddCheckbox("Hide the user interface", AdvancedVehicleOptionsUID.hideGUI.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.hideGUI.value = b;
                    AdvancedVehicleOptionsUID.UpdateGUI();
                });
                checkBox.tooltip = "Hide the UI completely if you feel like you are done with it\nand want to save the little bit of memory it takes\nEverything else will still be functional";

                checkBox = (UICheckBox)group.AddCheckbox("Disable warning at map loading", !AdvancedVehicleOptionsUID.onLoadCheck.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.onLoadCheck.value = !b;
                });
                checkBox.tooltip = "Disable service vehicle availability check at the loading of a map";
            }
            catch (Exception e)
            {
                DebugUtils.Log("OnSettingsUI failed");
                DebugUtils.LogException(e);
            }
        }
        // Serialize to save
        public void Serialize(DataSerializer s)
        {
            try
            {
                int count = options.Length;
                s.WriteInt32(count);

                for (int i = 0; i < count; i++)
                {
                    s.WriteUniqueString(options[i].name);
                    s.WriteBool(options[i].enabled);
                    s.WriteBool(options[i].addBackEngine);
                    s.WriteFloat(options[i].maxSpeed);
                    s.WriteFloat(options[i].acceleration);
                    s.WriteFloat(options[i].braking);
                    s.WriteFloat(options[i].turning);
                    s.WriteFloat(options[i].springs);
                    s.WriteFloat(options[i].dampers);
                    s.WriteFloat(options[i].leanMultiplier);
                    s.WriteFloat(options[i].nodMultiplier);
                    s.WriteBool(options[i].useColorVariations);
                    s.WriteUniqueString(options[i].color0.Value);
                    s.WriteUniqueString(options[i].color1.Value);
                    s.WriteUniqueString(options[i].color2.Value);
                    s.WriteUniqueString(options[i].color3.Value);
                    s.WriteInt32(options[i].capacity);
                    s.WriteInt32(options[i].specialcapacity);
                    s.WriteBool(options[i].isLargeVehicle);
                }
            }
            catch (Exception e)
            {
                DebugUtils.LogException(e);
            }
        }
        public void Deserialize(DataSerializer s)
        {
            try
            {
                options = null;
                data    = null;

                int count = s.ReadInt32();
                data = new VehicleData[count];

                DebugUtils.Log("AVO Savegame Version " + s.version);

                for (int i = 0; i < count; i++)
                {
                    data[i]               = new VehicleData();
                    data[i].name          = s.ReadUniqueString();
                    data[i].enabled       = s.ReadBool();
                    data[i].addBackEngine = s.ReadBool();
                    data[i].maxSpeed      = s.ReadFloat();
                    data[i].acceleration  = s.ReadFloat();
                    data[i].braking       = s.ReadFloat();

                    if (s.version >= 2)                                          // Skip loading new vehicle propertiers for all versions below 1.9.0
                    {
                        data[i].turning        = s.ReadFloat();
                        data[i].springs        = s.ReadFloat();
                        data[i].dampers        = s.ReadFloat();
                        data[i].leanMultiplier = s.ReadFloat();
                        data[i].nodMultiplier  = s.ReadFloat();
                    }

                    data[i].useColorVariations = s.ReadBool();
                    data[i].color0             = new HexaColor(s.ReadUniqueString());
                    data[i].color1             = new HexaColor(s.ReadUniqueString());
                    data[i].color2             = new HexaColor(s.ReadUniqueString());
                    data[i].color3             = new HexaColor(s.ReadUniqueString());
                    data[i].capacity           = s.ReadInt32();

                    if (s.version >= 3)                                         // Skip loading Special Capacity for all versions below 1.9.3
                    {
                        data[i].specialcapacity = s.ReadInt32();
                        data[i].isLargeVehicle  = s.ReadBool();
                    }
                }
            }
            catch (Exception e)
            {
                // Couldn't Deserialize
                DebugUtils.Warning("Couldn't deserialize");
                DebugUtils.LogException(e);
            }
        }
        public void Deserialize(string filename)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
            Configuration config        = null;

            options = null;
            data    = null;

            try
            {
                // Trying to Deserialize the configuration file
                using (FileStream stream = new FileStream(filename, FileMode.Open))
                {
                    config = xmlSerializer.Deserialize(stream) as Configuration;
                }
            }
            catch (Exception e)
            {
                // Couldn't Deserialize (XML malformed?)
                DebugUtils.Warning("Couldn't load configuration (XML malformed?)");
                DebugUtils.LogException(e);

                config = null;
            }

            if (config != null)
            {
                data = config.data;

                if (data != null)
                {
                    // Saves all default vehicle options that might not exist on the map
                    // I.E. Snowplow on non-snowy maps
                    m_defaultVehicles.Clear();
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (data[i] != null && !data[i].isCustomAsset)
                        {
                            m_defaultVehicles.Add(data[i]);
                        }
                    }
                }


                if (AdvancedVehicleOptionsUID.isGameLoaded)
                {
                    DataToOptions();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Called when the level (game, map editor, asset editor) is loaded
        /// </summary>
        public override void OnLevelLoaded(LoadMode mode)
        {
            try
            {
                // Is it an actual game ?
                if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame && mode != LoadMode.NewGameFromScenario)
                {
                    DefaultOptions.Clear();
                    DebugUtils.Log("AVO Incompatible GameMode " + mode);
                    return;
                }

                AdvancedVehicleOptionsUID.isGameLoaded = true;

                if (instance != null)
                {
                    GameObject.DestroyImmediate(instance.gameObject);
                }

                instance = new GameObject("AdvancedVehicleOptionsUID").AddComponent <AdvancedVehicleOptionsUID>();

                try
                {
                    DefaultOptions.BuildVehicleInfoDictionary();
                    VehicleOptions.Clear();
                    DebugUtils.Log("UIMainPanel created");
                }
                catch
                {
                    DebugUtils.Log("Could not create UIMainPanel");

                    if (instance != null)
                    {
                        GameObject.Destroy(instance.gameObject);
                    }

                    return;
                }

                //new EnumerableActionThread(BrokenAssetsFix);
            }
            catch (Exception e)
            {
                if (instance != null)
                {
                    GameObject.Destroy(instance.gameObject);
                }
                DebugUtils.LogException(e);
            }
        }
        // Serialize to file
        public void Serialize(string filename)
        {
            try
            {
                if (AdvancedVehicleOptionsUID.isGameLoaded)
                {
                    OptionsToData();
                }

                // Add back default vehicle options that might not exist on the map
                // I.E. Snowplow on non-snowy maps
                if (m_defaultVehicles.Count > 0)
                {
                    List <VehicleData> new_data = new List <VehicleData>(data);

                    for (int i = 0; i < m_defaultVehicles.Count; i++)
                    {
                        bool found = false;
                        for (int j = 0; j < data.Length; j++)
                        {
                            if (m_defaultVehicles[i].name == data[j].name)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            new_data.Add(m_defaultVehicles[i]);
                        }
                    }

                    data = new_data.ToArray();
                }

                using (FileStream stream = new FileStream(filename, FileMode.OpenOrCreate))
                {
                    stream.SetLength(0); // Emptying the file !!!
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
                    xmlSerializer.Serialize(stream, this);
                    DebugUtils.Log("Configuration saved");
                }
            }
            catch (Exception e)
            {
                DebugUtils.Warning("Couldn't save configuration at \"" + Directory.GetCurrentDirectory() + "\"");
                DebugUtils.LogException(e);
            }
        }
 public ModInfo()
 {
     try
     {
         // Creating setting file
         GameSettings.AddSettingsFile(new SettingsFile[] { new SettingsFile()
                                                           {
                                                               fileName = AdvancedVehicleOptionsUID.settingsFileName
                                                           } });
     }
     catch (Exception e)
     {
         DebugUtils.Log("Couldn't load/create the setting file.");
         DebugUtils.LogException(e);
     }
 }
        /// <summary>
        /// Called when the level is unloaded
        /// </summary>
        public override void OnLevelUnloading()
        {
            try
            {
                DebugUtils.Log("Restoring default values");
                DefaultOptions.RestoreAll();
                DefaultOptions.Clear();

                if (instance != null)
                {
                    GameObject.Destroy(instance.gameObject);
                }

                AdvancedVehicleOptionsUID.isGameLoaded = false;
            }
            catch (Exception e)
            {
                DebugUtils.LogException(e);
            }
        }
Beispiel #9
0
        private VehicleInfo GetEngine()
        {
            if (_trailerEngines == null)
            {
                _trailerEngines = new Dictionary <VehicleInfo, VehicleInfo>();

                for (uint i = 0; i < PrefabCollection <VehicleInfo> .PrefabCount(); i++)
                {
                    try
                    {
                        VehicleInfo prefab = PrefabCollection <VehicleInfo> .GetPrefab(i);

                        if (prefab == null || prefab.m_trailers == null || prefab.m_trailers.Length == 0)
                        {
                            continue;
                        }

                        for (int j = 0; j < prefab.m_trailers.Length; j++)
                        {
                            if (prefab.m_trailers[j].m_info != null && prefab.m_trailers[j].m_info != prefab && !_trailerEngines.ContainsKey(prefab.m_trailers[j].m_info))
                            {
                                _trailerEngines.Add(prefab.m_trailers[j].m_info, prefab);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        DebugUtils.LogException(e);
                    }
                }
            }

            if (_trailerEngines.ContainsKey(m_prefab))
            {
                return(_trailerEngines[m_prefab]);
            }

            return(null);
        }
        public void Deserialize(DataSerializer s)
        {
            try
            {
                options = null;
                data    = null;

                int count = s.ReadInt32();
                data = new VehicleData[count];

                for (int i = 0; i < count; i++)
                {
                    data[i]                    = new VehicleData();
                    data[i].name               = s.ReadUniqueString();
                    data[i].enabled            = s.ReadBool();
                    data[i].addBackEngine      = s.ReadBool();
                    data[i].maxSpeed           = s.ReadFloat();
                    data[i].acceleration       = s.ReadFloat();
                    data[i].braking            = s.ReadFloat();
                    data[i].turning            = s.ReadFloat();
                    data[i].springs            = s.ReadFloat();
                    data[i].dampers            = s.ReadFloat();
                    data[i].leanMultiplier     = s.ReadFloat();
                    data[i].nodMultiplier      = s.ReadFloat();
                    data[i].useColorVariations = s.ReadBool();
                    data[i].color0             = new HexaColor(s.ReadUniqueString());
                    data[i].color1             = new HexaColor(s.ReadUniqueString());
                    data[i].color2             = new HexaColor(s.ReadUniqueString());
                    data[i].color3             = new HexaColor(s.ReadUniqueString());
                    data[i].capacity           = s.ReadInt32();
                }
            }
            catch (Exception e)
            {
                // Couldn't Deserialize
                DebugUtils.Warning("Couldn't deserialize");
                DebugUtils.LogException(e);
            }
        }
        public void Start()
        {
            try
            {
                // Loading config
                AdvancedVehicleOptionsUID.InitConfig();

                if (AdvancedVehicleOptionsUID.onLoadCheck)
                {
                    AdvancedVehicleOptionsUID.CheckAllServicesValidity();
                }

                m_mainPanel = GameObject.FindObjectOfType <GUI.UIMainPanel>();
                UpdateGUI();
            }
            catch (Exception e)
            {
                DebugUtils.Log("UI initialization failed.");
                DebugUtils.LogException(e);

                GameObject.Destroy(gameObject);
            }
        }
Beispiel #12
0
        public void OnSettingsUI(UIHelperBase helper)
        {
            try
            {
                UICheckBox  checkBox;
                UITextField TextField;
                UIButton    Button;

// Section for General Settings

                UIHelperBase group_general = helper.AddGroup("General Settings                                                   " + Name);

                checkBox = (UICheckBox)group_general.AddCheckbox("Disable debug messages logging", DebugUtils.hideDebugMessages.value, (b) =>
                {
                    DebugUtils.hideDebugMessages.value = b;
                });
                checkBox.tooltip = "If checked, debug messages will not be logged.";

                group_general.AddSpace(10);

                checkBox = (UICheckBox)group_general.AddCheckbox("Hide the user interface", AdvancedVehicleOptionsUID.hideGUI.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.hideGUI.value = b;
                    AdvancedVehicleOptionsUID.UpdateGUI();
                });
                checkBox.tooltip = "Hide the UI completely if you feel like you are done with it and want to save\n" +
                                   "the little bit of memory it takes. Everything else will still be functional.";

                checkBox = (UICheckBox)group_general.AddCheckbox("Disable warning for no available services at map loading", !AdvancedVehicleOptionsUID.onLoadCheck.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.onLoadCheck.value = !b;
                });
                checkBox.tooltip = "Disable the check for missing service vehicles assigned in any category when loading a map.";

// Section for Game Balancing

                UIHelperBase group_balance = helper.AddGroup("Gameplay & Balancing");

// Checkbox for SpeedUnitOption kmh vs mph

                checkBox = (UICheckBox)group_balance.AddCheckbox("Display Miles per Hour (mph) instead of Kilometer per Hour (km/h)", AdvancedVehicleOptionsUID.SpeedUnitOption.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.SpeedUnitOption.value = b;
                });
                checkBox.tooltip = "Changes display of unit of speed from mph to km/h.";

// Checkbox for Game Balancing

                checkBox = (UICheckBox)group_balance.AddCheckbox("Enable various values for non-cargo and non-passenger vehicles", AdvancedVehicleOptionsUID.GameBalanceOptions.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.GameBalanceOptions.value = b;
                });
                checkBox.tooltip = "Allows changes the Firefighting Rate and Capacity for Fire Safety, the Crime Rate Capacity\n" +
                                   "for Police Vehicles and the Maintenance and Pumping Rate for Maintenance Vehicles.\n\n" +
                                   "Can de-balance the intended gameplay. Some values are not documented.";

// Section for Compatibility

                UIHelperBase group_compatibility = helper.AddGroup("Compatibility");

// Checkbox for Overriding Incompability Warnings

                checkBox = (UICheckBox)group_compatibility.AddCheckbox("Display Compatibility Warnings for Mods", AdvancedVehicleOptionsUID.OverrideCompatibilityWarnings.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.OverrideCompatibilityWarnings.value = b;
                });

                checkBox.tooltip = "If enabled, settings which can be modified in Improved Public Transport\n" +
                                   "(by BloodyPenguin) and Transport Lines Manager (by Klyte) will be shown\n" +
                                   "with warning color. Values should be edited in these mods only.\n\n" +
                                   "If disabled, the coloring will not shown.";
                //True, if AVO shall shall color shared mod setting values in red.

// Checkbox for Vehicle Color Expander

                checkBox = (UICheckBox)group_compatibility.AddCheckbox("Vehicle Color Expander: Priority over AVO vehicle coloring", AdvancedVehicleOptionsUID.OverrideVCX.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.OverrideVCX.value = b;
                });

                checkBox.tooltip = "Permanent setting, if Vehicle Color Expander (by Klyte) is active.\n" +
                                   "The color management is controlled by Vehicle Color Expander.\n\n" +
                                   "Values will be configured in Vehicle Color Expander.";

                //True, if AVO shall not override Vehicle Color Expander settings. As there is not Settings for Vehicle Color Expander. AVO will show the option, but user cannot change anything as long readOnly is True.
                checkBox.readOnly        = true;
                checkBox.label.textColor = Color.gray;

                if (!VCXCompatibilityPatch.IsVCXActive())
                {
                    checkBox.enabled = false;                   //Do not show the option Checkbox, if Vehicle Color Expander is not active.
                }

// Checkbox for No Big Trucks

                checkBox = (UICheckBox)group_compatibility.AddCheckbox("No Big Trucks: Classify Generic Industry vehicles as Large Vehicle", AdvancedVehicleOptionsUID.ControlTruckDelivery.value, (b) =>
                {
                    AdvancedVehicleOptionsUID.ControlTruckDelivery.value = b;
                });

                checkBox.tooltip = "If enabled, Delivery Trucks can be tagged as Large Vehicles.\n" +
                                   "Dispatch will be blocked by No Big Trucks (by MacSergey).\n\n" +
                                   "Warning: Experimental feature and may have impact on the simulation.";
                //True, if AVO shall be enabled to classify Generic Industry vehicles as Large Vehicles, so No Big Trucks can suppress the dispatch to small buildings.

                if (!NoBigTruckCompatibilityPatch.IsNBTActive())
                {
                    checkBox.enabled = false;   //Do not show the option Checkbox, if No Big Trucks is not active.
                }

// Add a Spacer
                group_compatibility.AddSpace(20);

// Add Trailer Compatibility Reference

                TextField         = (UITextField)group_compatibility.AddTextfield("Vehicle Trailer compatibility references last updated:", TrailerRef.Revision, (value) => Debug.Log(""), (value) => Debug.Log(""));
                TextField.tooltip = "This field shows the vehicle list revision date for the Bus, Trolley Bus, Fire and Police\n" +
                                    "trailers, which are in real life industry trailers, but have been re-categorized by AVO.";
                TextField.readOnly = true;

                // Support Section with Wiki and Output-Log

                UIHelperBase group_support = helper.AddGroup("Support");

                Button = (UIButton)group_support.AddButton("Open the Advanced Vehicle Options Wiki", () =>
                {
                    SimulationManager.instance.SimulationPaused = true;
                    Application.OpenURL("https://github.com/CityGecko/CS-AdvancedVehicleOptions/wiki");
                });
                Button.textScale = 0.8f;

                Button = (UIButton)group_support.AddButton("Open Cities:Skylines log folder (output_log.txt)", () =>
                {
                    Utils.OpenInFileBrowser(Application.dataPath);
                });
                Button.textScale = 0.8f;
            }

            catch (Exception e)
            {
                DebugUtils.Log("OnSettingsUI failed");
                DebugUtils.LogException(e);
            }
        }