From: DeaDDooMER Date: Mon, 26 Feb 2018 21:49:38 +0000 (+0300) Subject: Reserved key range for virtual keyboard + alternative virtkbd layout X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=54b1109da7cd0eb8498980a6ad57f2dcda49b022 Reserved key range for virtual keyboard + alternative virtkbd layout --- diff --git a/src/engine/e_input.pas b/src/engine/e_input.pas index 0baad37..1aae709 100644 --- a/src/engine/e_input.pas +++ b/src/engine/e_input.pas @@ -29,14 +29,16 @@ const e_MaxJoyBtns = 32; e_MaxJoyAxes = 8; e_MaxJoyHats = 8; + e_MaxVirtKeys = 32; e_MaxJoyKeys = e_MaxJoyBtns + e_MaxJoyAxes*2 + e_MaxJoyHats*4; - e_MaxInputKeys = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys - 1; + e_MaxInputKeys = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1; // $$$..$$$ - 321 Keyboard buttons/keys // $$$..$$$ - 4*32 Joystick buttons // $$$..$$$ - 8*2 Joystick axes (- and +) // $$$..$$$ - 4*4 Joystick hats (L U R D) + // $$$..$$$ - 32 Virtual buttons/keys // these are apparently used in g_gui and g_game and elsewhere IK_INVALID = 65535; @@ -84,6 +86,40 @@ const // TODO: think of something better than this shit IK_LASTKEY = SDL_NUM_SCANCODES-1; + VK_FIRSTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys; + VK_LEFT = VK_FIRSTKEY + 0; + VK_RIGHT = VK_FIRSTKEY + 1; + VK_UP = VK_FIRSTKEY + 2; + VK_DOWN = VK_FIRSTKEY + 3; + VK_FIRE = VK_FIRSTKEY + 4; + VK_OPEN = VK_FIRSTKEY + 5; + VK_JUMP = VK_FIRSTKEY + 6; + VK_CHAT = VK_FIRSTKEY + 7; + VK_ESCAPE = VK_FIRSTKEY + 8; + VK_0 = VK_FIRSTKEY + 9; + VK_1 = VK_FIRSTKEY + 10; + VK_2 = VK_FIRSTKEY + 11; + VK_3 = VK_FIRSTKEY + 12; + VK_4 = VK_FIRSTKEY + 13; + VK_5 = VK_FIRSTKEY + 14; + VK_6 = VK_FIRSTKEY + 15; + VK_7 = VK_FIRSTKEY + 16; + VK_8 = VK_FIRSTKEY + 17; + VK_9 = VK_FIRSTKEY + 18; + VK_A = VK_FIRSTKEY + 19; + VK_B = VK_FIRSTKEY + 20; + VK_C = VK_FIRSTKEY + 21; + VK_D = VK_FIRSTKEY + 22; + VK_E = VK_FIRSTKEY + 23; + VK_F = VK_FIRSTKEY + 24; + VK_CONSOLE = VK_FIRSTKEY + 25; + VK_STATUS = VK_FIRSTKEY + 26; + VK_TEAM = VK_FIRSTKEY + 27; + VK_PREV = VK_FIRSTKEY + 28; + VK_NEXT = VK_FIRSTKEY + 29; + VK_STRAFE = VK_FIRSTKEY + 30; + VK_LASTKEY = e_MaxKbdKeys + e_MaxJoys*e_MaxJoyKeys + e_MaxVirtKeys - 1; + AX_MINUS = 0; AX_PLUS = 1; HAT_LEFT = 0; @@ -128,6 +164,8 @@ const JOYA_END = JOYA_BEG + e_MaxJoyAxes*2*e_MaxJoys; JOYH_BEG = JOYA_END; JOYH_END = JOYH_BEG + e_MaxJoyHats*4*e_MaxJoys; + VIRT_BEG = JOYH_END; + VIRT_END = VIRT_BEG + e_MaxVirtKeys; type TJoystick = record @@ -144,6 +182,7 @@ type var KeyBuffer: array [0..e_MaxKbdKeys] of Boolean; + VirtBuffer: array [0..e_MaxVirtKeys] of Boolean; Joysticks: array of TJoystick = nil; function OpenJoysticks(): Byte; @@ -198,12 +237,14 @@ var i: Integer; begin for i := 0 to High(KeyBuffer) do KeyBuffer[i] := False; + for i := 0 to High(VirtBuffer) do VirtBuffer[i] := False; end; procedure e_KeyUpDown (key: Word; down: Boolean); begin - if (key > 0) and (key < Length(KeyBuffer)) then KeyBuffer[key] := down; + if (key > 0) and (key < Length(KeyBuffer)) then KeyBuffer[key] := down + else if (key >= VIRT_BEG) and (key < VIRT_END) then VirtBuffer[key - VIRT_BEG] := down end; @@ -285,6 +326,10 @@ begin e_KeyNames[k + i*4 + 3] := Format('JOY%d D%dD', [j, i]); end; end; + + // vitrual keys + for i := 0 to e_MaxVirtKeys-1 do + e_KeyNames[VIRT_BEG + i] := 'VIRTUAL ' + IntToStr(i); end; function e_InitInput(): Boolean; @@ -321,6 +366,8 @@ begin for d := Low(Joysticks[i].HatBuf[j]) to High(Joysticks[i].HatBuf[j]) do Joysticks[i].HatBuf[j, d] := False; end; + for i := Low(VirtBuffer) to High(VirtBuffer) do + VirtBuffer[i] := False; end; { @@ -388,7 +435,10 @@ begin dir := Key mod 4; Result := Joysticks[JoyI].HatBuf[Key div 4, dir]; end; - end; + end + + else if (Key >= VIRT_BEG) and (Key < VIRT_END) then + Result := VirtBuffer[Key - VIRT_BEG] end; procedure e_SetKeyState(key: Word; state: Integer); @@ -437,7 +487,10 @@ begin dir := Key mod 4; Joysticks[JoyI].HatBuf[Key div 4, dir] := (state <> 0); end; - end; + end + + else if (Key >= VIRT_BEG) and (Key < VIRT_END) then + VirtBuffer[Key - VIRT_BEG] := (state <> 0) end; function e_AnyKeyPressed(): Boolean; diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 230e5b6..2f3103a 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -1079,13 +1079,13 @@ begin IK_DELETE: if (Length(Line) > 0) and (CPos <= Length(Line)) then Delete(Line, CPos, 1); - IK_LEFT, IK_KPLEFT: + IK_LEFT, IK_KPLEFT, VK_LEFT: if CPos > 1 then CPos := CPos - 1; - IK_RIGHT, IK_KPRIGHT: + IK_RIGHT, IK_KPRIGHT, VK_RIGHT: if CPos <= Length(Line) then CPos := CPos + 1; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_OPEN, VK_FIRE: begin if Cons_Shown then g_Console_Process(Line) @@ -1122,7 +1122,7 @@ begin IK_TAB: if not gChatShow then Complete(); - IK_DOWN, IK_KPDOWN: + IK_DOWN, IK_KPDOWN, VK_DOWN: if not gChatShow then if (CommandHistory <> nil) and (CmdIndex < Length(CommandHistory)) then @@ -1132,7 +1132,7 @@ begin Line := CommandHistory[CmdIndex]; CPos := Length(Line) + 1; end; - IK_UP, IK_KPUP: + IK_UP, IK_KPUP, VK_UP: if not gChatShow then if (CommandHistory <> nil) and (CmdIndex <= Length(CommandHistory)) then @@ -1142,9 +1142,9 @@ begin Line := CommandHistory[CmdIndex]; Cpos := Length(Line) + 1; end; - IK_PAGEUP, IK_KPPAGEUP: // PgUp + IK_PAGEUP, IK_KPPAGEUP, VK_PREV: // PgUp if not gChatShow then Inc(conSkipLines); - IK_PAGEDN, IK_KPPAGEDN: // PgDown + IK_PAGEDN, IK_KPPAGEDN, VK_NEXT: // PgDown if not gChatShow and (conSkipLines > 0) then Dec(conSkipLines); IK_HOME, IK_KPHOME: CPos := 1; diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 5bceb41..80fb053 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -1596,7 +1596,10 @@ begin if (not g_Game_IsClient) and ( ( - (e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE)) + ( + e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or + e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) + ) and (not gJustChatted) and (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) ) @@ -2301,7 +2304,7 @@ begin g_ProcessMessages(); - if e_KeyPressed(IK_TAB) then + if e_KeyPressed(IK_TAB) or e_KeyPressed(VK_STATUS) then begin if not gStatsPressed then begin @@ -4400,7 +4403,7 @@ begin ProcessLoading(true); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then + if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then begin State := 0; break; diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas index 6f4dfbe..96df55b 100644 --- a/src/game/g_gui.pas +++ b/src/game/g_gui.pas @@ -835,7 +835,7 @@ begin if @FOnKeyDownEx <> nil then FOnKeyDownEx(self, Msg.wParam); if Msg.Msg = WM_KEYDOWN then - if Msg.wParam = IK_ESCAPE then + if (Msg.wParam = IK_ESCAPE) or (Msg.wParam = VK_ESCAPE) then begin g_GUI_HideWindow; Exit; @@ -966,7 +966,7 @@ begin case Msg.Msg of WM_KEYDOWN: case Msg.wParam of - IK_RETURN, IK_KPRETURN: Click(); + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: Click(); end; end; end; @@ -1180,7 +1180,7 @@ begin case Msg.Msg of WM_KEYDOWN: case Msg.wParam of - IK_UP, IK_KPUP: + IK_UP, IK_KPUP, VK_UP: begin repeat Dec(FIndex); @@ -1189,7 +1189,7 @@ begin g_Sound_PlayEx(MENU_CHANGESOUND); end; - IK_DOWN, IK_KPDOWN: + IK_DOWN, IK_KPDOWN, VK_DOWN: begin repeat Inc(FIndex); @@ -1198,7 +1198,7 @@ begin g_Sound_PlayEx(MENU_CHANGESOUND); end; - IK_RETURN, IK_KPRETURN: if (FIndex <> -1) and FButtons[FIndex].FEnabled then FButtons[FIndex].Click; + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: if (FIndex <> -1) and FButtons[FIndex].FEnabled then FButtons[FIndex].Click; end; end; end; @@ -1275,7 +1275,7 @@ begin case Msg.Msg of WM_KEYDOWN: case Msg.wParam of - IK_RETURN, IK_KPRETURN: if @FOnClickEvent <> nil then FOnClickEvent(); + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: if @FOnClickEvent <> nil then FOnClickEvent(); end; end; end; @@ -1527,7 +1527,7 @@ begin WM_KEYDOWN: begin case Msg.wParam of - IK_UP, IK_KPUP: + IK_UP, IK_KPUP, VK_UP: begin c := 0; repeat @@ -1548,7 +1548,7 @@ begin g_Sound_PlayEx(MENU_CHANGESOUND); end; - IK_DOWN, IK_KPDOWN: + IK_DOWN, IK_KPDOWN, VK_DOWN: begin c := 0; repeat @@ -1569,13 +1569,13 @@ begin g_Sound_PlayEx(MENU_CHANGESOUND); end; - IK_LEFT, IK_RIGHT, IK_KPLEFT, IK_KPRIGHT: + IK_LEFT, IK_RIGHT, IK_KPLEFT, IK_KPRIGHT, VK_LEFT, VK_RIGHT: begin if FIndex <> -1 then if FItems[FIndex].Control <> nil then FItems[FIndex].Control.OnMessage(Msg); end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: begin if FIndex <> -1 then begin @@ -2104,14 +2104,14 @@ begin WM_KEYDOWN: begin case Msg.wParam of - IK_LEFT, IK_KPLEFT: + IK_LEFT, IK_KPLEFT, VK_LEFT: if FValue > 0 then begin Dec(FValue); g_Sound_PlayEx(SCROLL_SUBSOUND); if @FOnChangeEvent <> nil then FOnChangeEvent(Self); end; - IK_RIGHT, IK_KPRIGHT: + IK_RIGHT, IK_KPRIGHT, VK_RIGHT: if FValue < FMax then begin Inc(FValue); @@ -2188,7 +2188,7 @@ begin case Msg.Msg of WM_KEYDOWN: case Msg.wParam of - IK_RETURN, IK_RIGHT, IK_KPRETURN, IK_KPRIGHT: + IK_RETURN, IK_RIGHT, IK_KPRETURN, IK_KPRIGHT, VK_FIRE, VK_OPEN, VK_RIGHT: begin if FIndex < High(FItems) then Inc(FIndex) @@ -2199,7 +2199,7 @@ begin FOnChangeEvent(Self); end; - IK_LEFT, IK_KPLEFT: + IK_LEFT, IK_KPLEFT, VK_LEFT: begin if FIndex > 0 then Dec(FIndex) @@ -2306,9 +2306,9 @@ begin IK_DELETE: Delete(FText, FCaretPos + 1, 1); IK_END, IK_KPEND: FCaretPos := Length(FText); IK_HOME, IK_KPHOME: FCaretPos := 0; - IK_LEFT, IK_KPLEFT: if FCaretPos > 0 then Dec(FCaretPos); - IK_RIGHT, IK_KPRIGHT: if FCaretPos < Length(FText) then Inc(FCaretPos); - IK_RETURN, IK_KPRETURN: + IK_LEFT, IK_KPLEFT, VK_LEFT: if FCaretPos > 0 then Dec(FCaretPos); + IK_RIGHT, IK_KPRIGHT, VK_RIGHT: if FCaretPos < Length(FText) then Inc(FCaretPos); + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: with FWindow do begin if FActiveControl <> Self then @@ -2407,12 +2407,12 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_ESCAPE: + IK_ESCAPE, VK_ESCAPE: begin if FIsQuery then actDefCtl(); FIsQuery := False; end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: begin if not FIsQuery then begin @@ -2446,7 +2446,7 @@ begin FKey := 0; actDefCtl(); end - else if FIsQuery and (wParam <> IK_ENTER) and (wParam <> IK_KPRETURN) then // Not IK_ENTER) and (wParam <> IK_KPRETURN) and (wParam <> VK_FIRE) and (wParam <> VK_OPEN) then // Not '' then FKey := wParam; @@ -2530,6 +2530,7 @@ begin (key = IK_BACKSPACE) or (key = IK_LEFT) or (key = IK_RIGHT) or (key = IK_KPLEFT) or (key = IK_KPRIGHT) or + (key = VK_LEFT) or (key = VK_RIGHT) or false; // oops end; @@ -2553,12 +2554,12 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_ESCAPE: + IK_ESCAPE, VK_ESCAPE: begin if FIsQuery then actDefCtl(); FIsQuery := False; end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: begin if not FIsQuery then begin @@ -2583,13 +2584,13 @@ begin actDefCtl(); end; end; - IK_LEFT, IK_KPLEFT: + IK_LEFT, IK_KPLEFT, VK_LEFT: if not FIsQuery then begin FKeyIdx := 0; actDefCtl(); end; - IK_RIGHT, IK_KPRIGHT: + IK_RIGHT, IK_KPRIGHT, VK_RIGHT: if not FIsQuery then begin FKeyIdx := 1; @@ -2604,7 +2605,7 @@ begin if (FKeyIdx = 0) then FKey0 := 0 else FKey1 := 0; actDefCtl(); end - else if FIsQuery and (wParam <> IK_ENTER) and (wParam <> IK_KPRETURN) then // Not IK_ENTER) and (wParam <> IK_KPRETURN) and (wParam <> VK_FIRE) and (wParam <> VK_OPEN) then // Not '' then begin @@ -3021,21 +3022,21 @@ begin FIndex := High(FItems); FStartLine := Max(High(FItems)-FHeight+1, 0); end; - IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT: + IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT, VK_LEFT: if FIndex > 0 then begin Dec(FIndex); if FIndex < FStartLine then Dec(FStartLine); if @FOnChangeEvent <> nil then FOnChangeEvent(Self); end; - IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT: + IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT, VK_RIGHT: if FIndex < High(FItems) then begin Inc(FIndex); if FIndex > FStartLine+FHeight-1 then Inc(FStartLine); if @FOnChangeEvent <> nil then FOnChangeEvent(Self); end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: with FWindow do begin if FActiveControl <> Self then SetActive(Self) @@ -3177,7 +3178,7 @@ begin FStartLine := High(FItems)-FHeight+1; end; - IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT: + IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT, VK_UP, VK_LEFT: if FIndex > 0 then begin Dec(FIndex); @@ -3187,7 +3188,7 @@ begin FOnChangeEvent(Self); end; - IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT: + IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT, VK_DOWN, VK_RIGHT: if FIndex < High(FItems) then begin Inc(FIndex); @@ -3197,7 +3198,7 @@ begin FOnChangeEvent(Self); end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: with FWindow do begin if FActiveControl <> Self then @@ -3378,13 +3379,13 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT: + IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT, VK_UP, VK_LEFT: if FStartLine > 0 then Dec(FStartLine); - IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT: + IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT, VK_DOWN, VK_RIGHT: if FStartLine < Length(FLines)-FHeight then Inc(FStartLine); - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN: with FWindow do begin if FActiveControl <> Self then diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 93655f6..07d2f48 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -491,12 +491,12 @@ begin if (g_ActiveWindow = nil) then g_Game_Pause(not gPause); end; - IK_BACKQUOTE: // <`/~/¨/¸>: + IK_BACKQUOTE, VK_CONSOLE: // <`/~/¨/¸>: begin g_Console_Switch(); end; - IK_ESCAPE: // : + IK_ESCAPE, VK_ESCAPE: // : begin if gChatShow then begin diff --git a/src/game/g_net.pas b/src/game/g_net.pas index 04382d3..b9f28b9 100644 --- a/src/game/g_net.pas +++ b/src/game/g_net.pas @@ -816,7 +816,7 @@ begin ProcessLoading(true); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then + if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then OuterLoop := False; end; @@ -979,7 +979,7 @@ begin ProcessLoading(true); - if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then + if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then break; end; Result := msgStream; diff --git a/src/game/g_netmaster.pas b/src/game/g_netmaster.pas index 05d79ed..f4ce798 100644 --- a/src/game/g_netmaster.pas +++ b/src/game/g_netmaster.pas @@ -513,7 +513,7 @@ begin qm := g_ProcessMessages(); // this updates kbd - if qm or e_KeyPressed(IK_ESCAPE) then + if qm or e_KeyPressed(IK_ESCAPE) or e_KeyPressed(VK_ESCAPE) then begin SL := nil; gState := STATE_MENU; @@ -524,7 +524,7 @@ begin Exit; end; - if e_KeyPressed(IK_SPACE) then + if e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_JUMP) then begin if not slFetched then begin @@ -549,7 +549,7 @@ begin if SL = nil then Exit; - if e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) then + if e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) then begin if not slReturnPressed then begin @@ -573,7 +573,7 @@ begin else slReturnPressed := False; - if e_KeyPressed(IK_DOWN) or e_KeyPressed(IK_KPDOWN) then + if e_KeyPressed(IK_DOWN) or e_KeyPressed(IK_KPDOWN) or e_KeyPressed(VK_DOWN) then begin if not slDirPressed then begin @@ -583,7 +583,7 @@ begin end; end; - if e_KeyPressed(IK_UP) or e_KeyPressed(IK_KPUP) then + if e_KeyPressed(IK_UP) or e_KeyPressed(IK_KPUP) or e_KeyPressed(VK_UP) then begin if not slDirPressed then begin @@ -594,7 +594,7 @@ begin end; end; - if (not e_KeyPressed(IK_DOWN)) and (not e_KeyPressed(IK_UP)) and (not e_KeyPressed(IK_KPDOWN)) and (not e_KeyPressed(IK_KPUP)) then + if (not e_KeyPressed(IK_DOWN)) and (not e_KeyPressed(IK_UP)) and (not e_KeyPressed(IK_KPDOWN)) and (not e_KeyPressed(IK_KPUP)) and (not e_KeyPressed(VK_DOWN)) and (not e_KeyPressed(VK_UP)) then slDirPressed := False; end; diff --git a/src/game/g_options.pas b/src/game/g_options.pas index ee8518a..b3b2f5a 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -196,18 +196,18 @@ begin for i := 10 to High(KeyWeapon) do KeyWeapon[i] := 0; - KeyRight2 := 0; - KeyLeft2 := 0; - KeyUp2 := 0; - KeyDown2 := 0; - KeyFire2 := 0; - KeyJump2 := 0; - KeyNextWeapon2 := 0; - KeyPrevWeapon2 := 0; - KeyOpen2 := 0; - KeyStrafe2 := 0; + KeyRight2 := VK_RIGHT; + KeyLeft2 := VK_LEFT; + KeyUp2 := VK_UP; + KeyDown2 := VK_DOWN; + KeyFire2 := VK_FIRE; + KeyJump2 := VK_JUMP; + KeyNextWeapon2 := VK_NEXT; + KeyPrevWeapon2 := VK_PREV; + KeyOpen2 := VK_OPEN; + KeyStrafe2 := VK_STRAFE; for i := 0 to High(KeyWeapon2) do - KeyWeapon2[i] := 0; + KeyWeapon2[i] := VK_0 + i; end; with gGameControls.P2Control do diff --git a/src/game/g_touch.pas b/src/game/g_touch.pas index 0a02e57..20aacd4 100644 --- a/src/game/g_touch.pas +++ b/src/game/g_touch.pas @@ -31,39 +31,13 @@ implementation SysUtils, e_log, e_graphics, e_input, g_options, g_game, g_main, g_weapons, g_console; - const - CTL_NONE = 0; - CTL_LEFT = 1; - CTL_RIGHT = 2; - CTL_UP = 3; - CTL_DOWN = 4; - CTL_FIRE = 5; - CTL_OPEN = 6; - CTL_JUMP = 7; - CTL_CHAT = 8; - CTL_ESC = 9; - CTL_W0 = 10; - CTL_W1 = 11; - CTL_W2 = 12; - CTL_W3 = 13; - CTL_W4 = 14; - CTL_W5 = 15; - CTL_W6 = 16; - CTL_W7 = 17; - CTL_W8 = 18; - CTL_W9 = 19; - CTL_W10 = 20; - CTL_CON = 21; - CTL_STAT = 22; - CTL_TCHAT = 23; - CTL_LAST = 23; - var + jab: Boolean; size: Single; enabled: Boolean; - keyFinger: array [1..CTL_LAST] of Integer; + keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer; - procedure GetControlRect(control: Integer; out x, y, w, h: Integer; out founded: Boolean); + procedure GetKeyRect(key: Word; out x, y, w, h: Integer; out founded: Boolean); var sw, sh, sz: Integer; dpi: Single; @@ -73,133 +47,117 @@ implementation founded := true; sz := Trunc(size * dpi); - x := 0; y := 0; w := sz; h := sz; sw := gScreenWidth; sh := gScreenHeight; - case control of - CTL_LEFT: begin x := 0; y := sh div 2 - h div 2; end; - CTL_RIGHT: begin x := w; y := sh div 2 - h div 2; end; - CTL_UP: begin x := sw - w - 1; y := sh div 2 - h div 2 - h; end; - CTL_DOWN: begin x := sw - w - 1; y := sh div 2 - h div 2 + h; end; - CTL_FIRE: begin x := sw - 1*w - 1; y := sh div 2 - h div 2; end; - CTL_OPEN: begin x := sw - 3*w - 1; y := sh div 2 - h div 2; end; - CTL_JUMP: begin x := sw - 2*w - 1; y := sh div 2 - h div 2; end; - else - w := sz div 2; h := sz div 2; - case control of - CTL_W0: begin x := sw div 2 - w div 2 - 5*w - 1; y := sh - 1*h - 1; end; - CTL_W1: begin x := sw div 2 - w div 2 - 4*w - 1; y := sh - 1*h - 1; end; - CTL_W2: begin x := sw div 2 - w div 2 - 3*w - 1; y := sh - 1*h - 1; end; - CTL_W3: begin x := sw div 2 - w div 2 - 2*w - 1; y := sh - 1*h - 1; end; - CTL_W4: begin x := sw div 2 - w div 2 - 1*w - 1; y := sh - 1*h - 1; end; - CTL_W5: begin x := sw div 2 - w div 2 + 0*w - 1; y := sh - 1*h - 1; end; - CTL_W6: begin x := sw div 2 - w div 2 + 1*w - 1; y := sh - 1*h - 1; end; - CTL_W7: begin x := sw div 2 - w div 2 + 2*w - 1; y := sh - 1*h - 1; end; - CTL_W8: begin x := sw div 2 - w div 2 + 3*w - 1; y := sh - 1*h - 1; end; - CTL_W9: begin x := sw div 2 - w div 2 + 4*w - 1; y := sh - 1*h - 1; end; - CTL_W10: begin x := sw div 2 - w div 2 + 5*w - 1; y := sh - 1*h - 1; end; - CTL_CHAT: begin x := sw div 2 - w div 2 - 2*w - 1; y := sh - 2*h - 1; end; - CTL_ESC: begin x := sw div 2 - w div 2 - 1*w - 1; y := sh - 2*h - 1; end; - CTL_CON: begin x := sw div 2 - w div 2 + 0*w - 1; y := sh - 2*h - 1; end; - CTL_STAT: begin x := sw div 2 - w div 2 + 1*w - 1; y := sh - 2*h - 1; end; - CTL_TCHAT: begin x := sw div 2 - w div 2 + 2*w - 1; y := sh - 2*h - 1; end; + if jab then + begin + w := sz div 2; h := sz div 3; + case key of + VK_CONSOLE: begin x := 0; y := 0 end; + VK_ESCAPE: begin x := sw - w - 1; y := 0 end; + VK_CHAT: begin x := sw div 2 - w - 4; y := 0 end; + VK_TEAM: begin x := sw div 2 + 0 + 4; y := 0 end; else - founded := false + w := sz; h := sz * 2; + case key of + VK_LEFT: begin x := 0; y := sh - h - 1 end; + VK_RIGHT: begin x := w; y := sh - h - 1 end; + else + w := sz; h := sz; + case key of + VK_OPEN: begin h := sz; x := sw - 1*w - 1; y := sh - 1*h - 1 end; + VK_JUMP: begin h := sz; x := sw - 1*w - 1; y := sh - 2*h - 1 end; + VK_UP: begin h := sz div 2; x := sw - 2*w - 1; y := sh - 2*sz - 1 end; + VK_FIRE: begin h := sz; x := sw - 2*w - 1; y := sh - sz div 2 - sz - 1 end; + VK_DOWN: begin h := sz div 2; x := sw - 2*w - 1; y := sh - sz div 2 - 1 end; + VK_PREV: begin h := sz div 2; x := 0; y := sh - 3*sz - 1 end; + VK_NEXT: begin h := sz div 2; x := sw - w - 1; y := sh - 3*sz - 1 end; + else + founded := false + end + end end end - end; - - function GetMenuKey(control: Integer): Word; - begin - case control of - CTL_LEFT: result := IK_LEFT; - CTL_RIGHT: result := IK_RIGHT; - CTL_UP: result := IK_UP; - CTL_DOWN: result := IK_DOWN; - CTL_OPEN: result := IK_ENTER; - CTL_FIRE: result := IK_ENTER; - CTL_JUMP: result := IK_SPACE; - CTL_ESC: result := IK_ESCAPE; - CTL_W0: result := SDL_SCANCODE_0; - CTL_W1: result := SDL_SCANCODE_1; - CTL_W2: result := SDL_SCANCODE_2; - CTL_W3: result := SDL_SCANCODE_3; - CTL_W4: result := SDL_SCANCODE_4; - CTL_W5: result := SDL_SCANCODE_5; - CTL_W6: result := SDL_SCANCODE_6; - CTL_W7: result := SDL_SCANCODE_7; - CTL_W8: result := SDL_SCANCODE_8; - CTL_W9: result := SDL_SCANCODE_9; - CTL_CON: result := IK_GRAVE; - else - result := IK_INVALID; - end - end; - - function GetPlayerKey(control: Integer): Word; - begin - case control of - CTL_LEFT: result := gGameControls.P1Control.KeyLeft; - CTL_RIGHT: result := gGameControls.P1Control.KeyRight; - CTL_UP: result := gGameControls.P1Control.KeyUp; - CTL_DOWN: result := gGameControls.P1Control.KeyDown; - CTL_OPEN: result := gGameControls.P1Control.KeyOpen; - CTL_FIRE: result := gGameControls.P1Control.KeyFire; - CTL_JUMP: result := gGameControls.P1Control.KeyJump; - CTL_CHAT: result := gGameControls.GameControls.Chat; - CTL_ESC: result := IK_ESCAPE; - CTL_W0: result := gGameControls.P1Control.KeyWeapon[WEAPON_KASTET]; - CTL_W1: result := gGameControls.P1Control.KeyWeapon[WEAPON_SAW]; - CTL_W2: result := gGameControls.P1Control.KeyWeapon[WEAPON_PISTOL]; - CTL_W3: result := gGameControls.P1Control.KeyWeapon[WEAPON_SHOTGUN1]; - CTL_W4: result := gGameControls.P1Control.KeyWeapon[WEAPON_SHOTGUN2]; - CTL_W5: result := gGameControls.P1Control.KeyWeapon[WEAPON_CHAINGUN]; - CTL_W6: result := gGameControls.P1Control.KeyWeapon[WEAPON_ROCKETLAUNCHER]; - CTL_W7: result := gGameControls.P1Control.KeyWeapon[WEAPON_PLASMA]; - CTL_W8: result := gGameControls.P1Control.KeyWeapon[WEAPON_BFG]; - CTL_W9: result := gGameControls.P1Control.KeyWeapon[WEAPON_SUPERPULEMET]; - CTL_W10: result := gGameControls.P1Control.KeyWeapon[WEAPON_FLAMETHROWER]; - CTL_CON: result := IK_GRAVE; - CTL_STAT: result := gGameControls.GameControls.Stat; - CTL_TCHAT: result := gGameControls.GameControls.TeamChat; else - result := IK_INVALID + 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; + 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; + else + founded := false + end + end end end; - function GetControlName(control: Integer): String; + function GetKeyName(key: Word): String; begin - case control of - CTL_LEFT: result := 'LEFT'; - CTL_RIGHT: result := 'RIGHT'; - CTL_UP: result := 'UP'; - CTL_DOWN: result := 'DOWN'; - CTL_OPEN: result := 'OPEN'; - CTL_FIRE: result := 'FIRE'; - CTL_JUMP: result := 'JUMP'; - CTL_CHAT: result := 'CHAT'; - CTL_ESC: result := 'ESC'; - CTL_W0: result := '0'; - CTL_W1: result := '1'; - CTL_W2: result := '2'; - CTL_W3: result := '3'; - CTL_W4: result := '4'; - CTL_W5: result := '5'; - CTL_W6: result := '6'; - CTL_W7: result := '7'; - CTL_W8: result := '8'; - CTL_W9: result := '9'; - CTL_W10: result := '10'; - CTL_CON: result := 'CON'; - CTL_STAT: result := 'STAT'; - CTL_TCHAT: result := 'TEAM'; + case key of + VK_LEFT: result := 'LEFT'; + VK_RIGHT: result := 'RIGHT'; + VK_UP: result := 'UP'; + VK_DOWN: result := 'DOWN'; + VK_FIRE: result := 'FIRE'; + VK_OPEN: result := 'OPEN'; + VK_JUMP: result := 'JUMP'; + VK_CHAT: result := 'CHAT'; + VK_ESCAPE: result := 'ESC'; + VK_0: result := '0'; + VK_1: result := '1'; + VK_2: result := '2'; + VK_3: result := '3'; + VK_4: result := '4'; + VK_5: result := '5'; + VK_6: result := '6'; + VK_7: result := '7'; + VK_8: result := '8'; + VK_9: result := '9'; + VK_A: result := '10'; + VK_B: result := '11'; + VK_C: result := '12'; + VK_D: result := '13'; + VK_E: result := '14'; + VK_F: result := '15'; + 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] + else + result := '<' + IntToStr(key) + '>' end end; procedure DrawRect(x, y, w, h: Integer); begin - e_DrawQuad(x, y, x + w, y + h, 0, 255, 0, 127); + e_DrawQuad(x, y, x + w, y + h, 0, 255, 0, 63); end; function IntersectControl(ctl, xx, yy: Integer): Boolean; @@ -207,7 +165,7 @@ implementation x, y, w, h: Integer; founded: Boolean; begin - GetControlRect(ctl, x, y, w, h, founded); + GetKeyRect(ctl, x, y, w, h, founded); result := founded and (xx >= x) and (yy >= y) and (xx <= x + w) and (yy <= y + h); end; @@ -237,7 +195,7 @@ implementation x := Trunc(ev.x * gScreenWidth); y := Trunc(ev.y * gScreenHeight); - for i := 1 to CTL_LAST do + for i := VK_FIRSTKEY to VK_LASTKEY do begin if IntersectControl(i, x, y) then begin @@ -247,7 +205,7 @@ implementation keyFinger[i] := finger else if ev.type_ = SDL_FINGERDOWN then begin - KeyPress(GetMenuKey(i)); + KeyPress(i); // Menu events keyFinger[i] := finger; end end @@ -259,8 +217,7 @@ implementation keyFinger[i] := 0 end; - e_KeyUpDown(GetPlayerKey(i), keyFinger[i] <> 0); - e_KeyUpDown(GetMenuKey(i), keyFinger[i] <> 0); + e_KeyUpDown(i, keyFinger[i] <> 0); end; end; @@ -275,13 +232,13 @@ implementation if SDL_IsTextInputActive() = SDL_True then Exit; - for i := 1 to CTL_LAST do + for i := VK_FIRSTKEY to VK_LASTKEY do begin - GetControlRect(i, x, y, w, h, founded); + GetKeyRect(i, x, y, w, h, founded); if founded then begin DrawRect(x, y, w, h); - e_TextureFontPrint(x, y, GetControlName(i), gStdFont) + e_TextureFontPrint(x, y, GetKeyName(i), gStdFont) end; end; {$ENDIF} @@ -294,6 +251,7 @@ initialization size := 1; conRegVar('touch_enable', @enabled, 'enable/disable virtual buttons', 'draw buttons'); conRegVar('touch_size', @size, 0.1, 10, 'size of virtual buttons', 'button size'); + conRegVar('touch_alt', @jab, 'althernative virtual buttons layout', 'althernative layout'); end.