public void TransferExperiment(WBIModuleScienceExperiment sourceExperiment) { //Load parameters from experiment definition LoadFromDefinition(sourceExperiment.experimentID); //Set state variables this.isCompleted = sourceExperiment.isCompleted; this.isRunning = sourceExperiment.isRunning; this.experimentFailed = sourceExperiment.experimentFailed; this.status = sourceExperiment.status; this.notificationSent = sourceExperiment.notificationSent; this.accumulatedResources = sourceExperiment.accumulatedResources; //Rebuild resource map rebuildResourceMap(); //Let listeners know if (onExperimentReceived != null) { onExperimentReceived(this); } if (sourceExperiment.onExperimentTransfered != null) { sourceExperiment.onExperimentTransfered(sourceExperiment); } //Now set the source experiment to a dummy experiment sourceExperiment.LoadFromDefinition(defaultExperiment); sourceExperiment.CheckCompletion(); //Do a quick check for completion CheckCompletion(); //If the experiment is completed then be sure to transfer its ScienceData. if (isCompleted) { finalTransfer = true; ScienceData[] scienceData = sourceExperiment.GetData(); for (int index = 0; index < scienceData.Length; index++) { ReturnData(scienceData[index]); } sourceExperiment.ResetExperiment(); } }
protected void drawExperiments() { ConfigNode experimentDef; ConfigNode[] defs = experimentDefs.ToArray(); if (experimentDefs == null) { GUILayout.Label("No experiment slots available"); return; } scrollPos = GUILayout.BeginScrollView(scrollPos); for (int index = 0; index < defs.Length; index++) { experimentDef = defs[index]; GUILayout.BeginVertical(); GUILayout.BeginScrollView(scrollPosPanel, experimentPanelOptions); GUILayout.BeginHorizontal(); //Transfer button if (GUILayout.Button(transferIcon, buttonOptions)) { //If needed make sure we can build the experiment. if (checkCreationResources && confirmCreationIndex == index) { confirmCreationIndex = -1; if (buildExperiment(experimentDef.GetValue("creationResources"))) { transferRecipient.LoadFromDefinition(experimentDef.GetValue("id"), true); SetVisible(false); } else //Not enough resources { ScreenMessages.PostScreenMessage("Insufficient resources to create the experiment.", 5.0f, ScreenMessageStyle.UPPER_CENTER); } } else if (checkCreationResources) { confirmCreationIndex = index; ScreenMessages.PostScreenMessage("Click again to confirm experiment creation.", 5.0f, ScreenMessageStyle.UPPER_CENTER); } //Resources not required, just transfer the experiment. else { transferRecipient.LoadFromDefinition(experimentDef.GetValue("id"), true); SetVisible(false); } } GUILayout.BeginVertical(); //Title GUILayout.BeginHorizontal(); GUILayout.Label(experimentIcon, iconOptions); GUILayout.Label(experimentDef.GetValue("title")); GUILayout.EndHorizontal(); //Creation costs if (checkCreationResources) { GUILayout.Label("To build: " + experimentDef.GetValue("creationResources")); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndScrollView(); //Hit test for the experiment panel if (Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition)) { if (lastExpDef != experimentDef) { lastExpDef = experimentDef; experimentSynopsis = getSynopsis(experimentDef); scrollPosSynopsis = new Vector2(0, 0); } } GUILayout.EndVertical(); } GUILayout.EndScrollView(); }