public EInvalidTemplateReasons CanUseTemplate(ConfigNode nodeTemplate)
        {
            string     value;
            PartModule requiredModule;
            EInvalidTemplateReasons invalidTemplateReason;

            //Make sure the vessel object is set
            if (this.vessel == null)
            {
                this.vessel = this.part.vessel;
            }

            //If we need a specific mod then check for it.
            value = nodeTemplate.GetValue("needs");
            if (string.IsNullOrEmpty(value) == false)
            {
                invalidTemplateReason = TemplateManager.CheckNeeds(value);

                if (invalidTemplateReason != EInvalidTemplateReasons.TemplateIsValid)
                {
                    return(invalidTemplateReason);
                }
            }

            //If we need a specific module then check for it.
            value = nodeTemplate.GetValue("requiresModule");
            if (string.IsNullOrEmpty(value) == false)
            {
                if (!this.part.Modules.Contains(value))
                {
                    return(EInvalidTemplateReasons.RequiredModuleNotFound);
                }
//                requiredModule = this.part.Modules[value];
//                if (requiredModule == null)
//                {
//                    return EInvalidTemplateReasons.RequiredModuleNotFound;
//                }
            }

            //If we need a specific template type then check for it.
            //Only templates with the appropriate tag will be accepted.
            if (string.IsNullOrEmpty(templateTags) == false)
            {
                if (nodeTemplate.HasValue("templateTags") == false)
                {
                    return(EInvalidTemplateReasons.TagsNotFound);
                }

                value = nodeTemplate.GetValue("templateTags");
                string[] tags = value.Split(new char[] { ';' });
                foreach (string tag in tags)
                {
                    if (templateTags.Contains(tag))
                    {
                        return(EInvalidTemplateReasons.TemplateIsValid);
                    }
                }
                return(EInvalidTemplateReasons.TagsNotFound);
            }

            return(EInvalidTemplateReasons.TemplateIsValid);
        }
Example #2
0
        public void DrawView()
        {
            if (templateCount == -1 && setupView != null)
            {
                setupView();
            }
            string  buttonLabel;
            string  panelName;
            Texture buttonDecal;

            getRequiredTraits();

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(250) });

            if (string.IsNullOrEmpty(templateTitle) == false)
            {
                GUILayout.Label("<color=white>Configuration: " + templateTitle + "</color>");
            }
            else
            {
                GUILayout.Label("<color=white>Configuration: " + templateName + "</color>");
            }

            if (inputList != null)
            {
                GUILayout.Label("<color=white>Resource Costs</color>");
                string[] resourceNames = inputList.Keys.ToArray();
                int      count         = resourceNames.Length;
                for (int index = 0; index < count; index++)
                {
                    GUILayout.Label(string.Format("<color=white>{0:s}: ({1:f2})</color>", resourceNames[index], inputList[resourceNames[index]]));
                }
            }

            if (string.IsNullOrEmpty(requiredSkill) == false)
            {
                GUILayout.Label("<color=white>Reconfigure Trait: " + requiredTraits + "</color>");
            }
            else
            {
                GUILayout.Label("<color=white>Reconfigure Trait: Any</color>");
            }

            //Templates
            _scrollPosTemplates = GUILayout.BeginScrollView(_scrollPosTemplates);
            foreach (ConfigNode nodeTemplate in this.templateManager.templateNodes)
            {
                //Button label
                if (nodeTemplate.HasValue("title"))
                {
                    buttonLabel = nodeTemplate.GetValue("title");
                }
                else
                {
                    buttonLabel = nodeTemplate.GetValue("name");
                }

                //Icon
                panelName = nodeTemplate.GetValue("logoPanel");
                if (panelName != null)
                {
                    buttonDecal = GameDatabase.Instance.GetTexture(panelName, false);
                }
                else
                {
                    buttonDecal = null;
                }

                //Button
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(buttonDecal, buttonOption))
                {
                    previewTemplate(nodeTemplate.GetValue("name"));
                }
                if (TemplateManager.TemplateTechResearched(nodeTemplate))
                {
                    GUILayout.Label("<color=white>" + buttonLabel + "</color>");
                }
                else
                {
                    GUILayout.Label("<color=#959595>" + buttonLabel + "\r\nNeeds " + TemplateManager.GetTechTreeTitle(nodeTemplate) + "</color>");
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndScrollView();

            //Update symmetry
            if (HighLogic.LoadedSceneIsFlight && this.part.symmetryCounterparts.Count > 0)
            {
                updateSymmetry = GUILayout.Toggle(updateSymmetry, "Update symmetry parts");
            }

            //Reconfigure button
            if (GUILayout.Button("Reconfigure") && setTemplate != null)
            {
                ConfigNode node = templateManager[templateName];
                if (confirmReconfigure || HighLogic.LoadedSceneIsEditor)
                {
                    if (TemplateManager.TemplateTechResearched(node))
                    {
                        setTemplate(templateName);
                        confirmReconfigure = false;
                    }
                    else
                    {
                        ScreenMessages.PostScreenMessage("Unable to use " + templateName + ". Research " + TemplateManager.GetTechTreeTitle(node) + " first.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    }
                }

                else
                {
                    ScreenMessages.PostScreenMessage("Click again to confirm reconfiguration.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    confirmReconfigure = true;
                }
            }

            GUILayout.EndVertical();

            GUILayout.BeginVertical(new GUILayoutOption[] { GUILayout.Width(390) });
            _scrollPos = GUILayout.BeginScrollView(_scrollPos);

            if (decal != null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label(decal, new GUILayoutOption[] { GUILayout.Width(128), GUILayout.Height(128) });
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            GUILayout.Label(info);

            GUILayout.EndScrollView();
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();
        }