<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using KSP;
using UnityEngine;
using KSPPluginFramework;

using TWPToolbarWrapper;
using TWP_KACWrapper;

namespace TransferWindowPlanner
{

    #region Starter Classes
    [KSPAddon(KSPAddon.Startup.Flight, false)]
    public class TransferWindowPlannerFlight : TransferWindowPlanner { }
    [KSPAddon(KSPAddon.Startup.EditorAny, false)]
    public class TransferWindowPlannerEditor : TransferWindowPlanner { }
    [KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
    public class TransferWindowPlannerSpaceCenter : TransferWindowPlanner { }
    [KSPAddon(KSPAddon.Startup.TrackingStation, false)]
    public class TransferWindowPlannerTrackingStation : TransferWindowPlanner { }
    #endregion    

    public partial class TransferWindowPlanner:MonoBehaviourExtended
    {
        internal static Settings settings;
        internal IButton btnToolbar = null;

        internal TWPWindow windowMain;
        internal TWPWindowSettings windowSettings;
        internal TWPWindowSettingsBlockout windowSettingsBlockout;
        // need two for unity skin
        internal TWPWindowSettingsBlockout windowSettingsBlockoutExtra;

        internal AngleRenderPhase PhaseAngle;
        internal AngleRenderEject EjectAngle;

        internal static List<GameScenes> lstScenesForAngles = new List<GameScenes>() { GameScenes.TRACKSTATION, GameScenes.FLIGHT };

        internal override void OnAwake()
        {
            LogFormatted("Awakening the TransferWindowPlanner (TWP)");

            LogFormatted("Checking for PluginData folder");
            if (!System.IO.Directory.Exists(Resources.PathPlugin + "/PluginData"))
                System.IO.Directory.CreateDirectory(Resources.PathPlugin + "/PluginData");

            LogFormatted("Loading Settings");
            settings = new Settings("PluginData/settings.cfg");
			Boolean blnSettingsLoaded = settings.Load();
			if (!blnSettingsLoaded)
			{
				settings = new Settings("settings.cfg");
				blnSettingsLoaded = settings.Load();
				if (blnSettingsLoaded)
				{
					settings.FilePath = "PluginData/settings.cfg";
					System.IO.File.Move(Resources.PathPlugin + "/settings.cfg", Resources.PathPlugin + "/PluginData/settings.cfg");
				}
			}

			if (!blnSettingsLoaded)
			{
				settings.FilePath = "PluginData/settings.cfg";
				LogFormatted("Settings Load Failed");
			}

            InitWindows();

            if(settings.SelectedCalendar==CalendarTypeEnum.Earth) {
                KSPDateStructure.SetEarthCalendar(settings.EarthEpoch);
                windowSettings.ddlSettingsCalendar.SelectedIndex = (Int32)settings.SelectedCalendar;
            }

            KSPDateStructure.UseStockDateFormatters = settings.UseStockDateFormatters;

            //plug us in to the draw queue and start the worker
            //Rem out for unity5
            //RenderingManager.AddToPostDrawQueue(1, DrawGUI);

            //Get whether the toolbar is there
            settings.BlizzyToolbarIsAvailable = ToolbarManager.ToolbarAvailable;

            //setup the Toolbar button if necessary
            if (settings.ButtonStyleToDisplay == Settings.ButtonStyleEnum.Toolbar)
            {
                btnToolbar = InitToolbarButton();
            }

            //Hook the App Launcher
            GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
            GameEvents.onGUIApplicationLauncherDestroyed.Add(DestroyAppLauncherButton);

            GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequestedForAppLauncher);

            // Need this one to handle the hideUI cancelling via pause menu
            GameEvents.onGameUnpause.Add(OnUnpause);

            //Hook the Angle renderers
            if (lstScenesForAngles.Contains(HighLogic.LoadedScene))
            {
                PhaseAngle = MapView.MapCamera.gameObject.AddComponent<AngleRenderPhase>();
                EjectAngle = MapView.MapCamera.gameObject.AddComponent<AngleRenderEject>();
            }

            //do the daily version check if required
            if (settings.DailyVersionCheck)
                settings.VersionCheck(this, false);
        }

        internal override void OnDestroy()
        {
            LogFormatted("Destroying the TransferWindowPlanner (TWP)");

            if (windowMain.bw!=null && windowMain.bw.IsBusy)
                windowMain.bw.CancelAsync();

            //Rem out for unity5
            //RenderingManager.RemoveFromPostDrawQueue(1, DrawGUI);

            if (PhaseAngle != null)
            {
                Destroy(PhaseAngle.gameObject);
            }
            if (EjectAngle != null)
            {
                Destroy(EjectAngle.gameObject);
            }

            GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
            GameEvents.onGUIApplicationLauncherDestroyed.Remove(DestroyAppLauncherButton);
            GameEvents.onGameSceneLoadRequested.Remove(OnGameSceneLoadRequestedForAppLauncher);

            // Need this one to handle the hideUI cancelling via pause menu<commit_msg>Dont destroy the camera - only the angle component :facepalm:<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using KSP;
using UnityEngine;
using KSPPluginFramework;

using TWPToolbarWrapper;
using TWP_KACWrapper;

namespace TransferWindowPlanner
{

    #region Starter Classes
    [KSPAddon(KSPAddon.Startup.Flight, false)]
    public class TransferWindowPlannerFlight : TransferWindowPlanner { }
    [KSPAddon(KSPAddon.Startup.EditorAny, false)]
    public class TransferWindowPlannerEditor : TransferWindowPlanner { }
    [KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
    public class TransferWindowPlannerSpaceCenter : TransferWindowPlanner { }
    [KSPAddon(KSPAddon.Startup.TrackingStation, false)]
    public class TransferWindowPlannerTrackingStation : TransferWindowPlanner { }
    #endregion    

    public partial class TransferWindowPlanner:MonoBehaviourExtended
    {
        internal static Settings settings;
        internal IButton btnToolbar = null;

        internal TWPWindow windowMain;
        internal TWPWindowSettings windowSettings;
        internal TWPWindowSettingsBlockout windowSettingsBlockout;
        // need two for unity skin
        internal TWPWindowSettingsBlockout windowSettingsBlockoutExtra;

        internal AngleRenderPhase PhaseAngle;
        internal AngleRenderEject EjectAngle;

        internal static List<GameScenes> lstScenesForAngles = new List<GameScenes>() { GameScenes.TRACKSTATION, GameScenes.FLIGHT };

        internal override void OnAwake()
        {
            LogFormatted("Awakening the TransferWindowPlanner (TWP)");

            LogFormatted("Checking for PluginData folder");
            if (!System.IO.Directory.Exists(Resources.PathPlugin + "/PluginData"))
                System.IO.Directory.CreateDirectory(Resources.PathPlugin + "/PluginData");

            LogFormatted("Loading Settings");
            settings = new Settings("PluginData/settings.cfg");
			Boolean blnSettingsLoaded = settings.Load();
			if (!blnSettingsLoaded)
			{
				settings = new Settings("settings.cfg");
				blnSettingsLoaded = settings.Load();
				if (blnSettingsLoaded)
				{
					settings.FilePath = "PluginData/settings.cfg";
					System.IO.File.Move(Resources.PathPlugin + "/settings.cfg", Resources.PathPlugin + "/PluginData/settings.cfg");
				}
			}

			if (!blnSettingsLoaded)
			{
				settings.FilePath = "PluginData/settings.cfg";
				LogFormatted("Settings Load Failed");
			}

            InitWindows();

            if(settings.SelectedCalendar==CalendarTypeEnum.Earth) {
                KSPDateStructure.SetEarthCalendar(settings.EarthEpoch);
                windowSettings.ddlSettingsCalendar.SelectedIndex = (Int32)settings.SelectedCalendar;
            }

            KSPDateStructure.UseStockDateFormatters = settings.UseStockDateFormatters;

            //plug us in to the draw queue and start the worker
            //Rem out for unity5
            //RenderingManager.AddToPostDrawQueue(1, DrawGUI);

            //Get whether the toolbar is there
            settings.BlizzyToolbarIsAvailable = ToolbarManager.ToolbarAvailable;

            //setup the Toolbar button if necessary
            if (settings.ButtonStyleToDisplay == Settings.ButtonStyleEnum.Toolbar)
            {
                btnToolbar = InitToolbarButton();
            }

            //Hook the App Launcher
            GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady);
            GameEvents.onGUIApplicationLauncherDestroyed.Add(DestroyAppLauncherButton);

            GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequestedForAppLauncher);

            // Need this one to handle the hideUI cancelling via pause menu
            GameEvents.onGameUnpause.Add(OnUnpause);

            //Hook the Angle renderers
            if (lstScenesForAngles.Contains(HighLogic.LoadedScene))
            {
                PhaseAngle = MapView.MapCamera.gameObject.AddComponent<AngleRenderPhase>();
                EjectAngle = MapView.MapCamera.gameObject.AddComponent<AngleRenderEject>();
            }

            //do the daily version check if required
            if (settings.DailyVersionCheck)
                settings.VersionCheck(this, false);
        }

        internal override void OnDestroy()
        {
            LogFormatted("Destroying the TransferWindowPlanner (TWP)");

            if (windowMain.bw!=null && windowMain.bw.IsBusy)
                windowMain.bw.CancelAsync();

            //Rem out for unity5
            //RenderingManager.RemoveFromPostDrawQueue(1, DrawGUI);

            if (PhaseAngle != null)
            {
                Destroy(PhaseAngle);
            }
            if (EjectAngle != null)
            {
                Destroy(EjectAngle);
            }

            GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady);
            GameEvents.onGUIApplicationLauncherDestroyed.Remove(DestroyAppLauncherButton);
            GameEvents.onGameSceneLoadRequested.Remove(OnGameSceneLoadRequestedForAppLauncher);

            // Need this one to handle the hideUI cancelling via pause menu
{'fraction_non_alphanumeric': 0.07770663562281722, 'fraction_numerical': 0.0011641443538998836, 'mean_word_length': 2.706939949658396, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '747145', 'n_tokens_mistral': 2781, 'n_tokens_neox': 2614, 'n_words': 529}