/* ************************************************************************************************ * Function Name: DrawProcessorControls * Input: None * Output: None * Purpose: This function will draw the four main processor control objects: the screenshot * button, the science button, and the next/previous processor buttons. * The screenshot button will only display and be available if the telescope has a valid * processor installed on the scope. * The science button will only appear if a target is selected, if there is a valid processor * installed, and if the game is not a sandbox game. It will generate a science report based * on the selected target. * The next/previous buttons will only appear if the scope has more than one processor installed, * and will allow the player to cycle through the different processors. * ************************************************************************************************/ private void DrawProcessorControls() { //if (!ActiveProcessor.IsActive()) //{ // //Craft is out of power. // Notification = "Image processor is out of power; shutting down processor."; // timer = 0f; // Processors.Remove(ActiveProcessor); //} //Draw save icon if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && ActiveProcessor.GetProcessorType().Contains("Wide Field")) { if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) + 20), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), SaveScreenshotTexture)) { //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName)); Notification = " Screenshot saved to " + WriteTextureToDrive(CameraModule.TakeScreenshot(ActiveProcessor)); timer = 0f; } } //Draw gather science icon //Atom6 icon from Freepik //<div>Icons made by Freepik from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0">CC BY 3.0</a></div> if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX) { if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) - 20), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Atom6Icon)) { //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName)); //ActiveProcessor.GenerateScienceReport(TakeScreenshot(ActiveProcessor.GetType())); try { Notification = ActiveProcessor.DoScience(GetTargetPos(FlightGlobals.fetch.VesselTarget.GetTransform().position, 500f), scienceMultiplier, CameraModule.FieldOfView, CameraModule.TakeScreenshot(ActiveProcessor)); } catch (Exception e) { Notification = "An error occured. Please post that you're having this error on the official CactEye 2 thread on the Kerbal Forums."; Debug.Log("CactEye 2: Exception 4: An error occured producing a science report!"); Debug.Log(e.ToString()); } timer = 0f; } } //Got an off-by-one error in the list somewhere //Previous/Next buttons if (Processors.Count <CactEyeProcessor>() > 1) { //Previous button if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) - 72), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Back9Icon)) { ActiveProcessor.Active = false; ActiveProcessor = GetPrevious(Processors, ActiveProcessor); ActiveProcessor.Active = true; } //Next Button if (GUI.Button(new Rect(ScopeRect.xMin + ((0.5f * ScopeRect.width) + 72), ScopeRect.yMin + (ScopeRect.height - 48f), 32, 32), Forward9Icon)) { ActiveProcessor.Active = false; ActiveProcessor = GetNext(Processors, ActiveProcessor); ActiveProcessor.Active = true; } } }
private void MainGUI(int WindowID) { timer += Planetarium.GetUniversalTime() - storedTime; storedTime = Planetarium.GetUniversalTime(); GUILayout.BeginHorizontal(); //Top right hand corner button that exits the window. if (GUI.Button(new Rect(WindowPosition.width - 18, 2, 16, 16), "")) { Toggle(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); //What you see looking through the telescope. ScopeRect = GUILayoutUtility.GetRect(400f, 400f); Texture2D ScopeScreen = CameraModule.UpdateTexture(ActiveProcessor); GUI.DrawTexture(ScopeRect, ScopeScreen); //Draw the preview texture GUI.DrawTexture(new Rect(ScopeRect.xMin, ScopeRect.yMax - 32f, 128f, 32f), PreviewTexture); //Draw the crosshair texture GUI.DrawTexture(new Rect(ScopeRect.xMin + (0.5f * ScopeRect.width) - 64, ScopeRect.yMin + (0.5f * ScopeRect.height) - 64, 128, 128), CrosshairTexture); //Draw the notification label if (timer > 5f) { Notification = ""; } GUI.Label(new Rect(ScopeRect.xMin + 16, ScopeRect.yMin + 16, 600, 32), new GUIContent(Notification)); ControlRect = GUILayoutUtility.GetRect(300f, 20f); if (Processors.Count > 1) { //Previous button if (GUI.Button(new Rect(433f, 72f, 32, 32), Back9Icon)) { ActiveProcessor.Active = false; ActiveProcessor = GetPrevious(Processors, ActiveProcessor); ActiveProcessor.Active = true; } if (GUI.Button(new Rect(635f, 72f, 32, 32), Forward9Icon)) { ActiveProcessor.Active = false; ActiveProcessor = GetNext(Processors, ActiveProcessor); ActiveProcessor.Active = true; } } GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperCenter; GUI.Label(new Rect(475f, 40f, 150, 32), "Active Processor"); GUI.Label(new Rect(475f, 72f, 150, 32), ActiveProcessor.GetProcessorType()); if (!isSmallOptics) { if (GUI.Button(new Rect(475f, 124f, 150, 48), ToggleAperatureIcon)) { aperature.Toggle(); } } if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && ActiveProcessor.GetProcessorType().Contains("Wide Field")) { GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleRight; GUI.Label(new Rect(425f, 188f, 150, 32), "Store Image:"); if (GUI.Button(new Rect(585f, 188f, 32, 32), SaveScreenshotTexture)) { //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName)); Notification = " Screenshot saved to " + WriteTextureToDrive(CameraModule.TakeScreenshot(ActiveProcessor)); timer = 0f; } } else { GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter; GUI.Label(new Rect(475f, 188f, 150, 32), "Imaging not available."); } if (FlightGlobals.fetch.VesselTarget != null && ActiveProcessor && HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX) { GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleRight; GUI.Label(new Rect(425f, 252f, 150, 32), "Process Data:"); if (GUI.Button(new Rect(585f, 252f, 32, 32), Atom6Icon)) { //DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName)); //ActiveProcessor.GenerateScienceReport(TakeScreenshot(ActiveProcessor.GetType())); try { Notification = ActiveProcessor.DoScience(GetTargetPos(FlightGlobals.fetch.VesselTarget.GetTransform().position, 500f), scienceMultiplier, CameraModule.FieldOfView, CameraModule.TakeScreenshot(ActiveProcessor)); } catch (Exception e) { Notification = "An error occured. Please post that you're having this error on the official CactEye 2 thread on the Kerbal Forums."; Debug.Log("CactEye 2: Exception 4: An error occured producing a science report!"); Debug.Log(e.ToString()); } timer = 0f; } } else { GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter; GUI.Label(new Rect(425f, 252f, 250, 32), "Data processing not available."); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); //Draw Processor controls in bottom center of display, with observation and screenshot buttons in center. DrawTargetPointer(); if (ActiveProcessor) { //Close window down if we run out of power if (!ActiveProcessor.IsActive()) { // Toggle(); // ScreenMessages.PostScreenMessage("Image processor is out of power. Please restore power to telescope.", 6, ScreenMessageStyle.UPPER_CENTER); ActiveProcessor = null; Notification = "Image Processor is out of power. Please restore power to telescope"; ScreenMessages.PostScreenMessage(Notification, 3f, ScreenMessageStyle.UPPER_CENTER); timer = 0f; Toggle(); } //Zoom Feedback Label. string LabelZoom = "Zoom/Magnification: x"; if (CameraModule.FieldOfView > 0.0064) { LabelZoom += string.Format("{0:####0.0}", 64 / CameraModule.FieldOfView); } else { LabelZoom += string.Format("{0:0.00E+0}", (64 / CameraModule.FieldOfView)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft; GUILayout.Label(LabelZoom); GUILayout.EndHorizontal(); //Zoom Slider Controls. GUILayout.BeginHorizontal(); FieldOfView = GUILayout.HorizontalSlider(FieldOfView, 0f, 1f); CameraModule.FieldOfView = 0.5f * Mathf.Pow(4f - FieldOfView * (4f - Mathf.Pow(ActiveProcessor.GetMinimumFOV(), (1f / 3f))), 3); GUILayout.EndHorizontal(); //Log spam //Debug.Log("CactEye 2: MinimumFOV = " + ActiveProcessor.GetMinimumFOV().ToString()); } else { GUILayout.BeginHorizontal(); GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft; GUILayout.Label("Processor not installed; optics module cannot function without an image processor."); GUILayout.EndHorizontal(); } //Gyro GUI. Active only if the craft has an active gyro if (GyroEnabled) { //Gyro Slider Label GUILayout.BeginHorizontal(); GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft; GUILayout.Label("Gyro Sensitivity: " + GyroSensitivity.ToString("P") + " + minimum gyroscopic torgue.", GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); //Gyro Slider Controls. GUILayout.BeginHorizontal(); GyroSensitivity = GUILayout.HorizontalSlider(GyroSensitivity, 0f, 1f, GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); SetTorgue(); } //Make the window draggable by the top bar only. GUI.DragWindow(new Rect(0, 0, WindowPosition.width, 16)); }