Skip to content

Commit a6a8a53

Browse files
Added start parameters per route, see also PR openrails/content#10
1 parent 7353625 commit a6a8a53

File tree

5 files changed

+431
-153
lines changed

5 files changed

+431
-153
lines changed

Source/Menu/DownloadContentForm.Designer.cs

Lines changed: 24 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Menu/DownloadContentForm.cs

Lines changed: 203 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ public DownloadContentForm(UserSettings settings)
7171
InfoTempFilename = Path.ChangeExtension(ImageTempFilename, "html");
7272
}
7373

74-
void dataGridViewDownloadContent_SelectionChanged(object sender, EventArgs e)
74+
private void dataGridViewDownloadContent_SelectionChanged(object sender, EventArgs e)
7575
{
7676
RouteName = dataGridViewDownloadContent.CurrentRow.Cells[0].Value.ToString();
7777

78+
// install button
79+
7880
DownloadContentButton.Enabled = string.IsNullOrWhiteSpace(Routes[RouteName].DateInstalled);
7981

8082
// picture box handling
@@ -108,16 +110,15 @@ void dataGridViewDownloadContent_SelectionChanged(object sender, EventArgs e)
108110
{
109111
myWebClient.DownloadFile(Routes[RouteName].Image, ImageTempFilename);
110112
}
113+
if (File.Exists(ImageTempFilename))
114+
{
115+
pictureBoxRoute.Image = new Bitmap(ImageTempFilename);
116+
}
111117
}
112118
catch
113119
{
114120
// route lives whithout a picture, not such a problem
115121
}
116-
117-
if (File.Exists(ImageTempFilename))
118-
{
119-
pictureBoxRoute.Image = new Bitmap(ImageTempFilename);
120-
}
121122
});
122123
ImageThread.Start();
123124
}
@@ -126,6 +127,20 @@ void dataGridViewDownloadContent_SelectionChanged(object sender, EventArgs e)
126127
// text box with description
127128

128129
textBoxRoute.Text = Routes[RouteName].Description;
130+
131+
// start button
132+
133+
startButton.Enabled = false;
134+
135+
if (!string.IsNullOrWhiteSpace(Routes[RouteName].DateInstalled))
136+
{
137+
// route installed
138+
if (!string.IsNullOrWhiteSpace(Routes[RouteName].Start.Route))
139+
{
140+
// start information available
141+
startButton.Enabled = true;
142+
}
143+
}
129144
}
130145

131146
private void InstallPathButton_Click(object sender, EventArgs e)
@@ -243,9 +258,28 @@ private void DownloadContentButton_Click(object sender, EventArgs e)
243258
Settings.Folders.Save();
244259
Settings.Routes.Save();
245260

