rnd-19981021-1
authorHolger Schemel <info@artsoft.org>
Wed, 21 Oct 1998 01:48:57 +0000 (03:48 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:31:18 +0000 (10:31 +0200)
src/game.c
src/init.c
src/joystick.c
src/main.c
src/main.h
src/misc.c
src/misc.h
src/screens.c
src/screens.h

index 2024abb41b49e957be9fabc3f2644f01e6dcb53f..23fcc2d4f6819093b0a003964f7ec4fe4a517e7e 100644 (file)
@@ -25,7 +25,7 @@
 
 void GetPlayerConfig()
 {
-  int old_joystick_nr = setup.joystick_nr;
+  int old_joystick_nr = setup.joy_input[0].joystick_nr;
 
   if (sound_status==SOUND_OFF)
     local_player->setup &= ~SETUP_SOUND;
@@ -42,13 +42,19 @@ void GetPlayerConfig()
   setup.direct_draw_on = SETUP_DIRECT_DRAW_ON(local_player->setup);
   setup.fading_on = SETUP_FADING_ON(local_player->setup);
   setup.autorecord_on = SETUP_AUTO_RECORD_ON(local_player->setup);
+
+#if 0
   setup.joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
+#endif
+
+  setup.joy_input[0].joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
+
   setup.quick_doors = SETUP_QUICK_DOORS_ON(local_player->setup);
   setup.scroll_delay_on = SETUP_SCROLL_DELAY_ON(local_player->setup);
   setup.soft_scrolling_on = SETUP_SOFT_SCROLL_ON(local_player->setup);
 
 #ifndef MSDOS
-  if (setup.joystick_nr != old_joystick_nr)
+  if (setup.joy_input[0].joystick_nr != old_joystick_nr)
   {
     if (joystick_device)
       close(joystick_device);
index ce82c209eb9c6dbeeaa5490c1d8976831303d17f..4a5578e643e3bcc02f2ccc87c6f3b04df1f4d576 100644 (file)
@@ -94,7 +94,7 @@ void InitLevelAndPlayerInfo()
 {
   int i;
 
-  /* initialize local player's setup */
+  /* initialize local setup */
   setup.sound_on = TRUE;
   setup.sound_loops_on = FALSE;
   setup.sound_music_on = FALSE;
@@ -106,7 +106,19 @@ void InitLevelAndPlayerInfo()
   setup.fading_on = FALSE;
   setup.autorecord_on = FALSE;
   setup.quick_doors = FALSE;
-  setup.joystick_nr = 0;
+  for (i=0; i<MAX_PLAYERS; i++)
+  {
+    setup.joy_input[i].use_joystick = FALSE;
+    setup.joy_input[i].joystick_nr = i;
+    setup.joy_input[i].button_snap = JOY_BUTTON_1;
+    setup.joy_input[i].button_bomb = JOY_BUTTON_2;
+    setup.key_input[i].left = DEFAULT_KEY_LEFT;
+    setup.key_input[i].right = DEFAULT_KEY_RIGHT;
+    setup.key_input[i].up = DEFAULT_KEY_UP;
+    setup.key_input[i].down = DEFAULT_KEY_DOWN;
+    setup.key_input[i].snap = DEFAULT_KEY_SNAP;
+    setup.key_input[i].bomb = DEFAULT_KEY_BOMB;
+  }
 
   /* choose default local player */
   local_player = &stored_player[0];
@@ -230,23 +242,25 @@ void InitSoundServer()
 
 void InitJoystick()
 {
+  int joystick_nr = setup.joy_input[0].joystick_nr;
+
   if (global_joystick_status == JOYSTICK_OFF)
     return;
 
 #ifndef MSDOS
-  if (access(joystick_device_name[setup.joystick_nr], R_OK) < 0)
+  if (access(joystick_device_name[joystick_nr], R_OK) < 0)
   {
     Error(ERR_RETURN, "cannot access joystick device '%s'",
-         joystick_device_name[setup.joystick_nr]);
+         joystick_device_name[joystick_nr]);
     joystick_status = JOYSTICK_OFF;
     return;
   }
 
   if ((joystick_device =
-       open(joystick_device_name[setup.joystick_nr], O_RDONLY)) < 0)
+       open(joystick_device_name[joystick_nr], O_RDONLY)) < 0)
   {
     Error(ERR_RETURN, "cannot open joystick device '%s'",
-         joystick_device_name[setup.joystick_nr]);
+         joystick_device_name[joystick_nr]);
     joystick_status = JOYSTICK_OFF;
     return;
   }
index 3e2b3abd698f5eb2ce50cc36926d9055cd12bb05..e9e520bd3245f11d691a38168763f081de4dfab4 100644 (file)
@@ -74,6 +74,7 @@ int Joystick()
   } joy_ctrl;
 #endif
 
