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