<commit_before>using System;
using System.Collections.Generic;
using UnityEngine;
using KSP.UI.Screens;

namespace AltFunding
{
    using Toolbar;

    [KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
    public class AltFundingAddon : MonoBehaviour
    {
        private IButton button;
        private ApplicationLauncherButton stockButton;
        private bool visible;
        private Rect position = new Rect(400, 200, 300, 100);
        private int windowId = 9653;

        public void Start()
        {
            Debug.Log("[AltFunding] AltFundingAddon.Start()");
            if(HighLogic.CurrentGame.Mode != Game.Modes.CAREER)
            {
                Debug.Log("[AltFunding] Not running in game mode " + HighLogic.CurrentGame.Mode);
                Destroy(this);
                return;
            }

            AltFundingScenario.Initialize();

            if(ToolbarManager.ToolbarAvailable)
            {
                button = ToolbarManager.Instance.add("AltFunding", "GUI");
                button.TexturePath = "AltFunding/icon24";
                button.ToolTip = "AltFunding";
                button.Enabled = true;
                button.OnClick += (e) => { ToggleVisibility(); };
            }
            else
            {
                Texture2D texture = GameDatabase.Instance.GetTexture("AltFunding/icon38", false);
                if(texture != null)
                {
                    stockButton = ApplicationLauncher.Instance.AddModApplication(
                        ToggleVisibility, ToggleVisibility, null, null, null, null, ApplicationLauncher.AppScenes.SPACECENTER, texture);
                }
            }
        }

        private void ToggleVisibility()
        {
            visible = !visible;
            position.height = 100;
        }

        internal void OnGUI()
        {
            if(visible)
            {
                GUI.skin = HighLogic.Skin;

                position = GUILayout.Window(windowId, position, DrawWindow, "AltFunding", GUILayout.ExpandHeight(true));
            }
        }

        internal void DrawWindow(int wid)
        {
            if(Time.timeSinceLevelLoad < 1)
            {
                return;
            }

            AltFundingScenario s = AltFundingScenario.Instance;
            FundingCalculator calculator = s.config.GetCalculator();
            if(calculator == null)
            {
                visible = false;
                return;
            }

            GUILayout.BeginVertical();

            double payPeriod = calculator.payPeriod;
            Date date = Calendar.Now;

            double payout;

            if(s.lastPayoutAmount > 0 && s.lastPayoutTime > 0)
            {
                Date lastPayout = AltFundingScenario.LastPayoutDate;
                payout = AltFundingScenario.Instance.lastPayoutAmount;

                GUILayout.Label("Last Payout:", GUILayout.ExpandWidth(true));
                GUILayout.Label(string.Format("${0:F0}", payout), GUILayout.ExpandWidth(true));
                GUILayout.Label(string.Format("Year {0} Day {1}", lastPayout.Year, lastPayout.DayOfYear),
                    GUILayout.ExpandWidth(true));
                GUILayout.Label(" ");
            }

            Date nextPayout = AltFundingScenario.NextPayoutDate;
            payout = calculator.GetPayment((int) Math.Round(nextPayout.UT / payPeriod));

            GUILayout.Label("Next Payout:", GUILayout.ExpandWidth(true));
            GUILayout.Label(string.Format("${0:F0}", payout), GUILayout.ExpandWidth(true));
            GUILayout.Label(string.Format("Year {0} Day {1}", nextPayout.Year, nextPayout.DayOfYear),
                GUILayout.ExpandWidth(true));
            GUILayout.Label(" ");

            double timeToPayout = nextPayout.UT - Planetarium.GetUniversalTime();
            Date toNextPayout = Calendar.FromUT(timeToPayout);

            GUILayout.Label("Time to Next Payout:", GUILayout.ExpandWidth(true));
            GUILayout.Label(string.Format("{0}d {1:00}:{2:00}:{3:00}", toNextPayout.DayOfYear - 1, toNextPayout.Hour, toNextPayout.Minute, toNextPayout.Second),
                GUILayout.ExpandWidth(true));

            GUILayout.EndVertical();

            GUI.DragWindow();
        }
<commit_msg>Making the UI a bit more compact<commit_after>using System;
using System.Collections.Generic;
using UnityEngine;
using KSP.UI.Screens;

namespace AltFunding
{
    using Toolbar;

    [KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
    public class AltFundingAddon : MonoBehaviour
    {
        private IButton button;
        private ApplicationLauncherButton stockButton;
        private bool visible;
        private Rect position = new Rect(400, 200, 250, 100);
        private int windowId = 9653;

        private GUIStyle alignLeft;
        private GUIStyle alignRight;

        public void Start()
        {
            Debug.Log("[AltFunding] AltFundingAddon.Start()");
            if(HighLogic.CurrentGame.Mode != Game.Modes.CAREER)
            {
                Debug.Log("[AltFunding] Not running in game mode " + HighLogic.CurrentGame.Mode);
                Destroy(this);
                return;
            }

            AltFundingScenario.Initialize();

            if(ToolbarManager.ToolbarAvailable)
            {
                button = ToolbarManager.Instance.add("AltFunding", "GUI");
                button.TexturePath = "AltFunding/icon24";
                button.ToolTip = "AltFunding";
                button.Enabled = true;
                button.OnClick += (e) => { ToggleVisibility(); };
            }
            else
            {
                Texture2D texture = GameDatabase.Instance.GetTexture("AltFunding/icon38", false);
                if(texture != null)
                {
                    stockButton = ApplicationLauncher.Instance.AddModApplication(
                        ToggleVisibility, ToggleVisibility, null, null, null, null, ApplicationLauncher.AppScenes.SPACECENTER, texture);
                }
            }
        }

        private void ToggleVisibility()
        {
            visible = !visible;
            position.height = 100;
        }

        internal void OnGUI()
        {
            if(visible)
            {
                GUI.skin = HighLogic.Skin;

                position = GUILayout.Window(windowId, position, DrawWindow, "AltFunding", GUILayout.ExpandHeight(true));
            }
        }

        internal void DrawWindow(int wid)
        {
            if(Time.timeSinceLevelLoad < 1)
            {
                return;
            }

            if(alignRight == null)
            {
                alignLeft = GUI.skin.label;
                alignLeft.alignment = TextAnchor.MiddleLeft;
                alignRight = new GUIStyle(alignLeft);
                alignRight.alignment = TextAnchor.MiddleRight;
            }

            AltFundingScenario s = AltFundingScenario.Instance;
            FundingCalculator calculator = s.config.GetCalculator();
            if(calculator == null)
            {
                visible = false;
                return;
            }

            GUILayout.BeginVertical();

            double payPeriod = calculator.payPeriod;
            Date date = Calendar.Now;

            double payout;

            if(s.lastPayoutAmount > 0 && s.lastPayoutTime > 0)
            {
                Date lastPayout = AltFundingScenario.LastPayoutDate;
                payout = AltFundingScenario.Instance.lastPayoutAmount;

                GUILayout.Label("Last Payout:", GUILayout.ExpandWidth(true));
                GUILayout.BeginHorizontal();
                GUILayout.Label(string.Format("Year {0} Day {1}", lastPayout.Year, lastPayout.DayOfYear),
                    alignLeft, GUILayout.Width(125));
                GUILayout.Label(string.Format("${0:F0}", payout), alignRight, GUILayout.ExpandWidth(true));
                GUILayout.EndHorizontal();
                GUILayout.Label(" ");
            }

            Date nextPayout = AltFundingScenario.NextPayoutDate;
            payout = calculator.GetPayment((int) Math.Round(nextPayout.UT / payPeriod));

            GUILayout.Label("Next Payout:", GUILayout.ExpandWidth(true));
            GUILayout.BeginHorizontal();
            GUILayout.Label(string.Format("Year {0} Day {1}", nextPayout.Year, nextPayout.DayOfYear),
                alignLeft, GUILayout.Width(125));
            GUILayout.Label(string.Format("${0:F0}", payout), alignRight, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();
            GUILayout.Label(" ");

            double timeToPayout = nextPayout.UT - Planetarium.GetUniversalTime();
            Date toNextPayout = Calendar.FromUT(timeToPayout);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Next Payout:", alignLeft, GUILayout.Width(125));
            GUILayout.Label(string.Format("{0}d {1:00}:{2:00}:{3:00}", toNextPayout.DayOfYear - 1, toNextPayout.Hour, toNextPayout.Minute, toNextPayout.Second),
                alignRight, GUILayout.ExpandWidth(true));
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUI.DragWindow();
        }

{'fraction_non_alphanumeric': 0.10164326912612907, 'fraction_numerical': 0.010991402764174556, 'mean_word_length': 1.8095383674717211, 'pattern_counts': {'":': 0, '<': 5, '<?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': '334363', 'n_tokens_mistral': 2702, 'n_tokens_neox': 2382, 'n_words': 429}