| f3ef3495 |
sago007 |
2008-11-13 20:00 |
1 |
/* |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2 |
=========================================================================== |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3 |
blockattack - Block Attack - Rise of the Blocks |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
4 |
Copyright (C) 2005-2012 Poul Sander |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
5 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
6 |
This program is free software: you can redistribute it and/or modify |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
7 |
it under the terms of the GNU General Public License as published by |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
8 |
the Free Software Foundation, either version 2 of the License, or |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
9 |
(at your option) any later version. |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
10 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
11 |
This program is distributed in the hope that it will be useful, |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
14 |
GNU General Public License for more details. |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
15 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
16 |
You should have received a copy of the GNU General Public License |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
17 |
along with this program. If not, see http://www.gnu.org/licenses/ |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
18 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
19 |
Source information and contacts persons can be found at |
| 021de090 |
sago007 |
2015-12-30 18:56 |
20 |
http://blockattack.net |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
21 |
=========================================================================== |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
22 |
*/ |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
23 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
24 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
25 |
#ifndef _MENUSYSTEM_H |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
26 |
#define _MENUSYSTEM_H |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
27 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
28 |
#include <string> |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
29 |
#include "SDL.h" |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
30 |
#include <vector> |
| b7590374 |
sago007 |
2011-05-19 16:15 |
31 |
#include "Libs/NFont.h" |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
32 |
#include "sago/SagoSprite.hpp" |
| 00e866da |
sago007 |
2016-10-31 20:47 |
33 |
#include "sago/GameStateInterface.hpp" |
| f3a1637d |
sago007 |
2015-11-14 21:32 |
34 |
#include <memory> |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
35 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
36 |
//The ButtonGfx object hold common media for all buttons, so we can reskin them by only changeing one pointer |
| 78ab168e |
sago007 |
2015-11-14 22:02 |
37 |
struct ButtonGfx |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
38 |
{ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
39 |
//The size of the buttons, so we don't have to ask w and h from the SDL Surfaces each time |
| 8ff26872 |
sago007 |
2016-03-25 09:46 |
40 |
int xsize = 0; |
| 8ff26872 |
sago007 |
2016-03-25 09:46 |
41 |
int ysize = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
42 |
//A TTFont used for writing the label on the buttons |
| 8ff26872 |
sago007 |
2016-03-25 09:46 |
43 |
NFont* thefont = nullptr; |
| 094b2dfe |
sago007 |
2016-06-12 10:50 |
44 |
void setSurfaces(); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
45 |
}; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
46 |
|
| b283e0f7 |
sago007 |
2012-07-29 14:01 |
47 |
extern ButtonGfx standardButton; |
| b283e0f7 |
sago007 |
2012-07-29 14:01 |
48 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
49 |
//A button |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
50 |
class Button |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
51 |
{ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
52 |
private: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
53 |
//Pointer to a callback function. |
| 29edda2d |
sago007 |
2016-10-08 18:06 |
54 |
void (*action)(void); |
| b4f1d3cf |
sago007 |
2012-08-20 21:28 |
55 |
|
| 67a32395 |
sago007 |
2012-04-19 18:40 |
56 |
//If true the menu should also be closed then the button is clicked |
| 8ff26872 |
sago007 |
2016-03-25 09:46 |
57 |
bool popOnRun = false; |
| b4f1d3cf |
sago007 |
2012-08-20 21:28 |
58 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
59 |
public: |
| c0a3362c |
sago007 |
2016-10-07 20:23 |
60 |
//The label. This is written on the button |
| c0a3362c |
sago007 |
2016-10-07 20:23 |
61 |
std::string label; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
62 |
//Is the button marked? |
| 733af903 |
sago007 |
2016-03-24 14:58 |
63 |
bool marked = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
64 |
//Where is the button on the screen |
| 733af903 |
sago007 |
2016-03-24 14:58 |
65 |
int x = 0; |
| 733af903 |
sago007 |
2016-03-24 14:58 |
66 |
int y = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
67 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
68 |
Button(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
69 |
Button(const Button& b); |
| de81e07d |
sago007 |
2016-07-10 20:22 |
70 |
virtual ~Button(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
71 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
72 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
73 |
//Set the text to write on the button |
| 33f4e975 |
sago007 |
2015-11-14 21:49 |
74 |
void setLabel(const std::string& text); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
75 |
//Set the action to run |
| 29edda2d |
sago007 |
2016-10-08 18:06 |
76 |
void setAction(void (*action2run)(void)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
77 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
78 |
virtual void doAction(); //Run the callback function |
| b4f1d3cf |
sago007 |
2012-08-20 21:28 |
79 |
void setPopOnRun(bool popOnRun); |
| b4f1d3cf |
sago007 |
2012-08-20 21:28 |
80 |
bool isPopOnRun() const; |
| b4f1d3cf |
sago007 |
2012-08-20 21:28 |
81 |
|
| 67a32395 |
sago007 |
2012-04-19 18:40 |
82 |
//May hold any other information the callback might need |
| 733af903 |
sago007 |
2016-03-24 14:58 |
83 |
int iGeneric1 = 0; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
84 |
}; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
85 |
|
| 26ddb424 |
sago007 |
2011-06-09 20:06 |
86 |
|
| 00e866da |
sago007 |
2016-10-31 20:47 |
87 |
class Menu : public sago::GameStateInterface |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
88 |
{ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
89 |
private: |
| 33f4e975 |
sago007 |
2015-11-14 21:49 |
90 |
std::vector<Button*> buttons; //Vector holder the buttons |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
91 |
Button exit; //The exit button is special since it does not have a callback function |
| 8ff26872 |
sago007 |
2016-03-25 09:46 |
92 |
bool isSubmenu = false; //True if the menu is a submenu |
| 8ff26872 |
sago007 |
2016-03-25 09:46 |
93 |
int marked = 0; //The index of the marked button (for keyboard up/down) |
| 733af903 |
sago007 |
2016-03-24 14:58 |
94 |
bool running = true; //The menu is running. The menu will terminate then this is false |
| 8ff26872 |
sago007 |
2016-03-25 09:46 |
95 |
SDL_Renderer *screen = nullptr; //Pointer to the screen to draw to |
| 33f4e975 |
sago007 |
2015-11-14 21:49 |
96 |
std::string title; |
| 95ab6b0d |
sago007 |
2016-11-12 16:11 |
97 |
void drawSelf(SDL_Renderer* target); //Private function to draw the screen |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
98 |
void placeButtons(); //Rearanges the buttons to the correct place. |
| 50fd2c5f |
sago007 |
2016-11-12 16:05 |
99 |
bool bMouseUp = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
100 |
public: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
101 |
//numberOfItems is the expected numberOfItems for vector initialization |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
102 |
//SubMenu is true by default |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
103 |
Menu(SDL_Renderer *screen,bool isSubmenu); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
104 |
Menu(SDL_Renderer *screen); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
105 |
Menu(SDL_Renderer *screen, const std::string& title, bool isSubmenu); |
| 00e866da |
sago007 |
2016-10-31 20:47 |
106 |
virtual ~Menu() {} |
| 00e866da |
sago007 |
2016-10-31 20:47 |
107 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
108 |
//Add a button to the menu |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
109 |
void addButton(Button *b); |
| 00e866da |
sago007 |
2016-10-31 20:47 |
110 |
|
| 00e866da |
sago007 |
2016-10-31 20:47 |
111 |
bool IsActive() override; |
| 00e866da |
sago007 |
2016-10-31 20:47 |
112 |
void Draw(SDL_Renderer* target) override; |
| 00e866da |
sago007 |
2016-10-31 20:47 |
113 |
void ProcessInput(const SDL_Event& event, bool &processed) override; |
| 50fd2c5f |
sago007 |
2016-11-12 16:05 |
114 |
void Update() override; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
115 |
}; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
116 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
117 |
class FileMenu |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
118 |
{ |
| cc3ef158 |
sago007 |
2011-07-03 16:13 |
119 |
private: |
| 33f4e975 |
sago007 |
2015-11-14 21:49 |
120 |
std::string pm_path; |
| 33f4e975 |
sago007 |
2015-11-14 21:49 |
121 |
std::string pm_fileending; |
| 8ff26872 |
sago007 |
2016-03-25 09:46 |
122 |
bool pm_hidden_files = false; |
| cc3ef158 |
sago007 |
2011-07-03 16:13 |
123 |
public: |
| 33f4e975 |
sago007 |
2015-11-14 21:49 |
124 |
FileMenu(const std::string& path, const std::string& fileending, bool hidden_files = false); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
125 |
|
| 33f4e975 |
sago007 |
2015-11-14 21:49 |
126 |
std::string getFile(SDL_Surface **screen); |
| cc3ef158 |
sago007 |
2011-07-03 16:13 |
127 |
}; |
| cc3ef158 |
sago007 |
2011-07-03 16:13 |
128 |
|
| d21782d4 |
sago007 |
2016-03-13 11:17 |
129 |
bool isUpEvent(const SDL_Event& event); |
| d21782d4 |
sago007 |
2016-03-13 11:17 |
130 |
|
| d21782d4 |
sago007 |
2016-03-13 11:17 |
131 |
bool isDownEvent(const SDL_Event& event); |
| d21782d4 |
sago007 |
2016-03-13 11:17 |
132 |
|
| d21782d4 |
sago007 |
2016-03-13 11:17 |
133 |
bool isLeftEvent(const SDL_Event& event); |
| d21782d4 |
sago007 |
2016-03-13 11:17 |
134 |
|
| d21782d4 |
sago007 |
2016-03-13 11:17 |
135 |
bool isRightEvent(const SDL_Event& event); |
| d21782d4 |
sago007 |
2016-03-13 11:17 |
136 |
|
| d21782d4 |
sago007 |
2016-03-13 11:17 |
137 |
bool isEscapeEvent(const SDL_Event& event); |
| d21782d4 |
sago007 |
2016-03-13 11:17 |
138 |
|
| d21782d4 |
sago007 |
2016-03-13 11:17 |
139 |
bool isConfirmEvent(const SDL_Event& event); |
| d21782d4 |
sago007 |
2016-03-13 11:17 |
140 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
141 |
#endif /* _MENUSYSTEM_H */ |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
142 |
|
|
|
1970-01-01 00:00 |
143 |
|