mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #393, allow to highlight a certain aircraft by blinking
* signatures in contexts * some specialized functions in aircraft list * context menus in aircraft view * default "blinking" implementation in driver common base class
This commit is contained in:
@@ -8,8 +8,11 @@
|
||||
*/
|
||||
|
||||
#include "simulator.h"
|
||||
#include "interpolator.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackSim;
|
||||
|
||||
namespace BlackCore
|
||||
@@ -21,7 +24,80 @@ namespace BlackCore
|
||||
|
||||
CSimulatorCommon::CSimulatorCommon(const BlackSim::CSimulatorInfo &simInfo, BlackMisc::Simulation::IOwnAircraftProvider *ownAircraftProvider, BlackMisc::Simulation::IRemoteAircraftProvider *remoteAircraftProvider, QObject *parent)
|
||||
: ISimulator(parent), COwnAircraftProviderSupport(ownAircraftProvider), CRemoteAircraftProviderSupport(remoteAircraftProvider), m_simulatorInfo(simInfo)
|
||||
{ }
|
||||
{
|
||||
m_oneSecondTimer = new QTimer(this);
|
||||
connect(this->m_oneSecondTimer, &QTimer::timeout, this, &CSimulatorCommon::ps_oneSecondTimer);
|
||||
m_oneSecondTimer->start(1000);
|
||||
}
|
||||
|
||||
void CSimulatorCommon::blinkHighlightedAircraft()
|
||||
{
|
||||
if (m_highlightedAircraft.isEmpty() || m_highlightEndTimeMsEpoch < 1) { return; }
|
||||
m_blinkCycle = !m_blinkCycle;
|
||||
|
||||
if (QDateTime::currentMSecsSinceEpoch() < m_highlightEndTimeMsEpoch)
|
||||
{
|
||||
// blink mode, toggle aircraft
|
||||
for (const CSimulatedAircraft &aircraft : m_highlightedAircraft)
|
||||
{
|
||||
if (m_blinkCycle)
|
||||
{
|
||||
this->removeRemoteAircraft(aircraft.getCallsign());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->addRemoteAircraft(aircraft);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// restore
|
||||
for (const CSimulatedAircraft &aircraft : m_highlightedAircraft)
|
||||
{
|
||||
// get the current state for this aircraft
|
||||
// it might has been removed in the mean time
|
||||
const CCallsign cs(aircraft.getCallsign());
|
||||
resetAircraftFromBacked(cs);
|
||||
}
|
||||
m_highlightedAircraft.clear();
|
||||
m_highlightEndTimeMsEpoch = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorCommon::resetAircraftFromBacked(const CCallsign &callsign)
|
||||
{
|
||||
CSimulatedAircraft aircraft(this->remoteAircraft().findFirstByCallsign(callsign));
|
||||
bool enabled = aircraft.isEnabled();
|
||||
if (enabled)
|
||||
{
|
||||
// are we already visible?
|
||||
if (!isRenderedAircraft(callsign))
|
||||
{
|
||||
this->addRemoteAircraft(aircraft);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
removeRemoteAircraft(callsign);
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorCommon::setInitialAircraftSituationAndParts(CSimulatedAircraft &aircraft) const
|
||||
{
|
||||
if (!this->m_interpolator) { return; }
|
||||
|
||||
const CCallsign callsign(aircraft.getCallsign());
|
||||
if (!this->m_interpolator->hasDataForCallsign(callsign)) { return; }
|
||||
|
||||
// with an interpolator the interpolated situation is used
|
||||
// to avoid position jittering
|
||||
qint64 time = QDateTime::currentMSecsSinceEpoch();
|
||||
IInterpolator::InterpolationStatus is;
|
||||
CAircraftSituation as(m_interpolator->getInterpolatedSituation(callsign, time, is));
|
||||
if (is.interpolationSucceeded) { aircraft.setSituation(as); }
|
||||
|
||||
}
|
||||
|
||||
int CSimulatorCommon::getMaxRenderedAircraft() const
|
||||
{
|
||||
@@ -50,4 +126,26 @@ namespace BlackCore
|
||||
return getInstalledModels().size();
|
||||
}
|
||||
|
||||
void CSimulatorCommon::highlightAircraft(const BlackMisc::Simulation::CSimulatedAircraft &aircraftToHighlight, bool enableHighlight, const BlackMisc::PhysicalQuantities::CTime &displayTime)
|
||||
{
|
||||
CCallsign cs(aircraftToHighlight.getCallsign());
|
||||
this->m_highlightedAircraft.removeByCallsign(cs);
|
||||
if (enableHighlight)
|
||||
{
|
||||
qint64 deltaT = displayTime.valueRounded(CTimeUnit::ms(), 0);
|
||||
this->m_highlightEndTimeMsEpoch = QDateTime::currentMSecsSinceEpoch() + deltaT;
|
||||
this->m_highlightedAircraft.push_back(aircraftToHighlight);
|
||||
}
|
||||
}
|
||||
|
||||
bool CSimulatorCommon::isRenderingEnabled() const
|
||||
{
|
||||
return m_maxRenderedAircraft < 1;
|
||||
}
|
||||
|
||||
void CSimulatorCommon::ps_oneSecondTimer()
|
||||
{
|
||||
blinkHighlightedAircraft();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user