From 040fb4ac9f2e6be72bca1fe14cb25ecd7787da6d Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sun, 6 May 2018 01:28:29 +0300 Subject: [PATCH] Added option for alt vkbd layout --- src/game/g_language.pas | 3 +++ src/game/g_menu.pas | 17 ++++++++++++++--- src/game/g_options.pas | 3 +++ src/game/g_touch.pas | 26 +++++++++++++------------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/game/g_language.pas b/src/game/g_language.pas index 18d0d72..8cadba1 100644 --- a/src/game/g_language.pas +++ b/src/game/g_language.pas @@ -207,6 +207,7 @@ type I_MENU_CONTROL_DEADZONE, I_MENU_CONTROL_TOUCH, + I_MENU_CONTROL_TOUCH_ALT, I_MENU_CONTROL_TOUCH_FIRE, I_MENU_CONTROL_TOUCH_SIZE, I_MENU_CONTROL_TOUCH_OFFSET, @@ -988,6 +989,8 @@ const ('MENU CONTROL TOCUH', 'Touchscreen Settings', 'Íàñòðîéêè ñåíñðíîãî ýêðàíà'), + ('MENU CONTROL TOUCH ALT', 'Alternative layout:', + 'Àëüòåðíàòèâíàÿ ðàñêëàäêà:'), ('MENU CONTROL TOUCH FIRE', 'Shoot Up/Down:', 'Ñòðåëÿòü ââåðõ/âíèç:'), ('MENU CONTROL TOUCH SIZE', 'Button size:', diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index 629c38c..b84467f 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -258,9 +258,10 @@ begin end; end; - if SDL_GetNumTouchDevices() > 0 then + if g_touch_enabled then begin menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsTouchMenu').GetControl('mOptionsControlsTouchMenu')); + g_touch_alt := TGUISwitch(menu.GetControl('swTouchAlt')).ItemIndex = 1; g_touch_size := TGUIScroll(menu.GetControl('scTouchSize')).Value / 10 + 0.5; g_touch_fire := TGUISwitch(menu.GetControl('swTouchFire')).ItemIndex = 1; g_touch_offset := TGUIScroll(menu.GetControl('scTouchOffset')).Value * 5; @@ -454,9 +455,11 @@ begin end; end; - if SDL_GetNumTouchDevices() > 0 then + if g_touch_enabled then begin menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsTouchMenu').GetControl('mOptionsControlsTouchMenu')); + with TGUISwitch(menu.GetControl('swTouchAlt')) do + if g_touch_alt then ItemIndex := 1 else ItemIndex := 0; TGUIScroll(menu.GetControl('scTouchSize')).Value := Round((g_touch_size - 0.5) * 10); with TGUISwitch(menu.GetControl('swTouchFire')) do if g_touch_fire then ItemIndex := 1 else ItemIndex := 0; @@ -1292,6 +1295,7 @@ var menu: TGUIMenu; begin menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsTouchMenu').GetControl('mOptionsControlsTouchMenu')); + g_touch_alt := TGUISwitch(menu.GetControl('swTouchAlt')).ItemIndex = 1; g_touch_size := TGUIScroll(menu.GetControl('scTouchSize')).Value / 10 + 0.5; g_touch_offset := TGUIScroll(menu.GetControl('scTouchOffset')).Value * 5; end; @@ -2742,7 +2746,7 @@ begin AddSpace(); AddButton(nil, _lc[I_MENU_CONTROL_JOYSTICKS], 'OptionsControlsJoystickMenu'); end; - if SDL_GetNumTouchDevices() > 0 then + if g_touch_enabled then begin AddSpace(); AddButton(nil, _lc[I_MENU_CONTROL_TOUCH], 'OptionsControlsTouchMenu'); @@ -2827,6 +2831,13 @@ begin with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_CONTROL_TOUCH]))) do begin Name := 'mOptionsControlsTouchMenu'; + with AddSwitch(_lc[I_MENU_CONTROL_TOUCH_ALT]) do + begin + Name := 'swTouchAlt'; + AddItem(_lc[I_MENU_NO]); + AddItem(_lc[I_MENU_YES]); + OnChange := ProcChangeTouchSettings; + end; with AddScroll(_lc[I_MENU_CONTROL_TOUCH_SIZE]) do begin Name := 'scTouchSize'; diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 0397f37..15719e6 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -170,6 +170,7 @@ begin g_touch_size := 1.0; g_touch_fire := True; g_touch_offset := 50; + g_touch_alt := False; for i := 0 to e_MaxJoys-1 do e_JoystickDeadzones[i] := 8192; @@ -426,6 +427,7 @@ begin g_touch_size := Max(config.ReadInt('Touch', 'Size', 10) / 10, 0.1); g_touch_fire := config.ReadBool('Touch', 'Fire', True); g_touch_offset := Max(Min(config.ReadInt('Touch', 'Offset', 50), 100), 0); + g_touch_alt := config.ReadBool('Touch', 'Alt', False); g_GFX_SetMax(Min(config.ReadInt('Game', 'MaxParticles', 1000), 50000)); g_Shells_SetMax(Min(config.ReadInt('Game', 'MaxShells', 300), 600)); @@ -670,6 +672,7 @@ begin config.WriteInt('Touch', 'Size', Round(g_touch_size * 10)); config.WriteBool('Touch', 'Fire', g_touch_fire); config.WriteInt('Touch', 'Offset', Round(g_touch_offset)); + config.WriteBool('Touch', 'Alt', g_touch_alt); with config do case gGibsCount of diff --git a/src/game/g_touch.pas b/src/game/g_touch.pas index 9256fb8..1778eca 100644 --- a/src/game/g_touch.pas +++ b/src/game/g_touch.pas @@ -22,9 +22,11 @@ interface SDL2; var - g_touch_size: Single = 1.0; - g_touch_offset: Single = 50; - g_touch_fire: Boolean = True; + g_touch_enabled: Boolean; + g_touch_size: Single; + g_touch_offset: Single; + g_touch_fire: Boolean; + g_touch_alt: Boolean; procedure g_Touch_Init; procedure g_Touch_ShowKeyboard(yes: Boolean); @@ -38,8 +40,6 @@ implementation e_log, e_graphics, e_input, g_options, g_game, g_main, g_weapons, g_console; var - jab: Boolean; - enabled: Boolean; angleFire: Boolean; keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer; @@ -54,7 +54,7 @@ implementation founded := true; sz := Trunc(g_touch_size * dpi); sw := gScreenWidth; sh := gScreenHeight; - if jab then + if g_touch_alt then begin w := sz div 2; h := sz div 2; case key of @@ -64,7 +64,7 @@ implementation VK_STATUS: begin x := sw div 2 - w div 2 + 0; y := 0 end; VK_TEAM: begin x := sw div 2 - w div 2 + w; y := 0 end; VK_PREV: begin x := 0; y := sh - 4*sz - 1; w := sz end; - VK_NEXT: begin x := sw - w - 1; y := sh - 4*sz - 1; w := sz end; + VK_NEXT: begin x := sw - sz - 1; y := sh - 4*sz - 1; w := sz end; else w := sz; h := sz * 3; case key of @@ -185,14 +185,14 @@ implementation procedure g_Touch_Init; begin {$IFNDEF HEADLESS} - enabled := SDL_GetNumTouchDevices() > 0 + g_touch_enabled := SDL_GetNumTouchDevices() > 0 {$ENDIF} end; procedure g_Touch_ShowKeyboard(yes: Boolean); begin {$IFNDEF HEADLESS} - if not enabled then + if not g_touch_enabled then Exit; if yes then @@ -206,7 +206,7 @@ implementation var x, y, i, finger: Integer; begin - if not enabled then + if not g_touch_enabled then Exit; if SDL_IsTextInputActive() = SDL_True then Exit; @@ -298,7 +298,7 @@ implementation founded: Boolean; begin {$IFNDEF HEADLESS} - if not enabled then + if not g_touch_enabled then Exit; if SDL_IsTextInputActive() = SDL_True then Exit; @@ -316,9 +316,9 @@ implementation end; initialization - conRegVar('touch_enable', @enabled, 'enable/disable virtual buttons', 'draw buttons'); + conRegVar('touch_enable', @g_touch_enabled, 'enable/disable virtual buttons', 'draw buttons'); conRegVar('touch_fire', @g_touch_fire, 'enable/disable fire when press virtual up/down', 'fire when press up/down'); conRegVar('touch_size', @g_touch_size, 0.1, 10, 'size of virtual buttons', 'button size'); conRegVar('touch_offset', @g_touch_offset, 0, 100, '', ''); - conRegVar('touch_alt', @jab, 'althernative virtual buttons layout', 'althernative layout'); + conRegVar('touch_alt', @g_touch_alt, 'althernative virtual buttons layout', 'althernative layout'); end. -- 2.29.2