Skip to content

Commit ee8cffc

Browse files
committed
Automatic merge of T1.5.1-1680-g0cd8cb893 and 14 pull requests
- Pull request #900 at b54024b: DMI in 3D cab + two more dials - Pull request #1030 at d3ae4a2: Refactor settings, in prep for settings exporter - Pull request #1045 at cc4d53c: Bugfix: Empty Start Time for Explore, and other issues loading from Menu Selection and Content Routes - Pull request #1052 at 382ea6d: Content Manager: Add axle count, and lowest derail force - Pull request #1057 at cf3caa0: Switchable brake system - Pull request #1062 at 3b18c48: Train Forces popup Window. - Pull request #1064 at 53dd604: Add Train Info tab to Help window (F1) - Pull request #1066 at 62c89c1: Log derailment, using TraceInformation. - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #1000 at d8d9709: Locomotive operation from control car - Pull request #1029 at 92c74ef: Superelevation Follow Up Fixes - Pull request #1065 at 409064d: Fix for PantographToggle sound event - Pull request #1068 at d6e1f83: Build for online-only documentation files - Pull request #896 at f1681df: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains
16 parents 0ec6982 + 0cd8cb8 + b54024b + d3ae4a2 + cc4d53c + 382ea6d + cf3caa0 + 3b18c48 + 53dd604 + 62c89c1 + 1f5ba4c + d8d9709 + 92c74ef + 409064d + d6e1f83 + f1681df commit ee8cffc

File tree

1 file changed

+98
-38
lines changed

1 file changed

+98
-38
lines changed

Source/Menu/MainForm.cs

Lines changed: 98 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,34 +1364,32 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
13641364
UpdateFromMenuSelection<T>(comboBox, index, map, default(T));
13651365
}
13661366

