-
Notifications
You must be signed in to change notification settings - Fork 22
/
PrenoteModule.cpp
212 lines (187 loc) · 10.6 KB
/
PrenoteModule.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "AcknowledgePrenoteMessage.h"
#include "CancelPrenoteMessageMenu.h"
#include "NewPrenotePushEventHandler.h"
#include "PlayNewPrenoteMessageSound.h"
#include "PrenoteAcknowledgedPushEventHandler.h"
#include "PrenoteDeletedPushEventHandler.h"
#include "PrenoteEventHandler.h"
#include "PrenoteIsSentFromUsersPosition.h"
#include "PrenoteIsTargetedToUser.h"
#include "PrenoteMessageCollection.h"
#include "PrenoteMessageEventHandlerCollection.h"
#include "PrenoteMessageStatusView.h"
#include "PrenoteMessageTimeout.h"
#include "PrenoteModule.h"
#include "PrenoteService.h"
#include "PrenoteStatusIndicatorTagItem.h"
#include "PublishedPrenoteCollection.h"
#include "PublishedPrenoteCollectionFactory.h"
#include "PublishedPrenoteMapper.h"
#include "SendNewPrenoteChatAreaMessage.h"
#include "SendPrenoteAcknowledgedChatAreaMessage.h"
#include "SendPrenoteCancelledChatAreaMessage.h"
#include "SendPrenoteMenu.h"
#include "TriggerPrenoteMessageStatusView.h"
#include "bootstrap/BootstrapWarningMessage.h"
#include "bootstrap/PersistenceContainer.h"
#include "controller/ControllerPosition.h"
#include "controller/ControllerPositionHierarchy.h"
#include "controller/ControllerPositionHierarchyFactory.h"
#include "dependency/DependencyLoaderInterface.h"
#include "euroscope/CallbackFunction.h"
#include "flightplan/FlightPlanEventHandlerCollection.h"
#include "message/UserMessager.h"
#include "plugin/FunctionCallEventHandler.h"
#include "plugin/UKPlugin.h"
#include "push/PushEventProcessorCollection.h"
#include "tag/TagItemCollection.h"
#include "timedevent/TimedEventCollection.h"
using UKControllerPlugin::Bootstrap::BootstrapWarningMessage;
using UKControllerPlugin::Bootstrap::PersistenceContainer;
using UKControllerPlugin::Controller::ControllerPositionCollection;
using UKControllerPlugin::Controller::ControllerPositionHierarchy;
using UKControllerPlugin::Controller::ControllerPositionHierarchyFactory;
using UKControllerPlugin::Dependency::DependencyLoaderInterface;
using UKControllerPlugin::Euroscope::CallbackFunction;
using UKControllerPlugin::Prenote::DeparturePrenote;
using UKControllerPlugin::Prenote::PrenoteEventHandler;
using UKControllerPlugin::RadarScreen::RadarRenderableCollection;
using UKControllerPlugin::Tag::TagFunction;
using UKControllerPlugin::Tag::TagItemCollection;
namespace UKControllerPlugin::Prenote {
const int MESSAGE_STATUS_INDICATOR_TAG_ITEM_ID = 127;
const int CANCEL_MESSAGE_MENU_TAG_FUNCTION_ID = 9016;
const int SEND_MESSAGE_MENU_TAG_FUNCTION_ID = 9017;
const int MESSAGE_STATUS_VIEW_TAG_FUNCTION_ID = 9018;
const int ACKNOWLEDGE_MESSAGE_TAG_FUNCTION_ID = 9019;
const int MESSAGE_TIMEOUT_CHECK_INTERVAL = 10;
std::shared_ptr<AcknowledgePrenoteMessage> acknowledge; // NOLINT
std::unique_ptr<PublishedPrenoteCollection> prenotes; // NOLINT
std::unique_ptr<PublishedPrenoteMapper> mapper; // NOLINT
void PrenoteModule::BootstrapPlugin(PersistenceContainer& persistence, DependencyLoaderInterface& dependency)
{
// Prenote reminders bootstrap
prenotes = CreatePublishedPrenoteCollection(
dependency.LoadDependency(GetDependencyKey(), nlohmann::json::array()),
*persistence.controllerHierarchyFactory);
mapper = std::make_unique<PublishedPrenoteMapper>(
*prenotes, *persistence.airfields, *persistence.sidMapper, *persistence.flightRules);
ControllerPositionHierarchyFactory hierarchyFactory(*persistence.controllerPositions);
persistence.flightplanHandler->RegisterHandler(std::make_shared<PrenoteEventHandler>(
std::make_unique<PrenoteService>(
*mapper, *persistence.airfieldOwnership, *persistence.activeCallsigns, *persistence.userMessager),
*persistence.pluginUserSettingHandler));
// Electronic prenote messages
const auto userTargetPrenoteRelevance = std::make_shared<PrenoteIsTargetedToUser>(*persistence.activeCallsigns);
const auto userSendingPrenoteRelevance =
std::make_shared<PrenoteIsSentFromUsersPosition>(*persistence.activeCallsigns);
persistence.prenotes = std::make_shared<PrenoteMessageCollection>();
persistence.prenoteMessageHandlers = std::make_unique<PrenoteMessageEventHandlerCollection>();
persistence.prenoteMessageHandlers->AddHandler(
std::make_shared<PlayNewPrenoteMessageSound>(userTargetPrenoteRelevance, *persistence.windows));
persistence.prenoteMessageHandlers->AddHandler(
std::make_shared<SendNewPrenoteChatAreaMessage>(userTargetPrenoteRelevance, *persistence.plugin));
persistence.prenoteMessageHandlers->AddHandler(
std::make_shared<SendPrenoteCancelledChatAreaMessage>(userTargetPrenoteRelevance, *persistence.plugin));
persistence.prenoteMessageHandlers->AddHandler(
std::make_shared<SendPrenoteAcknowledgedChatAreaMessage>(userSendingPrenoteRelevance, *persistence.plugin));
// Push event processors
persistence.pushEventProcessors->AddProcessor(std::make_shared<NewPrenotePushEventHandler>(
persistence.prenotes, *persistence.controllerPositions, *persistence.prenoteMessageHandlers));
persistence.pushEventProcessors->AddProcessor(std::make_shared<PrenoteAcknowledgedPushEventHandler>(
persistence.prenotes, *persistence.prenoteMessageHandlers));
persistence.pushEventProcessors->AddProcessor(std::make_shared<PrenoteDeletedPushEventHandler>(
persistence.prenotes, *persistence.prenoteMessageHandlers));
persistence.timedHandler->RegisterEvent(
std::make_shared<PrenoteMessageTimeout>(persistence.prenotes), MESSAGE_TIMEOUT_CHECK_INTERVAL);
// Status indicator tag item
persistence.tagHandler->RegisterTagItem(
MESSAGE_STATUS_INDICATOR_TAG_ITEM_ID,
std::make_shared<PrenoteStatusIndicatorTagItem>(persistence.prenotes));
// Cancelling prenote messages menu
auto cancelCallback = persistence.pluginFunctionHandlers->ReserveNextDynamicFunctionId();
auto cancelMenu = std::make_shared<CancelPrenoteMessageMenu>(
persistence.prenotes,
*persistence.controllerPositions,
*persistence.activeCallsigns,
*persistence.plugin,
*persistence.taskRunner,
*persistence.api,
cancelCallback);
TagFunction openCancelPrenoteMenu(
CANCEL_MESSAGE_MENU_TAG_FUNCTION_ID,
"Open Cancel Prenote Message Menu",
[cancelMenu](
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& fp,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& rt,
const std::string& context,
const POINT& mousePos) { cancelMenu->DisplayPrenoteToDeleteMenu(fp, mousePos); });
persistence.pluginFunctionHandlers->RegisterFunctionCall(openCancelPrenoteMenu);
CallbackFunction cancelPrenoteCallback(
cancelCallback, "Prenote Cancel", [cancelMenu](int functionId, std::string subject, RECT screenObjectArea) {
cancelMenu->ControllerForPrenoteDeletionSelected(std::move(subject));
});
persistence.pluginFunctionHandlers->RegisterFunctionCall(cancelPrenoteCallback);
// Send prenote messages menu
auto sendCallback = persistence.pluginFunctionHandlers->ReserveNextDynamicFunctionId();
auto sendMenu = std::make_shared<SendPrenoteMenu>(
persistence.prenotes,
*persistence.controllerPositions,
*persistence.activeCallsigns,
*persistence.plugin,
*persistence.taskRunner,
*persistence.api,
sendCallback);
TagFunction openSendPrenoteMenu(
SEND_MESSAGE_MENU_TAG_FUNCTION_ID,
"Open Prenote Controller Selection Menu",
[sendMenu](
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& fp,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& rt,
const std::string& context,
const POINT& mousePos) { sendMenu->DisplayControllerSelectionMenu(fp, mousePos); });
persistence.pluginFunctionHandlers->RegisterFunctionCall(openSendPrenoteMenu);
CallbackFunction sendPrenoteCallback(
sendCallback, "Prenote Send", [sendMenu](int functionId, std::string subject, RECT screenObjectArea) {
sendMenu->ControllerForPrenoteSelected(std::move(subject));
});
persistence.pluginFunctionHandlers->RegisterFunctionCall(sendPrenoteCallback);
// Acknowledge message
acknowledge = std::make_shared<AcknowledgePrenoteMessage>(
persistence.prenotes, *persistence.activeCallsigns, *persistence.taskRunner, *persistence.api);
auto acknowledgeForTagFunction = acknowledge;
TagFunction acknowledgePrenoteMessage(
ACKNOWLEDGE_MESSAGE_TAG_FUNCTION_ID,
"Acknowledge Prenote",
[acknowledgeForTagFunction](
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& fp,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& rt,
const std::string& context,
const POINT& mousePos) { acknowledgeForTagFunction->Acknowledge(fp); });
persistence.pluginFunctionHandlers->RegisterFunctionCall(acknowledgePrenoteMessage);
// Prenote message status view
auto statusViewTagFunction = std::make_shared<TriggerPrenoteMessageStatusView>();
TagFunction triggerStatusView(
MESSAGE_STATUS_VIEW_TAG_FUNCTION_ID,
"Open Prenote Message Status View",
[statusViewTagFunction](
UKControllerPlugin::Euroscope::EuroScopeCFlightPlanInterface& fp,
UKControllerPlugin::Euroscope::EuroScopeCRadarTargetInterface& rt,
const std::string& context,
const POINT& mousePos) { statusViewTagFunction->Trigger(fp, mousePos); });
persistence.pluginFunctionHandlers->RegisterFunctionCall(triggerStatusView);
}
void PrenoteModule::BootstrapRadarScreen(
const PersistenceContainer& persistence, RadarRenderableCollection& radarRenderables)
{
// Status view renderer
radarRenderables.RegisterRenderer(
radarRenderables.ReserveRendererIdentifier(),
std::make_shared<PrenoteMessageStatusView>(persistence.prenotes, *persistence.controllerPositions),
RadarRenderableCollection::afterLists);
}
auto PrenoteModule::GetDependencyKey() -> std::string
{
return "DEPENDENCY_PRENOTES_V2";
}
} // namespace UKControllerPlugin::Prenote