43 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
43 procedure ControllerButtonEvent(joy, button: Byte; pressed: Boolean); |
44 |
44 |
45 implementation |
45 implementation |
46 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug; |
46 uses uConsole, uCommands, uMisc, uVariables, uConsts, uUtils, uDebug; |
47 |
47 |
48 var tkbd: TKeyboardState; |
48 var tkbd: array[0..cKeyMaxIndex] of boolean; |
49 quitKeyCode: Byte; |
49 quitKeyCode: Byte; |
50 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
50 KeyNames: array [0..cKeyMaxIndex] of string[15]; |
51 CurrentBinds: TBinds; |
51 CurrentBinds: TBinds; |
52 |
52 |
53 function KeyNameToCode(name: shortstring): word; |
53 function KeyNameToCode(name: shortstring): word; |
62 procedure ProcessKey(code: LongInt; KeyDown: boolean); |
62 procedure ProcessKey(code: LongInt; KeyDown: boolean); |
63 var |
63 var |
64 Trusted: boolean; |
64 Trusted: boolean; |
65 s : string; |
65 s : string; |
66 begin |
66 begin |
|
67 |
|
68 if not(tkbd[code] xor KeyDown) then exit; |
|
69 tkbd[code]:= KeyDown; |
|
70 |
|
71 |
67 hideAmmoMenu:= false; |
72 hideAmmoMenu:= false; |
68 Trusted:= (CurrentTeam <> nil) |
73 Trusted:= (CurrentTeam <> nil) |
69 and (not CurrentTeam^.ExtDriven) |
74 and (not CurrentTeam^.ExtDriven) |
70 and (CurrentHedgehog^.BotLevel = 0); |
75 and (CurrentHedgehog^.BotLevel = 0); |
71 |
76 |
72 tkbd[code]:= ord(KeyDown); |
77 |
73 |
78 |
74 // ctrl/cmd + q to close engine and frontend |
79 // ctrl/cmd + q to close engine and frontend |
75 if(KeyDown and (code = quitKeyCode)) then |
80 if(KeyDown and (code = quitKeyCode)) then |
76 begin |
81 begin |
77 {$IFDEF DARWIN} |
82 {$IFDEF DARWIN} |
78 if ((tkbd[KeyNameToCode('left_meta')] = 1) or (tkbd[KeyNameToCode('right_meta')] = 1)) then |
83 if tkbd[KeyNameToCode('left_meta')] or tkbd[KeyNameToCode('right_meta')] then |
79 {$ELSE} |
84 {$ELSE} |
80 if ((tkbd[KeyNameToCode('left_ctrl')] = 1) or (tkbd[KeyNameToCode('right_ctrl')] = 1)) then |
85 if tkbd[KeyNameToCode('left_ctrl')] or tkbd[KeyNameToCode('right_ctrl')] then |
81 {$ENDIF} |
86 {$ENDIF} |
82 ParseCommand('halt', true); |
87 ParseCommand('halt', true); |
83 end; |
88 end; |
84 |
89 |
85 if CurrentBinds[code][0] <> #0 then |
90 if CurrentBinds[code][0] <> #0 then |
86 begin |
91 begin |
87 if (code > 3) and (KeyDown) and not ((CurrentBinds[code] = 'put') or (CurrentBinds[code] = 'ammomenu') or (CurrentBinds[code] = '+cur_u') or (CurrentBinds[code] = '+cur_d') or (CurrentBinds[code] = '+cur_l') or (CurrentBinds[code] = '+cur_r')) then hideAmmoMenu:= true; |
92 if (code > 3) and KeyDown and not ((CurrentBinds[code] = 'put') or (CurrentBinds[code] = 'ammomenu') or (CurrentBinds[code] = '+cur_u') or (CurrentBinds[code] = '+cur_d') or (CurrentBinds[code] = '+cur_l') or (CurrentBinds[code] = '+cur_r')) then hideAmmoMenu:= true; |
88 |
93 |
89 if (KeyDown) then |
94 if KeyDown then |
90 begin |
95 begin |
91 ParseCommand(CurrentBinds[code], Trusted); |
96 ParseCommand(CurrentBinds[code], Trusted); |
92 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
97 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
93 ParseCommand('gencmd R', true) |
98 ParseCommand('gencmd R', true) |
94 end |
99 end |
95 else if (CurrentBinds[code][1] = '+') and not KeyDown then |
100 else if (CurrentBinds[code][1] = '+') then |
96 begin |
101 begin |
97 s:= CurrentBinds[code]; |
102 s:= CurrentBinds[code]; |
98 s[1]:= '-'; |
103 s[1]:= '-'; |
99 ParseCommand(s, Trusted); |
104 ParseCommand(s, Trusted); |
100 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
105 if (CurrentTeam <> nil) and (not CurrentTeam^.ExtDriven) and (ReadyTimeLeft > 1) then |
101 ParseCommand('gencmd R', true) |
106 ParseCommand('gencmd R', true) |
102 end; |
107 end; |
103 end |
108 end |
104 |
|
105 end; |
109 end; |
106 |
110 |
107 procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
111 procedure ProcessKey(event: TSDL_KeyboardEvent); inline; |
108 begin |
112 begin |
109 ProcessKey(event.keysym.sym, event.type_ = SDL_KEYDOWN); |
113 ProcessKey(event.keysym.sym, event.type_ = SDL_KEYDOWN); |
127 |
131 |
128 procedure ResetKbd; |
132 procedure ResetKbd; |
129 var t: LongInt; |
133 var t: LongInt; |
130 begin |
134 begin |
131 for t:= 0 to cKeyMaxIndex do |
135 for t:= 0 to cKeyMaxIndex do |
132 if(tkbd[t] <> 0) then |
136 if tkbd[t] then |
133 ProcessKey(t, False); |
137 ProcessKey(t, False); |
134 end; |
138 end; |
135 |
139 |
136 procedure InitKbdKeyTable; |
140 procedure InitKbdKeyTable; |
137 var i, j, k, t: LongInt; |
141 var i, j, k, t: LongInt; |