]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/atcdialog.cxx
traffic: more pass by reference + member init
[flightgear.git] / src / ATC / atcdialog.cxx
index 51e319d5d6676a9a2ccdc864c05b51007ac3ab0e..1bf0c9cddaf04089f98bee2a290760b314f4e073 100644 (file)
@@ -44,6 +44,7 @@
 #include <Airports/simple.hxx>
 #include <ATC/CommStation.hxx>
 
+using std::string;
 
 static SGPropertyNode *getNamedNode(SGPropertyNode *prop, const char *name)
 {
@@ -144,17 +145,16 @@ void FGATCDialogNew::frequencyDisplay(const std::string& ident)
                return;
   }
   
-  int n = 0;
   for (unsigned int c=0; c < comms.size(); ++c) {
     flightgear::CommStation* comm = comms[c];
     
     // add frequency line (modified copy of <group-template>)
-               SGPropertyNode *entry = freq_group->getNode("group", n, true);
+               SGPropertyNode *entry = freq_group->getNode("group", c, true);
                copyProperties(freq_group->getNode("group-template", true), entry);
                entry->removeChildren("enabled", true);
     
     entry->setStringValue("text[0]/label", comm->ident());
-    
+
                char buf[8];
                snprintf(buf, 8, "%.2f", comm->freqMHz());
                if(buf[5] == '3') buf[5] = '2';
@@ -162,7 +162,6 @@ void FGATCDialogNew::frequencyDisplay(const std::string& ident)
                buf[7] = '\0';
     
                entry->setStringValue("text[1]/label", buf);
-    ++n;
   }
   
        _gui->showDialog(dialog_name);
@@ -188,8 +187,9 @@ static bool doFrequencyDisplay( const SGPropertyNode* args )
 FGATCDialogNew * FGATCDialogNew::_instance = NULL;
 
 FGATCDialogNew::FGATCDialogNew()
+: _gui(NULL),
+   dialogVisible(true)
 {
-  dialogVisible = true;
 }
 
 FGATCDialogNew::~FGATCDialogNew()
@@ -199,15 +199,15 @@ FGATCDialogNew::~FGATCDialogNew()
 
 
 void FGATCDialogNew::init() {
-       // Add ATC-dialog to the command list
+    // Add ATC-dialog to the command list
     globals->get_commands()->addCommand("ATC-dialog", FGATCDialogNew::popup );
-       // Add ATC-freq-search to the command list
-       globals->get_commands()->addCommand("ATC-freq-search", doFrequencySearch);
-  globals->get_commands()->addCommand("ATC-freq-display", doFrequencyDisplay);
+    // Add ATC-freq-search to the command list
+    globals->get_commands()->addCommand("ATC-freq-search", doFrequencySearch);
+    globals->get_commands()->addCommand("ATC-freq-display", doFrequencyDisplay);
   
-       // initialize properties polled in Update()
-       //globals->get_props()->setStringValue("/sim/atc/freq-airport", "");
-       globals->get_props()->setIntValue("/sim/atc/transmission-num", -1);
+    // initialize properties polled in Update()
+    //globals->get_props()->setStringValue("/sim/atc/freq-airport", "");
+    globals->get_props()->setIntValue("/sim/atc/transmission-num", -1);
 }
 
 
@@ -247,6 +247,10 @@ void FGATCDialogNew::update(double dt) {
 
     const char *dialog_name = "atc-dialog";
     _gui = (NewGUI *)globals->get_subsystem("gui");
+    if (!_gui) {
+      return;
+    }
+  
     SGPropertyNode_ptr dlg = _gui->getDialogProperties(dialog_name);
     if (!dlg)
         return;
@@ -283,14 +287,4 @@ void FGATCDialogNew::update(double dt) {
     } else {
         _gui->showDialog(dialog_name);
     }
-    //dialogVisible = !dialogVisible;
-    return;
-    /*
-    static SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true);
-    int n = trans_num->getIntValue();
-    if (n >= 0) {
-        trans_num->setIntValue(-1);
-           // PopupCallback(n);
-        cerr << "Selected transmission message" << n << endl;
-    } */
 }