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

namespace KSPRemoteLaunch
{
    //[KSPAddon(KSPAddon.Startup.Flight, false)]


    [KSPAddon(KSPAddon.Startup.EditorAny,false)]
    public class RemoteLaunchGUI:MonoBehaviourExtended
    {
        //windowPos is used to position the GUI window, lets set it in the center of the screen
        protected Rect windowPos = new Rect(Screen.width / 2, Screen.height / 2, 10, 10);
        private string latText = "0.0";
        private string lonText = "0.0";
        private string launchText = "";
        private string descText = "";
        private string planetText = "";
        private double lat = 0;
        private double lon = 0;
        private double height = 0.5;
        private bool windowActive = false;
        private string result = "";
        //private List<GUIToggleButton> SiteToggleList;
        private GUIOptionGroup SiteToggleList;

        private void WindowGUI(int windowID)
        {
            GUIStyle buttonSty = new GUIStyle(GUI.skin.button);
            buttonSty.normal.textColor = buttonSty.focused.textColor = Color.white;
            buttonSty.hover.textColor = buttonSty.active.textColor = Color.yellow;
            buttonSty.onNormal.textColor = buttonSty.onFocused.textColor = buttonSty.onHover.textColor = buttonSty.onActive.textColor = Color.green;
            buttonSty.padding = new RectOffset(8, 8, 8, 8);

            GUIStyle textSty = new GUIStyle(GUI.skin.textField);
            textSty.normal.textColor = buttonSty.focused.textColor = Color.white;
            textSty.padding = new RectOffset(8, 8, 8, 8);

            GUIStyle labelSty = new GUIStyle(GUI.skin.label);
            labelSty.normal.textColor = buttonSty.focused.textColor = Color.white;
            labelSty.padding = new RectOffset(8, 8, 8, 8);

            GUIStyle toggleSty = new GUIStyle(GUI.skin.button);
            toggleSty.normal.textColor = buttonSty.focused.textColor = Color.white;
            toggleSty.padding = new RectOffset(8, 8, 8, 8);
            //toggleSty.onNormal.textColor = Color.green;


            GUILayout.BeginVertical();
            

            GUILayout.Label("Launch Sites:", labelSty, GUILayout.ExpandWidth(true));
            
            //LaunchDriver.getLaunchSites().ForEach(delegate(PSystemSetup.LaunchSite site)
            //{
                //GUILayout.Label(site.name, labelSty, GUILayout.ExpandWidth(true));
                //Boolean enabled = true;
                //if (GUILayout.Toggle(enabled,site.name, toggleSty, GUILayout.ExpandWidth(true)))
                //{
                //    enabled = true;
                //    setLaunchSite(site);
                //}
            //    new GUIToggleButton().CheckPressed(site.name, delegate(bool enabled) { if (!enabled) setLaunchSite(site); });
            //});
            SiteToggleList.setStyle(toggleSty);
            SiteToggleList.checkSelected();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Latitude:  ", labelSty, GUILayout.ExpandWidth(true));
            latText = GUILayout.TextField(latText, textSty, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();
            
            GUILayout.BeginHorizontal();
            GUILayout.Label("Longitude: ", labelSty, GUILayout.ExpandWidth(true));
            lonText = GUILayout.TextField(lonText, textSty, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Planet:   ", labelSty, GUILayout.ExpandWidth(true));
            planetText = GUILayout.TextField(planetText, textSty, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Site Name: ", labelSty, GUILayout.ExpandWidth(true));
            launchText = GUILayout.TextField(launchText, textSty, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();


            GUILayout.Label("Result: " + result, labelSty, GUILayout.ExpandWidth(true));

            if (GUILayout.Button("Add & Set Launch Site", buttonSty, GUILayout.ExpandWidth(true)))
            {
                try
                {
                    lat = double.Parse(latText);
                    lon = double.Parse(lonText);
                    LogDebugOnly("Latitude: {0} , Longitude: {1}", lat, lon);
                    LogDebugOnly("Planet: {0}, Launch Pad: {1}", FlightGlobals.Bodies[1].name,launchText);
                    
                    //PSystemSetup.LaunchSite newSite = LaunchDriver.CreateCustomLaunchSite(lat, lon, FlightGlobals.Bodies[1], launchText,descText);
                    CelestialBody planet = FlightGlobals.Bodies.Single<CelestialBody>(body => body.name == planetText);
                    LaunchSiteExt newSite = LaunchDriver.CreateCustomLaunchSite(lat, lon, planet, launchText, descText);

                    //result = "Site '" + launchText + "' created!";
                    result = String.Format("Site '{0}' created @ Lat: {1} , Lon: {2}", launchText, lat, lon);

                    SiteToggleList.addActiveToggleButton(new GUIToggleButton(launchText, delegate(bool enabled) {
                        LogDebugOnly("Site: {0} | Enabled: {1}",newSite.name, enabled);
                        //if (!enabled)
                            setLaunchSite(newSite);
                            
                    }));

                    LaunchDriver.SaveLaunchSite(newSite);
                    
                }
                catch(Exception e)
                {
                    LogDebugOnly(e.Message);
                    result = e.Message;
                    
                }

            }

            descText = GUILayout.TextArea(descText, textSty, GUILayout.ExpandHeight(true));


            GUILayout.EndVertical();

            GUI.DragWindow(new Rect(0, 0, 250, 30));
        }

        private void setLaunchSite(LaunchSiteExt site)
        {
            try
            {
                LaunchDriver.SetLaunchSite(site.name);
                descText = site.description;
                //result = "Launch Site Loaded: '" + site.name + "'";
            }
            catch (Exception e)
            {
                LogDebugOnly(e.Message);
                result = "Can't find Launch Site";
            }

        }


        private void drawGUI()
        {<commit_msg>Add Site Debug Only, closes #18 Add Site button now only appears in DEBUG builds of the mod.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace KSPRemoteLaunch
{
    //[KSPAddon(KSPAddon.Startup.Flight, false)]


    [KSPAddon(KSPAddon.Startup.EditorAny,false)]
    public class RemoteLaunchGUI:MonoBehaviourExtended
    {
        //windowPos is used to position the GUI window, lets set it in the center of the screen
        protected Rect windowPos = new Rect(Screen.width / 2, Screen.height / 2, 10, 10);
        private string latText = "0.0";
        private string lonText = "0.0";
        private string launchText = "";
        private string descText = "";
        private string planetText = "";
        private double lat = 0;
        private double lon = 0;
        private double height = 0.5;
        private bool windowActive = false;
        private string result = "";
        //private List<GUIToggleButton> SiteToggleList;
        private GUIOptionGroup SiteToggleList;

        private void WindowGUI(int windowID)
        {
            GUIStyle buttonSty = new GUIStyle(GUI.skin.button);
            buttonSty.normal.textColor = buttonSty.focused.textColor = Color.white;
            buttonSty.hover.textColor = buttonSty.active.textColor = Color.yellow;
            buttonSty.onNormal.textColor = buttonSty.onFocused.textColor = buttonSty.onHover.textColor = buttonSty.onActive.textColor = Color.green;
            buttonSty.padding = new RectOffset(8, 8, 8, 8);

            GUIStyle textSty = new GUIStyle(GUI.skin.textField);
            textSty.normal.textColor = buttonSty.focused.textColor = Color.white;
            textSty.padding = new RectOffset(8, 8, 8, 8);

            GUIStyle labelSty = new GUIStyle(GUI.skin.label);
            labelSty.normal.textColor = buttonSty.focused.textColor = Color.white;
            labelSty.padding = new RectOffset(8, 8, 8, 8);

            GUIStyle toggleSty = new GUIStyle(GUI.skin.button);
            toggleSty.normal.textColor = buttonSty.focused.textColor = Color.white;
            toggleSty.padding = new RectOffset(8, 8, 8, 8);
            //toggleSty.onNormal.textColor = Color.green;


            GUILayout.BeginVertical();
            

            GUILayout.Label("Launch Sites:", labelSty, GUILayout.ExpandWidth(true));
            
            //LaunchDriver.getLaunchSites().ForEach(delegate(PSystemSetup.LaunchSite site)
            //{
                //GUILayout.Label(site.name, labelSty, GUILayout.ExpandWidth(true));
                //Boolean enabled = true;
                //if (GUILayout.Toggle(enabled,site.name, toggleSty, GUILayout.ExpandWidth(true)))
                //{
                //    enabled = true;
                //    setLaunchSite(site);
                //}
            //    new GUIToggleButton().CheckPressed(site.name, delegate(bool enabled) { if (!enabled) setLaunchSite(site); });
            //});
            SiteToggleList.setStyle(toggleSty);
            SiteToggleList.checkSelected();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Latitude:  ", labelSty, GUILayout.ExpandWidth(true));
            latText = GUILayout.TextField(latText, textSty, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();
            
            GUILayout.BeginHorizontal();
            GUILayout.Label("Longitude: ", labelSty, GUILayout.ExpandWidth(true));
            lonText = GUILayout.TextField(lonText, textSty, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Planet:   ", labelSty, GUILayout.ExpandWidth(true));
            planetText = GUILayout.TextField(planetText, textSty, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Site Name: ", labelSty, GUILayout.ExpandWidth(true));
            launchText = GUILayout.TextField(launchText, textSty, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();


            GUILayout.Label("Result: " + result, labelSty, GUILayout.ExpandWidth(true));
#if DEBUG
            if (GUILayout.Button("Add & Set Launch Site", buttonSty, GUILayout.ExpandWidth(true)))
            {
                try
                {
                    lat = double.Parse(latText);
                    lon = double.Parse(lonText);
                    LogDebugOnly("Latitude: {0} , Longitude: {1}", lat, lon);
                    LogDebugOnly("Planet: {0}, Launch Pad: {1}", FlightGlobals.Bodies[1].name,launchText);
                    
                    //PSystemSetup.LaunchSite newSite = LaunchDriver.CreateCustomLaunchSite(lat, lon, FlightGlobals.Bodies[1], launchText,descText);
                    CelestialBody planet = FlightGlobals.Bodies.Single<CelestialBody>(body => body.name == planetText);
                    LaunchSiteExt newSite = LaunchDriver.CreateCustomLaunchSite(lat, lon, planet, launchText, descText);

                    //result = "Site '" + launchText + "' created!";
                    result = String.Format("Site '{0}' created @ Lat: {1} , Lon: {2}", launchText, lat, lon);

                    SiteToggleList.addActiveToggleButton(new GUIToggleButton(launchText, delegate(bool enabled) {
                        LogDebugOnly("Site: {0} | Enabled: {1}",newSite.name, enabled);
                        //if (!enabled)
                            setLaunchSite(newSite);
                            
                    }));

                    LaunchDriver.SaveLaunchSite(newSite);
                    
                }
                catch(Exception e)
                {
                    LogDebugOnly(e.Message);
                    result = e.Message;
                    
                }

            }
#endif
            descText = GUILayout.TextArea(descText, textSty, GUILayout.ExpandHeight(true));


            GUILayout.EndVertical();

            GUI.DragWindow(new Rect(0, 0, 250, 30));
        }

        private void setLaunchSite(LaunchSiteExt site)
        {
            try
            {
                LaunchDriver.SetLaunchSite(site.name);
                descText = site.description;
                //result = "Launch Site Loaded: '" + site.name + "'";
            }
            catch (Exception e)
            {
                LogDebugOnly(e.Message);
                result = "Can't find Launch Site";
            }

        }


        private void drawGUI()
        {
{'fraction_non_alphanumeric': 0.10678199632578077, 'fraction_numerical': 0.007501530924678506, 'mean_word_length': 1.9007548845470692, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1079689', 'n_tokens_mistral': 3807, 'n_tokens_neox': 3400, 'n_words': 686}