/**
* Class MenuHandler, written by Justin Klein
(2004)
*
* This class internally handles a Menu
System, using a set of basic functions.
The menu
* is generated by Init(char* iniFileName)
from an INI file that should be structured as follows:
[Main Menu] //This segment is mandatory; contains info about
the Main Menu's items.
Type=Menu //Main Menu is, of course, a menu (and not an
action)
NumEntries=3 //Main Menu will have 3 entries, each listed below:
Entry0=Single Player //the first item in the main menu will
be called "Single Player";
//This
can be another submenu or an action, which will be defined later.
Entry1=Options //the second is called
"options"
Entry2=Quit //the third is called "quit"
[Single Player] //This
section defines the "Single Player" entree from above;
//Note
that EVERY entry that’s named in any menu MUST have its own
//section
like this one, or the program will crash.
Type=Action //Here, single player is an ACTION, not another
submenu
[Options] //the "Options" item in "Main
Menu" is a submenu with one entry
Type=Menu
NumEntries=1
Entry0=Main Menu //WARNING! This type of feature is
NOT supported yet; you CANNOT
//refer
back to already-existing menus.
[Quit] //the "Quit" item in "Main
Menu" is an action.
Type=Action
* The menus are handled through these
functions:
* void Init(char *iniFileName); Sets up the menu system as described
above
* void Cleanup(); Frees memory associated with the menu system
* void Reset(); Resets to the main menu with Entry0 selected
*
* Each of the below functions make a change
to the current state of the menu system, and returns
* that state as a MenuState*. This struct can
then be used to display the menu system.
* MenuState *MoveUp(); Changes the currently selected menu item to the
item above it
* MenuState *MoveDown(); Changes the currently selected
menu item to the item below it
* MenuState *Back(); Returns to the previous menu (unless current is
* MenuState *Select(); Selects the current menu item (this may navigate to
a submenu
* or
perform an action).
* bool
WasAction(char* ); Can be used so the user doesn't have to
manually check the
* contents
of MenuState.action; returns TRUE if the last action
* performed
matches the string parameter, false otherwise.
*
* struct MenuState contains the following
fields, which should be used to DISPLAY the menu:
* char
*name: The name of the current menu
* char
**items: An array of the names of the
current menu's entries
* int
numItems: The number of items in the
"items" array
* int
highlighted: The index in
"items" of the currently highlighted (selected) entry
* char *action: The name of an action if one is to be
performed, otherwise a zero length string
* (for
example, if the user selected “Quit” in the above menu, action would contain
“Quit”.
*
* Constants
*
MAXITEMLEN can be changed to allow longer names for menu entries
(default is 128)
*
MAXNUMITEMS can be changed to allow more entries per menu (default is
10)
**/