+  int joystick_nr = setup.joy_input[0].joystick_nr;
   int js_x,js_y, js_b1,js_b2;
   int left, right, up, down;
   int result=0;
@@ -99,14 +100,14 @@ int Joystick()
   js_b2 = joy_ctrl.buttons & 2;
 #endif
 
-  left = JoystickPosition(joystick[setup.joystick_nr].xmiddle,
-                         joystick[setup.joystick_nr].xleft,  js_x);
-  right = JoystickPosition(joystick[setup.joystick_nr].xmiddle,
-                          joystick[setup.joystick_nr].xright, js_x);
-  up =    JoystickPosition(joystick[setup.joystick_nr].ymiddle,
-                          joystick[setup.joystick_nr].yupper, js_y);
-  down =  JoystickPosition(joystick[setup.joystick_nr].ymiddle,
-                          joystick[setup.joystick_nr].ylower, js_y);
+  left = JoystickPosition(joystick[joystick_nr].xmiddle,
+                         joystick[joystick_nr].xleft,  js_x);
+  right = JoystickPosition(joystick[joystick_nr].xmiddle,
+                          joystick[joystick_nr].xright, js_x);
+  up =    JoystickPosition(joystick[joystick_nr].ymiddle,
+                          joystick[joystick_nr].yupper, js_y);
+  down =  JoystickPosition(joystick[joystick_nr].ymiddle,
+                          joystick[joystick_nr].ylower, js_y);
 
   if (left>JOYSTICK_PERCENT)
     result |= JOY_LEFT;
index ceebfb85afb392fcb65434655ba6d92622bcb757..5d8aa5c05093cfe7ea41e2444affade81901bf26 100644 (file)
@@ -100,8 +100,7 @@ int         TestPlayer = 0;
 
 struct LevelDirInfo    leveldir[MAX_LEVDIR_ENTRIES];
 struct LevelInfo       level;
-struct PlayerInfo      stored_player[MAX_PLAYERS+1];
-struct PlayerInfo      *local_player;
+struct PlayerInfo      stored_player[MAX_PLAYERS], *local_player;
 struct HiScore         highscore[MAX_SCORE_ENTRIES];
 struct SoundInfo       Sound[NUM_SOUNDS];
 struct RecordingInfo   tape;
index 7b9debaca77f20680ad0c35e467084e8e1bc9056..7fa6425715a497943e05c9b05b4c8354bd274928 100644 (file)
@@ -217,6 +217,24 @@ struct OptionInfo
   boolean verbose;
 };
 
+struct SetupKeyboardInfo
+{
+  KeySym left;
+  KeySym right;
+  KeySym up;
+  KeySym down;
+  KeySym snap;
+  KeySym bomb;
+};
+
+struct SetupJoystickInfo
+{
+  boolean use_joystick;
+  int joystick_nr;
+  int button_snap;
+  int button_bomb;
+};
+
 struct SetupInfo
 {
   boolean sound_on;
@@ -230,7 +248,8 @@ struct SetupInfo
   boolean fading_on;
   boolean autorecord_on;
   boolean quick_doors;
-  int joystick_nr;
+  struct SetupKeyboardInfo key_input[MAX_PLAYERS];
+  struct SetupJoystickInfo joy_input[MAX_PLAYERS];
 };
 
 struct PlayerInfo
@@ -401,14 +420,13 @@ extern int                TestPlayer;
 
 extern struct LevelDirInfo     leveldir[];
 extern struct LevelInfo                level;
-extern struct PlayerInfo       stored_player[];
-extern struct PlayerInfo       *local_player;
+extern struct PlayerInfo       stored_player[], *local_player;
 extern struct HiScore          highscore[];
 extern struct RecordingInfo    tape;
 extern struct SoundInfo                Sound[];
 extern struct JoystickInfo     joystick[];
