Skip to content

Commit f588e31

Browse files
Added activity start choice to the routes.json. Previously the activity was hardcoded.
1 parent 9bead33 commit f588e31

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

Source/Menu/DownloadContentForm.cs

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public partial class DownloadContentForm : Form
4646
private Thread ImageThread;
4747
private readonly string InfoTempFilename;
4848

49+
private bool ClosingBlocked;
50+
4951
//attribute used to refresh UI
5052
private readonly SynchronizationContext SynchronizationContext;
5153

@@ -761,20 +763,22 @@ void StartButton_Click(object sender, EventArgs e)
761763
mainForm.radioButtonModeActivity.Checked = true;
762764

763765
mainForm.LoadActivityList();
764-
// hardcoded: + Explore in Activity Mode +
765-
mainForm.comboBoxActivity.SelectedIndex = 1;
766+
mainForm.comboBoxActivity.SelectedIndex = determineSelectedIndex(mainForm.comboBoxActivity, route.Start.Activity);
766767

767-
mainForm.LoadLocomotiveList();
768-
mainForm.comboBoxLocomotive.SelectedIndex = determineSelectedIndex(mainForm.comboBoxLocomotive, route.Start.Locomotive);
769-
mainForm.comboBoxConsist.SelectedIndex = determineSelectedIndex(mainForm.comboBoxConsist, route.Start.Consist);
768+
if ((route.Start.Activity == "- Explore Route -") || (route.Start.Activity == "+ Explore in Activity Mode +"))
769+
{
770+
mainForm.LoadLocomotiveList();
771+
mainForm.comboBoxLocomotive.SelectedIndex = determineSelectedIndex(mainForm.comboBoxLocomotive, route.Start.Locomotive);
772+
mainForm.comboBoxConsist.SelectedIndex = determineSelectedIndex(mainForm.comboBoxConsist, route.Start.Consist);
770773

771-
mainForm.LoadStartAtList();
772-
mainForm.comboBoxStartAt.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartAt, route.Start.StartingAt);
773-
mainForm.comboBoxHeadTo.SelectedIndex = determineSelectedIndex(mainForm.comboBoxHeadTo, route.Start.HeadingTo);
774+
mainForm.LoadStartAtList();
775+
mainForm.comboBoxStartAt.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartAt, route.Start.StartingAt);
776+
mainForm.comboBoxHeadTo.SelectedIndex = determineSelectedIndex(mainForm.comboBoxHeadTo, route.Start.HeadingTo);
774777

775-
mainForm.comboBoxStartTime.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartTime, route.Start.Time);
776-
mainForm.comboBoxStartSeason.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartSeason, route.Start.Season);
777-
mainForm.comboBoxStartWeather.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartWeather, route.Start.Weather);
778+
mainForm.comboBoxStartTime.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartTime, route.Start.Time);
779+
mainForm.comboBoxStartSeason.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartSeason, route.Start.Season);
780+
mainForm.comboBoxStartWeather.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartWeather, route.Start.Weather);
781+
}
778782
}
779783
catch (StartNotFound error)
780784
{
@@ -798,7 +802,7 @@ void StartButton_Click(object sender, EventArgs e)
798802
// close the MainForm dialog, starts OR
799803
Owner.DialogResult = DialogResult.OK;
800804

801-
EnableButtons();
805+
ClosingBlocked = false;
802806
}
803807

804808
private int determineSelectedIndex(ComboBox comboBox, string compareWith)
@@ -816,6 +820,20 @@ private int determineSelectedIndex(ComboBox comboBox, string compareWith)
816820
throw new StartNotFound(Catalog.GetStringFmt(compareWith));
817821
}
818822

823+
if ((classOfItem == "DefaultExploreActivity") && (compareWith == "- Explore Route -"))
824+
{
825+
// "- Explore Route -" gets translated,
826+
// so it might not be found in the combobox
827+
found = true;
828+
index = 0;
829+
}
830+
if ((classOfItem == "DefaultExploreActivity") && (compareWith == "+ Explore in Activity Mode +"))
831+
{
832+
// "+ Explore in Activity Mode +" gets translated
833+
found = true;
834+
index = 1;
835+
}
836+
819837
while (!found && (index < comboBox.Items.Count))
820838
{
821839
string comboboxName = "";
@@ -827,14 +845,17 @@ private int determineSelectedIndex(ComboBox comboBox, string compareWith)
827845
case "Route":
828846
comboboxName = ((Menu.Route)comboBox.Items[index]).Name;
829847
break;
848+
case "DefaultExploreActivity":
849+
comboboxName = ((Menu.Activity)comboBox.Items[index]).Name;
850+
break;
830851
case "Locomotive":
831852
comboboxName = ((Menu.Locomotive)comboBox.Items[index]).Name;
832853
break;
833854
case "Consist":
834855
comboboxName = ((Menu.Consist)comboBox.Items[index]).Name;
835856
break;
836857
case "String":
837-
comboboxName = (String)comboBox.Items[index];
858+
comboboxName = (string)comboBox.Items[index];
838859
break;
839860
case "Path":
840861
comboboxName = ((Menu.Path)comboBox.Items[index]).End;
@@ -948,7 +969,7 @@ private void deleteRoute(string directoryInstalledIn)
948969
}), (TotalBytes / 1024).ToString("N0"));
949970
}
950971

