| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#ifndef _MENUSYSTEM_H |
| 26 |
#define _MENUSYSTEM_H |
| 27 |
|
| 28 |
#include <string> |
| 29 |
#include "SDL.h" |
| 30 |
#include <map> |
| 31 |
#include <vector> |
| 32 |
#include "sago/SagoSprite.hpp" |
| 33 |
#include "sago/GameStateInterface.hpp" |
| 34 |
#include <memory> |
| 35 |
#include "sago/SagoTextField.hpp" |
| 36 |
|
| 37 |
|
| 38 |
struct ButtonGfx |
| 39 |
{ |
| 40 |
|
| 41 |
int xsize = 0; |
| 42 |
int ysize = 0; |
| 43 |
sago::SagoTextField* getLabel(const std::string& text, bool marked) const; |
| 44 |
void setSurfaces(); |
| 45 |
std::string menu_marked = "menu_marked"; |
| 46 |
std::string menu_unmarked = "menu_unmarked"; |
| 47 |
private: |
| 48 |
mutable std::map<std::string, std::shared_ptr<sago::SagoTextField> > labels; |
| 49 |
mutable std::map<std::string, std::shared_ptr<sago::SagoTextField> > labels_marked; |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
class Button |
| 54 |
{ |
| 55 |
private: |
| 56 |
|
| 57 |
void (*action)(void) = nullptr; |
| 58 |
|
| 59 |
|
| 60 |
bool popOnRun = false; |
| 61 |
|
| 62 |
|
| 63 |
std::string label; |
| 64 |
public: |
| 65 |
|
| 66 |
bool marked = false; |
| 67 |
|
| 68 |
int x = 0; |
| 69 |
int y = 0; |
| 70 |
ButtonGfx standardButton; |
| 71 |
|
| 72 |
Button() = default; |
| 73 |
Button(const Button& b); |
| 74 |
Button& operator=(const Button& other); |
| 75 |
virtual ~Button() = default; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
void setLabel(const std::string& text); |
| 80 |
|
| 81 |
void setAction(void (*action2run)(void)); |
| 82 |
|
| 83 |
virtual void doAction(); |
| 84 |
void setPopOnRun(bool popOnRun); |
| 85 |
bool isPopOnRun() const; |
| 86 |
virtual const std::string& getLabel() const {return this->label; }; |
| 87 |
|
| 88 |
|
| 89 |
int iGeneric1 = 0; |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
class Menu : public sago::GameStateInterface |
| 94 |
{ |
| 95 |
private: |
| 96 |
bool isSubmenu = false; |
| 97 |
int marked = 0; |
| 98 |
bool running = true; |
| 99 |
SDL_Renderer *screen = nullptr; |
| 100 |
std::string title; |
| 101 |
bool bMouseUp = false; |
| 102 |
public: |
| 103 |
|
| 104 |
|
| 105 |
Menu(SDL_Renderer *screen,bool isSubmenu); |
| 106 |
explicit Menu(SDL_Renderer *screen); |
| 107 |
Menu(SDL_Renderer *screen, const std::string& title, bool isSubmenu); |
| 108 |
virtual ~Menu() {} |
| 109 |
|
| 110 |
|
| 111 |
void addButton(Button *b); |
| 112 |
|
| 113 |
bool IsActive() override; |
| 114 |
void Draw(SDL_Renderer* target) override; |
| 115 |
void ProcessInput(const SDL_Event& event, bool &processed) override; |
| 116 |
void Update() override; |
| 117 |
void drawSelf(SDL_Renderer* target); |
| 118 |
virtual void placeButtons(); |
| 119 |
|
| 120 |
std::vector<Button*> buttons; |
| 121 |
Button exit; |
| 122 |
}; |
| 123 |
|
| 124 |
class FileMenu |
| 125 |
{ |
| 126 |
private: |
| 127 |
std::string pm_path; |
| 128 |
std::string pm_fileending; |
| 129 |
bool pm_hidden_files = false; |
| 130 |
public: |
| 131 |
FileMenu(const std::string& path, const std::string& fileending, bool hidden_files = false); |
| 132 |
|
| 133 |
std::string getFile(SDL_Surface **screen); |
| 134 |
}; |
| 135 |
|
| 136 |
bool isUpEvent(const SDL_Event& event); |
| 137 |
|
| 138 |
bool isDownEvent(const SDL_Event& event); |
| 139 |
|
| 140 |
bool isLeftEvent(const SDL_Event& event); |
| 141 |
|
| 142 |
bool isRightEvent(const SDL_Event& event); |
| 143 |
|
| 144 |
bool isEscapeEvent(const SDL_Event& event); |
| 145 |
|
| 146 |
bool isConfirmEvent(const SDL_Event& event); |
| 147 |
|
| 148 |
#endif |
| 149 |
|