Пример #1
0
        public void AlarmAppendedToQueue(ref Alarm alarm)
        {
            if (alarm == null)
            {
                return;
            }

            switch (AlarmType)
            {
            case AlarmType.KerbalAlarmClock:
            {
                var alarms = KACUtils.GetSortedPlanningActiveAlarms();

                if (alarms.Any())
                {
                    double busy_UT_end = alarms.Last().AlarmTime;
                    double busyTime    = Math.Round(busy_UT_end - Utils.UT());

                    alarm.UT += busyTime;


                    Messages.Add(Localizer.Format("#KVASS_alarm_appended", alarm.Title), 0);
                }
                else
                {
                    Messages.Add(Localizer.Format("#KVASS_alarm_created", alarm.Title), 0);
                }
                break;
            }

            case AlarmType.AlarmClockApp:
            {
                var alarms = ACAUtils.GetSortedPlanningActiveAlarms();

                if (alarms.Any())
                {
                    double busy_UT_end = alarms.Last().ut;
                    double busyTime    = Math.Round(busy_UT_end - Utils.UT());


                    //Log(String.Format("Bef - title:{0}, UT:{1}, Time:{2}", alarm.Title, alarm.UT, alarm.Time));
                    alarm.UT   += busyTime;
                    alarm.Time += busyTime;
                    //Log(String.Format("Aft - title:{0}, UT:{1}, Time:{2}", alarm.Title, alarm.UT, alarm.Time));

                    Messages.Add(Localizer.Format("#KVASS_alarm_appended", alarm.Title), 0);
                }
                else
                {
                    Messages.Add(Localizer.Format("#KVASS_alarm_created", alarm.Title), 0);
                }
                break;
            }

            default:
                break;
            }
        }
Пример #2
0
        private void OnAlarmRemoving(AlarmTypeBase deleting_alarm)
        {
            if (deleting_alarm == null || deleting_alarm.Actioned)
            {
                return;
            }

            if (deleting_alarm.title.StartsWith(Localizer.Format("#KVASS_alarm_title_prefix"), StringComparison.Ordinal))
            {
                var alarms    = ACAUtils.GetSortedPlanningActiveAlarms().ToList();
                int del_index = alarms.FindIndex(z => z.Id == deleting_alarm.Id);

                double planning_UT_start;

                if (del_index == 0)
                {
                    planning_UT_start = Utils.UT();
                }
                else
                {
                    planning_UT_start = alarms[del_index - 1].ut;
                }

                double planning_UT_end = deleting_alarm.ut;

                double planningTime = Math.Round(planning_UT_end - planning_UT_start);

                for (var i = del_index + 1; i < alarms.Count; i++)
                {
                    //Log(String.Format("Rem Bef title:{0}, UT:{1:F0}, Time:{2:F0}", alarms[i].title, alarms[i].ut, alarms[i].timeEntry));
                    alarms[i].ut -= planningTime;

                    alarms[i].timeEntry = alarms[i].ut - Utils.UT(); //-= planningTime;

                    //Log(String.Format("Rem Aft title:{0}, UT:{1:F0}, Time:{2:F0}", alarms[i].title, alarms[i].ut, alarms[i].timeEntry));
                    alarms[i].OnScenarioUpdate();
                    alarms[i].UIInputPanelUpdate();
                }
                RemovingMessages(deleting_alarm.title, alarms.Count - del_index - 1);
            }
        }