From c94847b607606c78e9b7793b28e2708898870c2c Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Wed, 15 Dec 2021 13:24:42 +0100 Subject: [PATCH] allow more tag entries to customize the views --- src/PlugIn.cpp | 77 ++++++++++++++++++++++++++++++++------------------ src/PlugIn.h | 5 +++- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/src/PlugIn.cpp b/src/PlugIn.cpp index 3d220b1..b7177a3 100644 --- a/src/PlugIn.cpp +++ b/src/PlugIn.cpp @@ -61,7 +61,10 @@ PlugIn::PlugIn() : m_playbackValid(false) { GOOGLE_PROTOBUF_VERIFY_VERSION; + this->RegisterTagItemType("ETA", static_cast(PlugIn::TagItemElement::EstimatedTimeOfArrival)); + this->RegisterTagItemType("PTA", static_cast(PlugIn::TagItemElement::PlannedTimeOfArrival)); this->RegisterTagItemType("Delta time", static_cast(PlugIn::TagItemElement::DeltaTime)); + this->RegisterTagItemType("Fixed plan indicator", static_cast(PlugIn::TagItemElement::FixedPlanIndicator)); this->RegisterTagItemFunction("Force planning", static_cast(PlugIn::TagItemFunction::ForceToBackendMenu)); this->DisplayUserMessage(PLUGIN_NAME, "INFO", (std::string("Loaded ") + PLUGIN_NAME + " " + PLUGIN_VERSION).c_str(), true, true, false, false, false); @@ -444,44 +447,64 @@ void PlugIn::OnGetTagItem(EuroScopePlugIn::CFlightPlan flightPlan, EuroScopePlug this->m_updateQueueLock.lock(); /* check if the inbound is forced */ - const auto cIt = std::find(this->m_forcedToBackendCallsigns.cbegin(), this->m_forcedToBackendCallsigns.cend(), callsign); - forced = this->m_forcedToBackendCallsigns.cend() != cIt; + if (0 != this->m_forcedToBackendCallsigns.size()) { + const auto cIt = std::find(this->m_forcedToBackendCallsigns.cbegin(), this->m_forcedToBackendCallsigns.cend(), callsign); + forced = this->m_forcedToBackendCallsigns.cend() != cIt; + } /* check if the inbound is expected to be planned */ planExpected = this->m_updateQueue.cend() != this->m_updateQueue.find(destination); this->m_updateQueueLock.unlock(); - if (TagItemElement::DeltaTime == static_cast(itemCode)) { - if (true == this->m_compatible) { - std::lock_guard guard(this->m_inboundsQueueLock); - auto it = this->m_inbounds.find(callsign); + std::lock_guard guard(this->m_inboundsQueueLock); + auto it = this->m_inbounds.find(callsign); - /* inbound expected, but not available */ - if (this->m_inbounds.cend() == it && (true == forced || true == planExpected)) { - std::strcpy(itemString, "* ??:??"); - } - /* inbound is available */ - else if (this->m_inbounds.cend() != it) { - const auto ttl = static_cast(std::roundf(it->second.timeToLose().convert(second))); - const auto minutes = ttl / 60; - const auto seconds = std::abs(ttl) % 60; - - std::stringstream stream; - stream << (true == it->second.fixedPlan() ? "" : "* ") << std::setw(2) << std::setfill('0') << minutes << ":" - << std::setw(2) << std::setfill('0') << seconds; - std::strcpy(itemString, stream.str().c_str()); - } - else { - gsl::at(tagString, 0) = '\0'; - } + std::string message; + switch (static_cast(itemCode)) { + case TagItemElement::EstimatedTimeOfArrival: + { + if (this->m_inbounds.cend() != it) + message = UtcTime::timeToString(it->second.eta(), "%H:%M"); + else if (true == forced || true == planExpected) + message = "??:??"; + break; + } + case TagItemElement::PlannedTimeOfArrival: + { + if (this->m_inbounds.cend() != it) + message = UtcTime::timeToString(it->second.pta(), "%H:%M"); + else if (true == forced || true == planExpected) + message = "??:??"; + break; + } + case TagItemElement::DeltaTime: + { + if (this->m_inbounds.cend() != it) { + const auto ttl = static_cast(std::roundf(it->second.timeToLose().convert(second))); + std::stringstream stream; + stream << ttl; + message = stream.str(); } - else { - std::strcpy(itemString, "N/A"); + else if (true == forced || true == planExpected) { + message = "??"; } + break; + } + case TagItemElement::FixedPlanIndicator: + if (this->m_inbounds.cend() != it && false == it->second.fixedPlan()) + message = "*"; + else if (this->m_inbounds.cend() == it && (true == forced || true == planExpected)) + message = "*"; + break; + default: + break; } - *colorCode = EuroScopePlugIn::TAG_COLOR_DEFAULT; + if (0 != message.length()) { + std::strcpy(itemString, message.c_str()); + *colorCode = EuroScopePlugIn::TAG_COLOR_DEFAULT; + } } void PlugIn::OnFunctionCall(int functionId, const char* itemString, POINT pt, RECT area) { diff --git a/src/PlugIn.h b/src/PlugIn.h index 35f1741..46dc828 100644 --- a/src/PlugIn.h +++ b/src/PlugIn.h @@ -42,7 +42,10 @@ namespace aman { private: enum class TagItemElement { - DeltaTime = 0 + EstimatedTimeOfArrival = 0, + PlannedTimeOfArrival = 1, + DeltaTime = 2, + FixedPlanIndicator = 3 }; void validateBackendData();