public void Start() { settings = ConfigNode.Load(KSPUtil.ApplicationRootPath + "GameData/Diazo/ModActions/ModActions.cfg"); winTop = float.Parse(settings.GetValue("FltWinTop")); winLeft = float.Parse(settings.GetValue("FltWinLeft")); if (ToolbarManager.ToolbarAvailable) //check if toolbar available, load if it is { MABtn = ToolbarManager.Instance.add("ModActs", "MABtn"); MABtn.TexturePath = "Diazo/ModActions/Btn"; MABtn.ToolTip = "Mod Actions"; MABtn.OnClick += (e) => { ShowModActs = !ShowModActs; if (ShowModActs) { if (ourWin == null) { ourWin = new MainGUIWindow(FlightGlobals.ActiveVessel.Parts, winTop, winLeft); } ourWin.SetPart(null); lastSelectedPart = null; ourWin.drawWin = ShowModActs; } else { if (ourWin != null) { ourWin.drawWin = false; ourWin.Kill(); ourWin = null; } } }; } else { //now using stock toolbar as fallback ModActsFlightButton = ApplicationLauncher.Instance.AddModApplication(onStockToolbarClick, onStockToolbarClick, DummyVoid, DummyVoid, DummyVoid, DummyVoid, ApplicationLauncher.AppScenes.FLIGHT, (Texture)GameDatabase.Instance.GetTexture("Diazo/ModActions/BtnStock", false)); } }
public void OnDisable() { if (ourWin != null) { Debug.Log("ModActions Flight Dis b"); winTop = ourWin.MainWindowRect.y; winLeft = ourWin.MainWindowRect.x; ourWin.drawWin = false; ourWin.Kill(); } settings.RemoveValue("FltWinTop"); settings.RemoveValue("FltWinLeft"); settings.AddValue("FltWinTop", winTop); settings.AddValue("FltWinLeft", winLeft); Debug.Log("ModActions Flight Dis A"); settings.Save(KSPUtil.ApplicationRootPath + "GameData/Diazo/ModActions/ModActions.cfg"); Debug.Log("ModActions Flight Dis c"); ourWin = null; if (ToolbarManager.ToolbarAvailable) //if toolbar loaded, destroy button on leaving scene { Debug.Log("ModActions Flight Dis d"); MABtn.Destroy(); } else { Debug.Log("ModActions Flight Dis e"); ApplicationLauncher.Instance.RemoveModApplication(ModActsFlightButton); } Debug.Log("ModActions Flight Dis f"); }
public void onStockToolbarClick() { string errLine = "1"; try { errLine = "2"; ShowModActs = !ShowModActs; errLine = "3"; if (ShowModActs) { errLine = "4"; if (ourWin == null) { //Debug.Log("make win"); errLine = "5"; ourWin = new MainGUIWindow(FlightGlobals.ActiveVessel.Parts, winTop, winLeft); } errLine = "6"; ourWin.SetPart(null); errLine = "7"; lastSelectedPart = null; errLine = "8"; ourWin.drawWin = ShowModActs; } else { errLine = "9"; if (ourWin != null) { errLine = "10"; ourWin.drawWin = false; ourWin.Kill(); ourWin = null; } } } catch (Exception e) { Debug.Log("ModActs StockBtnClick " + errLine + " " + e); } }
public void WinChangeAction(IUIObject obj) { if (EditorLogic.fetch.editorScreen == EditorScreen.Actions) { if (ourWin == null) //initialize our window if not already extant, this event triggers twice per panels change { ourWin = new MainGUIWindow(EditorLogic.SortedShipList, winTop, winLeft); ourWin.drawWin = showWin; try //getselectedparts returns null somewhere above it in the hierchy, do it this way for simplicities sake { ourWin.SetPart(EditorActionGroups.Instance.GetSelectedParts().First()); lastSelectedPart = EditorActionGroups.Instance.GetSelectedParts().First(); } catch { ourWin.SetPart(null); lastSelectedPart = null; } } } else //moving away from actions panel, null our window { if (ourWin != null) { ourWin.drawWin = false; ourWin.Kill(); } ourWin = null; } }