1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
|
/*
===========================================================================
blockattack - Block Attack - Rise of the Blocks
Copyright (C) 2005-2013 Poul Sander
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/
Source information and contacts persons can be found at
http://blockattack.net
===========================================================================
*/
#include "global.hpp"
#include <iostream>
#include <stdlib.h>
#include "MenuSystem.h"
#include "common.h"
#include "HelpHowtoState.hpp"
#include "HelpGamepadState.hpp"
#include "HelpAboutState.hpp"
#include "ShowFileState.hpp"
using std::string;
using std::cerr;
using std::cout;
using std::vector;
#if 0
//Menu
static void PrintHi(Button* b) {
cout << "Hi" <<"\n";
}
#endif
//Stores the controls
struct control {
SDL_Keycode up;
SDL_Keycode down;
SDL_Keycode left;
SDL_Keycode right;
SDL_Keycode change;
SDL_Keycode push;
};
void OpenScoresDisplay();
extern control keySettings[3];
//Function to return the name of a key, to be displayed...
string getKeyName(SDL_Keycode key) {
string keyname(SDL_GetKeyName(key));
if (key == SDLK_UP) {
keyname = _("Up arrow");
}
if (key == SDLK_DOWN) {
keyname = _("Down arrow");
}
if (key == SDLK_LEFT) {
keyname = _("Left arrow");
}
if (key == SDLK_RIGHT) {
keyname = _("Right arrow");
}
if (key == SDLK_RCTRL) {
keyname = _("Right Ctrl");
}
if (key == SDLK_LCTRL) {
keyname = _("Left Ctrl");
}
if (key == SDLK_RSHIFT) {
keyname = _("Right shift");
}
if (key == SDLK_LSHIFT) {
keyname = _("Left shift");
}
if (key == SDLK_RALT) {
keyname = _("Right alt");
}
if (key == SDLK_LALT) {
keyname = _("Left alt");
}
if (key == SDLK_RETURN) {
keyname = _("Return");
}
if (key == SDLK_SPACE) {
keyname = _("Space");
}
if (globalData.verboseLevel) {
cout << key << " translated to " << keyname << "\n";
}
return keyname;
}
class Button_changekey : public Button {
private:
SDL_Keycode* m_key2change;
string m_keyname;
public:
Button_changekey(SDL_Keycode* key, string keyname);
void doAction();
};
Button_changekey::Button_changekey(SDL_Keycode* key, string keyname) {
m_key2change = key;
m_keyname = keyname;
setLabel(m_keyname+" : "+getKeyName(*m_key2change));
}
void Button_changekey::doAction() {
SDL_Event event;
bool finnish = false;
while (!finnish) {
SDL_Delay(10);
while ( SDL_PollEvent(&event) ) {
if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym != SDLK_ESCAPE) {
*m_key2change = event.key.keysym.sym;
}
finnish = true;
}
}
}
setLabel(m_keyname+" : "+getKeyName(*m_key2change));
}
void InitMenues() {
standardButton.setSurfaces();
}
static void runSinglePlayerEndless() {
runGame(Gametype::SinglePlayerEndless, 0);
}
static void runSinglePlayerTimeTrial() {
runGame(Gametype::SinglePlayerTimeTrial, 0);
}
static void runStageClear() {
runGame(Gametype::StageClear, 0);
}
static void runSinglePlayerPuzzle() {
runGame(Gametype::Puzzle, 0);
}
class RunSinglePlayerVsButton : public Button {
virtual void doAction() override {
runGame(Gametype::SinglePlayerVs, iGeneric1);
}
};
static void runTwoPlayerTimeTrial() {
runGame(Gametype::TwoPlayerTimeTrial, 0);
}
static void runTwoPlayerVs() {
runGame(Gametype::TwoPlayerVs, 0);
}
class MusicButton : public Button {
virtual void doAction() override {
globalData.MusicEnabled = !globalData.MusicEnabled;
setLabel(globalData.MusicEnabled? _("Music: On") : _("Music: Off"));
}
};
class SoundButton : public Button {
virtual void doAction() override {
globalData.SoundEnabled = !globalData.SoundEnabled;
setLabel(globalData.SoundEnabled? _("Sound: On") : _("Sound: Off") );
}
};
class FullscreenButton : public Button {
virtual void doAction() override {
globalData.bFullscreen = !globalData.bFullscreen;
setLabel(globalData.bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") );
ResetFullscreen();
}
};
static void buttonActionPlayer1Name() {
if ( OpenDialogbox(200, 100, globalData.player1name, _("Enter player 1 name:")) ) {
return; //must save if true
}
}
static void buttonActionPlayer2Name() {
if ( OpenDialogbox(200, 100, globalData.player2name, _("Enter player 2 name:")) ) {
return; //must save if true
}
}
static void buttonActionHighscores() {
OpenScoresDisplay();
}
static void ChangeKeysMenu(long playernumber) {
Menu km(globalData.screen,_("Change key bindings"),true);
Button_changekey bLeft(&keySettings[playernumber].left,_("Left") );
Button_changekey bRight(&keySettings[playernumber].right,_("Right") );
Button_changekey bUp(&keySettings[playernumber].up,_("Up") );
Button_changekey bDown(&keySettings[playernumber].down,_("Down") );
Button_changekey bPush(&keySettings[playernumber].push,_("Push") );
Button_changekey bSwitch(&keySettings[playernumber].change,_("Change") );
km.addButton(&bLeft);
km.addButton(&bRight);
km.addButton(&bUp);
km.addButton(&bDown);
km.addButton(&bPush);
km.addButton(&bSwitch);
RunGameState(km);
}
static void ChangeKeysMenu1() {
ChangeKeysMenu(0);
}
static void ChangeKeysMenu2() {
ChangeKeysMenu(2);
}
static void ConfigureMenu() {
Menu cm(globalData.screen,_("Configuration"),true);
Button bPlayer1Name,bPlayer2Name;
Button bPlayer1Keys, bPlayer2Keys;
MusicButton bMusic;
SoundButton bSound;
FullscreenButton buttonFullscreen;
bMusic.setLabel(globalData.MusicEnabled? _("Music: On") : _("Music: Off") );
bSound.setLabel(globalData.SoundEnabled? _("Sound: On") : _("Sound: Off") );
buttonFullscreen.setLabel(globalData.bFullscreen? _("Fullscreen: On") : _("Fullscreen: Off") );
bPlayer1Name.setAction(buttonActionPlayer1Name);
bPlayer1Name.setLabel(_("Change player 1's name") );
bPlayer2Name.setAction(buttonActionPlayer2Name);
bPlayer2Name.setLabel(_("Change player 2's name") );
bPlayer1Keys.setAction(ChangeKeysMenu1);
bPlayer1Keys.setLabel(_("Change player 1's keys") );
bPlayer2Keys.setAction(ChangeKeysMenu2);
bPlayer2Keys.setLabel(_("Change player 2's keys") );
cm.addButton(&bMusic);
cm.addButton(&bSound);
cm.addButton(&buttonFullscreen);
cm.addButton(&bPlayer1Name);
cm.addButton(&bPlayer2Name);
cm.addButton(&bPlayer1Keys);
cm.addButton(&bPlayer2Keys);
RunGameState(cm);
}
static void SinglePlayerVsMenu() {
Menu spvs(globalData.screen,_("Single player VS"),true);
RunSinglePlayerVsButton d1,d2,d3,d4,d5,d6,d7;
d1.setPopOnRun(true);
d2.setPopOnRun(true);
d3.setPopOnRun(true);
d4.setPopOnRun(true);
d5.setPopOnRun(true);
d6.setPopOnRun(true);
d7.setPopOnRun(true);
d1.iGeneric1 = 0;
d2.iGeneric1 = 1;
d3.iGeneric1 = 2;
d4.iGeneric1 = 3;
d5.iGeneric1 = 4;
d6.iGeneric1 = 5;
d7.iGeneric1 = 6;
d1.setLabel(_("Very easy"));
d2.setLabel(_("Easy"));
d3.setLabel(_("Below normal"));
d4.setLabel(_("Normal"));
d5.setLabel(_("Above normal"));
d6.setLabel(_("Hard"));
d7.setLabel(_("Hardest"));
spvs.addButton(&d1);
spvs.addButton(&d2);
spvs.addButton(&d3);
spvs.addButton(&d4);
spvs.addButton(&d5);
spvs.addButton(&d6);
spvs.addButton(&d7);
RunGameState(spvs);
}
static void MultiplayerMenu() {
Menu mm(globalData.screen,_("Multiplayer"),true);
Button bTT, bVs;
bTT.setLabel(_("Two player - time trial"));
bTT.setAction(runTwoPlayerTimeTrial);
bVs.setLabel(_("Two player - vs"));
bVs.setAction(runTwoPlayerVs);
mm.addButton(&bTT);
mm.addButton(&bVs);
RunGameState(mm);
}
static void runHowto() {
HelpHowtoState howto;
RunGameState(howto);
}
static void runHelpGamepad() {
HelpGamepadState helpGamepad;
RunGameState(helpGamepad);
}
static void runHelpAbout() {
HelpAboutState helpAbout;
RunGameState(helpAbout);
}
static void runCredits() {
ShowFileState creditsFile;
creditsFile.SetData("misc/AUTHORS", _("Credits"));
RunGameState(creditsFile);
}
static void HelpMenu() {
Menu m(globalData.screen, _("Help"), true);
Button bHowto;
bHowto.setLabel(_("How to"));
bHowto.setAction(runHowto);
m.addButton(&bHowto);
Button bGamepad;
bGamepad.setLabel(_("Gamepad"));
bGamepad.setAction(runHelpGamepad);
m.addButton(&bGamepad);
Button bCredits;
bCredits.setLabel(_("Credits"));
bCredits.setAction(runCredits);
m.addButton(&bCredits);
Button bAbout;
bAbout.setLabel(_("About"));
bAbout.setAction(runHelpAbout);
m.addButton(&bAbout);
RunGameState(m);
}
static void SinglePlayerMenu() {
Menu m(globalData.screen, _("Single player"), true);
Button bHi,bTimetrial1, bStageClear, bPuzzle, bVs1;
bHi.setLabel(_("Single player - endless") );
bHi.setAction(runSinglePlayerEndless);
bTimetrial1.setLabel(_("Single player - time trial") );
bTimetrial1.setAction(runSinglePlayerTimeTrial);
bStageClear.setLabel(_("Single player - stage clear") );
bStageClear.setAction(runStageClear);
bPuzzle.setLabel(_("Single player - puzzle mode") );
bPuzzle.setAction(runSinglePlayerPuzzle);
bVs1.setLabel(_("Single player - vs") );
bVs1.setAction(SinglePlayerVsMenu);
m.addButton(&bHi);
m.addButton(&bTimetrial1);
m.addButton(&bStageClear);
m.addButton(&bPuzzle);
m.addButton(&bVs1);
RunGameState(m);
}
void MainMenu() {
InitMenues();
Menu m(globalData.screen,_("Block Attack - Rise of the blocks"),false);
Button bHi, bMulti, bConfigure, bHighscore, bHelp;
bHi.setLabel(_("Single player") );
bHi.setAction(SinglePlayerMenu);
bMulti.setLabel(_("Multi player") );
bMulti.setAction(MultiplayerMenu);
bConfigure.setLabel(_("Configure") );
bConfigure.setAction(ConfigureMenu);
bHighscore.setLabel(_("Highscores") );
bHighscore.setAction(buttonActionHighscores);
bHelp.setLabel(_("Help"));
bHelp.setAction(HelpMenu);
m.addButton(&bHi);
m.addButton(&bMulti);
m.addButton(&bConfigure);
m.addButton(&bHighscore);
m.addButton(&bHelp);
RunGameState(m);
}
|