void MenuLoop(MenuSystem *menu) { assert(menu->numExitTypes > 0); for (;; SDL_Delay(10)) { // Input InputPoll(menu->joysticks, menu->keyboard); // Update if (menu->current->type == MENU_TYPE_KEYS && menu->current->u.normal.changeKeyMenu != NULL) { MenuProcessChangeKey(menu->current); } else { int cmd = GetMenuCmd(); menu->current = MenuProcessCmd(menu->current, cmd); } if (MenuHasExitType(menu, menu->current->type)) { break; } // Draw if (menu->bkg != NULL) { memcpy( GetDstScreen(), menu->bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); } ShowControls(); MenuDisplay(menu); CopyToScreen(); } }
void MenuLoop(MenuSystem *menu) { assert(menu->numExitTypes > 0); for (;; SDL_Delay(10)) { MusicSetPlaying(&gSoundDevice, SDL_GetAppState() & SDL_APPINPUTFOCUS); // Input InputPoll(menu->inputDevices, SDL_GetTicks()); // Update if (menu->current->type == MENU_TYPE_KEYS && menu->current->u.normal.changeKeyMenu != NULL) { MenuProcessChangeKey(menu->current); } else { int cmd = GetMenuCmd(gPlayerDatas); MenuProcessCmd(menu, cmd); } if (MenuIsExit(menu)) { break; } // Draw GraphicsBlitBkg(menu->graphics); ShowControls(); MenuDisplay(menu); BlitFlip(menu->graphics, &gConfig.Graphics); } }
int NumPlayersSelection( int *numPlayers, campaign_mode_e mode, GraphicsDevice *graphics, InputDevices *input) { MenuSystem ms; int i; int res = 0; MenuSystemInit( &ms, input, graphics, Vec2iZero(), Vec2iNew( graphics->cachedConfig.ResolutionWidth, graphics->cachedConfig.ResolutionHeight)); ms.root = ms.current = MenuCreateNormal( "", "Select number of players", MENU_TYPE_NORMAL, 0); for (i = 0; i < MAX_PLAYERS; i++) { if (mode == CAMPAIGN_MODE_DOGFIGHT && i == 0) { // At least two players for dogfights continue; } char buf[2]; sprintf(buf, "%d", i + 1); MenuAddSubmenu(ms.current, MenuCreateReturn(buf, i + 1)); } MenuAddExitType(&ms, MENU_TYPE_RETURN); for (;;) { int cmd; InputPoll(&gInputDevices, SDL_GetTicks()); if (KeyIsPressed(&gInputDevices.keyboard, SDLK_ESCAPE)) { res = 0; break; // hack to allow exit } cmd = GetMenuCmd(gPlayerDatas); MenuProcessCmd(&ms, cmd); if (MenuIsExit(&ms)) { *numPlayers = ms.current->u.returnCode; res = 1; break; } GraphicsBlitBkg(graphics); MenuDisplay(&ms); BlitFlip(graphics, &gConfig.Graphics); SDL_Delay(10); } MenuSystemTerminate(&ms); return res; }
int PlayerEquip(void *bkg) { int done1 = 0, done2; debug(D_NORMAL, "\n"); done2 = gOptions.twoPlayers ? 0 : 1; while (!done1 || !done2) { int cmd1 = 0; int cmd2 = 0; InputPoll(&gJoysticks, &gKeyboard); memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); GetPlayerCmd(&cmd1, &cmd2, 1); if (KeyIsPressed(&gKeyboard, keyEsc)) return 0; // hack to exit from menu if (gOptions.twoPlayers) { done1 = !WeaponSelection(CenterOfLeft(50), CHARACTER_PLAYER1, &gPlayer1Data, cmd1, done1); ShowSelection(CenterOfLeft(50), &gPlayer1Data,CHARACTER_PLAYER1); ShowPlayerControls(CenterOfLeft(100), &gConfig.Input.PlayerKeys[0]); done2 = !WeaponSelection(CenterOfRight(50), CHARACTER_PLAYER2, &gPlayer2Data, cmd2, done2); ShowSelection(CenterOfRight(50), &gPlayer2Data, CHARACTER_PLAYER2); ShowPlayerControls(CenterOfRight(100), &gConfig.Input.PlayerKeys[1]); } else { done1 = !WeaponSelection(CenterX(80), CHARACTER_PLAYER1, &gPlayer1Data, cmd1, done1); ShowSelection(CenterX(80), &gPlayer1Data, CHARACTER_PLAYER1); ShowPlayerControls(CenterX(100), &gConfig.Input.PlayerKeys[0]); } CopyToScreen(); SDL_Delay(10); } return 1; }
int PlayerSelection(int twoPlayers, void *bkg) { int mode1, mode2; mode1 = MODE_MAIN; mode2 = twoPlayers ? MODE_MAIN : MODE_DONE; SetPlayer(0, &gPlayer1Data); SetPlayer(1, &gPlayer2Data); KeyInit(&gKeyboard); while (mode1 != MODE_DONE || mode2 != MODE_DONE) { int cmd1 = 0; int cmd2 = 0; InputPoll(&gJoysticks, &gKeyboard); memcpy(GetDstScreen(), bkg, GraphicsGetMemSize(&gGraphicsDevice.cachedConfig)); GetPlayerCmd(&cmd1, &cmd2, 1); if (KeyIsPressed(&gKeyboard, keyEsc)) return 0; // hack to allow exit if (twoPlayers) { mode1 = MakeSelection(mode1, CenterOfLeft(50), CHARACTER_PLAYER1, &gPlayer1Data, cmd1); mode2 = MakeSelection(mode2, CenterOfRight(50), CHARACTER_PLAYER2, &gPlayer2Data, cmd2); } else { mode1 = MakeSelection(mode1, CenterX(50), CHARACTER_PLAYER1, &gPlayer1Data, cmd1); } CopyToScreen(); SDL_Delay(10); } return 1; }
int PlayerEquip(int numPlayers, GraphicsDevice *graphics) { int i; WeaponMenu menus[MAX_PLAYERS]; for (i = 0; i < numPlayers; i++) { WeaponMenuCreate( &menus[i], numPlayers, i, &gCampaign.Setting.characters.players[i], &gPlayerDatas[i], &gInputDevices, graphics, &gConfig.Input); } debug(D_NORMAL, "\n"); for (;;) { int cmds[MAX_PLAYERS]; int isDone = 1; InputPoll(&gInputDevices, SDL_GetTicks()); if (KeyIsPressed(&gInputDevices.keyboard, SDLK_ESCAPE)) { return 0; // hack to exit from menu } GetPlayerCmds(&cmds, gPlayerDatas); for (i = 0; i < numPlayers; i++) { if (!MenuIsExit(&menus[i].ms)) { MenuProcessCmd(&menus[i].ms, cmds[i]); } else if (gPlayerDatas[i].weaponCount == 0) { // Check exit condition; must have selected at least one weapon // Otherwise reset the current menu menus[i].ms.current = menus[i].ms.root; } } for (i = 0; i < numPlayers; i++) { if (!MenuIsExit(&menus[i].ms)) { isDone = 0; } } if (isDone) { break; } GraphicsBlitBkg(graphics); for (i = 0; i < numPlayers; i++) { MenuDisplay(&menus[i].ms); } BlitFlip(graphics, &gConfig.Graphics); SDL_Delay(10); } for (i = 0; i < numPlayers; i++) { MenuSystemTerminate(&menus[i].ms); } return 1; }
int PlayerSelection(int numPlayers, GraphicsDevice *graphics) { int i; int hasInputDevice[MAX_PLAYERS]; PlayerSelectMenu menus[MAX_PLAYERS]; for (i = 0; i < numPlayers; i++) { PlayerSelectMenusCreate( &menus[i], numPlayers, i, &gCampaign.Setting.characters.players[i], &gPlayerDatas[i], &gInputDevices, graphics, &gConfig.Input); hasInputDevice[i] = 0; } KeyInit(&gInputDevices.keyboard); for (;;) { int cmds[MAX_PLAYERS]; int isDone = 1; InputPoll(&gInputDevices, SDL_GetTicks()); if (KeyIsPressed(&gInputDevices.keyboard, SDLK_ESCAPE)) { // TODO: destroy menus return 0; // hack to allow exit } GetPlayerCmds(&cmds, gPlayerDatas); for (i = 0; i < numPlayers; i++) { if (hasInputDevice[i] && !MenuIsExit(&menus[i].ms)) { MenuProcessCmd(&menus[i].ms, cmds[i]); } } for (i = 0; i < numPlayers; i++) { if (!MenuIsExit(&menus[i].ms)) { isDone = 0; } } if (isDone) { break; } AssignPlayerInputDevices( hasInputDevice, numPlayers, gPlayerDatas, &gInputDevices, &gConfig.Input); GraphicsBlitBkg(graphics); for (i = 0; i < numPlayers; i++) { if (hasInputDevice[i]) { MenuDisplay(&menus[i].ms); } else { Vec2i center; const char *prompt = "Press Fire to join..."; Vec2i offset = Vec2iScaleDiv(TextGetSize(prompt), -2); int w = graphics->cachedConfig.ResolutionWidth; int h = graphics->cachedConfig.ResolutionHeight; switch (numPlayers) { case 1: // Center of screen center = Vec2iNew(w / 2, h / 2); break; case 2: // Side by side center = Vec2iNew(i * w / 2 + w / 4, h / 2); break; case 3: case 4: // Four corners center = Vec2iNew( (i & 1) * w / 2 + w / 4, (i / 2) * h / 2 + h / 4); break; default: assert(0 && "not implemented"); break; } DrawTextString(prompt, graphics, Vec2iAdd(center, offset)); } } BlitFlip(graphics, &gConfig.Graphics); SDL_Delay(10); } for (i = 0; i < numPlayers; i++) { MenuSystemTerminate(&menus[i].ms); } return 1; }