246-
MessageBox.Show(Catalog.GetString("Route installed"), Catalog.GetString("Done"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
247-
248-
Close();
261+
if (!string.IsNullOrWhiteSpace(Routes[RouteName].Start.Route))
262+
{
263+
// start information available
264+
startButton.Enabled = true;
265+
MessageBox.Show(Catalog.GetString("Route installed, press 'Start' button to start Open Rails for this route."),
266+
Catalog.GetString("Done"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
267+
}
268+
else
269+
{
270+
// no start information available
271+
MainForm mainForm = ((MainForm)Owner);
272+
mainForm.DoWithTask = false;
273+
mainForm.LoadFolderList();
274+
mainForm.comboBoxFolder.SelectedIndex = determineSelectedIndex(mainForm.comboBoxFolder, RouteName);
275+
mainForm.DoWithTask = true;
276+
277+
MessageBox.Show(Catalog.GetString("Route installed."),
278+
Catalog.GetString("Done"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
279+
280+
// close this dialog
281+
DialogResult = DialogResult.OK;
282+
}
249283
}
250284

251285
private bool downloadRoute(string installPathRoute)
@@ -263,6 +297,7 @@ private bool downloadRoute(string installPathRoute)
263297
returnValue = doTheZipDownload(Routes[RouteName].Url, Path.Combine(installPathRoute, RouteName + ".zip"));
264298
}
265299
});
300+
// start download in thread to be able to show the progress in the main thread
266301
downloadThread.Start();
267302

268303
while (downloadThread.IsAlive)
@@ -475,28 +510,29 @@ private void InfoButton_Click(object sender, EventArgs e)
475510

476511
if (string.IsNullOrWhiteSpace(route.AuthorUrl))
477512
{
478-
outputFile.WriteLine(string.Format("<p>created by : {0}</p>\n",
513+
outputFile.WriteLine(string.Format("<p>" + Catalog.GetString("created by") + ": {0}</p>\n",
479514
route.AuthorName));
480515
}
481516
else
482517
{
483-
outputFile.WriteLine(string.Format("<p>created by : <a href='{0}'>{1}</a></p>\n",
518+
outputFile.WriteLine(string.Format("<p>" + Catalog.GetString("created by") + ": <a href='{0}'>{1}</a></p>\n",
484519
route.AuthorUrl, route.AuthorName));
485520
}
486521

487522
if (!string.IsNullOrWhiteSpace(route.Screenshot))
488523
{
489-
outputFile.WriteLine(string.Format("<p>screenshots: <a href='{0}'>{1}</a></p>\n",
524+
outputFile.WriteLine(string.Format("<p>" + Catalog.GetString("screenshots") + ": <a href='{0}'>{1}</a></p>\n",
490525
route.Screenshot, route.Screenshot));
491526
}
492527

493528
if (route.Url.EndsWith("git"))
494529
{
495-
outputFile.WriteLine(String.Format("<p>Downloadable: GitHub format<br>\n"));
496-
outputFile.WriteLine(String.Format("- From: {0}<br>\n", route.Url));
530+
outputFile.WriteLine("<p>" + Catalog.GetString("Downloadable: GitHub format") + "<br>\n");
531+
outputFile.WriteLine(String.Format("- " + Catalog.GetString("From:") + "{0}<br>\n", route.Url));
497532
if (route.InstallSize > 0)
498533
{
499-
outputFile.WriteLine(String.Format("- Install size: {0} GB<br></p>\n", (route.InstallSize / (1024.0 * 1024 * 1024)).ToString("N")));
534+
outputFile.WriteLine("- " + Catalog.GetStringFmt("Install size: {0} GB",
535+
(route.InstallSize / (1024.0 * 1024 * 1024)).ToString("N")) + "<br></p>\n");
500536
}
501537
}
502538
if (route.Url.EndsWith("zip"))
@@ -505,26 +541,172 @@ private void InfoButton_Click(object sender, EventArgs e)
505541
outputFile.WriteLine(String.Format("- From: {0}<br>\n", route.Url));
506542
if (route.InstallSize > 0)
507543
{
508-
outputFile.WriteLine(String.Format("- Install size: {0} GB<br>\n", (route.InstallSize / (1024.0 * 1024 * 1024)).ToString("N")));
544+
outputFile.WriteLine("- " + Catalog.GetStringFmt("Install size: {0} GB",
545+
(route.InstallSize / (1024.0 * 1024 * 1024)).ToString("N")) + "<br>\n");
509546
}
510547
if (route.DownloadSize > 0)
511548
{
512-
outputFile.WriteLine(String.Format("- Download size: {0} GB<br></p>\n", (route.DownloadSize / (1024.0 * 1024 * 1024)).ToString("N")));
549+
outputFile.WriteLine("- " + Catalog.GetStringFmt("Download size: {0} GB",
550+
(route.DownloadSize / (1024.0 * 1024 * 1024)).ToString("N")) + "<br></p>\n");
513551
}
514552
}
515553

516554
if (!string.IsNullOrWhiteSpace(route.DateInstalled))
517555
{
518-
outputFile.WriteLine(String.Format("<p>Installed:<br>\n"));
519-
outputFile.WriteLine(String.Format("- at: {0}<br>\n", route.DateInstalled));
520-
outputFile.WriteLine(String.Format("- in: \"{0}\"<br></p>\n", route.DirectoryInstalledIn));
556+
outputFile.WriteLine("<p>" + Catalog.GetString("Installed") + ":<br>\n");
557+
outputFile.WriteLine(String.Format("- " + Catalog.GetString("at") + ": {0}<br>\n", route.DateInstalled));
558+
outputFile.WriteLine(String.Format("- " + Catalog.GetString("in:") + "\"{0}\"<br></p>\n", route.DirectoryInstalledIn));
559+
}
560+
561+
outputFile.WriteLine("<p>" + Catalog.GetString("Start options") + ":<br>\n");
562+
if (string.IsNullOrWhiteSpace(route.Start.Route))
563+
{
564+
// no start information
565+
outputFile.WriteLine("- " + Catalog.GetString("None") + "<br></p>\n");
566+
}
567+
else
568+
{
569+
outputFile.WriteLine("- " + Catalog.GetString("Installation profile") + ": " + RouteName + "<br>\n");
570+
outputFile.WriteLine("- " + Catalog.GetString("Route") + ": " + route.Start.Route + "<br>\n");
571+
outputFile.WriteLine("- " + Catalog.GetString("Locomotive") + ": " + route.Start.Locomotive + "<br>\n");
572+
outputFile.WriteLine("- " + Catalog.GetString("Consist") + ": " + route.Start.Consist + "<br>\n");
573+
outputFile.WriteLine("- " + Catalog.GetString("Starting at") + ": " + route.Start.StartingAt + "<br>\n");
574+
outputFile.WriteLine("- " + Catalog.GetString("Heading to") + ": " + route.Start.HeadingTo + "<br>\n");
575+
outputFile.WriteLine("- " + Catalog.GetString("Time") + ": " + route.Start.Time + "<br>\n");
576+
outputFile.WriteLine("- " + Catalog.GetString("Season") + ": " + route.Start.Season + "<br>\n");
577+
outputFile.WriteLine("- " + Catalog.GetString("Weather") + ": " + route.Start.Weather + "<br></p>\n");
521578
}
522579
}
523580

524581
// show html file in default browser
525582
System.Diagnostics.Process.Start(InfoTempFilename);
526583
}
527584

585+
void StartButton_Click(object sender, EventArgs e)
586+
{
587+
Cursor.Current = Cursors.WaitCursor;
588+
589+
RouteSettings.Route route = Routes[RouteName];
590+
MainForm mainForm = ((MainForm)Owner);
591+
592+
mainForm.DoWithTask = false;
593+
594+
try
595+
{
596+
mainForm.LoadFolderList();
597+
mainForm.comboBoxFolder.SelectedIndex = determineSelectedIndex(mainForm.comboBoxFolder, RouteName);
598+
599+
mainForm.LoadRouteList();
600+
mainForm.comboBoxRoute.SelectedIndex = determineSelectedIndex(mainForm.comboBoxRoute, route.Start.Route);
601+
602+
mainForm.radioButtonModeActivity.Checked = true;
603+
// hardcoded: + Explore in Activity Mode +
604+
mainForm.comboBoxActivity.SelectedIndex = 1;
605+
606+
mainForm.LoadLocomotiveList();
607+
mainForm.comboBoxLocomotive.SelectedIndex = determineSelectedIndex(mainForm.comboBoxLocomotive, route.Start.Locomotive);
608+
mainForm.comboBoxConsist.SelectedIndex = determineSelectedIndex(mainForm.comboBoxConsist, route.Start.Consist) ;
609+
610+
mainForm.LoadStartAtList();
611+
mainForm.comboBoxStartAt.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartAt, route.Start.StartingAt) ;
612+
mainForm.comboBoxHeadTo.SelectedIndex = determineSelectedIndex(mainForm.comboBoxHeadTo, route.Start.HeadingTo);
613+
614+
mainForm.comboBoxStartTime.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartTime, route.Start.Time);
615+
mainForm.comboBoxStartSeason.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartSeason, route.Start.Season);
616+
mainForm.comboBoxStartWeather.SelectedIndex = determineSelectedIndex(mainForm.comboBoxStartWeather, route.Start.Weather);
617+
}
618+
catch (StartNotFound error) {
619+
620+
string message = Catalog.GetStringFmt("Starting not possible, start from main form instead. Searching for '{0}'.", error.Message);
621+
MessageBox.Show(message, Catalog.GetString("Attention"), MessageBoxButtons.OK, MessageBoxIcon.Error);
622+
623+
mainForm.DoWithTask = true;
624+
625+
// close this dialog
626+
DialogResult = DialogResult.OK;
627+
628+
return;
629+
}
630+
631+
mainForm.DoWithTask = true;
632+
633+
// close this dialog
634+
DialogResult = DialogResult.OK;
635+
636+
// close the MainForm dialog, starts OR
637+
Owner.DialogResult = DialogResult.OK;
638+
}
639+
640+
private int determineSelectedIndex(ComboBox comboBox, string compareWith)
641+
{
642+
bool found = false;
643+
int index = 0;
644+
645+
string classOfItem;
646+
if (comboBox.Items.Count > 0)
647+
{
648+
classOfItem = comboBox.Items[0].GetType().Name;
649+
}
650+
else
651+
{
652+
throw new StartNotFound(Catalog.GetStringFmt(compareWith));
653+
}
654+
655+
while (!found && (index < comboBox.Items.Count))
656+
{
657+
string comboboxName = "";
658+
switch (classOfItem)
659+
{
660+
case "Folder":
661+
comboboxName = ((Menu.Folder)comboBox.Items[index]).Name;
662+
break;
663+
case "Route":
664+
comboboxName = ((Menu.Route)comboBox.Items[index]).Name;
665+
break;
666+
case "Locomotive":
667+
comboboxName = ((Menu.Locomotive)comboBox.Items[index]).Name;
668+
break;
669+
case "Consist":
670+
comboboxName = ((Menu.Consist)comboBox.Items[index]).Name;
671+
break;
672+
case "String":
673+
comboboxName = (String)comboBox.Items[index];
674+
break;
675+
case "Path":
676+
comboboxName = ((Menu.Path)comboBox.Items[index]).End;
677+
break;
678+
case "KeyedComboBoxItem":
679+
comboboxName = ((MainForm.KeyedComboBoxItem)comboBox.Items[index]).Value;
680+
break;
681+
}
682+
683+
if (comboboxName == compareWith)
684+
{
685+
found = true;
686+
}
687+
else
688+
{
689+
index++;
690+
}
691+
}
692+
if (found)
693+
{
694+
comboBox.SelectedIndex = index;
695+
}
696+
else
697+
{
698+
throw new StartNotFound(Catalog.GetStringFmt(compareWith));
699+
}
700+
701+
return index;
702+
}
703+
704+
private class StartNotFound : Exception
705+
{
706+
public StartNotFound(string message)
707+
: base(message)
708+
{ }
709+
}
528710

529711
private void DownloadContentForm_FormClosing(object sender, FormClosingEventArgs e)
530712
{
@@ -540,7 +722,7 @@ private void DownloadContentForm_FormClosing(object sender, FormClosingEventArgs
540722
}
541723
catch
542724
{
543-
// just ignore, the files are the user temp directory anyway
725+
// just ignore, the files are in the user temp directory anyway
544726
}
545727
}
546728
}

0 commit comments

Comments
 (0)