As I began thinking about how I would implement a promised graphical UI to configure the various "Progress Bar Tweaks" options, I determined there were 3 things that were important:
- I wanted to integrate with the existing Options menus/mechanisms
- I wanted a flexible, extensible system. In the future, I'll develop other mods with options. Writing essentially the same code twice is once too often
- I wanted to be able to add options for other mods with as little ui.menu hacking as possible.
This mod, labeled "Mods Options" for lack of imagination on my part, inserts additional buttons on both the start up and in game 'Options' displays as shown below:




Upon clicking the MODS button, a screen is displayed that lists all of the registered mod options sets (implemented as UI menus), along with a Change button (enabled when a mod option set is selected) and the obligatory Cancel button:


As part of the testing/verification of this mod I created 2 simple options menus. One, which is just an extension of the Mods Options mod allows disabling the start up, the in game, or both MODS buttons. Select the 'Mods' entry on the main Mods screen, followed by the Change button and you'll see one of the following:


Of course, if you disable both, the only way to get either back is by manually editing Baldur.lua, setting 'ModOptions','Disable Ingame Menu' or 'Disable Start Menu' to 0.
The second options menu, entitled 'Hidden Game', doesn't apply to a mod, but rather, provides a method of changing some of the otherwise 'hidden' Program/Game options in Baldur.lua. The menu appears as below and is pretty obvious:


To install Mods Options, grab the relevant attached zip(s), and follow the instructions in the 'Installation.txt' file ModsOptions folder within the zip. For more information, check out the announcement post below.
The remaining part of this post is basically talking about how Mods Options works and how it can be 'modded' or used in/for other mods. So if that kind of stuff doesn't interest you (meaning you're a normal, healthy human being
), have a great day!
First off, all of the code in the attached zips is free to be used, abused, renamed, re-painted, or incorporated into other code. In other words - I relinquish all exclusive rights (that should satisfy my lawyer son
). On to the important stuff. The Options setting mechanism for a particular mod is, as mentioned earlier, a menu defined in ui.menu. In particular, it must be a modal menu that is able to be safely invoked via 'Infinity_PushMenu ' and returns/exits via 'Infinity_PopMenu'. To facilitate the discussion, below is an implementation of the ubiquitous 'Hello World' written as a mod option:
`
if(modOptionsRegisterMenu) then
modOptionsRegisterMenu('Hello World', 'OPTIONS_HELLO', "The famous Hello World", 0)
end
`
menu
{
name 'OPTIONS_HELLO'
modal
align center center
button
{
area 0 0 300 100
fill 43 0 90 255
text style title
text lua 't("Hello, World!")'
action "Infinity_PopMenu()"
}
}
The menu itself is obvious - a purple button displaying "Hello, World!" that closes when you click it. In fact, you can paste this code to the end of ui.menu, and assuming you've installed Mods Options, it will show up in the main Mods screen, and when you select it and 'Change' - will display a fairly ugly and totally useless button on top of everything. And wait for you to click it. The interesting part is what precedes the menu declaration - the Lua code. After ensuring that the function 'modOptionsRegisterMenu' exists (to prevent errors/crashes if not present for some reason), it invokes the function with 4 arguments.
The first argument is required and is the mod name - that is, the name you want to appear in the main Mods Options screen list of mods. It can be a literal value (as above) or it can be the key to a string registered in uiStrings.
The second argument, also required, is the string that appears in the 'name' field of the menu definition. It will be the argument supplied to 'Infinity_PushMenu'.
The third argument is optional. It is the string which appears in the 'Help/Info' text area in the main Mods Options screen.
The fourth argument, also optional (defaults to 0), is a number that indicates whether the menu entry should available from the start menus (1 or "1"), the in game menu (2 or "2") or both (0 or actually anything that isn't 1, "1", 2, or "2).
Notice that the menu, which does the actual option setting, knows nothing and receives nothing from Mods Options. Similarly, Mods Options knows nothing about the menu other than what is passed via modOptionsRegisterMenu. Thus, the menu is free within the context of 'Infinity_PushMenu/Infinity_PopMenu' to do whatever it likes - so long as the environment is in the same state on exit as on entry. Similarly, any UI that implements modOptionsRegisterMenu and that can call 'Infinity_PushMenu' passing the registered menu name will be compatible with Mods Options menus.
Have fun - and let me know what you think and if you encounter problems.










