diff --git a/src/xswiftbus/traffic.cpp b/src/xswiftbus/traffic.cpp index 76ecfa72e..5d724f8bb 100644 --- a/src/xswiftbus/traffic.cpp +++ b/src/xswiftbus/traffic.cpp @@ -45,7 +45,8 @@ namespace XSwiftBus CTraffic::CTraffic(CDBusConnection *dbusConnection) : CDBusObject(dbusConnection), - m_followPlaneViewNextCommand("org/swift-project/xswiftbus/follow_next_plane", "Changes plane view to follow next plane in sequence", [this] { followNextPlane(); }) + m_followPlaneViewNextCommand("org/swift-project/xswiftbus/follow_next_plane", "Changes plane view to follow next plane in sequence", [this] { followNextPlane(); }), + m_followPlaneViewPreviousCommand("org/swift-project/xswiftbus/follow_previous_plane", "Changes plane view to follow previous plane in sequence", [this] { followPreviousPlane(); }) { registerDBusObjectPath(XSWIFTBUS_TRAFFIC_INTERFACENAME, XSWIFTBUS_TRAFFIC_OBJECTPATH); XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this); @@ -160,6 +161,19 @@ namespace XSwiftBus m_followPlaneViewCallsign = *callsignIt; } + void CTraffic::followPreviousPlane() + { + if (m_planesByCallsign.empty() || m_followPlaneViewCallsign.empty()) { return; } + auto callsignIt = std::find(m_followPlaneViewSequence.rbegin(), m_followPlaneViewSequence.rend(), m_followPlaneViewCallsign); + + // If we are not at the end, increase by one + if (callsignIt != m_followPlaneViewSequence.rend()) { callsignIt++; } + // If we were already at the end or reached it now, start from the beginning + if (callsignIt == m_followPlaneViewSequence.rend()) { callsignIt = m_followPlaneViewSequence.rbegin(); } + + m_followPlaneViewCallsign = *callsignIt; + } + int g_maxPlanes = 100; float g_drawDistance = 50.0f; diff --git a/src/xswiftbus/traffic.h b/src/xswiftbus/traffic.h index 1c4163656..fba846a8c 100644 --- a/src/xswiftbus/traffic.h +++ b/src/xswiftbus/traffic.h @@ -134,6 +134,7 @@ namespace XSwiftBus void emitPlaneAddingFailed(const std::string &callsign); void enableFollowPlaneView(const std::string &callsign); void followNextPlane(); + void followPreviousPlane(); static int preferences(const char *section, const char *name, int def); static float preferences(const char *section, const char *name, float def); @@ -169,12 +170,12 @@ namespace XSwiftBus CMenu m_followPlaneViewSubMenu; std::unordered_map m_followPlaneViewMenuItems; std::string m_followPlaneViewCallsign; + CCommand m_followPlaneViewNextCommand; + CCommand m_followPlaneViewPreviousCommand; DataRef m_worldRenderType; bool m_emitSimFrame = true; - CCommand m_followPlaneViewNextCommand; - int getPlaneData(void *id, int dataType, void *io_data); static int getPlaneData(void *id, int dataType, void *io_data, void *self) {