Skip to content

Commit 4d198e4

Browse files
Added support for activity location events to the TrackViewer
1 parent 58e6767 commit 4d198e4

11 files changed

+346
-14
lines changed

Source/Contrib/TrackViewer/Drawing/DrawColors.cs

+8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static class DrawColors
4646
public static ColorScheme colorsRoadsHotlight = new ColorScheme(HighlightType.Hotlight);
4747
public static ColorScheme colorsPathMain = new ColorScheme();
4848
public static ColorScheme colorsPathSiding = new ColorScheme();
49+
public static ColorScheme colorsEvent = new ColorScheme();
4950

5051
static ColorsGroupTrack trackGroupFlat = new ColorsGroupTrack();
5152
static ColorsGroupTrack roadTrackGroupFlat = new ColorsGroupTrack();
@@ -212,6 +213,11 @@ private static void SetItemColors(IPreferenceChanger preferenceChanger)
212213
TrackViewer.catalog.GetString("Select speedpost color"));
213214
itemColors.Speedpost = itemColor;
214215

216+
itemColor = new ColorWithHighlights(Color.DarkGray, 40);
217+
itemColor.MakeIntoUserPreference(preferenceChanger, "event",
218+
TrackViewer.catalog.GetString("Select event color"));
219+
itemColors.Event = itemColor;
220+
215221
itemColor = new ColorWithHighlights(Color.Blue, 40);
216222
itemColors.CandidateNode = itemColor;
217223

@@ -321,6 +327,7 @@ class ColorsGroupBasic {
321327
public ColorWithHighlights RoadCrossing { get; set; }
322328
public ColorWithHighlights Speedpost { get; set; }
323329
public ColorWithHighlights Siding { get; set; }
330+
public ColorWithHighlights Event { get; set; }
324331

325332
public ColorWithHighlights Text { get; set; }
326333
public ColorWithHighlights ClearWindowInset { get; set; }
@@ -362,6 +369,7 @@ class ColorScheme
362369
public Color RoadCrossing { get { return TrackItemColors.RoadCrossing.Colors[highlightType]; } }
363370
public Color Speedpost { get { return TrackItemColors.Speedpost.Colors[highlightType]; } }
364371
public Color Siding { get { return TrackItemColors.Siding.Colors[highlightType]; } }
372+
public Color Event { get { return TrackItemColors.Event.Colors[highlightType]; } }
365373

366374
public Color ActiveNode { get { return TrackItemColors.ActiveNode.Colors[highlightType]; } }
367375
public Color CandidateNode { get { return TrackItemColors.CandidateNode.Colors[highlightType]; } }

Source/Contrib/TrackViewer/Drawing/DrawTrackDB.cs

+97-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public class RouteData
4545
public RoadTrackDB RoadTrackDB { get; set; }
4646
/// <summary>The signal config file containing, for instance, the information to distinguish normal and non-normal signals</summary>
4747
public SignalConfigurationFile SigcfgFile { get; set; }
48+
/// <summary>
49+
/// <summary>Activity names</summary>
50+
/// </summary>
51+
public List<string> ActivityNames = new List<string> { };
4852

4953
private string storedRoutePath;
5054
private Dictionary<uint, string> signalFileNames;
@@ -87,7 +91,7 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
8791
}
8892
catch
8993
{
90-
}
94+
}
9195

