The default aircraft behaviour on the menu W&B dialog command is to
report a NASAL error on the STDERR of flightgear, with no reaction
in the game window. Included is a patch that pops up a dialog
instead, explaining why that wouldn't work.

The length is due to the diff inability to say that a lot of lines
were just indented right (as they were put inside an else {} )

Perhaps a GUI-cleaner way would be to condition the menu item
on the presence of the /yasim grove, yet I am unable to do it w/o
turning the whole submenu into a dynamic one, which I am lazy to do.

(Thanks to Melchior for suggesting the way it should behave instead)

Index: ../data/Nasal/gui.nas
===================================================================
RCS file: /var/cvs/FlightGear-0.9/data/Nasal/gui.nas,v
retrieving revision 1.10
diff -u -p -r1.10 gui.nas
--- ../data/Nasal/gui.nas       13 Jul 2005 11:30:32 -0000      1.10
+++ ../data/Nasal/gui.nas       15 Oct 2005 19:18:53 -0000
@@ -135,130 +135,139 @@ showWeightDialog = func {
     contentArea = dialog[name].addChild("group");
     contentArea.set("layout", "hbox");

-    grossWgt = props.globals.getNode("/yasim/gross-weight-lbs");
-    if(grossWgt != nil) {
-        gwg = dialog[name].addChild("group");
-        gwg.set("layout", "hbox");
-        gwg.addChild("empty").set("stretch", 1);
-        gwg.addChild("text").set("label", "Gross Weight:");
-        txt = gwg.addChild("text");
-        txt.set("label", "0123456789");
-        txt.set("format", "%.0f lb");
-        txt.set("property", "/yasim/gross-weight-lbs");
-        txt.set("live", 1);
-        gwg.addChild("empty").set("stretch", 1);
-    }
-
-    buttonBar = dialog[name].addChild("group");
-    buttonBar.set("layout", "hbox");
-    buttonBar.set("default-padding", 10);
-
-    ok = buttonBar.addChild("button");
-    ok.set("legend", "OK");
-    ok.prop().getNode("binding[0]/command", 1).setValue("dialog-apply");
-    ok.prop().getNode("binding[1]/command", 1).setValue("dialog-close");
-
-    # Temporary helper function
-    tcell = func {
-        cell = arg[0].addChild(arg[1]);
-        cell.set("row", arg[2]);
-        cell.set("col", arg[3]);
-        return cell;
-    }
-
-    #
-    # Fill in the content area
-    #
-    fuelArea = contentArea.addChild("group");
-    fuelArea.set("layout", "vbox");
-    fuelArea.addChild("text").set("label", "Fuel Tanks");
-
-    fuelTable = fuelArea.addChild("group");
-    fuelTable.set("layout", "table");
-
-    fuelArea.addChild("empty").set("stretch", 1);
-
-    tcell(fuelTable, "text", 0, 0).set("label", "Tank");
-    tcell(fuelTable, "text", 0, 3).set("label", "Pounds");
-    tcell(fuelTable, "text", 0, 4).set("label", "Gallons");
-
-    tanks = props.globals.getNode("/consumables/fuel").getChildren("tank");
-    for(i=0; i<size(tanks); i+=1) {
-        t = tanks[i];
-
-        tname = i ~ "";
-        tnode = t.getNode("name");
-        if(tnode != nil) { tname = tnode.getValue(); }
-
-        tankprop = "/consumables/fuel/tank["~i~"]";
-
-        cap = t.getNode("capacity-gal_us", 1).getValue();
-
-        # Hack, to ignore the "ghost" tanks created by the C++ code.
-        if(cap < 1) { continue; }
-
-        title = tcell(fuelTable, "text", i+1, 0);
-        title.set("label", tname);
-        title.set("halign", "right");
-
-        sel = tcell(fuelTable, "checkbox", i+1, 1);
-        sel.set("property", tankprop ~ "/selected");
-        sel.prop().getNode("binding[0]/command", 1).setValue("dialog-apply");
-
-        slider = tcell(fuelTable, "slider", i+1, 2);
-        slider.set("property", tankprop ~ "/level-gal_us");
-        slider.set("min", 0);
-        slider.set("max", cap);
-        slider.prop().getNode("binding[0]/command", 
1).setValue("dialog-apply");
-
-        lbs = tcell(fuelTable, "text", i+1, 3);
-        lbs.set("property", tankprop ~ "/level-lbs");
-        lbs.set("label", "0123456");
-        lbs.set("format", "%.3f");
-        lbs.set("live", 1);
-
-        gals = tcell(fuelTable, "text", i+1, 4);
-        gals.set("property", tankprop ~ "/level-gal_us");
-        gals.set("label", "0123456");
-        gals.set("format", "%.3f");
-        gals.set("live", 1);
-    }
-
-    weightArea = contentArea.addChild("group");
-    weightArea.set("layout", "vbox");
-    weightArea.addChild("text").set("label", "Payload");
-
-    weightTable = weightArea.addChild("group");
-    weightTable.set("layout", "table");
-
-    weightArea.addChild("empty").set("stretch", 1);
-
-    tcell(weightTable, "text", 0, 0).set("label", "Location");
-    tcell(weightTable, "text", 0, 2).set("label", "Pounds");
-
-    wgts = props.globals.getNode("/sim").getChildren("weight");
-    for(i=0; i<size(wgts); i+=1) {
-        w = wgts[i];
-        wname = w.getNode("name", 1).getValue();
-        max = w.getNode("max-lb", 1).getValue();
-        wprop = "/sim/weight[" ~ i ~ "]/weight-lb";
-
-        title = tcell(weightTable, "text", i+1, 0);
-        title.set("label", wname);
-        title.set("halign", "right");
-
-        slider = tcell(weightTable, "slider", i+1, 1);
-        slider.set("property", wprop);
-        slider.set("min", 0);
-        slider.set("max", max);
-        slider.prop().getNode("binding[0]/command", 
1).setValue("dialog-apply");
-
-        lbs = tcell(weightTable, "text", i+1, 2);
-        lbs.set("property", wprop);
-        lbs.set("label", "0123456");
-        lbs.set("format", "%.0f");
-        lbs.set("live", 1);
-    }
+       if (props.globals.getNode("/yasim") == nil) {
+               msg = dialog[name].addChild("text");
+               msg.set("label", "Weight/balance only supported for YASIM 
models!");
+               cancel = dialog[name].addChild("button");
+               cancel.set("legend", "OK");
+               cancel.prop().getNode("binding[0]/command", 
1).setValue("dialog-close");
+       }
+       else {
+               grossWgt = props.globals.getNode("/yasim/gross-weight-lbs");
+               if(grossWgt != nil) {
+                       gwg = dialog[name].addChild("group");
+                       gwg.set("layout", "hbox");
+                       gwg.addChild("empty").set("stretch", 1);
+                       gwg.addChild("text").set("label", "Gross Weight:");
+                       txt = gwg.addChild("text");
+                       txt.set("label", "0123456789");
+                       txt.set("format", "%.0f lb");
+                       txt.set("property", "/yasim/gross-weight-lbs");
+                       txt.set("live", 1);
+                       gwg.addChild("empty").set("stretch", 1);
+               }
+
+               buttonBar = dialog[name].addChild("group");
+               buttonBar.set("layout", "hbox");
+               buttonBar.set("default-padding", 10);
+
+               ok = buttonBar.addChild("button");
+               ok.set("legend", "OK");
+               ok.prop().getNode("binding[0]/command", 
1).setValue("dialog-apply");
+               ok.prop().getNode("binding[1]/command", 
1).setValue("dialog-close");
+
+               # Temporary helper function
+               tcell = func {
+                       cell = arg[0].addChild(arg[1]);
+                       cell.set("row", arg[2]);
+                       cell.set("col", arg[3]);
+                       return cell;
+               }
+
+               #
+               # Fill in the content area
+               #
+               fuelArea = contentArea.addChild("group");
+               fuelArea.set("layout", "vbox");
+               fuelArea.addChild("text").set("label", "Fuel Tanks");
+
+               fuelTable = fuelArea.addChild("group");
+               fuelTable.set("layout", "table");
+
+               fuelArea.addChild("empty").set("stretch", 1);
+
+               tcell(fuelTable, "text", 0, 0).set("label", "Tank");
+               tcell(fuelTable, "text", 0, 3).set("label", "Pounds");
+               tcell(fuelTable, "text", 0, 4).set("label", "Gallons");
+
+               tanks = 
props.globals.getNode("/consumables/fuel").getChildren("tank");
+               for(i=0; i<size(tanks); i+=1) {
+                       t = tanks[i];
+
+                       tname = i ~ "";
+                       tnode = t.getNode("name");
+                       if(tnode != nil) { tname = tnode.getValue(); }
+
+                       tankprop = "/consumables/fuel/tank["~i~"]";
+
+                       cap = t.getNode("capacity-gal_us", 1).getValue();
+
+                       # Hack, to ignore the "ghost" tanks created by the C++ 
code.
+                       if(cap < 1) { continue; }
+
+                       title = tcell(fuelTable, "text", i+1, 0);
+                       title.set("label", tname);
+                       title.set("halign", "right");
+
+                       sel = tcell(fuelTable, "checkbox", i+1, 1);
+                       sel.set("property", tankprop ~ "/selected");
+                       sel.prop().getNode("binding[0]/command", 
1).setValue("dialog-apply");
+
+                       slider = tcell(fuelTable, "slider", i+1, 2);
+                       slider.set("property", tankprop ~ "/level-gal_us");
+                       slider.set("min", 0);
+                       slider.set("max", cap);
+                       slider.prop().getNode("binding[0]/command", 
1).setValue("dialog-apply");
+
+                       lbs = tcell(fuelTable, "text", i+1, 3);
+                       lbs.set("property", tankprop ~ "/level-lbs");
+                       lbs.set("label", "0123456");
+                       lbs.set("format", "%.3f");
+                       lbs.set("live", 1);
+
+                       gals = tcell(fuelTable, "text", i+1, 4);
+                       gals.set("property", tankprop ~ "/level-gal_us");
+                       gals.set("label", "0123456");
+                       gals.set("format", "%.3f");
+                       gals.set("live", 1);
+               }
+
+               weightArea = contentArea.addChild("group");
+               weightArea.set("layout", "vbox");
+               weightArea.addChild("text").set("label", "Payload");
+
+               weightTable = weightArea.addChild("group");
+               weightTable.set("layout", "table");
+
+               weightArea.addChild("empty").set("stretch", 1);
+
+               tcell(weightTable, "text", 0, 0).set("label", "Location");
+               tcell(weightTable, "text", 0, 2).set("label", "Pounds");
+
+               wgts = props.globals.getNode("/sim").getChildren("weight");
+               for(i=0; i<size(wgts); i+=1) {
+                       w = wgts[i];
+                       wname = w.getNode("name", 1).getValue();
+                       max = w.getNode("max-lb", 1).getValue();
+                       wprop = "/sim/weight[" ~ i ~ "]/weight-lb";
+
+                       title = tcell(weightTable, "text", i+1, 0);
+                       title.set("label", wname);
+                       title.set("halign", "right");
+
+                       slider = tcell(weightTable, "slider", i+1, 1);
+                       slider.set("property", wprop);
+                       slider.set("min", 0);
+                       slider.set("max", max);
+                       slider.prop().getNode("binding[0]/command", 
1).setValue("dialog-apply");
+
+                       lbs = tcell(weightTable, "text", i+1, 2);
+                       lbs.set("property", wprop);
+                       lbs.set("label", "0123456");
+                       lbs.set("format", "%.0f");
+                       lbs.set("live", 1);
+               }
+       }

     # All done: pop it up
     fgcommand("dialog-new", dialog[name].prop());


_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d

Reply via email to