#include "ATCDialog.hxx"
#include "ATC.hxx"
#include "ATCmgr.hxx"
+#include "ATCdisplay.hxx"
#include "commlist.hxx"
#include "ATCutils.hxx"
#include <Airports/simple.hxx>
}
// ----------------------- Popup Dialog Statics------------------
-static puDialogBox* atcDialog;
-static puFrame* atcDialogFrame;
-static puText* atcDialogMessage;
-static puOneShot* atcDialogOkButton;
-static puOneShot* atcDialogCancelButton;
-static puButtonBox* atcDialogCommunicationOptions;
+static puDialogBox* atcDialog;
+static puFrame* atcDialogFrame;
+static puText* atcDialogMessage;
+static puOneShot* atcDialogOkButton;
+static puOneShot* atcDialogCancelButton;
+static puButtonBox* atcDialogCommunicationOptions;
// --------------------------------------------------------------
// ----------------------- Freq Dialog Statics-------------------
// --------------------------------------------------------------
//////////////// Popup callbacks ///////////////////
-static void ATCDialogOK(puObject *)
-{
- switch(atcDialogCommunicationOptions->getValue()) {
- case 0:
- //cout << "Option 0 chosen\n";
- fgSetBool("/sim/atc/opt0",true);
- break;
- case 1:
- //cout << "Option 1 chosen\n";
- fgSetBool("/sim/atc/opt1",true);
- break;
- case 2:
- //cout << "Option 2 chosen\n";
- fgSetBool("/sim/atc/opt2",true);
- break;
- case 3:
- //cout << "Option 2 chosen\n";
- fgSetBool("/sim/atc/opt3",true);
- break;
- default:
- break;
- }
+static void ATCDialogOK(puObject*) {
+ current_atcdialog->PopupCallback();
FG_POP_PUI_DIALOG( atcDialog );
}
-static void ATCDialogCancel(puObject *)
-{
+static void ATCDialogCancel(puObject*) {
FG_POP_PUI_DIALOG( atcDialog );
}
//////////////////////////////////////////////////
FGATCDialog::FGATCDialog() {
+ _callbackPending = false;
+ _callbackTimer = 0.0;
+ _callbackWait = 0.0;
+ _callbackPtr = NULL;
+ _callbackCode = 0;
}
FGATCDialog::~FGATCDialog() {
FG_FINALIZE_PUI_DIALOG(atcDialog);
}
+void FGATCDialog::Update(double dt) {
+ if(_callbackPending) {
+ if(_callbackTimer > _callbackWait) {
+ _callbackPtr->ReceiveUserCallback(_callbackCode);
+ _callbackPtr->NotifyTransmissionFinished(fgGetString("/sim/user/callsign"));
+ _callbackPending = false;
+ } else {
+ _callbackTimer += dt;
+ }
+ }
+}
+
// Add an entry
void FGATCDialog::add_entry(string station, string transmission, string menutext, atc_type type, int code) {
a.menuentry = menutext;
a.callback_code = code;
- //atcmentrylist_station[station.c_str()].push_back(a);
(available_dialog[type])[station.c_str()].push_back(a);
}
void FGATCDialog::remove_entry( const string &station, const string &trans, atc_type type ) {
- atcmentry_vec_type atcmlist = (available_dialog[type])[station];
- atcmentry_vec_iterator current = atcmlist.begin();
- atcmentry_vec_iterator last = atcmlist.end();
-
- while(current != last) {
- if(current->transmission == trans) current = atcmlist.erase(current);
+ atcmentry_vec_type* p = &((available_dialog[type])[station]);
+ atcmentry_vec_iterator current = p->begin();
+ while(current != p->end()) {
+ if(current->transmission == trans) current = p->erase(current);
else ++current;
}
}
void FGATCDialog::remove_entry( const string &station, int code, atc_type type ) {
- atcmentry_vec_type atcmlist = (available_dialog[type])[station];
- atcmentry_vec_iterator current = atcmlist.begin();
- atcmentry_vec_iterator last = atcmlist.end();
-
- while(current != last) {
- if(current->callback_code == code) current = atcmlist.erase(current);
+ atcmentry_vec_type* p = &((available_dialog[type])[station]);
+ atcmentry_vec_iterator current = p->begin();
+ while(current != p->end()) {
+ if(current->callback_code == code) current = p->erase(current);
else ++current;
}
}
// query the database whether the transmission is already registered;
bool FGATCDialog::trans_reg( const string &station, const string &trans, atc_type type ) {
- //atcmentry_list_type atcmlist = atcmentrylist_station[station];
- atcmentry_vec_type atcmlist = (available_dialog[type])[station];
- atcmentry_vec_iterator current = atcmlist.begin();
- atcmentry_vec_iterator last = atcmlist.end();
-
- for ( ; current != last ; ++current ) {
+ atcmentry_vec_type* p = &((available_dialog[type])[station]);
+ atcmentry_vec_iterator current = p->begin();
+ for ( ; current != p->end() ; ++current ) {
if ( current->transmission == trans ) return true;
}
return false;
// query the database whether the transmission is already registered;
bool FGATCDialog::trans_reg( const string &station, int code, atc_type type ) {
- //atcmentry_list_type atcmlist = atcmentrylist_station[station];
- atcmentry_vec_type atcmlist = (available_dialog[type])[station];
- atcmentry_vec_iterator current = atcmlist.begin();
- atcmentry_vec_iterator last = atcmlist.end();
-
- for ( ; current != last ; ++current ) {
+ atcmentry_vec_type* p = &((available_dialog[type])[station]);
+ atcmentry_vec_iterator current = p->begin();
+ for ( ; current != p->end() ; ++current ) {
if ( current->callback_code == code ) return true;
}
return false;
}
optList[k] = NULL;
atcDialogCommunicationOptions->newList(optList);
- atcDialogCommunicationOptions->setSize(w-100, h-100);
+ atcDialogCommunicationOptions->setSize(w-100, h-90);
atcDialogCommunicationOptions->reveal();
atcDialogMessage -> setLabel( "ATC Menu" );
atcDialogMessage -> setPosition(w / 2, h - 30);
FG_PUSH_PUI_DIALOG(atcDialog);
}
+void FGATCDialog::PopupCallback() {
+ FGATC* atcptr = globals->get_ATC_mgr()->GetComm1ATCPointer(); // FIXME - Hardwired to comm1 at the moment
+ if(atcptr) {
+ if(atcptr->GetType() == APPROACH) {
+ switch(atcDialogCommunicationOptions->getValue()) {
+ case 0:
+ fgSetBool("/sim/atc/opt0",true);
+ break;
+ case 1:
+ fgSetBool("/sim/atc/opt1",true);
+ break;
+ case 2:
+ fgSetBool("/sim/atc/opt2",true);
+ break;
+ case 3:
+ fgSetBool("/sim/atc/opt3",true);
+ break;
+ default:
+ break;
+ }
+ } else if(atcptr->GetType() == TOWER) {
+ //cout << "TOWER " << endl;
+ //cout << "ident is " << atcptr->get_ident() << endl;
+ atcmentry_vec_type atcmlist = (available_dialog[TOWER])[(string)atcptr->get_ident()];
+ if(atcmlist.size()) {
+ //cout << "Doing callback...\n";
+ ATCMenuEntry a = atcmlist[atcDialogCommunicationOptions->getValue()];
+ atcptr->SetFreqInUse();
+ globals->get_ATC_display()->RegisterSingleMessage(atcptr->GenText(a.transmission, a.callback_code));
+ _callbackPending = true;
+ _callbackTimer = 0.0;
+ _callbackWait = 5.0;
+ _callbackPtr = atcptr;
+ _callbackCode = a.callback_code;
+ } else {
+ //cout << "No options available...\n";
+ }
+ //cout << "Donded" << endl;
+ }
+ }
+}
void FGATCDialog::FreqDialog() {