internal List <Guid> loadPinnedContracts(List <Guid> gID)
        {
            List <contractContainer> temp = new List <contractContainer>();
            List <Guid> idTemp            = new List <Guid>();

            foreach (Guid id in gID)
            {
                contractContainer c = getContract(id);
                if (c != null)
                {
                    if (c.listOrder != null)
                    {
                        temp.Add(c);
                    }
                }
            }
            if (temp.Count > 0)
            {
                temp.Sort((a, b) =>
                {
                    return(Comparer <int?> .Default.Compare(a.listOrder, b.listOrder));
                });
                foreach (contractContainer c in temp)
                {
                    idTemp.Add(c.contract.ContractGuid);
                }
            }
            return(idTemp);
        }
        private void onParameterAdded(Contract c, ContractParameter cP)
        {
            contractContainer cc = contractParser.getActiveContract(c.ContractGuid);

            if (cc == null)
            {
                return;
            }

            var missions = getMissionsContaining(cc.ID);

            for (int i = missions.Count - 1; i >= 0; i--)
            {
                contractMission m = missions[i];

                if (m == null)
                {
                    continue;
                }

                contractUIObject cUI = m.getContract(cc.ID);

                if (cUI == null)
                {
                    continue;
                }

                cUI.AddParameter();
            }
        }
        private string stringConcat(List <Guid> source)
        {
            if (source.Count == 0)
            {
                return("");
            }
            List <string> s = new List <string>();

            for (int j = 0; j < source.Count; j++)
            {
                contractContainer c = getContract(source[j]);
                if (c == null)
                {
                    continue;
                }
                string i;
                if (c.listOrder == null)
                {
                    i = "N";
                }
                else
                {
                    i = c.listOrder.ToString();
                }
                bool   show = c.showParams;
                string id   = string.Format("{0}|{1}|{2}", source[j], i, show);
                s.Add(id);
            }

            return(string.Join(",", s.ToArray()));
        }
 internal void addContract(Guid id, contractContainer c)
 {
     if (!masterList.ContainsKey(id))
     {
         masterList.Add(id, c);
     }
     else
     {
         DMC_MBE.LogFormatted_DebugOnly("Contract Already Present In List");
     }
 }
        internal void loadContractLists(string s, int l)
        {
            if (string.IsNullOrEmpty(s))
            {
                if (l == 0)
                {
                    showList = new List <Guid>();
                }
                else
                {
                    hiddenList = new List <Guid>();
                }
            }
            else
            {
                string[]    sA  = s.Split(',');
                List <Guid> gID = new List <Guid>();
                for (int i = 0; i < sA.Length; i++)
                {
                    contractContainer c  = null;
                    string[]          sB = sA[i].Split('|');
                    try
                    {
                        Guid g = new Guid(sB[0]);
                        c = getContract(g);
                        if (c != null)
                        {
                            gID.Add(g);
                        }
                        else
                        {
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        DMC_MBW.LogFormatted("Guid invalid: {0}", e);
                        continue;
                    }

                    c.listOrder  = stringIntParse(sB[1]);
                    c.showParams = stringBoolParse(sB[2]);
                }
                if (l == 0)
                {
                    showList = gID;
                }
                else
                {
                    hiddenList = gID;
                }
            }
        }
 /// <summary>
 /// A method for returning a contractContainer object. The contract in question must be loaded by Contracts
 /// Window + and may return null. All fields within the object are publicly accessible through properties.
 /// </summary>
 /// <param name="contract">Instance of the contract in question</param>
 /// <returns>contractContainer object</returns>
 public static contractContainer getContractContainer(Contract contract)
 {
     try
     {
         contractContainer c = contractParser.getActiveContract(contract.ContractGuid);
         return(c);
     }
     catch (Exception e)
     {
         Debug.LogWarning("[Contracts +] Something went wrong when attempting to get a Contract Container object: " + e);
         return(null);
     }
 }
 /// <summary>
 /// A method for manually resetting locally cached contract notes.
 /// </summary>
 /// <param name="contract">Instance of the contract in question</param>
 /// <param name="notes">The new contract notes</param>
 public static void setContractNotes(Contract contract, string notes)
 {
     try
     {
         contractContainer c = contractParser.getActiveContract(contract.ContractGuid);
         if (c != null)
         {
             c.Notes = notes;
         }
     }
     catch (Exception e)
     {
         Debug.LogWarning("[Contracts +] Something went wrong when attempting to assign new Contract Notes: " + e);
     }
 }
        //Initializes all missions that were added during the loading process
        internal void loadAllMissionLists()
        {
            if (missionList.Count <= 0)
            {
                addFullMissionList();
            }
            else
            {
                for (int i = 0; i < missionList.Count; i++)
                {
                    contractMission m = missionList.At(i);

                    if (m == null)
                    {
                        continue;
                    }

                    if (m.MasterMission)
                    {
                        m.buildMissionList();

                        List <contractContainer> active = contractParser.getActiveContracts;

                        int l = active.Count;

                        for (int j = 0; j < l; j++)
                        {
                            contractContainer c = active[j];

                            if (c == null)
                            {
                                continue;
                            }

                            m.addContract(c, true, false);
                        }

                        masterMission = m;
                    }
                    else
                    {
                        m.buildMissionList();
                    }
                }
            }
        }
 /// <summary>
 /// A method for returning a parameterContainer object. The contract and parameter in question must be loaded by
 /// Contracts Window + and may return null. All fields within the object are publicly accessible through properties.
 /// </summary>
 /// <param name="contract">Instance of the root contract (contractParameter.Root)</param>
 /// <param name="parameter">Instance of the contract parameter in question</param>
 /// <returns>parameterContainer object</returns>
 public static parameterContainer getParameterContainer(Contract contract, ContractParameter parameter)
 {
     try
     {
         contractContainer  c  = contractParser.getActiveContract(contract.ContractGuid);
         parameterContainer pC = null;
         if (c != null)
         {
             pC = c.AllParamList.SingleOrDefault(a => a.CParam == parameter);
         }
         return(pC);
     }
     catch (Exception e)
     {
         Debug.LogWarning("[Contracts +] Something went wrong when attempting to get a Parameter Container object: " + e);
         return(null);
     }
 }
 /// <summary>
 /// A method for manually resetting a locally cached contract title.
 /// </summary>
 /// <param name="contract">Instance of the contract in question</param>
 /// <param name="name">The new contract title</param>
 public static void setContractTitle(Contract contract, string name)
 {
     try
     {
         if (string.IsNullOrEmpty(name))
         {
             return;
         }
         contractContainer c = contractParser.getActiveContract(contract.ContractGuid);
         if (c != null)
         {
             c.Title = name;
         }
     }
     catch (Exception e)
     {
         Debug.LogWarning("[Contracts +] Something went wrong when attempting to assign a new Contract Title: " + e);
     }
 }
 /// <summary>
 /// A method for manually resetting locally cached contract parameter notes.
 /// </summary>
 /// <param name="contract">Instance of the root contract (contractParameter.Root)</param>
 /// <param name="parameter">Instance of the contract parameter in question</param>
 /// <param name="notes">The new contract parameter notes</param>
 public static void setParameterNotes(Contract contract, ContractParameter parameter, string notes)
 {
     try
     {
         contractContainer c = contractParser.getActiveContract(contract.ContractGuid);
         if (c != null)
         {
             parameterContainer pC = c.AllParamList.SingleOrDefault(a => a.CParam == parameter);
             if (pC != null)
             {
                 pC.setNotes(notes);
             }
         }
     }
     catch (Exception e)
     {
         Debug.LogWarning("[Contracts +] Something went wrong when attempting to assign a new Parameter Notes: " + e);
     }
 }
        //Adds all contracts to the master mission
        private void addAllContractsToMaster()
        {
            contractMission Master = null;

            for (int i = missionList.Count - 1; i >= 0; i--)
            {
                contractMission m = missionList.At(i);

                if (m == null)
                {
                    continue;
                }

                if (!m.MasterMission)
                {
                    continue;
                }

                Master = m;
                break;
            }

            if (Master != null)
            {
                List <contractContainer> active = contractParser.getActiveContracts;

                int l = active.Count;

                for (int j = 0; j < l; j++)
                {
                    contractContainer c = active[j];

                    if (c == null)
                    {
                        continue;
                    }

                    Master.addContract(c, true, true);
                }
            }
        }
 internal contractUIObject(contractContainer c)
 {
     container = c;
     showParams = true;
     order = null;
 }
		internal void addContract(Guid id, contractContainer c)
		{
			if (!masterList.ContainsKey(id))
				masterList.Add(id, c);
			else
				DMC_MBE.LogFormatted("Error Adding Contract; Already Present In Master List");
		}
        private void buildParameterLabel(parameterContainer cP, contractContainer c, int level, int id, int size, ref Rect r)
        {
            string paramTitle = cP.Title;
            bool active = cP.CParam.State == ParameterState.Incomplete;
            bool greenState = cP.CParam.State == ParameterState.Complete || cP.CParam.State == ParameterState.Incomplete;
            bool redState = cP.CParam.State == ParameterState.Incomplete || cP.CParam.State == ParameterState.Failed;
            GUIStyle pStyle = paramState(cP);

            GUILayout.BeginHorizontal();
            GUILayout.Space(5 + (level * 5));

            r.x = 5 + (level * 5);
            r.y += r.height;

            //Note icon button
            if (active && !string.IsNullOrEmpty(cP.Notes))
            {
                r.x -= 2;
                r.y += 4;
                r.width = 12 + (size * 2);
                r.height = 14 + (size * 4);

                if (!cP.ShowNote)
                {
                    if (GUI.Button(r, new GUIContent(contractSkins.noteIcon, "Show Note"), contractSkins.texButtonSmall))
                        cP.ShowNote = !cP.ShowNote;
                }
                else
                {
                    if (GUI.Button(r, new GUIContent(contractSkins.noteIconOff, "Hide Note"), contractSkins.texButtonSmall))
                        cP.ShowNote = !cP.ShowNote;
                }
                GUILayout.Space(12 + size * 2);
            }

            /* FIXME - Disabled For Now; Need to Figure Out Changes Made In 0.90 */
            //Editor part icon button
            //if (cP.part != null && HighLogic.LoadedSceneIsEditor)
            //{
            //	if (GUILayout.Button(new GUIContent(contractSkins.partIcon, "Preview Part"), contractSkins.texButtonSmall, GUILayout.MaxWidth(18 + contractScenario.Instance.windowSize * 4), GUILayout.MaxHeight(18 + contractScenario.Instance.windowSize * 4)))
            //	{
            //		EditorLogic.fetch.Unlock(lockID);
            //		editorLocked = false;
            //		EditorPartList.Instance.RevealPart(cP.part, true);
            //	}
            //	GUILayout.Space(-3);
            //}

            //Contract parameter title
            if (!string.IsNullOrEmpty(cP.Notes))
                GUILayout.Box(paramTitle, pStyle, GUILayout.MaxWidth(208 - (level * 5) + size * 28));
            else
                GUILayout.Box(paramTitle, pStyle, GUILayout.MaxWidth(220 - (level * 5) + size * 30));

            r = GUILayoutUtility.GetLastRect();

            GUILayout.EndHorizontal();

            //Parameter reward info
            if (WindowRect.width >= 270 + (size * 30))
            {
                if (r.yMin >= (scroll.y - 20) && r.yMax <= (scroll.y + WindowRect.height - (30 + size * 6)))
                {
                    Rect rewardsRect = r;
                    rewardsRect.x = 230 + (size * 30);
                    rewardsRect.y += 4;

                    scaledContent(ref rewardsRect, cP.FundsRewString, cP.FundsPenString, Currency.Funds, size, greenState, redState);

                    scaledContent(ref rewardsRect, cP.SciRewString, "", Currency.Science, size, greenState, redState);

                    scaledContent(ref rewardsRect, cP.RepRewString, cP.RepPenString, Currency.Reputation, size, greenState, redState);
                }
            }

            //Display note
            if (!string.IsNullOrEmpty(cP.Notes) && cP.ShowNote && active)
            {
                GUILayout.Space(-6);
                GUILayout.Box(cP.Notes, GUILayout.MaxWidth(320 + size * 60));

                r.height += GUILayoutUtility.GetLastRect().height;
            }

            if (level < 4)
            {
                foreach (parameterContainer sP in cP.ParamList)
                {
                    if (sP.Level == level + 1 && !string.IsNullOrEmpty(sP.Title))
                    {
                        if (active)
                            buildParameterLabel(sP, c, level + 1, id, size, ref r);
                    }
                }
            }
        }
        internal parameterContainer(contractContainer Root, ContractParameter cP, int Level, string PartTestName)
        {
            root = Root;
            cParam = cP;
            showNote = false;
            level = Level;
            paramRewards(cP);
            paramPenalties(cP);
            title = cParam.Title;
            notes = cParam.Notes;

            if (level < 4)
            {
                for (int i = 0; i < cParam.ParameterCount; i++)
                {
                    ContractParameter param = cParam.GetParameter(i);
                    addSubParam(param, level + 1);
                }
            }

            if (!string.IsNullOrEmpty(PartTestName))
            {
                if (PartTestName == "partTest")
                {
                    part = ((Contracts.Parameters.PartTest)cParam).tgtPartInfo;
                    DMC_MBE.LogFormatted_DebugOnly("Part Assigned For Stock Part Test");
                }
                else if (PartTestName == "MCEScience")
                {
                    if (contractAssembly.MCELoaded)
                    {
                        part = PartLoader.Instance.parts.FirstOrDefault(p => p.partPrefab.partInfo.title == contractAssembly.MCEPartName(cParam));
                        if (part != null)
                            DMC_MBE.LogFormatted_DebugOnly("Part Assigned For Mission Controller Contract");
                        else
                            DMC_MBE.LogFormatted_DebugOnly("Part Not Found");
                    }
                }
                else if (PartTestName == "DMcollectScience")
                {
                    if (contractAssembly.DMLoaded)
                    {
                        part = PartLoader.getPartInfoByName(contractAssembly.DMagicSciencePartName(cParam));
                        if (part != null)
                            DMC_MBE.LogFormatted_DebugOnly("Part Assigned For DMagic Contract");
                        else
                            DMC_MBE.LogFormatted_DebugOnly("Part Not Found");
                    }
                }
                else if (PartTestName == "DManomalyScience")
                {
                    if (contractAssembly.DMALoaded)
                    {
                        part = PartLoader.getPartInfoByName(contractAssembly.DMagicAnomalySciencePartName(cParam));
                        if (part != null)
                            DMC_MBE.LogFormatted_DebugOnly("Part Assigned For DMagic Anomaly Contract");
                        else
                            DMC_MBE.LogFormatted_DebugOnly("Part Not Found");
                    }
                }
                else if (PartTestName == "DMasteroidScience")
                {
                    if (contractAssembly.DMAstLoaded)
                    {
                        part = PartLoader.getPartInfoByName(contractAssembly.DMagicAsteroidSciencePartName(cParam));
                        if (part != null)
                            DMC_MBE.LogFormatted_DebugOnly("Part Assigned For DMagic Asteroid Contract");
                        else
                            DMC_MBE.LogFormatted_DebugOnly("Part Not Found");
                    }
                }
                else if (PartTestName == "FinePrint")
                {
                    part = PartLoader.getPartInfoByName(contractAssembly.FPPartName(cParam));
                    if (part != null)
                        DMC_MBE.LogFormatted_DebugOnly("Part Assigned For Fine Print Contract");
                    else
                        DMC_MBE.LogFormatted_DebugOnly("Part Not Found");
                }
                else
                    part = null;
            }
        }