]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATCDialog.cxx
Multiplayer client/server system -- MessageBuf class and test harness complete
[flightgear.git] / src / ATC / ATCDialog.cxx
index 6b55eb7708562d9f60083ab980a1b6b3133c1cac..c83b514ede2da6ad0056e7cfce1a634be49a9bd6 100644 (file)
@@ -28,6 +28,7 @@
 #include "ATCDialog.hxx"
 #include "ATC.hxx"
 #include "ATCmgr.hxx"
+#include "ATCdisplay.hxx"
 #include "commlist.hxx"
 #include "ATCutils.hxx"
 #include <Airports/simple.hxx>
@@ -67,12 +68,12 @@ static void atcUppercase(string &s) {
 }
 
 // ----------------------- 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-------------------
@@ -93,33 +94,12 @@ static puText*          atcFreqDisplayText[ATC_MAX_FREQ_DISPLAY];
 // --------------------------------------------------------------
 
 //////////////// 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 );
 }
 //////////////////////////////////////////////////
@@ -143,6 +123,11 @@ static void FreqDisplayOK(puObject*) {
 
 
 FGATCDialog::FGATCDialog() {
+       _callbackPending = false;
+       _callbackTimer = 0.0;
+       _callbackWait = 0.0;
+       _callbackPtr = NULL;
+       _callbackCode = 0;
 }
 
 FGATCDialog::~FGATCDialog() {
@@ -247,6 +232,18 @@ void FGATCDialog::Init() {
        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) {
 
@@ -257,41 +254,33 @@ void FGATCDialog::add_entry(string station, string transmission, string menutext
   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;
@@ -299,12 +288,9 @@ bool FGATCDialog::trans_reg( const string &station, const string &trans, atc_typ
 
 // 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;
@@ -369,7 +355,7 @@ void FGATCDialog::PopupDialog() {
                                } 
                                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);
@@ -389,7 +375,39 @@ void FGATCDialog::PopupDialog() {
        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) {
+                       ATCMenuEntry a = ((available_dialog[TOWER])[(string)atcptr->get_ident()])[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;
+               }
+       }
+}
 
 void FGATCDialog::FreqDialog() {