public static object ParamsTextField(Criterion crton)
        {
            int i;
            if (int.TryParse(crton.tempParam.ToString(), out i))
                crton.paramValid = true;
            else
                crton.paramValid = false;
            GUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent(crton.valuesShortened + " " + crton.measure, crton.tooltip), crton.paramValid ? normalLabel : orangeLabel);
            GUILayout.FlexibleSpace();
            crton.tempParam = GUILayout.TextField(crton.tempParam.ToString(), 11, HighLogic.Skin.textField, GUILayout.Width(68f));
            GUILayout.EndHorizontal();

            return crton.tempParam;
        }
Exemplo n.º 2
0
        public bool LoadChecklists()
        {
            try
            {
                if (WernherChecker.Instance.Settings.cfgLoaded)
                {
                    availableChecklists.Clear();
                    foreach (ConfigNode checklistNode in WernherChecker.Instance.Settings.cfg.GetNodes("CHECKLIST"))
                    {
                        Log.Info("[WernherChecker]: Parsing checklist - " + checklistNode.GetValue("name"));
                        Checklist parsedChecklist = new Checklist();
                        parsedChecklist.items = new List <ChecklistItem>();
                        parsedChecklist.name  = checklistNode.GetValue("name");
                        if (checklistNode.HasValue("scene"))
                        {
                            var scene = checklistNode.GetValue("scene");

                            parsedChecklist.editorOnly = (scene == "editor");
                            parsedChecklist.flightOnly = (scene == "flight");
                        }
                        ///Begining item cycle
                        foreach (ConfigNode itemNode in checklistNode.GetNodes("CHECKLIST_ITEM"))
                        {
                            //Log.Info("parsing item " + itemNode.GetValue("name"));
                            ChecklistItem parsedItem = new ChecklistItem();
                            parsedItem.criteria = new List <Criterion>();
                            parsedItem.name     = itemNode.GetValue("name");
                            if (itemNode.HasValue("scene"))
                            {
                                var scene = itemNode.GetValue("scene");

                                parsedItem.editorOnly = (scene == "editor");
                                parsedItem.flightOnly = (scene == "flight");
                            }
                            if (!bool.TryParse(itemNode.GetValue("isManual"), out parsedItem.isManual))
                            {
                                parsedItem.isManual = false;
                            }
                            if (!bool.TryParse(itemNode.GetValue("allRequired"), out parsedItem.allRequired))
                            {
                                parsedItem.allRequired = true;
                            }
                            ;

                            //Begining criterion cycle
                            foreach (ConfigNode criterionNode in itemNode.GetNodes("CRITERION"))
                            {
                                //Log.Info("parsing criterion of type " + criterionNode.GetValue("type"));
                                Criterion parsedCriterion = new Criterion(criterionNode);
                                if (parsedCriterion.valid)
                                {
                                    parsedItem.criteria.Add(parsedCriterion);
                                }
                            }
                            if (parsedItem.criteria.Count() > 0 || parsedItem.isManual)
                            {
                                parsedChecklist.items.Add(parsedItem);
                            }
                        }
                        availableChecklists.Add(parsedChecklist);
                    }
                }
                return(true);
            }

            catch
            {
                Log.Warning("[WernherChecker]: Error loading checklist. Please, check your cfg file.");
                return(false);
            }
        }
Exemplo n.º 3
0
        public void CheckActiveVessel(Vessel ship)
        {
            Log.Info("CheckActiveVessel");
            if (!MainInstance.checklistSelected)
            {
                return;
            }

            if (MainInstance.checkSelected && MainInstance.partSelection != null)
            {
                partsToCheck = MainInstance.partSelection.selectedParts.Intersect(ship.Parts).ToList();
            }
            else
            {
                partsToCheck = ship.Parts;
            }

            for (int j = 0; j < activeChecklist.items.Count; j++)
            //foreach (ChecklistItem item in activeChecklist.items)
            {
                ChecklistItem item = activeChecklist.items[j];
                if (item.isManual)
                {
                    continue;
                }

                item.state = true;
                for (int i = 0; i < item.criteria.Count; i++)
                //foreach(Criterion crton in item.criteria)
                {
                    Criterion crton = item.criteria[i];
                    switch (crton.type)
                    {
                    case CriterionType.Module:
                        crton.met = CheckForModules(crton);
                        break;

                    case CriterionType.Part:
                        crton.met = CheckForParts(crton);
                        break;

                    case CriterionType.MinResourceLevel:
                        crton.met = CheckForResourceLevel(crton);
                        break;

                    case CriterionType.MinResourceCapacity:
                        crton.met = CheckForResourceCapacity(crton);
                        break;

                    case CriterionType.CrewMember:
                        crton.met = CheckForCrewMember(crton);
                        break;
                    }
                    item.criteria[i] = crton;
                }
                if (!item.allRequired)
                {
                    if (item.criteria.TrueForAll(c => !c.met))
                    {
                        item.state = false;
                    }
                }
                else if (item.criteria.Any(c => !c.met))
                {
                    item.state = false;
                }

                activeChecklist.items[j] = item;
                continue;
            }
        }
