Skip to content

Commit

Permalink
Automatic merge of T1.5.1-794-g4cad06780 and 14 pull requests
Browse files Browse the repository at this point in the history
- Pull request #570 at 3539862: Experimental glTF 2.0 support with PBR lighting
- Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters
- Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder
- Pull request #882 at a055bca: Blueprint/train car operations UI window
- Pull request #885 at 8f94333: feat: Add notifications to Menu
- Pull request #886 at 6c0785b: Scene viewer extension to TrackViewer
- Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH
- Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains
- Pull request #897 at 0a9d939: feat: Improved system information collection
- Pull request #899 at 2985bc1: Duplex steam engines - Booster Engine addition
- Pull request #903 at 7353625: Downloading route content (Github, zip)
- Pull request #906 at 5850660: Bug fix for https://bugs.launchpad.net/or/+bug/2047299 Crash loading a 3Dcab-only loco
- Pull request #907 at 9b0b04f: Bug fix for https://bugs.launchpad.net/or/+bug/2047300 Dynamic tracks disappear after long tunnel
- Pull request #908 at 4b4afe3: feat: supports switching adhesion precisions
  • Loading branch information
openrails-bot committed Jan 1, 2024
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 69 deletions.
180 changes: 144 additions & 36 deletions Source/Menu/MainForm.cs
Expand Up @@ -32,6 +32,7 @@
using System.Resources;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static ORTS.Notification;
using Path = ORTS.Menu.Path;
Expand Down Expand Up @@ -307,30 +308,49 @@ void MainForm_FormClosing(object sender, FormClosingEventArgs e)
File.Delete(file);
}

//void CheckForUpdate()
//{
// // This is known directly from the chosen channel so doesn't need to wait for the update check itself.
// linkLabelChangeLog.Visible = !string.IsNullOrEmpty(UpdateManager.ChangeLogLink);

// new Task<UpdateManager>(this, () =>
// {
// UpdateManager.Check();
// return null;
// }, _ =>
// {
// if (UpdateManager.LastCheckError != null)
// linkLabelUpdate.Text = catalog.GetString("Update check failed");
//else if (UpdateManager.LastUpdate != null && UpdateManager.LastUpdate.Version != VersionInfo.Version)
// linkLabelUpdate.Text = catalog.GetStringFmt("Update to {0}", UpdateManager.LastUpdate.Version);
//else
// linkLabelUpdate.Text = "";
//linkLabelUpdate.Enabled = true;
//linkLabelUpdate.Visible = linkLabelUpdate.Text.Length > 0;
//// Update link's elevation icon and size/position.
//if (UpdateManager.LastCheckError == null && UpdateManager.LastUpdate != null && UpdateManager.LastUpdate.Version != VersionInfo.Version && UpdateManager.UpdaterNeedsElevation)
// linkLabelUpdate.Image = ElevationIcon;
//else
// linkLabelUpdate.Image = null;
// });
//}
void CheckForUpdate()
{
// This is known directly from the chosen channel so doesn't need to wait for the update check itself.
linkLabelChangeLog.Visible = !string.IsNullOrEmpty(UpdateManager.ChangeLogLink);

new Task<UpdateManager>(this, () =>
{
UpdateManager.Check();
return null;
}, _ =>
{
if (UpdateManager.LastCheckError != null)
{
linkLabelUpdate.Text = catalog.GetString("Update check failed");
else if (UpdateManager.LastUpdate != null && UpdateManager.LastUpdate.Version != VersionInfo.Version)
linkLabelUpdate.Text = catalog.GetStringFmt("Update to {0}", UpdateManager.LastUpdate.Version);
else
linkLabelUpdate.Text = "";
linkLabelUpdate.Enabled = true;
linkLabelUpdate.Visible = linkLabelUpdate.Text.Length > 0;
// Update link's elevation icon and size/position.
if (UpdateManager.LastCheckError == null && UpdateManager.LastUpdate != null && UpdateManager.LastUpdate.Version != VersionInfo.Version && UpdateManager.UpdaterNeedsElevation)
linkLabelUpdate.Image = ElevationIcon;
else
linkLabelUpdate.Image = null;
linkLabelChangeLog.Visible = true;
}
if (UpdateManager.LastUpdate != null)
{
SetUpdateNotification();
}
});
}

