예제 #1
0
        public void TestFormats()
        {
            KSPDateTime dt = new KSPDateTime(1, 100);

            KSPDateStructure.Months = new List <KSPMonth>();

            Assert.AreEqual("100/00/0001", dt.ToString("dd/MM/yyyy"));

            Assert.AreEqual("Year 1, Day 100 - 0h, 0m", dt.ToString());


            KSPDateStructure.SetEarthCalendar();
            Assert.AreEqual("25/01/1951", dt.ToString("dd/MM/yyyy"));


            dt = new KSPDateTime(1951, 100);
            Assert.AreEqual("10/04/1951", dt.ToString("dd/MM/yyyy"));

            Assert.AreEqual("Hello there 1951", String.Format("Hello there {0:yyyy}", dt));
        }
예제 #2
0
        //List<KSPMonth> Months;

        public string getDateTimeStr(string format)
        {
            // This uses the class from TriggerAu, as copied from the TransferWindowPlanner

            if (lastTimeChecked < 0)
            {
                if (KSPDateStructure.CalendarType == CalendarTypeEnum.KSPStock)
                {
                    // If  we are using the stock calendar, we need to initialize the
                    // Months list, since the class doesn't do that
                    //
                    yearLen  = dayLen * daysInYear;
                    monthLen = yearLen / monthsInYear / dayLen;

                    List <KSPMonth> Months = new List <KSPMonth>();
                    double          x      = 0;

                    for (int i = 1; i < monthsInYear + 1; i++)
                    {
                        x += monthLen;
                        //if (x >= 7) x -= 7f;
                        KSPMonth m1 = new KSPMonth(i.ToString(), (int)x);
                        Months.Add(m1);
                        //Debug.Log("month list, i: " + i + ", x: " + ((int)x).ToString());
                    }
                    KSPDateStructure.Months = Months;
                }
            }
            if (Math.Abs(Planetarium.GetUniversalTime() - lastTimeChecked) < 1)
            {
                return(lastDateTimeReturned);
            }

            //secKerbinInitial = (Calendar.Instance.dtKerbinInitial.Year - 1) * yearLen;
            secKerbinInitial = (Calendar.Instance.dtKerbinInitial.Year - 1) * Math.Truncate(daysInYear) * dayLen;

            lastTimeChecked = Planetarium.GetUniversalTime();
            var dt = new KSPDateTime(lastTimeChecked + secKerbinInitial);

            //KSPDateStructure.Months = Months;

            lastDateTimeReturned = dt.ToString(format);

            return(lastDateTimeReturned);
        }
예제 #3
0
        //MainGUI Window Content
        private void MainGUI(int WindowID)
        {
            double budget = (Reputation.Instance.reputation * BudgetMultiplier);
            double bonus  = (ResearchAndDevelopment.Instance.Science * ScienceSellMultiplier);

            double      time = Planetarium.GetUniversalTime();
            KSPDateTime dt   = new KSPDateTime(time);
            KSPDateTime next = dt.AddDays(1);

            next = next.AddHours(4 - next.Hour);
            next = next.AddMinutes(-next.Minute);
            next = next.AddSeconds(-next.Second);

            KSPDateTime span = next.Subtract(dt);

            GUILayout.BeginVertical(GUILayout.Width(300), GUILayout.ExpandWidth(false));

            if (ShowSettings)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Budget Multiplier", headerText, GUILayout.Width(150));
                string text = GUILayout.TextField(BudgetMultiplier.ToString());
                int    temp = 0;
                if (int.TryParse(text, out temp))
                {
                    BudgetMultiplier = Mathf.Clamp(temp, 0, 1000000);
                }
                else if (text == "")
                {
                    BudgetMultiplier = 10;
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Science Bonus", headerText, GUILayout.Width(150));
                text = GUILayout.TextField(ScienceSellMultiplier.ToString());
                temp = 0;
                if (int.TryParse(text, out temp))
                {
                    ScienceSellMultiplier = Mathf.Clamp(temp, 0, 1000000);
                }
                else if (text == "")
                {
                    ScienceSellMultiplier = 10000;
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Tech Multiplier", headerText, GUILayout.Width(150));
                text = GUILayout.TextField(ScienceBuyMultiplier.ToString());
                temp = 0;
                if (int.TryParse(text, out temp))
                {
                    ScienceBuyMultiplier = Mathf.Clamp(temp, 0, 1000000);
                }
                else if (text == "")
                {
                    ScienceBuyMultiplier = 10000;
                }
                GUILayout.EndHorizontal();

                if (GUILayout.Button("< Back"))
                {
                    ShowSettings = false;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Next Budget", headerText, GUILayout.Width(100));
                GUILayout.Label(budget.ToString("C"), normalText);
                if (GUILayout.Button("$", GUILayout.Width(20), GUILayout.ExpandHeight(false)))
                {
                    ShowSettings = true;
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Due In", headerText, GUILayout.Width(100));
                GUILayout.Label(span.ToString("H\\h m\\m s\\s"), normalText);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Science Bonus", headerText, GUILayout.Width(100));
                GUILayout.Label(bonus.ToString("C"), normalText);
                GUILayout.EndHorizontal();

                GUILayout.Label("Cash out science", bigHeaderText);

                GUILayout.BeginHorizontal();
                if (GUILayout.Button("1"))
                {
                    CashOutScience(1);
                }
                if (GUILayout.Button("10"))
                {
                    CashOutScience(10);
                }
                if (GUILayout.Button("100"))
                {
                    CashOutScience(100);
                }
                GUILayout.EndHorizontal();

                if (GUILayout.Button("All"))
                {
                    CashOutScience(ResearchAndDevelopment.Instance.Science);
                }
            }

            GUILayout.EndVertical();
        }