hedgewars/uKeys.pas
changeset 4845 9a0f5377c529
parent 4751 849740a91d36
child 4850 434cd1284204
equal deleted inserted replaced
4843:673f74c89687 4845:9a0f5377c529
    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 var hideAmmoMenu: boolean;
       
    44     wheelUp: boolean;
       
    45     wheelDown: boolean;
       
    46 
       
    47     ControllerNumControllers: Integer;
       
    48     ControllerEnabled: Integer;
       
    49     ControllerNumAxes: array[0..5] of Integer;
       
    50     //ControllerNumBalls: array[0..5] of Integer;
       
    51     ControllerNumHats: array[0..5] of Integer;
       
    52     ControllerNumButtons: array[0..5] of Integer;
       
    53     ControllerAxes: array[0..5] of array[0..19] of Integer;
       
    54     //ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer;
       
    55     ControllerHats: array[0..5] of array[0..19] of Byte;
       
    56     ControllerButtons: array[0..5] of array[0..19] of Byte;
       
    57 
       
    58     DefaultBinds, CurrentBinds: TBinds;
       
    59 
       
    60     coeff: LongInt;
       
    61 {$IFDEF HWLIBRARY}
       
    62     leftClick: boolean;
       
    63     middleClick: boolean;
       
    64     rightClick: boolean;
       
    65 
       
    66     upKey: boolean;
       
    67     downKey: boolean;
       
    68     rightKey: boolean;
       
    69     leftKey: boolean;
       
    70     preciseKey: boolean;
       
    71 
       
    72     backspaceKey: boolean;
       
    73     spaceKey: boolean;
       
    74     enterKey: boolean;
       
    75     tabKey: boolean;
       
    76 
       
    77     chatAction: boolean;
       
    78     pauseAction: boolean;
       
    79 
       
    80 {$IFDEF IPHONEOS}
    43 {$IFDEF IPHONEOS}
    81 procedure setiPhoneBinds;
    44 procedure setiPhoneBinds;
    82 {$ENDIF}
    45 {$ENDIF}
    83 {$ENDIF}
    46 
    84 implementation
    47 implementation
    85 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug;
    48 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug;
    86 
    49 
    87 var tkbd, tkbdn: TKeyboardState;
    50 var tkbd, tkbdn: TKeyboardState;
    88     KeyNames: array [0..cKeyMaxIndex] of string[15];
    51     KeyNames: array [0..cKeyMaxIndex] of string[15];
   107           and (not CurrentTeam^.ExtDriven)
    70           and (not CurrentTeam^.ExtDriven)
   108           and (CurrentHedgehog^.BotLevel = 0);
    71           and (CurrentHedgehog^.BotLevel = 0);
   109 
    72 
   110 // move cursor/camera
    73 // move cursor/camera
   111 // TODO: Scale on screen dimensions and/or axis value (game controller)?
    74 // TODO: Scale on screen dimensions and/or axis value (game controller)?
   112 movecursor(coeff * CursorMovementX, coeff * CursorMovementY);
    75 movecursor(5 * CursorMovementX, 5 * CursorMovementY);
   113 
    76 
   114 k:= SDL_GetMouseState(nil, nil);
    77 k:= SDL_GetMouseState(nil, nil);
   115 
    78 
   116 {$IFDEF IPHONEOS}
    79 {$IFDEF IPHONEOS}
   117 SDL_GetKeyState(@j);
    80 SDL_GetKeyState(@j);
   137 wheelUp:= false;
   100 wheelUp:= false;
   138 wheelDown:= false;
   101 wheelDown:= false;
   139 
   102 
   140 {$IFDEF IPHONEOS}
   103 {$IFDEF IPHONEOS}
   141 setiPhoneBinds();
   104 setiPhoneBinds();
   142 {$ENDIF}
   105 {$ELSE}
   143 
       
   144 // Controller(s)
   106 // Controller(s)
   145 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
   146 for j:= 0 to Pred(ControllerNumControllers) do
   108 for j:= 0 to Pred(ControllerNumControllers) do
   147     begin
   109     begin
   148     for i:= 0 to Pred(ControllerNumAxes[j]) do
   110     for i:= 0 to Pred(ControllerNumAxes[j]) do
   162     for i:= 0 to Pred(ControllerNumButtons[j]) do
   124     for i:= 0 to Pred(ControllerNumButtons[j]) do
   163         begin
   125         begin
   164         tkbdn[k]:= ControllerButtons[j][i];
   126         tkbdn[k]:= ControllerButtons[j][i];
   165         inc(k, 1);
   127         inc(k, 1);
   166         end;
   128         end;
       
   129     end;
       
   130 {$ENDIF}
       
   131 
       
   132 // ctrl/cmd + w/q to close engine and/or frontend
       
   133 {$IFDEF DARWIN}
       
   134     if ((tkbdn[KeyNameToCode('left_meta')] = 1) or (tkbdn[KeyNameToCode('right_meta')] = 1)) then
       
   135 {$ELSE}
       
   136     if ((tkbdn[KeyNameToCode('left_ctrl')] = 1) or (tkbdn[KeyNameToCode('right_ctrl')] = 1)) then
       
   137 {$ENDIF}
       
   138     begin
       
   139         if tkbdn[KeyNameToCode('q')] = 1 then ParseCommand ('halt', true)
       
   140         else if tkbdn[KeyNameToCode('w')] = 1 then ParseCommand ('forcequit', true);
   167     end;
   141     end;
   168 
   142 
   169 // now process strokes
   143 // now process strokes
   170 for i:= 0 to cKeyMaxIndex do
   144 for i:= 0 to cKeyMaxIndex do
   171 if CurrentBinds[i][0] <> #0 then
   145 if CurrentBinds[i][0] <> #0 then
   220 wheelUp:= false;
   194 wheelUp:= false;
   221 wheelDown:= false;
   195 wheelDown:= false;
   222 
   196 
   223 {$IFDEF IPHONEOS}
   197 {$IFDEF IPHONEOS}
   224 setiPhoneBinds();
   198 setiPhoneBinds();
   225 {$ENDIF}
   199 {$ELSE}
   226 
       
   227 // Controller(s)
   200 // Controller(s)
   228 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   201 k:= j; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
   229 for j:= 0 to Pred(ControllerNumControllers) do
   202 for j:= 0 to Pred(ControllerNumControllers) do
   230     begin
   203     begin
   231     for i:= 0 to Pred(ControllerNumAxes[j]) do
   204     for i:= 0 to Pred(ControllerNumAxes[j]) do
   246         begin
   219         begin
   247         tkbdn[k]:= ControllerButtons[j][i];
   220         tkbdn[k]:= ControllerButtons[j][i];
   248         inc(k, 1);
   221         inc(k, 1);
   249         end;
   222         end;
   250     end;
   223     end;
       
   224 {$ENDIF}
   251 
   225 
   252 for t:= 0 to cKeyMaxIndex do
   226 for t:= 0 to cKeyMaxIndex do
   253     tkbd[i]:= tkbdn[i]
   227     tkbd[i]:= tkbdn[i]
   254 end;
   228 end;
   255 
   229 
   500 
   474 
   501 procedure initModule;
   475 procedure initModule;
   502 begin
   476 begin
   503     wheelUp:= false;
   477     wheelUp:= false;
   504     wheelDown:= false;
   478     wheelDown:= false;
   505     coeff:= 5;
       
   506 {$IFDEF HWLIBRARY}
   479 {$IFDEF HWLIBRARY}
   507     // this function is called by HW_allKeysUp so be careful
   480     // this function is called by HW_allKeysUp so be careful
   508 
   481 
   509     // mouse emulation
   482     // mouse emulation
   510     leftClick:= false;
   483     leftClick:= false;