/// <summary>Shows a window that displays the resource transfer controls.</summary> /// <param name="windowId">Window ID.</param> void TransferResourcesWindowFunc(int windowId) { // Allow the window to be dragged by its title bar. GuiWindow.DragWindow(ref windowRect, titleBarRect); MakeGuiStyles(); // In the docked mode the players must use the stock transfer mechanism. if (vessel == linkTarget.part.vessel) { GUILayout.Label(NotAvailableInDockedMode, new GUIStyle(GUI.skin.label) { wordWrap = false }); if (GUILayout.Button(CloseDialogBtn, MinSizeLayout)) { isGUIOpen = false; } SetPendingTransferOption(null); // Cancel all transfers. return; } if (guiActions.ExecutePendingGuiActions()) { MaybeUpdateResourceOptionList(); guiResourcesTable.UpdateFrame(); if (pendingOption != null) { if (!DoTransfer()) { SetPendingTransferOption(null); // Cancel all transfers. } } UpdateResourcesTransferGui(); } GUILayout.Label(OwnerVesselTxt.Format(vessel.vesselName), GUI.skin.box); GUILayout.Label(ConnectedVesselTxt.Format(linkTarget.part.vessel.vesselName), GUI.skin.box); for (var i = resourceRows.Length - 1; i >= 0; i--) { var row = resourceRows[i]; guiResourcesTable.StartNewRow(); using (new GUILayout.HorizontalScope()) { guiResourcesTable.AddTextColumn( row.caption, guiResourceStyle, minWidth: resourceName.guiTags.minWidth); guiResourcesTable.AddTextColumn( row.leftInfo, guiNoWrapCenteredStyle, minWidth: resourceAmounts.guiTags.minWidth); using (new GuiEnabledStateScope(row.canMoveRightToLeft)) { row.rightToLeftTransferToggle = GUILayoutButtons.Toggle( row.rightToLeftTransferToggle, leftToRigthToggleCnt, guiTransferBtnStyle, null, GuiActionUpdateTransferItem, GuiActionUpdateTransferItem, guiActions); row.rightToLeftTransferPress = GUILayoutButtons.Push( row.rightToLeftTransferPress, leftToRigthButtonCnt, guiTransferBtnStyle, null, GuiActionUpdateTransferItem, GuiActionUpdateTransferItem, guiActions); } using (new GuiEnabledStateScope(row.canMoveLeftToRight)) { row.leftToRightTransferPress = GUILayoutButtons.Push( row.leftToRightTransferPress, rightToLeftButtonCnt, guiTransferBtnStyle, null, GuiActionUpdateTransferItem, GuiActionUpdateTransferItem, guiActions); row.leftToRightTransferToggle = GUILayoutButtons.Toggle( row.leftToRightTransferToggle, rightToLeftToggleCnt, guiTransferBtnStyle, null, GuiActionUpdateTransferItem, GuiActionUpdateTransferItem, guiActions); } guiResourcesTable.AddTextColumn( row.rightInfo, guiNoWrapCenteredStyle, minWidth: resourceAmounts.guiTags.minWidth); guiResourcesTable.AddTextColumn( row.caption, guiResourceStyle, minWidth: resourceName.guiTags.minWidth); } } // Resource transfer speed. autoScaleSpeed = GUILayoutButtons.Toggle( autoScaleSpeed, autoScaleToggleCnt, GUI.skin.toggle, null, MaybeAutoScaleSpeed, null, guiActions); using (new GuiEnabledStateScope(!autoScaleSpeed)) { transferSpeed = GUILayout.HorizontalSlider(transferSpeed, 0f, maxTransferSpeed); if (transferSpeed < float.Epsilon && pendingOption != null) { guiActions.Add(() => SetPendingTransferOption(null)); // Cancel all transfers. } } GUILayout.Label(TransferSpeedTxt.Format(transferSpeed)); using (new GUILayout.HorizontalScope()) { if (GUILayout.Button(CloseDialogBtn, MinSizeLayout)) { guiActions.Add(() => isGUIOpen = false); } GUILayout.Label(""); GUI.Label(GUILayoutUtility.GetLastRect(), GUI.tooltip); } }
/// <summary>Shows a window that displays the winch controls.</summary> /// <param name="windowId">Window ID.</param> void ConsoleWindowFunc(int windowId) { MakeGuiStyles(); if (GuiActions.ExecutePendingGuiActions()) { MaybeUpdateModules(); _guiWinchTable.UpdateFrame(); } if (_sortedSceneModules.Length == 0) { GUILayout.Label(NoContentTxt, _guiNoWrapStyle); } // TODO(ihsoft): Add paging and the setting for the number of items per page. // Render the winch items if any. foreach (var winchState in _sortedSceneModules) { var winch = winchState.winchModule; var winchCable = winchState.winchModule.linkJoint as ILinkCableJoint; var disableWinchGui = !winch.part.vessel.IsControllable || winch.isNodeBlocked || winch.isLocked; var motorSpeed = winchState.motorSpeedSetting * winch.cfgMotorMaxSpeed; _guiWinchTable.StartNewRow(); using (new GUILayout.HorizontalScope(GUI.skin.box)) { // Winch highlighting column. winchState.highlighted = GUILayoutButtons.Toggle( winchState.highlighted, _highlightWinchCnt, GUI.skin.button, null, fnOn: () => { winch.part.SetHighlight(true, false); winch.part.SetHighlightType(Part.HighlightType.AlwaysOn); }, fnOff: () => { winch.part.SetHighlightDefault(); }, actionsList: GuiActions); // Cable retracting controls. System.Diagnostics.Debug.Assert(winchCable != null, nameof(winchCable) + " != null"); using (new GuiEnabledStateScope(!disableWinchGui && winchCable.realCableLength > 0)) { // Start retracting the cable column. winchState.retractBtnPressed &= winch.motorTargetSpeed < 0; winchState.retractBtnPressed = GUILayoutButtons.Toggle( winchState.retractBtnPressed, _startRetractingCnt, GUI.skin.button, new[] { MinSizeLayout }, fnOn: () => winch.SetMotor(-motorSpeed), fnOff: () => winch.SetMotor(0), actionsList: GuiActions); // Retract the cable column. winchState.retracting &= winch.motorTargetSpeed < 0; winchState.retracting = GUILayoutButtons.Push( winchState.retracting, _retractCnt, GUI.skin.button, new[] { MinSizeLayout }, fnPush: () => winch.SetMotor(-motorSpeed), fnRelease: () => winch.SetMotor(0), actionsList: GuiActions); } // Cable length/status column. if (!winch.part.vessel.IsControllable) { _guiWinchTable.AddTextColumn( _winchModeOfflineCnt, _guiNoWrapCenteredStyle, minWidth: _winchCableStatusMinWidth); } else if (winch.isNodeBlocked || winch.isLocked) { _guiWinchTable.AddTextColumn( _winchModeBlockedCnt, _guiNoWrapCenteredStyle, minWidth: _winchCableStatusMinWidth); } else if (winch.isConnectorLocked) { _guiWinchTable.AddTextColumn( _winchModeRetractedCnt, _guiNoWrapCenteredStyle, minWidth: _winchCableStatusMinWidth); } else { _cableStatusCnt.text = winchCable.realCableLength <= winch.currentCableLength ? RelaxedCableLengthTxt.Format(winch.currentCableLength, winchCable.realCableLength) : StrainedCableLengthTxt.Format(winch.currentCableLength, winchCable.realCableLength); _guiWinchTable.AddTextColumn( _cableStatusCnt, _guiNoWrapCenteredStyle, minWidth: _winchCableStatusMinWidth); } // Cable extending controls. using (new GuiEnabledStateScope( !disableWinchGui && winchCable.deployedCableLength < winch.cfgMaxCableLength)) { // Start extending the cable column. winchState.extendBtnPressed &= winch.motorTargetSpeed > 0; winchState.extendBtnPressed = GUILayoutButtons.Toggle( winchState.extendBtnPressed, _startExtendingCnt, GUI.skin.button, new[] { MinSizeLayout }, fnOn: () => winch.SetMotor(motorSpeed), fnOff: () => winch.SetMotor(0), actionsList: GuiActions); // Extend the cable column. winchState.extending &= winch.motorTargetSpeed > 0; winchState.extending = GUILayoutButtons.Push( winchState.extending, _extendCnt, GUI.skin.button, new[] { MinSizeLayout }, fnPush: () => winch.SetMotor(motorSpeed), fnRelease: () => winch.SetMotor(0), actionsList: GuiActions); } using (new GuiEnabledStateScope(!disableWinchGui)) { // Motor speed settings column. using (new GUILayout.VerticalScope(_motorSpeedSettingsCnt, GUI.skin.label)) { GUI.changed = false; GUILayout.FlexibleSpace(); var newMotorSpeedSetting = GUILayout.HorizontalSlider( winchState.motorSpeedSetting, 0.1f, 1.0f, GUILayout.Width(100f)); if (GUI.changed) { var state = winchState; GuiActions.Add(() => { state.motorSpeedSetting = newMotorSpeedSetting; var newSpeed = newMotorSpeedSetting * winch.cfgMotorMaxSpeed; if (state.extending || state.extendBtnPressed) { winch.SetMotor(newSpeed); } if (state.retracting || state.retractBtnPressed) { winch.SetMotor(-newSpeed); } }); } } } // Motor speed info column. _motorSpeedCnt.text = MotorSpeedTxt.Format(Mathf.Abs(winch.motorCurrentSpeed), motorSpeed); _guiWinchTable.AddTextColumn( _motorSpeedCnt, _guiNoWrapCenteredStyle, minWidth: MotorSpeedTxt.guiTags.minWidth); // Release cable column. using (new GuiEnabledStateScope( !disableWinchGui && winch.currentCableLength < winch.cfgMaxCableLength)) { if (GUILayout.Button(_releaseBtnCnt, GUI.skin.button, MinSizeLayout)) { GuiActions.Add(winch.ReleaseCable); } } // Stretch cable column. using (new GuiEnabledStateScope(!disableWinchGui && !winch.isConnectorLocked)) { if (GUILayout.Button(_stretchBtnCnt, GUI.skin.button, MinSizeLayout)) { GuiActions.Add(winch.StretchCable); } } // Disconnect connector column. using (new GuiEnabledStateScope(!disableWinchGui && winch.isLinked)) { if (GUILayout.Button(_detachBtnCnt, GUI.skin.button, MinSizeLayout)) { GuiActions.Add(() => winch.BreakCurrentLink(LinkActorType.Player)); } } } } using (new GUILayout.HorizontalScope()) { if (GUILayout.Button(_closeGuiCnt, MinSizeLayout)) { GuiActions.Add(() => _isGuiOpen = false); } GUILayout.Label(""); GUI.Label(GUILayoutUtility.GetLastRect(), GUI.tooltip); } // Allow the window to be dragged by its title bar. GuiWindow.DragWindow(ref _windowRect, TitleBarRect); }