OK, time for some menus!
For 2.4.3, Medo and me overhauled the system used to construct menus in GG2. I replaced the existing copy-pasted and inconsistent code using user-defined events that was a pain to manage, with a new menu API and common Menu code. Medo built upon the work I did, making several improvements.
This new system allows you to programmatically (with functions) add menu items.
Unlike the old menu system, this menu system is very developer friendly, and should make it much easier for plugin authors to add menus, and menu items.
Here's as a sample "gib everything" plugin:
object_event_add(InGameMenuController, ev_create, 0, '
menu_addlink("Gib all", "
with (Character) {
hp = 0;
lastDamageSource = Rocket;
}
");
');
First, notice object_event_add. This adds to the create event of the in-game menu. We can't just use menu functions directly against objects, we need to use them on
instances, so we're adding an event.
To object_event_add, we pass a script. This script calls menu_addlink. menu_addlink is a menu function to add a "link", an item with just a name and an action (doesn't take text/number input). To this we pass the name ("Gib all"), and a script. This script, well, gibs everyone.
Now what if we want to add a text field? It's quite simple. Here's an example from the host options menu:
menu_addedit_text("Password:", "global.serverPassword", '
gg2_write_ini("Server", "Password", argument0);
');
(this would have to be put in an event like before)
menu_addedit_text adds an editable text field to a menu. "Password:" is the title of the field, the bit on the left. The next bit is the name of the variable it will change. In this case, global.serverPassword.
Now we have a script. This script is passed in argument0, the new value of the edit box. We use gg2_write_ini (a new convenience function) to change the server password in the INI.
The procedure for a numeric field is very similar.
I hope you find this useful. Go out there and be awesome with awesome plugins