Updated footnotes for the interpreter...
Code:
#include <string>
#include "Menu.h"
#include <list>
class Interpreter
{
public:
virtual void Navigate_Menu(std::string Command)
{
//to first find the menu given by the command
//we have to find a way to organize the menus
//then
//if it is a recognized command, we delete
//the current list of valid commands
//then
//We make a new list of valid coimmands by
//inserting command strings into valid commands
//by looping through the selected menu's
//children and getting their Selection string
}
private:
std::list<std::string*> Valid_Commands;
};
Also an updated Menu class:
Code:
#ifndef MENU
#define MENU
#include <string>
#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);
}
//Get the menu name
std::string Return_Selection()
{
return Selection;
}
private:
// Set the parent of the child
void SetRootMenu(Menu* Root)
{
RootMenu = Root;
}
//menu name
std::string Selection;
protected:
// list of children
std::list<Menu*> MenuChoices;
// pointer to parent
Menu * RootMenu;
};
#endif
Hah I guess I still do know how to program a bit :d
Some new commentary:
Code:
/*
Somehow, I need to create a database of menus..
Never done this before.. I think I don't
actually have to store the menu objects
in a file, only strings for what menu's I need
and maybe some variables to show they connect together..
*/
And to further the todo list:
What exactly am I going to do with these automatically created Menu trees?
Well I know why I need them, so I don't have to hardcode all my menus, and so all my menus are connected the way they should be. But now what? How does the interpreter access the menus? I guess I have to manage the menu classes in dynamic memory... The resource manager could easily be requested to look for a menu class by string. From finding that initial root menu I could now instead use the pointers held in the menu classes themselves to navigate around the menu's... Even if they're all in the same manager.
O.o After afterthought!
I don't actually have to use the pointers in the menu classes at all, all I need them for is to create a new list of valid commands, then finally I can just use a resource_manager to access the menus. Though I wonder, is all this searching through a map by comparing strings going to give alot of overhead? Not that it really matters in a text game, but for future reference, anyone have any feedback so far?
I love it when everything works so perfectly, it's like magic.