Skip to content

Commit 3fc8bbe

Browse files
committed
Merge 3.10.0.0 to master
2 parents e733341 + ae3666a commit 3fc8bbe

28 files changed

+640
-343
lines changed

KerbalAlarmClock/AlarmObjects.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,31 @@ public enum ContractAlarmTypeEnum
145145
}
146146

147147

148-
#region "Constructors"
148+
#region "Constructors"
149149
public KACAlarm()
150150
{
151151
ID = Guid.NewGuid().ToString("N");
152152
}
153153
public KACAlarm(double UT) : this ()
154154
{
155155
AlarmTime.UT = UT;
156-
Remaining.UT = AlarmTime.UT - Planetarium.GetUniversalTime();
156+
_lastRemainingUTStringUpdate = double.MaxValue; //force the remaining string update;
157+
UpdateRemaining(AlarmTime.UT - Planetarium.GetUniversalTime());
158+
}
159+
160+
private double _lastRemainingUTStringUpdate;
161+
private string _remainingTimeStamp3;
162+
public string RemainingTimeSpanString3 { get { return _remainingTimeStamp3; } }
163+
internal void UpdateRemaining(double remaining)
164+
{
165+
Remaining.UT = remaining;
166+
167+
//Do we need to update strings?
168+
if (Math.Floor(remaining) != _lastRemainingUTStringUpdate)
169+
{
170+
_remainingTimeStamp3 = Remaining.ToStringStandard(KerbalAlarmClock.settings.TimeSpanFormat, 3);
171+
_lastRemainingUTStringUpdate = Math.Floor(remaining);
172+
}
157173
}
158174

159175
public KACAlarm(String NewName, double UT, AlarmTypeEnum atype, AlarmActions aAction)

KerbalAlarmClock/Framework/ExtensionsUnity.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,28 @@ public static Rect ClampToScreen(this Rect r)
3434
/// <param name="ScreenBorder">A Border to the screen bounds that the Rect will be clamped inside (can be negative)</param>
3535
public static Rect ClampToScreen(this Rect r, RectOffset ScreenBorder)
3636
{
37-
r.x = Mathf.Clamp(r.x, ScreenBorder.left, Screen.width - r.width - ScreenBorder.right);
38-
r.y = Mathf.Clamp(r.y, ScreenBorder.top, Screen.height - r.height - ScreenBorder.bottom);
37+
return r.ClampToScreen(ScreenBorder, 1f);
38+
}
39+
40+
/// <summary>
41+
/// Ensure that the Rect remains within the screen bounds
42+
/// </summary>
43+
/// <param name="ScreenBorder">A Border to the screen bounds that the Rect will be clamped inside (can be negative)</param>
44+
/// <param name="scale">the UIScale to calc at</param>
45+
public static Rect ClampToScreen(this Rect r, RectOffset ScreenBorder, float scale)
46+
{
47+
r.x = Mathf.Clamp(r.x * scale, ScreenBorder.left * scale, Screen.width - r.width * scale - ScreenBorder.right * scale) / scale;
48+
r.y = Mathf.Clamp(r.y * scale, ScreenBorder.top * scale, Screen.height - r.height * scale - ScreenBorder.bottom * scale) / scale;
49+
50+
if (r.x < 0)
51+
{
52+
r.x = 0;
53+
}
54+
55+
if (r.y < 0)
56+
{
57+
r.y = 0;
58+
}
3959
return r;
4060
}
4161

KerbalAlarmClock/Framework/MonoBehaviourExtended.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public abstract class MonoBehaviourExtended : MonoBehaviour
5757
//}
5858
static MonoBehaviourExtended()
5959
{
60-
UnityEngine.Random.seed = (int)(DateTime.Now - DateTime.Now.Date).TotalSeconds;
60+
//UnityEngine.Random.seed = (int)(DateTime.Now - DateTime.Now.Date).TotalSeconds;
61+
UnityEngine.Random.InitState((int)(DateTime.Now - DateTime.Now.Date).TotalSeconds);
6162
}
6263
#endregion
6364