-struct OptionInfo              options;
-struct SetupInfo               setup;
+extern struct OptionInfo       options;
+extern struct SetupInfo                setup;
 
 extern char            *sound_name[];
 extern int             background_loop[];
@@ -989,6 +1007,13 @@ extern int                num_bg_loops;
                                 (s)==SND_TYGER || (s)==SND_VOYAGER || \
                                 (s)==SND_TWILIGHT)
 
+/* default input keys */
+#define DEFAULT_KEY_LEFT       XK_Left
+#define DEFAULT_KEY_RIGHT      XK_Right
+#define DEFAULT_KEY_UP         XK_Up
+#define DEFAULT_KEY_DOWN       XK_Down
+#define DEFAULT_KEY_SNAP       XK_Shift_L
+#define DEFAULT_KEY_BOMB       XK_Shift_R
 
 /* directions for moving */
 #define MV_NO_MOVING           0
index 6cbd9655e60cd32ed28a514fef251691a8736932..e2c8d7e0bafbf52a8c11ebd91d38c67678fb5b72 100644 (file)
@@ -391,3 +391,84 @@ void *checked_malloc(unsigned long size)
 
   return ptr;
 }
+
+char *getKeySymName(KeySym key)
+{
+  static char key_name[20];
+  static struct
+  {
+    KeySym keysym;
+    char *name;
+  } translate[] =
+  {
+    { XK_Left,         "cursor left" },
+    { XK_Right,                "cursor right" },
+    { XK_Up,           "cursor up" },
+    { XK_Down,         "cursor down" },
+
+#ifdef XK_KP_Left
+    { XK_KP_Left,      "keypad left" },
+    { XK_KP_Right,     "keypad right" },
+    { XK_KP_Up,                "keypad up" },
+    { XK_KP_Down,      "keypad down" },
+#endif
+
+    { XK_BackSpace,    "backspace" },
+    { XK_Delete,       "delete" },
+    { XK_Insert,       "insert" },
+    { XK_Tab,          "tab" },
+    { XK_Home,         "home" },
+    { XK_End,          "end" },
+    { XK_Page_Up,      "page up" },
+    { XK_Page_Down,    "page down" },
+    { XK_space,                "space" },
+
+    { XK_Shift_L,      "left shift" },
+    { XK_Shift_R,      "right shift" },
+    { XK_Control_L,    "left ctrl" },
+    { XK_Control_R,    "right ctrl" },
+    { XK_Meta_L,       "left meta" },
+    { XK_Meta_R,       "right meta" },
+    { XK_Alt_L,                "left alt" },
+    { XK_Alt_R,                "right alt" },
+    { XK_Mode_switch,  "mode switch" },
+    { XK_Multi_key,    "multi key" },
+
+    { 0,                NULL }
+  };
+
+  if (key >= XK_A && key <= XK_Z)
+  {
+    sprintf(key_name, "%c", 'A' + (char)(key - XK_A));
+    return key_name;
+  }
+  else if (key >= XK_a && key <= XK_z)
+  {
+    sprintf(key_name, "%c", 'a' + (char)(key - XK_a));
+    return key_name;
+  }
+  else if (key >= XK_0 && key <= XK_9)
+  {
+    sprintf(key_name, "%c", '0' + (char)(key - XK_0));
+    return key_name;
+  }
+  else if (key >= XK_KP_0 && key <= XK_KP_9)
+  {
+    sprintf(key_name, "keypad %c", '0' + (char)(key - XK_KP_0));
+    return key_name;
+  }
+  else
+  {
+    int i = 0;
+
+    do
+    {
+      if (key == translate[i].keysym)
+       return translate[i].name;
+    }
+    while (translate[++i].name);
+
+    sprintf(key_name, "(unknown)");
+    return key_name;
+  }
+}
index 0c5ef87feaa9121e0e35a0aa18c265b28cfee847..5c23eb76427069cae31c5f19e175f8d2e095b911 100644 (file)
@@ -41,5 +41,6 @@ void MarkTileDirty(int, int);
 void GetOptions(char **);
 void Error(int, char *, ...);
 void *checked_malloc(unsigned long);
+char *getKeySymName(KeySym);
 
 #endif
