Jump to content

ApplicationLauncher creating extra copies of buttons?


Recommended Posts

I must be doing something stupid. It seems likely as it's late here. I'm getting five copies of the same button, and I just can't figure out why. I've even compared code to my previous plugin, and I'm not seeing it. Code below:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KSP;


namespace SpaceRace
{
[KSPAddon(KSPAddon.Startup.EveryScene, false)]
public class SpaceRaceMain : MonoBehaviour
{
private String save_folder;
public ApplicationLauncherButton buttonSR;
private Rect mainWindow = new Rect(Screen.width / 8 + 100, Screen.height / 4, 400, 125);
private Rect trainingWindow = new Rect(Screen.width / 8, Screen.height / 4 + 100, 400, 125);
private Rect researchWindow = new Rect(Screen.width / 8, Screen.height / 4 + 100, 400, 125);
private Rect rivalWindow = new Rect(Screen.width / 8, Screen.height / 4 + 100, 400, 125);
public static SpaceRaceMain InstanceSR;


public void Start()
{
if (InstanceSR != null)
{
Destroy(InstanceSR);
}
InstanceSR = this;
Debug.Log("Firing Start()");
GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
save_folder = GetRootPath() + "/saves/" + HighLogic.SaveFolder + "/";
}


void OnGUIAppLauncherReady()
{
{
this.buttonSR = ApplicationLauncher.Instance.AddModApplication(
onAppLauncherToggleOn,
onAppLauncherToggleOff,
null,
null,
null,
null,
ApplicationLauncher.AppScenes.SPACECENTER,
(Texture)GameDatabase.Instance.GetTexture("EvilCorp/Textures/icon_button_stock", false));
}
}


public void DestroyButtons()
{
GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
ApplicationLauncher.Instance.RemoveModApplication(buttonSR);
}


public static String GetRootPath()
{
String path = KSPUtil.ApplicationRootPath;
path = path.Replace("\\", "/");
if (path.EndsWith("/")) path = path.Substring(0, path.Length - 1);
return path;
}


void onAppLauncherToggleOn()
{
Debug.Log("SpaceRace: Open Menu");
RenderingManager.AddToPostDrawQueue(0, OnDraw);
}


void onAppLauncherToggleOff()
{
Debug.Log("SpaceRace: Close Menu");
RenderingManager.RemoveFromPostDrawQueue(0, OnDraw);
}


private void OnDraw()
{
mainWindow = GUILayout.Window(65832, mainWindow, OnWindow, "Space Race");
}


private void TrainingDraw()
{
trainingWindow = GUILayout.Window(87465, trainingWindow, TrainingWindow, "Training Center");
}


private void TrainingWindow(int windowId)
{


}


private void ResearchDraw()
{
researchWindow = GUILayout.Window(76132, researchWindow, ResearchWindow, "Research Center");
}


private void ResearchWindow(int windowId)
{


}


private void RivalDraw()
{
rivalWindow = GUILayout.Window(65324, rivalWindow, RivalWindow, "Rival Space Center");
}


private void RivalWindow(int windowId)
{


}


private void OnWindow(int windowId)
{
GUILayout.BeginHorizontal();
if (GUILayout.Button("Training Center"))
{
RenderingManager.AddToPostDrawQueue(0, TrainingDraw);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Research Center"))
{


}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("View Rival Space Center"))
{


}
GUILayout.EndHorizontal();
}
}
}

Edited by johnqevil
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...