Board index FlightGear Development

Control dialog for an AI scenario

FlightGear is opensource, so you can be the developer. In the need for help on anything? We are here to help you.
Forum rules
Core development is discussed on the official FlightGear-Devel development mailing list.

Bugs can be reported in the bug tracker.

Control dialog for an AI scenario

Postby Tomaskom » Fri Sep 26, 2014 8:55 am

Hi,
I'd like to add a control dialog to my scenario, including a convenient way of bringing the dialog up. My idea would be to either have a whole new menu in the top bar or a new entry in the AI menu for triggering it (in both cases created and removed when the scenario is enabled/disabled), and a standard dialog definition xml somewhere in the scenario package.
I tried some random ideas in the scenario xml file (both xml and the <load> Nasal, after observing the existing structure), but was not able to do anything. Any ideas?
The scenario I'm talking about: http://fguk.eu/index.php/hangar/viewdow ... -mach-loop
I'd like to include stuff like a slider for marker transparency, button for manually canceling the time measurement etc.
"There are no problems in the air. The only problem is hitting the ground"

Get my L-159 ALCA from the FGUK hangar. If you crash it, things gonna go boom!
User avatar
Tomaskom
 
Posts: 132
Joined: Sun Dec 02, 2012 8:03 pm
Location: Czech Republic
Callsign: OK-TomK
Version: git
OS: openSUSE (Linux)

Re: Control dialog for an AI scenario

Postby Hooray » Fri Sep 26, 2014 3:41 pm

Usually, you'll want to create a standalone GUI dialog, see $FG_ROOT/gui/dialogs for examples and refer to $FG_ROOT/Docs/README.gui for details.
People familiar with Nasal scripting can also create such dialogs procedurally - but that's a little awkward, any dynamic dialog would be better implemented using Nasal & Canvas - for details on that, see $FG_ROOT/Nasal/canvas/gui/dialogs

If you are not new to Nasal coding and OOP, Canvas is probably your best option - taking an existing dialog and adapting it should be fairly straightforward, even though you may need to create certain widgets from scratch that would be supporte by PUI
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11925
Joined: Tue Mar 25, 2008 8:40 am

Re: Control dialog for an AI scenario

Postby Tomaskom » Fri Sep 26, 2014 11:37 pm

I didn't think about Canvas, thanks for that bit :). I'm quite proficient when it comes to Nasal, so no problem here.
Still, the core of this question is how to add a menu entry to the menubar from a scenario (this entry would bring up the dialog).
"There are no problems in the air. The only problem is hitting the ground"

Get my L-159 ALCA from the FGUK hangar. If you crash it, things gonna go boom!
User avatar
Tomaskom
 
Posts: 132
Joined: Sun Dec 02, 2012 8:03 pm
Location: Czech Republic
Callsign: OK-TomK
Version: git
OS: openSUSE (Linux)

Re: Control dialog for an AI scenario

Postby Hooray » Sat Sep 27, 2014 7:24 am

gui.nas has helpers for adding custom menubar entries - this is usually used by aircraft scripts, so would work here, too.
But you'll need to use another script, because all those XML files are usually not well-integrated, i.e. features/tags supported by one subsystem are rarely, if ever, supported by others unfortunately. You could set up a wrapper script that dynamically adds items on demand, tutorial.nas should have examples on doing this kind of thing, but any aircraft-specific menu can be adapted easily.

Besides, Jabberwocky has been working on a Canvas-based menubar where such things could be directly supported, without any PUI workarounds, see the canvas sub forum for details - you could probably team up with him and use just Canvas for everything.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11925
Joined: Tue Mar 25, 2008 8:40 am

Re: Control dialog for an AI scenario

Postby wlbragg » Wed Oct 29, 2014 8:22 pm

how to add a menu entry to the menubar from a scenario (this entry would bring up the dialog)

I think what your looking for is the hook to whether or not the AI scenario is active.

That would be a listener looking for
/sim/ai/scenario="your scenario"

Sorry I don't know off hand the exact listener coding.
http://wiki.flightgear.org/Using_listeners_and_signals_with_Nasal

There is an example in bomable.nas (bomable add-on) as to how to create a dynamic (procedural) menu.

Below is what I adapted from bomable.nas. But this only adds the items to the existing FG menu. You could then have one of those items call your standalone dialog. Or it can all be created procedurally (again see bombable.nas)
Code: Select all
var init_towCargo_dialog = func () {
       
        #Set cargo_menuNum to -1 at initialization time. 
   #On reinit & some other times, this routine will be called again.
   #So if cargo_menuNum != -1 we know not to seek out another new menu number
   #Without this check, we'd get a new Cargo menu added each time FG reinits or re-positions.
   if (cargo_menuNum==nil or cargo_menuNum==-1) {
      #find the next open menu number
      cargo_menuNum=97; #the default
      for (var i=0;i<300;i+=1) {
         p=props.globals.getNode("/sim/menubar/default/menu["~i~"]");
         if ( typeof(p) == "nil" ) {
            cargo_menuNum=i;
            break;
         }   
      }
   }
   
   #create GUI menubar items
   props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/enabled", 1).setBoolValue(1);
   props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/label", 1).setValue("CargoTow");
   props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/item/enabled", 1).setBoolValue(1);
   
   props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/item/label", 1).setValue("RealTime " ~ props.globals.getNode( "controls/cargo-realtime").getBoolValue());
   props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/item/binding/command", 1).setValue("nasal");
   props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/item/binding/script", 1).setValue(
      'props.globals.getNode("controls/cargo-realtime" ).setBoolValue(!props.globals.getNode("controls/cargo-realtime" ).getBoolValue());
      props.globals.getNode ("/sim/menubar/default/menu['~cargo_menuNum~']/item/label", 1).setValue("RealTime " ~ props.globals.getNode( "controls/cargo-realtime").getBoolValue());
      fgcommand ("gui-redraw");'
      );
   
   props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/item[1]/label", 1).setValue("Hook Assist");
    props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/item[1]/binding/command", 1).setValue("nasal");
   props.globals.getNode ("/sim/menubar/default/menu["~cargo_menuNum~"]/item[1]/binding/script", 1).setValue('props.globals.getNode("controls/hook-assist").setBoolValue(!props.globals.getNode("controls/hook-assist").getBoolValue())');
      
   fgcommand ("gui-redraw");
            
}


I have no experience or opinion on what is the best way to proceed.
Kansas(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
Intel i5 3570K AMDRX480
User avatar
wlbragg
 
Posts: 5734
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/AMDRX480


Return to Development

Who is online

Users browsing this forum: No registered users and 2 guests