9296
string ORfilepath = System.IO.Path.Combine(routePath, "OpenRails");
9397
if (File.Exists(ORfilepath + @"\sigcfg.dat"))
@@ -102,6 +106,72 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
102106
{
103107
//sigcfgFile = null; // default initialization
104108
}
109+
110+
// read the activity location events and store them in the TrackDB.TrItemTable
111+
112+
ActivityNames.Clear();
113+
var directory = System.IO.Path.Combine(routePath, "ACTIVITIES");
114+
if (System.IO.Directory.Exists(directory))
115+
{
116+
// counting
117+
int cnt = 0;
118+
119+
foreach (var file in Directory.GetFiles(directory, "*.act"))
120+
{
121+
try
122+
{
123+
var activityFile = new ActivityFile(file);
124+
Events events = activityFile.Tr_Activity.Tr_Activity_File.Events;
125+
if (events != null)
126+
{
127+
for (int i = 0; i < events.EventList.Count; i++)
128+
{
129+
if (events.EventList[i].GetType() == typeof(EventCategoryLocation))
130+
{
131+
cnt++;
132+
}
133+
}
134+
}
135+
}
136+
catch { }
137+
}
138+
139+
// adding
140+
uint index = 0;
141+
foreach (var file in Directory.GetFiles(directory, "*.act"))
142+
{
143+
try
144+
{
145+
var activityFile = new ActivityFile(file);
146+
Events events = activityFile.Tr_Activity.Tr_Activity_File.Events;
147+
bool found = false;
148+
if (events != null)
149+
{
150+
for (int i = 0; i < events.EventList.Count; i++)
151+
{
152+
if (events.EventList[i].GetType() == typeof(EventCategoryLocation))
153+
{
154+
EventCategoryLocation eventCategoryLocation = (EventCategoryLocation)events.EventList[i];
155+
EventItem eventItem = new EventItem(
156+
activityFile.Tr_Activity.Tr_Activity_Header.Name + ":" + eventCategoryLocation.Name,
157+
eventCategoryLocation.Outcomes.DisplayMessage,
158+
eventCategoryLocation.TileX, eventCategoryLocation.TileZ,
159+
eventCategoryLocation.X, 0, eventCategoryLocation.Z,
160+
index);
161+
TrackDB.TrItemTable[index] = eventItem;
162+
index++;
163+
found = true;
164+
}
165+
}
166+
}
167+
if (found) {
168+
ActivityNames.Add(activityFile.Tr_Activity.Tr_Activity_Header.Name);
169+
}
170+
}
171+
catch { }
172+
}
173+
174+
}
105175
}
106176

107177
/// <summary>
@@ -176,6 +246,32 @@ public string GetSignalFilename(uint signalIndex)
176246
}
177247
}
178248

249+
/// <summary>
250+
/// represents an Activity Location EventItem
251+
/// </summary>
252+
/// defined in this trackviewer file because I want to keep changes localized to the TrackViewer
253+
254+
public class EventItem : TrItem
255+
{
256+
/// <summary>
257+
/// Default constructor, no file parsing used
258+
/// </summary>
259+
public EventItem(string itemName, string briefing, int tileX, int tileZ, float x, float y, float z, uint trItemId)
260+
{
261+
// ItemType is trEMPTY on purpose
262+
// so that Orts.Formats.Msts.TrItem.trItemType does not need a change
263+
ItemType = trItemType.trEMPTY;
264+
ItemName = itemName;
265+
TileX = tileX;
266+
TileZ = tileZ;
267+
X = x;
268+
Y = y;
269+
Z = z;
270+
TrItemId = trItemId;
271+
SData2 = briefing;
272+
}
273+
}
274+
179275
/// <summary>
180276
/// This is a big class where the drawing of everything in the track data base is done.
181277
/// This means tracks themselves (meaning so-called vector nodes that contain a number of sections,

Source/Contrib/TrackViewer/Drawing/DrawableTrackItem.cs

+48
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static DrawableTrackItem CreateDrawableTrItem(TrItem originalTrItem)
7070
if (originalTrItem is RoadLevelCrItem){ return new DrawableRoadLevelCrItem(originalTrItem); }
7171
if (originalTrItem is CarSpawnerItem) { return new DrawableCarSpawnerItem(originalTrItem); }
7272
if (originalTrItem is CrossoverItem) { return new DrawableCrossoverItem(originalTrItem); }
73+
if (originalTrItem is EventItem) { return new DrawableEvent(originalTrItem); }
7374
return new DrawableEmptyItem(originalTrItem);
7475
}
7576

@@ -605,4 +606,51 @@ internal override bool Draw(DrawArea drawArea, ColorScheme colors, bool drawAlwa
605606
}
606607
}
607608
#endregion
609+
610+
#region DrawableEvent
611+
/// <summary>
612+
/// Represents a drawable event
613+
/// </summary>
614+
class DrawableEvent : DrawableTrackItem
615+
{
616+
private string ItemName;
617+
618+
/// <summary>
619+
/// Default constructor
620+
/// </summary>
621+
/// <param name="originalTrItem">The original track item that we are representing for drawing</param>
622+
public DrawableEvent(TrItem originalTrItem)
623+
: base(originalTrItem)
624+
{
625+
Description = "event";
626+
ItemName = originalTrItem.ItemName;
627+
}
628+
629+
/// <summary>
630+
/// Draw an event
631+
/// </summary>
632+
/// <param name="drawArea">The area to draw upon</param>
633+
/// <param name="colors">The colorscheme to use</param>
634+
/// <param name="drawAlways">Do we need to draw anyway, independent of settings?</param>
635+
internal override bool Draw(DrawArea drawArea, ColorScheme colors, bool drawAlways)
636+
{
637+
bool returnValue = false;
638+
if (String.IsNullOrEmpty(Properties.Settings.Default.CurrentActivityName) ||
639+
(ItemName.StartsWith(Properties.Settings.Default.CurrentActivityName + ":")))
640+
{
641+
if (Properties.Settings.Default.showEvents || drawAlways)
642+
{
643+
drawArea.DrawTexture(WorldLocation, "disc", 6f, 0, colors.Event);
644+
returnValue = true;
645+
}
646+
if (Properties.Settings.Default.showEventNames || drawAlways)
647+
{
648+
drawArea.DrawExpandingString(this.WorldLocation, ItemName);
649+
returnValue = true;
650+
}
651+
}
652+
return returnValue;
653+
}
654+
}
655+
#endregion
608656
}

