80 {$IFDEF IPHONEOS} |
80 {$IFDEF IPHONEOS} |
81 procedure setiPhoneBinds; |
81 procedure setiPhoneBinds; |
82 {$ENDIF} |
82 {$ENDIF} |
83 {$ENDIF} |
83 {$ENDIF} |
84 implementation |
84 implementation |
85 uses uConsole, uCommands, uMisc, uVariables, uConsts; |
85 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils; |
86 //const KeyNumber = 1024; |
86 //const KeyNumber = 1024; |
87 |
87 |
88 var tkbd, tkbdn: TKeyboardState; |
88 var tkbd, tkbdn: TKeyboardState; |
89 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
89 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
90 |
90 |
191 begin |
191 begin |
192 |
192 |
193 k:= SDL_GetMouseState(nil, nil); |
193 k:= SDL_GetMouseState(nil, nil); |
194 {$IFNDEF IPHONEOS}pkbd:={$ENDIF}SDL_GetKeyState(@j); |
194 {$IFNDEF IPHONEOS}pkbd:={$ENDIF}SDL_GetKeyState(@j); |
195 |
195 |
196 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(j) + ')', true); |
196 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + IntToStr(j) + ')', true); |
197 |
197 |
198 {$IFNDEF IPHONEOS} |
198 {$IFNDEF IPHONEOS} |
199 for i:= 1 to pred(j) do |
199 for i:= 1 to pred(j) do |
200 tkbdn[i]:= pkbd^[i]; |
200 tkbdn[i]:= pkbd^[i]; |
201 {$ENDIF} |
201 {$ENDIF} |
260 KeyNames[5]:= 'wheeldown'; |
260 KeyNames[5]:= 'wheeldown'; |
261 |
261 |
262 for i:= 6 to cKeyMaxIndex do |
262 for i:= 6 to cKeyMaxIndex do |
263 begin |
263 begin |
264 s:= shortstring(sdl_getkeyname(i)); |
264 s:= shortstring(sdl_getkeyname(i)); |
265 //writeln(stdout,inttostr(i) + ': ' + s); |
265 //writeln(stdout,IntToStr(i) + ': ' + s); |
266 if s = 'unknown key' then KeyNames[i]:= '' |
266 if s = 'unknown key' then KeyNames[i]:= '' |
267 else |
267 else |
268 begin |
268 begin |
269 for t:= 1 to Length(s) do |
269 for t:= 1 to Length(s) do |
270 if s[t] = ' ' then s[t]:= '_'; |
270 if s[t] = ' ' then s[t]:= '_'; |
271 KeyNames[i]:= s |
271 KeyNames[i]:= s |
272 end; |
272 end; |
273 end; |
273 end; |
274 |
274 |
275 //for i:= 0 to cKeyMaxIndex do writeln(stdout,inttostr(i) + ': ' + KeyNames[i]); |
275 //for i:= 0 to cKeyMaxIndex do writeln(stdout,IntToStr(i) + ': ' + KeyNames[i]); |
276 |
276 |
277 // get the size of keyboard array |
277 // get the size of keyboard array |
278 SDL_GetKeyState(@k); |
278 SDL_GetKeyState(@k); |
279 |
279 |
280 // Controller(s) |
280 // Controller(s) |
281 for j:= 0 to Pred(ControllerNumControllers) do |
281 for j:= 0 to Pred(ControllerNumControllers) do |
282 begin |
282 begin |
283 for i:= 0 to Pred(ControllerNumAxes[j]) do |
283 for i:= 0 to Pred(ControllerNumAxes[j]) do |
284 begin |
284 begin |
285 keynames[k + 0]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'u'; |
285 keynames[k + 0]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'u'; |
286 keynames[k + 1]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'd'; |
286 keynames[k + 1]:= 'j' + IntToStr(j) + 'a' + IntToStr(i) + 'd'; |
287 inc(k, 2); |
287 inc(k, 2); |
288 end; |
288 end; |
289 for i:= 0 to Pred(ControllerNumHats[j]) do |
289 for i:= 0 to Pred(ControllerNumHats[j]) do |
290 begin |
290 begin |
291 keynames[k + 0]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'u'; |
291 keynames[k + 0]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'u'; |
292 keynames[k + 1]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'r'; |
292 keynames[k + 1]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'r'; |
293 keynames[k + 2]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'd'; |
293 keynames[k + 2]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'd'; |
294 keynames[k + 3]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'l'; |
294 keynames[k + 3]:= 'j' + IntToStr(j) + 'h' + IntToStr(i) + 'l'; |
295 inc(k, 4); |
295 inc(k, 4); |
296 end; |
296 end; |
297 for i:= 0 to Pred(ControllerNumButtons[j]) do |
297 for i:= 0 to Pred(ControllerNumButtons[j]) do |
298 begin |
298 begin |
299 keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i); |
299 keynames[k]:= 'j' + IntToStr(j) + 'b' + IntToStr(i); |
300 inc(k, 1); |
300 inc(k, 1); |
301 end; |
301 end; |
302 end; |
302 end; |
303 |
303 |
304 DefaultBinds[ 27]:= 'quit'; |
304 DefaultBinds[ 27]:= 'quit'; |
345 DefaultBinds[KeyNameToCode('left')]:= '+left'; |
345 DefaultBinds[KeyNameToCode('left')]:= '+left'; |
346 DefaultBinds[KeyNameToCode('right')]:= '+right'; |
346 DefaultBinds[KeyNameToCode('right')]:= '+right'; |
347 DefaultBinds[KeyNameToCode('left_shift')]:= '+precise'; |
347 DefaultBinds[KeyNameToCode('left_shift')]:= '+precise'; |
348 {$ENDIF} |
348 {$ENDIF} |
349 |
349 |
350 for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+inttostr(i))]:= 'slot '+inttostr(i); |
350 for i:= 1 to 10 do DefaultBinds[KeyNameToCode('f'+IntToStr(i))]:= 'slot '+IntToStr(i); |
351 |
351 |
352 SetDefaultBinds(); |
352 SetDefaultBinds(); |
353 end; |
353 end; |
354 |
354 |
355 procedure SetBinds(var binds: TBinds); |
355 procedure SetBinds(var binds: TBinds); |
420 |
420 |
421 SDL_InitSubSystem(SDL_INIT_JOYSTICK); |
421 SDL_InitSubSystem(SDL_INIT_JOYSTICK); |
422 ControllerNumControllers:= SDL_NumJoysticks(); |
422 ControllerNumControllers:= SDL_NumJoysticks(); |
423 if ControllerNumControllers > 6 then ControllerNumControllers:= 6; |
423 if ControllerNumControllers > 6 then ControllerNumControllers:= 6; |
424 |
424 |
425 WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers)); |
425 WriteLnToConsole('Number of game controllers: ' + IntToStr(ControllerNumControllers)); |
426 |
426 |
427 if ControllerNumControllers > 0 then |
427 if ControllerNumControllers > 0 then |
428 begin |
428 begin |
429 for j:= 0 to pred(ControllerNumControllers) do |
429 for j:= 0 to pred(ControllerNumControllers) do |
430 begin |
430 begin |
436 begin |
436 begin |
437 ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
437 ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]); |
438 //ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
438 //ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]); |
439 ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
439 ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]); |
440 ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
440 ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]); |
441 WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j])); |
441 WriteLnToConsole('* Number of axes: ' + IntToStr(ControllerNumAxes[j])); |
442 //WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j])); |
442 //WriteLnToConsole('* Number of balls: ' + IntToStr(ControllerNumBalls[j])); |
443 WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j])); |
443 WriteLnToConsole('* Number of hats: ' + IntToStr(ControllerNumHats[j])); |
444 WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j])); |
444 WriteLnToConsole('* Number of buttons: ' + IntToStr(ControllerNumButtons[j])); |
445 ControllerEnabled:= 1; |
445 ControllerEnabled:= 1; |
446 |
446 |
447 if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; |
447 if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20; |
448 //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
448 //if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20; |
449 if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; |
449 if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20; |