Implemented main menu and buttons

This commit is contained in:
Kayne Ruse
2013-05-15 23:20:47 +10:00
parent 613d9cec08
commit 30d163ec80
12 changed files with 108 additions and 34 deletions
+34 -4
View File
@@ -12,9 +12,20 @@ MainMenu::MainMenu() {
#ifdef DEBUG
cout << "entering MainMenu" << endl;
#endif
configUtil = GetSingletonPtr<ConfigUtility>();
surfaceMgr = GetSingletonPtr<SurfaceManager>();
surfaceMgr->Load("button", configUtil->String("interface") + "/button.bmp");
buttonMap["start"] = new Button(50, 50, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "start");
buttonMap["options"] = new Button(50, 100, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "options");
buttonMap["quit"] = new Button(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "quit");
}
MainMenu::~MainMenu() {
for (auto it : buttonMap) {
delete it.second;
}
#ifdef DEBUG
cout << "leaving MainMenu" << endl;
#endif
@@ -37,7 +48,9 @@ void MainMenu::Update() {
}
void MainMenu::Render(SDL_Surface* const screen) {
//
for (auto it : buttonMap) {
it.second->DrawTo(screen);
}
}
//-------------------------
@@ -45,15 +58,32 @@ void MainMenu::Render(SDL_Surface* const screen) {
//-------------------------
void MainMenu::MouseMotion(SDL_MouseMotionEvent const& motion) {
//
for (auto it : buttonMap) {
it.second->MouseMotion(motion);
}
}
void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
//
for (auto it : buttonMap) {
it.second->MouseButtonDown(button);
}
}
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//
if (buttonMap["start"]->MouseButtonUp(button) == Button::State::HOVER) {
//TODO
SetNextScene(SceneList::INGAME);
cout << "start" << endl;
}
if (buttonMap["options"]->MouseButtonUp(button) == Button::State::HOVER) {
//TODO
cout << "options" << endl;
}
if (buttonMap["quit"]->MouseButtonUp(button) == Button::State::HOVER) {
//TODO
SetNextScene(SceneList::QUIT);
cout << "quit" << endl;
}
}
void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {