Skip to content

Commit cdd9fb3

Browse files
committed
Automatic merge of T1.5.1-1088-g264349b1ce and 21 pull requests
- Pull request #891 at 9a1d6b2: Auto save - Pull request #959 at 2452cb0: Fix TrackViewer crash on big zoom value - Pull request #972 at e90a2aa: On Map window color changed switch or signal is not changed - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #882 at 8f695a4: Blueprint/train car operations UI window - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #922 at a3bc9e7: Autopilot for timetable mode - Pull request #953 at a519452: Fix Lights Crash on Corrupt Shapes - Pull request #962 at 46d0472: Fix pantographs on unpowered cars - Pull request #970 at 6fa5eed: feat: Remove unnecessary Windows.Forms usage - Pull request #973 at c35be87: fix: Using singular target framework to allow for different platforms across different projects - Pull request #900 at c27f32d: DMI updates - Pull request #903 at 9dabe97: Downloading route content (Github, zip) - Pull request #799 at dfc715e: Consolidated wind simulation - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #885 at 067662e: feat: Add notifications to Menu - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #946 at 91a03af: Advanced track sounds - Pull request #952 at 8347095: Investigation - Pulsing graphics - Pull request #954 at f837ffd: Multiple Track Profiles & Superelevation Improvements - Pull request #968 at a88cb26: Initial build of adding track section identifier for rack railway
23 parents e173f64 + 264349b + 9a1d6b2 + 2452cb0 + e90a2aa + d00beb9 + 8f695a4 + 1f5ba4c + a3bc9e7 + a519452 + 46d0472 + 6fa5eed + c35be87 + c27f32d + 9dabe97 + dfc715e + f92de76 + 067662e + 5866028 + 91a03af + 8347095 + f837ffd + a88cb26 commit cdd9fb3

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

Source/Menu/MainForm.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Menu/MainForm.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ void CheckForUpdate()
326326
}, _ =>
327327
{
328328
NotificationManager.CheckNotifications();
329+
UpdateNotificationPageAlert();
329330
});
330331
}
331332

@@ -1594,7 +1595,7 @@ private void ToggleNotificationPages()
15941595
{
15951596
NotificationManager.ArePagesVisible = true; // Set before calling ShowNotifcations()
15961597
ShowNotificationPages();
1597-
FiddleNewNotificationPageCount();
1598+
UpdateNotificationPageAlert();
15981599
}
15991600
else
16001601
{
@@ -1603,12 +1604,6 @@ private void ToggleNotificationPages()
16031604
}
16041605
}
16051606

