Skip to content

Commit 4fce9f7

Browse files
committed
Automatic merge of T1.5.1-1083-g7ca36e39f1 and 20 pull requests
- Pull request #891 at 9a1d6b2: Auto save - Pull request #959 at 2452cb0: Fix TrackViewer crash on big zoom value - Pull request #969 at 9d53199: Bugfix refocus to the main window when opening the map window - 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 #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 6426c6f: 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
22 parents 87a1efd + 7ca36e3 + 9a1d6b2 + 2452cb0 + 9d53199 + d00beb9 + 8f695a4 + 1f5ba4c + a3bc9e7 + a519452 + 46d0472 + 6fa5eed + c27f32d + 9dabe97 + dfc715e + f92de76 + 6426c6f + 5866028 + 91a03af + 8347095 + f837ffd + a88cb26 commit 4fce9f7

File tree

10 files changed

+262
-59
lines changed

10 files changed

+262
-59
lines changed

Source/Menu/MainForm.Designer.cs

Lines changed: 28 additions & 28 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: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,13 @@ void comboBoxTimetable_EnabledChanged(object sender, EventArgs e)
15691569
}
15701570

15711571
#region NotificationPages
1572+
public int CurrentNotificationNo = 0;
1573+
private bool firstVisible = true;
1574+
private bool previousVisible = false;
1575+
private bool lastVisible = false;
1576+
private bool nextVisible = true;
1577+
1578+
15721579
private void pbNotificationsNone_Click(object sender, EventArgs e)
15731580
{
15741581
ToggleNotificationPages();
@@ -1599,7 +1606,7 @@ private void ToggleNotificationPages()
15991606

16001607
private void FiddleNewNotificationPageCount()
16011608
{
1602-
NotificationManager.LastPageViewed = 1;
1609+
//NotificationManager.LastPageViewed = 1;
16031610
UpdateNotificationPageAlert();
16041611
}
16051612

@@ -1616,7 +1623,7 @@ void ShowNotificationPages()
16161623
{
16171624
Win32.LockWindowUpdate(Handle);
16181625
ClearPanel();
1619-
NotificationManager.PopulatePageList();
1626+
NotificationManager.PopulatePage();
16201627
var notificationPage = GetCurrentNotificationPage();
16211628
notificationPage.FlowNDetails();
16221629
Win32.LockWindowUpdate(IntPtr.Zero);
@@ -1628,12 +1635,23 @@ void ShowNotificationPages()
16281635
/// <returns></returns>
16291636
NotificationPage GetCurrentNotificationPage()
16301637
{
1631-
return NotificationManager.PageList[0];
1638+
return NotificationManager.Page;
16321639
}
16331640

1634-
public NotificationPage CreateNotificationPage(Notifications notifications)
1641+
/// <summary>
1642+
/// Returns a new notificationPage with default images and label
1643+
/// </summary>
1644+
/// <returns></returns>
1645+
public NotificationPage CreateNotificationPage()
1646+
// Located in MainForm to get access to MainForm.Resources
16351647
{
1636-
return new NotificationPage(this, panelDetails);
1648+
var previousImage = (Image)Resources.GetObject("Notification_previous");
1649+
var nextImage = (Image)Resources.GetObject("Notification_next");
1650+
var firstImage = (Image)Resources.GetObject("Notification_first");
1651+
var lastImage = (Image)Resources.GetObject("Notification_last");
1652+
var pageCount = $"{CurrentNotificationNo + 1}/{NotificationManager.Notifications.NotificationList.Count}";
1653+
return new NotificationPage(this, panelDetails, nextImage, previousImage, firstImage, lastImage, pageCount,
1654+
previousVisible, firstVisible, nextVisible, lastVisible);
16371655
}
16381656

16391657
// 3 should be enough, but is there a way to get unlimited buttons?
@@ -1650,6 +1668,51 @@ public void Button2_Click(object sender, EventArgs e)
16501668
GetCurrentNotificationPage().DoButton(UpdateManager, 2);
16511669
}
16521670

1671+
public void Next_Click(object sender, EventArgs e)
1672+
{
1673+
ChangePage(1);
1674+
// GetCurrentNotificationPage().DoNext(1);
1675+
}
1676+
1677+
public void Previous_Click(object sender, EventArgs e)
1678+
{
1679+
ChangePage(-1);
1680+
//GetCurrentNotificationPage().DoNext(-1);
1681+
}
1682+
1683+
private void ChangePage(int step)
1684+
{
1685+
SetVisibility(step);
1686+
CurrentNotificationNo += step;
1687+
ShowNotificationPages();
1688+
}
1689+
1690+
private void SetVisibility(int step)
1691+
{
1692+
if (step < 0)
1693+
{
1694+
if (CurrentNotificationNo + step <= 0)
1695+
{
1696+
previousVisible = false;
1697+
firstVisible = true;
1698+
return;
1699+
}
1700+
}
1701+
else
1702+
{
1703+
if (CurrentNotificationNo + step >= NotificationManager.Notifications.NotificationList.Count - 1)
1704+
{
1705+
nextVisible = false;
1706+
lastVisible = true;
1707+
return;
1708+
}
1709+
}
1710+
nextVisible = true;
1711+
lastVisible = false;
1712+
previousVisible = true;
1713+
firstVisible = false;
1714+
}
1715+
16531716
#endregion NotificationPages
16541717
}
16551718
}

