+#endif
+ }
+ }
+
+ BackToFront();
+
+ if (game_status == SETUP)
+ DoAnimation();
+}
+
+void DrawSetupScreen_Input()
+{
+ ClearWindow();
+ DrawText(SX+16, SY+16, "Setup Input", FS_BIG, FC_YELLOW);
+
+ initCursor(0, GFX_KUGEL_BLAU);
+ initCursor(1, GFX_KUGEL_BLAU);
+ initCursor(2, GFX_ARROW_BLUE_RIGHT);
+ initCursor(13, GFX_ARROW_BLUE_LEFT);
+
+ DrawGraphic(10, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_LEFT);
+ DrawGraphic(12, MENU_SCREEN_START_YPOS, GFX_ARROW_BLUE_RIGHT);
+
+ DrawText(SX+32, SY+2*32, "Player:", FS_BIG, FC_GREEN);
+ DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
+ DrawText(SX+32, SY+15*32, "Exit", FS_BIG, FC_GREEN);
+
+ DeactivateJoystickForCalibration();
+ DrawTextFCentered(SYSIZE - 20, FC_BLUE,
+ "Joysticks deactivated on this screen");
+
+ HandleSetupScreen_Input(0,0, 0,0, MB_MENU_INITIALIZE);
+ FadeToFront();
+ InitAnimation();
+}
+
+static void setJoystickDeviceToNr(char *device_name, int device_nr)
+{
+ if (device_name == NULL)
+ return;
+
+ if (device_nr < 0 || device_nr >= MAX_PLAYERS)
+ device_nr = 0;
+
+ if (strlen(device_name) > 1)
+ {
+ char c1 = device_name[strlen(device_name) - 1];
+ char c2 = device_name[strlen(device_name) - 2];
+
+ if (c1 >= '0' && c1 <= '9' && !(c2 >= '0' && c2 <= '9'))
+ device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
+ }
+ else
+ strncpy(device_name, getDeviceNameFromJoystickNr(device_nr),
+ strlen(device_name));
+}
+
+static void drawPlayerSetupInputInfo(int player_nr)
+{
+ int i;
+ static struct SetupKeyboardInfo custom_key;
+ static struct
+ {
+ Key *key;
+ char *text;
+ } custom[] =
+ {
+ { &custom_key.left, "Joystick Left" },
+ { &custom_key.right, "Joystick Right" },
+ { &custom_key.up, "Joystick Up" },
+ { &custom_key.down, "Joystick Down" },
+ { &custom_key.snap, "Button 1" },
+ { &custom_key.bomb, "Button 2" }
+ };
+ static char *joystick_name[MAX_PLAYERS] =
+ {
+ "Joystick1",
+ "Joystick2",
+ "Joystick3",
+ "Joystick4"
+ };
+
+ custom_key = setup.input[player_nr].key;
+
+ DrawText(SX+11*32, SY+2*32, int2str(player_nr + 1, 1), FS_BIG, FC_RED);
+ DrawGraphic(8, 2, GFX_SPIELER1 + player_nr);
+
+ if (setup.input[player_nr].use_joystick)
+ {
+ char *device_name = setup.input[player_nr].joy.device_name;
+
+ DrawText(SX+8*32, SY+3*32,
+ joystick_name[getJoystickNrFromDeviceName(device_name)],
+ FS_BIG, FC_YELLOW);
+ DrawText(SX+32, SY+4*32, "Calibrate", FS_BIG, FC_GREEN);
+ }
+ else
+ {
+ DrawText(SX+8*32, SY+3*32, "Keyboard ", FS_BIG, FC_YELLOW);
+ DrawText(SX+32, SY+4*32, "Customize", FS_BIG, FC_GREEN);
+ }
+
+ DrawText(SX+32, SY+5*32, "Actual Settings:", FS_BIG, FC_GREEN);
+ DrawGraphic(1, 6, GFX_ARROW_BLUE_LEFT);
+ DrawGraphic(1, 7, GFX_ARROW_BLUE_RIGHT);
+ DrawGraphic(1, 8, GFX_ARROW_BLUE_UP);
+ DrawGraphic(1, 9, GFX_ARROW_BLUE_DOWN);
+ DrawText(SX+2*32, SY+6*32, ":", FS_BIG, FC_BLUE);
+ DrawText(SX+2*32, SY+7*32, ":", FS_BIG, FC_BLUE);
+ DrawText(SX+2*32, SY+8*32, ":", FS_BIG, FC_BLUE);
+ DrawText(SX+2*32, SY+9*32, ":", FS_BIG, FC_BLUE);
+ DrawText(SX+32, SY+10*32, "Snap Field:", FS_BIG, FC_BLUE);
+ DrawText(SX+32, SY+12*32, "Place Bomb:", FS_BIG, FC_BLUE);
+
+ for (i=0; i<6; i++)
+ {
+ int ypos = 6 + i + (i > 3 ? i-3 : 0);
+
+ DrawText(SX + 3*32, SY + ypos*32,
+ " ", FS_BIG, FC_YELLOW);
+ DrawText(SX + 3*32, SY + ypos*32,
+ (setup.input[player_nr].use_joystick ?
+ custom[i].text :
+ getKeyNameFromKey(*custom[i].key)),
+ FS_BIG, FC_YELLOW);
+ }
+}
+
+void HandleSetupScreen_Input(int mx, int my, int dx, int dy, int button)
+{
+ static int choice = 0;
+ static int player_nr = 0;
+ int x = 0;
+ int y = choice;
+ int pos_start = SETUPINPUT_SCREEN_POS_START;
+ int pos_empty1 = SETUPINPUT_SCREEN_POS_EMPTY1;
+ int pos_empty2 = SETUPINPUT_SCREEN_POS_EMPTY2;
+ int pos_end = SETUPINPUT_SCREEN_POS_END;
+
+ if (button == MB_MENU_INITIALIZE)
+ {
+ drawPlayerSetupInputInfo(player_nr);
+ drawCursor(choice, FC_RED);
+ return;
+ }
+ else if (button == MB_MENU_LEAVE)
+ {
+ setup_mode = SETUP_MODE_MAIN;
+ DrawSetupScreen();
+ InitJoysticks();
+ }
+
+ if (mx || my) /* mouse input */
+ {
+ x = (mx - SX) / 32;
+ y = (my - SY) / 32 - MENU_SCREEN_START_YPOS;
+ }
+ else if (dx || dy) /* keyboard input */
+ {
+ if (dx && choice == 0)
+ x = (dx < 0 ? 10 : 12);
+ else if ((dx && choice == 1) ||
+ (dx == +1 && choice == 2) ||
+ (dx == -1 && choice == pos_end))
+ button = MB_MENU_CHOICE;
+ else if (dy)
+ y = choice + dy;
+
+ if (y >= pos_empty1 && y <= pos_empty2)
+ y = (dy > 0 ? pos_empty2 + 1 : pos_empty1 - 1);
+ }
+
+ if (y == 0 && ((x == 0 && !button) || ((x == 10 || x == 12) && button)))
+ {
+ static unsigned long delay = 0;
+
+ if (!DelayReached(&delay, GADGET_FRAME_DELAY))
+ goto out;
+
+ player_nr = (player_nr + (x == 10 ? -1 : +1) + MAX_PLAYERS) % MAX_PLAYERS;
+
+ drawPlayerSetupInputInfo(player_nr);
+ }
+ else if (x == 0 && y >= pos_start && y <= pos_end &&
+ !(y >= pos_empty1 && y <= pos_empty2))
+ {
+ if (button)
+ {
+ if (y != choice)