Jump to content
The simFlight Network Forums

Submenu in Add-ons


Recommended Posts

Now that I'm able to create a menu in add-ons, is it posible to create submenus inside this one?

FSUIPC doesn't support that at present, though SimConnect does, so it would be a possible extension I suppose. Really the FSUIPC option is a carry-over from the previous FSUIPC3 versions, and only provides that level of compatibility so that earlier apps could work with FSX without change.

If it is a serious need I could probably work out a way of building it onto the current FSUIPC3 facility, but it isn't an instant thing. I'd need to do a bit of research before I decided.

Regards

Pete

Link to comment
Share on other sites

Maybe you could put this in the "It would be nice to.." list.

Actually i just had a quick look and it may not be hard to do.

What about a design like this:

Having already setup the main menu, write this to 0x2FE0:

Byte 0 = 0x80 + slot number of main entry, as before

Byte 1 = Response value (any non-zero value 1 - 255)

Bytes 2-31 = The zero-terminated string for the submenu entry

SimConnect limits you to a max of 16 submenus. There are no further sub-levels.

When the user selects the submenu FSUIPC will fill in byte 3 of the slot with the "Response value" provided. Naturally you don't get notified when the main menu entry is selected when there are submenus.

What do you think? I reckon I could add that this week (FSUIPC4 only, I'm not adding it to FSUIPC3).

Regards

Pete

Link to comment
Share on other sites

Actually

Byte 0 is slot number

Byte 1 to 31 is menu name.

Not for the submenu. I need to use the second byte to determine the Response value. Please study it again.

Wouldn't the new design produce a conflict with already created applications?

No, because the maximum slot number is 56 (there are only 56 slots). The top bit (0x80 added is the flag which tells FSUIPC that this is for a submenu to be added to an already created menu entry. You have to refer to an already set menu slot.

Please study the proposal again and think about it. It is so easy to do I've almost finished and will be testing it later!

Regards

Pete

Link to comment
Share on other sites

I'll be waiting for this.

Okay. All done and dusted. Download 4.578 from the Updates announcement. Here's the documentation:

11. Facilities have been added to allow sub-menus to be added to menus created in the "Add-Ons" menu via the use of FSUIPC offset 2FE0 and the Hot Keys table at 3210. Full documentation will be included in the next SDK update, but meanwhile the included "MenuDemo.lua" plug-in and the following notes should be sufficient to allow full use:

Having already setup the main menu, as already documented, write this, in one write, to 0x2FE0:

Byte 0 = 0x80 + slot number of main entry, as before (i.e. 0 for 3210, 1 for 3214 etc. Remember the max is 55, there being 56 slots).

Byte 1 = Response value (any non-zero value 1 - 255). This is merely a value for you to test so you know which submenu was selected.

Bytes 2-31 = The zero-terminated string for the submenu entry

There's a limit of 16 submenus per menu entry (imposed by SimConnect), and there are no further sub-levels.

When the user selects the submenu FSUIPC will fill in byte 3 of the slot with the "Response value" provided. Naturally you don't get notified when the main menu entry is selected when there are submenus.

You can remove a submenu by doing the same as above but with a null string for the submenu entry (i.e. a single zero byte).

The included Lua plug-in demonstrates addition and deletion of submenus, as well as basic things like adding and removing the main menu, detecting which entry was selected, and maintaining the menu against the imposed timeout.

Have fun!

Regards

Pete

Link to comment
Share on other sites

Hi Pete,

Just to let you know that finally it is working perfectly!!! :D

It took me a long time, because in vb.net I have to write a value in local variable and then send it to FS calling FSUIPCConnection.Process(). It looks simple, but it is very important the exact moment when the values should be sent.

For anyone facing problems , like me, the algorithm is:

Write to free slot value &HFFFF (ex. &H3210)

send to FS

Write byte 1 of &H2FE0 with slot number (ex. 0 if using &H3210)

send to FS

' For menus

Write Menu title to byte 1 - 31 of &H2FE0

send to FS

'For submenus

Repeat

Write response number to byte 1 of &H2FE0

send to fs ----> here I had the headache

Write to byte 1 of &H2FE0 &H80 + slot number

write submenu title to byte 2 - 30 of &H2FE0

send to fs

until no more submenus

In a Timer control each 10 sec

write &HFF to byte 3 slot (with previous ex. it will be &H3213

Link to comment
Share on other sites

Write to free slot value &HFFFF (ex. &H3210)

send to FS

Write byte 1 of &H2FE0 with slot number (ex. 0 if using &H3210)

send to FS

' For menus

Write Menu title to byte 1 - 31 of &H2FE0

send to FS

That isn't right in two ways. First the slot number goes in Byte 0. The title starts in byte 1.

Second, you should write the whole lot in one write, because FSUIPC will be taking the action of adding the string to the menu system as soon as it sees you writing to 2FE0. If it appears to be working for you you are just lucky. It will be very time critical.

The correct way to do it is as shown in the documentation. Declare your title string as, say "XMy title string", i.e. with the extra character at the front, then, before writing that string, alter the first character to the binary number of the slot. Maybe in VB.NET you would have to do this by having the string declared as a BYTE array, so you can address byte [0] specifically./

'For submenus

Repeat

Write response number to byte 1 of &H2FE0

send to fs ----> here I had the headache

Write to byte 1 of &H2FE0 &H80 + slot number

write submenu title to byte 2 - 30 of &H2FE0

send to fs

until no more submenus

Same errors here. The 128 + slot number goes in byte 0 not 1 or you overwrite the response.

You should write all in one write again. Your title will have two preceding characters "XYMy Submenu title" and you replace X and Y before writing. Bytes [0] and [1]. In fact, because your response number is arbitrary -- your choice of any value from 1 to 255 -- you might as well make it an ASCII character, like 'A'. in which case you only have the Byte[0] to overwrite, in "XAMy Submenu Title"

If you are getting away with the code as you are stating it you are very lucky. It isn't designed to work that way. did you look at the Lua example I provided? Lua is quite Basic-like in many ways -- more restrictive in some, more flexible in others.

Regards

Pete

Link to comment
Share on other sites

First the slot number goes in Byte 0. The title starts in byte 1.

Upsss, type mismatch. I had it the correct way. :?

Declare your title string as, say "XMy title string", i.e. with the extra character at the front, then, before writing that string, alter the first character to the binary number of the slot. Maybe in VB.NET you would have to do this by having the string declared as a BYTE array, so you can address byte [0] specifically./

Yes, I tried that, but I can't manage to use it that way, because if declare as byte array, then I need to write each byte individually (that is each letter). Using a conversion function string to bytes (GetBytes) will also give me more problems, because the array initially declare as 30 byte, will change to the size of the string.

Same errors here. The 128 + slot number goes in byte 0 not 1 or you overwrite the response.

Same type mismatch (copy paste from the other one).

If you are getting away with the code as you are stating it you are very lucky.

After applying the theory it didn't work, so I start with trial and error and finally made it work, so I guess I'm lucky.

did you look at the Lua example I provided

Yes, but the difference is that lua writes directly to FS, and in vb.net I have to write locally and then send to FS. I know that it sounds ilogic, but, belive me, that make a lot of difference.

In any case, now it works, after 2 days fighting with 20 lines of code.

Soon I'll try to look at it again and let you know, if that is ok for you?

Thanks.

Link to comment
Share on other sites

Yes, I tried that, but I can't manage to use it that way, because if declare as byte array, then I need to write each byte individually (that is each letter). Using a conversion function string to bytes (GetBytes) will also give me more problems, because the array initially declare as 30 byte, will change to the size of the string.

Ugh. What a horrible language it must be!

Two points then:

1. It doesn't matter how many bytes you write, provided no more that the 32 (from offset 2FE0), and the last one is zero. It is the zero with terminates the title string, not the end of the area provided for it.

2. If you must write the parameter byte(s) and string separately, it would be safer to write the string first, then the "slot" byte (0), because it is writing the slot byte which triggers the action.

Of course, as I said, for submenus the "response byte" can be part of your title string. Just use distinct letters or number characters so you can distinguish the response when you receive it.

Regards

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.