1367+
/// <summary>
1368+
/// Update the combobox with the selection stored in the menu selection settings (from the previous run).
1369+
/// If the menu selection settings do not match the current selection use the default; except for
1370+
/// "Explore in Activity Mode" also try the content route settings (for the route).
1371+
/// </summary>
13671372
void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIndex index, Func<T, string> map, T defaultValue)
13681373
{
1369-
if (((index == UserSettings.Menu_SelectionIndex.Folder) ||
1370-
((comboBoxFolder.Items.Count > 0) && (SelectedFolder != null) &&
1371-
(Settings.Menu_Selection.Count() > 0) &&
1372-
(SelectedFolder.Path == Settings.Menu_Selection[(int)UserSettings.Menu_SelectionIndex.Folder]))) &&
1373-
(Settings.Menu_Selection.Length > (int)index) &&
1374-
(Settings.Menu_Selection[(int)index] != ""))
1374+
string value = GetValueFromMenuSelection(index);
1375+
if (!string.IsNullOrEmpty(value))
13751376
{
13761377
if (comboBox.DropDownStyle == ComboBoxStyle.DropDown)
1377-
{
1378-
comboBox.Text = Settings.Menu_Selection[(int)index];
1379-
}
1378+
comboBox.Text = value;
13801379
else
1381-
{
1382-
SelectComboBoxItem<T>(comboBox, item => map(item) == Settings.Menu_Selection[(int)index]);
1383-
}
1380+
SelectComboBoxItem<T>(comboBox, item => map(item) == value);
13841381
}
13851382
else
13861383
{
1384+
// when explore-in-activity mode, try the content route info
13871385
var routes = Settings.Content.ContentRouteSettings.Routes;
1388-
if ((SelectedFolder != null) &&
1389-
routes.ContainsKey(SelectedFolder.Name) &&
1390-
routes[SelectedFolder.Name].Installed &&
1391-
!string.IsNullOrEmpty(routes[SelectedFolder.Name].Start.Route))
1386+
if ((SelectedActivity != null && SelectedActivity is ExploreThroughActivity) &&
1387+
(SelectedFolder != null && routes.ContainsKey(SelectedFolder.Name) && routes[SelectedFolder.Name].Installed) &&
1388+
(!string.IsNullOrEmpty(routes[SelectedFolder.Name].Start.Route)))
13921389
{
13931390
var route = routes[SelectedFolder.Name];
13941391
string valueComboboxToSetTo = "";
1392+
string conditionalSecondValue = "";
13951393
switch (index)
13961394
{
13971395
case UserSettings.Menu_SelectionIndex.Route:
@@ -1408,6 +1406,7 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
14081406
break;
14091407
case UserSettings.Menu_SelectionIndex.Path:
14101408
valueComboboxToSetTo = route.Start.StartingAt;
1409+
conditionalSecondValue = route.Start.HeadingTo;
14111410
break;
14121411
case UserSettings.Menu_SelectionIndex.Time:
14131412
valueComboboxToSetTo = route.Start.Time;
@@ -1421,31 +1420,29 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
14211420
default:
14221421
break;
14231422
}
1424-
bool found = false;
1425-
if ((index != UserSettings.Menu_SelectionIndex.Path) ||
1426-
(SelectedActivity == null) || (!(SelectedActivity is ExploreActivity)))
1423+
1424+
if (index == UserSettings.Menu_SelectionIndex.Path)
1425+
{
1426+
if (!string.IsNullOrEmpty(valueComboboxToSetTo))
1427+
searchInComboBoxAndSet(comboBoxStartAt, valueComboboxToSetTo);
1428+
else
1429+
SetToDefault(comboBoxStartAt, index, map, defaultValue);
1430+
1431+
if (!string.IsNullOrEmpty(conditionalSecondValue))
1432+
searchInComboBoxAndSet(comboBoxHeadTo, conditionalSecondValue);
1433+
else
1434+
SetToDefault(comboBoxHeadTo, index, map, defaultValue);
1435+
}
1436+
else if (!string.IsNullOrEmpty(valueComboboxToSetTo))
14271437
{
14281438
if (comboBox.DropDownStyle == ComboBoxStyle.DropDown)
1429-
{
14301439
comboBox.Text = valueComboboxToSetTo;
1431-
found = true;
1440+
else
1441+
searchInComboBoxAndSet(comboBox, valueComboboxToSetTo);
14321442
}
14331443
else
14341444
{
1435-
found = searchInComboBox(comboBox, valueComboboxToSetTo);
1436-
}
1437-
}
1438-
else
1439-
{
1440-
found = searchInComboBox(comboBoxStartAt, valueComboboxToSetTo);
1441-
found = searchInComboBox(comboBoxHeadTo, valueComboboxToSetTo);
1442-
}
1443-
if (!found)
1444-
{
1445-
if (comboBox.Items.Count > 0)
1446-
{
1447-
comboBox.SelectedIndex = 0;
1448-
}
1445+
SetToDefault(comboBox, index, map, defaultValue);
14491446
}
14501447
}
14511448
else
@@ -1455,19 +1452,77 @@ void UpdateFromMenuSelection<T>(ComboBox comboBox, UserSettings.Menu_SelectionIn
14551452
}
14561453
}
14571454

1458-
bool searchInComboBox(ComboBox comboBox, string valueComboboxToSetTo)
1455+
/// <summary>
1456+
/// Get the combobox's value from the menu selection in the settings.
1457+
/// Checks that folder, route and activity/timetable-set match.
1458+
/// Returns the value from the settings, or an empty string.
1459+
/// </summary>
1460+
string GetValueFromMenuSelection(UserSettings.Menu_SelectionIndex index)
1461+
{
1462+
if (Settings.Menu_Selection.Length <= (int)index)
1463+
return ""; // not in menu selection settings
1464+
1465+
else if (index == UserSettings.Menu_SelectionIndex.Folder)
1466+
return Settings.Menu_Selection[(int)index];
1467+
1468+
else if (SelectedFolder == null)
1469+
return ""; // no current folder to match to
1470+
1471+
else if (SelectedFolder.Path != Settings.Menu_Selection[(int)UserSettings.Menu_SelectionIndex.Folder])
1472+
return ""; // current folder and menu selection settings folder don't match
1473+
1474+
else if (index == UserSettings.Menu_SelectionIndex.Route)
1475+
return Settings.Menu_Selection[(int)index];
1476+
1477+
else if (SelectedRoute == null)
1478+
return ""; // no current route to match to
1479+
1480+
else if (SelectedRoute.Path != Settings.Menu_Selection[(int)UserSettings.Menu_SelectionIndex.Route])
1481+
return ""; // current route and menu selection settings route don't match
1482+
1483+
else if (index == UserSettings.Menu_SelectionIndex.Activity || index == UserSettings.Menu_SelectionIndex.TimetableSet)
1484+
return Settings.Menu_Selection[(int)index];
1485+
1486+
else if (radioButtonModeActivity.Checked && SelectedActivity == null)
1487+
return ""; // no current activity to match to
1488+
1489+
else if (radioButtonModeTimetable.Checked && SelectedTimetableSet == null)
1490+
return ""; // no current timetable set to match to
1491+
1492+
else if (radioButtonModeActivity.Checked && SelectedActivity.Name != Settings.Menu_Selection[(int)UserSettings.Menu_SelectionIndex.Activity])
1493+
return ""; // current activity and menu selection settings activity don't match
1494+
1495+
else if (radioButtonModeTimetable.Checked && SelectedTimetableSet.fileName != Settings.Menu_Selection[(int)UserSettings.Menu_SelectionIndex.TimetableSet])
1496+
return ""; // current timetable set is different from timetable set in menu selection setting
1497+
1498+
else
1499+
return Settings.Menu_Selection[(int)index];
1500+
}
1501+
1502+
/// <summary>
1503+
/// Search the DropDown combobox (editable) for the specified string value.
1504+
/// When found, set the combobox to the value, otherwise to the first defined value.
1505+
/// Leave unselected when there are no defined values.
1506+
/// </summary>
1507+
void searchInComboBoxAndSet(ComboBox comboBox, string valueComboboxToSetTo)
14591508
{
14601509
for (var i = 0; i < comboBox.Items.Count; i++)
14611510
{
14621511
if ((string)comboBox.Items[i].ToString() == valueComboboxToSetTo)
14631512
{
14641513
comboBox.SelectedIndex = i;
1465-
return true;
1514+
return;
14661515
}
14671516
}
1468-
return false;
1517+
if (comboBox.Items.Count > 0)
1518+
{
1519+
comboBox.SelectedIndex = 0;
1520+
}
14691521
}
14701522

1523+
/// <summary>
1524+
/// Set the combobox to the specified default (item).
1525+
/// </summary>
14711526
void SetToDefault<T>(ComboBox comboBox, UserSettings.Menu_SelectionIndex index, Func<T, string> map, T defaultValue)
14721527
{
14731528
if (comboBox.DropDownStyle == ComboBoxStyle.DropDown)
@@ -1490,6 +1545,11 @@ void SetToDefault<T>(ComboBox comboBox, UserSettings.Menu_SelectionIndex index,
14901545
}
14911546
}
14921547

1548+
/// <summary>
1549+
/// Select the the specified item in the combobox (not editable).
1550+
/// When not found, set it to the first item.
1551+
/// Leave unselected when there are no defined items.
1552+
/// </summary>
14931553
void SelectComboBoxItem<T>(ComboBox comboBox, Func<T, bool> predicate)
14941554
{
14951555
if (comboBox.Items.Count == 0)

0 commit comments

Comments
 (0)