leveleditor improvements
[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 <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_SAVEGAME,
57   MNID_QUITWORLDMAP
58   };
59
60 enum LevelEditorMainMenuIDs {
61   MNID_RETURNLEVELEDITOR,
62   MNID_SUBSETSETTINGS,
63   MNID_QUITLEVELEDITOR
64   };
65
66 enum LevelEditorSettingsMenuIDs {
67   MNID_NAME,
68   MNID_AUTHOR,
69   MNID_SONG,
70   MNID_BGIMG,
71   MNID_LENGTH,
72   MNID_TIME,
73   MNID_GRAVITY,
74   MNID_TopRed,
75   MNID_TopGreen,
76   MNID_TopBlue,
77   MNID_BottomRed,
78   MNID_BottomGreen,
79   MNID_BottomBlue,
80   MNID_APPLY
81   };
82
83 bool confirm_dialog(char *text);
84
85 /* Kinds of menu items */
86 enum MenuItemKind {
87   MN_ACTION,
88   MN_GOTO,
89   MN_TOGGLE,
90   MN_BACK,
91   MN_DEACTIVE,
92   MN_TEXTFIELD,
93   MN_NUMFIELD,
94   MN_CONTROLFIELD,
95   MN_STRINGSELECT,
96   MN_LABEL,
97   MN_HL, /* horizontal line */
98 };
99
100 class Menu;
101
102 class MenuItem
103 {
104 public:
105   MenuItemKind kind;
106   int toggled;
107   char *text;
108   char *input;
109   int *int_p;   // used for setting keys (can be used for more stuff...)
110   int id;   // item id
111   string_list_type* list;
112   Menu* target_menu;
113
114   void change_text (const char *text);
115   void change_input(const char *text);
116
117   static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int id, int* int_p);
118
119   std::string get_input_with_symbol(bool active_item);   // returns the text with an input symbol
120 private:
121   bool input_flickering;
122   Timer input_flickering_timer;
123 };
124
125 class Menu
126 {
127 private:  
128   static std::vector<Menu*> last_menus;
129   static Menu* current_;
130
131   static void push_current(Menu* pmenu);
132   static void pop_current();
133
134 public:
135   /** Set the current menu, if pmenu is NULL, hide the current menu */
136   static void set_current(Menu* pmenu);
137
138   /** Return the current active menu or NULL if none is active */
139   static Menu* current() { return current_; }
140
141 private:
142   /* Action done on the menu */
143   enum MenuAction {
144     MENU_ACTION_NONE = -1,
145     MENU_ACTION_UP,
146     MENU_ACTION_DOWN,
147     MENU_ACTION_LEFT,
148     MENU_ACTION_RIGHT,
149     MENU_ACTION_HIT,
150     MENU_ACTION_INPUT,
151     MENU_ACTION_REMOVE
152   };
153
154   /** Number of the item that got 'hit' (ie. pressed) in the last
155       event()/action() call, -1 if none */
156   int hit_item;
157
158   // position of the menu (ie. center of the menu, not top/left)
159   int pos_x;
160   int pos_y;
161
162   /** input event for the menu (up, down, left, right, etc.) */
163   MenuAction menuaction;
164
165   /* input implementation variables */
166   int delete_character;
167   char mn_input_char;
168   
169 public:
170   Timer effect;
171   int arrange_left;
172   int active_item;
173
174   std::vector<MenuItem> item;
175
176   Menu();
177   ~Menu();
178
179   void additem(MenuItem* pmenu_item);
180   void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int id = -1, int *int_p = NULL);
181   
182   void  action ();
183   
184   /** Remove all entries from the menu */
185   void clear();
186
187   /** Return the index of the menu item that was 'hit' (ie. the user
188       clicked on it) in the last event() call */
189   int  check  ();
190
191   MenuItem& get_item(int index) { return item[index]; }
192   MenuItem& get_item_by_id(int id);
193
194   int get_active_item_id();
195
196   bool isToggled(int id);
197
198   void Menu::get_controlfield_key_into_input(MenuItem *item);
199
200   void draw   ();
201   void draw_item(int index, int menu_width, int menu_height);
202   void set_pos(int x, int y, float rw = 0, float rh = 0);
203
204   /** translate a SDL_Event into a menu_action */
205   void event(SDL_Event& event);
206
207   int get_width() const;
208   int get_height() const;
209
210   bool is_toggled(int id) const;
211 };
212
213 extern Surface* checkbox;
214 extern Surface* checkbox_checked;
215 extern Surface* back;
216 extern Surface* arrow_left;
217 extern Surface* arrow_right;
218
219 extern Menu* contrib_menu;
220 extern Menu* contrib_subset_menu;
221 extern Menu* main_menu;
222 extern Menu* game_menu;
223 extern Menu* worldmap_menu;
224 extern Menu* options_menu;
225 extern Menu* options_keys_menu;
226 extern Menu* options_joystick_menu;
227 extern Menu* highscore_menu;
228 extern Menu* load_game_menu;
229 extern Menu* save_game_menu;
230
231 #endif /*SUPERTUX_MENU_H*/
232
233 /* Local Variables: */
234 /* mode: c++ */
235 /* End: */