Advertisement
Guest User

App launcher button #2

a guest
Aug 11th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1.     public void Awake()
  2.         {
  3.             try
  4.             {
  5.                 Debug.Log("[DangIt]: Awaking runtime...");
  6.                 GameEvents.onGUIApplicationLauncherReady.Add(OnLauncherReady);
  7.             }
  8.             catch (Exception e)
  9.             {
  10.                 Debug.Log(e.Message);
  11.                 throw;
  12.             }
  13.         }
  14.  
  15.     void OnLauncherReady()
  16.         {
  17.             if (ApplicationLauncher.Ready)
  18.             {
  19.                 try
  20.                 {
  21.                     Debug.Log("About to add the app button...");
  22.  
  23.                     Texture btnTex = GameDatabase.Instance.GetTexture("DangIt/Textures/appBtn", false);
  24.                     if (btnTex == null)
  25.                         throw new Exception("The texture wasn't loaded!");
  26.  
  27.                     appBtn = ApplicationLauncher.Instance.AddModApplication(
  28.                                 onAppBtnToggleOn,
  29.                                 onAppBtnToggleOff,
  30.                                 dummyVoid,
  31.                                 dummyVoid,
  32.                                 dummyVoid,
  33.                                 dummyVoid,
  34.                                 ApplicationLauncher.AppScenes.SPACECENTER,
  35.                                 btnTex);
  36.                 }
  37.                 catch (Exception e)
  38.                 {
  39.                     Debug.Log("[DangIt]: Error! " + e.Message);
  40.                     throw;
  41.                 }
  42.             }
  43.         }
  44.  
  45.  
  46.         void onAppBtnToggleOn()
  47.         {
  48.             newSettings = this.currentSettings.ShallowClone();
  49.             this.showGUI = true;            
  50.         }
  51.  
  52.  
  53.         void onAppBtnToggleOff()
  54.         {
  55.             newSettings = null;
  56.             this.showGUI = false;
  57.         }
  58.  
  59.  
  60.         void dummyVoid()
  61.         {
  62.             return;
  63.         }
  64.  
  65.  
  66.         void OnGUI()
  67.         {
  68.             if (showGUI)
  69.             {
  70.                 GUI.skin = HighLogic.Skin;
  71.                 windowRect = GUILayout.Window("DangItSettings".GetHashCode(), windowRect, WindowFunction, "DangIt! Settings",
  72.                     GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
  73.             }
  74.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement