This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Tortuga/client/main_menu.cpp
T
2013-05-20 18:54:10 +10:00

93 lines
1.9 KiB
C++

#include "main_menu.hpp"
#include <iostream>
using namespace std;
//-------------------------
//Public access members
//-------------------------
MainMenu::MainMenu(ConfigUtility* cUtil, SurfaceManager* sMgr) {
#ifdef DEBUG
cout << "entering MainMenu" << endl;
#endif
configUtil = cUtil;
surfaceMgr = sMgr;
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
}
//-------------------------
//Frame loop
//-------------------------
void MainMenu::FrameStart() {
//
}
void MainMenu::FrameEnd() {
//
}
void MainMenu::Update() {
//
}
void MainMenu::Render(SDL_Surface* const screen) {
for (auto it : buttonMap) {
it.second->DrawTo(screen);
}
}
//-------------------------
//Event handlers
//-------------------------
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) {
SetNextScene(SceneList::LOBBY);
}
if (buttonMap["options"]->MouseButtonUp(button) == Button::State::HOVER) {
//TODO
}
if (buttonMap["quit"]->MouseButtonUp(button) == Button::State::HOVER) {
QuitEvent();
}
}
void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
}
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
//
}