hedgewars/uKeys.pas
changeset 6654 120e95c10532
parent 6580 6155187bf599
child 6700 e04da46ee43c
equal deleted inserted replaced
6653:d45b6dbd2ad6 6654:120e95c10532
    38 procedure ControllerClose;
    38 procedure ControllerClose;
    39 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
    39 procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
    40 procedure ControllerHatEvent(joy, hat, value: Byte);
    40 procedure ControllerHatEvent(joy, hat, value: Byte);
    41 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
    41 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
    42 
    42 
    43 {$IFDEF IPHONEOS}
    43 {$IFDEF MOBILE}
    44 procedure setiPhoneBinds;
    44 procedure setiPhoneBinds;
    45 {$ENDIF}
    45 {$ENDIF}
    46 
    46 
    47 implementation
    47 implementation
    48 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug;
    48 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug;
    61 
    61 
    62 procedure ProcessKbd;
    62 procedure ProcessKbd;
    63 var  i, j, k: LongInt;
    63 var  i, j, k: LongInt;
    64      s: shortstring;
    64      s: shortstring;
    65      Trusted: boolean;
    65      Trusted: boolean;
    66 {$IFNDEF IPHONEOS}pkbd: PByteArray;{$ENDIF}
    66 {$IFNDEF MOBILE}pkbd: PByteArray;{$ENDIF}
    67 begin
    67 begin
    68 hideAmmoMenu:= false;
    68 hideAmmoMenu:= false;
    69 Trusted:= (CurrentTeam <> nil)
    69 Trusted:= (CurrentTeam <> nil)
    70           and (not CurrentTeam^.ExtDriven)
    70           and (not CurrentTeam^.ExtDriven)
    71           and (CurrentHedgehog^.BotLevel = 0);
    71           and (CurrentHedgehog^.BotLevel = 0);
    74 // TODO: Scale on screen dimensions and/or axis value (game controller)?
    74 // TODO: Scale on screen dimensions and/or axis value (game controller)?
    75 movecursor(5 * CursorMovementX, 5 * CursorMovementY);
    75 movecursor(5 * CursorMovementX, 5 * CursorMovementY);
    76 
    76 
    77 k:= SDL_GetMouseState(nil, nil);
    77 k:= SDL_GetMouseState(nil, nil);
    78 
    78 
    79 {$IFDEF IPHONEOS}
    79 {$IFDEF MOBILE}
    80 SDL_GetKeyState(@j);
    80 SDL_GetKeyState(@j);
    81 {$ELSE}
    81 {$ELSE}
    82 pkbd:= SDL_GetKeyState(@j);
    82 pkbd:= SDL_GetKeyState(@j);
    83 for i:= 6 to pred(j) do // first 6 will be overwritten
    83 for i:= 6 to pred(j) do // first 6 will be overwritten
    84     tkbdn[i]:= pkbd^[i];
    84     tkbdn[i]:= pkbd^[i];
    98 tkbdn[4]:= ord(wheelDown);
    98 tkbdn[4]:= ord(wheelDown);
    99 tkbdn[5]:= ord(wheelUp);
    99 tkbdn[5]:= ord(wheelUp);
   100 wheelUp:= false;
   100 wheelUp:= false;
   101 wheelDown:= false;
   101 wheelDown:= false;
   102 
   102 
   103 {$IFDEF IPHONEOS}
   103 {$IFDEF MOBILE}
   104 setiPhoneBinds();
   104 setiPhoneBinds();
   105 {$ELSE}
   105 {$ELSE}
   106 // Controller(s)
   106 // Controller(s)
   107 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   107 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   108 for j:= 0 to Pred(ControllerNumControllers) do
   108 for j:= 0 to Pred(ControllerNumControllers) do
   168     end
   168     end
   169 end;
   169 end;
   170 
   170 
   171 procedure ResetKbd;
   171 procedure ResetKbd;
   172 var j, k, t: LongInt;
   172 var j, k, t: LongInt;
   173 {$IFNDEF IPHONEOS}
   173 {$IFNDEF MOBILE}
   174     i: LongInt;
   174     i: LongInt;
   175     pkbd: PByteArray;
   175     pkbd: PByteArray;
   176 {$ENDIF}
   176 {$ENDIF}
   177 begin
   177 begin
   178 
   178 
   179 k:= SDL_GetMouseState(nil, nil);
   179 k:= SDL_GetMouseState(nil, nil);
   180 {$IFNDEF IPHONEOS}pkbd:={$ENDIF}SDL_GetKeyState(@j);
   180 {$IFNDEF MOBILE}pkbd:={$ENDIF}SDL_GetKeyState(@j);
   181 
   181 
   182 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + IntToStr(j) + ')', true);
   182 TryDo(j < cKeyMaxIndex, 'SDL keys number is more than expected (' + IntToStr(j) + ')', true);
   183 
   183 
   184 {$IFNDEF IPHONEOS}
   184 {$IFNDEF MOBILE}
   185 for i:= 1 to pred(j) do
   185 for i:= 1 to pred(j) do
   186     tkbdn[i]:= pkbd^[i];
   186     tkbdn[i]:= pkbd^[i];
   187 {$ENDIF}
   187 {$ENDIF}
   188 
   188 
   189 // mouse buttons
   189 // mouse buttons
   200 tkbdn[4]:= ord(wheelDown);
   200 tkbdn[4]:= ord(wheelDown);
   201 tkbdn[5]:= ord(wheelUp);
   201 tkbdn[5]:= ord(wheelUp);
   202 wheelUp:= false;
   202 wheelUp:= false;
   203 wheelDown:= false;
   203 wheelDown:= false;
   204 
   204 
   205 {$IFDEF IPHONEOS}
   205 {$IFDEF MOBILE}
   206 setiPhoneBinds();
   206 setiPhoneBinds();
   207 {$ELSE}
   207 {$ELSE}
   208 // Controller(s)
   208 // Controller(s)
   209 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   209 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   210 for j:= 0 to Pred(ControllerNumControllers) do
   210 for j:= 0 to Pred(ControllerNumControllers) do
   323 DefaultBinds[ 3]:= 'ammomenu';
   323 DefaultBinds[ 3]:= 'ammomenu';
   324 DefaultBinds[ 8]:= 'hjump';
   324 DefaultBinds[ 8]:= 'hjump';
   325 DefaultBinds[ 9]:= 'switch';
   325 DefaultBinds[ 9]:= 'switch';
   326 DefaultBinds[13]:= 'ljump';
   326 DefaultBinds[13]:= 'ljump';
   327 DefaultBinds[32]:= '+attack';
   327 DefaultBinds[32]:= '+attack';
   328 {$IFDEF IPHONEOS}
   328 {$IFDEF MOBILE}
   329 DefaultBinds[23]:= '+up';
   329 DefaultBinds[23]:= '+up';
   330 DefaultBinds[24]:= '+down';
   330 DefaultBinds[24]:= '+down';
   331 DefaultBinds[25]:= '+left';
   331 DefaultBinds[25]:= '+left';
   332 DefaultBinds[26]:= '+right';
   332 DefaultBinds[26]:= '+right';
   333 DefaultBinds[27]:= '+precise';
   333 DefaultBinds[27]:= '+precise';
   347 SetDefaultBinds();
   347 SetDefaultBinds();
   348 end;
   348 end;
   349 
   349 
   350 procedure SetBinds(var binds: TBinds);
   350 procedure SetBinds(var binds: TBinds);
   351 begin
   351 begin
   352 {$IFDEF IPHONEOS}
   352 {$IFDEF MOBILE}
   353     binds:= binds; // avoid hint
   353     binds:= binds; // avoid hint
   354     CurrentBinds:= DefaultBinds;
   354     CurrentBinds:= DefaultBinds;
   355 {$ELSE}
   355 {$ELSE}
   356     CurrentBinds:= binds;
   356     CurrentBinds:= binds;
   357 {$ENDIF}
   357 {$ENDIF}
   360 procedure SetDefaultBinds;
   360 procedure SetDefaultBinds;
   361 begin
   361 begin
   362     CurrentBinds:= DefaultBinds;
   362     CurrentBinds:= DefaultBinds;
   363 end;
   363 end;
   364 
   364 
   365 {$IFDEF IPHONEOS}
   365 {$IFDEF MOBILE}
   366 procedure setiPhoneBinds;
   366 procedure setiPhoneBinds;
   367 begin
   367 begin
   368     tkbdn[ 1]:= ord(leftClick);
   368     tkbdn[ 1]:= ord(leftClick);
   369     tkbdn[ 2]:= ord(middleClick);
   369     tkbdn[ 2]:= ord(middleClick);
   370     tkbdn[ 3]:= ord(rightClick);
   370     tkbdn[ 3]:= ord(rightClick);
   409 
   409 
   410 procedure ControllerInit;
   410 procedure ControllerInit;
   411 var i, j: Integer;
   411 var i, j: Integer;
   412 begin
   412 begin
   413 ControllerEnabled:= 0;
   413 ControllerEnabled:= 0;
   414 {$IFDEF IPHONEOS}
   414 {$IFDEF MOBILE}
   415 exit; // joystick subsystem disabled on iPhone
   415 exit; // joystick subsystem disabled on iPhone
   416 {$ENDIF}
   416 {$ENDIF}
   417 
   417 
   418 SDL_InitSubSystem(SDL_INIT_JOYSTICK);
   418 SDL_InitSubSystem(SDL_INIT_JOYSTICK);
   419 ControllerNumControllers:= SDL_NumJoysticks();
   419 ControllerNumControllers:= SDL_NumJoysticks();