2013-12-25 20:54:22 +01:00
|
|
|
#ifndef _GAME_MENUSYSTEM_HPP_
|
|
|
|
#define _GAME_MENUSYSTEM_HPP_
|
2018-12-01 18:26:35 +01:00
|
|
|
|
2016-09-09 22:13:20 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2018-12-26 21:48:16 +01:00
|
|
|
#include <initializer_list>
|
2016-09-09 22:13:20 +02:00
|
|
|
#include <memory>
|
2018-12-01 18:26:35 +01:00
|
|
|
#include <optional>
|
2016-09-09 22:13:20 +02:00
|
|
|
#include <string>
|
2018-12-09 22:43:42 +01:00
|
|
|
#include <vector>
|
2013-12-25 20:54:22 +01:00
|
|
|
|
2018-12-09 22:43:42 +01:00
|
|
|
#include <glm/vec2.hpp>
|
2017-11-01 04:36:52 +01:00
|
|
|
|
2018-12-09 22:43:42 +01:00
|
|
|
#include <fonts/GameTexts.hpp>
|
2018-06-21 16:49:05 +02:00
|
|
|
#include <rw/debug.hpp>
|
2017-11-01 04:36:52 +01:00
|
|
|
|
2018-12-09 22:43:42 +01:00
|
|
|
class GameRenderer;
|
|
|
|
|
2016-08-16 01:28:35 +02:00
|
|
|
/**
|
|
|
|
* Default values for menus that should match the look and feel of the original
|
|
|
|
*/
|
2016-09-09 22:13:20 +02:00
|
|
|
namespace MenuDefaults {
|
2016-08-16 01:28:35 +02:00
|
|
|
constexpr int kFont = 1;
|
|
|
|
constexpr const char* kStartGameId = "FET_SAN";
|
|
|
|
constexpr const char* kResumeGameId = "FEM_RES";
|
|
|
|
constexpr const char* kLoadGameId = "FET_LG";
|
|
|
|
constexpr const char* kDebugId = "FEM_DBG";
|
|
|
|
constexpr const char* kOptionsId = "FET_OPT";
|
|
|
|
constexpr const char* kQuitGameId = "FET_QG";
|
|
|
|
}
|
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
/**
|
|
|
|
* @brief Implements user navigable menus
|
|
|
|
*
|
|
|
|
* This is a temporary implementation
|
|
|
|
*/
|
2016-09-09 22:13:20 +02:00
|
|
|
class Menu {
|
2013-12-25 20:54:22 +01:00
|
|
|
public:
|
2016-10-18 23:00:53 +02:00
|
|
|
/**
|
|
|
|
* @brief Handles rendering and dispatch of menu items
|
|
|
|
*/
|
|
|
|
class MenuEntry {
|
2016-09-09 22:13:20 +02:00
|
|
|
GameString text;
|
2016-10-18 23:00:53 +02:00
|
|
|
std::function<void(void)> callback;
|
2016-09-09 22:13:20 +02:00
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
public:
|
2018-05-08 16:10:29 +02:00
|
|
|
MenuEntry(const std::string& n, const std::function<void(void)>& cb)
|
2017-09-07 19:00:16 +02:00
|
|
|
: text(GameStringUtil::fromString(n, FONT_PRICEDOWN)), callback(cb) {
|
2016-10-18 23:00:53 +02:00
|
|
|
}
|
2018-05-08 16:10:29 +02:00
|
|
|
MenuEntry(const GameString& n, const std::function<void(void)>& cb)
|
2016-10-20 00:34:08 +02:00
|
|
|
: text(n), callback(cb) {
|
2016-09-09 22:13:20 +02:00
|
|
|
}
|
|
|
|
|
2018-12-01 18:57:06 +01:00
|
|
|
void draw(font_t font, float size, bool active, GameRenderer& r,
|
2018-12-09 22:43:42 +01:00
|
|
|
glm::vec2& basis);
|
2016-09-09 22:13:20 +02:00
|
|
|
|
|
|
|
void activate(float clickX, float clickY) {
|
|
|
|
RW_UNUSED(clickX);
|
|
|
|
RW_UNUSED(clickY);
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-26 21:48:16 +01:00
|
|
|
Menu(std::initializer_list<MenuEntry>&& initial,
|
|
|
|
const glm::vec2& offset = glm::vec2(), int font = MenuDefaults::kFont,
|
2016-10-20 00:34:08 +02:00
|
|
|
float size = 30.f)
|
2018-12-26 21:48:16 +01:00
|
|
|
: activeEntry(-1)
|
|
|
|
, offset(offset)
|
|
|
|
, font(font)
|
|
|
|
, size(size)
|
|
|
|
, entries(initial) {
|
2016-09-09 22:13:20 +02:00
|
|
|
}
|
|
|
|
|
2016-10-18 23:00:53 +02:00
|
|
|
Menu& lambda(const GameString& n, std::function<void()> callback) {
|
2016-10-20 00:34:08 +02:00
|
|
|
entries.emplace_back(n, callback);
|
2016-10-18 23:00:53 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Menu& lambda(const std::string& n, std::function<void(void)> callback) {
|
2017-09-07 19:00:16 +02:00
|
|
|
entries.emplace_back(GameStringUtil::fromString(n, FONT_PRICEDOWN), callback);
|
2016-10-18 23:00:53 +02:00
|
|
|
return *this;
|
|
|
|
}
|
2016-09-09 22:13:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Active Entry index
|
|
|
|
*/
|
|
|
|
int activeEntry;
|
|
|
|
|
2018-12-09 22:43:42 +01:00
|
|
|
void draw(GameRenderer& r);
|
2016-09-09 22:13:20 +02:00
|
|
|
|
2018-12-09 22:43:42 +01:00
|
|
|
void hover(const float x, const float y);
|
2016-09-09 22:13:20 +02:00
|
|
|
|
2018-12-09 22:43:42 +01:00
|
|
|
void click(const float x, const float y);
|
2016-09-09 22:13:20 +02:00
|
|
|
|
|
|
|
// Activates the menu entry at the current active index.
|
2018-12-09 22:43:42 +01:00
|
|
|
void activate();
|
2016-09-09 22:13:20 +02:00
|
|
|
|
2018-12-09 22:43:42 +01:00
|
|
|
void move(int movement);
|
2016-10-18 23:00:53 +02:00
|
|
|
|
|
|
|
const std::vector<MenuEntry>& getEntries() const {
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2018-12-26 21:48:16 +01:00
|
|
|
glm::vec2 offset{};
|
2016-10-18 23:00:53 +02:00
|
|
|
int font;
|
2016-10-20 00:34:08 +02:00
|
|
|
float size;
|
2016-10-18 23:00:53 +02:00
|
|
|
std::vector<MenuEntry> entries;
|
2013-12-25 20:54:22 +01:00
|
|
|
};
|
|
|
|
|
2014-06-01 19:26:53 +02:00
|
|
|
#endif
|