1 /*
2  * file menu_control.h - edit control settings
3  *
4  * $Id: menu_control.c,v 1.10 2006/02/10 13:22:11 fzago Exp $
5  *
6  * Program XBLAST
7  * (C) by Oliver Vogel (e-mail: m.vogel@ndh.net)
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published
11  * by the Free Software Foundation; either version 2; or (at your option)
12  * any later version
13  *
14  * This program is distributed in the hope that it will be entertaining,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17  * Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.
21  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 
24 #include "xblast.h"
25 
26 /*
27  * local macros
28  */
29 #define PLAYER_KEYB_1    0
30 #define PLAYER_KEYB_2    1
31 #define PLAYER_JOY_1     2
32 #define PLAYER_JOY_2     3
33 #define PLAYER_JOY_3     4
34 #define PLAYER_JOY_4     5
35 
36 /*
37  * local variables
38  */
39 
40 /* player controls */
41 static const char *joystickString[4] = {
42 	"Joystick 1",
43 	"Joystick 2",
44 	"Joystick 3",
45 	"Joystick 4",
46 };
47 
48 static XBBool CreateConfigKeyboardMenu1 (void *par);
49 /* controls code */
50 static XBEventCode ctrl[NUM_LOCAL_PLAYER] = {
51 	XBE_KEYB_1, XBE_KEYB_2, XBE_JOYST_1, XBE_JOYST_2, XBE_JOYST_3, XBE_JOYST_4,
52 };
53 
54 /* local copy od keybaord control */
55 static CFGControlKeyboard cfgKeyboard;
56 
57 /*
58  * store keyboard configuration
59  */
60 static XBBool
ButtonSaveKeyboard(void * par)61 ButtonSaveKeyboard (void *par)
62 {
63 	XBEventCode *pCtrl = par;
64 
65 	assert (pCtrl != NULL);
66 	StoreControlKeyboard (*pCtrl, &cfgKeyboard);
67 	GUI_UpdateKeyTables ();
68 	return CreateConfigControlMenu (NULL);
69 }								/* ButtonSaveKeyboard */
70 
71 /*
72  * menu to configure keyboard
73  */
74 static XBBool
CreateConfigKeyboardMenu(void * par)75 CreateConfigKeyboardMenu (void *par)
76 {
77 	XBEventCode *pCtrl = par;
78 	int row;
79 
80 	assert (pCtrl != NULL);
81 	/* retrieve controls */
82 	if (!RetrieveControlKeyboard (*pCtrl, &cfgKeyboard)) {
83 		memset (&cfgKeyboard, 0, sizeof (cfgKeyboard));
84 	}
85 	MenuClear ();
86 	/* title */
87 	MenuAddLabel (TITLE_LEFT, TITLE_TOP, TITLE_WIDTH, N_("Configure Keyboard"));
88 	/* Buttons */
89 	row = MENU_TOP;
90 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, N_("Go up:"), &cfgKeyboard.keyUp);
91 	MenuAddKeysym (8 * CELL_W, row, 5 * CELL_W, N_("Drop Bomb:"), &cfgKeyboard.keyBomb);
92 	row += CELL_H;
93 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, N_("Go down:"), &cfgKeyboard.keyDown);
94 	MenuAddKeysym (8 * CELL_W, row, 5 * CELL_W, N_("Special extra:"), &cfgKeyboard.keySpecial);
95 	row += CELL_H;
96 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, N_("Go left:"), &cfgKeyboard.keyLeft);
97 	MenuAddKeysym (8 * CELL_W, row, 5 * CELL_W, N_("Pause game:"), &cfgKeyboard.keyPause);
98 	row += CELL_H;
99 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, N_("Go right:"), &cfgKeyboard.keyRight);
100 	MenuAddKeysym (8 * CELL_W, row, 5 * CELL_W, N_("Abort level:"), &cfgKeyboard.keyAbort);
101 	/* Skywalker */
102 	row += CELL_H;
103 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, N_("Laola:"), &cfgKeyboard.keyLaola);
104 	MenuAddKeysym (8 * CELL_W, row, 5 * CELL_W, N_("Looser:"), &cfgKeyboard.keyLooser);
105 	/* */
106 	row += CELL_H;
107 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, N_("Stop:"), &cfgKeyboard.keyStop);
108 	MenuAddKeysym (8 * CELL_W, row, 5 * CELL_W, N_("Cancel abort:"), &cfgKeyboard.keyAbortCancel);
109 	row += CELL_H;
110 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, N_("Bot:"), &cfgKeyboard.keyBot);
111 	MenuAddKeysym (8 * CELL_W, row, 5 * CELL_W, N_("Chat Send:"), &cfgKeyboard.keyChatSend);
112 	row += CELL_H;
113 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, N_("Chat Start:"), &cfgKeyboard.keyChatStart);
114 	MenuAddKeysym (8 * CELL_W, row, 5 * CELL_W, N_("Chat Cancel:"), &cfgKeyboard.keyChatCancel);
115 	/* ok and cancel */
116 	MenuSetAbort (MenuAddHButton
117 				  (3 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, N_("Cancel"), CreateConfigControlMenu,
118 				   NULL));
119 	MenuAddHButton (11 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, N_("Next"), CreateConfigKeyboardMenu1,
120 					par);
121 	MenuSetDefault (MenuAddHButton
122 					(19 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, N_("Ok"), ButtonSaveKeyboard, par));
123 	/* --- */
124 	MenuSetLinks ();
125 	/* that's all */
126 	return XBFalse;
127 }								/* CreateConfigKeyboardMenu */
128 
129 /*
130  * store keyboard configuration
131  */
132 static XBBool
BackToCreateConfigKeyboard(void * par)133 BackToCreateConfigKeyboard (void *par)
134 {
135 	XBEventCode *pCtrl = par;
136 
137 	assert (pCtrl != NULL);
138 	StoreControlKeyboard (*pCtrl, &cfgKeyboard);
139 	GUI_UpdateKeyTables ();
140 	return CreateConfigKeyboardMenu (par);
141 }								/* BackToCreateConfigKeyboard */
142 
143 /*
144  * menu to configure keyboard
145  */
146 static XBBool
CreateConfigKeyboardMenu1(void * par)147 CreateConfigKeyboardMenu1 (void *par)
148 {
149 	XBEventCode *pCtrl = par;
150 	int row;
151 
152 	assert (pCtrl != NULL);
153 	/* retrieve controls */
154 	StoreControlKeyboard (*pCtrl, &cfgKeyboard);
155 	GUI_UpdateKeyTables ();
156 	if (!RetrieveControlKeyboard (*pCtrl, &cfgKeyboard)) {
157 		memset (&cfgKeyboard, 0, sizeof (cfgKeyboard));
158 	}
159 	MenuClear ();
160 	/* title */
161 	MenuAddLabel (TITLE_LEFT, TITLE_TOP, TITLE_WIDTH, N_("Configure Keyboard"));
162 	/* Buttons */
163 	row = MENU_TOP;
164 	/* ok and cancel */
165 	MenuAddKeysym (2 * CELL_W, row, 5 * CELL_W, "Chatmsg Rec.:",
166 				   &cfgKeyboard.keyChatChangeReceiver);
167 
168 	MenuSetAbort (MenuAddHButton
169 				  (3 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, N_("Cancel"), CreateConfigControlMenu,
170 				   NULL));
171 	MenuAddHButton (11 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, N_("Last"), BackToCreateConfigKeyboard,
172 					par);
173 	MenuSetDefault (MenuAddHButton
174 					(19 * CELL_W / 2, MENU_BOTTOM, 3 * CELL_W, N_("Ok"), ButtonSaveKeyboard, par));
175 	/* --- */
176 	MenuSetLinks ();
177 	/* that's all */
178 	return XBFalse;
179 }								/* CreateConfigKeyboardMenu */
180 
181 /*
182  * menu to select input device to configure
183  */
184 XBBool
CreateConfigControlMenu(void * par)185 CreateConfigControlMenu (void *par)
186 {
187 	int i, row;
188 	int numJoysticks = GUI_NumJoysticks ();
189 	MENU_ID id;
190 
191 	MenuClear ();
192 	/* title */
193 	MenuAddLabel (TITLE_LEFT, TITLE_TOP, TITLE_WIDTH, N_("Configure Controls"));
194 	/* Buttons */
195 	row = MENU_TOP;
196 	MenuAddHButton (MENU_LEFT, row, MENU_WIDTH, N_("Right Keyboard"), CreateConfigKeyboardMenu,
197 					ctrl + PLAYER_KEYB_1);
198 	row += CELL_H;
199 	MenuAddHButton (MENU_LEFT, row, MENU_WIDTH, N_("Left Keyboard"), CreateConfigKeyboardMenu,
200 					ctrl + PLAYER_KEYB_2);
201 	row += CELL_H;
202 	for (i = 0; i < numJoysticks; i++) {
203 		id = MenuAddHButton (MENU_LEFT, row, MENU_WIDTH, joystickString[i], NULL, NULL);
204 		MenuSetActive (id, XBFalse);
205 		row += CELL_H;
206 	}
207 	MenuSetAbort (MenuAddHButton
208 				  (MENU_LEFT, MENU_BOTTOM, MENU_WIDTH, N_("Options Menu"), CreateOptionsMenu, NULL));
209 	row += CELL_H;
210 	MenuSetLinks ();
211 	/* that's all */
212 	return XBFalse;
213 }								/* CreateConfigControlMenu */
214 
215 /*
216  * end of file menu_control.c
217  */
218