index 481ab6f884490ff0499f6b8f8c7a6eb34b07c656..ad05d1a610becd58fa93050d1098ff7034dea37e 100644 (file)
@@ -1112,7 +1112,12 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
       }
       else if (y==14)
       {
+       /*
        CalibrateJoystick();
+       */
+
+       CustomizeKeyboard();
+
        redraw = TRUE;
       }
       else if (y==pos_end-1 || y==pos_end)
@@ -1135,6 +1140,120 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
     DoAnimation();
 }
 
+void CustomizeKeyboard( /* int player_nr */ )
+{
+  int player_nr = 0;
+
+  int i;
+  boolean finished = FALSE;
+  static struct SetupKeyboardInfo custom_key;
+  static struct
+  {
+    KeySym *keysym;
+    char *text;
+  } customize_step[] =
+  {
+    { &custom_key.left,  "Move Left"  },
+    { &custom_key.right, "Move Right" },
+    { &custom_key.up,    "Move Up"    },
+    { &custom_key.down,  "Move Down"  },
+    { &custom_key.snap,  "Snap Field" },
+    { &custom_key.bomb,  "Place Bomb" }
+  };
+
+  custom_key = setup.key_input[player_nr];
+
+  ClearWindow();
+  DrawText(SX+16, SY+16, "Keyboard Input", FS_BIG, FC_YELLOW);
+
+  BackToFront();
+  InitAnimation();
+
+  i = 0;
+  DrawText(SX, SY+(2+2*i)*32, customize_step[i].text, FS_BIG, FC_GREEN);
+  DrawText(SX, SY+(2+2*i+1)*32, "Key:", FS_BIG, FC_GREEN);
+  DrawText(SX + 5*32, SY+(2+2*i+1)*32,
+          getKeySymName(*customize_step[i].keysym), FS_BIG, FC_BLUE);
+
+  while(!finished)
+  {
+    if (XPending(display))     /* got event from X server */
+    {
+      XEvent event;
+
+      XNextEvent(display, &event);
+      switch(event.type)
+      {
+       case Expose:
+         HandleExposeEvent((XExposeEvent *) &event);
+         break;
+       case UnmapNotify:
+         SleepWhileUnmapped();
+         break;
+       case KeyPress:
+         {
+           KeySym key = XLookupKeysym((XKeyEvent *)&event,
+                                      ((XKeyEvent *)&event)->state);
+
+           if (key == XK_Escape || (key == XK_Return && i == 6))
+           {
+             finished = TRUE;
+             break;
+           }
+
+           if (key == XK_Return || i == 6)
+             break;
+
+           /* got new key binding */
+           *customize_step[i].keysym = key;
+           DrawText(SX + 5*32, SY+(2+2*i+1)*32,
+                    "            ", FS_BIG, FC_YELLOW);
+           DrawText(SX + 5*32, SY+(2+2*i+1)*32,
+                    getKeySymName(key), FS_BIG, FC_YELLOW);
+
+           i++;
+
+           if (i == 6)
+           {
+             DrawText(SX+16, SY+15*32+16, "Press Enter", FS_BIG, FC_YELLOW);
+             break;
+           }
+
+           /* ask for next key binding */
+           DrawText(SX, SY+(2+2*i)*32,
+                    customize_step[i].text, FS_BIG, FC_GREEN);
+           DrawText(SX, SY+(2+2*i+1)*32, "Key:", FS_BIG, FC_GREEN);
+           DrawText(SX + 5*32, SY+(2+2*i+1)*32,
+                    getKeySymName(*customize_step[i].keysym),
+                    FS_BIG, FC_BLUE);
+         }
+         break;
+       case KeyRelease:
+         key_joystick_mapping = 0;
+         break;
+       case FocusIn:
+       case FocusOut:
+         HandleFocusEvent((XFocusChangeEvent *) &event);
+         break;
+        case ClientMessage:
+         HandleClientMessageEvent((XClientMessageEvent *) &event);
+         break;
+       default:
+         break;
+      }
+    }
+
+    BackToFront();
+    DoAnimation();
+
+    /* don't eat all CPU time */
+    Delay(10);
+  }
+
+  StopAnimation();
+  DrawSetupScreen();
+}
+
 void CalibrateJoystick()
 {
 #ifdef __FreeBSD__
@@ -1152,6 +1271,7 @@ void CalibrateJoystick()
   char joy_nr[4];
 #endif
 
+  int joystick_nr = setup.joy_input[0].joystick_nr;
   int new_joystick_xleft = 128, new_joystick_xright = 128;
   int new_joystick_yupper = 128, new_joystick_ylower = 128;
   int new_joystick_xmiddle, new_joystick_ymiddle;
@@ -1256,12 +1376,12 @@ void CalibrateJoystick()
     new_joystick_ymiddle =
       new_joystick_yupper + (new_joystick_ylower - new_joystick_yupper) / 2;
 
-    joystick[setup.joystick_nr].xleft = new_joystick_xleft;
-    joystick[setup.joystick_nr].yupper = new_joystick_yupper;
-    joystick[setup.joystick_nr].xright = new_joystick_xright;
-    joystick[setup.joystick_nr].ylower = new_joystick_ylower;
-    joystick[setup.joystick_nr].xmiddle = new_joystick_xmiddle;
-    joystick[setup.joystick_nr].ymiddle = new_joystick_ymiddle;
+    joystick[joystick_nr].xleft = new_joystick_xleft;
+    joystick[joystick_nr].yupper = new_joystick_yupper;
+    joystick[joystick_nr].xright = new_joystick_xright;
+    joystick[joystick_nr].ylower = new_joystick_ylower;
+    joystick[joystick_nr].xmiddle = new_joystick_xmiddle;
+    joystick[joystick_nr].ymiddle = new_joystick_ymiddle;
 
     CheckJoystickData();
 
@@ -1289,13 +1409,13 @@ void CalibrateJoystick()
 
 #if 0
       printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
-            joystick[setup.joystick_nr].xleft,
-            joystick[setup.joystick_nr].xmiddle,
-            joystick[setup.joystick_nr].xright);
+            joystick[joystick_nr].xleft,
+            joystick[joystick_nr].xmiddle,
+            joystick[joystick_nr].xright);
       printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
