I decided that I needed a working Menu class, so I write this bad boy
Code:
#include <list>
class Menu
{
public:
Menu(std::string mSelection)
{
mSelection = Selection;
}
virtual ~Menu() { Destroy(); }
// deletes self
void Release() { delete this; }
// call update on all children
virtual void Update()
{
for( std::list<Menu*>::iterator i = MenuChoices.begin();
i != MenuChoices.end(); i++ )
{
(*i)->Update();
}
}
// recursively destroy all children and self
void Destroy()
{
for( std::list<Menu*>::iterator i = MenuChoices.begin();
i != MenuChoices.end(); i++ )
(*i)->Release();
MenuChoices.clear();
}
// add a child
void MenuSelection( Menu* MenuSelection )
{
MenuSelection->SetRootMenu(this);
MenuChoices.push_back(MenuSelection);
}
// Set the parent of the child
void SetRootMenu(Menu* Root)
{
RootMenu = Root;
}
protected:
// list of children
std::list<Menu*> MenuChoices;
// pointer to parent
Menu * RootMenu;
std::string Selection;
};
I'm going to have my interpreter access a list or vector or container of some sort of root menu's, which will lead to submenus, and finally menu selections, etc..