/// <summary> /// returns capacity of parts we are transferring to (targets relative to xferMode) /// </summary> internal double ToCapacity(SMAddon.XFERDirection XferMode) { if (XferMode == SMAddon.XFERDirection.SourceToTarget) return CalcResourceCapacity(SMAddon.smController.SelectedPartsTarget, ResourceName); else return CalcResourceCapacity(SMAddon.smController.SelectedPartsSource, ResourceName); }
// methods to derive data from part selection lists and xferMode internal double XferAmount(SMAddon.XFERDirection XferMode) { // which way we going? if (XferMode == SMAddon.XFERDirection.SourceToTarget) return srcXferAmount; else return tgtXferAmount; }
private static void ResourceDetails(List<Part> partsSource, List<Part> partsTarget, SMAddon.XFERDirection xferMode, Vector2 scrollPosition) { // This routine assumes that a resource has been selected on the Resource manifest window. // Set scrollX offsets for left and right viewers int xOffset = xferMode == SMAddon.XFERDirection.SourceToTarget ? 30 : 330; int yOffset = 160; string label = ""; string toolTip = ""; Rect rect = new Rect(); // Pass in static vars to improve readability. List<string> selectedResources = SMAddon.smController.SelectedResources; List<TransferResource> XferResources = SMAddon.smController.ResourcesToXfer; if (partsSource.Count > 0) { TransferResource modResource = TransferResource.GetXferResource(XferResources, xferMode, false); TransferResource ratioResource = TransferResource.GetXferResource(XferResources, xferMode, true); modResource.XferRatio = 1; ratioResource.XferRatio = TransferResource.CalcRatio(XferResources, xferMode); double thisXferAmount = modResource.XferAmount(xferMode); double ratioXferAmt = ratioResource.XferAmount(xferMode); string strXferAmount = modResource.XferAmount(xferMode).ToString(); // Set tooltips directional data string strTarget = xferMode == SMAddon.XFERDirection.SourceToTarget ? "Target" : "Source"; // Resource Flow control Display loop ResourceFlowButtons(partsSource, xferMode, scrollPosition, xOffset, yOffset); // Xfer Controls Display // let's determine how much of a resource we can move to the target. double maxXferAmount = TransferResource.CalcMaxXferAmt(partsSource, partsTarget, selectedResources); if (maxXferAmount > 0 || TransferResource.ResourceXferActive) { GUILayout.BeginHorizontal(); if (TransferResource.ResourceXferActive) { // We want to show this during transfer if the direction is correct... if (SMAddon.XferMode == xferMode) { GUILayout.Label("Xfer Remaining:", GUILayout.Width(120)); GUILayout.Label((modResource.XferAmount(SMAddon.XferMode) - modResource.AmtXferred).ToString("#######0.##")); if (SMAddon.smController.SelectedResources.Count > 1) GUILayout.Label(" | " + (ratioResource.XferAmount(SMAddon.XferMode) - ratioResource.AmtXferred).ToString("#######0.##")); } } else { // Lets parse the string to allow decimal points. strXferAmount = modResource.XferAmount(xferMode).ToString(); // add the decimal point if it was typed. strXferAmount = modResource.GetStringDecimal(strXferAmount, xferMode); // add the zero if it was typed. strXferAmount = modResource.GetStringZero(strXferAmount, xferMode); // Now update the static var modResource.SetXferAmountString(strXferAmount, xferMode); if (selectedResources.Count > 1) { label = "Xfer Amts:"; toolTip = "Displays xfer amounts of both resourses selected."; toolTip += "\r\nAllows editing of part's larger capacity resourse xfer value."; toolTip += "\r\nIt then calculates the smaller xfer amount using a ratio"; toolTip += "\r\n of the smaller capacity resource to the larger."; } else { label = "Xfer Amt:"; toolTip += "Displays the Amount of selected resource to xfer."; toolTip += "\r\nAllows editing of the xfer value."; } GUILayout.Label(new GUIContent(label, toolTip), GUILayout.Width(65)); rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips == true) ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - scrollPosition.y); strXferAmount = GUILayout.TextField(strXferAmount, 20, GUILayout.Width(95), GUILayout.Height(20)); // update decimal bool modResource.SetStringDecimal(strXferAmount, xferMode); //update zero bool modResource.SetStringZero(strXferAmount, xferMode); // Update static Xfer Amount var thisXferAmount = modResource.UpdateXferAmount(strXferAmount, xferMode); ratioXferAmt = thisXferAmount * ratioResource.XferRatio > ratioResource.FromCapacity(xferMode) ? ratioResource.FromCapacity(xferMode) : thisXferAmount * ratioResource.XferRatio; if (SMAddon.smController.SelectedResources.Count > 1) { label = " | " + ratioXferAmt.ToString("#######0.##"); toolTip = "Smaller Tank xfer amount. Calculated at " + ratioResource.XferRatio.ToString() + ".\r\n(Note: A value of 0.818181 = 0.9/1.1)"; GUILayout.Label(new GUIContent(label, toolTip), GUILayout.Width(80)); rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips == true) ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - scrollPosition.y); } } GUILayout.EndHorizontal(); if (IsShipControllable() && CanResourceBeXferred(xferMode, maxXferAmount)) { GUILayout.BeginHorizontal(); GUIStyle noPad = SMStyle.LabelStyleNoPad; label = "Xfer:"; toolTip = "Xfer amount slider control.\r\nMove slider to select a different value.\r\nYou can use this instead of the text box above."; GUILayout.Label(new GUIContent(label, toolTip), noPad, GUILayout.Width(50), GUILayout.Height(20)); rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips == true) ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - scrollPosition.y); thisXferAmount = (double)GUILayout.HorizontalSlider((float)thisXferAmount, 0, (float)maxXferAmount, GUILayout.Width(190)); // set button style GUIContent xferContent = null; if (!TransferResource.ResourceXferActive) xferContent = new GUIContent("Xfer", "Transfers the selected resource\r\nto the selected " + strTarget + " Part"); else xferContent = new GUIContent("Stop", "Halts the Transfer of the selected resource\r\nto the selected " + strTarget + " Part"); if (GUILayout.Button(xferContent, GUILayout.Width(40), GUILayout.Height(18))) { if (!TransferResource.ResourceXferActive) { //Calc amounts and update xfer modules AssignXferAmounts(XferResources, xferMode, thisXferAmount); TransferResources(partsSource, partsTarget); } else if (TransferResource.ResourceXferActive && SMSettings.RealismMode) TransferResource.XferState = TransferResource.ResourceXFERState.Stop; } rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && ShowToolTips == true) ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - scrollPosition.y); GUILayout.EndHorizontal(); } if (!TransferResource.ResourceXferActive) modResource.UpdateXferAmount(thisXferAmount.ToString(), xferMode); } } }
/// <summary> /// returns amount remaining in parts we are transferring to (targets relative to xferMode) /// </summary> internal double ToAmtRemaining(SMAddon.XFERMode XferMode) { if (XferMode == SMAddon.XFERMode.SourceToTarget) return CalcResourceRemaining(SMAddon.smController.SelectedPartsTarget, ResourceName); else return CalcResourceRemaining(SMAddon.smController.SelectedPartsSource, ResourceName); }
internal void SetStringZero(string strXferAmount, SMAddon.XFERMode XferMode) { if (XferMode == SMAddon.XFERMode.SourceToTarget) { if (strXferAmount.Contains(".") && strXferAmount.EndsWith("0")) srcXferAmountHasZero = true; else srcXferAmountHasZero = false; } else { if (strXferAmount.Contains(".") && strXferAmount.EndsWith("0")) tgtXferAmountHasZero = true; else tgtXferAmountHasZero = false; } }
internal string GetStringZero(string strXferAmount, SMAddon.XFERMode XferMode) { if (XferMode == SMAddon.XFERMode.SourceToTarget) { if (srcXferAmountHasZero) strXferAmount += "0"; } else { if (tgtXferAmountHasZero) strXferAmount += "0"; } return strXferAmount; }
internal static void XferResource(List<Part> XferParts, TransferResource modResource, double XferAmount, SMAddon.XFERMode XferMode, bool drain) { // This adjusts the delta when we get to the end of the xfer. Utilities.LogMessage("XferResource: " + modResource.ResourceName + " - 1. XferAmount = " + XferAmount.ToString() + ", Drain? " + drain.ToString(), "Info", SMSettings.VerboseLogging); // This var keeps track of what we actually moved.. double XferBalance = XferAmount; double XferBalanceOld = XferBalance; int XferTimeout = 0; // Not all parts will have enough resource to meet the SrcPartAmt to move. We need to account for that. // count up source parts with avalilabe resources. so we can devide by them while (XferBalance > 0.0000001d) { Utilities.LogMessage("XferResource: " + modResource.ResourceName + " - 2. XferBalance = " + XferBalance.ToString() + ", Is Source: " + drain.ToString(), "Info", SMSettings.VerboseLogging); // Lets account for any empty/full containers int PartCount = 0; foreach (Part part in XferParts) if ((drain && part.Resources[modResource.ResourceName].amount > 0d) || (!drain && part.Resources[modResource.ResourceName].amount < part.Resources[modResource.ResourceName].maxAmount)) PartCount += 1; // now split up the xfer amount evenly across the number of tanks that can send/receive resources double PartAmt = XferBalance / PartCount; // Calculate Xfer amounts for each part and move. foreach (Part part in XferParts) { double AmtToMove = 0d; if (drain) { AmtToMove = part.Resources[modResource.ResourceName].amount >= PartAmt ? PartAmt : part.Resources[modResource.ResourceName].amount; part.Resources[modResource.ResourceName].amount -= AmtToMove; } else { double CapacityAvail = part.Resources[modResource.ResourceName].maxAmount - part.Resources[modResource.ResourceName].amount; AmtToMove = CapacityAvail >= PartAmt ? PartAmt : CapacityAvail; part.Resources[modResource.ResourceName].amount += AmtToMove; } Utilities.LogMessage("XferResource: " + modResource.ResourceName + " - 3. AmtToMove = " + AmtToMove.ToString() + ", Drain: " + drain.ToString(), "Info", SMSettings.VerboseLogging); // Report ramaining balance after Transfer. XferBalance -= AmtToMove; } // account for rounding and double resolution issues if (XferBalance <= 0.0000001d) break; else if (XferBalance != XferBalanceOld) { XferBalanceOld = XferBalance; XferTimeout = 0; } else if (XferBalance == XferBalanceOld) { XferTimeout += 1; if (XferTimeout >= 30) { Utilities.LogMessage("XferResource Timeout! Resource: " + modResource.ResourceName + " - 3. XferBalance = " + XferBalance.ToString() + ", Drain: " + drain.ToString(), "Error", true); break; } } } }
internal static double CalcRatio(List<TransferResource> Resources, SMAddon.XFERMode XferMode) { if (Resources.Count > 1) { if (Resources[0].ToCapacity(XferMode) > Resources[1].ToCapacity(XferMode)) return Resources[1].ToCapacity(XferMode) / Resources[0].ToCapacity(XferMode); else return Resources[0].ToCapacity(XferMode) / Resources[1].ToCapacity(XferMode); } else return 1; }
private static bool IsVesselSelectable(string SelectedResource, SMAddon.XFERDirection xferMode, ModDockedVessel modDockedVessel) { bool isSelectable = true; if (xferMode == SMAddon.XFERDirection.SourceToTarget) { if (SMAddon.smController.SelectedVesselsTarget.Contains(modDockedVessel)) isSelectable = false; } else { if (SMAddon.smController.SelectedVesselsSource.Contains(modDockedVessel)) isSelectable = false; } return isSelectable; }
private static bool IsPartSelectable(string SelectedResource, SMAddon.XFERDirection xferMode, Part part) { bool isSelectable = true; if (SelectedResource != "Crew" && SelectedResource != "Science") { if (xferMode == SMAddon.XFERDirection.SourceToTarget) { if (SMAddon.smController.SelectedPartsTarget.Contains(part)) isSelectable = false; } else { if (SMAddon.smController.SelectedPartsSource.Contains(part)) isSelectable = false; } } return isSelectable; }
private static bool CanResourceBeXferred(SMAddon.XFERDirection thisXferMode, double maxXferAmount) { return ((!TransferResource.ResourceXferActive && maxXferAmount > 0) || (TransferResource.ResourceXferActive && SMAddon.XferMode == thisXferMode)); }
private static void VesselButtonToggled(SMAddon.XFERDirection xferMode, ModDockedVessel modVessel) { string step = "Vessel Button Toggled"; try { if (xferMode == SMAddon.XFERDirection.SourceToTarget) { // Now lets update the list... if (SMAddon.smController.SelectedVesselsSource.Contains(modVessel)) SMAddon.smController.SelectedVesselsSource.Remove(modVessel); else SMAddon.smController.SelectedVesselsSource.Add(modVessel); SMAddon.smController.SelectedPartsSource = SMAddon.smController.GetSelectedVesselsParts(SMAddon.smController.SelectedVesselsSource, SMAddon.smController.SelectedResources); } else { if (SMAddon.smController.SelectedVesselsTarget.Contains(modVessel)) SMAddon.smController.SelectedVesselsTarget.Remove(modVessel); else SMAddon.smController.SelectedVesselsTarget.Add(modVessel); SMAddon.smController.SelectedPartsTarget = SMAddon.smController.GetSelectedVesselsParts(SMAddon.smController.SelectedVesselsTarget, SMAddon.smController.SelectedResources); } WindowManifest.ReconcileSelectedXferParts(SMAddon.smController.SelectedResources); step = "Set Xfer amounts?"; foreach (TransferResource modResource in SMAddon.smController.ResourcesToXfer) { modResource.srcXferAmount = TransferResource.CalcMaxResourceXferAmt(SMAddon.smController.SelectedPartsSource, SMAddon.smController.SelectedPartsTarget, modResource.ResourceName); modResource.tgtXferAmount = TransferResource.CalcMaxResourceXferAmt(SMAddon.smController.SelectedPartsTarget, SMAddon.smController.SelectedPartsSource, modResource.ResourceName); } } catch (Exception ex) { if (!SMAddon.frameErrTripped) { Utilities.LogMessage("Error in WindowTransfer.VesselButtonToggled (" + xferMode.ToString() + ") at step: " + step + ". Error: " + ex.ToString(), "Error", true); SMAddon.frameErrTripped = true; } } }
private static void PartButtonToggled(SMAddon.XFERDirection xferMode, Part part) { string step = "Part Button Toggled"; try { if (!SMAddon.smController.CrewTransfer.CrewXferActive && !TransferResource.ResourceXferActive) { if (xferMode == SMAddon.XFERDirection.SourceToTarget) { // Now lets update the list... if (SMAddon.smController.SelectedPartsSource.Contains(part)) { SMAddon.smController.SelectedPartsSource.Remove(part); } else { if (SMAddon.smController.SelectedResources.Contains("Crew") || SMAddon.smController.SelectedResources.Contains("Science")) SMAddon.smController.SelectedPartsSource.Clear(); SMAddon.smController.SelectedPartsSource.Add(part); } if (SMAddon.smController.SelectedResources.Contains("Crew") && SMSettings.EnableCLS) { SMAddon.UpdateCLSSpaces(); } SMAddon.smController.SelectedModuleSource = null; WindowTransfer._ScienceModulesSource = null; } else { if (SMAddon.smController.SelectedPartsTarget.Contains(part)) { SMAddon.smController.SelectedPartsTarget.Remove(part); } else { if (SMAddon.smController.SelectedResources.Contains("Crew") || SMAddon.smController.SelectedResources.Contains("Science")) SMAddon.smController.SelectedPartsTarget.Clear(); SMAddon.smController.SelectedPartsTarget.Add(part); } SMAddon.smController.SelectedModuleTarget = null; } step = "Set Xfer amounts?"; if (!SMAddon.smController.SelectedResources.Contains("Crew") && !SMAddon.smController.SelectedResources.Contains("Science")) { step = "Set Xfer amounts = yes"; foreach (TransferResource modResource in SMAddon.smController.ResourcesToXfer) { modResource.srcXferAmount = TransferResource.CalcMaxResourceXferAmt(SMAddon.smController.SelectedPartsSource, SMAddon.smController.SelectedPartsTarget, modResource.ResourceName); modResource.tgtXferAmount = TransferResource.CalcMaxResourceXferAmt(SMAddon.smController.SelectedPartsTarget, SMAddon.smController.SelectedPartsSource, modResource.ResourceName); } } } } catch (Exception ex) { if (!SMAddon.frameErrTripped) { Utilities.LogMessage("Error in WindowTransfer.PartButtonToggled (" + xferMode.ToString() + ") at step: " + step + ". Error: " + ex.ToString(), "Error", true); SMAddon.frameErrTripped = true; } } }
private static void AssignXferAmounts(List<TransferResource> XferResources, SMAddon.XFERDirection XferMode, double thisXferAmount) { if (XferResources.Count > 1) { // Calculate Ratio and transfer amounts. Ratio is based off the largest amount to move, so will always be less than 1. double ratio = TransferResource.CalcRatio(XferResources, XferMode); if (XferResources[0].ToCapacity(XferMode) > XferResources[1].ToCapacity(XferMode)) { XferResources[0].XferRatio = 1; XferResources[1].XferRatio = ratio; if (XferMode == SMAddon.XFERDirection.SourceToTarget) { XferResources[0].srcXferAmount = thisXferAmount; XferResources[1].srcXferAmount = thisXferAmount * ratio <= XferResources[1].FromCapacity(XferMode) ? thisXferAmount * ratio : XferResources[1].FromCapacity(XferMode); } else { XferResources[0].tgtXferAmount = thisXferAmount; XferResources[1].tgtXferAmount = thisXferAmount * ratio <= XferResources[1].FromCapacity(XferMode) ? thisXferAmount * ratio : XferResources[1].FromCapacity(XferMode); } } else { XferResources[1].XferRatio = 1; XferResources[0].XferRatio = ratio; if (XferMode == SMAddon.XFERDirection.SourceToTarget) { XferResources[1].srcXferAmount = thisXferAmount; XferResources[0].srcXferAmount = thisXferAmount * ratio <= XferResources[0].FromCapacity(XferMode) ? thisXferAmount * ratio : XferResources[0].FromCapacity(XferMode); } else { XferResources[1].tgtXferAmount = thisXferAmount; XferResources[0].tgtXferAmount = thisXferAmount * ratio <= XferResources[0].FromCapacity(XferMode) ? thisXferAmount * ratio : XferResources[0].FromCapacity(XferMode); } } } else { XferResources[0].XferRatio = 1; if (XferMode == SMAddon.XFERDirection.SourceToTarget) XferResources[0].srcXferAmount = thisXferAmount; else XferResources[0].tgtXferAmount = thisXferAmount; } }
private static GUIStyle GetPartButtonStyle(SMAddon.XFERDirection xferMode, Part part) { GUIStyle style = SMStyle.ButtonSourceStyle; if (xferMode == SMAddon.XFERDirection.SourceToTarget) { if (SMAddon.smController.SelectedPartsSource.Contains(part)) style = SMStyle.ButtonToggledSourceStyle; else style = SMStyle.ButtonSourceStyle; } else { if (SMAddon.smController.SelectedPartsTarget.Contains(part)) style = SMStyle.ButtonToggledTargetStyle; else style = SMStyle.ButtonTargetStyle; } return style; }
private static void ResourceFlowButtons(List<Part> partsSource, SMAddon.XFERDirection XferMode, Vector2 scrollPosition, int scrollX, int scrollY) { string step = ""; try { foreach (TransferResource modResource in SMAddon.smController.ResourcesToXfer) { string resource = modResource.ResourceName; // this var is used for button state change management bool flowState = true; // Loop through parts to establish flow state. Any part that is off, means all are off for display purposes. if (partsSource.Count > 0) { step = "We have parts. Get flowstate"; foreach (Part part in partsSource) { if (!part.Resources[resource].flowState) flowState = false; } string flowtext = flowState ? "On" : "Off"; // Flow control Display step = "resource quantities labels"; GUILayout.BeginHorizontal(); GUIStyle noWrap = SMStyle.LabelStyleNoWrap; GUILayout.Label(string.Format("{0}: ({1}/{2})", resource, modResource.FromAmtRemaining(XferMode).ToString("#######0.##"), modResource.FromCapacity(XferMode).ToString("######0.##")), SMStyle.LabelStyleNoWrap, GUILayout.Width(220), GUILayout.Height(18)); GUILayout.Label(string.Format("{0}", flowtext), GUILayout.Width(20), GUILayout.Height(18)); if (SMAddon.vessel.IsControllable) { step = "render flow button(s)"; if (GUILayout.Button(new GUIContent("Flow", "Enables/Disables flow of selected resource(s) from selected part(s)."), GUILayout.Width(40), GUILayout.Height(20))) { foreach (Part part in partsSource) { part.Resources[resource].flowState = !flowState; } flowtext = flowState ? "Off" : "On"; } if (Event.current.type == EventType.Repaint && ShowToolTips == true) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, scrollX, scrollY - scrollPosition.y); } } GUILayout.EndHorizontal(); } } } catch (Exception ex) { if (!SMAddon.frameErrTripped) { Utilities.LogMessage(string.Format(" in WindowTransfer.ResourceFlowButtons at step: " + step + ". Error: {0} \r\n\r\n{1}", ex.Message, ex.StackTrace), "Error", true); SMAddon.frameErrTripped = true; } } }
private static GUIStyle GetVesselButtonStyle(SMAddon.XFERDirection xferMode, ModDockedVessel modDockedVessel) { GUIStyle style = SMStyle.ButtonSourceStyle; if (xferMode == SMAddon.XFERDirection.SourceToTarget) { if (SMAddon.smController.SelectedVesselsSource.Contains(modDockedVessel)) style = SMStyle.ButtonToggledSourceStyle; else style = SMStyle.ButtonSourceStyle; } else { if (SMAddon.smController.SelectedVesselsTarget.Contains(modDockedVessel)) style = SMStyle.ButtonToggledTargetStyle; else style = SMStyle.ButtonTargetStyle; } return style; }
// multi Resource methods internal static TransferResource GetXferResource(List<TransferResource> XferResources, SMAddon.XFERMode XferMode, bool isRatio = false) { if (XferResources.Count > 1) { if (isRatio) { if (XferResources[1].ToCapacity(XferMode) > XferResources[0].ToCapacity(XferMode)) return XferResources[0]; else return XferResources[1]; } else { if (XferResources[0].ToCapacity(XferMode) > XferResources[1].ToCapacity(XferMode)) return XferResources[0]; else return XferResources[1]; } } else { return XferResources[0]; } }
private static void TextBetweenViewers(List<Part> SelectedParts, SMAddon.XFERDirection xferMode) { string labelText = ""; GUILayout.BeginHorizontal(); if (SMAddon.smController.SelectedResources.Contains("Crew")) labelText = SelectedParts.Count > 0 ? string.Format("{0}", SelectedParts[0].partInfo.title) : "No Part Selected"; else { if (SelectedParts != null) { if (SelectedParts.Count > 1) labelText = string.Format("{0}", "Multiple Parts Selected"); else if (SelectedParts.Count == 1) labelText = string.Format("{0}", SelectedParts[0].partInfo.title); else labelText = string.Format("{0}", "No Part Selected"); } } GUILayout.Label(labelText, SMStyle.LabelStyleNoWrap, GUILayout.Width(200)); if (CanShowVessels()) { if (xferMode == SMAddon.XFERDirection.SourceToTarget) { bool prevValue = WindowTransfer.ShowSourceVessels; WindowTransfer.ShowSourceVessels = GUILayout.Toggle(WindowTransfer.ShowSourceVessels, "Vessels", GUILayout.Width(90)); if (!prevValue && WindowTransfer.ShowSourceVessels) WindowManifest.ReconcileSelectedXferParts(SMAddon.smController.SelectedResources); } else { bool prevValue = WindowTransfer.ShowSourceVessels; WindowTransfer.ShowTargetVessels = GUILayout.Toggle(WindowTransfer.ShowTargetVessels, "Vessels", GUILayout.Width(90)); if (!prevValue && WindowTransfer.ShowSourceVessels) WindowManifest.ReconcileSelectedXferParts(SMAddon.smController.SelectedResources); } } GUILayout.EndHorizontal(); }
internal string GetStringDecimal(string strXferAmount, SMAddon.XFERMode XferMode) { if (XferMode == SMAddon.XFERMode.SourceToTarget) { if (srcXferAmountHasDecimal) strXferAmount += "."; } else { if (tgtXferAmountHasDecimal) strXferAmount += "."; } return strXferAmount; }
private static void PartsTransferViewer(List<string> SelectedResources, SMAddon.XFERDirection xferMode, Vector2 ViewerScrollPosition) { float scrollX = WindowTransfer.Position.x + (xferMode == SMAddon.XFERDirection.SourceToTarget ? 20 : 320); float scrollY = WindowTransfer.Position.y + 30 - ViewerScrollPosition.y; string step = "begin"; try { step = "begin button loop"; foreach (Part part in SMAddon.smController.SelectedResourcesParts) { // Build the part button title... step = "part button title"; string strDescription = GetResourceDescription(SelectedResources, part); // set the conditions for a button style change. int btnWidth = 270; if (!SMSettings.RealismMode && !SelectedResources.Contains("Science")) btnWidth = 190; // Set style based on viewer and toggled state. step = "Set style"; GUIStyle style = GetPartButtonStyle(xferMode, part); GUILayout.BeginHorizontal(); // Now let's account for any target buttons already pressed. (sources and targets for resources cannot be the same) GUI.enabled = IsPartSelectable(SelectedResources[0], xferMode, part); step = "Render part Buttons"; if (GUILayout.Button(string.Format("{0}", strDescription), style, GUILayout.Width(btnWidth), GUILayout.Height(20))) { PartButtonToggled(xferMode, part); } Rect rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition)) { SMHighlighter.IsMouseOver = true; SMHighlighter.MouseOverMode = xferMode; SMHighlighter.MouseOverRect = new Rect(scrollX + rect.x, scrollY + rect.y, rect.width, rect.height); SMHighlighter.MouseOverpart = part; } // Reset Button enabling. GUI.enabled = true; step = "Render dump/fill buttons"; if (!SMSettings.RealismMode && SelectedResources[0] != "Science") { if (SelectedResources[0] == "Crew") GUI.enabled = part.protoModuleCrew.Count > 0; else if (SelectedResources.Count > 1) GUI.enabled = (part.Resources[SelectedResources[0]].amount > 0 || part.Resources[SelectedResources[1]].amount > 0) ? true : false; else GUI.enabled = part.Resources[SelectedResources[0]].amount > 0 ? true : false; var style1 = xferMode == SMAddon.XFERDirection.SourceToTarget ? SMStyle.ButtonSourceStyle : SMStyle.ButtonTargetStyle; if (GUILayout.Button(string.Format("{0}", "Dump"), style1, GUILayout.Width(45), GUILayout.Height(20))) { if (SelectedResources[0] == "Crew") SMController.DumpPartCrew(part); else { SMController.DumpPartResource(part, SelectedResources[0]); if (SelectedResources.Count > 1) SMController.DumpPartResource(part, SelectedResources[1]); } } var style2 = xferMode == SMAddon.XFERDirection.SourceToTarget ? SMStyle.ButtonSourceStyle : SMStyle.ButtonTargetStyle; if (SelectedResources[0] == "Crew") GUI.enabled = part.protoModuleCrew.Count < part.CrewCapacity; else if (SelectedResources.Count > 1) GUI.enabled = part.Resources[SelectedResources[0]].amount < part.Resources[SelectedResources[0]].maxAmount || part.Resources[SelectedResources[1]].amount < part.Resources[SelectedResources[1]].maxAmount ? true : false; else GUI.enabled = part.Resources[SelectedResources[0]].amount < part.Resources[SelectedResources[0]].maxAmount ? true : false; if (GUILayout.Button(string.Format("{0}", "Fill"), style2, GUILayout.Width(30), GUILayout.Height(20))) { if (SelectedResources[0] == "Crew") SMController.FillPartCrew(part); SMController.FillPartResource(part, SelectedResources[0]); if (SelectedResources.Count > 1) SMController.FillPartResource(part, SelectedResources[1]); } GUI.enabled = true; } GUILayout.EndHorizontal(); } } catch (Exception ex) { if (!SMAddon.frameErrTripped) { Utilities.LogMessage("Error in Windowtransfer.PartsTransferViewer (" + xferMode.ToString() + ") at step: " + step + ". Error: " + ex.ToString(), "Error", true); SMAddon.frameErrTripped = true; } } }
internal void SetStringDecimal(string strXferAmount, SMAddon.XFERMode XferMode) { if (XferMode == SMAddon.XFERMode.SourceToTarget) { if (strXferAmount.EndsWith(".") || strXferAmount.EndsWith(".0")) srcXferAmountHasDecimal = true; else srcXferAmountHasDecimal = false; } else { if (strXferAmount.EndsWith(".") || strXferAmount.EndsWith(".0")) tgtXferAmountHasDecimal = true; else tgtXferAmountHasDecimal = false; } }
private static void VesselTransferViewer(List<string> SelectedResources, SMAddon.XFERDirection xferMode, Vector2 ViewerScrollPosition) { float scrollX = WindowTransfer.Position.x + (xferMode == SMAddon.XFERDirection.SourceToTarget ? 20 : 320); float scrollY = WindowTransfer.Position.y + 30 - ViewerScrollPosition.y; string step = "begin"; try { step = "begin button loop"; foreach (ModDockedVessel modDockedVessel in SMAddon.smController.DockedVessels) { // Build the part button title... step = "vessel button title"; string strDescription = GetResourceDescription(SelectedResources, modDockedVessel); // set the conditions for a button style change. int btnWidth = 265; if (!SMSettings.RealismMode) btnWidth = 180; // Set style based on viewer and toggled state. step = "Set style"; GUIStyle style = GetVesselButtonStyle(xferMode, modDockedVessel); GUILayout.BeginHorizontal(); // Now let's account for any target buttons already pressed. (sources and targets for resources cannot be the same) GUI.enabled = IsVesselSelectable(SelectedResources[0], xferMode, modDockedVessel); step = "Render part Buttons"; if (GUILayout.Button(string.Format("{0}", strDescription), style, GUILayout.Width(btnWidth), GUILayout.Height(20))) { VesselButtonToggled(xferMode, modDockedVessel); } Rect rect = GUILayoutUtility.GetLastRect(); if (Event.current.type == EventType.Repaint && rect.Contains(Event.current.mousePosition)) { SMHighlighter.IsMouseOver = true; SMHighlighter.MouseOverMode = xferMode; SMHighlighter.MouseOverRect = new Rect(scrollX + rect.x, scrollY + rect.y, rect.width, rect.height); SMHighlighter.MouseOverpart = null; SMHighlighter.MouseOverparts = modDockedVessel.VesselParts; } // Reset Button enabling. GUI.enabled = true; //step = "Render dump/fill buttons"; if (!SMSettings.RealismMode) { if (SelectedResources.Count > 1) GUI.enabled = (TransferResource.CalcResourceRemaining(modDockedVessel.VesselParts, SelectedResources[0]) > 0 || TransferResource.CalcResourceRemaining(modDockedVessel.VesselParts, SelectedResources[1]) > 0) ? true : false; else GUI.enabled = TransferResource.CalcResourceRemaining(modDockedVessel.VesselParts, SelectedResources[0]) > 0 ? true : false; var style1 = xferMode == SMAddon.XFERDirection.SourceToTarget ? SMStyle.ButtonSourceStyle : SMStyle.ButtonTargetStyle; if (GUILayout.Button(string.Format("{0}", "Dump"), style1, GUILayout.Width(45), GUILayout.Height(20))) { SMController.DumpPartsResource(modDockedVessel.VesselParts, SelectedResources[0]); if (SelectedResources.Count > 1) SMController.DumpPartsResource(modDockedVessel.VesselParts, SelectedResources[1]); } var style2 = xferMode == SMAddon.XFERDirection.SourceToTarget ? SMStyle.ButtonSourceStyle : SMStyle.ButtonTargetStyle; if (SelectedResources.Count > 1) GUI.enabled = TransferResource.CalcRemainingCapacity(modDockedVessel.VesselParts, SelectedResources[0]) > 0 || TransferResource.CalcRemainingCapacity(modDockedVessel.VesselParts, SelectedResources[0]) > 0 ? true : false; else GUI.enabled = TransferResource.CalcRemainingCapacity(modDockedVessel.VesselParts, SelectedResources[0]) > 0 ? true : false; if (GUILayout.Button(string.Format("{0}", "Fill"), style2, GUILayout.Width(30), GUILayout.Height(20))) { SMController.FillPartsResource(modDockedVessel.VesselParts, SelectedResources[0]); if (SelectedResources.Count > 1) SMController.FillPartsResource(modDockedVessel.VesselParts, SelectedResources[1]); } GUI.enabled = true; } GUILayout.EndHorizontal(); } } catch (Exception ex) { if (!SMAddon.frameErrTripped) { Utilities.LogMessage("Error in Windowtransfer.VesselTransferViewer (" + xferMode.ToString() + ") at step: " + step + ". Error: " + ex.ToString(), "Error", true); SMAddon.frameErrTripped = true; } } }
// these methods are for managing textbox string data entry for xfer amounts internal void SetXferAmountString(string xferAmount, SMAddon.XFERMode xferMode) { // Needed so we can alter slider controls on both the source and target windows. if (xferMode == SMAddon.XFERMode.TargetToSource) strSrcXferAmount = xferAmount; else strTgtXferAmount = xferAmount; }
private static void CrewDetails(List<Part> SelectedPartsFrom, List<Part> SelectedPartsTo, SMAddon.XFERDirection xferMode, Vector2 scrollPosition) { // Since only one Crew Part can be selected, all lists will use an index of [0]. float xOffset = xferMode == SMAddon.XFERDirection.SourceToTarget ? 30 : 330; float yOffset = 160; if (SelectedPartsFrom.Count > 0) { List<ProtoCrewMember> crewMembers = SelectedPartsFrom[0].protoModuleCrew; for (int x = 0; x < SelectedPartsFrom[0].protoModuleCrew.Count(); x++) { ProtoCrewMember crewMember = SelectedPartsFrom[0].protoModuleCrew[x]; GUILayout.BeginHorizontal(); if (crewMember.seat != null) { if (SMAddon.smController.CrewTransfer.CrewXferActive || TransferResource.ResourceXferActive) GUI.enabled = false; if (GUILayout.Button(new GUIContent(">>", "Move Kerbal to another seat within Part"), SMStyle.ButtonStyle, GUILayout.Width(15), GUILayout.Height(20))) { ToolTip = ""; SMAddon.smController.CrewTransfer.CrewTransferBegin(crewMember, SelectedPartsFrom[0], SelectedPartsFrom[0]); } if (Event.current.type == EventType.Repaint && ShowToolTips == true) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - scrollPosition.y); } GUI.enabled = true; } GUILayout.Label(string.Format(" {0}", crewMember.name + " (" + crewMember.experienceTrait.Title + ")"), GUILayout.Width(190), GUILayout.Height(20)); if (SMAddon.CanKerbalsBeXferred(SelectedPartsFrom, SelectedPartsTo)) GUI.enabled = true; else GUI.enabled = false; if ((SMAddon.smController.CrewTransfer.FromCrewMember == crewMember || SMAddon.smController.CrewTransfer.ToCrewMember == crewMember) && (SMAddon.smController.CrewTransfer.CrewXferActive || TransferResource.ResourceXferActive)) { GUI.enabled = true; GUILayout.Label("Moving", GUILayout.Width(50), GUILayout.Height(20)); } else { if (GUILayout.Button(new GUIContent("Xfer", xferToolTip), SMStyle.ButtonStyle, GUILayout.Width(50), GUILayout.Height(20))) { SMAddon.smController.CrewTransfer.FromCrewMember = crewMember; SMAddon.smController.CrewTransfer.CrewTransferBegin(crewMember, SelectedPartsFrom[0], SelectedPartsTo[0]); } if (Event.current.type == EventType.Repaint && ShowToolTips == true) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - scrollPosition.y); } } GUI.enabled = true; GUILayout.EndHorizontal(); } // Cater for DeepFreeze Continued... parts - list frozen kerbals if (DF.DFInterface.IsDFInstalled) { try { IDeepFreezer sourcepartFrzr = SelectedPartsFrom[0].FindModuleImplementing<IDeepFreezer>(); if (sourcepartFrzr != null) { if (sourcepartFrzr.DFIStoredCrewList.Count > 0) { DF.IDFInterface DFOjbect = DF.DFInterface.GetFrozenKerbals(); foreach (DF.FrznCrewMbr frzncrew in sourcepartFrzr.DFIStoredCrewList) { GUILayout.BeginHorizontal(); GUI.enabled = false; if (GUILayout.Button(new GUIContent(">>", "Move Kerbal to another seat within Part"), SMStyle.ButtonStyle, GUILayout.Width(15), GUILayout.Height(20))) { ToolTip = ""; } if (Event.current.type == EventType.Repaint && ShowToolTips == true) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - scrollPosition.y); } string trait = DFOjbect.FrozenKerbals[frzncrew.CrewName].experienceTraitName; GUI.enabled = true; GUILayout.Label(string.Format(" {0}", frzncrew.CrewName + " (" + trait + ")"), SMStyle.LabelStyleCyan, GUILayout.Width(190), GUILayout.Height(20)); if (GUILayout.Button(new GUIContent("Thaw", "This Kerbal is Frozen. Click to Revive kerbal"), SMStyle.ButtonStyle, GUILayout.Width(50), GUILayout.Height(20))) { WindowRoster.ThawKerbal(frzncrew.CrewName); ToolTip = ""; } if (Event.current.type == EventType.Repaint && ShowToolTips == true) { Rect rect = GUILayoutUtility.GetLastRect(); ToolTip = SMToolTips.SetActiveTooltip(rect, WindowTransfer.Position, GUI.tooltip, ref ToolTipActive, xOffset, yOffset - scrollPosition.y); } GUILayout.EndHorizontal(); } } } } catch (Exception ex) { Debug.Log("Error attempting to check DeepFreeze for FrozenKerbals"); Debug.Log(ex.Message); } } } }
internal float UpdateXferAmount(string strXferAmount, SMAddon.XFERMode xferMode) { // Needed so we can alter slider controls on both the source and target windows. // Also, slider requires a float number... float newAmount = 0; if (float.TryParse(strXferAmount, out newAmount)) if (xferMode == SMAddon.XFERMode.SourceToTarget) srcXferAmount = newAmount; else tgtXferAmount = newAmount; return newAmount; }
public SMAddon() { Instance = this; }