From: Holger Schemel Date: Wed, 21 Oct 1998 01:48:57 +0000 (+0200) Subject: rnd-19981021-1 X-Git-Tag: 1.2.0^2~49 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=8cef2a63b6c56ba086183693d3f73f02862cbd8f;p=rocksndiamonds.git rnd-19981021-1 --- diff --git a/src/game.c b/src/game.c index 2024abb4..23fcc2d4 100644 --- a/src/game.c +++ b/src/game.c @@ -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); diff --git a/src/init.c b/src/init.c index ce82c209..4a5578e6 100644 --- a/src/init.c +++ b/src/init.c @@ -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; iJOYSTICK_PERCENT) result |= JOY_LEFT; diff --git a/src/main.c b/src/main.c index ceebfb85..5d8aa5c0 100644 --- a/src/main.c +++ b/src/main.c @@ -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; diff --git a/src/main.h b/src/main.h index 7b9debac..7fa64257 100644 --- a/src/main.h +++ b/src/main.h @@ -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 diff --git a/src/misc.c b/src/misc.c index 6cbd9655..e2c8d7e0 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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; + } +} diff --git a/src/misc.h b/src/misc.h index 0c5ef87f..5c23eb76 100644 --- a/src/misc.h +++ b/src/misc.h @@ -41,5 +41,6 @@ void MarkTileDirty(int, int); void GetOptions(char **); void Error(int, char *, ...); void *checked_malloc(unsigned long); +char *getKeySymName(KeySym); #endif diff --git a/src/screens.c b/src/screens.c index 481ab6f8..ad05d1a6 100644 --- a/src/screens.c +++ b/src/screens.c @@ -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(); diff --git a/src/screens.h b/src/screens.h index 1e29566a..7c551760 100644 --- a/src/screens.h +++ b/src/screens.h @@ -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);