public void TransferExperiment(WBIModuleScienceExperiment experiment) { WBIModuleScienceExperiment experimentSlot; //Find an available slot for (int index = 0; index < experimentSlots.Length; index++) { experimentSlot = experimentSlots[index]; if (experimentSlot.experimentID == experimentSlot.defaultExperiment) { experimentSlot.TransferExperiment(experiment); ScreenMessages.PostScreenMessage(experimentSlot.title + " transfered to " + this.part.partInfo.title, 5.0f, ScreenMessageStyle.UPPER_CENTER); return; } } }
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 OnExperimentReceived(WBIModuleScienceExperiment transferRecipient) { ConfigNode nodeResource = null; PartResource resource = null; string resourceName; string[] mapKeys; int index; //If the experiment has resources then go through them and either add //the resources it needs or increase the max amount if (transferRecipient.resourceMap != null) { mapKeys = transferRecipient.resourceMap.Keys.ToArray <string>(); for (index = 0; index < mapKeys.Length; index++) { resourceName = mapKeys[index]; //Add the resource if needed if (this.part.Resources.Contains(resourceName) == false) { nodeResource = new ConfigNode("RESOURCE"); nodeResource.AddValue("name", resourceName); nodeResource.AddValue("amount", "0"); nodeResource.AddValue("maxAmount", transferRecipient.resourceMap[resourceName].targetAmount.ToString()); resource = this.part.Resources.Add(nodeResource); resource.isVisible = false; resource.isTweakable = false; } //Add to max amount to account for amount that the experiment needs else { this.part.Resources[resourceName].maxAmount += transferRecipient.resourceMap[resourceName].targetAmount; } } //Dirty the GUI MonoUtilities.RefreshContextWindows(this.part); } }
protected void OnExperimentTransfered(WBIModuleScienceExperiment transferedExperiment) { }
protected void OnExperimentReceived(WBIModuleScienceExperiment transferRecipient) { }
protected void transferExperiment(WBIModuleScienceExperiment experimentSlot) { bool createNewExperiment = canCreateExperiments && experimentSlot.experimentID == experimentSlot.defaultExperiment && HighLogic.LoadedSceneIsFlight; //Inform user if we are trying to create a new experiment but we don't have the ability. if (createNewExperiment && !hasCreationAbility) { ScreenMessages.PostScreenMessage("You need a " + minimumCreationLevel + "-star " + experimentCreationSkill + " and a connection to KSC in order to create experiments.", 5.0f, ScreenMessageStyle.UPPER_CENTER); return; } //If we're in the editor or we are creating a new experiment then show the load experiment screen. else if (HighLogic.LoadedSceneIsEditor || (createNewExperiment && hasCreationAbility)) { //If creating a new experiment then set the check resources flag and creation tags. loadExperimentView.creationTags = string.Empty; if (createNewExperiment && experimentLab != null) { loadExperimentView.checkCreationResources = experimentLab.checkCreationResources; loadExperimentView.creationTags = experimentLab.creationTags; loadExperimentView.minimumCreationAmount = experimentLab.minimumCreationAmount; loadExperimentView.defaultCreationResource = experimentLab.defaultCreationResource; } loadExperimentView.defaultExperiment = experimentSlot.defaultExperiment; loadExperimentView.transferRecipient = experimentSlot; loadExperimentView.part = this.part; loadExperimentView.windowPos = this.windowPos; loadExperimentView.windowPos.position += new Vector2(40.0f, 40.0f); loadExperimentView.SetVisible(true); } //If we're in flight then highlight the available experiment containers. else if (HighLogic.LoadedSceneIsFlight) { //Make sure we have an experiment to transfer. if (experimentSlot.experimentID == experimentSlot.defaultExperiment) { ScreenMessages.PostScreenMessage("No experiment to transfer, this slot is empty.", 5.0f, ScreenMessageStyle.UPPER_CENTER); return; } List <WBIExperimentManifest> manifests = this.part.vessel.FindPartModulesImplementing <WBIExperimentManifest>(); List <WBIExperimentLab> labs = this.part.vessel.FindPartModulesImplementing <WBIExperimentLab>(); WBIExperimentLab thisLab = this.part.FindModuleImplementing <WBIExperimentLab>(); WBIExperimentManifest thisManifest = this.part.FindModuleImplementing <WBIExperimentManifest>(); Color sourceColor = new Color(1, 1, 0); Color destinationColor = new Color(0, 191, 243); bool foundAvailableSlot = false; int index; int totalCount; WBIExperimentManifest manifest; WBIExperimentLab lab; //Highlight the manifests totalCount = manifests.Count; for (index = 0; index < totalCount; index++) { manifest = manifests[index]; //Part can accept the experiment if it is not full. if (manifest != thisManifest && manifest.HasAvailableSlots()) { foundAvailableSlot = true; manifest.part.Highlight(destinationColor); manifest.part.AddOnMouseDown(onPartMouseDown); } else { manifest.part.Highlight(sourceColor); } } //Highlight labs totalCount = labs.Count; for (index = 0; index < totalCount; index++) { lab = labs[index]; //Part can accept the experiment if it is not full. if (lab != thisLab && lab.HasAvailableSlots()) { foundAvailableSlot = true; lab.part.Highlight(destinationColor); lab.part.AddOnMouseDown(onPartMouseDown); } else { lab.part.Highlight(sourceColor); } } //If we couldn't find an available slot then don't transfer the experiment. if (foundAvailableSlot) { //Save the experiment to transfer experimentToTransfer = experimentSlot; //Tell user what to do ScreenMessages.PostScreenMessage("Click a destination to receive the experiment. Press the ESCAPE key to cancel.", 5.0f, ScreenMessageStyle.UPPER_CENTER); InputLockManager.SetControlLock(ControlTypes.ALLBUTCAMERAS, "ExperimentManifestLock"); } else { //Clear highlights if (thisManifest != null) { thisManifest.part.Highlight(false); } if (thisLab != null) { thisLab.part.Highlight(false); } ScreenMessages.PostScreenMessage("You need more experiment space.", 5.0f, ScreenMessageStyle.UPPER_CENTER); } } }
protected void drawExperiments() { int index; WBIModuleScienceExperiment experimentSlot; if (experimentSlots == null) { GUILayout.Label("No experiment slots available"); return; } checkCreationAbility(); scrollPos = GUILayout.BeginScrollView(scrollPos); for (index = 0; index < experimentSlots.Length; index++) { experimentSlot = experimentSlots[index]; GUILayout.BeginVertical(); GUILayout.BeginScrollView(scrollPosPanel, experimentPanelOptions); GUILayout.BeginHorizontal(); //Transfer button Texture xFerIcon; if (hasCreationAbility && experimentSlot.experimentID == experimentSlot.defaultExperiment) { xFerIcon = loadIcon; } else if (HighLogic.LoadedSceneIsFlight) { xFerIcon = transferIcon; } else { xFerIcon = loadIcon; } if (GUILayout.Button(xFerIcon, buttonOptions)) { transferExperiment(experimentSlot); } GUILayout.BeginVertical(); //Title GUILayout.BeginHorizontal(); GUILayout.Label(experimentIcon, iconOptions); GUILayout.Label(experimentSlot.title); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); //Run/Pause (flight only, Experiment Lab only) if (experimentLab != null && labGUIVisible) { if (HighLogic.LoadedSceneIsFlight && experimentSlot.isCompleted == false) { if (experimentSlot.isRunning) { if (GUILayout.Button(pauseIcon, iconOptions)) { experimentSlot.isRunning = false; } } else { if (GUILayout.Button(playIcon, iconOptions)) { experimentSlot.isRunning = true; } } } if (experimentSlot.isRunning && experimentLab.IsActivated == false) { experimentLab.StartConverter(); } } //Trashcan if (GUILayout.Button(trashcanIcon, iconOptions)) { //Verify that user wants to clear the experiment. //If so, then clear the experiment (load the default). if (HighLogic.LoadedSceneIsFlight && !clearExperimentConfirmed) { clearExperimentConfirmed = true; ScreenMessages.PostScreenMessage("Existing experiment will be removed. Click a second time to confirm.", 5.0f, ScreenMessageStyle.UPPER_CENTER); } else { clearExperimentConfirmed = false; experimentSlot.ClearExperiment(); } } //Status if (experimentStatusVisible) { if (experimentSlot.isCompleted) { GUILayout.Label(completedIcon, iconOptions); } else { GUILayout.Label(infoIcon, iconOptions); } GUILayout.Label(experimentSlot.status); } else if (experimentLab == null && experimentSlot.isCompleted) { GUILayout.Label("Ready to be recovered"); } GUILayout.EndHorizontal(); 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 (lastExperimentSlot != experimentSlot) { lastExperimentSlot = experimentSlot; experimentSynopsis = experimentSlot.GetInfo(); scrollPosSynopsis = new Vector2(0, 0); } } GUILayout.EndVertical(); } GUILayout.EndScrollView(); }