Exemplo n.º 4
0
        public void CheckVessel(ShipConstruct ship)
        {
            if (HighLogic.LoadedScene != GameScenes.EDITOR)
            {
                return;
            }

            if (MainInstance == null || !MainInstance.checklistSelected)
            {
                return;
            }

            if (EditorLogic.RootPart == null || (MainInstance.partSelection == null && MainInstance.checkSelected))
            {
                if (ActiveChecklist.items != null)
                {
                    ActiveChecklist.items.ForEach(i => i.state = false);
                }
                return;
            }

            if (MainInstance.checkSelected && MainInstance.partSelection != null && MainInstance.partSelection.selectedParts != null)
            {
                partsToCheck = MainInstance.partSelection.selectedParts.Intersect(ship.Parts).ToList();
            }
            else
            {
                partsToCheck = ship.Parts;
            }

            for (int j = 0; j < activeChecklist.items.Count; j++)
            //foreach (ChecklistItem item in activeChecklist.items)
            {
                ChecklistItem item = activeChecklist.items[j];
                if (item.isManual)
                {
                    continue;
                }

                item.state = true;
                for (int i = 0; i < item.criteria.Count; i++)
                //foreach(Criterion crton in item.criteria)
                {
                    Criterion crton = item.criteria[i];
                    switch (crton.type)
                    {
                    case CriterionType.Module:
                        crton.met = CheckForModules(crton);
                        break;

                    case CriterionType.Part:
                        crton.met = CheckForParts(crton);
                        break;

                    case CriterionType.MinResourceLevel:
                        crton.met = CheckForResourceLevel(crton);
                        break;

                    case CriterionType.MinResourceCapacity:
                        crton.met = CheckForResourceCapacity(crton);
                        break;

                    case CriterionType.CrewMember:
                        crton.met = CheckForCrewMember(crton);
                        break;
                    }
                    item.criteria[i] = crton;
                }
                if (!item.allRequired)
                {
                    if (item.criteria.TrueForAll(c => !c.met))
                    {
                        item.state = false;
                    }
                }
                else if (item.criteria.Any(c => !c.met))
                {
                    item.state = false;
                }

                activeChecklist.items[j] = item;
                continue;
            }
        }
        bool CheckForResourceLevel(Criterion crton)
        {
            double quantity = 0;
            foreach (Part part in partsToCheck.Where(p => p.Resources.Contains(crton.resourceName)))
            {
                quantity += part.Resources.list.Find(r => r.resourceName == crton.resourceName).amount;
            }
            if (quantity >= int.Parse(crton.parameter.ToString()))
                return true;

            return false;
        }
        bool CheckForParts(Criterion crton)
        {
            int quantity = 0;
            foreach (string part in crton.parts)
            {
                quantity += partsToCheck.Where(p => p.name == part).Count();
            }
            if (quantity >= int.Parse(crton.parameter.ToString()))
                return true;

            return false;
        }
        bool CheckForModules(Criterion crton)
        {
            int quantity = 0;
            foreach (string module in crton.modules)
            {
                quantity += partsToCheck.Where(p => p.Modules.Contains(module)).Count();
            }
            if (quantity >= int.Parse(crton.parameter.ToString()))
                return true;

            return false;
        }
 bool CheckForCrewMember(Criterion crton)
 {
     try
     {
         foreach (PartCrewManifest part in CMAssignmentDialog.Instance.GetManifest().GetCrewableParts().Where(p => partsToCheck.Exists(pt => pt.partInfo == p.PartInfo)))
         {
             if (part.GetPartCrew().Where(c => c != null).Any(c => c.experienceTrait.Title == crton.experienceTrait && c.experienceLevel >= int.Parse(crton.parameter.ToString())))
             {
                 //Debug.Log("Crew OK");
                 return true;
             }
         }
         //Debug.Log("Crew KO");
         return false;
     }
     catch(Exception ex)
     {
         Debug.LogWarning("[WernherChecker]: Error checking crew:\n" + ex + "\n\n<b><color=lime>Please note, that this can sometimes happen after entering the editor and attaching the part for the first time.</color> <color=#ff4444ff>If this is not the case, please, report it.</color></b>");
         return false;
     }
 }
        public bool LoadChecklists()
        {
            try
            {
                if (WernherChecker.Instance.Settings.cfgLoaded)
                {
                    availableChecklists.Clear();
                    foreach (ConfigNode checklistNode in WernherChecker.Instance.Settings.cfg.GetNodes("CHECKLIST"))
                    {
                        Debug.Log("[WernherChecker]: Parsing checklist - " + checklistNode.GetValue("name"));
                        Checklist parsedChecklist = new Checklist();
                        parsedChecklist.items = new List<ChecklistItem>();
                        parsedChecklist.name = checklistNode.GetValue("name");

                        ///Begining item cycle
                        foreach (ConfigNode itemNode in checklistNode.GetNodes("CHECKLIST_ITEM"))
                        {
                            //Debug.Log("parsing item " + itemNode.GetValue("name"));
                            ChecklistItem parsedItem = new ChecklistItem();
                            parsedItem.criteria = new List<Criterion>();
                            parsedItem.name = itemNode.GetValue("name");
                            if (!bool.TryParse(itemNode.GetValue("isManual"), out parsedItem.isManual))
                                parsedItem.isManual = false;
                            if(!bool.TryParse(itemNode.GetValue("allRequired"), out parsedItem.allRequired))
                                parsedItem.allRequired = true; ;

                            //Begining criterion cycle
                            foreach (ConfigNode criterionNode in itemNode.GetNodes("CRITERION"))
                            {
                                //Debug.Log("parsing criterion of type " + criterionNode.GetValue("type"));
                                Criterion parsedCriterion = new Criterion(criterionNode);

                                parsedItem.criteria.Add(parsedCriterion);
                            }
                            parsedChecklist.items.Add(parsedItem);
                        }
                        availableChecklists.Add(parsedChecklist);
                    }
                }
                return true;
            }

            catch
            {
                Debug.LogWarning("[WernherChecker]: Error loading checklist. Please, check your cfg file.");
                return false;
            }
        }