Пример #1
0
        bool GetCFG()
        {
            var ship        = EditorLogic.fetch.ship;
            var TCA_Modules = ModuleTCA.AllTCA(ship);

            if (TCA_Modules.Count == 0)
            {
                Reset(); return(false);
            }
            CFG = null;
            foreach (var tca in TCA_Modules)
            {
                if (tca.CFG == null)
                {
                    continue;
                }
                CFG = NamedConfig.FromVesselConfig(ship.shipName, tca.CFG);
                break;
            }
            if (CFG == null)
            {
                CFG = NamedConfig.FromVesselConfig(ship.shipName, TCAScenario.GetDefaultConfig(ship.shipFacility));
                if (CFG.EnginesProfiles.Empty)
                {
                    CFG.EnginesProfiles.AddProfile(Engines);
                }
            }
            else
            {
                CFG.ActiveProfile.Apply(Engines);
            }
            UpdateCFG(TCA_Modules);
            return(true);
        }
Пример #2
0
 public static void LoadConfigs(ConfigNode node)
 {
     if (ConfigsLoaded)
     {
         return;
     }
     Configs.Clear();
     NamedConfigs.Clear();
     foreach (var n in node.GetNodes())
     {
         if (n.name == VSL_NODE)
         {
             foreach (var c in n.GetNodes(VesselConfig.NODE_NAME))
             {
                 var config = new VesselConfig();
                 config.Load(c);
                 Configs[config.VesselID] = config;
             }
         }
         else if (n.name == NAMED_NODE)
         {
             foreach (var c in n.GetNodes(NamedConfig.NODE_NAME))
             {
                 var config = new NamedConfig();
                 config.Load(c);
                 NamedConfigs[config.Name] = config;
             }
         }
     }
     VAB_DefaultConfig.LoadFrom(node, "VAB_DefaultConfig");
     SPH_DefaultConfig.LoadFrom(node, "SPH_DefaultConfig");
     ConfigsLoaded = true;
 }
        bool GetCFG(ShipConstruct ship)
        {
            var TCA_Modules = ModuleTCA.AllTCA(ship);

            if (TCA_Modules.Count == 0)
            {
                Reset(); return(false);
            }
            CFG = null;
            foreach (var tca in TCA_Modules)
            {
                if (tca.CFG == null)
                {
                    continue;
                }
                CFG = NamedConfig.FromVesselConfig(ship.shipName, tca.CFG);
                break;
            }
            if (CFG == null)
            {
                CFG = new NamedConfig(ship.shipName);
                CFG.EnginesProfiles.AddProfile(Engines);
            }
            else
            {
                CFG.ActiveProfile.Apply(Engines);
            }
            CFG.ActiveProfile.Update(Engines);
            UpdateCFG(TCA_Modules);
            return(true);
        }
Пример #4
0
 public static void LoadLegacyConfigs(ConfigNode node)
 {
     Configs.Clear();
     NamedConfigs.Clear();
     foreach (var n in node.GetNodes())
     {
         if (n.name == HighLogic.CurrentGame.Title.Split()[0])
         {
             foreach (var c in n.GetNodes(VesselConfig.NODE_NAME))
             {
                 var config = new VesselConfig();
                 config.Load(c);
                 Configs[config.VesselID] = config;
             }
         }
         else if (n.name == NAMED_NODE)
         {
             foreach (var c in n.GetNodes(NamedConfig.NODE_NAME))
             {
                 var config = new NamedConfig();
                 config.Load(c);
                 NamedConfigs[config.Name] = config;
             }
         }
     }
 }
        public static NamedConfig FromVesselConfig(string name, VesselConfig other)
        {
            var nc = new NamedConfig();

            nc.CopyFrom(other);
            nc.Name = name;
            return(nc);
        }
 void Update()
 {
     if (EditorLogic.fetch == null || EditorLogic.fetch.ship == null)
     {
         return;
     }
     update_stats |= HaveSelectedPart;
     if (reset)
     {
         Available = false;
         Modules.Clear();
         Engines.Clear();
         PartsEditor.SetCFG(null);
         CFG   = null;
         reset = false;
     }
     if (init_engines)
     {
         if (UpdateEngines())
         {
             GetCFG();
         }
         init_engines = false;
         update_stats = true;
     }
     if (update_engines)
     {
         if (UpdateEngines())
         {
             if (CFG != null)
             {
                 UpdateCFG();
             }
             else
             {
                 GetCFG();
             }
         }
         update_engines = false;
         update_stats   = true;
     }
     if (autoconfigure_profile)
     {
         AutoconfigureProfile();
         autoconfigure_profile = false;
         update_stats          = true;
     }
     if (update_stats)
     {
         UpdateShipStats();
         update_stats = false;
     }
     Available |= CFG != null && Engines.Count > 0;
     TCA_highlight.Update(Available && doShow);
     Engines_highlight.Update(Available && doShow && show_imbalance && ActiveEngines.Count > 0);
 }
