1 //  $Id: menu.h 1053 2004-05-09 18:08:02Z tobgle $
2 //
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 
20 #ifndef SUPERTUX_MENU_H
21 #define SUPERTUX_MENU_H
22 
23 #include <SDL.h>
24 #include <vector>
25 #include "texture.h"
26 #include "timer.h"
27 #include "type.h"
28 #include "mousecursor.h"
29 
30 /* IDs for menus */
31 
32 enum MainMenuIDs {
33   MNID_STARTGAME,
34   MNID_CONTRIB,
35   MNID_OPTIONMENU,
36   MNID_LEVELEDITOR,
37   MNID_CREDITS,
38   MNID_QUITMAINMENU
39   };
40 
41 enum OptionsMenuIDs {
42   MNID_OPENGL,
43   MNID_FULLSCREEN,
44   MNID_SOUND,
45   MNID_MUSIC,
46   MNID_SHOWFPS
47   };
48 
49 enum GameMenuIDs {
50   MNID_CONTINUE,
51   MNID_ABORTLEVEL
52   };
53 
54 enum WorldMapMenuIDs {
55   MNID_RETURNWORLDMAP,
56   MNID_QUITWORLDMAP
57   };
58 
59 enum LevelEditorMainMenuIDs {
60   MNID_RETURNLEVELEDITOR,
61   MNID_SUBSETSETTINGS,
62   MNID_QUITLEVELEDITOR
63   };
64 
65 enum LevelEditorSubsetSettingsIDs {
66   MNID_SUBSETTITLE,
67   MNID_SUBSETDESCRIPTION,
68   MNID_SUBSETSAVECHANGES
69   };
70 
71 enum LevelEditorSubsetNewIDs {
72  MNID_SUBSETNAME,
73  MNID_CREATESUBSET
74 };
75 
76 enum LevelEditorSettingsMenuIDs {
77   MNID_NAME,
78   MNID_AUTHOR,
79   MNID_SONG,
80   MNID_BGIMG,
81   MNID_PARTICLE,
82   MNID_LENGTH,
83   MNID_TIME,
84   MNID_GRAVITY,
85   MNID_BGSPEED,
86   MNID_TopRed,
87   MNID_TopGreen,
88   MNID_TopBlue,
89   MNID_BottomRed,
90   MNID_BottomGreen,
91   MNID_BottomBlue,
92   MNID_APPLY
93   };
94 
95 bool confirm_dialog(std::string text);
96 
97 /* Kinds of menu items */
98 enum MenuItemKind {
99   MN_ACTION,
100   MN_GOTO,
101   MN_TOGGLE,
102   MN_BACK,
103   MN_DEACTIVE,
104   MN_TEXTFIELD,
105   MN_NUMFIELD,
106   MN_CONTROLFIELD,
107   MN_STRINGSELECT,
108   MN_LABEL,
109   MN_HL, /* horizontal line */
110 };
111 
112 class Menu;
113 
114 class MenuItem
115 {
116 public:
117   MenuItemKind kind;
118   int toggled;
119   char *text;
120   char *input;
121   int *int_p;   // used for setting keys (can be used for more stuff...)
122   int id;   // item id
123   string_list_type* list;
124   Menu* target_menu;
125 
126   void change_text (const char *text);
127   void change_input(const char *text);
128 
129   static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p);
130 
131   std::string get_input_with_symbol(bool active_item);   // returns the text with an input symbol
132 private:
133   bool input_flickering;
134   Timer input_flickering_timer;
135 };
136 
137 class Menu
138 {
139 private:
140   static std::vector<Menu*> last_menus;
141   static Menu* current_;
142 
143   static void push_current(Menu* pmenu);
144   static void pop_current();
145 
146 public:
147   /** Set the current menu, if pmenu is NULL, hide the current menu */
148   static void set_current(Menu* pmenu);
149 
150   /** Return the current active menu or NULL if none is active */
current()151   static Menu* current() { return current_; }
152 
153 private:
154   /* Action done on the menu */
155   enum MenuAction {
156     MENU_ACTION_NONE = -1,
157     MENU_ACTION_UP,
158     MENU_ACTION_DOWN,
159     MENU_ACTION_LEFT,
160     MENU_ACTION_RIGHT,
161     MENU_ACTION_HIT,
162     MENU_ACTION_INPUT,
163     MENU_ACTION_REMOVE
164   };
165 
166   /** Number of the item that got 'hit' (ie. pressed) in the last
167       event()/action() call, -1 if none */
168   int hit_item;
169 
170   // position of the menu (ie. center of the menu, not top/left)
171   int pos_x;
172   int pos_y;
173 
174   /** input event for the menu (up, down, left, right, etc.) */
175   MenuAction menuaction;
176 
177   /* input implementation variables */
178   int delete_character;
179   char mn_input_char;
180 
181 public:
182   Timer effect;
183   int arrange_left;
184   int active_item;
185 
186   std::vector<MenuItem> item;
187 
188   Menu();
189   ~Menu();
190 
191   void additem(MenuItem* pmenu_item);
192   void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL);
193 
194   void  action ();
195 
196   /** Remove all entries from the menu */
197   void clear();
198 
199   /** Return the index of the menu item that was 'hit' (ie. the user
200       clicked on it) in the last event() call */
201   int  check  ();
202 
get_item(int index)203   MenuItem& get_item(int index) { return item[index]; }
204   MenuItem& get_item_by_id(int id);
205 
206   int get_active_item_id();
207 
208   bool isToggled(int id);
209 
210   void get_controlfield_key_into_input(MenuItem *item);
211 
212   void draw   ();
213   void draw_item(int index, int menu_width, int menu_height);
214   void set_pos(int x, int y, float rw = 0, float rh = 0);
215 
216   /** translate a SDL_Event into a menu_action */
217   void event(SDL_Event& event);
218 
219   int get_width() const;
220   int get_height() const;
221 
222   bool is_toggled(int id) const;
223 };
224 
225 extern Surface* checkbox;
226 extern Surface* checkbox_checked;
227 extern Surface* back;
228 extern Surface* arrow_left;
229 extern Surface* arrow_right;
230 
231 extern Menu* contrib_menu;
232 extern Menu* contrib_subset_menu;
233 extern Menu* main_menu;
234 extern Menu* game_menu;
235 extern Menu* worldmap_menu;
236 extern Menu* options_menu;
237 extern Menu* options_keys_menu;
238 extern Menu* options_joystick_menu;
239 extern Menu* highscore_menu;
240 extern Menu* load_game_menu;
241 extern Menu* save_game_menu;
242 
243 #endif /*SUPERTUX_MENU_H*/
244 
245 /* Local Variables: */
246 /* mode: c++ */
247 /* End: */
248