File: | src/menu.c |
Location: | line 1773, column 11 |
Description: | Potential leak of memory pointed to by 'char_name' |
1 | /* | |||
2 | * | |||
3 | * Copyright (c) 1994, 2002, 2003 Johannes Prix | |||
4 | * Copyright (c) 1994, 2002 Reinhard Prix | |||
5 | * Copyright (c) 2004-2010 Arthur Huillet | |||
6 | * | |||
7 | * | |||
8 | * This file is part of Freedroid | |||
9 | * | |||
10 | * Freedroid is free software; you can redistribute it and/or modify | |||
11 | * it under the terms of the GNU General Public License as published by | |||
12 | * the Free Software Foundation; either version 2 of the License, or | |||
13 | * (at your option) any later version. | |||
14 | * | |||
15 | * Freedroid is distributed in the hope that it will be useful, | |||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
18 | * GNU General Public License for more details. | |||
19 | * | |||
20 | * You should have received a copy of the GNU General Public License | |||
21 | * along with Freedroid; see the file COPYING. If not, write to the | |||
22 | * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |||
23 | * MA 02111-1307 USA | |||
24 | * | |||
25 | */ | |||
26 | ||||
27 | /** | |||
28 | * This file contains all menu functions and their subfunctions | |||
29 | */ | |||
30 | ||||
31 | #define _menu_c | |||
32 | ||||
33 | #include "system.h" | |||
34 | ||||
35 | #include "defs.h" | |||
36 | #include "struct.h" | |||
37 | #include "global.h" | |||
38 | #include "proto.h" | |||
39 | ||||
40 | #include "widgets/widgets.h" | |||
41 | ||||
42 | int Single_Player_Menu(void); | |||
43 | ||||
44 | #define SINGLE_PLAYER_STRING("Play"[0]!='\0'?dcgettext (((void*)0), "Play", 5):"") _("Play")("Play"[0]!='\0'?dcgettext (((void*)0), "Play", 5):"") | |||
45 | #define LOAD_EXISTING_HERO_STRING("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: " , 5):"") _("Your characters: ")("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: " , 5):"") | |||
46 | #define DELETE_EXISTING_HERO_STRING("Select character to delete: "[0]!='\0'?dcgettext (((void*)0 ), "Select character to delete: ", 5):"") _("Select character to delete: ")("Select character to delete: "[0]!='\0'?dcgettext (((void*)0 ), "Select character to delete: ", 5):"") | |||
47 | ||||
48 | #define MENU_SELECTION_DEBUG1 1 | |||
49 | ||||
50 | #define AUTO_SCROLL_RATE(0.02f) (0.02f) | |||
51 | ||||
52 | #define MAX_MENU_ITEMS100 100 | |||
53 | ||||
54 | /** | |||
55 | * This function tells over which menu item the mouse cursor would be, | |||
56 | * if there were infinitely many menu items. | |||
57 | */ | |||
58 | static int MouseCursorIsOverMenuItem(int first_menu_item_pos_y, int h) | |||
59 | { | |||
60 | int PureFraction; | |||
61 | ||||
62 | PureFraction = (GetMousePos_y() - first_menu_item_pos_y) / h; | |||
63 | ||||
64 | // Now it can be that the pure difference is negative or that it is positive. | |||
65 | // However we should not always round towards zero here, but rather always to | |||
66 | // the next LOWER integer! This will be done here: | |||
67 | // | |||
68 | if ((GetMousePos_y() - first_menu_item_pos_y) < 0) | |||
69 | PureFraction--; | |||
70 | else | |||
71 | PureFraction++; | |||
72 | ||||
73 | return (PureFraction); | |||
74 | ||||
75 | }; // void MouseCursorIsOverMenuItem( first_menu_item_pos_y ) | |||
76 | ||||
77 | /** | |||
78 | * | |||
79 | * | |||
80 | */ | |||
81 | static void print_menu_text(char *InitialText, char *MenuTexts[], int first_menu_item_pos_y, const char *background_name, void *MenuFont) | |||
82 | { | |||
83 | char open_gl_string[2000]; | |||
84 | ||||
85 | InitiateMenu(background_name); | |||
86 | ||||
87 | // Maybe if this is the very first startup menu, we should also print | |||
88 | // out some status variables like whether using OpenGL or not DIRECTLY | |||
89 | // ON THE MENU SCREEN... | |||
90 | // | |||
91 | if (!strcmp(MenuTexts[0], SINGLE_PLAYER_STRING)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (MenuTexts[0]) && __builtin_constant_p (("Play"[0]!= '\0'?dcgettext (((void*)0), "Play", 5):"")) && (__s1_len = strlen (MenuTexts[0]), __s2_len = strlen (("Play"[0]!='\0' ?dcgettext (((void*)0), "Play", 5):"")), (!((size_t)(const void *)((MenuTexts[0]) + 1) - (size_t)(const void *)(MenuTexts[0] ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((("Play"[0]!='\0'?dcgettext (((void*)0), "Play", 5):"")) + 1) - (size_t)(const void *)(("Play"[0]!='\0'?dcgettext (((void *)0), "Play", 5):"")) == 1) || __s2_len >= 4)) ? __builtin_strcmp (MenuTexts[0], ("Play"[0]!='\0'?dcgettext (((void*)0), "Play" , 5):"")) : (__builtin_constant_p (MenuTexts[0]) && ( (size_t)(const void *)((MenuTexts[0]) + 1) - (size_t)(const void *)(MenuTexts[0]) == 1) && (__s1_len = strlen (MenuTexts [0]), __s1_len < 4) ? (__builtin_constant_p (("Play"[0]!='\0' ?dcgettext (((void*)0), "Play", 5):"")) && ((size_t)( const void *)((("Play"[0]!='\0'?dcgettext (((void*)0), "Play" , 5):"")) + 1) - (size_t)(const void *)(("Play"[0]!='\0'?dcgettext (((void*)0), "Play", 5):"")) == 1) ? __builtin_strcmp (MenuTexts [0], ("Play"[0]!='\0'?dcgettext (((void*)0), "Play", 5):"")) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (("Play"[0]!='\0'?dcgettext (((void*) 0), "Play", 5):"")); int __result = (((const unsigned char *) (const char *) (MenuTexts[0]))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[0]))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[0]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (MenuTexts[0]))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p (("Play"[0]!='\0'?dcgettext (( (void*)0), "Play", 5):"")) && ((size_t)(const void *) ((("Play"[0]!='\0'?dcgettext (((void*)0), "Play", 5):"")) + 1 ) - (size_t)(const void *)(("Play"[0]!='\0'?dcgettext (((void *)0), "Play", 5):"")) == 1) && (__s2_len = strlen (("Play" [0]!='\0'?dcgettext (((void*)0), "Play", 5):"")), __s2_len < 4) ? (__builtin_constant_p (MenuTexts[0]) && ((size_t )(const void *)((MenuTexts[0]) + 1) - (size_t)(const void *)( MenuTexts[0]) == 1) ? __builtin_strcmp (MenuTexts[0], ("Play" [0]!='\0'?dcgettext (((void*)0), "Play", 5):"")) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (MenuTexts[0]); int __result = (((const unsigned char *) (const char *) (("Play"[0]!='\0'?dcgettext (((void*)0), "Play" , 5):"")))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( ("Play"[0]!='\0'?dcgettext (((void*)0), "Play", 5):"")))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (("Play"[0]!='\0' ?dcgettext (((void*)0), "Play", 5):"")))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (("Play"[0]!='\0'?dcgettext (((void*) 0), "Play", 5):"")))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (MenuTexts[0], ("Play"[0]!='\0'?dcgettext (((void*)0), "Play" , 5):""))))); })) { | |||
92 | put_string_right(FPS_Display_BFont, GameConfig.screen_height - 0.7 * FontHeight(GetCurrentFont()), freedroid_version); | |||
93 | // printf ("\n%s %s \n", PACKAGE, VERSION); | |||
94 | #ifdef HAVE_LIBGL1 | |||
95 | sprintf(open_gl_string, _("OpenGL support compiled: YES")("OpenGL support compiled: YES"[0]!='\0'?dcgettext (((void*)0 ), "OpenGL support compiled: YES", 5):"")); | |||
96 | #else | |||
97 | sprintf(open_gl_string, _("OpenGL support compiled: NO")("OpenGL support compiled: NO"[0]!='\0'?dcgettext (((void*)0) , "OpenGL support compiled: NO", 5):"")); | |||
98 | #endif | |||
99 | put_string_left(FPS_Display_BFont, GameConfig.screen_height - 2.4 * FontHeight(GetCurrentFont()), open_gl_string); | |||
100 | sprintf(open_gl_string, _("OpenGL output active: ")("OpenGL output active: "[0]!='\0'?dcgettext (((void*)0), "OpenGL output active: " , 5):"")); | |||
101 | if (use_open_gl) | |||
102 | sprintf(open_gl_string, _("OpenGL output active: YES")("OpenGL output active: YES"[0]!='\0'?dcgettext (((void*)0), "OpenGL output active: YES" , 5):"")); | |||
103 | else | |||
104 | sprintf(open_gl_string, _("OpenGL output active: NO")("OpenGL output active: NO"[0]!='\0'?dcgettext (((void*)0), "OpenGL output active: NO" , 5):"")); | |||
105 | put_string_left(FPS_Display_BFont, GameConfig.screen_height - 1.4 * FontHeight(GetCurrentFont()), open_gl_string); | |||
106 | } | |||
107 | // Now that the possible font-changing small info printing is | |||
108 | // done, we can finally set the right font for the menu itself. | |||
109 | // | |||
110 | if (MenuFont == NULL((void*)0)) | |||
111 | SetCurrentFont(Menu_BFont); | |||
112 | else | |||
113 | SetCurrentFont((BFont_Info *) MenuFont); | |||
114 | ||||
115 | }; // void print_menu_text ( ... ) | |||
116 | ||||
117 | /** | |||
118 | * This function performs a menu for the player to select from, using the | |||
119 | * keyboard only, currently, sorry. | |||
120 | * | |||
121 | * This function EXPECTS, that MenuTexts[] is an array of strings, THE | |||
122 | * LAST OF WHICH IS AN EMPTY STRING TO DENOTE THE END OF THE ARRAY! If | |||
123 | * this is not respected, segfault errors are likely. | |||
124 | * | |||
125 | */ | |||
126 | int DoMenuSelection(char *InitialText, char **MenuTexts, int FirstItem, const char *background_name, void *MenuFont) | |||
127 | { | |||
128 | int h; | |||
129 | int i; | |||
130 | static int MenuPosition = 1; | |||
131 | int VertScrollOffset = 0; | |||
132 | int NumberOfOptionsGiven; | |||
133 | int LongestOption; | |||
134 | SDL_Rect HighlightRect; | |||
135 | SDL_Rect BackgroundRect; | |||
136 | int first_menu_item_pos_y; | |||
137 | int *MenuTextWidths; | |||
138 | float auto_scroll_start = 0.0f; | |||
139 | int auto_scroll_run = TRUE(1); | |||
140 | int ret = -1; | |||
141 | int old_game_status = game_status; | |||
142 | SDL_Event event; | |||
143 | ||||
144 | game_status = INSIDE_MENU; | |||
145 | ||||
146 | // We set the given font, if appropriate, and set the font height variable... | |||
147 | // | |||
148 | if (MenuFont != NULL((void*)0)) | |||
149 | SetCurrentFont(MenuFont); | |||
150 | h = FontHeight(GetCurrentFont()); | |||
151 | ||||
152 | // Some menus are intended to start with the default setting of the | |||
153 | // first menu option selected. However this is not always desired. | |||
154 | // It might happen, that a submenu returns to the upper menu and then | |||
155 | // the upper menu should not be reset to the first position selected. | |||
156 | // For this case we have some special '-1' entry reserved as the marked | |||
157 | // menu entry. This means, that the menu position from last time will | |||
158 | // simply be re-used. | |||
159 | // | |||
160 | if (FirstItem != (-1)) | |||
161 | MenuPosition = FirstItem; | |||
162 | ||||
163 | // First thing we do is find out how may options we have | |||
164 | // been given for the menu | |||
165 | // For each option, we compute and store its pixel-width | |||
166 | // Then the longest one is found | |||
167 | for (i = 0; TRUE(1); ++i) { | |||
168 | if (MenuTexts[i][0] == '\0') | |||
169 | break; | |||
170 | } | |||
171 | NumberOfOptionsGiven = i; | |||
172 | MenuTextWidths = (int *)malloc(sizeof(int) * (NumberOfOptionsGiven + 1)); | |||
173 | ||||
174 | LongestOption = 0; | |||
175 | for (i = 0; i < NumberOfOptionsGiven; ++i) { | |||
176 | MenuTextWidths[i] = text_width(GetCurrentFont(), MenuTexts[i]); | |||
177 | if (MenuTextWidths[i] > LongestOption) | |||
178 | LongestOption = MenuTextWidths[i]; | |||
179 | } | |||
180 | MenuTextWidths[NumberOfOptionsGiven] = 0; | |||
181 | ||||
182 | // Clamp the longest option to the available width on the screen | |||
183 | // (50 pixels around the menu's background, and 1.5 fontheigth around the text) | |||
184 | LongestOption = min(GameConfig.screen_width - 100 - 3 * h, LongestOption)((GameConfig.screen_width - 100 - 3 * h) > (LongestOption) ? (LongestOption) : (GameConfig.screen_width - 100 - 3 * h) ); | |||
185 | ||||
186 | // Find how many options you can fit in the menu | |||
187 | int max_options = (GameConfig.screen_height - 100)/h; | |||
188 | ||||
189 | // In those cases where we don't reset the menu position upon | |||
190 | // initalization of the menu, we must check for menu positions | |||
191 | // outside the bounds of the current menu. | |||
192 | // | |||
193 | if (MenuPosition > NumberOfOptionsGiven) { | |||
194 | MenuPosition = 1; | |||
195 | } else if (MenuPosition > max_options) { | |||
196 | VertScrollOffset = (MenuPosition - 1)/max_options; | |||
197 | MenuPosition = MenuPosition % max_options; | |||
198 | } | |||
199 | ||||
200 | first_menu_item_pos_y = (GameConfig.screen_height - min(max_options, NumberOfOptionsGiven)((max_options) > (NumberOfOptionsGiven) ? (NumberOfOptionsGiven ) : (max_options) ) * h) / 2; | |||
201 | ||||
202 | print_menu_text(InitialText, MenuTexts, first_menu_item_pos_y, background_name, MenuFont); | |||
203 | ||||
204 | StoreMenuBackground(0); | |||
205 | ||||
206 | BackgroundRect.x = (GameConfig.screen_width - LongestOption - 3 * h) / 2; | |||
207 | BackgroundRect.y = first_menu_item_pos_y - 50; | |||
208 | BackgroundRect.w = LongestOption + 3 * h; | |||
209 | BackgroundRect.h = (h * min(max_options, NumberOfOptionsGiven)((max_options) > (NumberOfOptionsGiven) ? (NumberOfOptionsGiven ) : (max_options) )) + 100; | |||
210 | ||||
211 | while (1) { | |||
212 | save_mouse_state(); | |||
213 | ||||
214 | // We write out the normal text of the menu, either by doing it once more | |||
215 | // in the open_gl case or by restoring what we have saved earlier, in the | |||
216 | // SDL output case. | |||
217 | // | |||
218 | RestoreMenuBackground(0); | |||
219 | ||||
220 | // Maybe we should display some thumbnails with the saved games entries? | |||
221 | // But this will only apply for the load_hero and the delete_hero menus... | |||
222 | // | |||
223 | if (((!strcmp(InitialText, LOAD_EXISTING_HERO_STRING)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (InitialText) && __builtin_constant_p (("Your characters: " [0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) && (__s1_len = strlen (InitialText), __s2_len = strlen (("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: " , 5):"")), (!((size_t)(const void *)((InitialText) + 1) - (size_t )(const void *)(InitialText) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) + 1) - (size_t)(const void *)(("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) == 1) || __s2_len >= 4)) ? __builtin_strcmp (InitialText, ("Your characters: "[0]!='\0'?dcgettext (((void *)0), "Your characters: ", 5):"")) : (__builtin_constant_p (InitialText ) && ((size_t)(const void *)((InitialText) + 1) - (size_t )(const void *)(InitialText) == 1) && (__s1_len = strlen (InitialText), __s1_len < 4) ? (__builtin_constant_p (("Your characters: " [0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) && ((size_t)(const void *)((("Your characters: "[0]!= '\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) + 1) - (size_t)(const void *)(("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) == 1) ? __builtin_strcmp (InitialText, ("Your characters: "[0]!='\0'?dcgettext (((void *)0), "Your characters: ", 5):"")) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (("Your characters: " [0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) ; int __result = (((const unsigned char *) (const char *) (InitialText ))[0] - __s2[0]); if (__s1_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (InitialText ))[1] - __s2[1]); if (__s1_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (InitialText ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (InitialText ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ( ("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: " , 5):"")) && ((size_t)(const void *)((("Your characters: " [0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) + 1) - (size_t)(const void *)(("Your characters: "[0]!='\0'? dcgettext (((void*)0), "Your characters: ", 5):"")) == 1) && (__s2_len = strlen (("Your characters: "[0]!='\0'?dcgettext ( ((void*)0), "Your characters: ", 5):"")), __s2_len < 4) ? ( __builtin_constant_p (InitialText) && ((size_t)(const void *)((InitialText) + 1) - (size_t)(const void *)(InitialText ) == 1) ? __builtin_strcmp (InitialText, ("Your characters: " [0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (InitialText); int __result = (((const unsigned char *) (const char *) (("Your characters: "[0]!='\0' ?dcgettext (((void*)0), "Your characters: ", 5):"")))[0] - __s2 [0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (("Your characters: " [0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) )[1] - __s2[1]); if (__s2_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (("Your characters: " [0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) )[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (("Your characters: " [0]!='\0'?dcgettext (((void*)0), "Your characters: ", 5):"")) )[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (InitialText , ("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: " , 5):""))))); })) || | |||
224 | (!strcmp(InitialText, DELETE_EXISTING_HERO_STRING)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (InitialText) && __builtin_constant_p (("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")) && (__s1_len = strlen (InitialText), __s2_len = strlen (("Select character to delete: "[0]!='\0'?dcgettext (((void*)0), "Select character to delete: ", 5):"")), (!((size_t )(const void *)((InitialText) + 1) - (size_t)(const void *)(InitialText ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((("Select character to delete: "[0]!='\0'?dcgettext (((void *)0), "Select character to delete: ", 5):"")) + 1) - (size_t) (const void *)(("Select character to delete: "[0]!='\0'?dcgettext (((void*)0), "Select character to delete: ", 5):"")) == 1) || __s2_len >= 4)) ? __builtin_strcmp (InitialText, ("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")) : (__builtin_constant_p (InitialText) && (( size_t)(const void *)((InitialText) + 1) - (size_t)(const void *)(InitialText) == 1) && (__s1_len = strlen (InitialText ), __s1_len < 4) ? (__builtin_constant_p (("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")) && ((size_t)(const void *)((("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")) + 1) - (size_t)(const void *)(("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")) == 1) ? __builtin_strcmp (InitialText, ("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")); int __result = (((const unsigned char *) (const char *) (InitialText))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (InitialText))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (InitialText))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (InitialText))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (("Select character to delete: "[0]!='\0'?dcgettext (((void* )0), "Select character to delete: ", 5):"")) && ((size_t )(const void *)((("Select character to delete: "[0]!='\0'?dcgettext (((void*)0), "Select character to delete: ", 5):"")) + 1) - ( size_t)(const void *)(("Select character to delete: "[0]!='\0' ?dcgettext (((void*)0), "Select character to delete: ", 5):"" )) == 1) && (__s2_len = strlen (("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")), __s2_len < 4) ? (__builtin_constant_p (InitialText ) && ((size_t)(const void *)((InitialText) + 1) - (size_t )(const void *)(InitialText) == 1) ? __builtin_strcmp (InitialText , ("Select character to delete: "[0]!='\0'?dcgettext (((void* )0), "Select character to delete: ", 5):"")) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (InitialText); int __result = (((const unsigned char *) (const char *) (("Select character to delete: "[0]!='\0'? dcgettext (((void*)0), "Select character to delete: ", 5):"") ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ( ("Select character to delete: "[0]!='\0'?dcgettext (((void*)0 ), "Select character to delete: ", 5):"")))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (("Select character to delete: " [0]!='\0'?dcgettext (((void*)0), "Select character to delete: " , 5):"")))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (InitialText, ("Select character to delete: "[0]!='\0'?dcgettext (((void*)0), "Select character to delete: ", 5):""))))); }))) && | |||
225 | (MenuPosition + VertScrollOffset < NumberOfOptionsGiven) && | |||
226 | strcmp(MenuTexts[MenuPosition - 1 + VertScrollOffset], _("[down]"))__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && __builtin_constant_p (("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")) && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset ]), __s2_len = strlen (("[down]"[0]!='\0'?dcgettext (((void*) 0), "[down]", 5):"")), (!((size_t)(const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1) - (size_t)(const void *)(MenuTexts [MenuPosition - 1 + VertScrollOffset]) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((("[down]"[0]!='\0'? dcgettext (((void*)0), "[down]", 5):"")) + 1) - (size_t)(const void *)(("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5 ):"")) == 1) || __s2_len >= 4)) ? __builtin_strcmp (MenuTexts [MenuPosition - 1 + VertScrollOffset], ("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")) : (__builtin_constant_p (MenuTexts [MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1 ) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s1_len < 4) ? (__builtin_constant_p (("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")) && ((size_t)(const void *)((("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")) + 1) - (size_t)(const void *) (("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")) == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset ], ("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"") ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (("[down]"[0]!='\0'?dcgettext (((void *)0), "[down]", 5):"")); int __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p (("[down]"[0]!='\0'?dcgettext ( ((void*)0), "[down]", 5):"")) && ((size_t)(const void *)((("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"" )) + 1) - (size_t)(const void *)(("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")) == 1) && (__s2_len = strlen (("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")) , __s2_len < 4) ? (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)( (MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1) - (size_t )(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset ], ("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"") ) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]); int __result = (((const unsigned char *) (const char *) ( ("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")))[ 0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (("[down]" [0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")))[1] - __s2 [1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (("[down]"[0]!='\0' ?dcgettext (((void*)0), "[down]", 5):"")))[2] - __s2[2]); if ( __s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"")))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset ], ("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):"") )))); }) && | |||
227 | strcmp(MenuTexts[MenuPosition - 1 + VertScrollOffset], _("[up]"))__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && __builtin_constant_p (("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):"")) && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset ]), __s2_len = strlen (("[up]"[0]!='\0'?dcgettext (((void*)0) , "[up]", 5):"")), (!((size_t)(const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1) - (size_t)(const void *)(MenuTexts [MenuPosition - 1 + VertScrollOffset]) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):"")) + 1) - (size_t)(const void *)(( "[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):"")) == 1) || __s2_len >= 4)) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], ("[up]"[0]!='\0'?dcgettext (((void* )0), "[up]", 5):"")) : (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)( (MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1) - (size_t )(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s1_len < 4) ? (__builtin_constant_p (("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):"")) && ((size_t)(const void *)((("[up]"[0]!='\0'?dcgettext (((void* )0), "[up]", 5):"")) + 1) - (size_t)(const void *)(("[up]"[0] !='\0'?dcgettext (((void*)0), "[up]", 5):"")) == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], ("[up]"[0]!= '\0'?dcgettext (((void*)0), "[up]", 5):"")) : (__extension__ ( { const unsigned char *__s2 = (const unsigned char *) (const char *) (("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):"")); int __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):"")) && ((size_t)(const void *)((("[up]"[0]!='\0'?dcgettext (((void* )0), "[up]", 5):"")) + 1) - (size_t)(const void *)(("[up]"[0] !='\0'?dcgettext (((void*)0), "[up]", 5):"")) == 1) && (__s2_len = strlen (("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]" , 5):"")), __s2_len < 4) ? (__builtin_constant_p (MenuTexts [MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1 ) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset ], ("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):"")) : ( - (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]); int __result = (((const unsigned char *) (const char *) ( ("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):"")))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (("[up]"[0]!='\0' ?dcgettext (((void*)0), "[up]", 5):"")))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (("[up]"[0]!='\0'?dcgettext (((void*) 0), "[up]", 5):"")))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):""))) [3] - __s2[3]); } } __result; })))) : __builtin_strcmp (MenuTexts [MenuPosition - 1 + VertScrollOffset], ("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):""))))); }) && | |||
228 | strcmp(MenuTexts[MenuPosition - 1 + VertScrollOffset], " ")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && __builtin_constant_p (" ") && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s2_len = strlen (" "), (!((size_t) (const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset ]) + 1) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset]) == 1) || __s1_len >= 4) && (!( (size_t)(const void *)((" ") + 1) - (size_t)(const void *)(" " ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ") : (__builtin_constant_p (MenuTexts [MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1 ) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s1_len < 4) ? (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (" "); int __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) && (__s2_len = strlen (" " ), __s2_len < 4) ? (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)( (MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1) - (size_t )(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset ], " ") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset]); int __result = (((const unsigned char *) (const char *) (" "))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (" "))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (" "))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (" "))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ")))); })) { | |||
229 | // We load the thumbnail, or at least we try to do it... | |||
230 | // | |||
231 | LoadAndShowThumbnail(MenuTexts[MenuPosition - 1 + VertScrollOffset]); | |||
232 | LoadAndShowStats(MenuTexts[MenuPosition - 1 + VertScrollOffset]); | |||
233 | } | |||
234 | // Draw the menu's background | |||
235 | // | |||
236 | ShadowingRectangle(Screen, BackgroundRect); | |||
237 | ||||
238 | // Display each option | |||
239 | // | |||
240 | for (i = 0; TRUE(1); i++) { | |||
241 | if (i >= min(max_options, NumberOfOptionsGiven)((max_options) > (NumberOfOptionsGiven) ? (NumberOfOptionsGiven ) : (max_options) )) | |||
242 | break; | |||
243 | int i_abs = i + VertScrollOffset; | |||
244 | char *str = NULL((void*)0); | |||
245 | int width = 0; | |||
246 | ||||
247 | if (MenuTextWidths[i_abs] == 0) | |||
248 | break; | |||
249 | ||||
250 | // Don't select empty menu entries | |||
251 | if (strcmp(MenuTexts[i_abs], " ")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (MenuTexts[i_abs]) && __builtin_constant_p (" ") && (__s1_len = strlen (MenuTexts[i_abs]), __s2_len = strlen (" " ), (!((size_t)(const void *)((MenuTexts[i_abs]) + 1) - (size_t )(const void *)(MenuTexts[i_abs]) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((" ") + 1) - (size_t)(const void * )(" ") == 1) || __s2_len >= 4)) ? __builtin_strcmp (MenuTexts [i_abs], " ") : (__builtin_constant_p (MenuTexts[i_abs]) && ((size_t)(const void *)((MenuTexts[i_abs]) + 1) - (size_t)(const void *)(MenuTexts[i_abs]) == 1) && (__s1_len = strlen (MenuTexts[i_abs]), __s1_len < 4) ? (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) ? __builtin_strcmp (MenuTexts[i_abs ], " ") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (" "); int __result = (((const unsigned char *) (const char *) (MenuTexts[i_abs]))[0] - __s2 [0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[i_abs] ))[1] - __s2[1]); if (__s1_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (MenuTexts [i_abs]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (MenuTexts [i_abs]))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) && (__s2_len = strlen (" " ), __s2_len < 4) ? (__builtin_constant_p (MenuTexts[i_abs] ) && ((size_t)(const void *)((MenuTexts[i_abs]) + 1) - (size_t)(const void *)(MenuTexts[i_abs]) == 1) ? __builtin_strcmp (MenuTexts[i_abs], " ") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (MenuTexts [i_abs]); int __result = (((const unsigned char *) (const char *) (" "))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( " "))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (" " ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (" "))[ 3] - __s2[3]); } } __result; })))) : __builtin_strcmp (MenuTexts [i_abs], " ")))); }) == 0) | |||
252 | continue; | |||
253 | ||||
254 | // Define the actual text to display | |||
255 | // If the text is too long, handle autoscroll and clip it | |||
256 | ||||
257 | str = strdup(MenuTexts[i_abs] + (i == MenuPosition - 1 ? (int)auto_scroll_start : 0))(__extension__ (__builtin_constant_p (MenuTexts[i_abs] + (i == MenuPosition - 1 ? (int)auto_scroll_start : 0)) && ( (size_t)(const void *)((MenuTexts[i_abs] + (i == MenuPosition - 1 ? (int)auto_scroll_start : 0)) + 1) - (size_t)(const void *)(MenuTexts[i_abs] + (i == MenuPosition - 1 ? (int)auto_scroll_start : 0)) == 1) ? (((const char *) (MenuTexts[i_abs] + (i == MenuPosition - 1 ? (int)auto_scroll_start : 0)))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (MenuTexts [i_abs] + (i == MenuPosition - 1 ? (int)auto_scroll_start : 0 )) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, MenuTexts [i_abs] + (i == MenuPosition - 1 ? (int)auto_scroll_start : 0 ), __len); __retval; })) : __strdup (MenuTexts[i_abs] + (i == MenuPosition - 1 ? (int)auto_scroll_start : 0)))); | |||
258 | width = min(MenuTextWidths[i_abs], LongestOption)((MenuTextWidths[i_abs]) > (LongestOption) ? (LongestOption ) : (MenuTextWidths[i_abs]) ); | |||
259 | ||||
260 | if (CutDownStringToMaximalSize(str, LongestOption) == FALSE(0)) { | |||
261 | // if cutting was not needed, we are at the end of the text, | |||
262 | // so stop autoscroll | |||
263 | if (i == MenuPosition - 1) { | |||
264 | auto_scroll_run = FALSE(0); | |||
265 | auto_scroll_start = 0.0f; | |||
266 | } | |||
267 | } | |||
268 | ||||
269 | // Depending on what highlight method has been used, we so some highlighting | |||
270 | // of the currently selected menu options location on the screen... | |||
271 | // | |||
272 | if (i == MenuPosition - 1) { | |||
273 | HighlightRect.x = (GameConfig.screen_width - width) / 2 - h; | |||
274 | HighlightRect.y = first_menu_item_pos_y + i * h; | |||
275 | HighlightRect.w = width + 2 * h; | |||
276 | HighlightRect.h = h; | |||
277 | HighlightRectangle(Screen, HighlightRect); | |||
278 | ||||
279 | if (auto_scroll_run == TRUE(1)) { | |||
280 | auto_scroll_start += AUTO_SCROLL_RATE(0.02f); | |||
281 | } | |||
282 | } | |||
283 | // Draw the option's text | |||
284 | put_string_centered(GetCurrentFont(), first_menu_item_pos_y + i * h, str); | |||
285 | ||||
286 | free(str); | |||
287 | } | |||
288 | if (strlen(InitialText) > 0) | |||
289 | display_text(InitialText, 50, 50, NULL((void*)0)); | |||
290 | ||||
291 | // Now the mouse cursor must be brought to the screen | |||
292 | blit_mouse_cursor(); | |||
293 | ||||
294 | // Image should be ready now, so we can show it... | |||
295 | // | |||
296 | our_SDL_flip_wrapper(); | |||
297 | ||||
298 | // Now it's time to handle the possible keyboard and mouse | |||
299 | // input from the user... | |||
300 | // | |||
301 | int old_menu_position = MenuPosition; | |||
302 | int old_scroll_offset = VertScrollOffset; | |||
303 | ||||
304 | if (SDL_PollEvent(&event)) { | |||
305 | ||||
306 | if (event.type == SDL_QUIT) { | |||
307 | Terminate(EXIT_SUCCESS0); | |||
308 | } | |||
309 | //(clever?) hack : mouse wheel up and down behave | |||
310 | //exactly like UP and DOWN arrow, so we mangle the event | |||
311 | if (event.type == SDL_MOUSEBUTTONDOWN) { | |||
312 | switch (event.button.button) { | |||
313 | case SDL_BUTTON_WHEELUP4: | |||
314 | event.type = SDL_KEYDOWN; | |||
315 | event.key.keysym.sym = SDLK_UP; | |||
316 | break; | |||
317 | case SDL_BUTTON_WHEELDOWN5: | |||
318 | event.type = SDL_KEYDOWN; | |||
319 | event.key.keysym.sym = SDLK_DOWN; | |||
320 | break; | |||
321 | default: | |||
322 | break; | |||
323 | } | |||
324 | } | |||
325 | ||||
326 | if (event.type == SDL_KEYDOWN) { | |||
327 | switch (event.key.keysym.sym) { | |||
328 | case SDLK_ESCAPE: | |||
329 | MenuItemDeselectedSound(); | |||
330 | ret = -1; | |||
331 | goto out; | |||
332 | break; | |||
333 | ||||
334 | case SDLK_RETURN: | |||
335 | case SDLK_SPACE: | |||
336 | case SDLK_LEFT: | |||
337 | case SDLK_RIGHT: | |||
338 | // The space key or enter key or arrow keys all indicate, that | |||
339 | // the user has made a selection. | |||
340 | // | |||
341 | // | |||
342 | MenuItemSelectedSound(); | |||
343 | ret = MenuPosition + VertScrollOffset; | |||
344 | goto out; | |||
345 | break; | |||
346 | ||||
347 | case SDLK_UP: | |||
348 | if ((MenuPosition == 1) | |||
349 | && (VertScrollOffset > 0) | |||
350 | && (NumberOfOptionsGiven > max_options)) { | |||
351 | ||||
352 | --VertScrollOffset; | |||
353 | continue; | |||
354 | } | |||
355 | if (MenuPosition > 1) | |||
356 | MenuPosition--; | |||
357 | ||||
358 | // Skip any blank positions when moving with the keyboard | |||
359 | if (strcmp(MenuTexts[MenuPosition - 1 + VertScrollOffset], " ")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && __builtin_constant_p (" ") && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s2_len = strlen (" "), (!((size_t) (const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset ]) + 1) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset]) == 1) || __s1_len >= 4) && (!( (size_t)(const void *)((" ") + 1) - (size_t)(const void *)(" " ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ") : (__builtin_constant_p (MenuTexts [MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1 ) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s1_len < 4) ? (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (" "); int __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) && (__s2_len = strlen (" " ), __s2_len < 4) ? (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)( (MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1) - (size_t )(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset ], " ") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset]); int __result = (((const unsigned char *) (const char *) (" "))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (" "))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (" "))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (" "))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ")))); }) == 0) | |||
360 | MenuPosition = (MenuPosition == 1) ? MenuPosition + 1 : MenuPosition - 1; | |||
361 | ||||
362 | MoveMenuPositionSound(); | |||
363 | HighlightRect.x = UNIVERSAL_COORD_W(320)(int)((float)(320) * ((float)(GameConfig . screen_width) / 640.0 )); // ( TextWidth ( MenuTexts [ MenuPosition - 1 ] ) ) / 2 ; | |||
364 | HighlightRect.y = first_menu_item_pos_y | |||
365 | + (MenuPosition - 1) * h; | |||
366 | SDL_WarpMouse(HighlightRect.x, HighlightRect.y + h/2); | |||
367 | break; | |||
368 | ||||
369 | case SDLK_DOWN: | |||
370 | if ((MenuPosition == max_options) | |||
371 | && (VertScrollOffset + max_options < NumberOfOptionsGiven) | |||
372 | && (NumberOfOptionsGiven > max_options)) { | |||
373 | ||||
374 | ++VertScrollOffset; | |||
375 | continue; | |||
376 | } | |||
377 | if (MenuPosition < min(max_options, NumberOfOptionsGiven)((max_options) > (NumberOfOptionsGiven) ? (NumberOfOptionsGiven ) : (max_options) )) | |||
378 | MenuPosition++; | |||
379 | ||||
380 | // Skip any blank positions when moving with the keyboard | |||
381 | if (strcmp(MenuTexts[MenuPosition - 1 + VertScrollOffset], " ")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && __builtin_constant_p (" ") && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s2_len = strlen (" "), (!((size_t) (const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset ]) + 1) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset]) == 1) || __s1_len >= 4) && (!( (size_t)(const void *)((" ") + 1) - (size_t)(const void *)(" " ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ") : (__builtin_constant_p (MenuTexts [MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1 ) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s1_len < 4) ? (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (" "); int __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) && (__s2_len = strlen (" " ), __s2_len < 4) ? (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)( (MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1) - (size_t )(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset ], " ") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset]); int __result = (((const unsigned char *) (const char *) (" "))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (" "))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (" "))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (" "))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ")))); }) == 0) | |||
382 | MenuPosition = (MenuPosition == min(max_options, NumberOfOptionsGiven)((max_options) > (NumberOfOptionsGiven) ? (NumberOfOptionsGiven ) : (max_options) )) ? MenuPosition - 1 : MenuPosition + 1; | |||
383 | ||||
384 | MoveMenuPositionSound(); | |||
385 | HighlightRect.x = UNIVERSAL_COORD_W(320)(int)((float)(320) * ((float)(GameConfig . screen_width) / 640.0 )); // ( TextWidth ( MenuTexts [ MenuPosition - 1 ] ) ) / 2 ; | |||
386 | HighlightRect.y = first_menu_item_pos_y | |||
387 | + (MenuPosition - 1) * h; | |||
388 | SDL_WarpMouse(HighlightRect.x, HighlightRect.y + h/2); | |||
389 | break; | |||
390 | ||||
391 | default: | |||
392 | break; | |||
393 | } | |||
394 | } | |||
395 | ||||
396 | } | |||
397 | ||||
398 | if (MouseLeftClicked()) { | |||
399 | // Only when the mouse click really occurred on the menu do we | |||
400 | // interpret it as a menu choice. Otherwise we'll just ignore | |||
401 | // it. Also, we completely ignore any clicks if the clicked | |||
402 | // position is blank. | |||
403 | if (MouseCursorIsOverMenuItem(first_menu_item_pos_y, h) == MenuPosition && | |||
404 | strcmp(MenuTexts[MenuPosition - 1 + VertScrollOffset], " ")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && __builtin_constant_p (" ") && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s2_len = strlen (" "), (!((size_t) (const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset ]) + 1) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset]) == 1) || __s1_len >= 4) && (!( (size_t)(const void *)((" ") + 1) - (size_t)(const void *)(" " ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ") : (__builtin_constant_p (MenuTexts [MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)((MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1 ) - (size_t)(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) && (__s1_len = strlen (MenuTexts[MenuPosition - 1 + VertScrollOffset]), __s1_len < 4) ? (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (" "); int __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (MenuTexts [MenuPosition - 1 + VertScrollOffset]))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset ]))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (" ") && ((size_t)(const void *)((" ") + 1) - (size_t )(const void *)(" ") == 1) && (__s2_len = strlen (" " ), __s2_len < 4) ? (__builtin_constant_p (MenuTexts[MenuPosition - 1 + VertScrollOffset]) && ((size_t)(const void *)( (MenuTexts[MenuPosition - 1 + VertScrollOffset]) + 1) - (size_t )(const void *)(MenuTexts[MenuPosition - 1 + VertScrollOffset ]) == 1) ? __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset ], " ") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (MenuTexts[MenuPosition - 1 + VertScrollOffset]); int __result = (((const unsigned char *) (const char *) (" "))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (" "))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (" "))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (" "))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (MenuTexts[MenuPosition - 1 + VertScrollOffset], " ")))); }) != 0) { | |||
405 | ||||
406 | MenuItemSelectedSound(); | |||
407 | ret = MenuPosition + VertScrollOffset; | |||
408 | goto out; | |||
409 | } | |||
410 | } | |||
411 | ||||
412 | MenuPosition = MouseCursorIsOverMenuItem(first_menu_item_pos_y, h); | |||
413 | if (MenuPosition < 1) | |||
414 | MenuPosition = 1; | |||
415 | if (MenuPosition > min(max_options, NumberOfOptionsGiven)((max_options) > (NumberOfOptionsGiven) ? (NumberOfOptionsGiven ) : (max_options) )) | |||
416 | MenuPosition = min(max_options, NumberOfOptionsGiven)((max_options) > (NumberOfOptionsGiven) ? (NumberOfOptionsGiven ) : (max_options) ); | |||
417 | ||||
418 | // If the selected option has changed, halt eventual current autoscrolling | |||
419 | if (MenuPosition != old_menu_position || VertScrollOffset != old_scroll_offset) { | |||
420 | auto_scroll_run = TRUE(1); | |||
421 | auto_scroll_start = 0.0f; | |||
422 | } | |||
423 | // At this the while (1) overloop ends. But for the menu, we really do not | |||
424 | // need to hog the CPU. Therefore some waiting should be introduced here. | |||
425 | // | |||
426 | SDL_Delay(1); | |||
427 | } | |||
428 | ||||
429 | out: | |||
430 | free(MenuTextWidths); | |||
431 | while (MouseLeftPressed()) //eat the click that may have happened | |||
432 | SDL_Delay(1); | |||
433 | input_handle(); | |||
434 | game_status = old_game_status; | |||
435 | return ret; | |||
436 | }; // int DoMenuSelection( ... ) | |||
437 | ||||
438 | /** | |||
439 | * This function prepares the screen for the big Escape menu and | |||
440 | * its submenus. This means usual content of the screen, i.e. the | |||
441 | * combat screen and top status bar, is "faded out", the rest of | |||
442 | * the screen is cleared. This function resolves some redundancy | |||
443 | * that occured since there are so many submenus needing this. | |||
444 | */ | |||
445 | void InitiateMenu(const char *background_name) | |||
446 | { | |||
447 | // Here comes the standard initializer for all the menus and submenus | |||
448 | // of the big escape menu. This prepares the screen, so that we can | |||
449 | // write on it further down. | |||
450 | // | |||
451 | SDL_SetClipRect(Screen, NULL((void*)0)); | |||
452 | ||||
453 | if (!strcmp(background_name, "--GAME_BACKGROUND--")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (background_name) && __builtin_constant_p ("--GAME_BACKGROUND--" ) && (__s1_len = strlen (background_name), __s2_len = strlen ("--GAME_BACKGROUND--"), (!((size_t)(const void *)((background_name ) + 1) - (size_t)(const void *)(background_name) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("--GAME_BACKGROUND--" ) + 1) - (size_t)(const void *)("--GAME_BACKGROUND--") == 1) || __s2_len >= 4)) ? __builtin_strcmp (background_name, "--GAME_BACKGROUND--" ) : (__builtin_constant_p (background_name) && ((size_t )(const void *)((background_name) + 1) - (size_t)(const void * )(background_name) == 1) && (__s1_len = strlen (background_name ), __s1_len < 4) ? (__builtin_constant_p ("--GAME_BACKGROUND--" ) && ((size_t)(const void *)(("--GAME_BACKGROUND--") + 1) - (size_t)(const void *)("--GAME_BACKGROUND--") == 1) ? __builtin_strcmp (background_name, "--GAME_BACKGROUND--") : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("--GAME_BACKGROUND--"); int __result = (((const unsigned char *) (const char *) (background_name))[0] - __s2[0]); if ( __s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (background_name))[1] - __s2 [1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (background_name) )[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (background_name ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ( "--GAME_BACKGROUND--") && ((size_t)(const void *)(("--GAME_BACKGROUND--" ) + 1) - (size_t)(const void *)("--GAME_BACKGROUND--") == 1) && (__s2_len = strlen ("--GAME_BACKGROUND--"), __s2_len < 4) ? (__builtin_constant_p (background_name) && ((size_t )(const void *)((background_name) + 1) - (size_t)(const void * )(background_name) == 1) ? __builtin_strcmp (background_name, "--GAME_BACKGROUND--") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (background_name ); int __result = (((const unsigned char *) (const char *) ("--GAME_BACKGROUND--" ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) ("--GAME_BACKGROUND--" ))[1] - __s2[1]); if (__s2_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) ("--GAME_BACKGROUND--" ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) ("--GAME_BACKGROUND--" ))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (background_name , "--GAME_BACKGROUND--")))); })) { // Show game background | |||
454 | AssembleCombatPicture(SHOW_ITEMS | NO_CURSOR); | |||
455 | } else if (!strcmp(background_name, "--EDITOR_BACKGROUND--")__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (background_name) && __builtin_constant_p ("--EDITOR_BACKGROUND--" ) && (__s1_len = strlen (background_name), __s2_len = strlen ("--EDITOR_BACKGROUND--"), (!((size_t)(const void *)( (background_name) + 1) - (size_t)(const void *)(background_name ) == 1) || __s1_len >= 4) && (!((size_t)(const void *)(("--EDITOR_BACKGROUND--") + 1) - (size_t)(const void *)("--EDITOR_BACKGROUND--" ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (background_name , "--EDITOR_BACKGROUND--") : (__builtin_constant_p (background_name ) && ((size_t)(const void *)((background_name) + 1) - (size_t)(const void *)(background_name) == 1) && (__s1_len = strlen (background_name), __s1_len < 4) ? (__builtin_constant_p ("--EDITOR_BACKGROUND--") && ((size_t)(const void *) (("--EDITOR_BACKGROUND--") + 1) - (size_t)(const void *)("--EDITOR_BACKGROUND--" ) == 1) ? __builtin_strcmp (background_name, "--EDITOR_BACKGROUND--" ) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) ("--EDITOR_BACKGROUND--"); int __result = (((const unsigned char *) (const char *) (background_name) )[0] - __s2[0]); if (__s1_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (background_name ))[1] - __s2[1]); if (__s1_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (background_name ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (background_name ))[3] - __s2[3]); } } __result; }))) : (__builtin_constant_p ( "--EDITOR_BACKGROUND--") && ((size_t)(const void *)(( "--EDITOR_BACKGROUND--") + 1) - (size_t)(const void *)("--EDITOR_BACKGROUND--" ) == 1) && (__s2_len = strlen ("--EDITOR_BACKGROUND--" ), __s2_len < 4) ? (__builtin_constant_p (background_name) && ((size_t)(const void *)((background_name) + 1) - ( size_t)(const void *)(background_name) == 1) ? __builtin_strcmp (background_name, "--EDITOR_BACKGROUND--") : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (background_name); int __result = (((const unsigned char *) (const char *) ("--EDITOR_BACKGROUND--"))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ("--EDITOR_BACKGROUND--"))[1 ] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ("--EDITOR_BACKGROUND--" ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) ("--EDITOR_BACKGROUND--" ))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (background_name , "--EDITOR_BACKGROUND--")))); })) { // Show editor background | |||
456 | AssembleCombatPicture(ONLY_SHOW_MAP_AND_TEXT | SHOW_ITEMS | OMIT_TUX | GameConfig.omit_obstacles_in_level_editor * | |||
457 | OMIT_OBSTACLES | GameConfig.omit_enemies_in_level_editor * OMIT_ENEMIES | OMIT_BLASTS | SKIP_LIGHT_RADIUS | | |||
458 | NO_CURSOR | OMIT_ITEMS_LABEL); | |||
459 | } else { | |||
460 | blit_background(background_name); | |||
461 | } | |||
462 | ||||
463 | SDL_SetClipRect(Screen, NULL((void*)0)); | |||
464 | }; // void InitiateMenu(void) | |||
465 | ||||
466 | /** | |||
467 | * This function provides a convenient cheat menu, so that any | |||
468 | * tester does not have to play all through the game again and again | |||
469 | * to see if a bug in a certain position has been removed or not. | |||
470 | */ | |||
471 | void Cheatmenu(void) | |||
472 | { | |||
473 | int can_continue; | |||
474 | int i, l; | |||
475 | int x0, y0; | |||
476 | int skip_dead = 0; | |||
477 | item cheat_gun; | |||
478 | ||||
479 | // Prevent distortion of framerate by the delay coming from | |||
480 | // the time spend in the menu. | |||
481 | // | |||
482 | Activate_Conservative_Frame_Computation(); | |||
483 | ||||
484 | // Some small font is needed, such that we can get a lot of lines on | |||
485 | // one single cheat menu page... | |||
486 | // | |||
487 | SetCurrentFont(FPS_Display_BFont); | |||
488 | ||||
489 | x0 = 50; | |||
490 | y0 = 20; | |||
491 | ||||
492 | can_continue = FALSE(0); | |||
493 | while (!can_continue) { | |||
494 | clear_screen(); | |||
495 | printf_SDL(Screen, x0, y0, "Current position: Level=%d, X=%d, Y=%d\n", Me.pos.z, (int)Me.pos.x, (int)Me.pos.y); | |||
496 | printf_SDL(Screen, -1, -1, " f. xray_vision_for_tux: %s", GameConfig.xray_vision_for_tux ? "ON\n" : "OFF\n"); | |||
497 | printf_SDL(Screen, -1, -1, " g. god mode: %s\n", Me.god_mode ? "ON" : "OFF"); | |||
498 | printf_SDL(Screen, -1, -1, " i. Make tux invisible: %s", (Me.invisible_duration > 1) ? "ON\n" : "OFF\n"); | |||
499 | printf_SDL(Screen, -1, -1, " l. robot list of current level\n"); | |||
500 | printf_SDL(Screen, -1, -1, " L. alive robot list of current level\n"); | |||
501 | printf_SDL(Screen, -1, -1, " k. dead robot list of current level\n"); | |||
502 | printf_SDL(Screen, -1, -1, " d. destroy robots on current level\n"); | |||
503 | printf_SDL(Screen, -1, -1, " h. Auto-acquire all skills\n"); | |||
504 | printf_SDL(Screen, -1, -1, " c. Acquire 1 million circuits, current worth: %d\n", Me.Gold); | |||
505 | printf_SDL(Screen, -1, -1, " n. No hidden droids: %s", show_all_droids ? "ON\n" : "OFF\n"); | |||
506 | printf_SDL(Screen, -1, -1, " r. Infinite running stamina: %s", GameConfig.cheat_running_stamina ? "ON\n" : "OFF\n"); | |||
507 | printf_SDL(Screen, -1, -1, " s. Double speed running: %s\n", GameConfig.cheat_double_speed ? "ON" : "OFF"); | |||
508 | printf_SDL(Screen, -1, -1, " t. Give a cheat gun\n"); | |||
509 | printf_SDL(Screen, -1, -1, " x. Cheatkeys : %s", GameConfig.enable_cheatkeys ? "ON\n" : "OFF\n"); | |||
510 | printf_SDL(Screen, -1, -1, " T. Add a training point. Current training points: %d\n", Me.points_to_distribute); | |||
511 | printf_SDL(Screen, -1, -1, " e. Show enemies' states: %s", GameConfig.All_Texts_Switch ? "ON\n" : "OFF\n"); | |||
512 | printf_SDL(Screen, -1, -1, " q. RESUME game\n"); | |||
513 | ||||
514 | // Now we show it... | |||
515 | // | |||
516 | our_SDL_flip_wrapper(); | |||
517 | ||||
518 | switch (getchar_raw(NULL((void*)0))) { | |||
519 | case 'f': | |||
520 | GameConfig.xray_vision_for_tux = !GameConfig.xray_vision_for_tux; | |||
521 | break; | |||
522 | case 'g': | |||
523 | Me.god_mode = !Me.god_mode; | |||
524 | break; | |||
525 | case 'T': | |||
526 | Me.points_to_distribute++; | |||
527 | break; | |||
528 | case 'i': | |||
529 | if (Me.invisible_duration == 0) { | |||
530 | Me.invisible_duration += 50000; | |||
531 | break; | |||
532 | } | |||
533 | if (Me.invisible_duration > 0) { | |||
534 | Me.invisible_duration = 0.0; | |||
535 | break; | |||
536 | } | |||
537 | break; | |||
538 | case 'k': | |||
539 | skip_dead = 2; | |||
540 | break; | |||
541 | case 'L': | |||
542 | if (skip_dead == 0) | |||
543 | skip_dead = 1; | |||
544 | break; | |||
545 | case 'l': // robot list of this deck | |||
546 | l = 0; // l is counter for lines of display of enemy output | |||
547 | for (i = ((skip_dead == 1) ? 1 : 0); i < ((skip_dead == 2) ? 1 : 2); i++) { | |||
548 | enemy *erot; | |||
549 | list_for_each_entry(erot, (i) ? &alive_bots_head : &dead_bots_head, global_list)for (erot = ({ const typeof( ((typeof(*erot) *)0)->global_list ) *__mptr = (((i) ? &alive_bots_head : &dead_bots_head )->next); (typeof(*erot) *)( (char *)__mptr - __builtin_offsetof (typeof(*erot), global_list) );}); &erot->global_list != ((i) ? &alive_bots_head : &dead_bots_head); erot = ( { const typeof( ((typeof(*erot) *)0)->global_list ) *__mptr = (erot->global_list.next); (typeof(*erot) *)( (char *)__mptr - __builtin_offsetof(typeof(*erot), global_list) );})) { | |||
550 | if (erot->pos.z == Me.pos.z) { | |||
551 | ||||
552 | if (l && !(l % ((GameConfig.screen_height == 768) ? 25 : 16))) { | |||
553 | printf_SDL(Screen, -1, -1, " --- MORE --- \n"); | |||
554 | our_SDL_flip_wrapper(); | |||
555 | if (getchar_raw(NULL((void*)0)) == 'q') | |||
556 | break; | |||
557 | } | |||
558 | if (!(l % ((GameConfig.screen_height == 768) ? 25 : 16))) { | |||
559 | clear_screen(); | |||
560 | printf_SDL(Screen, 15, y0, | |||
561 | "ID X Y ENERGY speedX Status Friendly An-type An-Phase \n"); | |||
562 | printf_SDL(Screen, -1, -1, "---------------------------------------------\n"); | |||
563 | } | |||
564 | ||||
565 | l++; | |||
566 | if ((erot->type >= 0) && (erot->type <= Number_Of_Droid_Types)) { | |||
567 | printf_SDL(Screen, 15, -1, | |||
568 | "%s %3.1f %3.1f %4d %g ", | |||
569 | Droidmap[erot->type].droidname, | |||
570 | erot->pos.x, erot->pos.y, (int)erot->energy, erot->speed.x); | |||
571 | } else { | |||
572 | printf_SDL(Screen, 15, -1, "SEVERE ERROR: Type=%d. ", erot->type); | |||
573 | } | |||
574 | if (is_friendly(erot->faction, FACTION_SELF)) | |||
575 | printf_SDL(Screen, -1, -1, " YES"); | |||
576 | else | |||
577 | printf_SDL(Screen, -1, -1, " NO"); | |||
578 | switch (erot->animation_type) { | |||
579 | case WALK_ANIMATION113: | |||
580 | printf_SDL(Screen, -1, -1, " Walk"); | |||
581 | break; | |||
582 | case ATTACK_ANIMATION114: | |||
583 | printf_SDL(Screen, -1, -1, " Atta"); | |||
584 | break; | |||
585 | case GETHIT_ANIMATION115: | |||
586 | printf_SDL(Screen, -1, -1, " GHit"); | |||
587 | break; | |||
588 | case DEATH_ANIMATION116: | |||
589 | printf_SDL(Screen, -1, -1, " Deth"); | |||
590 | break; | |||
591 | case DEAD_ANIMATION118: | |||
592 | printf_SDL(Screen, -1, -1, " Dead"); | |||
593 | break; | |||
594 | case STAND_ANIMATION117: | |||
595 | printf_SDL(Screen, -1, -1, " Stnd"); | |||
596 | break; | |||
597 | default: | |||
598 | printf_SDL(Screen, -1, -1, " ERROR!"); | |||
599 | break; | |||
600 | } | |||
601 | printf_SDL(Screen, -1, -1, " %4.1f", erot->animation_phase); | |||
602 | printf_SDL(Screen, -1, -1, "\n"); | |||
603 | ||||
604 | } // if (enemy on current level) | |||
605 | } | |||
606 | } | |||
607 | ||||
608 | printf_SDL(Screen, 15, -1, " --- END --- \n"); | |||
609 | CountNumberOfDroidsOnShip(); | |||
610 | printf_SDL(Screen, 15, -1, " BTW: Number_Of_Droids_On_Ship: %d \n", Number_Of_Droids_On_Ship); | |||
611 | our_SDL_flip_wrapper(); | |||
612 | while ((!SpacePressed()) && (!EscapePressed()) && (!MouseLeftPressed())) ; | |||
613 | while (SpacePressed() || EscapePressed() || MouseLeftPressed()) ; | |||
614 | break; | |||
615 | ||||
616 | case 'd': // destroy all robots on this level, very useful | |||
617 | { | |||
618 | enemy *erot, *nerot; | |||
619 | BROWSE_ALIVE_BOTS_SAFE(erot, nerot)for (erot = ({ const typeof( ((typeof(*erot) *)0)->global_list ) *__mptr = ((&alive_bots_head)->next); (typeof(*erot ) *)( (char *)__mptr - __builtin_offsetof(typeof(*erot), global_list ) );}), nerot = ({ const typeof( ((typeof(*erot) *)0)->global_list ) *__mptr = (erot->global_list.next); (typeof(*erot) *)( ( char *)__mptr - __builtin_offsetof(typeof(*erot), global_list ) );}); &erot->global_list != (&alive_bots_head); erot = nerot, nerot = ({ const typeof( ((typeof(*nerot) *)0)-> global_list ) *__mptr = (nerot->global_list.next); (typeof (*nerot) *)( (char *)__mptr - __builtin_offsetof(typeof(*nerot ), global_list) );})) { | |||
620 | if (erot->pos.z == Me.pos.z) | |||
621 | hit_enemy(erot, erot->energy + 1, 0, -1, 0); | |||
622 | } | |||
623 | ||||
624 | printf_SDL(Screen, -1, -1, "All robots on this deck killed!\n"); | |||
625 | our_SDL_flip_wrapper(); | |||
626 | getchar_raw(NULL((void*)0)); | |||
627 | } | |||
628 | break; | |||
629 | ||||
630 | case 'h': // auto-aquire all skills | |||
631 | for (i = 0; i < number_of_skills; i++) | |||
632 | Me.skill_level[i]++; | |||
633 | break; | |||
634 | ||||
635 | case 'c': // Add 1 million circuits | |||
636 | Me.Gold += 1000000; | |||
637 | break; | |||
638 | ||||
639 | case 'n': // toggle display of all droids | |||
640 | show_all_droids = !show_all_droids; | |||
641 | break; | |||
642 | ||||
643 | case 'r': | |||
644 | GameConfig.cheat_running_stamina = !GameConfig.cheat_running_stamina; | |||
645 | break; | |||
646 | ||||
647 | case 's': | |||
648 | GameConfig.cheat_double_speed = !GameConfig.cheat_double_speed; | |||
649 | break; | |||
650 | ||||
651 | case 't': | |||
652 | cheat_gun = create_item_with_id("Cheat Gun", TRUE(1), 1); | |||
653 | equip_item(&cheat_gun); | |||
654 | break; | |||
655 | ||||
656 | case 'e': | |||
657 | GameConfig.All_Texts_Switch = !GameConfig.All_Texts_Switch; | |||
658 | break; | |||
659 | ||||
660 | case 'x': | |||
661 | GameConfig.enable_cheatkeys = !GameConfig.enable_cheatkeys; | |||
662 | break; | |||
663 | ||||
664 | case ' ': | |||
665 | case 'q': | |||
666 | while (QPressed()) | |||
667 | SDL_Delay(1); | |||
668 | can_continue = 1; | |||
669 | break; | |||
670 | } /* switch (getchar_raw()) */ | |||
671 | } /* while (!can_continue) */ | |||
672 | ||||
673 | clear_screen(); | |||
674 | our_SDL_flip_wrapper(); | |||
675 | ||||
676 | return; | |||
677 | }; // void Cheatmenu() | |||
678 | ||||
679 | /*********************** | |||
680 | * Menus : Most of the menus are split into two parts | |||
681 | * - handle, that handles the user selection | |||
682 | * - fill, that creates the names of the button. | |||
683 | * | |||
684 | * Because there is much code that must be generated for each "menu" | |||
685 | * like prototypes, enums, I use this trick to do the job, and this way | |||
686 | * I'm sure there is no mismatch in the orders | |||
687 | */ | |||
688 | ||||
689 | #define MENU_LISTMENU(Startup, STARTUP) MENU(Escape, ESCAPE) MENU(Options, OPTIONS ) MENU(Resolution, RESOLUTION) MENU(Graphics, GRAPHICS) MENU( Sound, SOUND) MENU(Performance, PERFORMANCE) MENU(OSD, OSD) MENU (Game, GAME) MENU(Startup, STARTUP) MENU(Escape, ESCAPE) \ | |||
690 | MENU(Options, OPTIONS) MENU(Resolution, RESOLUTION) \ | |||
691 | MENU(Graphics, GRAPHICS) MENU(Sound, SOUND) \ | |||
692 | MENU(Performance, PERFORMANCE) \ | |||
693 | MENU(OSD, OSD) \ | |||
694 | MENU(Game, GAME) | |||
695 | ||||
696 | enum { | |||
697 | EXIT_MENU = -2, | |||
698 | CONTINUE_MENU = -1, | |||
699 | #define MENU(x, y) MENU_##y, | |||
700 | MENU_LISTMENU(Startup, STARTUP) MENU(Escape, ESCAPE) MENU(Options, OPTIONS ) MENU(Resolution, RESOLUTION) MENU(Graphics, GRAPHICS) MENU( Sound, SOUND) MENU(Performance, PERFORMANCE) MENU(OSD, OSD) MENU (Game, GAME) | |||
701 | #ifdef ENABLE_NLS1 | |||
702 | MENU(Language, LANGUAGE) | |||
703 | #endif | |||
704 | #undef MENU | |||
705 | MENU_NUM | |||
706 | }; | |||
707 | ||||
708 | #define MENU(x, y) static int x##_handle (int); static void x##_fill (char *[MAX_MENU_ITEMS100]); | |||
709 | MENU_LISTMENU(Startup, STARTUP) MENU(Escape, ESCAPE) MENU(Options, OPTIONS ) MENU(Resolution, RESOLUTION) MENU(Graphics, GRAPHICS) MENU( Sound, SOUND) MENU(Performance, PERFORMANCE) MENU(OSD, OSD) MENU (Game, GAME) | |||
710 | #ifdef ENABLE_NLS1 | |||
711 | MENU(Language, LANGUAGE) | |||
712 | #endif | |||
713 | #undef MENU | |||
714 | struct Menu { | |||
715 | int (*HandleSelection) (int); | |||
716 | void (*FillText) (char *[MAX_MENU_ITEMS100]); | |||
717 | }; | |||
718 | ||||
719 | struct Menu menus[] = { | |||
720 | #define MENU(x, y) { x##_handle, x##_fill }, | |||
721 | MENU_LISTMENU(Startup, STARTUP) MENU(Escape, ESCAPE) MENU(Options, OPTIONS ) MENU(Resolution, RESOLUTION) MENU(Graphics, GRAPHICS) MENU( Sound, SOUND) MENU(Performance, PERFORMANCE) MENU(OSD, OSD) MENU (Game, GAME) | |||
722 | #ifdef ENABLE_NLS1 | |||
723 | MENU(Language, LANGUAGE) | |||
724 | #endif | |||
725 | #undef MENU | |||
726 | {NULL((void*)0), NULL((void*)0)} | |||
727 | }; | |||
728 | ||||
729 | static void RunSubMenu(int startup, int menu_id) | |||
730 | { | |||
731 | int can_continue = 0; | |||
732 | char *texts[MAX_MENU_ITEMS100]; | |||
733 | int i = 0; | |||
734 | while (!can_continue) { | |||
735 | int pos; | |||
736 | // We need to fill at each loop because | |||
737 | // several menus change their contents | |||
738 | for (i = 0; i < MAX_MENU_ITEMS100; i++) | |||
739 | texts[i] = (char *)malloc(1024); | |||
740 | menus[menu_id].FillText(texts); | |||
741 | ||||
742 | if (startup) | |||
743 | pos = DoMenuSelection("", texts, -1, "title.jpg", Menu_BFont); | |||
744 | else | |||
745 | pos = DoMenuSelection("", texts, 1, "--GAME_BACKGROUND--", Menu_BFont); | |||
746 | ||||
747 | int ret = menus[menu_id].HandleSelection(pos); | |||
748 | ||||
749 | for (i = 0; i < MAX_MENU_ITEMS100; i++) | |||
750 | free(texts[i]); | |||
751 | ||||
752 | if (ret == EXIT_MENU) { | |||
753 | can_continue = TRUE(1); | |||
754 | } | |||
755 | ||||
756 | if (ret > 0) | |||
757 | RunSubMenu(startup, ret); | |||
758 | } | |||
759 | } | |||
760 | ||||
761 | static void RunMenu(int is_startup) | |||
762 | { | |||
763 | int start_menu = is_startup ? MENU_STARTUP : MENU_ESCAPE; | |||
764 | SetCurrentFont(Menu_BFont); | |||
765 | Activate_Conservative_Frame_Computation(); | |||
766 | if (is_startup) { | |||
767 | // Can the music be disabled by a submenu ? | |||
768 | SwitchBackgroundMusicTo("menu.ogg"); | |||
769 | SDL_SetClipRect(Screen, NULL((void*)0)); | |||
770 | ||||
771 | if (skip_initial_menus && Single_Player_Menu()) | |||
772 | return; | |||
773 | } else { | |||
774 | while (EscapePressed()) ; | |||
775 | } | |||
776 | RunSubMenu(is_startup, start_menu); | |||
777 | clear_screen(); | |||
778 | } | |||
779 | ||||
780 | void StartupMenu(void) | |||
781 | { | |||
782 | RunMenu(1); | |||
783 | } | |||
784 | ||||
785 | void EscapeMenu(void) | |||
786 | { | |||
787 | RunMenu(0); | |||
788 | } | |||
789 | ||||
790 | static int Startup_handle(int n) | |||
791 | { | |||
792 | enum { | |||
793 | SINGLE_PLAYER_POSITION = 1, | |||
794 | TUTORIAL_POSITION, | |||
795 | LVLEDIT_POSITION, | |||
796 | OPTIONS_POSITION, | |||
797 | CREDITS_POSITION, | |||
798 | CONTRIBUTE_POSITION, | |||
799 | EXIT_FREEDROID_POSITION | |||
800 | }; | |||
801 | switch (n) { | |||
802 | case SINGLE_PLAYER_POSITION: | |||
803 | game_root_mode = ROOT_IS_GAME; | |||
804 | if (Single_Player_Menu()) { | |||
805 | return EXIT_MENU; | |||
806 | } | |||
807 | break; | |||
808 | case LVLEDIT_POSITION: //allow starting directly in leveleditor - the hack is a little dirty but it does its work. | |||
809 | prepare_level_editor(); | |||
810 | return EXIT_MENU; | |||
811 | break; | |||
812 | case TUTORIAL_POSITION: //Similar hack to start Tutorial. | |||
813 | game_root_mode = ROOT_IS_GAME; | |||
814 | skip_initial_menus = 1; | |||
815 | char fpp[PATH_MAX4096]; | |||
816 | find_file("levels.dat", MAP_DIR, fpp, PLEASE_INFORM | IS_FATAL); | |||
817 | LoadShip(fpp, 0); | |||
818 | PrepareStartOfNewCharacter("TutorialTuxStart"); | |||
819 | skip_initial_menus = 0; | |||
820 | free(Me.character_name); | |||
821 | Me.character_name = strdup("TutorialTux")(__extension__ (__builtin_constant_p ("TutorialTux") && ((size_t)(const void *)(("TutorialTux") + 1) - (size_t)(const void *)("TutorialTux") == 1) ? (((const char *) ("TutorialTux" ))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("TutorialTux") + 1; char *__retval = ( char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "TutorialTux", __len); __retval; } )) : __strdup ("TutorialTux"))); | |||
822 | return EXIT_MENU; | |||
823 | break; | |||
824 | case OPTIONS_POSITION: | |||
825 | return MENU_OPTIONS; | |||
826 | case CREDITS_POSITION: | |||
827 | PlayATitleFile("Credits.lua"); | |||
828 | break; | |||
829 | case CONTRIBUTE_POSITION: | |||
830 | PlayATitleFile("Contribute.lua"); | |||
831 | break; | |||
832 | case (-1): | |||
833 | case EXIT_FREEDROID_POSITION: | |||
834 | Terminate(EXIT_SUCCESS0); | |||
835 | break; | |||
836 | default: | |||
837 | break; | |||
838 | } | |||
839 | return CONTINUE_MENU; | |||
840 | } | |||
841 | ||||
842 | static void Startup_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
843 | { | |||
844 | int i = 0; | |||
845 | strncpy(MenuTexts[i++], _("Play"), 1024)__builtin_strncpy (MenuTexts[i++], ("Play"[0]!='\0'?dcgettext (((void*)0), "Play", 5):""), 1024); | |||
846 | strncpy(MenuTexts[i++], _("Tutorial"), 1024)__builtin_strncpy (MenuTexts[i++], ("Tutorial"[0]!='\0'?dcgettext (((void*)0), "Tutorial", 5):""), 1024); | |||
847 | strncpy(MenuTexts[i++], _("Level Editor"), 1024)__builtin_strncpy (MenuTexts[i++], ("Level Editor"[0]!='\0'?dcgettext (((void*)0), "Level Editor", 5):""), 1024); | |||
848 | strncpy(MenuTexts[i++], _("Options"), 1024)__builtin_strncpy (MenuTexts[i++], ("Options"[0]!='\0'?dcgettext (((void*)0), "Options", 5):""), 1024); | |||
849 | strncpy(MenuTexts[i++], _("Credits"), 1024)__builtin_strncpy (MenuTexts[i++], ("Credits"[0]!='\0'?dcgettext (((void*)0), "Credits", 5):""), 1024); | |||
850 | strncpy(MenuTexts[i++], _("Contribute"), 1024)__builtin_strncpy (MenuTexts[i++], ("Contribute"[0]!='\0'?dcgettext (((void*)0), "Contribute", 5):""), 1024); | |||
851 | strncpy(MenuTexts[i++], _("Exit FreedroidRPG"), 1024)__builtin_strncpy (MenuTexts[i++], ("Exit FreedroidRPG"[0]!='\0' ?dcgettext (((void*)0), "Exit FreedroidRPG", 5):""), 1024); | |||
852 | MenuTexts[i++][0] = '\0'; | |||
853 | } | |||
854 | ||||
855 | static int Game_handle(int n) | |||
856 | { | |||
857 | enum { | |||
858 | DIFFICULTY = 1, | |||
859 | LEAVE_MENU | |||
860 | }; | |||
861 | switch (n) { | |||
862 | case (-1): | |||
863 | return EXIT_MENU; | |||
864 | break; | |||
865 | case DIFFICULTY: | |||
866 | GameConfig.difficulty_level++; | |||
867 | GameConfig.difficulty_level %= 3; | |||
868 | alert_window("%s", _("You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience.")("You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." [0]!='\0'?dcgettext (((void*)0), "You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." , 5):"")); | |||
869 | return CONTINUE_MENU; | |||
870 | case LEAVE_MENU: | |||
871 | return EXIT_MENU; | |||
872 | default: | |||
873 | break; | |||
874 | } | |||
875 | return CONTINUE_MENU; | |||
876 | } | |||
877 | ||||
878 | static void Game_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
879 | { | |||
880 | const char *difficulty_str[] = { | |||
881 | [DIFFICULTY_EASY] = N_("easy")("easy"), | |||
882 | [DIFFICULTY_NORMAL] = N_("normal")("normal"), | |||
883 | [DIFFICULTY_HARD] = N_("hard")("hard"), | |||
884 | }; | |||
885 | ||||
886 | sprintf(MenuTexts[0], _("Difficulty: %s")("Difficulty: %s"[0]!='\0'?dcgettext (((void*)0), "Difficulty: %s" , 5):""), _(difficulty_str[GameConfig.difficulty_level])(difficulty_str[GameConfig.difficulty_level][0]!='\0'?dcgettext (((void*)0), difficulty_str[GameConfig.difficulty_level], 5) :"")); | |||
887 | strncpy(MenuTexts[1], _("Back"), 1024)__builtin_strncpy (MenuTexts[1], ("Back"[0]!='\0'?dcgettext ( ((void*)0), "Back", 5):""), 1024); | |||
888 | MenuTexts[2][0] = '\0'; | |||
889 | } | |||
890 | ||||
891 | static int Options_handle(int n) | |||
892 | { | |||
893 | enum { | |||
894 | GAME_OPTIONS = 1, | |||
895 | GRAPHICS_OPTIONS, | |||
896 | SOUND_OPTIONS, | |||
897 | KEYMAP_OPTIONS, | |||
898 | #ifdef ENABLE_NLS1 | |||
899 | LANGUAGE_OPTIONS, | |||
900 | #endif | |||
901 | ON_SCREEN_DISPLAYS, | |||
902 | PERFORMANCE_TWEAKS_OPTIONS, | |||
903 | LEAVE_OPTIONS_MENU | |||
904 | }; | |||
905 | switch (n) { | |||
906 | case (-1): | |||
907 | return EXIT_MENU; | |||
908 | break; | |||
909 | #ifdef ENABLE_NLS1 | |||
910 | case LANGUAGE_OPTIONS: | |||
911 | return MENU_LANGUAGE; | |||
912 | #endif | |||
913 | case GAME_OPTIONS: | |||
914 | return MENU_GAME; | |||
915 | case GRAPHICS_OPTIONS: | |||
916 | return MENU_GRAPHICS; | |||
917 | case SOUND_OPTIONS: | |||
918 | return MENU_SOUND; | |||
919 | case KEYMAP_OPTIONS: | |||
920 | keychart(); | |||
921 | return CONTINUE_MENU; | |||
922 | case ON_SCREEN_DISPLAYS: | |||
923 | return MENU_OSD; | |||
924 | case PERFORMANCE_TWEAKS_OPTIONS: | |||
925 | return MENU_PERFORMANCE; | |||
926 | case LEAVE_OPTIONS_MENU: | |||
927 | return EXIT_MENU; | |||
928 | default: | |||
929 | break; | |||
930 | } | |||
931 | return CONTINUE_MENU; | |||
932 | } | |||
933 | ||||
934 | static void Options_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
935 | { | |||
936 | int i = 0; | |||
937 | strncpy(MenuTexts[i++], _("Gameplay"), 1024)__builtin_strncpy (MenuTexts[i++], ("Gameplay"[0]!='\0'?dcgettext (((void*)0), "Gameplay", 5):""), 1024); | |||
938 | strncpy(MenuTexts[i++], _("Graphics"), 1024)__builtin_strncpy (MenuTexts[i++], ("Graphics"[0]!='\0'?dcgettext (((void*)0), "Graphics", 5):""), 1024); | |||
939 | strncpy(MenuTexts[i++], _("Sound"), 1024)__builtin_strncpy (MenuTexts[i++], ("Sound"[0]!='\0'?dcgettext (((void*)0), "Sound", 5):""), 1024); | |||
940 | strncpy(MenuTexts[i++], _("Keys"), 1024)__builtin_strncpy (MenuTexts[i++], ("Keys"[0]!='\0'?dcgettext (((void*)0), "Keys", 5):""), 1024); | |||
941 | #ifdef ENABLE_NLS1 | |||
942 | strncpy(MenuTexts[i++], _("Languages"), 1024)__builtin_strncpy (MenuTexts[i++], ("Languages"[0]!='\0'?dcgettext (((void*)0), "Languages", 5):""), 1024); | |||
943 | #endif | |||
944 | strncpy(MenuTexts[i++], _("On-Screen displays"), 1024)__builtin_strncpy (MenuTexts[i++], ("On-Screen displays"[0]!= '\0'?dcgettext (((void*)0), "On-Screen displays", 5):""), 1024 ); | |||
945 | strncpy(MenuTexts[i++], _("Performance tweaks"), 1024)__builtin_strncpy (MenuTexts[i++], ("Performance tweaks"[0]!= '\0'?dcgettext (((void*)0), "Performance tweaks", 5):""), 1024 ); | |||
946 | strncpy(MenuTexts[i++], _("Back"), 1024)__builtin_strncpy (MenuTexts[i++], ("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""), 1024); | |||
947 | MenuTexts[i++][0] = '\0'; | |||
948 | } | |||
949 | ||||
950 | static int Escape_handle(int n) | |||
951 | { | |||
952 | enum { | |||
953 | RESUME_GAME_POSITION = 1, | |||
954 | SAVE_GAME_POSITION, | |||
955 | OPTIONS_POSITION, | |||
956 | LOAD_GAME_POSITION, | |||
957 | LOAD_BACKUP_POSITION, | |||
958 | NEW_GAME_POSITION, | |||
959 | QUIT_POSITION | |||
960 | }; | |||
961 | switch (n) { | |||
962 | case (-1): | |||
963 | case (RESUME_GAME_POSITION): | |||
964 | return EXIT_MENU; | |||
965 | case OPTIONS_POSITION: | |||
966 | return MENU_OPTIONS; | |||
967 | case LOAD_GAME_POSITION: | |||
968 | LoadGame(); | |||
969 | return EXIT_MENU; | |||
970 | case LOAD_BACKUP_POSITION: | |||
971 | LoadBackupGame(); | |||
972 | return EXIT_MENU; | |||
973 | case NEW_GAME_POSITION: | |||
974 | GameOver = TRUE(1); | |||
975 | return EXIT_MENU; | |||
976 | case SAVE_GAME_POSITION: | |||
977 | SaveGame(); | |||
978 | break; | |||
979 | case QUIT_POSITION: | |||
980 | DebugPrintf(2, "\nvoid EscapeMenu( void ): Quit requested by user. Terminating..."); | |||
981 | Terminate(EXIT_SUCCESS0); | |||
982 | break; | |||
983 | default: | |||
984 | break; | |||
985 | } | |||
986 | ||||
987 | return CONTINUE_MENU; | |||
988 | } | |||
989 | ||||
990 | static void Escape_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
991 | { | |||
992 | if (game_root_mode == ROOT_IS_GAME) | |||
993 | strncpy(MenuTexts[0], _("Resume Play"), 1024)__builtin_strncpy (MenuTexts[0], ("Resume Play"[0]!='\0'?dcgettext (((void*)0), "Resume Play", 5):""), 1024); | |||
994 | else | |||
995 | strncpy(MenuTexts[0], _("Resume Playtest"), 1024)__builtin_strncpy (MenuTexts[0], ("Resume Playtest"[0]!='\0'? dcgettext (((void*)0), "Resume Playtest", 5):""), 1024); | |||
996 | ||||
997 | strncpy(MenuTexts[1], _("Save Hero"), 1024)__builtin_strncpy (MenuTexts[1], ("Save Hero"[0]!='\0'?dcgettext (((void*)0), "Save Hero", 5):""), 1024); | |||
998 | strncpy(MenuTexts[2], _("Options"), 1024)__builtin_strncpy (MenuTexts[2], ("Options"[0]!='\0'?dcgettext (((void*)0), "Options", 5):""), 1024); | |||
999 | strncpy(MenuTexts[3], _("Load Latest"), 1024)__builtin_strncpy (MenuTexts[3], ("Load Latest"[0]!='\0'?dcgettext (((void*)0), "Load Latest", 5):""), 1024); | |||
1000 | strncpy(MenuTexts[4], _("Load Backup"), 1024)__builtin_strncpy (MenuTexts[4], ("Load Backup"[0]!='\0'?dcgettext (((void*)0), "Load Backup", 5):""), 1024); | |||
1001 | if (game_root_mode == ROOT_IS_GAME) | |||
1002 | strncpy(MenuTexts[5], _("Quit to Main Menu"), 1024)__builtin_strncpy (MenuTexts[5], ("Quit to Main Menu"[0]!='\0' ?dcgettext (((void*)0), "Quit to Main Menu", 5):""), 1024); | |||
1003 | else | |||
1004 | strncpy(MenuTexts[5], _("Return to Level Editor"), 1024)__builtin_strncpy (MenuTexts[5], ("Return to Level Editor"[0] !='\0'?dcgettext (((void*)0), "Return to Level Editor", 5):"" ), 1024); | |||
1005 | strncpy(MenuTexts[6], _("Exit FreedroidRPG"), 1024)__builtin_strncpy (MenuTexts[6], ("Exit FreedroidRPG"[0]!='\0' ?dcgettext (((void*)0), "Exit FreedroidRPG", 5):""), 1024); | |||
1006 | MenuTexts[7][0] = '\0'; | |||
1007 | } | |||
1008 | ||||
1009 | #ifdef ENABLE_NLS1 | |||
1010 | static int Language_handle(int n) | |||
1011 | { | |||
1012 | if (n == -1) | |||
1013 | return EXIT_MENU; | |||
1014 | ||||
1015 | n -= 2; // Second menu entry is index 0 of the language list | |||
1016 | ||||
1017 | // Do nothing if 'Back' was selected | |||
1018 | if (n >= lang_specs.size) | |||
1019 | return EXIT_MENU; | |||
1020 | ||||
1021 | if (n == -1) { | |||
1022 | // 'System default' was selected | |||
1023 | lang_set(""); | |||
1024 | } else { | |||
1025 | // Else, use the selected language | |||
1026 | struct langspec *lang = dynarray_member(&lang_specs, n, sizeof(struct langspec)); | |||
1027 | lang_set(lang->locale); | |||
1028 | } | |||
1029 | ||||
1030 | return CONTINUE_MENU; | |||
1031 | } | |||
1032 | #endif | |||
1033 | ||||
1034 | #ifdef ENABLE_NLS1 | |||
1035 | static void Language_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
1036 | { | |||
1037 | int i = 0; | |||
1038 | int l; | |||
1039 | char mark; | |||
1040 | ||||
1041 | mark = ' '; | |||
1042 | if (!GameConfig.locale || strlen(GameConfig.locale) == 0) | |||
1043 | mark = '*'; | |||
1044 | snprintf(MenuTexts[i++], 1024, "%c %s ", mark, _("System default")("System default"[0]!='\0'?dcgettext (((void*)0), "System default" , 5):"")); | |||
1045 | ||||
1046 | for (l = 0; l < lang_specs.size; l++) { | |||
1047 | struct langspec *lang = dynarray_member(&lang_specs, l, sizeof(struct langspec)); | |||
1048 | mark = ' '; | |||
1049 | if (GameConfig.locale && !strcmp(GameConfig.locale, lang->locale)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (GameConfig.locale) && __builtin_constant_p (lang-> locale) && (__s1_len = strlen (GameConfig.locale), __s2_len = strlen (lang->locale), (!((size_t)(const void *)((GameConfig .locale) + 1) - (size_t)(const void *)(GameConfig.locale) == 1 ) || __s1_len >= 4) && (!((size_t)(const void *)(( lang->locale) + 1) - (size_t)(const void *)(lang->locale ) == 1) || __s2_len >= 4)) ? __builtin_strcmp (GameConfig. locale, lang->locale) : (__builtin_constant_p (GameConfig. locale) && ((size_t)(const void *)((GameConfig.locale ) + 1) - (size_t)(const void *)(GameConfig.locale) == 1) && (__s1_len = strlen (GameConfig.locale), __s1_len < 4) ? ( __builtin_constant_p (lang->locale) && ((size_t)(const void *)((lang->locale) + 1) - (size_t)(const void *)(lang ->locale) == 1) ? __builtin_strcmp (GameConfig.locale, lang ->locale) : (__extension__ ({ const unsigned char *__s2 = ( const unsigned char *) (const char *) (lang->locale); int __result = (((const unsigned char *) (const char *) (GameConfig.locale ))[0] - __s2[0]); if (__s1_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (GameConfig .locale))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) ( GameConfig.locale))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (GameConfig.locale))[3] - __s2[3]); } } __result; }))) : ( __builtin_constant_p (lang->locale) && ((size_t)(const void *)((lang->locale) + 1) - (size_t)(const void *)(lang ->locale) == 1) && (__s2_len = strlen (lang->locale ), __s2_len < 4) ? (__builtin_constant_p (GameConfig.locale ) && ((size_t)(const void *)((GameConfig.locale) + 1) - (size_t)(const void *)(GameConfig.locale) == 1) ? __builtin_strcmp (GameConfig.locale, lang->locale) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (GameConfig.locale); int __result = (((const unsigned char * ) (const char *) (lang->locale))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (lang->locale))[1] - __s2[1]); if ( __s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (lang->locale))[2] - __s2 [2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (lang->locale))[ 3] - __s2[3]); } } __result; })))) : __builtin_strcmp (GameConfig .locale, lang->locale)))); })) | |||
1050 | mark = '*'; | |||
1051 | snprintf(MenuTexts[i++], 1024, "%c %s ", mark, lang->name); | |||
1052 | } | |||
1053 | snprintf(MenuTexts[i++], 1024, " %s ", _("Back")("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):"")); | |||
1054 | MenuTexts[i++][0] = '\0'; | |||
1055 | } | |||
1056 | #endif | |||
1057 | ||||
1058 | extern screen_resolution screen_resolutions[]; | |||
1059 | ||||
1060 | static int Resolution_handle(int n) | |||
1061 | { | |||
1062 | if (n == -1) | |||
1063 | return EXIT_MENU; | |||
1064 | ||||
1065 | // First value of 'n' is '1', so decrement it. | |||
1066 | --n; | |||
1067 | ||||
1068 | int nb_res = 0; | |||
1069 | int nb_supported_res = 0; | |||
1070 | while (screen_resolutions[nb_res].xres != -1) { | |||
1071 | if (screen_resolutions[nb_res].supported) | |||
1072 | ++nb_supported_res; | |||
1073 | ++nb_res; | |||
1074 | } | |||
1075 | ||||
1076 | // + 2 here accounts for 'Back' and end-of-list marker | |||
1077 | int offset = max(0, nb_supported_res - MAX_MENU_ITEMS + 2)((0) < (nb_supported_res - 100 + 2) ? (nb_supported_res - 100 + 2) : (0) ); | |||
1078 | ||||
1079 | // Last menu entry is 'Back' | |||
1080 | if (n == nb_supported_res - offset) { | |||
1081 | while (EnterPressed() || SpacePressed()) ; | |||
1082 | return EXIT_MENU; | |||
1083 | } | |||
1084 | // Wrong entry. How is it possible ??? | |||
1085 | if (n < 0 || n > nb_supported_res) | |||
1086 | return CONTINUE_MENU; | |||
1087 | ||||
1088 | int i, j; | |||
1089 | for (i = offset, j = 0; i < nb_res; ++i) { | |||
1090 | // Only supported screen resolution are displayed | |||
1091 | if (!screen_resolutions[i].supported) | |||
1092 | continue; | |||
1093 | ||||
1094 | // Is the current supported resolution the selected one ? | |||
1095 | if (n == j) { | |||
1096 | while (EnterPressed() || SpacePressed()) ; | |||
1097 | GameConfig.next_time_width_of_screen = screen_resolutions[i].xres; | |||
1098 | GameConfig.next_time_height_of_screen = screen_resolutions[i].yres; | |||
1099 | alert_window(_("You selected %d x %d pixels.\n\nYou need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience.")("You selected %d x %d pixels.\n\nYou need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." [0]!='\0'?dcgettext (((void*)0), "You selected %d x %d pixels.\n\nYou need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." , 5):""), screen_resolutions[i].xres, screen_resolutions[i].yres); | |||
1100 | return CONTINUE_MENU; | |||
1101 | } | |||
1102 | ++j; | |||
1103 | } | |||
1104 | ||||
1105 | return CONTINUE_MENU; | |||
1106 | } | |||
1107 | ||||
1108 | static void Resolution_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
1109 | { | |||
1110 | int i = 0; | |||
1111 | int j = 0; | |||
1112 | int nb_res = 0; | |||
1113 | ||||
1114 | // Count the resolutions, stop on our delimiter | |||
1115 | for (i = 0; screen_resolutions[i].xres != -1; i++); | |||
1116 | nb_res = i; | |||
1117 | ||||
1118 | // we require an offset in case we need to truncate the beginning of the list | |||
1119 | // '-2' to make room for 'Back' and end-of-list marker | |||
1120 | int offset = max(0, nb_res - (MAX_MENU_ITEMS - 2))((0) < (nb_res - (100 - 2)) ? (nb_res - (100 - 2)) : (0) ); | |||
1121 | i = offset; | |||
1122 | ||||
1123 | // '-2' here accounts for 'Back' and end-of-list marker | |||
1124 | while (i < nb_res && j < (MAX_MENU_ITEMS100 - 2)) { | |||
1125 | //Only supported screen resolution are displayed | |||
1126 | if (screen_resolutions[i].supported) { | |||
1127 | char flag = ' '; | |||
1128 | if (GameConfig.next_time_width_of_screen == screen_resolutions[i].xres && | |||
1129 | GameConfig.next_time_height_of_screen == screen_resolutions[i].yres) { | |||
1130 | flag = '*'; | |||
1131 | } | |||
1132 | sprintf(MenuTexts[j++], "%c %dx%d", flag, screen_resolutions[i].xres, screen_resolutions[i].yres); | |||
1133 | } | |||
1134 | ++i; | |||
1135 | } | |||
1136 | // Append 'Back' option | |||
1137 | strncpy(MenuTexts[j++], _("Back"), 1024)__builtin_strncpy (MenuTexts[j++], ("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""), 1024); | |||
1138 | MenuTexts[j][0] = '\0'; | |||
1139 | } | |||
1140 | ||||
1141 | static int Graphics_handle(int n) | |||
1142 | { | |||
1143 | enum { | |||
1144 | CHANGE_SCREEN_RESOLUTION = 1, | |||
1145 | SET_FULLSCREEN_FLAG, | |||
1146 | SET_GAMMA_CORRECTION, | |||
1147 | SET_SHOW_BLOOD_FLAG, | |||
1148 | LEAVE_OPTIONS_MENU | |||
1149 | }; | |||
1150 | switch (n) { | |||
1151 | case (-1): | |||
1152 | return EXIT_MENU; | |||
1153 | case SET_GAMMA_CORRECTION: | |||
1154 | if (RightPressed()) { | |||
1155 | while (RightPressed()) ; | |||
1156 | GameConfig.current_gamma_correction += 0.05; | |||
1157 | SDL_SetGamma(GameConfig.current_gamma_correction, GameConfig.current_gamma_correction, | |||
1158 | GameConfig.current_gamma_correction); | |||
1159 | } | |||
1160 | ||||
1161 | if (LeftPressed()) { | |||
1162 | while (LeftPressed()) ; | |||
1163 | GameConfig.current_gamma_correction -= 0.05; | |||
1164 | if (GameConfig.current_gamma_correction < 0.0) { | |||
1165 | GameConfig.current_gamma_correction = 0.0; | |||
1166 | } | |||
1167 | SDL_SetGamma(GameConfig.current_gamma_correction, GameConfig.current_gamma_correction, | |||
1168 | GameConfig.current_gamma_correction); | |||
1169 | } | |||
1170 | ||||
1171 | break; | |||
1172 | ||||
1173 | case SET_FULLSCREEN_FLAG: | |||
1174 | while (EnterPressed() || SpacePressed()) ; | |||
1175 | GameConfig.fullscreen_on = !GameConfig.fullscreen_on; | |||
1176 | #ifndef __WIN32__ | |||
1177 | SDL_WM_ToggleFullScreen(Screen); | |||
1178 | #else | |||
1179 | alert_window(_("You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience.")("You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." [0]!='\0'?dcgettext (((void*)0), "You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." , 5):"")); | |||
1180 | #endif | |||
1181 | break; | |||
1182 | ||||
1183 | case CHANGE_SCREEN_RESOLUTION: | |||
1184 | while (EnterPressed() || SpacePressed()) ; | |||
1185 | return MENU_RESOLUTION; | |||
1186 | ||||
1187 | case SET_SHOW_BLOOD_FLAG: | |||
1188 | while (EnterPressed() || SpacePressed()) ; | |||
1189 | GameConfig.show_blood = !GameConfig.show_blood; | |||
1190 | break; | |||
1191 | ||||
1192 | case LEAVE_OPTIONS_MENU: | |||
1193 | while (EnterPressed() || SpacePressed()) ; | |||
1194 | return EXIT_MENU; | |||
1195 | break; | |||
1196 | ||||
1197 | default: | |||
1198 | break; | |||
1199 | ||||
1200 | } | |||
1201 | return CONTINUE_MENU; | |||
1202 | } | |||
1203 | ||||
1204 | static void Graphics_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
1205 | { | |||
1206 | char Options[20][1000]; | |||
1207 | int i = 0; | |||
1208 | sprintf(MenuTexts[i++], _("Change screen resolution")("Change screen resolution"[0]!='\0'?dcgettext (((void*)0), "Change screen resolution" , 5):"")); | |||
1209 | ||||
1210 | sprintf(Options[i], _("Fullscreen mode: %s")("Fullscreen mode: %s"[0]!='\0'?dcgettext (((void*)0), "Fullscreen mode: %s" , 5):""), GameConfig.fullscreen_on ? _("ON")("ON"[0]!='\0'?dcgettext (((void*)0), "ON", 5):"") : _("OFF")("OFF"[0]!='\0'?dcgettext (((void*)0), "OFF", 5):"")); | |||
1211 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1212 | i++; | |||
1213 | ||||
1214 | sprintf(Options[i], _("<-- Gamma correction: %1.2f -->")("<-- Gamma correction: %1.2f -->"[0]!='\0'?dcgettext ( ((void*)0), "<-- Gamma correction: %1.2f -->", 5):""), GameConfig.current_gamma_correction); | |||
1215 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1216 | i++; | |||
1217 | ||||
1218 | sprintf(Options[i], _("Show blood: %s")("Show blood: %s"[0]!='\0'?dcgettext (((void*)0), "Show blood: %s" , 5):""), GameConfig.show_blood ? _("YES")("YES"[0]!='\0'?dcgettext (((void*)0), "YES", 5):"") : _("NO")("NO"[0]!='\0'?dcgettext (((void*)0), "NO", 5):"")); | |||
1219 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1220 | i++; | |||
1221 | ||||
1222 | strncpy(MenuTexts[i++], _("Back"), 1024)__builtin_strncpy (MenuTexts[i++], ("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""), 1024); | |||
1223 | MenuTexts[i++][0] = '\0'; | |||
1224 | } | |||
1225 | ||||
1226 | static int Sound_handle(int n) | |||
1227 | { | |||
1228 | enum { | |||
1229 | SET_BG_MUSIC_VOLUME = 1, | |||
1230 | SET_SOUND_FX_VOLUME, | |||
1231 | SET_SOUND_OUTPUT_FMT, | |||
1232 | LEAVE_OPTIONS_MENU | |||
1233 | }; | |||
1234 | switch (n) { | |||
1235 | case (-1): | |||
1236 | return EXIT_MENU; | |||
1237 | case SET_BG_MUSIC_VOLUME: | |||
1238 | if (RightPressed()) { | |||
1239 | while (RightPressed()) ; | |||
1240 | GameConfig.Current_BG_Music_Volume += 0.05; | |||
1241 | if (GameConfig.Current_BG_Music_Volume > 1.0) | |||
1242 | GameConfig.Current_BG_Music_Volume = 1.0; | |||
1243 | SetBGMusicVolume(GameConfig.Current_BG_Music_Volume); | |||
1244 | } | |||
1245 | ||||
1246 | if (LeftPressed()) { | |||
1247 | while (LeftPressed()) ; | |||
1248 | GameConfig.Current_BG_Music_Volume -= 0.05; | |||
1249 | if (GameConfig.Current_BG_Music_Volume < 0.0) | |||
1250 | GameConfig.Current_BG_Music_Volume = 0.0; | |||
1251 | SetBGMusicVolume(GameConfig.Current_BG_Music_Volume); | |||
1252 | } | |||
1253 | ||||
1254 | break; | |||
1255 | ||||
1256 | case SET_SOUND_FX_VOLUME: | |||
1257 | if (RightPressed()) { | |||
1258 | while (RightPressed()) ; | |||
1259 | GameConfig.Current_Sound_FX_Volume += 0.05; | |||
1260 | if (GameConfig.Current_Sound_FX_Volume > 1.0) | |||
1261 | GameConfig.Current_Sound_FX_Volume = 1.0; | |||
1262 | SetSoundFXVolume(GameConfig.Current_Sound_FX_Volume); | |||
1263 | } | |||
1264 | ||||
1265 | if (LeftPressed()) { | |||
1266 | while (LeftPressed()) ; | |||
1267 | GameConfig.Current_Sound_FX_Volume -= 0.05; | |||
1268 | if (GameConfig.Current_Sound_FX_Volume < 0.0) | |||
1269 | GameConfig.Current_Sound_FX_Volume = 0.0; | |||
1270 | SetSoundFXVolume(GameConfig.Current_Sound_FX_Volume); | |||
1271 | } | |||
1272 | break; | |||
1273 | ||||
1274 | case SET_SOUND_OUTPUT_FMT: | |||
1275 | if (RightPressed()) { | |||
1276 | while (RightPressed()) ; | |||
1277 | GameConfig.Current_Sound_Output_Fmt = | |||
1278 | (GameConfig.Current_Sound_Output_Fmt + 1) % ALL_SOUND_OUTPUTS; | |||
1279 | alert_window(_("You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience.")("You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." [0]!='\0'?dcgettext (((void*)0), "You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." , 5):"")); | |||
1280 | } | |||
1281 | ||||
1282 | if (LeftPressed()) { | |||
1283 | while (LeftPressed()) ; | |||
1284 | GameConfig.Current_Sound_Output_Fmt = | |||
1285 | (GameConfig.Current_Sound_Output_Fmt - 1) == -1 ? ALL_SOUND_OUTPUTS-1 : (GameConfig.Current_Sound_Output_Fmt - 1); | |||
1286 | alert_window(_("You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience.")("You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." [0]!='\0'?dcgettext (((void*)0), "You need to restart FreedroidRPG for the changes to take effect.\n\nSorry for the inconvenience." , 5):"")); | |||
1287 | } | |||
1288 | break; | |||
1289 | ||||
1290 | case LEAVE_OPTIONS_MENU: | |||
1291 | while (EnterPressed() || SpacePressed()) ; | |||
1292 | return EXIT_MENU; | |||
1293 | break; | |||
1294 | ||||
1295 | default: | |||
1296 | break; | |||
1297 | } | |||
1298 | return CONTINUE_MENU; | |||
1299 | } | |||
1300 | ||||
1301 | static void Sound_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
1302 | { | |||
1303 | char Options[20][1000]; | |||
1304 | int i = 0; | |||
1305 | sprintf(Options[i], _("<-- Background music volume: %1.2f -->")("<-- Background music volume: %1.2f -->"[0]!='\0'?dcgettext (((void*)0), "<-- Background music volume: %1.2f -->", 5):""), GameConfig.Current_BG_Music_Volume); | |||
1306 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1307 | i++; | |||
1308 | ||||
1309 | sprintf(Options[i], _("<-- Sound effects volume: %1.2f -->")("<-- Sound effects volume: %1.2f -->"[0]!='\0'?dcgettext (((void*)0), "<-- Sound effects volume: %1.2f -->", 5) :""), GameConfig.Current_Sound_FX_Volume); | |||
1310 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1311 | i++; | |||
1312 | ||||
1313 | switch (GameConfig.Current_Sound_Output_Fmt) { | |||
1314 | case SOUND_OUTPUT_FMT_STEREO: | |||
1315 | sprintf(Options[i], _("<-- Output: Stereo -->")("<-- Output: Stereo -->"[0]!='\0'?dcgettext (((void*)0 ), "<-- Output: Stereo -->", 5):"")); | |||
1316 | break; | |||
1317 | ||||
1318 | case SOUND_OUTPUT_FMT_SURROUND40: | |||
1319 | sprintf(Options[i], _("<-- Output: 4.0 Surround -->")("<-- Output: 4.0 Surround -->"[0]!='\0'?dcgettext (((void *)0), "<-- Output: 4.0 Surround -->", 5):"")); | |||
1320 | break; | |||
1321 | ||||
1322 | case SOUND_OUTPUT_FMT_SURROUND51: | |||
1323 | sprintf(Options[i], _("<-- Output: 5.1 Surround -->")("<-- Output: 5.1 Surround -->"[0]!='\0'?dcgettext (((void *)0), "<-- Output: 5.1 Surround -->", 5):"")); | |||
1324 | break; | |||
1325 | ||||
1326 | default: | |||
1327 | sprintf(Options[i], _("<-- Output: Error -->")("<-- Output: Error -->"[0]!='\0'?dcgettext (((void*)0) , "<-- Output: Error -->", 5):"")); | |||
1328 | break; | |||
1329 | } | |||
1330 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1331 | i++; | |||
1332 | ||||
1333 | strncpy(MenuTexts[i++], _("Back"), 1024)__builtin_strncpy (MenuTexts[i++], ("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""), 1024); | |||
1334 | MenuTexts[i++][0] = '\0'; | |||
1335 | } | |||
1336 | ||||
1337 | static int Performance_handle(int n) | |||
1338 | { | |||
1339 | enum { | |||
1340 | SET_LIMIT_FRAMERATE_FLAG = 1, | |||
1341 | SKIP_LIGHT_RADIUS_MODE, | |||
1342 | SKIP_SHADOWS, | |||
1343 | TOGGLE_LAZYLOAD, | |||
1344 | LEAVE_PERFORMANCE_TWEAKS_MENU | |||
1345 | }; | |||
1346 | switch (n) { | |||
1347 | case (-1): | |||
1348 | return EXIT_MENU; | |||
1349 | ||||
1350 | case SET_LIMIT_FRAMERATE_FLAG: | |||
1351 | while (EnterPressed() || SpacePressed() || MouseLeftPressed()) ; | |||
1352 | GameConfig.limit_framerate = !GameConfig.limit_framerate; | |||
1353 | break; | |||
1354 | ||||
1355 | case SKIP_LIGHT_RADIUS_MODE: | |||
1356 | while (EnterPressed() || SpacePressed() || MouseLeftPressed()) ; | |||
1357 | GameConfig.skip_light_radius = !GameConfig.skip_light_radius; | |||
1358 | break; | |||
1359 | ||||
1360 | case SKIP_SHADOWS: | |||
1361 | while (EnterPressed() || SpacePressed() || MouseLeftPressed()) ; | |||
1362 | GameConfig.skip_shadow_blitting = !GameConfig.skip_shadow_blitting; | |||
1363 | break; | |||
1364 | ||||
1365 | case LEAVE_PERFORMANCE_TWEAKS_MENU: | |||
1366 | while (EnterPressed() || SpacePressed() || MouseLeftPressed()) ; | |||
1367 | return EXIT_MENU; | |||
1368 | break; | |||
1369 | ||||
1370 | case TOGGLE_LAZYLOAD: | |||
1371 | GameConfig.lazyload = !GameConfig.lazyload; | |||
1372 | break; | |||
1373 | ||||
1374 | default: | |||
1375 | break; | |||
1376 | ||||
1377 | } | |||
1378 | return CONTINUE_MENU; | |||
1379 | } | |||
1380 | ||||
1381 | static void Performance_fill(char *MenuTexts[]) | |||
1382 | { | |||
1383 | char Options[20][1000]; | |||
1384 | int i = 0; | |||
1385 | sprintf(Options[i], _("Limit framerate (powersaving): %s")("Limit framerate (powersaving): %s"[0]!='\0'?dcgettext (((void *)0), "Limit framerate (powersaving): %s", 5):""), GameConfig.limit_framerate ? _("YES")("YES"[0]!='\0'?dcgettext (((void*)0), "YES", 5):"") : _("NO")("NO"[0]!='\0'?dcgettext (((void*)0), "NO", 5):"")); | |||
1386 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1387 | i++; | |||
1388 | sprintf(Options[i], _("Show light radius: %s")("Show light radius: %s"[0]!='\0'?dcgettext (((void*)0), "Show light radius: %s" , 5):""), GameConfig.skip_light_radius ? _("NO")("NO"[0]!='\0'?dcgettext (((void*)0), "NO", 5):"") : _("YES")("YES"[0]!='\0'?dcgettext (((void*)0), "YES", 5):"")); | |||
1389 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1390 | i++; | |||
1391 | sprintf(Options[i], _("Show obstacle shadows: %s")("Show obstacle shadows: %s"[0]!='\0'?dcgettext (((void*)0), "Show obstacle shadows: %s" , 5):""), GameConfig.skip_shadow_blitting ? _("NO")("NO"[0]!='\0'?dcgettext (((void*)0), "NO", 5):"") : _("YES")("YES"[0]!='\0'?dcgettext (((void*)0), "YES", 5):"")); | |||
1392 | strncpy(MenuTexts[i], Options[i], 1024)__builtin_strncpy (MenuTexts[i], Options[i], 1024); | |||
1393 | i++; | |||
1394 | // was before: sprintf(MenuTexts[i], _("Graphics lazy loading: %s"), GameConfig.lazyload ? _("YES") : _("NO")); | |||
1395 | // moved to performance settings from graphics settings | |||
1396 | sprintf(MenuTexts[i], _("Precache item graphics: %s")("Precache item graphics: %s"[0]!='\0'?dcgettext (((void*)0), "Precache item graphics: %s", 5):""), GameConfig.lazyload ? _("NO")("NO"[0]!='\0'?dcgettext (((void*)0), "NO", 5):"") : _("YES")("YES"[0]!='\0'?dcgettext (((void*)0), "YES", 5):"")); | |||
1397 | i++; | |||
1398 | strncpy(MenuTexts[i++], _("Back"), 1024)__builtin_strncpy (MenuTexts[i++], ("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""), 1024); | |||
1399 | MenuTexts[i++][0] = '\0'; | |||
1400 | } | |||
1401 | ||||
1402 | static int OSD_handle(int n) | |||
1403 | { | |||
1404 | enum { | |||
1405 | SHOW_POSITION = 1, | |||
1406 | SHOW_FRAMERATE, | |||
1407 | SHOW_ENEMY_ENERGY_BARS, | |||
1408 | PARALLEL_BIG_SCREEN_MESSAGES_AT_MOST_POSITION, | |||
1409 | BIG_SCREEN_MESSAGES_DURATION_POSITION, | |||
1410 | LEAVE_OPTIONS_MENU | |||
1411 | }; | |||
1412 | ||||
1413 | int *shows[4] = { | |||
1414 | &GameConfig.Draw_Position, &GameConfig.Draw_Framerate, | |||
1415 | &GameConfig.enemy_energy_bars_visible | |||
1416 | }; | |||
1417 | ||||
1418 | if (n >= 1 && n < PARALLEL_BIG_SCREEN_MESSAGES_AT_MOST_POSITION) { | |||
1419 | while (EnterPressed() || SpacePressed()) ; | |||
1420 | *shows[n - 1] = !*shows[n - 1]; | |||
1421 | } else { | |||
1422 | switch (n) { | |||
1423 | case -1: | |||
1424 | return EXIT_MENU; | |||
1425 | case PARALLEL_BIG_SCREEN_MESSAGES_AT_MOST_POSITION: | |||
1426 | if (LeftPressed()) { | |||
1427 | while (LeftPressed()) ; | |||
1428 | if (GameConfig.number_of_big_screen_messages > 0) { | |||
1429 | GameConfig.number_of_big_screen_messages--; | |||
1430 | } | |||
1431 | } else if (RightPressed()) { | |||
1432 | while (RightPressed()) ; | |||
1433 | if (GameConfig.number_of_big_screen_messages < MAX_BIG_SCREEN_MESSAGES10) { | |||
1434 | GameConfig.number_of_big_screen_messages++; | |||
1435 | } | |||
1436 | } | |||
1437 | break; | |||
1438 | ||||
1439 | case BIG_SCREEN_MESSAGES_DURATION_POSITION: | |||
1440 | if (LeftPressed()) { | |||
1441 | while (LeftPressed()) ; | |||
1442 | if (GameConfig.delay_for_big_screen_messages >= 0.5) { | |||
1443 | GameConfig.delay_for_big_screen_messages -= 0.5; | |||
1444 | } | |||
1445 | } else if (RightPressed()) { | |||
1446 | while (RightPressed()) ; | |||
1447 | GameConfig.delay_for_big_screen_messages += 0.5; | |||
1448 | } | |||
1449 | break; | |||
1450 | ||||
1451 | case LEAVE_OPTIONS_MENU: | |||
1452 | while (EnterPressed() || SpacePressed()) ; | |||
1453 | return EXIT_MENU; | |||
1454 | default: | |||
1455 | break; | |||
1456 | } | |||
1457 | } | |||
1458 | return CONTINUE_MENU; | |||
1459 | } | |||
1460 | ||||
1461 | static void OSD_fill(char *MenuTexts[MAX_MENU_ITEMS100]) | |||
1462 | { | |||
1463 | sprintf(MenuTexts[0], _("Show position: %s")("Show position: %s"[0]!='\0'?dcgettext (((void*)0), "Show position: %s" , 5):""), GameConfig.Draw_Position ? _("YES")("YES"[0]!='\0'?dcgettext (((void*)0), "YES", 5):"") : _("NO")("NO"[0]!='\0'?dcgettext (((void*)0), "NO", 5):"")); | |||
1464 | sprintf(MenuTexts[1], _("Show framerate: %s")("Show framerate: %s"[0]!='\0'?dcgettext (((void*)0), "Show framerate: %s" , 5):""), GameConfig.Draw_Framerate ? _("YES")("YES"[0]!='\0'?dcgettext (((void*)0), "YES", 5):"") : _("NO")("NO"[0]!='\0'?dcgettext (((void*)0), "NO", 5):"")); | |||
1465 | sprintf(MenuTexts[2], _("Show enemies' energy bars: %s")("Show enemies' energy bars: %s"[0]!='\0'?dcgettext (((void*) 0), "Show enemies' energy bars: %s", 5):""), GameConfig.enemy_energy_bars_visible ? _("YES")("YES"[0]!='\0'?dcgettext (((void*)0), "YES", 5):"") : _("NO")("NO"[0]!='\0'?dcgettext (((void*)0), "NO", 5):"")); | |||
1466 | sprintf(MenuTexts[3], _("<-- Max. screen messages: %d -->")("<-- Max. screen messages: %d -->"[0]!='\0'?dcgettext ( ((void*)0), "<-- Max. screen messages: %d -->", 5):""), GameConfig.number_of_big_screen_messages); | |||
1467 | sprintf(MenuTexts[4], _("<-- Screen message lifetime: %3.1fs -->")("<-- Screen message lifetime: %3.1fs -->"[0]!='\0'?dcgettext (((void*)0), "<-- Screen message lifetime: %3.1fs -->" , 5):""), GameConfig.delay_for_big_screen_messages); | |||
1468 | strcpy(MenuTexts[5], _("Back")("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):"")); | |||
1469 | MenuTexts[6][0] = '\0'; | |||
1470 | ||||
1471 | } | |||
1472 | ||||
1473 | ||||
1474 | ||||
1475 | ||||
1476 | ||||
1477 | #define FIRST_MIS_SELECT_ITEM_POS_X(0.0) (0.0) | |||
1478 | #define FIRST_MIS_SELECT_ITEM_POS_Y(BANNER_HEIGHT + FontHeight(Menu_BFont)) (BANNER_HEIGHT + FontHeight(Menu_BFont)) | |||
1479 | ||||
1480 | /** | |||
1481 | * @return true if there is already a save game using specified name | |||
1482 | */ | |||
1483 | static int savegame_exists(const char *name) | |||
1484 | { | |||
1485 | struct dirent **eps = NULL((void*)0); | |||
1486 | int n = find_saved_games(&eps); | |||
1487 | int exists = 0; | |||
1488 | int i; | |||
1489 | for (i = 0; i < n; i++) { | |||
1490 | if (strcmp(eps[i]->d_name, name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (eps[i]->d_name) && __builtin_constant_p (name) && (__s1_len = strlen (eps[i]->d_name), __s2_len = strlen (name ), (!((size_t)(const void *)((eps[i]->d_name) + 1) - (size_t )(const void *)(eps[i]->d_name) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((name) + 1) - (size_t)( const void *)(name) == 1) || __s2_len >= 4)) ? __builtin_strcmp (eps[i]->d_name, name) : (__builtin_constant_p (eps[i]-> d_name) && ((size_t)(const void *)((eps[i]->d_name ) + 1) - (size_t)(const void *)(eps[i]->d_name) == 1) && (__s1_len = strlen (eps[i]->d_name), __s1_len < 4) ? ( __builtin_constant_p (name) && ((size_t)(const void * )((name) + 1) - (size_t)(const void *)(name) == 1) ? __builtin_strcmp (eps[i]->d_name, name) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (name); int __result = (((const unsigned char *) (const char *) (eps[i]-> d_name))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) ( eps[i]->d_name))[1] - __s2[1]); if (__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (eps[i]->d_name))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((const unsigned char *) (const char *) (eps[i]->d_name))[3] - __s2[3]); } } __result ; }))) : (__builtin_constant_p (name) && ((size_t)(const void *)((name) + 1) - (size_t)(const void *)(name) == 1) && (__s2_len = strlen (name), __s2_len < 4) ? (__builtin_constant_p (eps[i]->d_name) && ((size_t)(const void *)((eps[ i]->d_name) + 1) - (size_t)(const void *)(eps[i]->d_name ) == 1) ? __builtin_strcmp (eps[i]->d_name, name) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (eps[i]->d_name); int __result = (((const unsigned char *) (const char *) (name))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const unsigned char *) (const char *) (name))[1] - __s2[1]); if (__s2_len > 1 && __result == 0) { __result = (((const unsigned char *) (const char *) (name))[2] - __s2[2]); if (__s2_len > 2 && __result == 0) __result = (((const unsigned char * ) (const char *) (name))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (eps[i]->d_name, name)))); }) == 0) { | |||
1491 | exists = 1; | |||
1492 | break; | |||
1493 | } | |||
1494 | } | |||
1495 | for (i = 0; i <n; i++) | |||
1496 | free(eps[i]); | |||
1497 | free(eps); | |||
1498 | return exists; | |||
1499 | } | |||
1500 | ||||
1501 | /** | |||
1502 | * Prompt the user for the name of a new character. | |||
1503 | */ | |||
1504 | static char *get_new_character_name(void) | |||
1505 | { | |||
1506 | char *str; | |||
1507 | InitiateMenu("title.jpg"); | |||
1508 | ||||
1509 | // Loop until the player enters a name that does not already exist. | |||
1510 | int loop = 1; | |||
1511 | while (loop) { | |||
1512 | if (!skip_initial_menus) | |||
1513 | str = get_string(MAX_CHARACTER_NAME_LENGTH13 - 1, "title.jpg", _("\n\("\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " [0]!='\0'?dcgettext (((void*)0), "\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " , 5):"") | |||
1514 | Please enter a name\n\("\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " [0]!='\0'?dcgettext (((void*)0), "\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " , 5):"") | |||
1515 | for the new hero: \n\n\("\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " [0]!='\0'?dcgettext (((void*)0), "\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " , 5):"") | |||
1516 | ---ENTER to accept.\n\("\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " [0]!='\0'?dcgettext (((void*)0), "\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " , 5):"") | |||
1517 | ---ESCAPE to cancel.\n\n\("\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " [0]!='\0'?dcgettext (((void*)0), "\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " , 5):"") | |||
1518 | > ")("\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " [0]!='\0'?dcgettext (((void*)0), "\n Please enter a name\n for the new hero: \n\n ---ENTER to accept.\n ---ESCAPE to cancel.\n\n > " , 5):"")); | |||
1519 | else | |||
1520 | str = strdup("MapEd")(__extension__ (__builtin_constant_p ("MapEd") && ((size_t )(const void *)(("MapEd") + 1) - (size_t)(const void *)("MapEd" ) == 1) ? (((const char *) ("MapEd"))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen ("MapEd" ) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, "MapEd" , __len); __retval; })) : __strdup ("MapEd"))); | |||
1521 | ||||
1522 | // User cancelled -- abort here | |||
1523 | if (!str) | |||
1524 | break; | |||
1525 | ||||
1526 | // Parse string for illegal chars | |||
1527 | int i; | |||
1528 | for (i = 0; i < strlen(str); i++) | |||
1529 | if (!isalnum(str[i])((*__ctype_b_loc ())[(int) ((str[i]))] & (unsigned short int ) _ISalnum) && str[i] != '-') | |||
1530 | str[i] = '-'; | |||
1531 | ||||
1532 | // Check if name already exists | |||
1533 | loop = savegame_exists(str); | |||
1534 | if (loop) { | |||
1535 | alert_window(_("A character named \"%s\" already exists.\nPlease choose another name.")("A character named \"%s\" already exists.\nPlease choose another name." [0]!='\0'?dcgettext (((void*)0), "A character named \"%s\" already exists.\nPlease choose another name." , 5):""), str); | |||
1536 | free(str); | |||
1537 | } | |||
1538 | } | |||
1539 | ||||
1540 | return str; | |||
1541 | } | |||
1542 | ||||
1543 | int load_named_game(const char *name) | |||
1544 | { | |||
1545 | if (strlen(name) >= MAX_CHARACTER_NAME_LENGTH13) { | |||
1546 | error_message(__FUNCTION__, "The saved game name is too long.", NO_REPORT); | |||
1547 | return ERR-1; | |||
1548 | } | |||
1549 | ||||
1550 | if (!Me.character_name || strcmp(name, Me.character_name)__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (name) && __builtin_constant_p (Me.character_name) && (__s1_len = strlen (name), __s2_len = strlen (Me.character_name ), (!((size_t)(const void *)((name) + 1) - (size_t)(const void *)(name) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((Me.character_name) + 1) - (size_t)(const void *)(Me .character_name) == 1) || __s2_len >= 4)) ? __builtin_strcmp (name, Me.character_name) : (__builtin_constant_p (name) && ((size_t)(const void *)((name) + 1) - (size_t)(const void *) (name) == 1) && (__s1_len = strlen (name), __s1_len < 4) ? (__builtin_constant_p (Me.character_name) && (( size_t)(const void *)((Me.character_name) + 1) - (size_t)(const void *)(Me.character_name) == 1) ? __builtin_strcmp (name, Me .character_name) : (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (Me.character_name) ; int __result = (((const unsigned char *) (const char *) (name ))[0] - __s2[0]); if (__s1_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (name ))[1] - __s2[1]); if (__s1_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (name ))[2] - __s2[2]); if (__s1_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (name)) [3] - __s2[3]); } } __result; }))) : (__builtin_constant_p (Me .character_name) && ((size_t)(const void *)((Me.character_name ) + 1) - (size_t)(const void *)(Me.character_name) == 1) && (__s2_len = strlen (Me.character_name), __s2_len < 4) ? ( __builtin_constant_p (name) && ((size_t)(const void * )((name) + 1) - (size_t)(const void *)(name) == 1) ? __builtin_strcmp (name, Me.character_name) : (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (const char *) (name); int __result = (((const unsigned char *) (const char *) (Me.character_name ))[0] - __s2[0]); if (__s2_len > 0 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (Me.character_name ))[1] - __s2[1]); if (__s2_len > 1 && __result == 0 ) { __result = (((const unsigned char *) (const char *) (Me.character_name ))[2] - __s2[2]); if (__s2_len > 2 && __result == 0 ) __result = (((const unsigned char *) (const char *) (Me.character_name ))[3] - __s2[3]); } } __result; })))) : __builtin_strcmp (name , Me.character_name)))); })) { | |||
1551 | free(Me.character_name); | |||
1552 | Me.character_name = strdup(name)(__extension__ (__builtin_constant_p (name) && ((size_t )(const void *)((name) + 1) - (size_t)(const void *)(name) == 1) ? (((const char *) (name))[0] == '\0' ? (char *) calloc ( (size_t) 1, (size_t) 1) : ({ size_t __len = strlen (name) + 1 ; char *__retval = (char *) malloc (__len); if (__retval != ( (void*)0)) __retval = (char *) memcpy (__retval, name, __len) ; __retval; })) : __strdup (name))); | |||
1553 | } | |||
1554 | ||||
1555 | if (LoadGame() != OK0) | |||
1556 | return ERR-1; | |||
1557 | ||||
1558 | GetEventTriggers("events.dat"); | |||
1559 | item_held_in_hand = NULL((void*)0); | |||
1560 | return OK0; | |||
1561 | } | |||
1562 | ||||
1563 | enum { | |||
1564 | SAVEGAME_LOAD, | |||
1565 | SAVEGAME_DELETE, | |||
1566 | }; | |||
1567 | ||||
1568 | static int do_savegame_selection_and_act(int action) | |||
1569 | { | |||
1570 | char *MenuTexts[MAX_MENU_ITEMS100]; | |||
1571 | struct dirent **eps; | |||
1572 | int n; | |||
1573 | int cnt; | |||
1574 | int MenuPosition; | |||
1575 | int saveoffset = 0; | |||
1576 | char SafetyText[500]; | |||
1577 | char *menu_title = NULL((void*)0); | |||
1578 | int rtn; | |||
1579 | ||||
1580 | switch (action) { | |||
1581 | case SAVEGAME_LOAD: | |||
1582 | menu_title = LOAD_EXISTING_HERO_STRING("Your characters: "[0]!='\0'?dcgettext (((void*)0), "Your characters: " , 5):""); | |||
1583 | break; | |||
1584 | case SAVEGAME_DELETE: | |||
1585 | menu_title = DELETE_EXISTING_HERO_STRING("Select character to delete: "[0]!='\0'?dcgettext (((void*)0 ), "Select character to delete: ", 5):""); | |||
1586 | break; | |||
1587 | } | |||
1588 | ||||
1589 | InitiateMenu("title.jpg"); | |||
1590 | ||||
1591 | // We use empty strings to denote the end of any menu selection, | |||
1592 | // therefore also for the end of the list of saved characters. | |||
1593 | // | |||
1594 | for (n = 0; n < MAX_SAVED_CHARACTERS_ON_DISK7 + 1; n++) { | |||
1595 | MenuTexts[n] = ""; | |||
1596 | } | |||
1597 | ||||
1598 | n = find_saved_games(&eps); | |||
1599 | ||||
1600 | if (n > 0) { | |||
1601 | while (1) { | |||
1602 | ||||
1603 | if (saveoffset != 0) { | |||
1604 | /* Display "up" */ | |||
1605 | MenuTexts[0] = _("[up]")("[up]"[0]!='\0'?dcgettext (((void*)0), "[up]", 5):""); | |||
1606 | } else { | |||
1607 | MenuTexts[0] = " "; | |||
1608 | } | |||
1609 | ||||
1610 | for (cnt = 1; cnt + saveoffset - 1 < n && cnt < MAX_SAVED_CHARACTERS_ON_DISK7; cnt++) { | |||
1611 | MenuTexts[cnt] = eps[cnt + saveoffset - 1]->d_name; | |||
1612 | } | |||
1613 | ||||
1614 | if (cnt >= 7) { | |||
1615 | /* Display "down" */ | |||
1616 | MenuTexts[cnt++] = _("[down]")("[down]"[0]!='\0'?dcgettext (((void*)0), "[down]", 5):""); | |||
1617 | } else | |||
1618 | MenuTexts[cnt++] = " "; | |||
1619 | ||||
1620 | MenuTexts[cnt] = _("Back")("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""); | |||
1621 | MenuTexts[cnt + 1] = ""; | |||
1622 | ||||
1623 | MenuPosition = DoMenuSelection(menu_title, MenuTexts, 1, "title.jpg", NULL((void*)0)); | |||
1624 | ||||
1625 | if (MenuPosition == (-1) || MenuPosition == cnt + 1) { | |||
1626 | for (cnt = 0; cnt < n; cnt++) | |||
1627 | free(eps[cnt]); | |||
1628 | free(eps); | |||
1629 | return FALSE(0); | |||
1630 | } | |||
1631 | if (MenuPosition == cnt) { | |||
1632 | if (cnt + saveoffset - 1 < n) | |||
1633 | saveoffset++; | |||
1634 | } else if (MenuPosition == 1) { | |||
1635 | if (saveoffset > 0) | |||
1636 | saveoffset--; | |||
1637 | } else | |||
1638 | break; | |||
1639 | } | |||
1640 | ||||
1641 | free(Me.character_name); | |||
1642 | Me.character_name = strdup(MenuTexts[MenuPosition - 1])(__extension__ (__builtin_constant_p (MenuTexts[MenuPosition - 1]) && ((size_t)(const void *)((MenuTexts[MenuPosition - 1]) + 1) - (size_t)(const void *)(MenuTexts[MenuPosition - 1]) == 1) ? (((const char *) (MenuTexts[MenuPosition - 1]))[ 0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (MenuTexts[MenuPosition - 1]) + 1; char *__retval = (char *) malloc (__len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, MenuTexts[MenuPosition - 1], __len ); __retval; })) : __strdup (MenuTexts[MenuPosition - 1]))); | |||
1643 | ||||
1644 | for (cnt = 0; cnt < n; cnt++) | |||
1645 | free(eps[cnt]); | |||
1646 | free(eps); | |||
1647 | ||||
1648 | goto do_action; | |||
1649 | } else { | |||
1650 | ||||
1651 | MenuTexts[0] = _("Back")("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""); | |||
1652 | MenuTexts[1] = ""; | |||
1653 | ||||
1654 | DoMenuSelection(_("\n\nNo saved games found!")("\n\nNo saved games found!"[0]!='\0'?dcgettext (((void*)0), "\n\nNo saved games found!" , 5):""), MenuTexts, 1, "title.jpg", NULL((void*)0)); | |||
1655 | ||||
1656 | return FALSE(0); | |||
1657 | } | |||
1658 | ||||
1659 | return FALSE(0); | |||
1660 | ||||
1661 | do_action: | |||
1662 | rtn = FALSE(0); | |||
1663 | switch (action) { | |||
1664 | case SAVEGAME_LOAD: | |||
1665 | if (load_named_game(Me.character_name) == OK0) { | |||
1666 | rtn = TRUE(1); | |||
1667 | } else { | |||
1668 | rtn = FALSE(0); | |||
1669 | } | |||
1670 | break; | |||
1671 | case SAVEGAME_DELETE: | |||
1672 | ||||
1673 | // We do a final safety check to ask for confirmation. | |||
1674 | MenuTexts[0] = _("Sure!")("Sure!"[0]!='\0'?dcgettext (((void*)0), "Sure!", 5):""); | |||
1675 | MenuTexts[1] = _("Back")("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""); | |||
1676 | MenuTexts[2] = ""; | |||
1677 | sprintf(SafetyText, _("Really delete hero '%s'?")("Really delete hero '%s'?"[0]!='\0'?dcgettext (((void*)0), "Really delete hero '%s'?" , 5):""), Me.character_name); | |||
1678 | int FinalDecision = DoMenuSelection(SafetyText, MenuTexts, 1, "title.jpg", NULL((void*)0)); | |||
1679 | ||||
1680 | if (FinalDecision == 1) | |||
1681 | DeleteGame(); | |||
1682 | rtn = TRUE(1); | |||
1683 | break; | |||
1684 | } | |||
1685 | ||||
1686 | our_SDL_flip_wrapper(); | |||
1687 | return rtn; | |||
1688 | } | |||
1689 | ||||
1690 | /** | |||
1691 | * Load a savegame | |||
1692 | */ | |||
1693 | static int Load_Existing_Hero_Menu(void) | |||
1694 | { | |||
1695 | return do_savegame_selection_and_act(SAVEGAME_LOAD); | |||
1696 | } | |||
1697 | ||||
1698 | /** | |||
1699 | * Delete a savegame | |||
1700 | */ | |||
1701 | static int Delete_Existing_Hero_Menu(void) | |||
1702 | { | |||
1703 | return do_savegame_selection_and_act(SAVEGAME_DELETE); | |||
1704 | } | |||
1705 | ||||
1706 | /** | |||
1707 | * This function provides the single player menu. It offers to start a | |||
1708 | * new hero, to load an old one and to go back. | |||
1709 | * | |||
1710 | * The return value indicates, whether the calling function (StartupMenu) | |||
1711 | * can really enter the new game after this function (cause a new player | |||
1712 | * has been set up properly) or not, cause no player is specified yet and | |||
1713 | * nothing is known. | |||
1714 | * | |||
1715 | */ | |||
1716 | int Single_Player_Menu(void) | |||
1717 | { | |||
1718 | int can_continue = FALSE(0); | |||
1719 | int MenuPosition = 1; | |||
1720 | char *MenuTexts[MAX_MENU_ITEMS100]; | |||
1721 | char *char_name = NULL((void*)0); | |||
1722 | ||||
1723 | enum { | |||
1724 | NEW_HERO_POSITION = 1, | |||
1725 | LOAD_EXISTING_HERO_POSITION, | |||
1726 | DELETE_EXISTING_HERO_POSITION, | |||
1727 | BACK_POSITION | |||
1728 | }; | |||
1729 | ||||
1730 | MenuTexts[0] = _("New Hero")("New Hero"[0]!='\0'?dcgettext (((void*)0), "New Hero", 5):"" ); | |||
1731 | MenuTexts[1] = _("Load existing Hero")("Load existing Hero"[0]!='\0'?dcgettext (((void*)0), "Load existing Hero" , 5):""); | |||
1732 | MenuTexts[2] = _("Delete existing Hero")("Delete existing Hero"[0]!='\0'?dcgettext (((void*)0), "Delete existing Hero" , 5):""); | |||
1733 | MenuTexts[3] = _("Back")("Back"[0]!='\0'?dcgettext (((void*)0), "Back", 5):""); | |||
1734 | MenuTexts[4] = ""; | |||
1735 | ||||
1736 | while (!can_continue) { | |||
| ||||
1737 | ||||
1738 | if (!skip_initial_menus) | |||
1739 | MenuPosition = DoMenuSelection("", MenuTexts, 1, "title.jpg", Menu_BFont); | |||
1740 | else | |||
1741 | MenuPosition = NEW_HERO_POSITION; | |||
1742 | ||||
1743 | switch (MenuPosition) { | |||
1744 | case NEW_HERO_POSITION: | |||
1745 | while (EnterPressed() || SpacePressed()) ; | |||
1746 | char_name = get_new_character_name(); | |||
1747 | if (char_name && strlen(char_name)) { | |||
1748 | char fp[PATH_MAX4096]; | |||
1749 | find_file("levels.dat", MAP_DIR, fp, PLEASE_INFORM | IS_FATAL); | |||
1750 | LoadShip(fp, 0); | |||
1751 | PrepareStartOfNewCharacter("NewTuxStartGameSquare"); | |||
1752 | free(Me.character_name); | |||
1753 | Me.character_name = strdup(char_name)(__extension__ (__builtin_constant_p (char_name) && ( (size_t)(const void *)((char_name) + 1) - (size_t)(const void *)(char_name) == 1) ? (((const char *) (char_name))[0] == '\0' ? (char *) calloc ((size_t) 1, (size_t) 1) : ({ size_t __len = strlen (char_name) + 1; char *__retval = (char *) malloc ( __len); if (__retval != ((void*)0)) __retval = (char *) memcpy (__retval, char_name, __len); __retval; })) : __strdup (char_name ))); | |||
1754 | can_continue = TRUE(1); | |||
1755 | free(char_name); | |||
1756 | } | |||
1757 | break; | |||
1758 | ||||
1759 | case LOAD_EXISTING_HERO_POSITION: | |||
1760 | while (EnterPressed() || SpacePressed()) ; | |||
1761 | ||||
1762 | if (Load_Existing_Hero_Menu() == TRUE(1)) | |||
1763 | can_continue = TRUE(1); | |||
1764 | break; | |||
1765 | ||||
1766 | case DELETE_EXISTING_HERO_POSITION: | |||
1767 | while (EnterPressed() || SpacePressed()) ; | |||
1768 | Delete_Existing_Hero_Menu(); | |||
1769 | break; | |||
1770 | ||||
1771 | case (-1): | |||
1772 | case BACK_POSITION: | |||
1773 | while (EnterPressed() || SpacePressed() || EscapePressed()) ; | |||
| ||||
1774 | return FALSE(0); | |||
1775 | break; | |||
1776 | default: | |||
1777 | break; | |||
1778 | } | |||
1779 | } | |||
1780 | return (TRUE(1)); | |||
1781 | } | |||
1782 | ||||
1783 | #undef _menu_c |