// See CompilePartInfo
        public static AvailablePart.ModuleInfo GetModuleInfo(PartModule pm)
        {
            AvailablePart.ModuleInfo moduleInfo = new AvailablePart.ModuleInfo();
            if (pm is IModuleInfo)
            {
                IModuleInfo iModuleInfo = pm as IModuleInfo;
                moduleInfo.moduleName  = iModuleInfo.GetModuleTitle();
                moduleInfo.info        = iModuleInfo.GetInfo().Trim();
                moduleInfo.primaryInfo = iModuleInfo.GetPrimaryField();
            }
            else
            {
                moduleInfo.moduleName = (pm.GUIName ?? KSPUtil.PrintModuleName(pm.moduleName));
                moduleInfo.info       = pm.GetInfo().Trim();
            }

            if (pm.showUpgradesInModuleInfo && pm.HasUpgrades())
            {
                moduleInfo.info += "\n" + pm.PrintUpgrades();
            }

            moduleInfo.moduleDisplayName = pm.GetModuleDisplayName();
            if (moduleInfo.moduleDisplayName == string.Empty)
            {
                moduleInfo.moduleDisplayName = moduleInfo.moduleName;
            }
            return(moduleInfo);
        }
Example #2
0
        public void generate_details(Configure cfg)
        {
            // If a setup component is defined after the Configure module in the ConfigNode,
            // then it is not present in the part during Configure::OnLoad (at precompilation time)
            // so, find_module() will fail in that situation, resulting in no component details
            // being added to the Configure window. Therefore we are forced to generate the details
            // at first use every time the module is loaded, instead of generating them only once.

            // already generated
            if (details != null)
            {
                return;
            }

            // generate module details
            details = new List <Detail>();
            foreach (ConfigureModule cm in modules)
            {
                // find module, skip if it doesn't exist
                PartModule m = cfg.find_module(cm);
                if (m == null)
                {
                    continue;
                }

                // get title
                IModuleInfo module_info = m as IModuleInfo;
                string      title       = module_info != null?module_info.GetModuleTitle() : cm.type;

                if (title.Length == 0)
                {
                    continue;
                }

                // get specs, skip if not implemented by module
                ISpecifics specifics = m as ISpecifics;
                if (specifics == null)
                {
                    continue;
                }
                Specifics specs = specifics.Specs();
                if (specs.entries.Count == 0)
                {
                    continue;
                }

                // add title to details
                details.Add(new Detail(Lib.BuildString("<b><color=#00ffff>", title, "</color></b>")));

                // add specs to details
                foreach (Specifics.Entry e in specs.entries)
                {
                    details.Add(new Detail(e.label, e.value));
                }
            }

            // get visible resources subset
            List <ConfigureResource> visible_resources = resources.FindAll(k => Lib.GetDefinition(k.name).isVisible);

            // generate resource details
            if (visible_resources.Count > 0)
            {
                // add resources title
                details.Add(new Detail("<b><color=#00ffff>Resources</color></b>"));

                // for each visible resource
                foreach (ConfigureResource cr in visible_resources)
                {
                    // add capacity info
                    details.Add(new Detail(cr.name, Lib.Parse.ToDouble(cr.maxAmount).ToString("F2")));
                }
            }

            // generate extra details
            if (mass > double.Epsilon || cost > double.Epsilon)
            {
                details.Add(new Detail("<b><color=#00ffff>Extra</color></b>"));
                if (mass > double.Epsilon)
                {
                    details.Add(new Detail("mass", Lib.HumanReadableMass(mass)));
                }
                if (cost > double.Epsilon)
                {
                    details.Add(new Detail("cost", Lib.HumanReadableCost(cost)));
                }
            }
        }