Skip to content

Commit

Permalink
Adds Notification class with NDetail elements shown in the panel
Browse files Browse the repository at this point in the history
  • Loading branch information
cjakeman committed Dec 29, 2023
1 parent f70d0aa commit 06b8a9e
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 14 deletions.
49 changes: 36 additions & 13 deletions Source/Menu/MainForm.cs
Expand Up @@ -33,6 +33,7 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using static ORTS.Notification;
using Path = ORTS.Menu.Path;

namespace ORTS
Expand Down Expand Up @@ -1171,7 +1172,7 @@ private void AddDetails()
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
private string[] HideStartParameters(string [] info)
private string[] HideStartParameters(string[] info)
{
var fullStartTime = info[0].TrimStart();
var startTimeArray = fullStartTime.Split('$');
Expand Down Expand Up @@ -1352,7 +1353,7 @@ void SelectComboBoxItem<T>(ComboBox comboBox, Func<T, bool> predicate)
var index = (int)UserSettings.Menu_SelectionIndex.Activity;
for (var i = 0; i < comboBox.Items.Count; i++)
{
if (comboBox.Items[i] is T && predicate((T)comboBox.Items[i]) || (Settings.Menu_Selection.Length > i && comboBox.Items[i].ToString() == Settings.Menu_Selection[index] ))
if (comboBox.Items[i] is T && predicate((T)comboBox.Items[i]) || (Settings.Menu_Selection.Length > i && comboBox.Items[i].ToString() == Settings.Menu_Selection[index]))
{
comboBox.SelectedIndex = i;
return;
Expand Down Expand Up @@ -1474,9 +1475,6 @@ void comboBoxTimetable_EnabledChanged(object sender, EventArgs e)
int LastNotificationViewed = 0;

List<Notification> NotificationList = new List<Notification>();
class Notification
{
}

private void pbNotificationsNone_Click(object sender, EventArgs e)
{
Expand Down Expand Up @@ -1519,23 +1517,48 @@ void ShowNotifications()
{
Win32.LockWindowUpdate(Handle);
ClearPanel();
AddNotifications();
FlowDetails();
PopulateNotificationList();
var notification = GetCurrentNotification();
notification.FlowNDetails();
Win32.LockWindowUpdate(IntPtr.Zero);
}

private void AddNotifications()
/// <summary>
/// Populate the Notifications list
/// </summary>
private void PopulateNotificationList()
{
//if (NotificationList.Count == 0)
if (NotificationList.Count != 0)
NotificationList.Clear();
if (NotificationList.Count == 0)
{
AddDetail("Notifications", new string[] { "No notifications are available." });
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
{
AddDetail("Notification 1", new string[] { "This is a dummy notification." });
}
AddDetail("", new string[] { "Toggle icon to hide notifications." });
var notification = NotificationList.LastOrDefault();
new NTextControl(panelDetails, "").Add(notification);
new NTextControl(panelDetails, "(Toggle icon to hide notifications.)").Add(notification);
}

/// <summary>
/// INCOMPLETE
/// </summary>
/// <returns></returns>
Notification GetCurrentNotification()
{
return NotificationList[0];
}

#endregion Notifications
Expand Down
2 changes: 1 addition & 1 deletion Source/Menu/MainForm.resx
Expand Up @@ -130,7 +130,7 @@
<data name="pbNotificationsNone.InitialImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAACUAAAAfCAYAAABgfwTIAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
vQAADr0BR/uQrQAABk5JREFUWEfNmHlMVFcUxkdttdVWW621VYtaWtQqxlptG+JaG1Nj05j+0dQ0jYnV
vAAADrwBlbxySQAABk5JREFUWEfNmHlMVFcUxkdttdVWW621VYtaWtQqxlptG+JaG1Nj05j+0dQ0jYnV
NjGBGJeCOgouDSCDsrYqVFka6xJEkGU0ERgXGiCoKApI1SCKCMMMw5KBWd7p903mmbFOiLZCvMkv793l
3fvdc5c5ZzQi8hJ4B8wD34LvwFLwBZgPPnIzFfgBXzAe+IBxYBR4DQwG00EA+AAMB0P5dDY1Te6Mjl7c
qdOJefFiMfr5iXHSJDEvWiQoa7EVF4cqZvPnaPsuGERR7JDCXgWjwRjwpgccmEIoaArgwMxTFL8hats3
Expand Down
206 changes: 206 additions & 0 deletions Source/Menu/Notification.cs
@@ -0,0 +1,206 @@
// COPYRIGHT 2009, 2010, 2011, 2012, 2013, 2014, 2015 by the Open Rails project.
//
// This file is part of Open Rails.
//
// Open Rails is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Open Rails is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Open Rails. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ORTS
{
public class Notification
{
public List<NDetail> NDetailList = new List<NDetail>();

public class NDetail
{
public static readonly int TopPadding = 20;
public static readonly int VerticalSpacing = 10;
public static readonly int LeftPadding = 10;
public static readonly int LeftPaddingIndented = 20;
public static readonly int TitleHeight = 20;
public static readonly int HeadingHeight = 30;
public static readonly int TextHeight = 18;
public static readonly int ButtonHeight = 30;
public static readonly int RecordHeight = 15;
public const int ScrollBarWidth = 20;

public Label Control;

public void Add(Notification notification)
{
notification.NDetailList.Add(this);
}
}

/// <summary>
/// Title for the notification
/// </summary>
public class NTitleControl : NDetail
{
public NTitleControl(Panel panelDetails, DateTime date, string text)
{
var title = $"Notification 1/1: {date:dd-MMM-yyyy} - {text}";
var left = LeftPadding;
Control = new Label
{
Text = title,
UseMnemonic = false,
Font = new Font(panelDetails.Font, FontStyle.Bold),
TextAlign = ContentAlignment.BottomLeft,
Height = TitleHeight,
Width = panelDetails.Width - ScrollBarWidth - left,
Left = LeftPadding
};
panelDetails.Controls.Add(Control);
}
}
public class NHeadingControl : NDetail
{
public NHeadingControl(Panel panelDetails, string text, Color color = default)
{
var left = LeftPadding;
Control = new Label
{
ForeColor = color,
Text = text,
UseMnemonic = false,
Font = new Font(panelDetails.Font, FontStyle.Bold),
TextAlign = ContentAlignment.BottomLeft,
Height = HeadingHeight,
Width = panelDetails.Width - ScrollBarWidth - left,
Left = left,
Top = TopPadding,
};
panelDetails.Controls.Add(Control);
}
}
public class NTextControl : NDetail
{
public NTextControl(Panel panelDetails, string text)
{
var left = LeftPaddingIndented;
Control = new Label
{
Text = text,
UseMnemonic = false,
Font = new Font(panelDetails.Font, FontStyle.Regular),
TextAlign = ContentAlignment.BottomLeft,
Height = TextHeight,
Width = panelDetails.Width - ScrollBarWidth - left,
Left = left,
};
panelDetails.Controls.Add(Control);
}
}
public class NButtonControl : NDetail
{
public Button Button;
public NButtonControl(Panel panelDetails, string legend, int width, string description)
{
var buttonLeft = LeftPaddingIndented;
Button = new Button
{
Margin = new Padding(20),
Text = legend,
UseMnemonic = false,
Font = new Font(panelDetails.Font, FontStyle.Regular),
TextAlign = ContentAlignment.MiddleCenter,
Height = ButtonHeight,
Width = width,
Left = buttonLeft,
Top = TopPadding,
BackColor = SystemColors.ButtonFace
};
panelDetails.Controls.Add(Button);

var labelLeft = Button.Left + Button.Width + LeftPaddingIndented;
Control = new Label
{
Margin = new Padding(20),
Text = description,
UseMnemonic = false,
Font = new Font(panelDetails.Font, FontStyle.Regular),
TextAlign = ContentAlignment.MiddleLeft,
Height = ButtonHeight,
Width = panelDetails.Width - ScrollBarWidth - labelLeft,
Top = TopPadding,
Left = labelLeft
};
panelDetails.Controls.Add(Control);
}
}
public class NRecordControl : NDetail
{
public Label Field;
public NRecordControl(Panel panelDetails, string label, int width, string field)
{
Control = new Label
{
Text = label + ":",
UseMnemonic = false,
Font = new Font(panelDetails.Font, FontStyle.Bold),
TextAlign = ContentAlignment.BottomRight,
Width = width,
Height = RecordHeight,
Left = LeftPadding,
Top = TopPadding
};
panelDetails.Controls.Add(Control);

var left = width + LeftPadding;
Field = new Label
{
Text = field,
UseMnemonic = false,
Font = new Font(panelDetails.Font, FontStyle.Regular),
TextAlign = ContentAlignment.BottomLeft,
Width = panelDetails.Width - ScrollBarWidth - left,
Height = RecordHeight,
Left = left,
Top = TopPadding
};
panelDetails.Controls.Add(Field);
}
}

public void FlowNDetails()
{
var top = 2;
foreach (var nDetail in NDetailList)
{
nDetail.Control.Top = top;

// Adjust details that have a second part.
if (nDetail is NButtonControl)
{
((NButtonControl)nDetail).Button.Top = top;
}
if (nDetail is NRecordControl)
{
((NRecordControl)nDetail).Field.Top = top;
}

top += nDetail.Control.Height + NDetail.VerticalSpacing;
}
}
}

}

0 comments on commit 06b8a9e

Please sign in to comment.