Source/Contrib/TrackViewer/Editing/Charts/DrawPathChart.cs

-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ private void OnPathChanged()
161161
}
162162
pathData.Update(trainpath);
163163
chartWindow.Draw();
164-
chartWindow.SetTitle(pathEditor.CurrentTrainPath.PathName);
165164
}
166165

167166
/// <summary>

Source/Contrib/TrackViewer/Editing/Charts/PathChartWindow.xaml.cs

-9
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,6 @@ public void Draw()
9191
}
9292

9393
}
94-
95-
/// <summary>
96-
/// Set the title of the window
97-
/// </summary>
98-
/// <param name="newTitle"></param>
99-
public void SetTitle(string newTitle)
100-
{
101-
this.Title = newTitle;
102-
}
10394
#endregion
10495

10596
#region Window events

Source/Contrib/TrackViewer/Properties/Settings.Designer.cs

+53-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Contrib/TrackViewer/Properties/Settings.settings

+9
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@
122122
<Setting Name="showSoundRegions" Type="System.Boolean" Scope="User">
123123
<Value Profile="(Default)">False</Value>
124124
</Setting>
125+
<Setting Name="showEvents" Type="System.Boolean" Scope="User">
126+
<Value Profile="(Default)">False</Value>
127+
</Setting>
128+
<Setting Name="showEventNames" Type="System.Boolean" Scope="User">
129+
<Value Profile="(Default)">False</Value>
130+
</Setting>
125131
<Setting Name="showLabels" Type="System.Boolean" Scope="User">
126132
<Value Profile="(Default)">False</Value>
127133
</Setting>
@@ -158,6 +164,9 @@
158164
<Setting Name="statusShowNames" Type="System.Boolean" Scope="User">
159165
<Value Profile="(Default)">False</Value>
160166
</Setting>
167+
<Setting Name="statusShowEventNames" Type="System.Boolean" Scope="User">
168+
<Value Profile="(Default)">False</Value>
169+
</Setting>
161170
<Setting Name="statusShowTerrain" Type="System.Boolean" Scope="User">
162171
<Value Profile="(Default)">False</Value>
163172
</Setting>

Source/Contrib/TrackViewer/TrackViewer.cs

+14-1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ protected override void Initialize()
220220

221221
drawPathChart = new DrawPathChart();
222222

223+
Properties.Settings.Default.CurrentActivityName = "";
224+
223225
base.Initialize();
224226
}
225227

@@ -519,6 +521,8 @@ protected override void Update(GameTime gameTime)
519521
base.Update(gameTime);
520522

521523
HandleCommandLineArgs();
524+
525+
SetTitle();
522526
}
523527

524528
/// <summary>
@@ -933,6 +937,7 @@ public void SetRoute(Route newRoute)
933937
menuControl.PopulatePlatforms();
934938
menuControl.PopulateStations();
935939
menuControl.PopulateSidings();
940+
menuControl.PopulateActivitiesMenu();
936941
}
937942

938943
/// <summary>
@@ -942,7 +947,15 @@ void SetTitle()
942947
{
943948
Assembly assembly = Assembly.GetExecutingAssembly();
944949
AssemblyTitleAttribute assemblyTitle = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0] as AssemblyTitleAttribute;
945-
Window.Title = assemblyTitle.Title + ": " + RouteData.RouteName;
950+
Window.Title = assemblyTitle.Title;
951+
if ((RouteData != null) && (RouteData.RouteName != null))
952+
{
953+
Window.Title += ": " + RouteData.RouteName;
954+
}
955+
if (!String.IsNullOrEmpty(Properties.Settings.Default.CurrentActivityName))
956+
{
957+
Window.Title += " Activity: " + Properties.Settings.Default.CurrentActivityName;
958+
}
946959
}
947960

948961
#endregion

0 commit comments

Comments
 (0)