internal static void UpdateDisplayPumps() { // Now lets update the Resource Xfer pumps for display use... if (!SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources)) { return; } if (!WindowTransfer.DisplayPumps.Any()) { CreateDisplayPumps(); } // Lets create a pump Object for managing pump options and data. List <Part> sourceParts = WindowTransfer.ShowSourceVessels ? SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsSource, SMAddon.SmVessel.SelectedResources) : SMAddon.SmVessel.SelectedPartsSource; List <Part> targetParts = WindowTransfer.ShowTargetVessels ? SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsTarget, SMAddon.SmVessel.SelectedResources) : SMAddon.SmVessel.SelectedPartsTarget; List <TransferPump> .Enumerator dPumps = WindowTransfer.DisplayPumps.GetEnumerator(); while (dPumps.MoveNext()) { if (dPumps.Current == null) { continue; } // Lets update pump data (it persists). TransferPump pump = dPumps.Current; switch (pump.PumpType) { case TypePump.Dump: case TypePump.SourceToTarget: pump.FromParts = sourceParts; pump.ToParts = targetParts; break; case TypePump.TargetToSource: pump.FromParts = targetParts; pump.ToParts = sourceParts; break; } pump.EditSliderAmount = CalcMaxPumpAmt(pump.FromParts, pump.ToParts, SMAddon.SmVessel.SelectedResources) .ToString(CultureInfo.InvariantCulture); } dPumps.Dispose(); }
internal static void CreateDisplayPumps() { // Now lets update the Resource Xfer pumps for display use... WindowTransfer.DisplayPumps.Clear(); if (!SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources)) { return; } // Lets create a pump Object for managing pump options and data. List <Part> displaySourceParts = WindowTransfer.ShowSourceVessels ? SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsSource, SMAddon.SmVessel.SelectedResources) : SMAddon.SmVessel.SelectedPartsSource; List <Part> displayTargetParts = WindowTransfer.ShowTargetVessels ? SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsTarget, SMAddon.SmVessel.SelectedResources) : SMAddon.SmVessel.SelectedPartsTarget; List <string> .Enumerator resources = SMAddon.SmVessel.SelectedResources.GetEnumerator(); while (resources.MoveNext()) { TransferPump pump1 = new TransferPump { Resource = resources.Current, PumpType = TypePump.SourceToTarget, PumpAmount = CalcMaxPumpAmt(displaySourceParts, displayTargetParts, SMAddon.SmVessel.SelectedResources), EditSliderAmount = CalcMaxPumpAmt(displaySourceParts, displayTargetParts, SMAddon.SmVessel.SelectedResources) .ToString(CultureInfo.InvariantCulture), FromParts = displaySourceParts, ToParts = displayTargetParts }; WindowTransfer.DisplayPumps.Add(pump1); TransferPump pump2 = new TransferPump { Resource = resources.Current, PumpType = TypePump.TargetToSource, PumpAmount = CalcMaxPumpAmt(displayTargetParts, displaySourceParts, SMAddon.SmVessel.SelectedResources), EditSliderAmount = CalcMaxPumpAmt(displayTargetParts, displaySourceParts, SMAddon.SmVessel.SelectedResources) .ToString(CultureInfo.InvariantCulture), FromParts = displayTargetParts, ToParts = displaySourceParts }; WindowTransfer.DisplayPumps.Add(pump2); } resources.Dispose(); }
internal static void ResolveResourcePartSelections(List <string> resourceNames) { try { if (resourceNames.Count > 0) { List <Part> newSources = new List <Part>(); List <Part> newTargets = new List <Part>(); if (WindowTransfer.ShowSourceVessels && SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources)) { SMAddon.SmVessel.SelectedPartsSource = SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsSource, resourceNames); if (!WindowTransfer.ShowTargetVessels) { List <Part> .Enumerator srcParts = SMAddon.SmVessel.SelectedPartsSource.GetEnumerator(); while (srcParts.MoveNext()) { if (srcParts.Current == null) { continue; } if (!SMAddon.SmVessel.SelectedPartsTarget.Contains(srcParts.Current)) { continue; } SMAddon.SmVessel.SelectedPartsTarget.Remove(srcParts.Current); } srcParts.Dispose(); } } else { List <Part> .Enumerator parts = SMAddon.SmVessel.SelectedPartsSource.GetEnumerator(); while (parts.MoveNext()) { if (parts.Current == null) { continue; } if (resourceNames.Count > 1) { if (parts.Current.Resources.Contains(resourceNames[0]) && parts.Current.Resources.Contains(resourceNames[1])) { newSources.Add(parts.Current); } } else { if (resourceNames[0] == SMConditions.ResourceType.Crew.ToString() && parts.Current.CrewCapacity > 0) { newSources.Add(parts.Current); } else if (resourceNames[0] == SMConditions.ResourceType.Science.ToString() && parts.Current.FindModulesImplementing <IScienceDataContainer>().Count > 0) { newSources.Add(parts.Current); } else if (parts.Current.Resources.Contains(resourceNames[0])) { newSources.Add(parts.Current); } } } parts.Dispose(); SMAddon.SmVessel.SelectedPartsSource.Clear(); SMAddon.SmVessel.SelectedPartsSource = newSources; } if (WindowTransfer.ShowTargetVessels && SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources)) { SMAddon.SmVessel.SelectedPartsTarget = SMAddon.SmVessel.GetSelectedVesselsParts(SMAddon.SmVessel.SelectedVesselsTarget, resourceNames); if (!WindowTransfer.ShowSourceVessels) { List <Part> .Enumerator tgtParts = SMAddon.SmVessel.SelectedPartsTarget.GetEnumerator(); while (tgtParts.MoveNext()) { if (tgtParts.Current == null) { continue; } if (!SMAddon.SmVessel.SelectedPartsSource.Contains(tgtParts.Current)) { continue; } SMAddon.SmVessel.SelectedPartsSource.Remove(tgtParts.Current); } tgtParts.Dispose(); } } else { List <Part> .Enumerator tgtParts = SMAddon.SmVessel.SelectedPartsTarget.GetEnumerator(); while (tgtParts.MoveNext()) { if (tgtParts.Current == null) { continue; } if (resourceNames.Count > 1) { if (tgtParts.Current.Resources.Contains(resourceNames[0]) && tgtParts.Current.Resources.Contains(resourceNames[1])) { newTargets.Add(tgtParts.Current); } } else { if (resourceNames[0] == SMConditions.ResourceType.Crew.ToString() && tgtParts.Current.CrewCapacity > 0) { newTargets.Add(tgtParts.Current); } else if (resourceNames[0] == SMConditions.ResourceType.Science.ToString() && tgtParts.Current.FindModulesImplementing <IScienceDataContainer>().Count > 0) { newTargets.Add(tgtParts.Current); } else if (tgtParts.Current.Resources.Contains(resourceNames[0])) { newTargets.Add(tgtParts.Current); } } } tgtParts.Dispose(); SMAddon.SmVessel.SelectedPartsTarget.Clear(); SMAddon.SmVessel.SelectedPartsTarget = newTargets; } if (SMConditions.AreSelectedResourcesTypeOther(resourceNames)) { TransferPump.CreateDisplayPumps(); return; } SMAddon.SmVessel.SelectedVesselsSource.Clear(); SMAddon.SmVessel.SelectedVesselsTarget.Clear(); } else { SMAddon.SmVessel.SelectedPartsSource.Clear(); SMAddon.SmVessel.SelectedPartsTarget.Clear(); SMAddon.SmVessel.SelectedVesselsSource.Clear(); SMAddon.SmVessel.SelectedVesselsTarget.Clear(); } } catch (Exception ex) { SMUtils.LogMessage( string.Format(" in WindowManifest.ReconcileSelectedXferParts. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); // in, Error } }
private static void ResourceDetailsViewer() { try { _resourceScrollViewerPosition = GUILayout.BeginScrollView(_resourceScrollViewerPosition, SMStyle.ScrollStyle, GUILayout.Height(100), GUILayout.Width(300)); GUILayout.BeginVertical(); if (SMAddon.SmVessel.SelectedResources.Count > 0) { List <Part> .Enumerator pParts = SMAddon.SmVessel.SelectedResourcesParts.GetEnumerator(); while (pParts.MoveNext()) { if (pParts.Current == null) { continue; } Part part = pParts.Current; if (SMConditions.AreSelectedResourcesTypeOther(SMAddon.SmVessel.SelectedResources)) { GUIStyle noWrap = SMStyle.LabelStyleNoWrap; GUILayout.Label(string.Format("{0}", part.partInfo.title), noWrap, GUILayout.Width(265), GUILayout.Height(18)); GUIStyle noPad = SMStyle.LabelStyleNoPad; List <string> .Enumerator sResources = SMAddon.SmVessel.SelectedResources.GetEnumerator(); while (sResources.MoveNext()) { if (sResources.Current == null) { continue; } GUILayout.Label( string.Format(" - {0}: ({1:######0.####}/{2:######0.####})", sResources.Current, part.Resources[sResources.Current].amount, part.Resources[sResources.Current].maxAmount), noPad, GUILayout.Width(265), GUILayout.Height(16)); } sResources.Dispose(); } else if (SMAddon.SmVessel.SelectedResources.Contains(SMConditions.ResourceType.Crew.ToString())) { GUILayout.BeginHorizontal(); GUILayout.Label( string.Format("{0}, ({1}/{2})", part.partInfo.title, SMUtils.GetPartCrewCount(part), part.CrewCapacity), GUILayout.Width(265), GUILayout.Height(20)); GUILayout.EndHorizontal(); } else if (SMAddon.SmVessel.SelectedResources.Contains(SMConditions.ResourceType.Science.ToString())) { int scienceCount = 0; IEnumerator pModules = part.Modules.GetEnumerator(); while (pModules.MoveNext()) { if (pModules.Current == null) { continue; } PartModule pm = (PartModule)pModules.Current; ModuleScienceContainer container = pm as ModuleScienceContainer; if (container != null) { scienceCount += container.GetScienceCount(); } else if (pm is ModuleScienceExperiment) { scienceCount += ((ModuleScienceExperiment)pm).GetScienceCount(); } } GUILayout.BeginHorizontal(); GUILayout.Label(string.Format("{0}, ({1})", part.partInfo.title, scienceCount), GUILayout.Width(265)); GUILayout.EndHorizontal(); } } pParts.Dispose(); } } catch (Exception ex) { if (!SMAddon.FrameErrTripped) { SMUtils.LogMessage( string.Format(" in WindowManifest.ResourceDetailsViewer. Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), SMUtils.LogType.Error, true); // in, Error SMAddon.FrameErrTripped = true; } } GUILayout.EndVertical(); GUILayout.EndScrollView(); }