Expand Down Expand Up @@ -1479,6 +1499,9 @@ void comboBoxTimetable_EnabledChanged(object sender, EventArgs e)
// Will probably move this region and the Details region into separate files.

bool AreNotificationsVisible = false;
// New notifications are those with a date after the NotificationsReadDate.
// Notifications are listed in reverse date order, with the newest one at the front.
// We don't track the reading of each notification but set the NewNotificationCount = 0 after the last of the new ones has been read.
int NewNotificationCount = 1;
int LastNotificationViewed = 0;

Expand All @@ -1501,19 +1524,25 @@ private void ToggleNotifications()
{
if (AreNotificationsVisible == false)
{
AreNotificationsVisible = true; // Set before calling ShowNotifcations()
ShowNotifications();
FiddleNewNotificationCount();
}
else
{
AreNotificationsVisible = false;
ShowDetails();
}
AreNotificationsVisible = !AreNotificationsVisible;
}

private void FiddleNewNotificationCount()
{
LastNotificationViewed = 1;
UpdateNotificationAlert();
}

private void UpdateNotificationAlert()
{
if (LastNotificationViewed >= NewNotificationCount)
{
pbNotificationsSome.Visible = false;
Expand All @@ -1534,30 +1563,52 @@ void ShowNotifications()
/// <summary>
/// Populate the Notifications list
/// </summary>
//private void PopulateNotificationList()
//{
//NotificationList.Clear();
//if (NotificationList.Count == 0)
//{
// var newNotification = new Notification();
// NotificationList.Add(newNotification);
//new NHeadingControl(panelDetails, "This is a dummy notification", Color.OrangeRed).Add(newNotification);
//new NTitleControl(panelDetails, DateTime.Now, "Update is available").Add(newNotification);
//new NRecordControl(panelDetails, "Update mode", 140, "Stable").Add(newNotification);
//new NRecordControl(panelDetails, "Installed version", 140, "1.3.1").Add(newNotification);
//new NRecordControl(panelDetails, "New version available", 140, "1.4").Add(newNotification);
//new NButtonControl(panelDetails, "What's new", 90, "Find out on-line what's new in this version.").Add(newNotification);
//new NButtonControl(panelDetails, "Install", 90, "Install the new version.").Add(newNotification);
//new NHeadingControl(panelDetails, "Warning", Color.OrangeRed).Add(newNotification);
//new NTextControl(panelDetails, "The update from your current version may affect the behaviour of some of your content.").Add(newNotification);
//new NButtonControl(panelDetails, "Issue details", 90, "More details about this issue are available on-line.").Add(newNotification);

//new NTitleControl(panelDetails, new DateTime(2024, 8, 31, 0, 0, 0), "Update is available").Add(newNotification);
//new NRecordControl(panelDetails, "Update mode", 140, "Stable").Add(newNotification);
//new NRecordControl(panelDetails, "Installed version", 140, "1.6").Add(newNotification);
//new NRecordControl(panelDetails, "New version available", 140, "1.7").Add(newNotification);
//new NButtonControl(panelDetails, "What's new", 90, "Find out on-line what's new in this version.").Add(newNotification);
//new NHeadingControl(panelDetails, "Install Not Available", Color.OrangeRed).Add(newNotification);
//new NTextControl(panelDetails, "V1.7 cannot be installed on your system until the graphics card is upgraded.").Add(newNotification);
//new NButtonControl(panelDetails, "Graphics card", 90, "Find out on-line about graphics hardware needed.").Add(newNotification);
//new NHeadingControl(panelDetails, "More Realism", Color.Blue).Add(newNotification);
//new NTextControl(panelDetails, "This update supports graphics which are significantly more realistic.").Add(newNotification);
//new NButtonControl(panelDetails, "Enhancement", 90, "More details about this enhancement are available on-line.").Add(newNotification);

//}
//else
//{
//}
//var notification = NotificationList.LastOrDefault();
//new NTextControl(panelDetails, "").Add(notification);
//new NTextControl(panelDetails, "(Toggle icon to hide notifications.)").Add(notification);
//}

private void PopulateNotificationList()
{
NotificationList.Clear();
if (NotificationList.Count == 0)
{
var newNotification = new Notification();
NotificationList.Add(newNotification);
new NHeadingControl(panelDetails, "This is a dummy notification", Color.OrangeRed).Add(newNotification);
new NTitleControl(panelDetails, DateTime.Now, "Update is available").Add(newNotification);
new NRecordControl(panelDetails, "Update mode", 140, "Stable").Add(newNotification);
new NRecordControl(panelDetails, "Installed version", 140, "1.3.1").Add(newNotification);
new NRecordControl(panelDetails, "New version available", 140, "1.4").Add(newNotification);
new NButtonControl(panelDetails, "What's new", 90, "Find out on-line what's new in this version.").Add(newNotification);
new NButtonControl(panelDetails, "Install", 90, "Install the new version.").Add(newNotification);
new NHeadingControl(panelDetails, "Warning", Color.OrangeRed).Add(newNotification);
new NTextControl(panelDetails, "The update from your current version may affect the behaviour of some of your content.").Add(newNotification);
new NButtonControl(panelDetails, "Issue details", 90, "More details about this issue are available on-line.").Add(newNotification);
}
else
{
}
SetUpdateNotification();

var notification = NotificationList.LastOrDefault();
new NTextControl(panelDetails, "").Add(notification);
new NTextControl(panelDetails, "(Toggle icon to hide notifications.)").Add(notification);
new NTextControl(notification, "").Add();
new NTextControl(notification, "(Toggle icon to hide notifications.)").Add();
}

/// <summary>
Expand All @@ -1569,6 +1620,63 @@ Notification GetCurrentNotification()
return NotificationList[0];
}

/// <summary>
/// Ultimately there will be a list of notifications downloaded for openrails/content.
/// Until then, there is a single notification announcing either that a new update is available or the installation is up to date.
/// </summary>
void SetUpdateNotification()
{
NewNotificationCount = (IsUpdateAvailable()) ? 1 : 0;
UpdateNotificationAlert();
NotificationList.Clear();
var newNotification = new Notification(panelDetails);
if (IsUpdateAvailable())
{
NewNotificationCount = 1;
if (AreNotificationsVisible)
{
new NTitleControl(newNotification, UpdateManager.LastUpdate.Date, "Update is available").Add();
new NRecordControl(newNotification, "Update mode", 140, UpdateManager.ChannelName).Add();
new NRecordControl(newNotification, "Installed version", 140, VersionInfo.VersionOrBuild).Add();
new NRecordControl(newNotification, "New version available", 140, UpdateManager.LastUpdate.Version).Add();
new NLinkControl(newNotification, "What's new", 90, "Find out on-line what's new in this version.", this, UpdateManager.ChangeLogLink).Add();
new NUpdateControl(newNotification, "Install", 90, "Install the new version.", this).Add();
}
}
else
{
NewNotificationCount = 0;
if (AreNotificationsVisible)
{
var channelName = UpdateManager.ChannelName == "" ? "None" : UpdateManager.ChannelName;
new NTitleControl(newNotification, DateTime.Now, "Installation is up to date").Add();
new NRecordControl(newNotification, "Update mode", 140, channelName).Add();
new NRecordControl(newNotification, "Installed version", 140, VersionInfo.VersionOrBuild).Add();
new NRecordControl(newNotification, "New version available", 140, "none").Add();
}
}
NotificationList.Add(newNotification);
}

bool IsUpdateAvailable()
{
return UpdateManager.LastUpdate != null
&& UpdateManager.LastUpdate.Version != VersionInfo.Version;
}

// 3 should be enough, but is there a way to get unlimited buttons?
public void Button0_Click(object sender, EventArgs e)
{
GetCurrentNotification().DoButton(UpdateManager, 0);
}
public void Button1_Click(object sender, EventArgs e)
{
GetCurrentNotification().DoButton(UpdateManager, 1);
}
public void Button2_Click(object sender, EventArgs e)
{
GetCurrentNotification().DoButton(UpdateManager, 2);
}
#endregion Notifications
}
}

0 comments on commit e6ddd3d

Please sign in to comment.