1606-
private void FiddleNewNotificationPageCount()
1607-
{
1608-
//NotificationManager.LastPageViewed = 1; //TODO
1609-
UpdateNotificationPageAlert();
1610-
}
1611-
16121607
public void ShowNotificationPages()
16131608
{
16141609
Win32.LockWindowUpdate(Handle);
@@ -1621,7 +1616,13 @@ public void ShowNotificationPages()
16211616

16221617
public void UpdateNotificationPageAlert()
16231618
{
1624-
if (NotificationManager.LastPageViewed >= NotificationManager.NewPageCount)
1619+
if (NotificationManager.NewPagesViewed < NotificationManager.NewPageCount)
1620+
{
1621+
pbNotificationsSome.Visible = true;
1622+
lblNotificationCount.Visible = true;
1623+
lblNotificationCount.Text = $"{NotificationManager.NewPageCount - NotificationManager.NewPagesViewed}";
1624+
}
1625+
else
16251626
{
16261627
pbNotificationsSome.Visible = false;
16271628
lblNotificationCount.Visible = false;

Source/Menu/Notifications/NotificationManager.cs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using System.Drawing;
3131
using System.Windows.Forms;
3232
using System.Linq;
33+
using System.Diagnostics;
3334

3435
//TODO indicate number of never read notifications
3536

@@ -45,11 +46,12 @@ namespace ORTS
4546
public class NotificationManager
4647
{
4748
public bool ArePagesVisible = false;
48-
// New notifications are those with a date after the NotificationsReadDate.
49+
4950
// Notifications are listed in reverse date order, with the newest one at the front.
50-
// We don't track the reading of each notification but set the NewNotificationCount = 0 after the last of the new ones has been read.
51-
public int NewPageCount = 1;
52-
public int LastPageViewed = 0;
51+
// We track the reading of each new notification but set the NewPageCount = 0 after the last of the new ones has been read.
52+
public string LastViewDate; // This is the date when notifications were last viewed and is saved in yyyy-MM-dd format as a hidden UserSetting.
53+
public int NewPageCount; // New notifications are those with a date after the LastViewDate.
54+
public int NewPagesViewed; // Viewing always starts at the first, newest notification. The user sees (NewPageCount - NewpagesViewed)
5355

5456
public Notifications Notifications; // An object defined by the JSON schema
5557
public int CurrentNotificationNo = 0;
@@ -140,6 +142,11 @@ public Notifications GetNotifications()
140142
var jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto };
141143
var jsonInput = JsonConvert.DeserializeObject<Notifications>(notificationsSerial, jsonSettings);
142144

145+
NewPageCount = 0;
146+
NewPagesViewed = 0;
147+
LastViewDate = Settings.LastViewNotificationDate;
148+
if (LastViewDate == "") LastViewDate = "2024-01-01"; // Date of this code - i.e. before Notifications went public
149+
143150
//TODO Cache jsonInput
144151

145152
return jsonInput;
@@ -164,12 +171,19 @@ private string GetRemoteJson()
164171

165172
private List<Notification> IncludeValid(List<Notification> list)
166173
{
174+
NewPageCount = 0;
175+
167176
var filteredList = new List<Notification>();
168177
foreach (var n in list)
169178
{
170179
if (AreNotificationChecksMet(n))
171180
{
172-
if (n.Date == "none") n.Date = " none"; // UpdateChannel = "none" found; push this to end of the list
181+
if (n.Date == "none")
182+
n.Date = " none"; // UpdateChannel = "none" found; push this to end of the list
183+
else
184+
{
185+
if (String.Compare(LastViewDate, n.Date) == -1) NewPageCount++;
186+
}
173187
filteredList.Insert(0, n); // Add to head of list to provide a basic pre-sort.
174188
}
175189
}
@@ -186,6 +200,8 @@ private List<Notification> SortByDate(List<Notification> list)
186200
/// </summary>
187201
public void PopulatePage()
188202
{
203+
Settings.LastViewNotificationDate = $"{DateTime.Today:yyyy-MM-dd}";
204+
Settings.Save("LastViewNotificationDate"); // Saves the date on any viewing of notifications
189205
Page = new NotificationPage(MainForm, Panel, this);
190206

191207
if (UpdateManager.LastCheckError != null || Error != null)
@@ -209,7 +225,6 @@ public void PopulatePage()
209225
Page.NDetailList.Add(new NRetryControl(Page, "Retry", 140, "Try again to fetch notifications", MainForm));
210226
}
211227

212-
NewPageCount = 1;
213228
var list = Notifications.NotificationList;
214229
var n = list[CurrentNotificationNo];
215230
LogNotification(n);
@@ -590,7 +605,12 @@ public OverrideParameterList GetOverrideParameters()
590605
public void ChangePage(int step)
591606
{
592607
CurrentNotificationNo += step;
593-
//SetVisibility(step);
608+
if (step > 0
609+
&& CurrentNotificationNo > NewPagesViewed // and this is a new unviewed page
610+
&& CurrentNotificationNo <= NewPageCount) // and there are still new unviewed pages to be viewed
611+
{
612+
NewPagesViewed++;
613+
}
594614
MainForm.ShowNotificationPages();
595615
}
596616

Source/ORTS.Settings/UserSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ public enum DirectXFeature
210210
public int AntiAliasing { get; set; }
211211

212212
// Simulation settings:
213-
214213
[Default(false)]
215214
public bool SimpleControlPhysics { get; set; }
216215
[Default(true)]
@@ -259,7 +258,6 @@ public enum DirectXFeature
259258
[Default(false)]
260259
public bool DataLogStationStops { get; set; }
261260

262-
263261
// Timetable settings:
264262
[Default(true)]
265263
public bool TTUseRestartDelays { get; set; }
@@ -416,6 +414,8 @@ public string DirectXFeatureLevel
416414
public int[] WindowPosition_ComposeMessage { get; set; }
417415
[Default(new[] { 100, 0 })]
418416
public int[] WindowPosition_TrainList { get; set; }
417+
[Default("")]
418+
public string LastViewNotificationDate { get; set; }
419419

420420
// Menu-game communication settings:
421421
[Default(false)]

0 commit comments

Comments
 (0)