/// <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 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); } }
//Change parameter title GUIStyle based on its current state private GUIStyle paramState(parameterContainer cP) { switch (cP.CParam.State) { case ParameterState.Complete: return contractSkins.paramCompleted; case ParameterState.Failed: return contractSkins.paramFailed; default: if (cP.Level == 0) return contractSkins.paramText; else return contractSkins.paramSub; } }
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 void addToParamList(parameterContainer pC) { allParamList.Add(pC); }