You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.8 KiB
C++

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include "main.hpp"
#include "mainmenu.hpp"
namespace Proto4 {
// IDEA: implement Menu superclass, which has a sf::Text title,
// vector<MenuAction> actions, and implements updating and drawing?
// eg. struct MenuAction { sf::Keyboard key, String text, AppState
// transition }
bool MainMenu::init(sf::Font &font) {
font = font;
view.setCenter(middleX, middleY);
view.setSize(xResolution, yResolution);
view.setViewport(sf::FloatRect(0, 0, 1, 1));
mainLine.setString("Proto 4");
entry1.setString("[S] Start New Game");
entry2.setString("[Q] Quit Game");
mainLine.setFont(font);
entry1.setFont(font);
entry2.setFont(font);
mainLine.setPosition(32.f, 32.f);
entry1.setPosition(32.f, 96.f);
entry2.setPosition(32.f, 160.f);
return true;
}
void MainMenu::resize(sf::Event &resizeEvent) {
view.setSize(resizeEvent.size.width, resizeEvent.size.height);
view.setCenter(resizeEvent.size.width / 2, resizeEvent.size.height / 2);
}
// Unlike in game, this gets only called on keypresses.
AppState MainMenu::handleKey(const sf::Event &keyEvent) {
if (keyEvent.key.code == sf::Keyboard::Q)
return AppState::Exit;
if (keyEvent.key.code == sf::Keyboard::S)
return AppState::Game;
// to satisfy the analyzer
return AppState::MainMenu;
}
void MainMenu::draw(sf::RenderTarget &target,
sf::RenderStates states) const {
states.transform *= getTransform();
target.setView(view);
target.draw(mainLine, states);
target.draw(entry1, states);
target.draw(entry2, states);
}
}