MrMcCommieJr

Mach.cs

Jun 3rd, 2015
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using UnityEngine;
  2. using Mach.Extensions;
  3. using KSP.IO;
  4.  
  5. namespace Mach
  6. {
  7.     public class Mach : PartModule
  8.     {
  9.         private static Rect _windowPosition = new Rect();
  10.  
  11.         public override void OnStart(StartState state)
  12.         {
  13.             if (state != StartState.Editor)
  14.             {
  15.                 RenderingManager.AddToPostDrawQueue(0, OnDraw);
  16.             }
  17.         }
  18.  
  19.         public override void OnSave(ConfigNode node)
  20.         {
  21.             PluginConfiguration config = PluginConfiguration.CreateForType<Mach>();
  22.  
  23.             config.SetValue("Window Position", _windowPosition);
  24.             config.save();
  25.         }
  26.  
  27.         public override void OnLoad(ConfigNode node)
  28.         {
  29.             PluginConfiguration config = PluginConfiguration.CreateForType<Mach>();
  30.  
  31.             config.load();
  32.             _windowPosition = config.GetValue<Rect>("Window Position");
  33.         }
  34.        
  35.         private void OnDraw()
  36.         {
  37.             if (this.vessel == FlightGlobals.ActiveVessel && this.part.IsPrimary(this.vessel.parts, this.ClassID)) ;
  38.             {
  39.                 _windowPosition = GUILayout.Window(10, _windowPosition, OnWindow, "Mach Gauge");
  40.  
  41.                 if (_windowPosition.x == 0f && _windowPosition.y == 0f)
  42.                     _windowPosition = _windowPosition.CenterScreen();
  43.             }
  44.         }
  45.  
  46.         private void OnWindow(int windowid)
  47.         {
  48.             GUILayout.Label(vessel.mach.ToString("0.0"), GUILayout.Width(100f));
  49.            
  50.             GUI.DragWindow();
  51.         }  
  52.     }
  53. }
Add Comment
Please, Sign In to add comment