From: DeaDDooMER Date: Thu, 1 Mar 2018 16:08:29 +0000 (+0300) Subject: Virtual keyboard improvements: added strafe, up+fire, down+fire, prev/next weapon... X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=271f8f040cb0bd53be1ee6f682a346101f578491;p=d2df-sdl.git Virtual keyboard improvements: added strafe, up+fire, down+fire, prev/next weapon buttons --- diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index 1aae709..1c27249 100644 --- a/src/engine/e_input.pas +++ b/src/engine/e_input.pas @@ -29,7 +29,7 @@ const e_MaxJoyBtns = 32; e_MaxJoyAxes = 8; e_MaxJoyHats = 8; - e_MaxVirtKeys = 32; + e_MaxVirtKeys = 48; e_MaxJoyKeys = e_MaxJoyBtns + e_MaxJoyAxes*2 + e_MaxJoyHats*4; @@ -38,7 +38,7 @@ const // $$$..$$$ - 4*32 Joystick buttons // $$$..$$$ - 8*2 Joystick axes (- and +) // $$$..$$$ - 4*4 Joystick hats (L U R D) - // $$$..$$$ - 32 Virtual buttons/keys + // $$$..$$$ - 48 Virtual buttons/keys // these are apparently used in g_gui and g_game and elsewhere IK_INVALID = 65535; @@ -118,6 +118,9 @@ const VK_PREV = VK_FIRSTKEY + 28; VK_NEXT = VK_FIRSTKEY + 29; VK_STRAFE = VK_FIRSTKEY + 30; + VK_LSTRAFE = VK_FIRSTKEY + 31; + VK_RSTRAFE = VK_FIRSTKEY + 32; + VK_PRINTSCR = VK_FIRSTKEY + 33; VK_LASTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1; AX_MINUS = 0; diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 80fb053..1923452 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1695,23 +1695,25 @@ begin begin if g_ActiveWindow = nil then begin - if e_KeyPressed(gGameControls.GameControls.Chat) then + if e_KeyPressed(gGameControls.GameControls.Chat) or e_KeyPressed(VK_CHAT) then g_Console_Chat_Switch(False) - else if (e_KeyPressed(gGameControls.GameControls.TeamChat)) and + else if (e_KeyPressed(gGameControls.GameControls.TeamChat) or e_KeyPressed(VK_TEAM)) and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then g_Console_Chat_Switch(True); end; end else if not gChatEnter then if (not e_KeyPressed(gGameControls.GameControls.Chat)) - and (not e_KeyPressed(gGameControls.GameControls.TeamChat)) then + and (not e_KeyPressed(gGameControls.GameControls.TeamChat)) + and (not e_KeyPressed(VK_CHAT)) + and (not e_KeyPressed(VK_TEAM)) then gChatEnter := True; // Ñòàòèñòèêà ïî Tab: if gGameOn then IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and - e_KeyPressed(gGameControls.GameControls.Stat); + (e_KeyPressed(gGameControls.GameControls.Stat) or e_KeyPressed(VK_STATUS)); // Èãðà èäåò: if gGameOn and not gPause and (gState <> STATE_FOLD) then @@ -2011,7 +2013,7 @@ begin end; // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä): - if e_KeyPressed(gGameControls.GameControls.TakeScreenshot) then + if e_KeyPressed(gGameControls.GameControls.TakeScreenshot) or e_KeyPressed(VK_PRINTSCR) then if (GetTimer()-LastScreenShot) > 200000 div 1000 then begin g_TakeScreenShot(); diff --git a/src/game/g_touch.pas b/src/game/g_touch.pas index 20aacd4..52167bd 100644 --- a/src/game/g_touch.pas +++ b/src/game/g_touch.pas @@ -35,12 +35,13 @@ implementation jab: Boolean; size: Single; enabled: Boolean; + angleFireEnabled, angleFire: Boolean; keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer; procedure GetKeyRect(key: Word; out x, y, w, h: Integer; out founded: Boolean); - var - sw, sh, sz: Integer; - dpi: Single; + var + sw, sh, sz: Integer; + dpi: Single; begin if SDL_GetDisplayDPI(0, @dpi, nil, nil) <> 0 then dpi := 96; @@ -81,32 +82,36 @@ implementation begin x := 0; y := 0; w := sz; h := sz; case key of - VK_LEFT: begin x := 0; y := sh div 2 - h div 2; end; - VK_RIGHT: begin x := w; y := sh div 2 - h div 2; end; - VK_UP: begin x := sw - w - 1; y := sh div 2 - h div 2 - h; end; - VK_DOWN: begin x := sw - w - 1; y := sh div 2 - h div 2 + h; end; - VK_FIRE: begin x := sw - 1*w - 1; y := sh div 2 - h div 2; end; - VK_OPEN: begin x := sw - 3*w - 1; y := sh div 2 - h div 2; end; - VK_JUMP: begin x := sw - 2*w - 1; y := sh div 2 - h div 2; end; + VK_LSTRAFE: begin x := 0; y := sh div 2 - h div 2; w := w div 2 end; + VK_LEFT: begin x := w div 2; y := sh div 2 - h div 2 end; + VK_RIGHT: begin x := w div 2 + 1*w;y := sh div 2 - h div 2 end; + VK_RSTRAFE: begin x := w div 2 + 2*w;y := sh div 2 - h div 2; w := w div 2 end; + VK_UP: begin x := sw - w - 1; y := sh div 2 - h div 2 - h end; + VK_FIRE: begin x := sw - 1*w - 1; y := sh div 2 - h div 2 end; + VK_DOWN: begin x := sw - w - 1; y := sh div 2 - h div 2 + h end; + VK_NEXT: begin x := sw - 2*w - 1; y := sh div 2 - h div 2 - h end; + VK_JUMP: begin x := sw - 2*w - 1; y := sh div 2 - h div 2 end; + VK_PREV: begin x := sw - 3*w - 1; y := sh div 2 - h div 2 - h end; + VK_OPEN: begin x := sw - 3*w - 1; y := sh div 2 - h div 2 end; else w := sz div 2; h := sz div 2; case key of - VK_0: begin x := sw div 2 - w div 2 - 5*w - 1; y := sh - 1*h - 1; end; - VK_1: begin x := sw div 2 - w div 2 - 4*w - 1; y := sh - 1*h - 1; end; - VK_2: begin x := sw div 2 - w div 2 - 3*w - 1; y := sh - 1*h - 1; end; - VK_3: begin x := sw div 2 - w div 2 - 2*w - 1; y := sh - 1*h - 1; end; - VK_4: begin x := sw div 2 - w div 2 - 1*w - 1; y := sh - 1*h - 1; end; - VK_5: begin x := sw div 2 - w div 2 + 0*w - 1; y := sh - 1*h - 1; end; - VK_6: begin x := sw div 2 - w div 2 + 1*w - 1; y := sh - 1*h - 1; end; - VK_7: begin x := sw div 2 - w div 2 + 2*w - 1; y := sh - 1*h - 1; end; - VK_8: begin x := sw div 2 - w div 2 + 3*w - 1; y := sh - 1*h - 1; end; - VK_9: begin x := sw div 2 - w div 2 + 4*w - 1; y := sh - 1*h - 1; end; - VK_A: begin x := sw div 2 - w div 2 + 5*w - 1; y := sh - 1*h - 1; end; - VK_CHAT: begin x := sw div 2 - w div 2 - 2*w - 1; y := sh - 2*h - 1; end; - VK_ESCAPE: begin x := sw div 2 - w div 2 - 1*w - 1; y := sh - 2*h - 1; end; - VK_CONSOLE: begin x := sw div 2 - w div 2 + 0*w - 1; y := sh - 2*h - 1; end; - VK_STATUS: begin x := sw div 2 - w div 2 + 1*w - 1; y := sh - 2*h - 1; end; - VK_TEAM: begin x := sw div 2 - w div 2 + 2*w - 1; y := sh - 2*h - 1; end; + VK_0: begin x := sw div 2 - w div 2 - 5*w - 1; y := sh - 1*h - 1 end; + VK_1: begin x := sw div 2 - w div 2 - 4*w - 1; y := sh - 1*h - 1 end; + VK_2: begin x := sw div 2 - w div 2 - 3*w - 1; y := sh - 1*h - 1 end; + VK_3: begin x := sw div 2 - w div 2 - 2*w - 1; y := sh - 1*h - 1 end; + VK_4: begin x := sw div 2 - w div 2 - 1*w - 1; y := sh - 1*h - 1 end; + VK_5: begin x := sw div 2 - w div 2 + 0*w - 1; y := sh - 1*h - 1 end; + VK_6: begin x := sw div 2 - w div 2 + 1*w - 1; y := sh - 1*h - 1 end; + VK_7: begin x := sw div 2 - w div 2 + 2*w - 1; y := sh - 1*h - 1 end; + VK_8: begin x := sw div 2 - w div 2 + 3*w - 1; y := sh - 1*h - 1 end; + VK_9: begin x := sw div 2 - w div 2 + 4*w - 1; y := sh - 1*h - 1 end; + VK_A: begin x := sw div 2 - w div 2 + 5*w - 1; y := sh - 1*h - 1 end; + VK_CHAT: begin x := sw div 2 - w div 2 - 2*w - 1; y := sh - 2*h - 1 end; + VK_ESCAPE: begin x := sw div 2 - w div 2 - 1*w - 1; y := sh - 2*h - 1 end; + VK_CONSOLE: begin x := sw div 2 - w div 2 + 0*w - 1; y := sh - 2*h - 1 end; + VK_STATUS: begin x := sw div 2 - w div 2 + 1*w - 1; y := sh - 2*h - 1 end; + VK_TEAM: begin x := sw div 2 - w div 2 + 2*w - 1; y := sh - 2*h - 1 end; else founded := false end @@ -145,8 +150,10 @@ implementation VK_CONSOLE: result := 'CON'; VK_STATUS: result := 'STAT'; VK_TEAM: result := 'TEAM'; - VK_PREV: result := ' 0) and (key < e_MaxInputKeys) then result := e_KeyNames[key] @@ -157,7 +164,7 @@ implementation procedure DrawRect(x, y, w, h: Integer); begin - e_DrawQuad(x, y, x + w, y + h, 0, 255, 0, 63); + e_DrawQuad(x, y, x + w, y + h, 0, 255, 0, 31); end; function IntersectControl(ctl, xx, yy: Integer): Boolean; @@ -219,6 +226,57 @@ implementation e_KeyUpDown(i, keyFinger[i] <> 0); end; + + (* emulate up+fire / donw+fire *) + if angleFireEnabled 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); + 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; procedure g_Touch_Draw; @@ -249,7 +307,9 @@ initialization enabled := true; {$ENDIF} size := 1; + angleFire := true; conRegVar('touch_enable', @enabled, 'enable/disable virtual buttons', 'draw buttons'); + conRegVar('touch_anglefire', @angleFireEnabled, 'enable/disable fire when press virtual up/down', 'fire when press up/down'); conRegVar('touch_size', @size, 0.1, 10, 'size of virtual buttons', 'button size'); conRegVar('touch_alt', @jab, 'althernative virtual buttons layout', 'althernative layout'); end.