KerbalAlarmClock/FrameworkExt/AudioController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ internal class AudioController:MonoBehaviourExtended
1313
{
1414
//Parent Objects
1515
internal KerbalAlarmClock mbKAC;
16-
private Settings settings;
17-
16+
//private Settings settings; //Commented because usage removed
17+
1818
AudioSource audiosourceAlarm;
1919

2020
internal void Init()
2121
{
22-
settings = KerbalAlarmClock.settings;
22+
//settings = KerbalAlarmClock.settings; //Commented cause usage removed
2323

2424
//if (Resources.clipAlarms.ContainsKey(settings.AlarmsAlertSound))
2525
// mbARP.clipAlarmsAlert = Resources.clipAlarms[settings.AlarmsAlertSound];

KerbalAlarmClock/FrameworkExt/KSPDateStructure.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,30 @@ static public KSPDateTime EpochAsKSPDateTime {
3232
/// <summary>How many minutes make up an hour</summary>
3333
static public Int32 MinutesPerHour { get; private set; }
3434
/// <summary>How many hours make up a day</summary>
35-
static public Int32 HoursPerDay { get; private set; }
35+
static public double HoursPerDay { get; private set; }
3636
/// <summary>How many days make up a year</summary>
37-
static public Int32 DaysPerYear { get; private set; }
37+
static public double DaysPerYear { get; private set; }
3838

3939
/// <summary>How many seconds (game UT) make up an hour</summary>
4040
static public Int32 SecondsPerHour { get { return SecondsPerMinute * MinutesPerHour; } }
4141
/// <summary>How many seconds (game UT) make up a day</summary>
42-
static public Int32 SecondsPerDay { get { return SecondsPerHour * HoursPerDay; } }
42+
static public double SecondsPerDay { get { return SecondsPerHour * HoursPerDay; } }
4343
/// <summary>How many seconds (game UT) make up a year - not relevant for Earth time</summary>
44-
static public Int32 SecondsPerYear { get { return SecondsPerDay * DaysPerYear; } }
44+
static public double SecondsPerYear { get { return SecondsPerDay * DaysPerYear; } }
4545

4646
/// <summary>How many seconds (game UT) make up a year - not relevant for Earth time</summary>
47-
static public Int32 HoursPerYear { get { return HoursPerDay * DaysPerYear; } }
47+
static public double HoursPerYear { get { return HoursPerDay * DaysPerYear; } }
4848

4949

5050
/// <summary>What Earth date does UT 0 represent</summary>
5151
static public DateTime CustomEpochEarth { get; private set; }
5252

5353
/// <summary>What type of Calendar is being used - KSPStock, Earth, or custom</summary>
5454
static public CalendarTypeEnum CalendarType {get; private set;}
55-
55+
56+
/// <summary>Set true to use the KSP IDateTimeFormatter outputs where possible</summary>
57+
static public bool UseStockDateFormatters = true;
58+
5659
/// <summary>Sets the Date Structure to be stock KSP</summary>
5760
static public void SetKSPStockCalendar()
5861
{
@@ -63,8 +66,8 @@ static public void SetKSPStockCalendar()
6366
SecondsPerMinute = 60;
6467
MinutesPerHour = 60;
6568

66-
HoursPerDay = GameSettings.KERBIN_TIME ? 6 : 24;
67-
DaysPerYear = GameSettings.KERBIN_TIME ? 426 : 365;
69+
HoursPerDay = KSPUtil.dateTimeFormatter.Day / 3600; // GameSettings.KERBIN_TIME ? 6 : 24;
70+
DaysPerYear = KSPUtil.dateTimeFormatter.Year / KSPUtil.dateTimeFormatter.Day; // GameSettings.KERBIN_TIME ? 426 : 365;
6871
}
6972

7073
/// <summary>Sets the Date Structure to be Earth based - Accepts Epoch date as string</summary>
@@ -134,6 +137,8 @@ static KSPDateStructure()
134137

135138
Months = new List<KSPMonth>();
136139
//LeapDays = new List<KSPLeapDay>();
140+
141+
UseStockDateFormatters = true;
137142
}
138143

139144
/// <summary>List of KSPMonth objects representing the months in the year</summary>

KerbalAlarmClock/FrameworkExt/KSPDateTime.cs

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public int Year {
2121
get { if (CalType == CalendarTypeEnum.Earth)
2222
return _EarthDateTime.Year;
2323
else
24-
return KSPDateStructure.EpochYear + (Int32)UT / KSPDateStructure.SecondsPerYear;
24+
return KSPDateStructure.EpochYear + (Int32)(UT / KSPDateStructure.SecondsPerYear);
2525
}
2626
}
2727

@@ -31,7 +31,7 @@ public int DayOfYear {
3131
get { if (CalType == CalendarTypeEnum.Earth)
3232
return _EarthDateTime.DayOfYear;
3333
else
34-
return KSPDateStructure.EpochDayOfYear + (Int32)UT / KSPDateStructure.SecondsPerDay % KSPDateStructure.DaysPerYear;
34+
return KSPDateStructure.EpochDayOfYear + (Int32)(UT / KSPDateStructure.SecondsPerDay % KSPDateStructure.DaysPerYear);
3535
}
3636
}
3737

@@ -184,7 +184,7 @@ public KSPDateTime(int year, int day, int hour, int minute, int second, int mill
184184
{
185185
//Test for entering values outside the norm - eg 25 hours, day 600
186186

187-
UT = new KSPTimeSpan((year - KSPDateStructure.EpochYear) * KSPDateStructure.DaysPerYear +
187+
UT = new KSPTimeSpan((Int32)((year - KSPDateStructure.EpochYear) * KSPDateStructure.DaysPerYear) +
188188
(day - KSPDateStructure.EpochDayOfYear),
189189
hour,
190190
minute,
@@ -247,39 +247,54 @@ private enum AMPMEnum {
247247
AM,PM,OddHoursPerDay
248248
}
249249

250-
/// <summary>Generates some standard Templated versions of output</summary>
251-
/// <param name="DateFormat">Enum of some common formats</param>
252-
/// <returns>A string that represents the value of this instance.</returns>
253-
public String ToStringStandard(DateStringFormatsEnum DateFormat){
254-
switch (DateFormat)
255-
{
256-
case DateStringFormatsEnum.TimeAsUT:
257-
String strReturn = "";
258-
if (UT < 0) strReturn += "+ ";
259-
strReturn += String.Format("{0:N0}s", Math.Abs(UT));
260-
return strReturn;
261-
case DateStringFormatsEnum.KSPFormat:
262-
return ToString();
263-
case DateStringFormatsEnum.KSPFormatWithSecs:
264-
return ToString("Year y, Da\\y d - H\\h, m\\m, s\\s");
265-
case DateStringFormatsEnum.DateTimeFormat:
266-
if (KSPDateStructure.CalendarType==CalendarTypeEnum.Earth)
250+
/// <summary>Generates some standard Templated versions of output</summary>
251+
/// <param name="DateFormat">Enum of some common formats</param>
252+
/// <returns>A string that represents the value of this instance.</returns>
253+
public String ToStringStandard(DateStringFormatsEnum DateFormat)
254+
{
255+
switch (DateFormat)
256+
{
257+
case DateStringFormatsEnum.TimeAsUT:
258+
return (UT < 0 ? "+ " : "") + String.Format("{0:N0}s", Math.Abs(UT));
259+
case DateStringFormatsEnum.KSPFormat:
260+
return ToString();
261+
case DateStringFormatsEnum.KSPFormatWithSecs:
262+
if (KSPDateStructure.UseStockDateFormatters)
263+
{
264+
return KSPUtil.dateTimeFormatter.PrintDate(UT, true, true);
265+
}
266+
return ToString("Year y, Da\\y d - H\\h, m\\m, s\\s");
267+
case DateStringFormatsEnum.DateTimeFormat:
268+
if (KSPDateStructure.CalendarType == CalendarTypeEnum.Earth)
269+
{
267270
return ToString("d MMM yyyy, HH:mm:ss");
271+
}
268272
else
269-
return ToString("Year y, Da\\y d, HH:mm:ss");
270-
default:
271-
return ToString();
272-
}
273-
}
273+
{
274+
if (KSPDateStructure.UseStockDateFormatters)
275+
{
274276

275-
/// <summary>Returns the string representation of the value of this instance.</summary>
276-
/// <returns>A string that represents the value of this instance.</returns>
277-
public override String ToString()
277+
return KSPUtil.dateTimeFormatter.PrintDateNew(UT, true);
278+
}
279+
return ToString("Year y, Da\\y d, HH:mm:ss");
280+
}
281+
default:
282+
return ToString();
283+
}
284+
}
285+
286+
/// <summary>Returns the string representation of the value of this instance.</summary>
287+
/// <returns>A string that represents the value of this instance.</returns>
288+
public override String ToString()
278289
{
279290
if (CalType ==CalendarTypeEnum.Earth) {
280291
return ToString(System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern);
281292
} else {
282-
return ToString("Year y, Da\\y d - H\\h, m\\m", null);
293+
if (KSPDateStructure.UseStockDateFormatters)
294+
{
295+
return KSPUtil.dateTimeFormatter.PrintDate(UT, true, false);
296+
}
297+
return ToString("Year y, Da\\y d - H\\h, m\\m", null);
283298
}
284299
}
285300
/// <summary>Returns the string representation of the value of this instance.</summary>

0 commit comments

Comments
 (0)