hedgewars/uKeys.pas
author unc0rr
Mon, 12 Oct 2009 16:44:30 +0000
changeset 2428 6800f8aa0184
parent 2407 9f413bd5150e
child 2436 246ef6271470
permissions -rw-r--r--
Huge Smaxx patch with some fixes by me: - support for non power of two textures - modelview matrix calculation optimizations - health effect when picking up health crates or using vampirism - rc plane training time trial - fix visual gear drawing position (might require recheck) - gamepad support - reordered options in frontend - updated binding options (subcaptions, descriptions and localizable names) - cfg-dir parameter for frontend (allows teams/settings to sit on a usb flash drive for example) - icons for chatroom user list
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     1
(*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 1051
diff changeset
     2
 * Hedgewars, a free turn based strategy game
883
07a568ba44e0 Update copyright info in source files headers
unc0rr
parents: 846
diff changeset
     3
 * Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com>
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     4
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
     8
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    12
 * GNU General Public License for more details.
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    13
 *
183
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    14
 * You should have received a copy of the GNU General Public License
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    15
 * along with this program; if not, write to the Free Software
57c2ef19f719 Relicense to GPL
unc0rr
parents: 176
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    17
 *)
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    18
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    19
unit uKeys;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    20
interface
345
fa39c61be4de Some fixes, revert debug code
unc0rr
parents: 299
diff changeset
    21
uses uConsts;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    22
{$INCLUDE options.inc}
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    23
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    24
type TBinds = array[0..cKeyMaxIndex] of shortstring;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    25
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    26
function KeyNameToCode(name: string): word;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    27
procedure ProcessKbd;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    28
procedure ResetKbd;
948
5d49a92c240a Fix chat behavior
unc0rr
parents: 947
diff changeset
    29
procedure FreezeEnterKey;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    30
procedure InitKbdKeyTable;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    31
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    32
procedure SetBinds(var binds: TBinds);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    33
procedure SetDefaultBinds;
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    34
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    35
procedure ControllerInit;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    36
procedure ControllerClose;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    37
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    38
procedure ControllerHatEvent(joy, hat, value: Byte);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    39
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    40
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    41
var hideAmmoMenu: boolean;
2379
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
    42
	wheelUp: boolean = false;
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
    43
	wheelDown: boolean = false;
161
d8870bbf960e - AmmoMenu
unc0rr
parents: 109
diff changeset
    44
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    45
	ControllerNumControllers: Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    46
    ControllerEnabled: Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    47
    ControllerNumAxes: array[0..5] of Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    48
    //ControllerNumBalls: array[0..5] of Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    49
	ControllerNumHats: array[0..5] of Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    50
	ControllerNumButtons: array[0..5] of Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    51
	ControllerAxes: array[0..5] of array[0..19] of Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    52
	//ControllerBalls: array[0..5] of array[0..19] of array[0..1] of Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    53
	ControllerHats: array[0..5] of array[0..19] of Byte;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    54
	ControllerButtons: array[0..5] of array[0..19] of Byte;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    55
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    56
implementation
2222
2e98698b76aa reworked progress structure
koda
parents: 2171
diff changeset
    57
uses SDLh, uTeams, uConsole, uMisc, uStore;
109
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 42
diff changeset
    58
const KeyNumber = 1024;
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 42
diff changeset
    59
type TKeyboardState = array[0..cKeyMaxIndex] of Byte;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    60
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    61
var tkbd: TKeyboardState;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    62
    KeyNames: array [0..cKeyMaxIndex] of string[15];
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    63
    DefaultBinds, CurrentBinds: TBinds;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    64
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    65
function KeyNameToCode(name: string): word;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 345
diff changeset
    66
var Result: Word;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    67
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    68
Result:= cKeyMaxIndex;
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 345
diff changeset
    69
while (Result > 0) and (KeyNames[Result] <> name) do dec(Result);
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 345
diff changeset
    70
KeyNameToCode:= Result
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    71
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    72
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    73
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    74
procedure ProcessKbd;
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    75
var  i, j, k: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    76
     pkbd: PByteArray;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    77
     Trusted: boolean;
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    78
     s: shortstring;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
    79
begin
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    80
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    81
hideAmmoMenu:= false;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
    82