-            joystick[setup.joystick_nr].yupper,
-            joystick[setup.joystick_nr].ymiddle,
-            joystick[setup.joystick_nr].ylower);
+            joystick[joystick_nr].yupper,
+            joystick[joystick_nr].ymiddle,
+            joystick[joystick_nr].ylower);
 #endif
     }
 
@@ -1339,6 +1459,7 @@ void CalibrateJoystick_OLD()
   char joy_nr[4];
 #endif
 
+  int joystick_nr = setup.joy_input[0].joystick_nr;
   int new_joystick_xleft, new_joystick_xright, new_joystick_xmiddle;
   int new_joystick_yupper, new_joystick_ylower, new_joystick_ymiddle;
 
@@ -1432,12 +1553,12 @@ void CalibrateJoystick_OLD()
   new_joystick_xmiddle = joy_ctrl.x;
   new_joystick_ymiddle = joy_ctrl.y;
 
-  joystick[setup.joystick_nr].xleft = new_joystick_xleft;
-  joystick[setup.joystick_nr].yupper = new_joystick_yupper;
-  joystick[setup.joystick_nr].xright = new_joystick_xright;
-  joystick[setup.joystick_nr].ylower = new_joystick_ylower;
-  joystick[setup.joystick_nr].xmiddle = new_joystick_xmiddle;
-  joystick[setup.joystick_nr].ymiddle = new_joystick_ymiddle;
+  joystick[joystick_nr].xleft = new_joystick_xleft;
+  joystick[joystick_nr].yupper = new_joystick_yupper;
+  joystick[joystick_nr].xright = new_joystick_xright;
+  joystick[joystick_nr].ylower = new_joystick_ylower;
+  joystick[joystick_nr].xmiddle = new_joystick_xmiddle;
+  joystick[joystick_nr].ymiddle = new_joystick_ymiddle;
 
   CheckJoystickData();
 
index 1e29566aa86327cfb6865c4c0c42c1b48ec1bd62..7c551760c6263ac858ce65272f3730b78515876d 100644 (file)
@@ -37,6 +37,7 @@ void DrawHallOfFame(int);
 void HandleHallOfFame(int);
 void DrawSetupScreen(void);
 void HandleSetupScreen(int, int, int, int, int);
+void CustomizeKeyboard(void);
 void CalibrateJoystick(void);
 void HandleGameActions(byte);
 void HandleVideoButtons(int, int, int);