API Question Triggering the 'gBody selection menu' from a vessel

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
10,002
Reaction score
4,418
Points
203
Location
Toulouse
I tried quite a few things there but I can't get it to work...

My goal is to use a 'gBody selection menu' similar to the one you get when clicking on the 'REF' button of 'OrbitMFD' (and then be able to use the selection 'choice'). Has anyone managed to do that ? Anything I should know ? An example (within a vessel) would be very much appreciated.

1766283861108.png
 
I tried quite a few things there but I can't get it to work...

My goal is to use a 'gBody selection menu' similar to the one you get when clicking on the 'REF' button of 'OrbitMFD' (and then be able to use the selection 'choice'). Has anyone managed to do that ? Anything I should know ? An example (within a vessel) would be very much appreciated.

View attachment 46297
This context menu is not accessible from the OAPI. Internally it's using the Instrument class that is not exported.
Two menus are hardcoded in that class :
Code:
    void OpenSelect_CelBody (const char *title, Select::Callbk enter_cbk, DWORD flag = 0);
    // Open a selection box for a celestial object.
    // The callback function is called if a selection is made.
    // The following bit flags are supported:
    //   1: do not include Star objects

    void OpenSelect_Tgt (const char *title, Select::Callbk enter_cbk, const CelestialBody *ref = 0, DWORD flag = 0);
    // Open a selection box for a target object
    // Supported bitflags:
    //   1: don't display 'By name' option
    //   2: don't display other targets than those orbiting 'ref'
Exposing them should be possible but that would be in the next release.
A lower access to the internal "Select" API should also be possible, to be able to make completely custom entries, but it can be complicated to use. For example the CelBody selector :
Code:
bool Instrument::ClbkSelect_CelBody (Select *menu, int item, char *str, void *data)
{
    int i, n;
    if (!str) { // root menu
        n = (SelCelBodyFlag & 1 ? 0 : g_psys->nStar());
        for (i = 0; i < n; i++) {
            Star *star = g_psys->GetStar (i);
            menu->Append (star->Name());
        }
        if (n) menu->AppendSeparator();
        n = g_psys->nPlanet();
        for (i = 0; i < n; i++) {
            Planet *planet = g_psys->GetPlanet (i);
            if (planet->isMoon()) continue; // only use primaries in root
            menu->Append (planet->Name(), planet->nSecondary() ? ITEM_SUBMENU : 0);
        }
        return true;
    } else { // submenu
        CelestialBody *cbody = g_psys->GetGravObj (str, true);
        if (cbody) {
            n = cbody->nSecondary();
            for (i = 0; i < n; i++) {
                const CelestialBody *moon = cbody->Secondary(i);
                menu->Append (moon->Name(), moon->nSecondary() ? ITEM_SUBMENU : 0);
            }
            return (n > 0);
        } else return false;
    }
    return false;
}
 
Exposing them should be possible but that would be in the next release.

Ah, thank you for the clarification.

I'll use an 'input box' then.
 
Back
Top