Source/Menu/Notifications/NotificationManager.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
//TODO Add caching of criteria
3535
//TODO Add "includeIf" for individual notifications
3636

37+
// Notifications are read only once as a background task at start into NotificationList.
38+
// Every time the notifications page is re-visited, the options may have changed, so
39+
// the visibility of each notification in NotificationList is re-assessed. Also its date.
40+
// A SortedPageList is created which contains a list of indexes for the notifications to be shown sorted as latest first.
41+
// Every time the notifications page is re-visited or the page is incremented up or down,
42+
// the current notification is re-assessed and
43+
// the panel is re-loaded with Controls for the current page.
44+
3745
namespace ORTS
3846
{
3947
class NotificationManager
@@ -44,17 +52,18 @@ class NotificationManager
4452
// We don't track the reading of each notification but set the NewNotificationCount = 0 after the last of the new ones has been read.
4553
public int NewPageCount = 1;
4654
public int LastPageViewed = 0;
47-
public int Index = 0;
55+
//public int Index = 0;
4856

4957
public Notifications Notifications;
50-
public List<NotificationPage> PageList = new List<NotificationPage>();
5158
private Exception Error;
5259
private Dictionary<string, string> ParameterDictionary;
5360

5461
private readonly MainForm MainForm; // Needed so we can add controls to the NotificationPage
5562
private readonly UpdateManager UpdateManager;
5663
private readonly UserSettings Settings;
5764

65+
public NotificationPage Page { get; private set; }
66+
5867
public NotificationManager(MainForm mainForm, UpdateManager updateManager, UserSettings settings)
5968
{
6069
MainForm = mainForm;
@@ -78,7 +87,7 @@ public void CheckNotifications()
7887
ReplaceParameters();
7988
LogParameters();
8089

81-
PopulatePageList();
90+
PopulatePage();
8291
ArePagesVisible = false;
8392
}
8493
catch (WebException ex)
@@ -135,24 +144,22 @@ private string GetRemoteJson()
135144
return client.DownloadString(new Uri("https://wepp.co.uk/openrails/notifications2/menu.json"));
136145
}
137146

138-
public void PopulatePageList()
147+
public void PopulatePage()
139148
{
140-
SetUpdateNotificationPage();
141-
142-
var NotificationPage = PageList.LastOrDefault();
143-
new NTextControl(NotificationPage, "").Add();
144-
new NTextControl(NotificationPage, "(Toggle icon to hide these notifications.)").Add();
149+
Page = UpdateNotificationPage();
150+
new NTextControl(Page, "").Add();
151+
new NTextControl(Page, "(Toggle icon to hide these notifications.)").Add();
145152
}
146153

147154
/// <summary>
148155
/// Ultimately there will be a list of notifications downloaded from https://static.openrails.org/api/notifications/menu.json .
149156
/// Until then, there is a single notification announcing either that a new update is available or the installation is up to date.
150157
/// </summary>
151-
private void SetUpdateNotificationPage()
158+
private NotificationPage UpdateNotificationPage()
152159
{
160+
var page = MainForm.CreateNotificationPage();
161+
153162
MainForm.UpdateNotificationPageAlert();
154-
PageList.Clear();
155-
var page = MainForm.CreateNotificationPage(Notifications);
156163

157164
if (UpdateManager.LastCheckError != null || Error != null)
158165
{
@@ -173,24 +180,23 @@ private void SetUpdateNotificationPage()
173180
new NTextControl(page, "Is your Internet connected?").Add();
174181

175182
new NRetryControl(page, "Retry", 140, "Try again to fetch notifications", MainForm).Add();
176-
PageList.Add(page);
177-
return;
178183
}
179184

180185
NewPageCount = 1;
181186
var list = Notifications.NotificationList;
182-
var n = list[Index];
187+
var n = list[MainForm.CurrentNotificationNo];
183188
LogNotification(n);
184189

185-
var skipPage = false;
186-
new NTitleControl(page, Index + 1, list.Count, n.Date, n.Title).Add();
190+
//var skipPage = false;
191+
new NTitleControl(page, MainForm.CurrentNotificationNo + 1, list.Count, n.Date, n.Title).Add();
187192

188193
// Check constraints for each item
189-
foreach(var item in n.ItemList)
194+
foreach (var item in n.ItemList)
190195
{
191196
if (AreChecksMet(item)) AddItemToPage(page, item);
192197
}
193-
if (skipPage == false) PageList.Add(page);
198+
199+
return page;
194200
}
195201

196202
#region Process Criteria
@@ -337,9 +343,6 @@ public void ReplaceParameters()
337343
{
338344
n.Title = ReplaceParameter(n.Title);
339345
n.Date = ReplaceParameter(n.Date);
340-
//n.PrefixItemList?.ForEach(item => ReplaceItemParameter(item));
341-
//n.Met.ItemList?.ForEach(item => ReplaceItemParameter(item));
342-
//n.SuffixItemList?.ForEach(item => ReplaceItemParameter(item));
343346
n.ItemList?.ForEach(item => ReplaceItemParameter(item));
344347
}
345348
foreach (var list in Notifications.CheckList)

0 commit comments

Comments
 (0)