mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
Add new command to jump to next plane in follow plane view
ref T269
This commit is contained in:
committed by
Klaus Basan
parent
d41bd1d26c
commit
10b8cf5fea
@@ -44,7 +44,8 @@ namespace XSwiftBus
|
|||||||
}
|
}
|
||||||
|
|
||||||
CTraffic::CTraffic(CDBusConnection *dbusConnection) :
|
CTraffic::CTraffic(CDBusConnection *dbusConnection) :
|
||||||
CDBusObject(dbusConnection)
|
CDBusObject(dbusConnection),
|
||||||
|
m_planeViewNextCommand("org/swift-project/xswiftbus/follow_next_plane", "Changes plane view to follow next plane in sequence", [this] { followNextPlane(); })
|
||||||
{
|
{
|
||||||
registerDBusObjectPath(XSWIFTBUS_TRAFFIC_INTERFACENAME, XSWIFTBUS_TRAFFIC_OBJECTPATH);
|
registerDBusObjectPath(XSWIFTBUS_TRAFFIC_INTERFACENAME, XSWIFTBUS_TRAFFIC_OBJECTPATH);
|
||||||
XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
XPLMRegisterDrawCallback(drawCallback, xplm_Phase_Airplanes, 1, this);
|
||||||
@@ -146,6 +147,19 @@ namespace XSwiftBus
|
|||||||
XPLMControlCamera(xplm_ControlCameraUntilViewChanges, orbitPlaneFunc, this);
|
XPLMControlCamera(xplm_ControlCameraUntilViewChanges, orbitPlaneFunc, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CTraffic::followNextPlane()
|
||||||
|
{
|
||||||
|
if (m_planesByCallsign.empty() || m_planeViewCallsign.empty()) { return; }
|
||||||
|
auto callsignIt = std::find(m_followPlaneViewSequence.begin(), m_followPlaneViewSequence.end(), m_planeViewCallsign);
|
||||||
|
|
||||||
|
// If we are not at the end, increase by one
|
||||||
|
if (callsignIt != m_followPlaneViewSequence.end()) { callsignIt++; }
|
||||||
|
// If we were already at the end or reached it now, start from the beginning
|
||||||
|
if (callsignIt == m_followPlaneViewSequence.end()) { callsignIt = m_followPlaneViewSequence.begin(); }
|
||||||
|
|
||||||
|
m_planeViewCallsign = *callsignIt;
|
||||||
|
}
|
||||||
|
|
||||||
int g_maxPlanes = 100;
|
int g_maxPlanes = 100;
|
||||||
float g_drawDistance = 50.0f;
|
float g_drawDistance = 50.0f;
|
||||||
|
|
||||||
@@ -239,6 +253,7 @@ namespace XSwiftBus
|
|||||||
// Create view menu item
|
// Create view menu item
|
||||||
CMenuItem planeViewMenuItem = m_planeViewSubMenu.item(callsign, [this, callsign] { switchToPlaneView(callsign); });
|
CMenuItem planeViewMenuItem = m_planeViewSubMenu.item(callsign, [this, callsign] { switchToPlaneView(callsign); });
|
||||||
m_planeViewMenuItems[callsign] = planeViewMenuItem;
|
m_planeViewMenuItems[callsign] = planeViewMenuItem;
|
||||||
|
m_followPlaneViewSequence.push_back(callsign);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,6 +269,9 @@ namespace XSwiftBus
|
|||||||
auto planeIt = m_planesByCallsign.find(callsign);
|
auto planeIt = m_planesByCallsign.find(callsign);
|
||||||
if (planeIt == m_planesByCallsign.end()) { return; }
|
if (planeIt == m_planesByCallsign.end()) { return; }
|
||||||
|
|
||||||
|
m_followPlaneViewSequence.erase(std::remove(m_followPlaneViewSequence.begin(), m_followPlaneViewSequence.end(), callsign),
|
||||||
|
m_followPlaneViewSequence.end());
|
||||||
|
|
||||||
Plane *plane = planeIt->second;
|
Plane *plane = planeIt->second;
|
||||||
m_planesByCallsign.erase(callsign);
|
m_planesByCallsign.erase(callsign);
|
||||||
m_planesById.erase(plane->id);
|
m_planesById.erase(plane->id);
|
||||||
@@ -280,6 +298,7 @@ namespace XSwiftBus
|
|||||||
m_planesByCallsign.clear();
|
m_planesByCallsign.clear();
|
||||||
m_planesById.clear();
|
m_planesById.clear();
|
||||||
m_planeViewMenuItems.clear();
|
m_planeViewMenuItems.clear();
|
||||||
|
m_followPlaneViewSequence.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTraffic::setPlanesPositions(const std::vector<std::string> &callsigns, std::vector<double> latitudes, std::vector<double> longitudes, std::vector<double> altitudes,
|
void CTraffic::setPlanesPositions(const std::vector<std::string> &callsigns, std::vector<double> latitudes, std::vector<double> longitudes, std::vector<double> altitudes,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
//! \file
|
//! \file
|
||||||
|
|
||||||
#include "dbusobject.h"
|
#include "dbusobject.h"
|
||||||
|
#include "command.h"
|
||||||
#include "datarefs.h"
|
#include "datarefs.h"
|
||||||
#include "terrainprobe.h"
|
#include "terrainprobe.h"
|
||||||
#include "menus.h"
|
#include "menus.h"
|
||||||
@@ -132,6 +133,7 @@ namespace XSwiftBus
|
|||||||
void emitPlaneAdded(const std::string &callsign);
|
void emitPlaneAdded(const std::string &callsign);
|
||||||
void emitPlaneAddingFailed(const std::string &callsign);
|
void emitPlaneAddingFailed(const std::string &callsign);
|
||||||
void switchToPlaneView(const std::string &callsign);
|
void switchToPlaneView(const std::string &callsign);
|
||||||
|
void followNextPlane();
|
||||||
|
|
||||||
static int preferences(const char *section, const char *name, int def);
|
static int preferences(const char *section, const char *name, int def);
|
||||||
static float preferences(const char *section, const char *name, float def);
|
static float preferences(const char *section, const char *name, float def);
|
||||||
@@ -161,6 +163,7 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
std::unordered_map<std::string, Plane *> m_planesByCallsign;
|
std::unordered_map<std::string, Plane *> m_planesByCallsign;
|
||||||
std::unordered_map<void *, Plane *> m_planesById;
|
std::unordered_map<void *, Plane *> m_planesById;
|
||||||
|
std::vector<std::string> m_followPlaneViewSequence;
|
||||||
std::chrono::system_clock::time_point m_timestampLastSimFrame = std::chrono::system_clock::now();
|
std::chrono::system_clock::time_point m_timestampLastSimFrame = std::chrono::system_clock::now();
|
||||||
|
|
||||||
CMenu m_planeViewSubMenu;
|
CMenu m_planeViewSubMenu;
|
||||||
@@ -170,6 +173,8 @@ namespace XSwiftBus
|
|||||||
DataRef<xplane::data::sim::graphics::view::world_render_type> m_worldRenderType;
|
DataRef<xplane::data::sim::graphics::view::world_render_type> m_worldRenderType;
|
||||||
bool m_emitSimFrame = true;
|
bool m_emitSimFrame = true;
|
||||||
|
|
||||||
|
CCommand m_planeViewNextCommand;
|
||||||
|
|
||||||
int getPlaneData(void *id, int dataType, void *io_data);
|
int getPlaneData(void *id, int dataType, void *io_data);
|
||||||
static int getPlaneData(void *id, int dataType, void *io_data, void *self)
|
static int getPlaneData(void *id, int dataType, void *io_data, void *self)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user