]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/hub.cpp
Import of version 1.14 minus music and sounds.
[quix0rs-blobwars.git] / src / hub.cpp
1 /*
2 Copyright (C) 2004 Parallel Realities
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "hub.h"
22
23 void createStatsPanel(int page)
24 {
25         SDL_Surface *image = graphics.getSprite("infoPanel", true)->image[0];
26
27         graphics.drawRect(1, 1, image->w - 2, image->h - 2, graphics.black, graphics.white, image);
28
29         char string[100];
30         int x1 = 80;
31         int x2 = 270;
32         int x3 = 300;
33         int y = 15;
34
35         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
36
37         graphics.drawString(_("Metal Blob Solid : Statistics"), 200, y, true, image);
38         y += 10;
39         
40         Sprite *arrows = graphics.getSprite("HubArrows", true);
41
42         switch (page)
43         {
44                 case 0:
45                         graphics.drawString(_("Skill Level:"), x1, y += 20, false, image);
46                         sprintf(string, "%s", _(skill[game.skill]));
47                         graphics.drawString(string, x2, y, false, image);
48
49                         graphics.drawString(_("Score:"), x1, y += 20, false, image);
50                         sprintf(string, "%d", game.score);
51                         graphics.drawString(string, x2, y, false, image);
52
53                         graphics.drawString(_("MIAs Saved:"), x1, y += 20, false, image);
54                         sprintf(string, "%d", game.totalMIAsRescued);
55                         graphics.drawString(string, x2, y, false, image);
56
57                         graphics.drawString(_("Objectives Completed:"), x1, y += 20, false, image);
58                         sprintf(string, "%d", game.totalObjectivesCompleted);
59                         graphics.drawString(string, x2, y, false, image);
60
61                         // Don't do this on Extreme or it will always say 100%
62                         if (game.skill < 3)
63                         {
64                                 graphics.drawString(_("Percentage Complete:"), x1, y += 20, false, image);
65                                 sprintf(string, "%d%%", gameData.getPercentageComplete());
66                                 graphics.drawString(string, x2, y, false, image);
67                         }
68
69                         sprintf(string, "%s", _("Total Game Time"));
70                         sprintf(string, "%s - %.2d:%.2d:%.2d", string, game.totalHours, game.totalMinutes, game.totalSeconds);
71                         graphics.drawString(string, 200, y += 110, true, image);
72
73                         break;
74
75                 case 1:
76
77                         graphics.drawString(_("Enemies Defeated:"), x1, y += 20, false, image);
78                         sprintf(string, "%d", game.totalEnemiesDefeated);
79                         graphics.drawString(string, x2, y, false, image);
80
81                         graphics.drawString(_("Items Collected:"), x1, y += 20, false, image);
82                         sprintf(string, "%d", game.totalItemsCollected);
83                         graphics.drawString(string, x2, y, false, image);
84
85                         graphics.drawString(_("Bonuses Picked Up:"), x1, y += 20, false, image);
86                         sprintf(string, "%d", game.totalBonusesCollected);
87                         graphics.drawString(string, x2, y, false, image);
88
89                         graphics.drawString(_("Best Combo:"), x1, y += 20, false, image);
90                         sprintf(string, _("%d Hits"), game.maxComboHits);
91                         graphics.drawString(string, x2, y, false, image);
92                         
93                         graphics.drawString(_("Missions Started:"), x1, y += 20, false, image);
94                         sprintf(string, "%d", game.levelsStarted);
95                         graphics.drawString(string, x2, y, false, image);
96
97                         graphics.drawString(_("Continues Used:"), x1, y += 20, false, image);
98                         sprintf(string, "%d", game.continuesUsed);
99                         graphics.drawString(string, x2, y, false, image);
100                         
101                         if ((game.continuesUsed > 0) && (game.levelsStarted > 0))
102                         {
103                                 graphics.drawString(_("Average Continue Usage:"), x1, y += 20, false, image);
104                                 sprintf(string, "%d", (game.continuesUsed / game.levelsStarted));
105                                 graphics.drawString(string, x2, y, false, image);
106                         }
107
108                         graphics.drawString(_("Escapes Used:"), x1, y += 20, false, image);
109                         sprintf(string, "%d", game.escapes);
110                         graphics.drawString(string, x2, y, false, image);
111
112                         break;
113
114                 case 2:
115                 
116                         x1 = 20;
117                         x2 = 170;
118                         x3 = 300;
119
120                         graphics.drawString(_("Weapon"), x1, y += 20, false, image);
121                         graphics.drawString(_("Ammo Used"), x2, y, false, image);
122                         graphics.drawString(_("Accuracy"), x3, y, false, image);
123
124                         graphics.drawString(_("Pistol"), x1, y += 30, false, image);
125                         sprintf(string, "%d", game.bulletsFired[WP_PISTOL]);
126                         graphics.drawString(string, x2, y, false, image);
127                         sprintf(string, "%d%%", game.getWeaponAccuracy(WP_PISTOL));
128                         graphics.drawString(string, x3, y, false, image);
129
130                         graphics.drawString(_("Machine Gun"), x1, y += 20, false, image);
131                         sprintf(string, "%d", game.bulletsFired[WP_MACHINEGUN]);
132                         graphics.drawString(string, x2, y, false, image);
133                         sprintf(string, "%d%%", game.getWeaponAccuracy(WP_MACHINEGUN));
134                         graphics.drawString(string, x3, y, false, image);
135
136                         graphics.drawString(_("Laser Cannon"), x1, y += 20, false, image);
137                         sprintf(string, "%d", game.bulletsFired[WP_LASER]);
138                         graphics.drawString(string, x2, y, false, image);
139                         sprintf(string, "%d%%", game.getWeaponAccuracy(WP_LASER));
140                         graphics.drawString(string, x3, y, false, image);
141                         
142                         graphics.drawString(_("Grenades"), x1, y += 20, false, image);
143                         sprintf(string, "%d", game.bulletsFired[WP_GRENADES]);
144                         graphics.drawString(string, x2, y, false, image);
145                         sprintf(string, "%d%%", game.getWeaponAccuracy(WP_GRENADES));
146                         graphics.drawString(string, x3, y, false, image);
147
148                         graphics.drawString(_("Spread Gun"), x1, y += 20, false, image);
149                         sprintf(string, "%d", game.bulletsFired[WP_SPREAD]);
150                         graphics.drawString(string, x2, y, false, image);
151                         sprintf(string, "%d%%", game.getWeaponAccuracy(WP_SPREAD));
152                         graphics.drawString(string, x3, y, false, image);
153                         
154                         graphics.drawString(_("Total"), x1, y += 30, false, image);
155                         sprintf(string, "%d", game.getTotalBulletsFired());
156                         graphics.drawString(string, x2, y, false, image);
157                         sprintf(string, "%d%%", game.getTotalAccuracy());
158                         graphics.drawString(string, x3, y, false, image);
159
160                         sprintf(string, "%s - %s", _("Most Used Weapon"), _(weapon[game.getMostUsedWeapon()].name));
161                         graphics.drawString(string, 200, y += 50, true, image);
162
163                         break;
164         }
165
166         graphics.blit(arrows->image[0], 150, 260, image, false);
167         graphics.blit(arrows->image[2], 200, 260, image, false);
168
169         if (page == 0)
170                 graphics.blit(arrows->image[1], 150, 260, image, false);
171
172         if (page == 2)
173                 graphics.blit(arrows->image[3], 200, 260, image, false);
174 }
175
176 void loadLevelBrief(const char *levelName)
177 {
178         char briefLine[1024];
179
180         if (!engine.loadData(_("data/levelBrief")))
181         {
182                 graphics.showErrorAndExit("Couldn't load mission briefing file (%s)", _("data/levelBrief"));
183         }
184
185         char *line = strtok((char*)engine.dataBuffer, "\n");
186         bool collectData = false;
187         SDL_Surface *image = graphics.getSprite("infoPanel", true)->image[0];
188
189         int i = 0 ;
190
191         graphics.clearChatString();
192
193         while (true)
194         {
195                 if (collectData)
196                 {
197                         sscanf(line, "%[^\n\r]", briefLine);
198
199                         if (strcmp(briefLine, "@EOF@") == 0)
200                                 break;
201
202                         if (line[0] == '[')
203                                 break;
204
205                         graphics.createChatString(line);
206                 }
207                 else
208                 {
209                         if (line[0] == '[')
210                         {
211                                 sscanf(line, "%*c %[^]]", briefLine);
212                                 if (strcmp(briefLine, levelName) == 0)
213                                         collectData = true;
214                         }
215                 }
216
217                 line = strtok(NULL, "\n");
218                 if (line == NULL)
219                         break;
220
221                 i++;
222
223                 // sanity check!
224                 if (i == 10000)
225                         break;
226         }
227         
228         graphics.drawChatString(image, 40);
229 }
230
231 void createObjectivesPanel(const char *levelName)
232 {
233         SDL_Surface *image = graphics.getSprite("infoPanel", true)->image[0];
234
235         Data *data = (Data*)gameData.dataList.getHead();
236
237         bool found = false;
238
239         graphics.drawRect(1, 1, image->w - 2, image->h - 2, graphics.black, graphics.white, image);
240
241         char string[100];
242         char levelMIAKey[100];
243         int x1 = 60;
244         int x2 = 260;
245         int y = 15;
246         
247         sprintf(levelMIAKey, "%s MIAs", levelName);
248
249         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
250
251         sprintf(string, _("Information for %s"), _(levelName));
252         graphics.drawString(string, 200, y, true, image);
253         y += 10;
254
255         while (data->next != NULL)
256         {
257                 data = (Data*)data->next;
258
259                 if ((strcmp(data->key, levelName) == 0) || (strstr(data->key, levelMIAKey)))
260                 {
261                         found = true;
262
263                         if (strstr(data->key, "MIAs"))
264                         {
265                                 // if it says 0 / 0 don't bother...
266                                 if (strcmp(data->value, "0 / 0"))
267                                 {
268                                         graphics.drawString(_("MIAs Rescued"), x1, y += 20, false, image);
269                                         sprintf(string, "%d / %d", data->current, data->target);
270                                         (data->isComplete()) ? graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00) : graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
271                                         graphics.drawString(string, x2, y, false, image);
272                                 }
273                         }
274                         else if (!strstr(data->value, "MIA_"))
275                         {
276                                 if ((game.skill < 3) &&  (strstr(data->value, "L.R.T.S.")) && (!gameData.completedWorld))
277                                 {
278                                         graphics.drawString(_("???? ???????? ????"), x1, y += 20, false, image);
279                                 }
280                                 else
281                                 {
282                                         strcpy(string, _(data->value));
283                                         
284                                         if (strlen(string) >= 25)
285                                         {
286                                                 int cut_char = 25;
287                                                 // don't break unicode characters
288                                                 while (((string[cut_char] >> 6) & 3) == 2)
289                                                 {
290                                                         cut_char--;
291                                                 }
292
293                                                 string[cut_char++] = '.';
294                                                 string[cut_char++] = '.';
295                                                 string[cut_char++] = '.';
296                                                 string[cut_char] = '\0';
297                                         }
298                                         
299                                         graphics.drawString(string, x1, y += 20, false, image);
300                                 }
301                                 
302                                 if (data->target == 1)
303                                 {
304                                         sprintf(string, "%s", (data->isComplete()) ? _("Completed") : _("Incomplete"));
305                                 }
306                                 else
307                                 {
308                                         sprintf(string, "%d / %d", data->current, data->target);
309                                 }
310                                 
311                                 (data->isComplete()) ? graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00) : graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
312                                 graphics.drawString(string, x2, y, false, image);
313                         }
314                 }
315
316                 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
317         }
318
319         if (!found)
320                 loadLevelBrief(levelName);
321 }
322
323 void createMIAPanel(int start, int max)
324 {
325         char string[100];
326         char name[100];
327         int x1 = 20;
328         int x2 = 130;
329         int x3 = 310;
330         int y = 15;
331
332         int current = 0;
333         int end = 0;
334
335         SDL_Surface *image = graphics.getSprite("infoPanel", true)->image[0];
336
337         Data *data = (Data*)gameData.dataList.getHead();
338
339         graphics.drawRect(1, 1, image->w - 2, image->h - 2, graphics.black, graphics.white, image);
340
341         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
342
343         graphics.drawString(_("MIA Statistics"), 200, y, true, image);
344
345         graphics.drawString(_("Name"), x1, y += 20, false, image);
346         graphics.drawString(_("Location"), x2, y, false, image);
347         graphics.drawString(_("Status"), x3, y, false, image);
348
349         y += 10;
350
351         while (data->next != NULL)
352         {
353                 data = (Data*)data->next;
354
355                 if (strstr(data->value, "MIA_"))
356                 {
357                         if (current < start)
358                         {
359                                 current++;
360                                 continue;
361                         }
362
363                         sprintf(name, "%s", data->value);
364                         strtok(name, "_");
365
366                         sprintf(string, "%s", strtok(NULL, "_"));
367                         graphics.drawString(string, x1, y += 20, false, image);
368
369                         graphics.drawString(_(data->key), x2, y, false, image);
370
371                         if (data->isComplete())
372                         {
373                                 sprintf(string, "%s", _("Found"));
374                                 graphics.setFontColor(0x00, 0xff, 0x00, 0x00, 0x00, 0x00);
375                         }
376                         else
377                         {
378                                 sprintf(string, "%s", _("Missing"));
379                                 graphics.setFontColor(0xff, 0x00, 0x00, 0x00, 0x00, 0x00);
380                         }
381
382                         graphics.drawString(string, x3, y, false, image);
383
384                         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
385
386                         end++;
387
388                         if (end == 9)
389                                 break;
390                 }
391         }
392
393         Sprite *arrows = graphics.getSprite("HubArrows", true);
394
395         if (start > 0)
396                 graphics.blit(arrows->image[0], 150, 260, image, false);
397         else
398                 graphics.blit(arrows->image[1], 150, 260, image, false);
399
400         if ((end == 9) && (current + 9 < max))
401                 graphics.blit(arrows->image[2], 200, 260, image, false);
402         else
403                 graphics.blit(arrows->image[3], 200, 260, image, false);
404 }
405
406 bool requirementMet(const char *requiredLevel)
407 {
408         if (engine.cheatLevels)
409         {
410                 return true;
411         }
412
413         if (strcmp(requiredLevel, "@none@") == 0)
414         {
415                 return true;
416         }
417
418         if (strstr(requiredLevel, "Stages"))
419         {
420                 int stages = 0;
421                 sscanf(requiredLevel, "%*s %d", &stages);
422
423                 if (game.stagesCleared >= stages)
424                 {
425                         return true;
426                 }
427         }
428
429         return gameData.requiredLevelCleared(requiredLevel);
430 }
431
432 int doHub()
433 {
434         SDL_FillRect(graphics.screen, NULL, graphics.black);
435         graphics.delay(1000);
436         
437         graphics.free();
438         audio.free();
439
440         graphics.loadBackground("gfx/main/worldMap.jpg");
441         audio.loadMusic("music/forAFriend.mod");
442         
443         graphics.quickSprite("cheatHeader", graphics.loadImage("gfx/main/cheats.png"));
444         graphics.quickSprite("optionsHeader", graphics.loadImage("gfx/main/options.png"));
445         graphics.quickSprite("keyHeader", graphics.loadImage("gfx/main/keyConfig.png"));
446         graphics.quickSprite("joystickHeader", graphics.loadImage("gfx/main/joystickConfig.png"));
447         graphics.quickSprite("optionsBackground", graphics.loadImage("gfx/main/optionsBackground.png"));
448
449         char string[80];
450
451         Sprite *cursor = graphics.addSprite("Cursor");
452         for (int i = 0 ; i < 6 ; i++)
453         {
454                 sprintf(string, "gfx/main/cursor%d.png", i + 1);
455                 cursor->setFrame(i, graphics.loadImage(string), 10);
456         }
457
458         Sprite *newTarget = graphics.addSprite("NewTarget");
459         Sprite *visitedTarget = graphics.addSprite("VisitedTarget");
460         
461         for (int i = 0 ; i < 5 ; i++)
462         {
463                 sprintf(string, "gfx/sprites/miaSignal%d.png", i + 1);
464                 
465                 newTarget->setFrame(i, graphics.loadImage(string, -60, 0, 0), 15);
466                 visitedTarget->setFrame(i, graphics.loadImage(string, 0, 0, 0), 15);
467         }
468
469         Sprite *hubIcons = graphics.addSprite("HubIcons");
470         for (int i = 0 ; i < 6 ; i++)
471         {
472                 sprintf(string, "gfx/main/hubIcon%d.png", i + 1);
473                 hubIcons->setFrame(i, graphics.loadImage(string), 60);
474         }
475
476         SDL_Surface *infoPanel = graphics.quickSprite("infoPanel", graphics.createSurface(400, 300));
477
478         Sprite *hubArrows = graphics.addSprite("HubArrows");
479         hubArrows->setFrame(0, graphics.loadImage("gfx/main/hubArrowLeft.png"), 60);
480         hubArrows->setFrame(1, graphics.loadImage("gfx/main/hubArrowLeft2.png"), 60);
481         hubArrows->setFrame(2, graphics.loadImage("gfx/main/hubArrowRight.png"), 60);
482         hubArrows->setFrame(3, graphics.loadImage("gfx/main/hubArrowRight2.png"), 60);
483
484         List hubList;
485         HubLevel *hubPoint;
486
487         engine.loadData("data/hub");
488
489         char *line = strtok((char*)engine.dataBuffer, "\n");
490
491         char name[50], level[50], requiredLevel[50];
492         int x, y;
493
494         #if !USEPAK
495         char pos[50];
496         #endif
497
498         graphics.setFontSize(0);
499         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
500         
501         int numberOfHubs = 0;
502         
503         gameData.calculateWorldCompleted();
504
505         while (true)
506         {
507                 sscanf(line, "%*c %[^\"] %*c %*c %[^\"] %*c %d %d %*c %[^\"] %*c", name, level, &x, &y, requiredLevel);
508
509                 if (strcmp(name, "@EOF@") == 0)
510                 {
511                         break;
512                 }
513                 
514                 // don't show boss levels on Easy (they might be cheating!)
515                 if (game.skill == 0)
516                 {
517                         if (strstr(name, "BioMech"))
518                         {
519                                 line = strtok(NULL, "\n");
520                                 continue;
521                         }
522                 }
523
524                 if (requirementMet(requiredLevel))
525                 {
526                         if (!gameData.levelPrefectlyCleared(name))
527                         {
528                                 hubPoint = new HubLevel;
529                                 hubPoint->set(name, level, x, y);
530                                 hubPoint->levelNameImage = graphics.getString(_(name), false);
531                                 
532                                 (!gameData.stagePreviouslyCleared(name)) ? hubPoint->target = newTarget : hubPoint->target = visitedTarget;
533                                 
534                                 hubList.add(hubPoint);
535                                 numberOfHubs++;
536                         }
537                 }
538
539                 line = strtok(NULL, "\n");
540         }
541
542         int rtn = -1;
543         
544         strcpy(level, "@none@");
545         strcpy(game.stageName, "@none@");
546
547         bool showData = false;
548         bool showStats = false;
549         bool showMIAs = false;
550         
551         int miaStart = 0;
552         int miaMax = 0;
553         int page = 0;
554         
555         int labelX, labelY;
556
557         Data *data = (Data*)gameData.dataList.getHead();
558
559         while (data->next != NULL)
560         {
561                 data = (Data*)data->next;
562
563                 if (strstr(data->value, "MIA_"))
564                 {
565                         miaMax++;
566                 }
567         }
568         
569         bool validStage = false;
570         
571         if ((numberOfHubs == 0) && (gameData.completedWorld))
572         {
573                 game.setMapName("data/spaceStation");
574                 strcpy(game.stageName, "Space Station");
575                 createObjectivesPanel("Space Station");
576                 showData = true;
577                 showStats = showMIAs = false;
578                 validStage = true;
579                 
580                 // Wait wait wait... we're in easy mode. Game ends here.
581                 if (game.skill == 0)
582                 {
583                         hubList.clear();
584                         return SECTION_EASYOVER;
585                 }
586         }
587         
588         audio.playMusic();
589
590         int labelWidth = 0;
591         Uint32 frameLimit = SDL_GetTicks() + 16;
592         
593         int mouseXDelta = 0;
594         int mouseYDelta = 0;
595
596         while (rtn == -1)
597         {
598                 graphics.updateScreen();
599                 graphics.drawBackground();
600                 graphics.animateSprites();
601
602                 if (validStage)
603                 {
604                         graphics.drawRect(10, 400, 620, 20, graphics.black, graphics.white, graphics.screen);
605                         sprintf(string, "%s", _("Selected Destination"));
606                         sprintf(string, "%s : %s", string, _(game.stageName));
607                         graphics.drawString(string, 320, 409, true, graphics.screen);
608                 }
609                 
610                 graphics.drawRect(10, 430, 620, 40, graphics.black, graphics.white, graphics.screen);
611
612                 #if !USEPAK
613                 sprintf(pos, "%.3d:%.3d", engine.getMouseX(), engine.getMouseY());
614                 graphics.drawString(pos, 320, 15, true, graphics.screen);
615                 #endif
616
617                 engine.getInput();
618                 config.populate();
619                 
620                 if (config.isControl(CONTROL::RIGHT))
621                 {
622                         mouseXDelta = 5;
623                 }
624                 
625                 if (config.isControl(CONTROL::LEFT))
626                 {
627                         mouseXDelta = -5;
628                 }
629                 
630                 if (config.isControl(CONTROL::DOWN))
631                 {
632                         mouseYDelta = 5;
633                 }
634                 
635                 if (config.isControl(CONTROL::UP) || config.isControl(CONTROL::JUMP))
636                 {
637                         mouseYDelta = -5;
638                 }
639
640                 if ((mouseXDelta != 0) || (mouseYDelta != 0))
641                 {
642                         engine.setMouse(engine.getMouseX() + (int)mouseXDelta, engine.getMouseY() + (int)mouseYDelta);
643                         mouseXDelta = 0;
644                         mouseYDelta = 0;
645                 }
646
647                 hubPoint = (HubLevel*)hubList.getHead();
648
649                 // Collisions for Hub Points
650                 while (hubPoint->next != NULL)
651                 {
652                         hubPoint = (HubLevel*)hubPoint->next;
653
654                         graphics.blit(hubPoint->target->getCurrentFrame(), hubPoint->x, hubPoint->y, graphics.screen, false);
655
656                         if (Collision::collision(engine.getMouseX(), engine.getMouseY(), 1, 1, hubPoint->x, hubPoint->y, 16, 16))
657                         {
658                                 labelX = engine.getMouseX();
659                                 labelY = engine.getMouseY() - 20;
660
661                                 labelWidth = hubPoint->levelNameImage->w / 2;
662
663                                 Math::limitInt(&labelX, 10 + labelWidth, 630 - labelWidth);
664
665                                 graphics.blit(hubPoint->levelNameImage, labelX, labelY, graphics.screen, true);
666
667                                 if (engine.mouseLeft || config.isControl(CONTROL::FIRE))
668                                 {
669                                         game.setMapName(hubPoint->filename);
670                                         game.setStageName(hubPoint->stageName);
671                                         validStage = true;
672                                         engine.mouseLeft = 0;
673                                         config.resetControl(CONTROL::FIRE);
674                                 }
675
676                                 if (engine.mouseRight || config.isControl(CONTROL::MAP))
677                                 {
678                                         game.setMapName(hubPoint->filename);
679                                         game.setStageName(hubPoint->stageName);
680                                         createObjectivesPanel(game.stageName);
681                                         showData = true;
682                                         showStats = false;
683                                         engine.mouseRight = 0;
684                                         config.resetControl(CONTROL::MAP);
685                                 }
686                         }
687                 }
688
689                 // Collisions for Panel
690                 for (int i = ((1 - validStage) * 2) ; i < 6 ; i++)
691                 {
692                         graphics.blit(hubIcons->image[i], 50 + (i * 100), 440, graphics.screen, false);
693                         if (Collision::collision(engine.getMouseX(), engine.getMouseY(), 1, 1, 50 + (i * 100), 440, hubIcons->image[i]->w, hubIcons->image[i]->h))
694                         {
695                                 if (engine.mouseLeft || config.isControl(CONTROL::FIRE))
696                                 {
697                                         switch (i)
698                                         {
699                                                 case 0:
700                                                         rtn = SECTION_GAME;
701                                                         break;
702                                                 case 1:
703                                                         createObjectivesPanel(game.stageName);
704                                                         showData = !showData;
705                                                         showStats = showMIAs = false;
706                                                         break;
707                                                 case 2:
708                                                         createMIAPanel(miaStart, miaMax);
709                                                         showStats = showData = false;
710                                                         showMIAs = !showMIAs;
711                                                         break;
712                                                 case 3:
713                                                         createStatsPanel(page);
714                                                         showStats = !showStats;
715                                                         showData = showMIAs = false;
716                                                         break;
717                                                 case 4:
718                                                         showOptions();
719                                                         graphics.setFontSize(0);
720                                                         graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
721                                                         break;
722                                                 case 5:
723                                                         rtn = SECTION_TITLE;
724                                                         break;
725                                         }
726
727                                         engine.mouseLeft = false;
728                                         config.resetControl(CONTROL::FIRE);
729                                 }
730                         }
731                 }
732                 
733                 // Collisions for Panel Buttons
734                 if ((showMIAs) || (showStats))
735                 {
736                     // SDLK_LCTRL is the "fire" button.
737                         if (engine.mouseLeft || config.isControl(CONTROL::FIRE))
738                         {
739                                 if (Collision::collision(engine.getMouseX(), engine.getMouseY(), 1, 1, 270, 310, 32, 32))
740                                 {
741                                         if (showMIAs)
742                                         {
743                                                 if (miaStart > 0)
744                                                 {
745                                                         Math::limitInt(&(miaStart -= 9), 0, miaMax);
746                                                         createMIAPanel(miaStart, miaMax);
747                                                 }
748                                         }
749
750                                         if (showStats)
751                                         {
752                                                 Math::limitInt(&(--page), 0, 2);
753                                                 createStatsPanel(page);
754                                         }
755
756                                         engine.mouseLeft = 0;
757                                         config.resetControl(CONTROL::FIRE);
758                                 }
759
760
761                                 if (Collision::collision(engine.getMouseX(), engine.getMouseY(), 1, 1, 320, 310, 32, 32))
762                                 {
763                                         if (showMIAs)
764                                         {
765                                                 if (miaStart + 9 < miaMax)
766                                                 {
767                                                         Math::limitInt(&(miaStart += 9), 0, miaMax);
768                                                         createMIAPanel(miaStart, miaMax);
769                                                 }
770                                         }
771
772                                         if (showStats)
773                                         {
774                                                 Math::limitInt(&(++page), 0, 2);
775                                                 createStatsPanel(page);
776                                         }
777
778                                         engine.mouseLeft = 0;
779                                         config.resetControl(CONTROL::FIRE);
780                                 }
781                         }
782                 }
783
784                 if ((showData) || (showStats) || (showMIAs))
785                 {
786                         graphics.blit(infoPanel, 320, 200, graphics.screen, true);
787                         if (engine.mouseLeft || config.isControl(CONTROL::FIRE))
788                         {
789                                 showData = showStats = showMIAs = false;
790                         }
791                 }
792
793                 graphics.blit(cursor->getCurrentFrame(), engine.getMouseX(), engine.getMouseY(), graphics.screen, true);
794
795                 engine.delay(frameLimit);
796                 frameLimit = SDL_GetTicks() + 16;
797         }
798
799         hubList.clear();
800
801         return rtn;
802 }