From: Ketmar Dark Date: Mon, 5 Jun 2017 15:51:06 +0000 (+0300) Subject: "strife" key for gaypad keyset X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=c60af5eda7f59dd43a46577bf27497a8e74f04fd;p=d2df-sdl.git "strife" key for gaypad keyset --- diff --git a/src/game/g_game.pas b/src/game/g_game.pas index baf0f63..110111e 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -300,6 +300,12 @@ var gEvents: Array of TGameEvent; gDelayedEvents: Array of TDelayedEvent; + // move button values: + // bits 0-1: l/r state: + // 0: neither left, nor right pressed + // 1: left pressed + // 2: right pressed + // bits 4-5: l/r state when strafe was pressed P1MoveButton: Byte = 0; P2MoveButton: Byte = 0; @@ -1229,9 +1235,12 @@ end; procedure processPlayerControls (plr: TPlayer; var ctrl: TPlayerControl; var MoveButton: Byte; p2hack: Boolean=false); var time: Word; + strafeDir: Byte; begin if (plr = nil) then exit; if (p2hack) then time := 1000 else time := 1; + strafeDir := MoveButton shr 4; + MoveButton := MoveButton and $0F; with ctrl do begin if isKeyPressed(KeyLeft, KeyLeft2) and (not isKeyPressed(KeyRight, KeyRight2)) then MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî" @@ -1242,12 +1251,29 @@ begin if MoveButton = 1 then plr.PressKey(KEY_LEFT, time) else if MoveButton = 2 then plr.PressKey(KEY_RIGHT, time); - // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî: - if (MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then plr.SetDirection(D_LEFT) - // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî: - else if (MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then plr.SetDirection(D_RIGHT) - // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì: - else if MoveButton <> 0 then plr.SetDirection(TDirection(MoveButton-1)); + // if we have "strafe" key, turn off old strafe mechanics + if isKeyPressed(KeyStrafe, KeyStrafe2) then + begin + // new strafe mechanics + if (strafeDir = 0) then strafeDir := MoveButton; // start strafing + // now set direction according to strafe + if (strafeDir = 1) then plr.SetDirection(D_LEFT) + else if (strafeDir = 2) then plr.SetDirection(D_RIGHT) + else plr.SetDirection(TDirection(MoveButton-1)); + end + else + begin + strafeDir := 0; // not strafing anymore + // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî: + if (MoveButton = 2) and isKeyPressed(KeyLeft, KeyLeft2) then plr.SetDirection(D_LEFT) + // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî: + else if (MoveButton = 1) and isKeyPressed(KeyRight, KeyRight2) then plr.SetDirection(D_RIGHT) + // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì: + else if MoveButton <> 0 then plr.SetDirection(TDirection(MoveButton-1)); + end; + + // fix movebutton state + MoveButton := MoveButton or (strafeDir shl 4); // Îñòàëüíûå êëàâèøè: if isKeyPressed(KeyJump, KeyJump2) then plr.PressKey(KEY_JUMP, time); diff --git a/src/game/g_language.pas b/src/game/g_language.pas index 1d90b69..d340408 100644 --- a/src/game/g_language.pas +++ b/src/game/g_language.pas @@ -203,6 +203,7 @@ type I_MENU_CONTROL_USE, I_MENU_CONTROL_NEXT_WEAPON, I_MENU_CONTROL_PREV_WEAPON, + I_MENU_CONTROL_STRAFE, I_MENU_COUNT_NONE, I_MENU_COUNT_SMALL, @@ -911,14 +912,14 @@ const 'Îñòàëîñü %d ñåêóíä äî ñëåäóþùåãî ðàóíäà'), ('MENU LOADING', 'Loading...', 'Çàãðóçêà...'), - ('MENU PLAYER 1', 'Player 1', - 'Ïåðâûé èãðîê'), - ('MENU PLAYER 2', 'Player 2', - 'Âòîðîé èãðîê'), - ('MENU PLAYER 1 ALT', 'Player 1 ALT', - 'Ïåðâûé èãðîê ALT'), - ('MENU PLAYER 2 ALT', 'Player 2 ALT', - 'Âòîðîé èãðîê ALT'), + ('MENU PLAYER 1', 'Player 1 KEYBOARD', + 'Ïåðâûé èãðîê, êëàâèàòóðà'), + ('MENU PLAYER 2', 'Player 2 KEYBOARD', + 'Âòîðîé èãðîê, êëàâèàòóðà'), + ('MENU PLAYER 1 ALT', 'Player 1 GAMEPAD', + 'Ïåðâûé èãðîê GAMEPAD'), + ('MENU PLAYER 2 ALT', 'Player 2 GAMEPAD', + 'Âòîðîé èãðîê GAMEPAD'), ('MENU CONTROL JOYSTICKS', 'Joystick Settings', 'Íàñòðîéêè äæîéñòèêîâ'), @@ -953,6 +954,8 @@ const 'Ñëåä. îðóæèå:'), ('MENU CONTROL PREV WEAPON', 'Prev weapon:', 'Ïðåä. îðóæèå:'), + ('MENU CONTROL STRAFE', 'Strafe:', + 'Ñòðýéô:'), ('MENU COUNT NONE', 'None', 'Íåò'), diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index bdf925b..5cd389b 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -189,6 +189,7 @@ begin KeyNextWeapon2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_NEXT_WEAPON])).Key; KeyPrevWeapon2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_PREV_WEAPON])).Key; KeyOpen2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_USE])).Key; + KeyStrafe2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_STRAFE])).Key; end; menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsP2Menu').GetControl('mOptionsControlsP2Menu')); @@ -217,6 +218,7 @@ begin KeyNextWeapon2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_NEXT_WEAPON])).Key; KeyPrevWeapon2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_PREV_WEAPON])).Key; KeyOpen2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_USE])).Key; + KeyStrafe2 := TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_STRAFE])).Key; end; if e_JoysticksAvailable > 0 then @@ -355,6 +357,7 @@ begin TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_NEXT_WEAPON])).Key := KeyNextWeapon2; TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_PREV_WEAPON])).Key := KeyPrevWeapon2; TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_USE])).Key := KeyOpen2; + TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_STRAFE])).Key := KeyStrafe2; end; menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsP2Menu').GetControl('mOptionsControlsP2Menu')); @@ -383,6 +386,7 @@ begin TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_NEXT_WEAPON])).Key := KeyNextWeapon2; TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_PREV_WEAPON])).Key := KeyPrevWeapon2; TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_USE])).Key := KeyOpen2; + TGUIKeyRead(GetControl(_lc[I_MENU_CONTROL_STRAFE])).Key := KeyStrafe2; end; if e_JoysticksAvailable > 0 then @@ -2637,6 +2641,7 @@ begin AddKeyRead(_lc[I_MENU_CONTROL_USE]).Name := _lc[I_MENU_CONTROL_USE]; AddKeyRead(_lc[I_MENU_CONTROL_NEXT_WEAPON]).Name := _lc[I_MENU_CONTROL_NEXT_WEAPON]; AddKeyRead(_lc[I_MENU_CONTROL_PREV_WEAPON]).Name := _lc[I_MENU_CONTROL_PREV_WEAPON]; + AddKeyRead(_lc[I_MENU_CONTROL_STRAFE]).Name := _lc[I_MENU_CONTROL_STRAFE]; end; Menu.DefControl := 'mOptionsControlsP1MenuAlt'; g_GUI_AddWindow(Menu); @@ -2671,6 +2676,7 @@ begin AddKeyRead(_lc[I_MENU_CONTROL_USE]).Name := _lc[I_MENU_CONTROL_USE]; AddKeyRead(_lc[I_MENU_CONTROL_NEXT_WEAPON]).Name := _lc[I_MENU_CONTROL_NEXT_WEAPON]; AddKeyRead(_lc[I_MENU_CONTROL_PREV_WEAPON]).Name := _lc[I_MENU_CONTROL_PREV_WEAPON]; + AddKeyRead(_lc[I_MENU_CONTROL_STRAFE]).Name := _lc[I_MENU_CONTROL_STRAFE]; end; Menu.DefControl := 'mOptionsControlsP2MenuAlt'; g_GUI_AddWindow(Menu); diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 65e6f21..2ad3e6e 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -32,6 +32,7 @@ type KeyNextWeapon: Word; KeyPrevWeapon: Word; KeyOpen: Word; + KeyStrafe: Word; KeyRight2: Word; KeyLeft2: Word; @@ -42,6 +43,7 @@ type KeyNextWeapon2: Word; KeyPrevWeapon2: Word; KeyOpen2: Word; + KeyStrafe2: Word; end; TGameControls = record @@ -175,6 +177,7 @@ begin KeyNextWeapon := 73; KeyPrevWeapon := 71; KeyOpen := 54; + KeyStrafe := 0; KeyRight2 := 0; KeyLeft2 := 0; @@ -185,6 +188,7 @@ begin KeyNextWeapon2 := 0; KeyPrevWeapon2 := 0; KeyOpen2 := 0; + KeyStrafe2 := 0; end; with gGameControls.P2Control do @@ -198,6 +202,7 @@ begin KeyNextWeapon := 19; KeyPrevWeapon := 17; KeyOpen := 58; + KeyStrafe := 0; KeyRight2 := 0; KeyLeft2 := 0; @@ -208,6 +213,7 @@ begin KeyNextWeapon2 := 0; KeyPrevWeapon2 := 0; KeyOpen2 := 0; + KeyStrafe2 := 0; end; with gPlayer1Settings do @@ -314,6 +320,7 @@ begin KeyNextWeapon := ReadInt('Player1', 'KeyNextWeapon', 19); KeyPrevWeapon := ReadInt('Player1', 'KeyPrevWeapon', 17); KeyOpen := ReadInt('Player1', 'KeyOpen', 58); + KeyStrafe := ReadInt('Player1', 'KeyStrafe', 0); KeyRight2 := ReadInt('Player1', 'KeyRight2', 0); KeyLeft2 := ReadInt('Player1', 'KeyLeft2', 0); @@ -324,6 +331,7 @@ begin KeyNextWeapon2 := ReadInt('Player1', 'KeyNextWeapon2', 0); KeyPrevWeapon2 := ReadInt('Player1', 'KeyPrevWeapon2', 0); KeyOpen2 := ReadInt('Player1', 'KeyOpen2', 0); + KeyStrafe2 := ReadInt('Player1', 'KeyStrafe2', 0); end; with gPlayer1Settings, config do @@ -349,6 +357,7 @@ begin KeyNextWeapon := ReadInt('Player2', 'KeyNextWeapon', 73); KeyPrevWeapon := ReadInt('Player2', 'KeyPrevWeapon', 71); KeyOpen := ReadInt('Player2', 'KeyOpen', 54); + KeyStrafe := ReadInt('Player2', 'KeyStrafe', 0); KeyRight2 := ReadInt('Player2', 'KeyRight2', 0); KeyLeft2 := ReadInt('Player2', 'KeyLeft2', 0); @@ -359,6 +368,7 @@ begin KeyNextWeapon2 := ReadInt('Player2', 'KeyNextWeapon2', 0); KeyPrevWeapon2 := ReadInt('Player2', 'KeyPrevWeapon2', 0); KeyOpen2 := ReadInt('Player2', 'KeyOpen2', 0); + KeyStrafe2 := ReadInt('Player2', 'KeyStrafe2', 0); end; with gPlayer2Settings, config do @@ -550,6 +560,7 @@ begin WriteInt('Player1', 'KeyNextWeapon', KeyNextWeapon); WriteInt('Player1', 'KeyPrevWeapon', KeyPrevWeapon); WriteInt('Player1', 'KeyOpen', KeyOpen); + WriteInt('Player1', 'KeyStrafe', KeyStrafe); WriteInt('Player1', 'KeyRight2', KeyRight2); WriteInt('Player1', 'KeyLeft2', KeyLeft2); @@ -560,6 +571,7 @@ begin WriteInt('Player1', 'KeyNextWeapon2', KeyNextWeapon2); WriteInt('Player1', 'KeyPrevWeapon2', KeyPrevWeapon2); WriteInt('Player1', 'KeyOpen2', KeyOpen2); + WriteInt('Player1', 'KeyStrafe2', KeyStrafe2); WriteStr('Player1', 'Name', Name); WriteStr('Player1', 'model', Model); @@ -580,6 +592,7 @@ begin WriteInt('Player2', 'KeyNextWeapon', KeyNextWeapon); WriteInt('Player2', 'KeyPrevWeapon', KeyPrevWeapon); WriteInt('Player2', 'KeyOpen', KeyOpen); + WriteInt('Player2', 'KeyStrafe', KeyStrafe); WriteInt('Player2', 'KeyRight2', KeyRight2); WriteInt('Player2', 'KeyLeft2', KeyLeft2); @@ -590,6 +603,7 @@ begin WriteInt('Player2', 'KeyNextWeapon2', KeyNextWeapon2); WriteInt('Player2', 'KeyPrevWeapon2', KeyPrevWeapon2); WriteInt('Player2', 'KeyOpen2', KeyOpen2); + WriteInt('Player2', 'KeyStrafe2', KeyStrafe2); WriteStr('Player2', 'Name', Name); WriteStr('Player2', 'model', Model);