Esempio n. 1
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;
 }
Esempio n. 2
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;
             }
         }
     }
 }
Esempio n. 3
0
 public static void UpdateAvailableComponents(VesselConfig CFG)
 {
     AvailableComponents.Clear();
     foreach (var c in Components.Keys)
     {
         var cmp       = Components[c];
         var reqs      = cmp.Component.GetCustomAttributes(typeof(RequireModules), true) as RequireModules[];
         var available = true;
         if (reqs != null && reqs.Length > 0)
         {
             foreach (var req in reqs)
             {
                 foreach (var m in req.Modules)
                 {
                     available &= TCAModulesDatabase.ModuleAvailable(m, CFG);
                     if (!available)
                     {
                         break;
                     }
                 }
                 if (!available)
                 {
                     break;
                 }
             }
         }
         if (available)
         {
             AvailableComponents[c] = cmp;
         }
     }
 }
        public static bool DrawMacroSelector(VesselConfig cfg, out TCAMacro macro)
        {
            macro = null;
            TCAMacro sel = null;
            bool     ret = false;

            GUILayout.BeginVertical();
            GUILayout.Label("Load Macro form Library", Styles.enabled, GUILayout.ExpandWidth(true));
            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Current Vessel", Styles.active, GUILayout.ExpandWidth(true));
            if (cfg.Macros.Selector(out sel))
            {
                ret = true; macro = sel;
            }
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.Label("Global Database", Styles.active, GUILayout.ExpandWidth(true));
            if (TCAScenario.Macros.Selector(out sel))
            {
                ret = true; macro = sel;
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            ret |= GUILayout.Button("Cancel", Styles.close_button, GUILayout.ExpandWidth(true));
            GUILayout.EndVertical();
            return(ret);
        }
            public bool Draw(VesselConfig CFG)
            {
                var button_pressed = false;

                if (CFG.EnabledTCAParts.Contains(part.Name))
                {
                    if (!part.Active)
                    {
                        GUILayout.Label(button, Styles.inactive_button);
                    }
                    else if (GUILayout.Button(button, Styles.enabled_button, GUILayout.ExpandWidth(true)) && Editable)
                    {
                        CFG.EnabledTCAParts.Remove(part.Name);
                        button_pressed = true;
                    }
                }
                else
                {
                    if (GUILayout.Button(button, Styles.active_button, GUILayout.ExpandWidth(true)) && Editable)
                    {
                        CFG.EnabledTCAParts.Add(part.Name);
                        button_pressed = true;
                    }
                }
                if (Event.current.type == EventType.Repaint)
                {
                    button_rect = GUILayoutUtility.GetLastRect();
                }
                return(button_pressed);
            }
        public static NamedConfig FromVesselConfig(string name, VesselConfig other)
        {
            var nc = new NamedConfig();

            nc.CopyFrom(other);
            nc.Name = name;
            return(nc);
        }
 public override void SetCFG(VesselConfig cfg)
 {
     base.SetCFG(cfg);
     for (int i = 0, count = Subnodes.Count; i < count; i++)
     {
         Subnodes[i].SetCFG(cfg);
     }
 }
 static public void Edit(VesselConfig cfg)
 {
     if (cfg == null)
     {
         return;
     }
     CFG = cfg;
     EditMacro(CFG.SelectedMacro);
 }
Esempio n. 9
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);
 }
Esempio n. 10
0
 public static void UpdateDefaultConfig(EditorFacility facility, VesselConfig config)
 {
     if (facility == EditorFacility.SPH)
     {
         SPH_DefaultConfig.CopyFrom(config);
     }
     else
     {
         VAB_DefaultConfig.CopyFrom(config);
     }
 }
 void Update()
 {
     if (exit)
     {
         CFG   = null;
         Macro = null;
         SelectAction(null);
         SelectCondition(null);
         Show(false);
         exit = false;
     }
 }
Esempio n. 12
0
        public static void UpdateConfig(VesselConfig config)
        {
            VesselConfig old;

            if (Configs.TryGetValue(config.VesselID, out old))
            {
                old.CopyFrom(config);
            }
            else
            {
                Configs.Add(config.VesselID, config);
            }
        }
