Esempio n. 1
0
        public override void Load(ConfigNode node)
        {
            Volumes.Clear();
            base.Load(node);
            var volumes = node.GetNodes();

            for (int i = 0; i < volumes.Length; i++)
            {
                var v = volumes[i];
                if (v.name == TankVolume.NODE_NAME)
                {
                    var preset = VolumeConfigsLibrary.GetConfig(v.GetValue("name"));
                    if (preset != null)
                    {
                        float volume;
                        if (!float.TryParse(v.GetValue("Volume"), out volume))
                        {
                            volume = 100f;
                        }
                        var cfg = preset.Clone <VolumeConfiguration>();
                        cfg.Volume = volume;
                        Volumes.Add(cfg);
                    }
                    else
                    {
                        Volumes.Add(ConfigNodeObject.FromConfig <TankVolume>(v));
                    }
                }
                else if (v.name == NODE_NAME)
                {
                    Volumes.Add(ConfigNodeObject.FromConfig <VolumeConfiguration>(v));
                }
            }
        }
 void init_supported_types()
 {
     exclude        = Utils.ParseLine(ExcludeTankTypes, Utils.Comma);
     include        = Utils.ParseLine(IncludeTankTypes, Utils.Comma);
     SupportedTypes = SwitchableTankType.TankTypeNames(include, exclude);
     SupportedTypes.AddRange(VolumeConfigsLibrary.AllConfigNames(include, exclude));
     if (SupportedTypes.Count > 0)
     {
         selected_tank_type = SupportedTypes[0];
     }
 }
        void volume_configs_gui()
        {
            if (!AddRemoveEnabled)
            {
                return;
            }
            GUILayout.BeginHorizontal();
            VolumeConfiguration cfg = null;

            GUILayout.Label("Configuration Name:", GUILayout.ExpandWidth(false));
            config_name = GUILayout.TextField(config_name, GUILayout.ExpandWidth(true), GUILayout.MinWidth(50));
            if (GUILayout.Button(VolumeConfigsLibrary.HaveUserConfig(config_name)? "Save" : "Add",
                                 Styles.add_button, GUILayout.ExpandWidth(false)) &&
                !string.IsNullOrEmpty(config_name))
            {
                //add new config
                var node = new ConfigNode();
                Save(node);
                cfg = ConfigNodeObject.FromConfig <VolumeConfiguration>(node);
                if (cfg.Valid)
                {
                    cfg.name   = config_name;
                    cfg.Volume = TotalVolume;
                    VolumeConfigsLibrary.AddOrSave(cfg);
                    init_supported_types();
                }
                else
                {
                    Utils.Log("Configuration is invalid:\n{}\nThis should never happen!", node);
                }
            }
            config_name = Utils.LeftRightChooser(config_name, VolumeConfigsLibrary.UserConfigs,
                                                 "Select tank configuration to edit", 200);
            if (config_name == null)
            {
                config_name = "";
            }
            if (GUILayout.Button("Delete", Styles.danger_button, GUILayout.ExpandWidth(false)) &&
                !string.IsNullOrEmpty(config_name))
            {
                //remove config
                if (VolumeConfigsLibrary.RemoveConfig(config_name))
                {
                    init_supported_types();
                }
                config_name = "";
            }
            GUILayout.EndHorizontal();
        }
        /// <summary>
        /// Searches for a named tank type or configuration and adds tanks accordingly.
        /// </summary>
        /// <returns><c>true</c>, if configuration was added, <c>false</c> otherwise.</returns>
        /// <param name="name">A name of a tank type or tank configuration.</param>
        /// <param name="volume">Total volume of the configuration.</param>
        /// <param name="update_counterparts">If counterparts are to be updated.</param>
        public bool AddVolume(string name, float volume, bool update_counterparts = true)
        {
            if (!AddRemoveEnabled)
            {
                return(false);
            }
            if (AddTank(name, volume, update_counterparts: update_counterparts))
            {
                return(true);
            }
            var cfg = VolumeConfigsLibrary.GetConfig(name);

            if (cfg == null)
            {
                Utils.Log("SwitchableTankManager: no such tank configuration: {}", name);
                return(false);
            }
            return(AddConfiguration(cfg, volume, update_counterparts));
        }