Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for activity location events to the TrackViewer #802

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Source/Contrib/TrackViewer/Drawing/DrawColors.cs
Expand Up @@ -46,6 +46,7 @@ static class DrawColors
public static ColorScheme colorsRoadsHotlight = new ColorScheme(HighlightType.Hotlight);
public static ColorScheme colorsPathMain = new ColorScheme();
public static ColorScheme colorsPathSiding = new ColorScheme();
public static ColorScheme colorsEvent = new ColorScheme();

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

itemColor = new ColorWithHighlights(Color.DarkGray, 40);
itemColor.MakeIntoUserPreference(preferenceChanger, "event",
TrackViewer.catalog.GetString("Select event color"));
itemColors.Event = itemColor;

itemColor = new ColorWithHighlights(Color.Blue, 40);
itemColors.CandidateNode = itemColor;

Expand Down Expand Up @@ -321,6 +327,7 @@ class ColorsGroupBasic {
public ColorWithHighlights RoadCrossing { get; set; }
public ColorWithHighlights Speedpost { get; set; }
public ColorWithHighlights Siding { get; set; }
public ColorWithHighlights Event { get; set; }

public ColorWithHighlights Text { get; set; }
public ColorWithHighlights ClearWindowInset { get; set; }
Expand Down Expand Up @@ -362,6 +369,7 @@ class ColorScheme
public Color RoadCrossing { get { return TrackItemColors.RoadCrossing.Colors[highlightType]; } }
public Color Speedpost { get { return TrackItemColors.Speedpost.Colors[highlightType]; } }
public Color Siding { get { return TrackItemColors.Siding.Colors[highlightType]; } }
public Color Event { get { return TrackItemColors.Event.Colors[highlightType]; } }

public Color ActiveNode { get { return TrackItemColors.ActiveNode.Colors[highlightType]; } }
public Color CandidateNode { get { return TrackItemColors.CandidateNode.Colors[highlightType]; } }
Expand Down
98 changes: 97 additions & 1 deletion Source/Contrib/TrackViewer/Drawing/DrawTrackDB.cs
Expand Up @@ -45,6 +45,10 @@ public class RouteData
public RoadTrackDB RoadTrackDB { get; set; }
/// <summary>The signal config file containing, for instance, the information to distinguish normal and non-normal signals</summary>
public SignalConfigurationFile SigcfgFile { get; set; }
/// <summary>
/// <summary>Activity names</summary>
/// </summary>
public List<string> ActivityNames = new List<string> { };

private string storedRoutePath;
private Dictionary<uint, string> signalFileNames;
Expand Down Expand Up @@ -87,7 +91,7 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
}
catch
{
}
}

string ORfilepath = System.IO.Path.Combine(routePath, "OpenRails");
if (File.Exists(ORfilepath + @"\sigcfg.dat"))
Expand All @@ -102,6 +106,72 @@ public RouteData(string routePath, MessageDelegate messageDelegate)
{
//sigcfgFile = null; // default initialization
}

// read the activity location events and store them in the TrackDB.TrItemTable

ActivityNames.Clear();
var directory = System.IO.Path.Combine(routePath, "ACTIVITIES");
if (System.IO.Directory.Exists(directory))
{
// counting
int cnt = 0;

foreach (var file in Directory.GetFiles(directory, "*.act"))
{
try
{
var activityFile = new ActivityFile(file);
Events events = activityFile.Tr_Activity.Tr_Activity_File.Events;
if (events != null)
{
for (int i = 0; i < events.EventList.Count; i++)
{
if (events.EventList[i].GetType() == typeof(EventCategoryLocation))
{
cnt++;
}
}
}
}
catch { }
}

// adding
uint index = 0;
foreach (var file in Directory.GetFiles(directory, "*.act"))
{
try
{
var activityFile = new ActivityFile(file);
Events events = activityFile.Tr_Activity.Tr_Activity_File.Events;
bool found = false;
if (events != null)
{
for (int i = 0; i < events.EventList.Count; i++)
{
if (events.EventList[i].GetType() == typeof(EventCategoryLocation))
{
EventCategoryLocation eventCategoryLocation = (EventCategoryLocation)events.EventList[i];
EventItem eventItem = new EventItem(
activityFile.Tr_Activity.Tr_Activity_Header.Name + ":" + eventCategoryLocation.Name,
eventCategoryLocation.Outcomes.DisplayMessage,
eventCategoryLocation.TileX, eventCategoryLocation.TileZ,
eventCategoryLocation.X, 0, eventCategoryLocation.Z,
index);
TrackDB.TrItemTable[index] = eventItem;
index++;
found = true;
}
}
}
if (found) {
ActivityNames.Add(activityFile.Tr_Activity.Tr_Activity_Header.Name);
}
}
catch { }
}

}
}

/// <summary>
Expand Down Expand Up @@ -176,6 +246,32 @@ public string GetSignalFilename(uint signalIndex)
}
}

/// <summary>
/// represents an Activity Location EventItem
/// </summary>
/// defined in this trackviewer file because I want to keep changes localized to the TrackViewer

public class EventItem : TrItem
{
/// <summary>
/// Default constructor, no file parsing used
/// </summary>
public EventItem(string itemName, string briefing, int tileX, int tileZ, float x, float y, float z, uint trItemId)
{
// ItemType is trEMPTY on purpose
// so that Orts.Formats.Msts.TrItem.trItemType does not need a change
ItemType = trItemType.trEMPTY;
ItemName = itemName;
TileX = tileX;
TileZ = tileZ;
X = x;
Y = y;
Z = z;
TrItemId = trItemId;
SData2 = briefing;
}
}