Trusted:= (CurrentTeam <> nil)
351
29bc9c36ad5f Fixed-point arithmetics in engine.
unc0rr
parents: 345
diff changeset
    83
          and (not CurrentTeam^.ExtDriven)
846
08c3f0bc766c Fix bug with handling keys while it is AI's turn
unc0rr
parents: 626
diff changeset
    84
          and (CurrentHedgehog^.BotLevel = 0);
161
d8870bbf960e - AmmoMenu
unc0rr
parents: 109
diff changeset
    85
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    86
// move cursor/camera
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    87
// TODO: Scale on screen dimensions and/or axis value (game controller)?
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
    88
movecursor(5 * CursorMovementX, 5 * CursorMovementY);
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
    89
{$IFDEF SDL13}
2171
8208946331ba Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents: 2163
diff changeset
    90
pkbd := SDL_GetKeyboardState(nil);
2328
e74f2db28b21 improved fix for right click on mac
koda
parents: 2312
diff changeset
    91
i    := SDL_GetMouseState(0, nil, nil);
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
    92
{$ELSE}
2171
8208946331ba Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents: 2163
diff changeset
    93
pkbd := SDL_GetKeyState(nil);
2328
e74f2db28b21 improved fix for right click on mac
koda
parents: 2312
diff changeset
    94
i    := SDL_GetMouseState(nil, nil);
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
    95
{$ENDIF}
2379
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
    96
// mouse buttons
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
    97
{$IFDEF DARWIN}
2328
e74f2db28b21 improved fix for right click on mac
koda
parents: 2312
diff changeset
    98
pkbd^[1]:= ((i and 1) and not (pkbd^[306] or pkbd^[305]));
e74f2db28b21 improved fix for right click on mac
koda
parents: 2312
diff changeset
    99
pkbd^[3]:= ((i and 1) and (pkbd^[306] or pkbd^[305])) or (i and 4);
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
   100
{$ELSE}
2328
e74f2db28b21 improved fix for right click on mac
koda
parents: 2312
diff changeset
   101
pkbd^[1]:= (i and 1);
161
d8870bbf960e - AmmoMenu
unc0rr
parents: 109
diff changeset
   102
pkbd^[3]:= ((i shr 2) and 1);
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
   103
{$ENDIF}
2328
e74f2db28b21 improved fix for right click on mac
koda
parents: 2312
diff changeset
   104
pkbd^[2]:= ((i shr 1) and 1);
e74f2db28b21 improved fix for right click on mac
koda
parents: 2312
diff changeset
   105