Esempio n. 13
0
        void updateCFG()
        {
            var group  = GetGroup();
            var master = group.FirstOrDefault(tca => tca.GroupMaster);

            if (this == master)
            {
                if (CFG == null)
                {
                    CFG = new VesselConfig();
                }
                group.ForEach(tca => tca.CFG = CFG);
            }
        }
 public void UpdateInfo(VesselConfig CFG = null)
 {
     if (info == null)
     {
         info = PartLoader.getPartInfoByName(Name);
         if (info != null)
         {
             Title       = info.title;
             Description = info.description;
         }
         if (string.IsNullOrEmpty(Title))
         {
             Title = Utils.ParseCamelCase(Name);
         }
     }
     Purchased = Utils.PartIsPurchased(Name);
     Active    = Modules.All(m => TCAModulesDatabase.ModuleAvailable(m.Module, CFG));
 }
            public bool Draw(VesselConfig CFG)
            {
                var button_pressed = false;

                GUILayout.BeginHorizontal();
                foreach (var tier in tiers.Keys)
                {
                    GUILayout.BeginVertical(Styles.white, GUILayout.ExpandHeight(true));
                    GUILayout.Label("Tier " + tier, GUILayout.ExpandWidth(true));
                    tiers[tier].ForEach(node => button_pressed = node.Draw(CFG) || button_pressed);
                    GUILayout.EndVertical();
                    if (tier < tiers.Count)
                    {
                        GUILayout.Space(10);
                    }
                }
                GUILayout.EndHorizontal();
                return(button_pressed);
            }
        void updateCFG()
        {
            //get all ModuleTCA instances in the vessel
            var TCA_Modules = AllTCA(vessel);

            //try to get saved CFG from other modules, if needed
            if (CFG == null)
            {
                foreach (var tca in TCA_Modules)
                {
                    if (tca.CFG == null)
                    {
                        continue;
                    }
                    CFG = tca.CFG;
                    break;
                }
            }
            //if it is found in one of the modules, use it
            //else, get it from common database or create a new one
            if (CFG != null)
            {
                if (CFG.VesselID == Guid.Empty)
                {
                    CFG.VesselID = vessel.id;
                }
                else if (CFG.VesselID != vessel.id)
                {
                    CFG = VesselConfig.FromVesselConfig(vessel, CFG);
                }
                TCAScenario.Configs[CFG.VesselID] = CFG;
            }
            else
            {
                CFG = TCAScenario.GetConfig(vessel);
            }
            //finally, update references in other modules
            TCA_Modules.ForEach(m => m.CFG = CFG);
        }
        public static bool ModuleAvailable(Type mtype, VesselConfig CFG)
        {
            if (!ValidModule(mtype))
            {
                return(false);
            }
            var meta = GetModuleMeta(mtype);

            if (meta == null)
            {
                return(true);
            }
            if (CFG != null && !CFG.EnabledTCAParts.Contains(meta.PartName))
            {
                return(false);
            }
            if (!Globals.Instance.IntegrateIntoCareer)
            {
                return(true);
            }
            return((string.IsNullOrEmpty(meta.PartName) ||
                    Utils.PartIsPurchased(meta.PartName)) &&
                   meta.Requires.All(m => ModuleAvailable(m, CFG)));
        }
 public override void SetCFG(VesselConfig cfg)
 {
     base.SetCFG(cfg);
     Block.SetCFG(cfg);
 }
 public virtual void SetCFG(VesselConfig cfg)
 {
     EditedCFG = cfg;
 }
 public void SetCFG(VesselConfig cfg)
 {
     CFG = cfg;
     update_part_status();
 }
 void set_altitude(VesselConfig cfg)
 {
     cfg.DesiredAltitude = Altitude; cfg.BlockThrottle = true;
 }
        public static void UpdateAvailableComponents(VesselConfig CFG)
        {
            ComponentDB <Condition> .UpdateAvailableComponents(CFG);

            ComponentDB <MacroNode> .UpdateAvailableComponents(CFG);
        }