removed in favor of the new library
[supertux.git] / src / menu.h
1 //  $Id$
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 <vector>
24
25 #include "SDL.h"
26
27 #include "screen/surface.h"
28 #include "timer.h"
29 #include "type.h"
30 #include "mousecursor.h"
31
32 /* IDs for menus */
33
34 enum MainMenuIDs {
35   MNID_STARTGAME,
36   MNID_LEVELS_CONTRIB,
37   MNID_OPTIONMENU,
38   MNID_LEVELEDITOR,
39   MNID_CREDITS,
40   MNID_QUITMAINMENU
41   };
42
43 enum OptionsMenuIDs {
44   MNID_OPENGL,
45   MNID_FULLSCREEN,
46   MNID_SOUND,
47   MNID_MUSIC,
48   MNID_SHOWFPS
49   };
50
51 enum GameMenuIDs {
52   MNID_CONTINUE,
53   MNID_ABORTLEVEL
54   };
55
56 enum WorldMapMenuIDs {
57   MNID_RETURNWORLDMAP,
58   MNID_QUITWORLDMAP
59   };
60
61 enum LevelEditorMainMenuIDs {
62   MNID_RETURNLEVELEDITOR,
63   MNID_SUBSETSETTINGS,
64   MNID_QUITLEVELEDITOR
65   };
66   
67 enum LevelEditorSubsetSettingsIDs {
68   MNID_SUBSETTITLE,
69   MNID_SUBSETDESCRIPTION,
70   MNID_SUBSETSAVECHANGES
71   };
72   
73 enum LevelEditorSubsetNewIDs {
74  MNID_SUBSETNAME,
75  MNID_CREATESUBSET
76 };
77
78 enum LevelEditorSettingsMenuIDs {
79   MNID_NAME,
80   MNID_AUTHOR,
81   MNID_SONG,
82   MNID_BGIMG,
83   MNID_PARTICLE,
84   MNID_LENGTH,
85   MNID_HEIGHT,
86   MNID_TIME,
87   MNID_GRAVITY,
88   MNID_BGSPEED,
89   MNID_TopRed,
90   MNID_TopGreen,
91   MNID_TopBlue,
92   MNID_BottomRed,
93   MNID_BottomGreen,
94   MNID_BottomBlue,
95   MNID_APPLY
96   };
97
98 bool confirm_dialog(Surface* background, std::string text);
99
100 /* Kinds of menu items */
101 enum MenuItemKind {
102   MN_ACTION,
103   MN_GOTO,
104   MN_TOGGLE,
105   MN_BACK,
106   MN_DEACTIVE,
107   MN_TEXTFIELD,
108   MN_NUMFIELD,
109   MN_CONTROLFIELD_KB,
110   MN_CONTROLFIELD_JS,
111   MN_STRINGSELECT,
112   MN_LABEL,
113   MN_HL, /* horizontal line */
114 };
115
116 class Menu;
117
118 class MenuItem
119 {
120 public:
121   MenuItemKind kind;
122   int toggled;
123   char *text;
124   char *input;
125   int *int_p;   // used for setting keys (can be used for more stuff...)
126   int id;   // item id
127   string_list_type* list;
128   Menu* target_menu;
129
130   void change_text (const char *text);
131   void change_input(const char *text);
132
133   static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p);
134
135   std::string get_input_with_symbol(bool active_item);   // returns the text with an input symbol
136 private:
137   bool input_flickering;
138   Timer input_flickering_timer;
139 };
140
141 class Menu
142 {
143 private:  
144   static std::vector<Menu*> last_menus;
145   static Menu* current_;
146
147   static void push_current(Menu* pmenu);
148   static void pop_current();
149
150 public:
151   /** Set the current menu, if pmenu is NULL, hide the current menu */
152   static void set_current(Menu* pmenu);
153
154   /** Return the current active menu or NULL if none is active */
155   static Menu* current() { return current_; }
156
157 private:
158   /* Action done on the menu */
159   enum MenuAction {
160     MENU_ACTION_NONE = -1,
161     MENU_ACTION_UP,
162     MENU_ACTION_DOWN,
163     MENU_ACTION_LEFT,
164     MENU_ACTION_RIGHT,
165     MENU_ACTION_HIT,
166     MENU_ACTION_INPUT,
167     MENU_ACTION_REMOVE
168   };
169
170   /** Number of the item that got 'hit' (ie. pressed) in the last
171       event()/action() call, -1 if none */
172   int hit_item;
173
174   // position of the menu (ie. center of the menu, not top/left)
175   int pos_x;
176   int pos_y;
177
178   /** input event for the menu (up, down, left, right, etc.) */
179   MenuAction menuaction;
180
181   /* input implementation variables */
182   int delete_character;
183   char mn_input_char;
184   Timer joystick_timer;
185   
186 public:
187   Timer effect;
188   int arrange_left;
189   int active_item;
190
191   std::vector<MenuItem> item;
192
193   Menu();
194   ~Menu();
195
196   void additem(MenuItem* pmenu_item);
197   void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL);
198   
199   void  action ();
200   
201   /** Remove all entries from the menu */
202   void clear();
203
204   /** Return the index of the menu item that was 'hit' (ie. the user
205       clicked on it) in the last event() call */
206   int  check  ();
207
208   MenuItem& get_item(int index) { return item[index]; }
209   MenuItem& get_item_by_id(int id);
210
211   int get_active_item_id();
212
213   bool isToggled(int id);
214
215   void Menu::get_controlfield_key_into_input(MenuItem *item);
216   void Menu::get_controlfield_js_into_input(MenuItem *item);
217
218   void draw(DrawingContext& context);
219   void draw_item(DrawingContext& context,
220       int index, int menu_width, int menu_height);
221   void set_pos(int x, int y, float rw = 0, float rh = 0);
222
223   /** translate a SDL_Event into a menu_action */
224   void event(SDL_Event& event);
225
226   int get_width() const;
227   int get_height() const;
228
229   bool is_toggled(int id) const;
230 };
231
232 extern Surface* checkbox;
233 extern Surface* checkbox_checked;
234 extern Surface* back;
235 extern Surface* arrow_left;
236 extern Surface* arrow_right;
237
238 extern Menu* contrib_menu;
239 extern Menu* contrib_subset_menu;
240 extern Menu* main_menu;
241 extern Menu* game_menu;
242 extern Menu* worldmap_menu;
243 extern Menu* options_menu;
244 extern Menu* options_keys_menu;
245 extern Menu* options_joystick_menu;
246 extern Menu* highscore_menu;
247 extern Menu* load_game_menu;
248 extern Menu* save_game_menu;
249
250 #endif /*SUPERTUX_MENU_H*/
251
252 /* Local Variables: */
253 /* mode: c++ */
254 /* End: */