After re-reading what I wrote yesterday, I realized I was talking about a completely different thing what I actually have. I am terribly sorry about this, but I had some beers
Well, I will try to explain the real thing this time.
So, I have a MenuEntry class like this:
class MenuEntry
{
public:
MenuEntry (std::string label, int x, int y, const sf::Font& font);
~MenuEntry ();
void SelectEntry ();
void DeSelectEntry ();
void Update (); // this function checks the IsSelected boolean, and changes the color of the sf::Text object
void Draw (sf::RenderTarget& target);
private:
bool IsSelected;
int mPosX;
int mPosY;
sf::Text mLabel;
};
And I create instances of it:
MenuEntry newGame(...);
MenuEntry exitGame(...);
But I want to make my life easier, so I created a manager-like class, called MenuSystem. So decided to store all my MenuEntry objects in a container, and then I can update and draw them with one line of code, instead writing:
menu1.Update();
menu2.Update();
....
menuN.Update();
menu1.Draw();
menu2.Draw();
....
menuN.Draw();
So at the moment I update and draw them like this:
MenuSystem test;
MenuEntry menu1, menu2 ....menuN;
test.AddEntry(menu1);
test.AddEntry(menu2);
....
test.AddEntry(menuN);
// in main loop
test.UpdateEntries();
test.DrawEntries();
This is still not the thing I really want. Because I have to add all MenuEntry objects to the manager by hand, which is not cool. But works. The real problem however is this: this MenuSystem class only stores, updates and draws the MenuEntry objects, but it doesn't know what they do. So I can't tell this manager to do something like this:
if "newGame" is selected, create a new game
if "exitGame" is selected, close the application
What I tried to do, searching in the vector with find from <algorithm> didn't worked. Maybe I used in a wrong way.
I may be just overcomplicating this, but I'm stuck. Should I forget about the manager, and just hard code the menu ? But I really want a nice and reusable code.