2379
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   106
// mouse wheels (see event loop in project file)
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   107
pkbd^[4]:= ord(wheelDown);
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   108
pkbd^[5]:= ord(wheelUp);
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   109
wheelUp:= false;
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   110
wheelDown:= false;
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
   111
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   112
// Controller(s)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   113
k:= 500; // should we test k for hitting the limit? sounds rather unlikely to ever reach it
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   114
for j:= 0 to Pred(ControllerNumControllers) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   115
	begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   116
	for i:= 0 to Pred(ControllerNumAxes[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   117
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   118
		if ControllerAxes[j][i] > 20000 then pkbd^[k + 0]:= 1 else pkbd^[k + 0]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   119
		if ControllerAxes[j][i] < -20000 then pkbd^[k + 1]:= 1 else pkbd^[k + 1]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   120
		inc(k, 2);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   121
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   122
	for i:= 0 to Pred(ControllerNumHats[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   123
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   124
		pkbd^[k + 0]:= ControllerHats[j][i] and SDL_HAT_UP;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   125
		pkbd^[k + 1]:= ControllerHats[j][i] and SDL_HAT_RIGHT;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   126
		pkbd^[k + 2]:= ControllerHats[j][i] and SDL_HAT_DOWN;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   127
		pkbd^[k + 3]:= ControllerHats[j][i] and SDL_HAT_LEFT;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   128
		inc(k, 4);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   129
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   130
	for i:= 0 to Pred(ControllerNumButtons[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   131
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   132
		pkbd^[k]:= ControllerButtons[j][i];
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   133
		inc(k, 1);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   134
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   135
	end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   136
2379
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   137
// now process strokes
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   138
for i:= 1 to cKeyMaxIndex do
947
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   139
if CurrentBinds[i][0] <> #0 then
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   140
	begin
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   141
	if (i > 3) and (pkbd^[i] <> 0) and not (hideAmmoMenu or (CurrentBinds[i] = 'put') or (CurrentBinds[i] = 'ammomenu') or (CurrentBinds[i] = '+cur_u') or (CurrentBinds[i] = '+cur_d') or (CurrentBinds[i] = '+cur_l') or (CurrentBinds[i] = '+cur_r')) then hideAmmoMenu:= true;
947
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   142
	if (tkbd[i] = 0) and (pkbd^[i] <> 0) then ParseCommand(CurrentBinds[i], Trusted)
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   143
	else if (CurrentBinds[i][1] = '+')
948
5d49a92c240a Fix chat behavior
unc0rr
parents: 947
diff changeset
   144
			and (pkbd^[i] = 0)
5d49a92c240a Fix chat behavior
unc0rr
parents: 947
diff changeset
   145
			and (tkbd[i] <> 0) then
947
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   146
			begin
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   147
			s:= CurrentBinds[i];
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   148
			s[1]:= '-';
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   149
			ParseCommand(s, Trusted)
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   150
			end;
4e0c3ad89483 - 't' key for entering chat message
unc0rr
parents: 883
diff changeset
   151
	tkbd[i]:= pkbd^[i]
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   152
	end;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   153
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   154
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   155
procedure ResetKbd;
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   156
var i, j, k, t: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   157
    pkbd: PByteArray;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   158
begin
2171
8208946331ba Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents: 2163
diff changeset
   159
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
   160
{$IFDEF SDL13}
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
   161
pkbd:= PByteArray(SDL_GetKeyboardState(@i));
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
   162
{$ELSE}
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   163
pkbd:= PByteArray(SDL_GetKeyState(@i));
2152
a2811690da1b Patch by koda:
unc0rr
parents: 2008
diff changeset
   164
{$ENDIF}
109
ab0340f580c2 - Initialize translations earlier
unc0rr
parents: 42
diff changeset
   165
TryDo(i < cKeyMaxIndex, 'SDL keys number is more than expected (' + inttostr(i) + ')', true);
2171
8208946331ba Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents: 2163
diff changeset
   166
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   167
k:= 500;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   168
for j:= 0 to Pred(ControllerNumControllers) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   169
	begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   170
	for i:= 0 to Pred(ControllerNumAxes[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   171
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   172
		pkbd^[k + 0]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   173
		pkbd^[k + 1]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   174
		inc(k, 2);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   175
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   176
	for i:= 0 to Pred(ControllerNumHats[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   177
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   178
		pkbd^[k + 0]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   179
		pkbd^[k + 1]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   180
		pkbd^[k + 2]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   181
		pkbd^[k + 3]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   182
		inc(k, 4);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   183
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   184
	for i:= 0 to Pred(ControllerNumButtons[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   185
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   186
		pkbd^[k]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   187
		inc(k, 1);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   188
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   189
	end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   190
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   191
for t:= 0 to Pred(i) do
2284
bd091b6b128d - Remove one AddProgress call
unc0rr
parents: 2222
diff changeset
   192
    tkbd[i]:= pkbd^[i]
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   193
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   194
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   195
procedure InitKbdKeyTable;
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   196
var i, j, k, t: LongInt;
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   197
    s: string[15];
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   198
begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   199
KeyNames[1]:= 'mousel';
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   200
KeyNames[2]:= 'mousem';
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   201
KeyNames[3]:= 'mouser';
2379
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   202
KeyNames[4]:= 'wheelup';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   203
KeyNames[5]:= 'wheeldown';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   204
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   205
for i:= 6 to cKeyMaxIndex do
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   206
    begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   207
    s:= SDL_GetKeyName(i);
2379
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   208
	//addfilelog(inttostr(i) + ' ' + s);
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   209
    if s = 'unknown key' then KeyNames[i]:= ''
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   210
       else begin
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   211
       for t:= 1 to Length(s) do
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   212
           if s[t] = ' ' then s[t]:= '_';
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   213
       KeyNames[i]:= s
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   214
       end;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   215
    end;
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   216
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   217
// Controller(s)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   218
k:= 500;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   219
for j:= 0 to Pred(ControllerNumControllers) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   220
	begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   221
	for i:= 0 to Pred(ControllerNumAxes[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   222
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   223
		keynames[k + 0]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'u';
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   224
		keynames[k + 1]:= 'j' + inttostr(j) + 'a' + inttostr(i) + 'd';
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   225
		inc(k, 2);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   226
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   227
	for i:= 0 to Pred(ControllerNumHats[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   228
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   229
		keynames[k + 0]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'u';
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   230
		keynames[k + 1]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'r';
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   231
		keynames[k + 2]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'd';
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   232
		keynames[k + 3]:= 'j' + inttostr(j) + 'h' + inttostr(i) + 'l';
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   233
		inc(k, 4);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   234
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   235
	for i:= 0 to Pred(ControllerNumButtons[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   236
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   237
		keynames[k]:= 'j' + inttostr(j) + 'b' + inttostr(i);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   238
		inc(k, 1);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   239
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   240
	end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   241
	
2379
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   242
DefaultBinds[ 27]:= 'quit';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   243
DefaultBinds[ 96]:= 'history';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   244
DefaultBinds[127]:= 'rotmask';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   245
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   246
DefaultBinds[KeyNameToCode('0')]:= '+volup';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   247
DefaultBinds[KeyNameToCode('9')]:= '+voldown';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   248
DefaultBinds[KeyNameToCode('c')]:= 'capture';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   249
DefaultBinds[KeyNameToCode('h')]:= 'findhh';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   250
DefaultBinds[KeyNameToCode('p')]:= 'pause';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   251
DefaultBinds[KeyNameToCode('s')]:= '+speedup';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   252
DefaultBinds[KeyNameToCode('t')]:= 'chat';
d62b1f224982 - Implement zoom reset
unc0rr
parents: 2328
diff changeset
   253
DefaultBinds[KeyNameToCode('y')]:= 'confirm';
1051
dfdd5dfe97d4 Enable fullscreen switching back, now it's bound on F12
unc0rr
parents: 1022
diff changeset
   254
2407
9f413bd5150e - Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents: 2379
diff changeset
   255
DefaultBinds[KeyNameToCode('mousem')]:= 'zoomreset';
9f413bd5150e - Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents: 2379
diff changeset
   256
DefaultBinds[KeyNameToCode('wheelup')]:= 'zoomout';
9f413bd5150e - Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents: 2379
diff changeset
   257
DefaultBinds[KeyNameToCode('wheeldown')]:= 'zoomin';
9f413bd5150e - Fix mouse cursor bugs in net game (still has a bug near water)
unc0rr
parents: 2379
diff changeset
   258
1051
dfdd5dfe97d4 Enable fullscreen switching back, now it's bound on F12
unc0rr
parents: 1022
diff changeset
   259
DefaultBinds[KeyNameToCode('f12')]:= 'fullscr';
dfdd5dfe97d4 Enable fullscreen switching back, now it's bound on F12
unc0rr
parents: 1022
diff changeset
   260
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   261
SetDefaultBinds
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   262
end;
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   263
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   264
procedure SetBinds(var binds: TBinds);
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   265
begin
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   266
CurrentBinds:= binds
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   267
end;
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   268
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   269
procedure SetDefaultBinds;
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   270
begin
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   271
CurrentBinds:= DefaultBinds
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   272
end;
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   273
948
5d49a92c240a Fix chat behavior
unc0rr
parents: 947
diff changeset
   274
procedure FreezeEnterKey;
5d49a92c240a Fix chat behavior
unc0rr
parents: 947
diff changeset
   275
begin
5d49a92c240a Fix chat behavior
unc0rr
parents: 947
diff changeset
   276
tkbd[13]:= 1;
5d49a92c240a Fix chat behavior
unc0rr
parents: 947
diff changeset
   277
tkbd[271]:= 1
5d49a92c240a Fix chat behavior
unc0rr
parents: 947
diff changeset
   278
end;
167
805fa9a27e9e "Trusted" binds
unc0rr
parents: 161
diff changeset
   279
2428
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   280
var Controller: array [0..5] of PSDLJoystick;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   281
	
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   282
procedure ControllerInit;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   283
var i, j: Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   284
begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   285
ControllerEnabled:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   286
ControllerNumControllers:= SDL_NumJoysticks;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   287
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   288
if ControllerNumControllers > 6 then ControllerNumControllers:= 6;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   289
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   290
WriteLnToConsole('Number of game controllers: ' + inttostr(ControllerNumControllers));
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   291
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   292
if ControllerNumControllers > 0 then
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   293
	begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   294
	for j:= 0 to pred(ControllerNumControllers) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   295
		begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   296
		WriteLnToConsole('Using game controller: ' + SDL_JoystickName(j));
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   297
		Controller[j]:= SDL_JoystickOpen(j);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   298
		if Controller[j] = nil then
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   299
			WriteLnToConsole('* Failed to open game controller!')
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   300
		else
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   301
			begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   302
			ControllerNumAxes[j]:= SDL_JoystickNumAxes(Controller[j]);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   303
			//ControllerNumBalls[j]:= SDL_JoystickNumBalls(Controller[j]);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   304
			ControllerNumHats[j]:= SDL_JoystickNumHats(Controller[j]);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   305
			ControllerNumButtons[j]:= SDL_JoystickNumButtons(Controller[j]);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   306
			WriteLnToConsole('* Number of axes: ' + inttostr(ControllerNumAxes[j]));
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   307
			//WriteLnToConsole('* Number of balls: ' + inttostr(ControllerNumBalls[j]));
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   308
			WriteLnToConsole('* Number of hats: ' + inttostr(ControllerNumHats[j]));
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   309
			WriteLnToConsole('* Number of buttons: ' + inttostr(ControllerNumButtons[j]));
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   310
			ControllerEnabled:= 1;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   311
			
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   312
			if ControllerNumAxes[j] > 20 then ControllerNumAxes[j]:= 20;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   313
			//if ControllerNumBalls[j] > 20 then ControllerNumBalls[j]:= 20;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   314
			if ControllerNumHats[j] > 20 then ControllerNumHats[j]:= 20;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   315
			if ControllerNumButtons[j] > 20 then ControllerNumButtons[j]:= 20;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   316
			
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   317
			// reset all buttons/axes
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   318
			for i:= 0 to pred(ControllerNumAxes[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   319
				ControllerAxes[j][i]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   320
			(*for i:= 0 to pred(ControllerNumBalls[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   321
				begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   322
				ControllerBalls[j][i][0]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   323
				ControllerBalls[j][i][1]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   324
				end;*)
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   325
			for i:= 0 to pred(ControllerNumHats[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   326
				ControllerHats[j][i]:= SDL_HAT_CENTERED;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   327
			for i:= 0 to pred(ControllerNumButtons[j]) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   328
				ControllerButtons[j][i]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   329
			end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   330
		end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   331
	// enable event generation/controller updating
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   332
	SDL_JoystickEventState(1);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   333
	end
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   334
else	
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   335
	WriteLnToConsole('Not using any game controller');
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   336
end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   337
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   338
procedure ControllerClose;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   339
var j: Integer;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   340
begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   341
if ControllerEnabled > 0 then
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   342
	for j:= 0 to pred(ControllerNumControllers) do
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   343
		SDL_JoystickClose(Controller[j]);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   344
end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   345
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   346
procedure ControllerAxisEvent(joy, axis: Byte; value: Integer);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   347
begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   348
	ControllerAxes[joy][axis]:= value;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   349
end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   350
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   351
procedure ControllerHatEvent(joy, hat, value: Byte);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   352
begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   353
	ControllerHats[joy][hat]:= value;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   354
end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   355
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   356
procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean);
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   357
begin
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   358
	if pressed then ControllerButtons[joy][button]:= 1 else ControllerButtons[joy][button]:= 0;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   359
end;
6800f8aa0184 Huge Smaxx patch with some fixes by me:
unc0rr
parents: 2407
diff changeset
   360
4
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   361
initialization
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   362
bcbd7adb4e4b - set svn:eol-style to native
unc0rr
parents: 1
diff changeset
   363
end.