/// <summary>
/// This is a big class where the drawing of everything in the track data base is done.
/// This means tracks themselves (meaning so-called vector nodes that contain a number of sections,
Expand Down
48 changes: 48 additions & 0 deletions Source/Contrib/TrackViewer/Drawing/DrawableTrackItem.cs
Expand Up @@ -70,6 +70,7 @@ public static DrawableTrackItem CreateDrawableTrItem(TrItem originalTrItem)
if (originalTrItem is RoadLevelCrItem){ return new DrawableRoadLevelCrItem(originalTrItem); }
if (originalTrItem is CarSpawnerItem) { return new DrawableCarSpawnerItem(originalTrItem); }
if (originalTrItem is CrossoverItem) { return new DrawableCrossoverItem(originalTrItem); }
if (originalTrItem is EventItem) { return new DrawableEvent(originalTrItem); }
return new DrawableEmptyItem(originalTrItem);
}

Expand Down Expand Up @@ -605,4 +606,51 @@ internal override bool Draw(DrawArea drawArea, ColorScheme colors, bool drawAlwa
}
}
#endregion

#region DrawableEvent
/// <summary>
/// Represents a drawable event
/// </summary>
class DrawableEvent : DrawableTrackItem
{
private string ItemName;

/// <summary>
/// Default constructor
/// </summary>
/// <param name="originalTrItem">The original track item that we are representing for drawing</param>
public DrawableEvent(TrItem originalTrItem)
: base(originalTrItem)
{
Description = "event";
ItemName = originalTrItem.ItemName;
}

/// <summary>
/// Draw an event
/// </summary>
/// <param name="drawArea">The area to draw upon</param>
/// <param name="colors">The colorscheme to use</param>
/// <param name="drawAlways">Do we need to draw anyway, independent of settings?</param>
internal override bool Draw(DrawArea drawArea, ColorScheme colors, bool drawAlways)
{
bool returnValue = false;
if (String.IsNullOrEmpty(Properties.Settings.Default.CurrentActivityName) ||
(ItemName.StartsWith(Properties.Settings.Default.CurrentActivityName + ":")))
{
if (Properties.Settings.Default.showEvents || drawAlways)
{
drawArea.DrawTexture(WorldLocation, "disc", 6f, 0, colors.Event);
returnValue = true;
}
if (Properties.Settings.Default.showEventNames || drawAlways)
{
drawArea.DrawExpandingString(this.WorldLocation, ItemName);
returnValue = true;
}
}
return returnValue;
}
}
#endregion
}
1 change: 0 additions & 1 deletion Source/Contrib/TrackViewer/Editing/Charts/DrawPathChart.cs
Expand Up @@ -161,7 +161,6 @@ private void OnPathChanged()
}
pathData.Update(trainpath);
chartWindow.Draw();
chartWindow.SetTitle(pathEditor.CurrentTrainPath.PathName);
}

/// <summary>
Expand Down
Expand Up @@ -91,15 +91,6 @@ public void Draw()
}

}

/// <summary>
/// Set the title of the window
/// </summary>
/// <param name="newTitle"></param>
public void SetTitle(string newTitle)
{
this.Title = newTitle;
}
#endregion

#region Window events
Expand Down
55 changes: 53 additions & 2 deletions Source/Contrib/TrackViewer/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Source/Contrib/TrackViewer/Properties/Settings.settings
Expand Up @@ -122,6 +122,12 @@
<Setting Name="showSoundRegions" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="showEvents" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="showEventNames" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="showLabels" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
Expand Down Expand Up @@ -158,6 +164,9 @@
<Setting Name="statusShowNames" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="statusShowEventNames" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="statusShowTerrain" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
Expand Down
15 changes: 14 additions & 1 deletion Source/Contrib/TrackViewer/TrackViewer.cs
Expand Up @@ -220,6 +220,8 @@ protected override void Initialize()

drawPathChart = new DrawPathChart();

Properties.Settings.Default.CurrentActivityName = "";

base.Initialize();
}

Expand Down Expand Up @@ -519,6 +521,8 @@ protected override void Update(GameTime gameTime)
base.Update(gameTime);

HandleCommandLineArgs();

SetTitle();
}

/// <summary>
Expand Down Expand Up @@ -933,6 +937,7 @@ public void SetRoute(Route newRoute)
menuControl.PopulatePlatforms();
menuControl.PopulateStations();
menuControl.PopulateSidings();
menuControl.PopulateActivitiesMenu();
}

/// <summary>
Expand All @@ -942,7 +947,15 @@ void SetTitle()
{
Assembly assembly = Assembly.GetExecutingAssembly();
AssemblyTitleAttribute assemblyTitle = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0] as AssemblyTitleAttribute;
Window.Title = assemblyTitle.Title + ": " + RouteData.RouteName;
Window.Title = assemblyTitle.Title;
if ((RouteData != null) && (RouteData.RouteName != null))
{
Window.Title += ": " + RouteData.RouteName;
}
if (!String.IsNullOrEmpty(Properties.Settings.Default.CurrentActivityName))
{
Window.Title += " Activity: " + Properties.Settings.Default.CurrentActivityName;
}
}

#endregion
Expand Down