Пример #7
0
 public static bool SaveNamedConfig(string name, VesselConfig config, bool overwrite = false)
 {
     if (name == string.Empty || //do not allow empty name
         NamedConfigs.ContainsKey(name) && !overwrite)
     {
         return(false);
     }
     NamedConfigs[name] = NamedConfig.FromVesselConfig(name, config);
     return(true);
 }
Пример #8
0
        public static NamedConfig NewNamedConfig(string name)
        {
            if (NamedConfigs.ContainsKey(name))
            {
                return(null);
            }
            var c = new NamedConfig(name);

            NamedConfigs[name] = c;
            return(c);
        }
 void SelectConfig()
 {
     if (TCAScenario.NamedConfigs.Count == 0)
     {
         GUILayout.Label("", Styles.white, GUILayout.ExpandWidth(true));
     }
     else
     {
         named_configs.DrawButton();
         var new_config = TCAScenario.GetConfig(named_configs.SelectedIndex);
         if (new_config != selected_config)
         {
             selected_config = new_config;
             config_name     = selected_config != null? selected_config.Name : string.Empty;
         }
     }
 }
 void Update()
 {
     if (EditorLogic.fetch == null)
     {
         return;
     }
     if (reset)
     {
         Available = false;
         Engines.Clear();
         CFG   = null;
         reset = false;
     }
     if (init_engines)
     {
         if (UpdateEngines(EditorLogic.fetch.ship))
         {
             GetCFG(EditorLogic.fetch.ship);
         }
         init_engines = false;
     }
     if (update_engines)
     {
         if (UpdateEngines(EditorLogic.fetch.ship))
         {
             if (CFG != null)
             {
                 UpdateCFG(EditorLogic.fetch.ship);
             }
             else
             {
                 GetCFG(EditorLogic.fetch.ship);
             }
             if (CFG != null)
             {
                 CFG.ActiveProfile.Update(Engines);
             }
         }
         update_engines = false;
     }
     Available |= CFG != null && Engines.Count > 0;
     if (Available)
     {
         CFG.GUIVisible = CFG.Enabled;
     }
 }
 void ConfigsGUI()
 {
     GUILayout.BeginVertical();
     GUILayout.Label("Manage named configurations", Styles.label, GUILayout.ExpandWidth(true));
     GUILayout.BeginHorizontal();
     GUILayout.Label("Name:", GUILayout.ExpandWidth(false));
     config_name = GUILayout.TextField(config_name, GUILayout.ExpandWidth(true), GUILayout.MinWidth(50));
     if (TCAScenario.NamedConfigs.ContainsKey(config_name))
     {
         if (GUILayout.Button(new GUIContent("Overwrite", "Overwrite selected configuration with the current one"),
                              Styles.danger_button, GUILayout.ExpandWidth(false)))
         {
             TCAScenario.SaveNamedConfig(config_name, CFG, true);
         }
     }
     else if (GUILayout.Button(new GUIContent("Add", "Save current configuration"),
                               Styles.add_button, GUILayout.ExpandWidth(false)) &&
              config_name != string.Empty)
     {
         TCAScenario.SaveNamedConfig(config_name, CFG);
         UpdateNamedConfigs();
         named_configs.SelectItem(TCAScenario.NamedConfigs.IndexOfKey(config_name));
     }
     SelectConfig();
     if (GUILayout.Button(new GUIContent("Load", "Load selected configuration"),
                          Styles.active_button, GUILayout.ExpandWidth(false)) &&
         selected_config != null)
     {
         CFG.CopyFrom(selected_config);
     }
     if (GUILayout.Button(new GUIContent("Delete", "Delete selected configuration"),
                          Styles.danger_button, GUILayout.ExpandWidth(false)) &&
         selected_config != null)
     {
         TCAScenario.NamedConfigs.Remove(selected_config.Name);
         named_configs.SelectItem(named_configs.SelectedIndex - 1);
         UpdateNamedConfigs();
         selected_config = null;
     }
     GUILayout.EndHorizontal();
     GUILayout.EndVertical();
 }