]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATCDialog.cxx
The most important part is that it fixes possible
[flightgear.git] / src / ATC / ATCDialog.cxx
index def15c132252e85020fc3a8fb6271cbc25eb2784..0f1bc8e652c4bba38acbee0ec0c83cbc2af2f225 100644 (file)
@@ -71,14 +71,17 @@ static void atcUppercase(string &s) {
 }
 
 // find child whose <name>...</name> entry matches 'name'
-static SGPropertyNode_ptr namedNode(const vector<SGPropertyNode_ptr> &children, const char *name) {
-       SGPropertyNode_ptr ret;
-       for (int i = 0; i < children.size(); i++)
-               if (!strcmp(children[i]->getStringValue("name"), name)) {
-                       ret = children[i];
-                       break;
-               }
-       return ret;
+static SGPropertyNode *getNamedNode(SGPropertyNode *prop, const char *name) {
+       SGPropertyNode* p;
+
+       for (int i = 0; i < prop->nChildren(); i++)
+               if ((p = getNamedNode(prop->getChild(i), name)))
+                       return p;
+
+       if (!strcmp(prop->getStringValue("name"), name))
+               return prop;
+
+       return 0;
 }
 
 
@@ -192,7 +195,7 @@ void FGATCDialog::PopupDialog() {
 
        _gui->closeDialog(dialog_name);
 
-       SGPropertyNode_ptr button_group = namedNode(dlg->getChildren("group"), "transmission-choice");
+       SGPropertyNode_ptr button_group = getNamedNode(dlg, "transmission-choice");
        // remove all transmission buttons
        button_group->removeChildren("button", false);
 
@@ -236,6 +239,7 @@ void FGATCDialog::PopupDialog() {
                copyProperties(button_group->getNode("button-template", true), entry);
                entry->removeChildren("hide", false);
                entry->setStringValue("property", buf);
+               entry->setIntValue("keynum", '1' + n);
                if (n == 0)
                        entry->setBoolValue("default", true);
 
@@ -285,10 +289,10 @@ struct atcdata {
                id = i, name = n, distance = d;
        }
        bool operator<(const atcdata& a) const {
-               return a.id != id && a.distance > distance;
+               return id != a.id && distance < a.distance;
        }
        bool operator==(const atcdata& a) const {
-               return a.distance == distance && a.id == id;
+               return id == a.id && distance == a.distance;
        }
        string id;
        string name;
@@ -303,8 +307,8 @@ void FGATCDialog::FreqDialog() {
 
        _gui->closeDialog(dialog_name);
 
-       SGPropertyNode_ptr button_group = namedNode(dlg->getChildren("group"), "quick-buttons");
-       // remove all dynamic ATC buttons
+       SGPropertyNode_ptr button_group = getNamedNode(dlg, "quick-buttons");
+       // remove all dynamic airport/ATC buttons
        button_group->removeChildren("button", false);
 
        // Find the ATC stations within a reasonable range (about 40 miles?)
@@ -321,7 +325,7 @@ void FGATCDialog::FreqDialog() {
        int num_stat = current_commlist->FindByPos(lon, lat, elev, 40.0, &atc_stations);
        if (num_stat != 0) {
                map<atcdata, bool> uniq;
-               // fill map (sorts by distance)
+               // fill map (sorts by distance and removes duplicates)
                comm_list_iterator itr = atc_stations.begin();
                for (; itr != atc_stations.end(); ++itr) {
                        Point3D station = Point3D(itr->x, itr->y, itr->z);
@@ -340,7 +344,7 @@ void FGATCDialog::FreqDialog() {
        }
 
        // (un)hide message saying no things in range
-       SGPropertyNode_ptr range_error = namedNode(dlg->getChildren("text"), "no-atc-in-range");
+       SGPropertyNode_ptr range_error = getNamedNode(dlg, "no-atc-in-range");
        range_error->setBoolValue("hide", num_stat);
 
        _gui->showDialog(dialog_name);
@@ -354,7 +358,7 @@ void FGATCDialog::FreqDisplay(string& ident) {
 
        _gui->closeDialog(dialog_name);
 
-       SGPropertyNode_ptr freq_group = namedNode(dlg->getChildren("group"), "frequency-list");
+       SGPropertyNode_ptr freq_group = getNamedNode(dlg, "frequency-list");
        // remove all frequency entries
        freq_group->removeChildren("group", false);