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