Menu framework in place
This commit is contained in:
+21
-4
@@ -12,6 +12,9 @@ Lobby::Lobby() {
|
||||
#ifdef DEBUG
|
||||
cout << "entering Lobby" << endl;
|
||||
#endif
|
||||
refreshButton.Setup(50, 50, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Refresh");
|
||||
joinButton.Setup(50, 100, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Join");
|
||||
backButton.Setup(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Back");
|
||||
}
|
||||
|
||||
Lobby::~Lobby() {
|
||||
@@ -37,7 +40,9 @@ void Lobby::FrameEnd() {
|
||||
}
|
||||
|
||||
void Lobby::Render(SDL_Surface* const screen) {
|
||||
//
|
||||
refreshButton.DrawTo(screen);
|
||||
joinButton.DrawTo(screen);
|
||||
backButton.DrawTo(screen);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -45,15 +50,27 @@ void Lobby::Render(SDL_Surface* const screen) {
|
||||
//-------------------------
|
||||
|
||||
void Lobby::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
//
|
||||
refreshButton.MouseMotion(motion);
|
||||
joinButton.MouseMotion(motion);
|
||||
backButton.MouseMotion(motion);
|
||||
}
|
||||
|
||||
void Lobby::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
//
|
||||
refreshButton.MouseButtonDown(button);
|
||||
joinButton.MouseButtonDown(button);
|
||||
backButton.MouseButtonDown(button);
|
||||
}
|
||||
|
||||
void Lobby::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
//
|
||||
if (refreshButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
//ping the server
|
||||
}
|
||||
if (joinButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
//join a server
|
||||
}
|
||||
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
QuitEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void Lobby::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
#define LOBBY_HPP_
|
||||
|
||||
#include "base_scene.hpp"
|
||||
#include "service_locator.hpp"
|
||||
|
||||
#include "config_utility.hpp"
|
||||
#include "surface_manager.hpp"
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
class Lobby : public BaseScene {
|
||||
public:
|
||||
@@ -17,11 +23,21 @@ protected:
|
||||
void Render(SDL_Surface* const);
|
||||
|
||||
/* Event handlers */
|
||||
void QuitEvent() { SetNextScene(SceneList::MAINMENU); }
|
||||
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||
void KeyDown(SDL_KeyboardEvent const&);
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//services
|
||||
ConfigUtility* configUtil = ServiceLocator<ConfigUtility>::Get();
|
||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
||||
UDPNetworkUtility* netUtil = ServiceLocator<UDPNetworkUtility>::Get();
|
||||
|
||||
Button refreshButton;
|
||||
Button joinButton;
|
||||
Button backButton;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+21
-8
@@ -12,6 +12,9 @@ MainMenu::MainMenu() {
|
||||
#ifdef DEBUG
|
||||
cout << "entering MainMenu" << endl;
|
||||
#endif
|
||||
startButton.Setup(50, 50, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Start");
|
||||
optionsButton.Setup(50, 100, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Options");
|
||||
quitButton.Setup(50, 150, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Quit");
|
||||
}
|
||||
|
||||
MainMenu::~MainMenu() {
|
||||
@@ -37,7 +40,9 @@ void MainMenu::FrameEnd() {
|
||||
}
|
||||
|
||||
void MainMenu::Render(SDL_Surface* const screen) {
|
||||
//
|
||||
startButton.DrawTo(screen);
|
||||
optionsButton.DrawTo(screen);
|
||||
quitButton.DrawTo(screen);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -45,15 +50,27 @@ void MainMenu::Render(SDL_Surface* const screen) {
|
||||
//-------------------------
|
||||
|
||||
void MainMenu::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
//
|
||||
startButton.MouseMotion(motion);
|
||||
optionsButton.MouseMotion(motion);
|
||||
quitButton.MouseMotion(motion);
|
||||
}
|
||||
|
||||
void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
//
|
||||
startButton.MouseButtonDown(button);
|
||||
optionsButton.MouseButtonDown(button);
|
||||
quitButton.MouseButtonDown(button);
|
||||
}
|
||||
|
||||
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
//
|
||||
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
SetNextScene(SceneList::LOBBY);
|
||||
}
|
||||
if (optionsButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
SetNextScene(SceneList::OPTIONSCREEN);
|
||||
}
|
||||
if (quitButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
QuitEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
@@ -63,7 +80,3 @@ void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
//
|
||||
}
|
||||
|
||||
+10
-1
@@ -2,6 +2,10 @@
|
||||
#define MAINMENU_HPP_
|
||||
|
||||
#include "base_scene.hpp"
|
||||
#include "service_locator.hpp"
|
||||
|
||||
#include "surface_manager.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
class MainMenu : public BaseScene {
|
||||
public:
|
||||
@@ -21,7 +25,12 @@ protected:
|
||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||
void KeyDown(SDL_KeyboardEvent const&);
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
||||
|
||||
Button startButton;
|
||||
Button optionsButton;
|
||||
Button quitButton;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,6 +12,7 @@ OptionScreen::OptionScreen() {
|
||||
#ifdef DEBUG
|
||||
cout << "entering OptionScreen" << endl;
|
||||
#endif
|
||||
backButton.Setup(50, 50, surfaceMgr->Get("button"), surfaceMgr->Get("font"), "Back");
|
||||
}
|
||||
|
||||
OptionScreen::~OptionScreen() {
|
||||
@@ -24,20 +25,8 @@ OptionScreen::~OptionScreen() {
|
||||
//Frame loop
|
||||
//-------------------------
|
||||
|
||||
void OptionScreen::FrameStart() {
|
||||
//
|
||||
}
|
||||
|
||||
void OptionScreen::Update(double delta) {
|
||||
//
|
||||
}
|
||||
|
||||
void OptionScreen::FrameEnd() {
|
||||
//
|
||||
}
|
||||
|
||||
void OptionScreen::Render(SDL_Surface* const screen) {
|
||||
//
|
||||
backButton.DrawTo(screen);
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -45,15 +34,17 @@ void OptionScreen::Render(SDL_Surface* const screen) {
|
||||
//-------------------------
|
||||
|
||||
void OptionScreen::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
//
|
||||
backButton.MouseMotion(motion);
|
||||
}
|
||||
|
||||
void OptionScreen::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
//
|
||||
backButton.MouseButtonDown(button);
|
||||
}
|
||||
|
||||
void OptionScreen::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
//
|
||||
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
QuitEvent();
|
||||
}
|
||||
}
|
||||
|
||||
void OptionScreen::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
@@ -63,7 +54,3 @@ void OptionScreen::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionScreen::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
//
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
#define OPTIONSCREEN_HPP_
|
||||
|
||||
#include "base_scene.hpp"
|
||||
#include "service_locator.hpp"
|
||||
|
||||
#include "surface_manager.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
class OptionScreen : public BaseScene {
|
||||
public:
|
||||
@@ -11,17 +15,17 @@ public:
|
||||
|
||||
protected:
|
||||
/* Frame loop */
|
||||
void FrameStart();
|
||||
void Update(double delta);
|
||||
void FrameEnd();
|
||||
void Render(SDL_Surface* const);
|
||||
|
||||
/* Event handlers */
|
||||
void QuitEvent() { SetNextScene(SceneList::MAINMENU); }
|
||||
void MouseMotion(SDL_MouseMotionEvent const&);
|
||||
void MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||
void KeyDown(SDL_KeyboardEvent const&);
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
SurfaceManager* surfaceMgr = ServiceLocator<SurfaceManager>::Get();
|
||||
Button backButton;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,15 +23,13 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
Button::Button():
|
||||
Button(0,0, nullptr, nullptr)
|
||||
{
|
||||
Button::Button(Sint16 i, Sint16 j, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string s) {
|
||||
Setup(i, j, imageSurface, fontSurface, s);
|
||||
}
|
||||
|
||||
Button::Button(Sint16 i, Sint16 j, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string s) {
|
||||
void Button::Setup(Sint16 i, Sint16 j, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string s) {
|
||||
x = i;
|
||||
y = j;
|
||||
state = State::NORMAL;
|
||||
|
||||
SetSurfaces(imageSurface, fontSurface);
|
||||
|
||||
|
||||
@@ -34,9 +34,11 @@ public:
|
||||
NORMAL, HOVER, PRESSED
|
||||
};
|
||||
|
||||
Button();
|
||||
Button() = default;
|
||||
Button(Sint16 x, Sint16 y, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string text = "");
|
||||
|
||||
void Setup(Sint16 x, Sint16 y, SDL_Surface* imageSurface, SDL_Surface* fontSurface, std::string text = "");
|
||||
|
||||
//return the current state
|
||||
State MouseMotion(SDL_MouseMotionEvent const&);
|
||||
State MouseButtonDown(SDL_MouseButtonEvent const&);
|
||||
@@ -69,11 +71,11 @@ public:
|
||||
private:
|
||||
State CalcState(Sint16 x, Sint16 y, bool leftPressed);
|
||||
|
||||
Sint16 x, y;
|
||||
Sint16 textX, textY; //prevent recalc every loop
|
||||
Sint16 x = 0, y = 0;
|
||||
Sint16 textX = 0, textY = 0; //prevent recalc every loop
|
||||
Image image;
|
||||
RasterFont font;
|
||||
State state;
|
||||
State state = State::NORMAL;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user