From: DeaDDooMER Date: Fri, 5 Apr 2019 14:21:06 +0000 (+0300) Subject: fix virtual keyboard X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=31039aaf7e1623de1a4be292d0c77532fcfbf3e6;p=d2df-sdl.git fix virtual keyboard --- diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index bf7f614..b93ca59 100644 --- a/src/engine/e_input.pas +++ b/src/engine/e_input.pas @@ -174,6 +174,8 @@ const VK_LSTRAFE = VK_FIRSTKEY + 31; VK_RSTRAFE = VK_FIRSTKEY + 32; VK_PRINTSCR = VK_FIRSTKEY + 33; + VK_SHOWKBD = VK_FIRSTKEY + 34; + VK_HIDEKBD = VK_FIRSTKEY + 35; VK_LASTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1; AX_MINUS = 0; diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 5439a0f..fd8e24b 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -644,15 +644,15 @@ begin if (gInputBinds[i].down <> nil) then begin act := act + gInputBinds[i].down[0]; - for j := 1 to High(gInputBinds[i].down) do - act := act + ' ;' + gInputBinds[i].down[j]; + for j := 1 to High(gInputBinds[i].down) - 1 do + act := act + '; ' + gInputBinds[i].down[j]; end; act := act + '" "'; if (gInputBinds[i].up <> nil) then begin act := act + gInputBinds[i].up[0]; for j := 1 to High(gInputBinds[i].up) do - act := act + ' ;' + gInputBinds[i].up[j]; + act := act + '; ' + gInputBinds[i].up[j]; end; act := act + '"'; g_Console_Add(act) @@ -672,7 +672,11 @@ begin g_Console_Add('unbind '); 'unbindall': for i := 0 to e_MaxInputKeys - 1 do - g_Console_BindKey(i, '') + g_Console_BindKey(i, ''); + 'showkeyboard': + g_Touch_ShowKeyboard(True); + 'hidekeyboard': + g_Touch_ShowKeyboard(False); end end; @@ -756,6 +760,8 @@ begin AddCommand('bindlist', BindCommands); AddCommand('unbind', BindCommands); AddCommand('unbindall', BindCommands); + AddCommand('showkeyboard', BindCommands); + AddCommand('hidekeyboard', BindCommands); AddCommand('clear', ConsoleCommands, 'clear console'); AddCommand('clearhistory', ConsoleCommands); @@ -1722,6 +1728,8 @@ begin g_Console_BindKey(e_JoyButtonToKey(i, 7), '+p' + IntToStr(i mod 2 + 1) + '_strafe', '-p' + IntToStr(i mod 2 + 1) + '_strafe'); end; + g_Console_BindKey(VK_LSTRAFE, '+moveleft; +strafe', '-moveleft; -strafe'); + g_Console_BindKey(VK_RSTRAFE, '+moveright; +strafe', '-moveright; -strafe'); g_Console_BindKey(VK_LEFT, '+moveleft', '-moveleft'); g_Console_BindKey(VK_RIGHT, '+moveright', '-moveright'); g_Console_BindKey(VK_UP, '+lookup', '-lookup'); @@ -1747,6 +1755,8 @@ begin g_Console_BindKey(VK_TEAM, 'toggleteamchat'); g_Console_BindKey(VK_PRINTSCR, 'screenshot'); g_Console_BindKey(VK_STATUS, '+scores', '-scores'); + g_Console_BindKey(VK_SHOWKBD, 'showkeyboard'); + g_Console_BindKey(VK_HIDEKBD, 'hidekeyboard'); // VK_CONSOLE // VK_ESCAPE diff --git a/src/game/g_touch.pas b/src/game/g_touch.pas index 15ecb11..0638cc2 100644 --- a/src/game/g_touch.pas +++ b/src/game/g_touch.pas @@ -22,11 +22,11 @@ interface SDL2; var - g_touch_enabled: Boolean; - g_touch_size: Single; - g_touch_offset: Single; - g_touch_fire: Boolean; - g_touch_alt: Boolean; + g_touch_enabled: Boolean = False; + g_touch_size: Single = 1.0; + g_touch_offset: Single = 50.0; + g_touch_fire: Boolean = True; + g_touch_alt: Boolean = False; procedure g_Touch_Init; procedure g_Touch_ShowKeyboard(yes: Boolean); @@ -39,10 +39,6 @@ implementation SysUtils, e_log, e_graphics, e_input, g_options, g_game, g_main, g_weapons, g_console; - const - VS_KEYBOARD = 60000; - VS_HIDEKEYBOARD = 60001; - var angleFire: Boolean; keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer; @@ -72,14 +68,14 @@ implementation if SDL_IsTextInputActive() = SDL_True then case key of - VS_HIDEKEYBOARD: S(sw - (sz/2), 0, sz / 2, sz / 2); + VK_HIDEKBD: S(sw - (sz/2), 0, sz / 2, sz / 2); end else if g_touch_alt then case key of (* top ------- x ------------------------------- y w ----- h -- *) VK_CONSOLE: S(0, 0, sz / 2, sz / 2); VK_ESCAPE: S(sw - 1*(sz/2) - 1, 0, sz / 2, sz / 2); - VS_KEYBOARD: S(sw - 2*(sz/2) - 1, 0, sz / 2, sz / 2); + VK_SHOWKBD: S(sw - 2*(sz/2) - 1, 0, sz / 2, sz / 2); VK_CHAT: S(sw / 2 - (sz/2) / 2 - (sz/2) - 1, 0, sz / 2, sz / 2); VK_STATUS: S(sw / 2 - (sz/2) / 2 - 1, 0, sz / 2, sz / 2); VK_TEAM: S(sw / 2 - (sz/2) / 2 + (sz/2) - 1, 0, sz / 2, sz / 2); @@ -116,7 +112,7 @@ implementation VK_CONSOLE: S(sw/2 - sz/4 - 1*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2); VK_STATUS: S(sw/2 - sz/4 - 0*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2); VK_TEAM: S(sw/2 - sz/4 - -1*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2); - VS_KEYBOARD: S(sw/2 - sz/4 - -2*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2); + VK_SHOWKBD: S(sw/2 - sz/4 - -2*(sz/2) - 1, sh - 2*(sz/2) - 1, sz / 2, sz / 2); VK_0: S(sw/2 - sz/4 - 5*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2); VK_1: S(sw/2 - sz/4 - 4*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2); VK_2: S(sw/2 - sz/4 - 3*(sz/2) - 1, sh - 1*(sz/2) - 1, sz / 2, sz / 2); @@ -134,8 +130,8 @@ implementation function GetKeyName(key: Integer): String; begin case key of - VS_KEYBOARD: result := 'KBD'; - VS_HIDEKEYBOARD: result := 'KBD'; + VK_SHOWKBD: result := 'KBD'; + VK_HIDEKBD: result := 'KBD'; VK_LEFT: result := 'LEFT'; VK_RIGHT: result := 'RIGHT'; VK_UP: result := 'UP'; @@ -208,6 +204,62 @@ implementation procedure g_Touch_HandleEvent(const ev: TSDL_TouchFingerEvent); var x, y, i, finger: Integer; + + procedure KeyUp (finger, i: Integer); + begin + keyFinger[i] := 0; + e_KeyUpDown(i, False); + g_Console_ProcessBind(i, False); + + (* up/down + fire hack *) + if g_touch_fire and (gGameSettings.GameType <> GT_NONE) and angleFire then + begin + if (i = VK_UP) or (i = VK_DOWN) then + begin + angleFire := False; + keyFinger[VK_FIRE] := 0; + e_KeyUpDown(VK_FIRE, False); + g_Console_ProcessBind(VK_FIRE, False) + end + end + end; + + procedure KeyDown (finger, i: Integer); + begin + KeyPress(i); // Menu events + keyFinger[i] := finger; + e_KeyUpDown(i, True); + g_Console_ProcessBind(i, True); + + (* up/down + fire hack *) + if g_touch_fire and (gGameSettings.GameType <> GT_NONE) then + begin + if i = VK_UP then + begin + angleFire := True; + keyFinger[VK_FIRE] := -1; + e_KeyUpDown(VK_FIRE, True); + g_Console_ProcessBind(VK_FIRE, True) + end + else if i = VK_DOWN then + begin + angleFire := True; + keyFinger[VK_FIRE] := -1; + e_KeyUpDown(VK_FIRE, True); + g_Console_ProcessBind(VK_FIRE, True) + end + end + end; + + procedure KeyMotion (finger, i: Integer); + begin + if keyFinger[i] <> finger then + begin + KeyUp(finger, i); + KeyDown(finger, i) + end + end; + begin if not g_touch_enabled then Exit; @@ -221,108 +273,38 @@ implementation if IntersectControl(i, x, y) then begin if ev.type_ = SDL_FINGERUP then - keyFinger[i] := 0 + KeyUp(finger, i) else if ev.type_ = SDL_FINGERMOTION then - keyFinger[i] := finger + KeyMotion(finger, i) else if ev.type_ = SDL_FINGERDOWN then - begin - KeyPress(i); // Menu events - keyFinger[i] := finger; - end + keyDown(finger, i) end else if keyFinger[i] = finger then begin if ev.type_ = SDL_FINGERUP then - keyFinger[i] := 0 + KeyUp(finger, i) else if ev.type_ = SDL_FINGERMOTION then - keyFinger[i] := 0 - end; - - e_KeyUpDown(i, keyFinger[i] <> 0); - end; - - if IntersectControl(VS_KEYBOARD, x, y) then - g_Touch_ShowKeyboard(true); - if IntersectControl(VS_HIDEKEYBOARD, x, y) then - g_Touch_ShowKeyboard(false); - - (* emulate up+fire / donw+fire *) - if g_touch_fire and (gGameSettings.GameType <> GT_NONE) then - begin - if keyFinger[VK_UP] <> 0 then - begin - angleFire := true; - keyFinger[VK_FIRE] := keyFinger[VK_UP]; - e_KeyUpDown(VK_FIRE, true); - end - else if keyFinger[VK_DOWN] <> 0 then - begin - angleFire := true; - keyFinger[VK_FIRE] := keyFinger[VK_DOWN]; - e_KeyUpDown(VK_FIRE, true); + KeyUp(finger, i) end - else if angleFire then - begin - angleFire := false; - keyFinger[VK_FIRE] := 0; - e_KeyUpDown(VK_FIRE, false); - end - end; - - (* left/right strafe *) - if gGameSettings.GameType <> GT_NONE then - begin - if keyFinger[VK_LSTRAFE] <> 0 then - begin - keyFinger[VK_LEFT] := finger; - keyFinger[VK_RIGHT] := 0; - keyFinger[VK_STRAFE] := finger; - e_KeyUpDown(VK_LEFT, true); - e_KeyUpDown(VK_RIGHT, false); - e_KeyUpDown(VK_STRAFE, true); - end - else if keyFinger[VK_RSTRAFE] <> 0 then - begin - keyFinger[VK_LEFT] := 0; - keyFinger[VK_RIGHT] := finger; - keyFinger[VK_STRAFE] := finger; - e_KeyUpDown(VK_LEFT, false); - e_KeyUpDown(VK_RIGHT, true); - e_KeyUpDown(VK_STRAFE, true); - end - else - begin - keyFinger[VK_STRAFE] := 0; - e_KeyUpDown(VK_STRAFE, false); - end - - end; + end end; procedure g_Touch_Draw; - var i: Integer; + var i, x, y, w, h: Integer; founded: Boolean; + begin +{$IFNDEF HEADLESS} + if not g_touch_enabled then + Exit; - procedure Draw (i: Integer); - var x, y, w, h: Integer; founded: Boolean; + for i := VK_FIRSTKEY to VK_LASTKEY do begin GetKeyRect(i, x, y, w, h, founded); if founded then begin e_DrawQuad(x, y, x + w, y + h, 0, 255, 0, 31); e_TextureFontPrintEx(x, y, GetKeyName(i), gStdFont, 255, 255, 255, 1, True) - end; - end; - - begin -{$IFNDEF HEADLESS} - if not g_touch_enabled then - Exit; - - for i := VK_FIRSTKEY to VK_LASTKEY do - Draw(i); - - Draw(VS_KEYBOARD); - Draw(VS_HIDEKEYBOARD); + end + end {$ENDIF} end;