951-
while ((deleteThread.IsAlive) && (sw.ElapsedMilliseconds <= 1000)) { }
972+
while (deleteThread.IsAlive && (sw.ElapsedMilliseconds <= 1000)) { }
952973
}
953974
}
954975
#endregion
@@ -959,6 +980,8 @@ private void updateButton_Click(object sender, EventArgs e)
959980
ContentRouteSettings.Route route = Routes[RouteName];
960981
string message;
961982

983+
DisableButtons();
984+
962985
List<string> commitStrings = getCommits(route.DirectoryInstalledIn);
963986
if (commitStrings.Count > 0)
964987
{
@@ -991,6 +1014,8 @@ private void updateButton_Click(object sender, EventArgs e)
9911014
message = Catalog.GetString("No updates found");
9921015
MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OK, MessageBoxIcon.Information);
9931016
}
1017+
1018+
EnableButtons();
9941019
}
9951020

9961021
private bool doThePull(ContentRouteSettings.Route route) {
@@ -1024,7 +1049,7 @@ private bool doThePull(ContentRouteSettings.Route route) {
10241049

10251050
private void DisableButtons()
10261051
{
1027-
UseWaitCursor = true;
1052+
setCursorToWaitCursor();
10281053

10291054
dataGridViewDownloadContent.Enabled = false;
10301055
InstallPathTextBox.Enabled = false;
@@ -1037,11 +1062,17 @@ private void DisableButtons()
10371062
updateButton.Enabled = false;
10381063
}
10391064

1040-
private void EnableButtons()
1065+
private void setCursorToWaitCursor()
10411066
{
1042-
ContentRouteSettings.Route route = Routes[RouteName];
1067+
ClosingBlocked = true;
10431068

1044-
UseWaitCursor = false;
1069+
MainForm mainForm = (MainForm)Owner;
1070+
mainForm.Cursor = Cursors.WaitCursor;
1071+
}
1072+
1073+
private void EnableButtons()
1074+
{
1075+
ContentRouteSettings.Route route = Routes[RouteName];
10451076

10461077
dataGridViewDownloadContent.Enabled = true;
10471078
InstallPathTextBox.Enabled = true;
@@ -1051,6 +1082,16 @@ private void EnableButtons()
10511082
startButton.Enabled = route.Installed && !string.IsNullOrWhiteSpace(route.Start.Route);
10521083
deleteButton.Enabled = route.Installed;
10531084
updateButton.Enabled = route.Installed && (route.getDownloadType() == ContentRouteSettings.DownloadType.github);
1085+
1086+
setCursorToDefaultCursor();
1087+
}
1088+
1089+
private void setCursorToDefaultCursor()
1090+
{
1091+
MainForm mainForm = (MainForm)Owner;
1092+
mainForm.Cursor = Cursors.Default;
1093+
1094+
ClosingBlocked = false;
10541095
}
10551096

10561097
private bool areThereChangedAddedFiles(ContentRouteSettings.Route route)
@@ -1225,7 +1266,7 @@ private List<string> getCommits(string installPathRoute)
12251266

12261267
private void DownloadContentForm_FormClosing(object sender, FormClosingEventArgs formClosingEventArgs)
12271268
{
1228-
if (UseWaitCursor)
1269+
if (ClosingBlocked)
12291270
{
12301271
// cancelled event, so continue
12311272
formClosingEventArgs.Cancel = true;

Source/Menu/MainForm.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ void MainForm_Shown(object sender, EventArgs e)
138138
var options = Environment.GetCommandLineArgs().Where(a => (a.StartsWith("-") || a.StartsWith("/"))).Select(a => a.Substring(1));
139139
Settings = new UserSettings(options);
140140

141+
Cursor = Cursors.Default;
142+
141143
LoadOptions();
142144
LoadLanguage();
143145

Source/ORTS.Settings/ContentRouteSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public enum DownloadType
3939
public class Start
4040
{
4141
public string Route;
42+
public string Activity;
4243
public string Locomotive;
4344
public string Consist;
4445
public string StartingAt;
@@ -205,6 +206,7 @@ public void LoadContentAndInstalled()
205206
Start start = new Start
206207
{
207208
Route = convertResultToString(startToken, "route"),
209+
Activity = convertResultToString(startToken,"activity"),
208210
Locomotive = convertResultToString(startToken, "locomotive"),
209211
Consist = convertResultToString(startToken, "consist"),
210212
StartingAt = convertResultToString(startToken, "startingat"),

0 commit comments

Comments
 (0)