Debian Codegraph @

src/menu.cpp

raw symbols SCIP
1 #cxx . . $ `<file>/src/menu.cpp`/include <SDL.h>
2 #include "files.h"cxx . . $ `<file>/src/files.h`/
3 #include "menu.h"cxx . . $ `<file>/src/menu.h`/
4 #include "draw.h"cxx . . $ `<file>/src/draw.h`/
5 #include "dfont.h"cxx . . $ `<file>/src/dfont.h`/
6
7
8 SDL_Surface *menu_screencxx . . $ menu_screen.;
9
10 int Main_Menucxx . . $ Main_Menu(8294d564b9200189).(int *mission_number, SDL_Surface *screen)
11 {
12 SDL_Rect dest;
13 int command = 0;
14 int selected_button = BUTTON_PLAYcxx . . $ `src/menu.h:7:9`!;
15 int action;
16 Uint32cxx . . $ Uint32# menu_colour = SDL_MapRGB(screen->format, 0, 200,0);
17 menu_screencxx . . $ menu_screen. = screen;
18
19 dest.x = 400; dest.y = 0; dest.w = 624; dest.h = 768;
20 Display_Missioncxx . . $ Display_Mission(7864480464b09eea).(*mission_number);
21 while (! command)
22 {
23 Draw_Main_Menucxx . . $ Draw_Main_Menu(b223e862534b1804).(selected_button, menu_colour);
24 SDL_UpdateRects(menu_screencxx . . $ menu_screen., 1, &dest);
25 action = Menu_Inputcxx . . $ Menu_Input(b126dc7c1de90089).();
26 if (action == BUTTON_ACTIVATEcxx . . $ `src/menu.h:13:9`!)
27 action = selected_button;
28 switch (action)
29 {
30 case BUTTON_PLAYcxx . . $ `src/menu.h:7:9`!: command = ACTION_MISSIONcxx . . $ `src/menu.h:5:9`!; break;
31 case BUTTON_QUITcxx . . $ `src/menu.h:8:9`!: command = ACTION_QUITcxx . . $ `src/menu.h:4:9`!; break;
32 case BUTTON_PREV_MISSIONcxx . . $ `src/menu.h:9:9`!:
33 selected_button = BUTTON_PREV_MISSIONcxx . . $ `src/menu.h:9:9`!;
34 *mission_number = New_Missioncxx . . $ New_Mission(9b79fb6aee4c0440).(MISSION_PREVIOUScxx . . $ `src/menu.h:15:9`!, *mission_number);
35 Display_Missioncxx . . $ Display_Mission(7864480464b09eea).(*mission_number);
36 break;
37 case BUTTON_NEXT_MISSIONcxx . . $ `src/menu.h:10:9`!:
38 selected_button = BUTTON_NEXT_MISSIONcxx . . $ `src/menu.h:10:9`!;
39 *mission_number = New_Missioncxx . . $ New_Mission(9b79fb6aee4c0440).(MISSION_NEXTcxx . . $ `src/menu.h:16:9`!, *mission_number);
40 Display_Missioncxx . . $ Display_Mission(7864480464b09eea).(*mission_number);
41 break;
42 case BUTTON_MOVE_UPcxx . . $ `src/menu.h:11:9`!:
43 selected_button--;
44 if (selected_button < BUTTON_PLAYcxx . . $ `src/menu.h:7:9`!)
45 selected_button = BUTTON_NEXT_MISSIONcxx . . $ `src/menu.h:10:9`!;
46 break;
47 case BUTTON_MOVE_DOWNcxx . . $ `src/menu.h:12:9`!:
48 selected_button++;
49 if (selected_button > BUTTON_NEXT_MISSIONcxx . . $ `src/menu.h:10:9`!)
50 selected_button = BUTTON_PLAYcxx . . $ `src/menu.h:7:9`!;
51 break;
52
53 }
54 SDL_Delay(100);
55 }
56
57 #ifdef DEBUG
58 printf("Returning menu command: %d\n", command);
59 #endif
60 return command;
61 }
62
63
64
65 int New_Missioncxx . . $ New_Mission(9b79fb6aee4c0440).(int next_prev, int old_mission)
66 {
67 FILE *mission_file;
68 char *mission_path;
69 char mission_filename[256];
70 int new_mission;
71
72 if (next_prev == MISSION_PREVIOUScxx . . $ `src/menu.h:15:9`!)
73 {
74 new_mission = old_mission - 1;
75 if (new_mission < 0)
76 new_mission = 0;
77 }
78 else
79 {
80 new_mission = old_mission + 1;
81 }
82
83 #ifndef WIN32
84 snprintf(mission_filename, 256, "data/mission%d.dat", new_mission);
85 #else
86 sprintf(mission_filename, "data/mission%d.dat", new_mission);
87 #endif
88 mission_path = Find_Data_Filecxx . . $ Find_Data_File(7a9722d75b371431).(mission_filename);
89 mission_file = fopen(mission_path, "r");
90 if ( (mission_path) && (mission_path != mission_filename) )
91 freecxx . . $ free(bd21765a0afc8e3c).(mission_path);
92
93 // found mission file, return the new number
94 if (mission_file)
95 {
96 fclose(mission_file);
97 return new_mission;
98 }
99
100 // we do not have a matching mission file, return the last good one
101 return old_mission;
102 }
103
104
105
106 int Display_Missioncxx . . $ Display_Mission(7864480464b09eea).(int mission_number)
107 {
108 char *full_path, filename[256];
109 FILE *mission_file;
110 char line[256];
111 int y = 610;
112 DFontcxx . . $ DFont# my_fontcxx . . $ DFont#DFont(d0489a02ea06dfc6).("images/font.png", "data/font.dat");
113 Uint32cxx . . $ Uint32# menu_background = SDL_MapRGB(menu_screencxx . . $ menu_screen.->format, 0, 0, 0);
114
115 #ifndef WIN32
116 snprintf(filename, 256, "data/orders%d.txt", mission_number);
117 #else
118 sprintf(filename, "data/orders%d.txt", mission_number);
119 #endif
120 full_path = Find_Data_Filecxx . . $ Find_Data_File(7a9722d75b371431).(filename);
121 mission_file = fopen(full_path, "r");
122 if ( (full_path) && (full_path != filename) )
123 freecxx . . $ free(bd21765a0afc8e3c).(full_path);
124 if (mission_file)
125 {
126 FillRectanglecxx . . $ FillRectangle(1738f3ac1892ed0c).(menu_screencxx . . $ menu_screen., 440, 610, 980, 730, menu_background);
127 full_path = fgets(line, 256, mission_file);
128 while (full_path)
129 {
130 my_font.PutStringcxx . . $ DFont#PutString(dae77c54ebf0dad5).(menu_screencxx . . $ menu_screen., 440, y, line);
131 full_path = fgets(line, 256, mission_file);
132 y += 12;
133 }
134 fclose(mission_file);
135 }
136 return TRUEcxx . . $ `src/menu.h:19:9`!;
137 }
138
139
140
141 int Draw_Main_Menucxx . . $ Draw_Main_Menu(b223e862534b1804).(int selected, Uint32cxx . . $ Uint32# menu_colour)
142 {
143 Uint32cxx . . $ Uint32# menu_background = SDL_MapRGB(menu_screencxx . . $ menu_screen.->format, 0, 0, 0);
144 // wipe everything first
145 DrawRectanglecxx . . $ DrawRectangle(1738f3ac1892ed0c).(menu_screencxx . . $ menu_screen., 540, 160, 885, 235, menu_background);
146 DrawRectanglecxx . . $ DrawRectangle(1738f3ac1892ed0c).(menu_screencxx . . $ menu_screen., 540, 260, 885, 335, menu_background);
147 FillCirclecxx . . $ FillCircle(23d17e51af626352).(menu_screencxx . . $ menu_screen., 465, 565, 5, menu_background);
148 FillCirclecxx . . $ FillCircle(23d17e51af626352).(menu_screencxx . . $ menu_screen., 940, 565, 5, menu_background);
149
150 switch (selected)
151 {
152 case BUTTON_PLAYcxx . . $ `src/menu.h:7:9`!:
153 DrawRectanglecxx . . $ DrawRectangle(1738f3ac1892ed0c).(menu_screencxx . . $ menu_screen., 540, 160, 885, 235, menu_colour);
154 break;
155 case BUTTON_QUITcxx . . $ `src/menu.h:8:9`!:
156 DrawRectanglecxx . . $ DrawRectangle(1738f3ac1892ed0c).(menu_screencxx . . $ menu_screen., 540, 260, 885, 335, menu_colour);
157 break;
158 case BUTTON_PREV_MISSIONcxx . . $ `src/menu.h:9:9`!:
159 FillCirclecxx . . $ FillCircle(23d17e51af626352).(menu_screencxx . . $ menu_screen., 465, 565, 5, menu_colour);
160 break;
161 case BUTTON_NEXT_MISSIONcxx . . $ `src/menu.h:10:9`!:
162 FillCirclecxx . . $ FillCircle(23d17e51af626352).(menu_screencxx . . $ menu_screen., 940, 565, 5, menu_colour);
163 break;
164
165 }
166 return TRUEcxx . . $ `src/menu.h:19:9`!;
167 }
168
169
170
171 int Menu_Inputcxx . . $ Menu_Input(b126dc7c1de90089).()
172 {
173 int action = 0;
174 SDL_Event event;
175 int mousex, mousey;
176
177 #ifdef DEBUG
178 printf("About to check for event.\n");
179 #endif
180 while ( SDL_PollEvent(&event) )
181 {
182 #ifdef DEBUG
183 printf("Got event.\n");
184 #endif
185 switch (event.type)
186 {
187 case SDL_MOUSEBUTTONDOWN:
188 mousex = event.button.x;
189 mousey = event.button.y;
190 if ( (mousex > 540) && (mousex < 885) &&
191 (mousey > 160) && (mousey < 235) )
192 action = BUTTON_PLAYcxx . . $ `src/menu.h:7:9`!;
193 else if ( (mousex > 540) && (mousex < 885) &&
194 (mousey > 260) && (mousey < 335) )
195 action = BUTTON_QUITcxx . . $ `src/menu.h:8:9`!;
196 else if ( (mousex > 440) && (mousex < 475) &&
197 (mousey > 550) && (mousey < 580) )
198 action = BUTTON_PREV_MISSIONcxx . . $ `src/menu.h:9:9`!;
199 else if ( (mousex > 920) && (mousex < 960) &&
200 (mousey > 550) && (mousey < 580) )
201 action = BUTTON_NEXT_MISSIONcxx . . $ `src/menu.h:10:9`!;
202
203 break; // end of mouse stuff
204 case SDL_KEYDOWN:
205 if (event.key.keysym.sym == SDLK_UPcxx . . $ SDLK_UP.)
206 action = BUTTON_MOVE_UPcxx . . $ `src/menu.h:11:9`!;
207 else if (event.key.keysym.sym == SDLK_DOWNcxx . . $ SDLK_DOWN.)
208 action = BUTTON_MOVE_DOWNcxx . . $ `src/menu.h:12:9`!;
209 else if (event.key.keysym.sym == SDLK_ESCAPEcxx . . $ SDLK_ESCAPE.)
210 action = BUTTON_QUITcxx . . $ `src/menu.h:8:9`!;
211 else if ( (event.key.keysym.sym == SDLK_SPACEcxx . . $ SDLK_SPACE.) ||
212 (event.key.keysym.sym == SDLK_RETURNcxx . . $ SDLK_RETURN.) )
213 action = BUTTON_ACTIVATEcxx . . $ `src/menu.h:13:9`!;
214 break;
215 } // end of switch
216 } // end of which event
217
218 #ifdef DEBUG
219 printf("Returning action: %d\n", action);
220 #endif
221 return action;
222 }
223