From 4ac477a64781436f4518e96009c3eef29979290b Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Thu, 1 Mar 2018 21:26:32 +0300 Subject: [PATCH] Added touchscreen settings --- src/game/g_language.pas | 11 ++++++++ src/game/g_main.pas | 3 +- src/game/g_menu.pas | 62 +++++++++++++++++++++++++++++++++++++---- src/game/g_options.pas | 10 ++++++- src/game/g_touch.pas | 28 +++++++++++-------- 5 files changed, 95 insertions(+), 19 deletions(-) diff --git a/src/game/g_language.pas b/src/game/g_language.pas index f325846..5bb1e5a 100644 --- a/src/game/g_language.pas +++ b/src/game/g_language.pas @@ -206,6 +206,10 @@ type I_MENU_CONTROL_JOYSTICKS, I_MENU_CONTROL_DEADZONE, + I_MENU_CONTROL_TOUCH, + I_MENU_CONTROL_TOUCH_FIRE, + I_MENU_CONTROL_TOUCH_SIZE, + I_MENU_CONTROL_GLOBAL, I_MENU_CONTROL_SCREENSHOT, I_MENU_CONTROL_STAT, @@ -981,6 +985,13 @@ const ('MENU CONTROL DEADZONE', 'Joystick %d Deadzone', '̸ðòâàÿ çîíà äæîéñòèêà %d'), + ('MENU CONTROL TOCUH', 'Touchscreen Settings', + 'Íàñòðîéêè ñåíñðíîãî ýêðàíà'), + ('MENU CONTROL TOUCH FIRE', 'Shoot Up/Down:', + 'Ñòðåëÿòü ââåðõ/âíèç:'), + ('MENU CONTROL TOUCH SIZE', 'Button size:', + 'Ðàçìåð êíîïîê:'), + ('MENU CONTROL GLOBAL', 'Global Controls', 'ÎÁÙÅÅ ÓÏÐÀÂËÅÍÈÅ'), ('MENU CONTROL SCREENSHOT', 'Screenshot:', diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 960eb9e..b564911 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -46,7 +46,7 @@ uses e_graphics, e_input, g_game, g_console, g_gui, e_sound, g_options, g_sound, g_player, g_basic, g_weapons, SysUtils, g_triggers, MAPDEF, g_map, - g_menu, g_language, g_net, g_holmes, + g_menu, g_language, g_net, g_holmes, g_touch, utils, conbuf, envvars, fui_wadread, fui_style, fui_gfx_gl, xparser; @@ -201,6 +201,7 @@ begin e_WriteLog('Init Input', TMsgType.Notify); e_InitInput(); + g_Touch_Init; if (e_JoysticksAvailable > 0) then e_WriteLog('Input: Joysticks available.', TMsgType.Notify) diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index 3056950..35a4a0b 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -52,7 +52,7 @@ uses e_log, SysUtils, CONFIG, g_playermodel, DateUtils, sdl2, MAPDEF, Math, g_saveload, e_texture, g_language, - g_net, g_netmsg, g_netmaster, g_items, e_input, + g_net, g_netmsg, g_netmaster, g_items, e_input, g_touch, utils, wadreader; @@ -164,7 +164,7 @@ begin gShowMessages := TGUISwitch(menu.GetControl('swMessages')).ItemIndex = 0; gRevertPlayers := TGUISwitch(menu.GetControl('swRevertPlayers')).ItemIndex = 0; gChatBubble := TGUISwitch(menu.GetControl('swChatBubble')).ItemIndex; - g_dbg_scale := TGUIScroll(menu.GetControl('swScaleFactor')).Value + 1; + g_dbg_scale := TGUIScroll(menu.GetControl('scScaleFactor')).Value + 1; menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsMenu').GetControl('mOptionsControlsMenu')); @@ -258,6 +258,13 @@ begin end; end; + if SDL_GetNumTouchDevices() > 0 then + begin + menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsTouchMenu').GetControl('mOptionsControlsTouchMenu')); + g_touch_size := TGUIScroll(menu.GetControl('scTouchSize')).Value / 10 + 0.5; + g_touch_fire := TGUISwitch(menu.GetControl('swTouchFire')).ItemIndex = 1; + end; + menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP1Menu').GetControl('mOptionsPlayersP1Menu')); gPlayer1Settings.Name := b_Text_Unformat(TGUIEdit(menu.GetControl('edP1Name')).Text); @@ -446,6 +453,14 @@ begin end; end; + if SDL_GetNumTouchDevices() > 0 then + begin + menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsTouchMenu').GetControl('mOptionsControlsTouchMenu')); + 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; + end; + menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsMenu').GetControl('mOptionsControlsMenu')); with menu, gGameControls.GameControls do begin @@ -496,7 +511,7 @@ begin with TGUISwitch(menu.GetControl('swChatBubble')) do ItemIndex := gChatBubble; - TGUIScroll(menu.GetControl('swScaleFactor')).Value := Round(g_dbg_scale - 1); + TGUIScroll(menu.GetControl('scScaleFactor')).Value := Round(g_dbg_scale - 1); menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP1Menu').GetControl('mOptionsPlayersP1Menu')); @@ -1267,7 +1282,15 @@ var menu: TGUIMenu; begin menu := TGUIMenu(g_GUI_GetWindow('OptionsGameMenu').GetControl('mOptionsGameMenu')); - g_dbg_scale := TGUIScroll(menu.GetControl('swScaleFactor')).Value + 1; + g_dbg_scale := TGUIScroll(menu.GetControl('scScaleFactor')).Value + 1; +end; + +procedure ProcChangeTouchSettings(Sender: TGUIControl); +var + menu: TGUIMenu; +begin + menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsTouchMenu').GetControl('mOptionsControlsTouchMenu')); + g_touch_size := TGUIScroll(menu.GetControl('scTouchSize')).Value / 10 + 0.5; end; procedure ProcOptionsPlayersMIMenu(); @@ -2686,7 +2709,7 @@ begin end; with AddScroll(_lc[I_MENU_GAME_SCALE_FACTOR]) do begin - Name := 'swScaleFactor'; + Name := 'scScaleFactor'; Max := 10; OnChange := ProcChangeGameSettings; end; @@ -2711,9 +2734,16 @@ begin AddButton(nil, _lc[I_MENU_PLAYER_2_KBD], 'OptionsControlsP2Menu'); {AddButton(nil, _lc[I_MENU_PLAYER_2_ALT], 'OptionsControlsP2MenuAlt');} AddButton(nil, _lc[I_MENU_PLAYER_2_WEAPONS], 'OptionsControlsP2MenuWeapons'); - AddSpace(); if e_JoysticksAvailable <> 0 then + begin + AddSpace(); AddButton(nil, _lc[I_MENU_CONTROL_JOYSTICKS], 'OptionsControlsJoystickMenu'); + end; + if SDL_GetNumTouchDevices() > 0 then + begin + AddSpace(); + AddButton(nil, _lc[I_MENU_CONTROL_TOUCH], 'OptionsControlsTouchMenu'); + end; end; Menu.DefControl := 'mOptionsControlsMenu'; g_GUI_AddWindow(Menu); @@ -2790,6 +2820,26 @@ begin Menu.DefControl := 'mOptionsControlsJoystickMenu'; g_GUI_AddWindow(Menu); + Menu := TGUIWindow.Create('OptionsControlsTouchMenu'); + with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_CONTROL_TOUCH]))) do + begin + Name := 'mOptionsControlsTouchMenu'; + with AddScroll(_lc[I_MENU_CONTROL_TOUCH_SIZE]) do + begin + Name := 'scTouchSize'; + Max := 20; + OnChange := ProcChangeTouchSettings; + end; + with AddSwitch(_lc[I_MENU_CONTROL_TOUCH_FIRE]) do + begin + Name := 'swTouchFire'; + AddItem(_lc[I_MENU_NO]); + AddItem(_lc[I_MENU_YES]); + end; + end; + Menu.DefControl := 'mOptionsControlsTouchMenu'; + g_GUI_AddWindow(Menu); + Menu := TGUIWindow.Create('OptionsPlayersMenu'); with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_PLAYER_OPTIONS]))) do begin diff --git a/src/game/g_options.pas b/src/game/g_options.pas index a1397a8..3d2fed9 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -141,7 +141,7 @@ uses {$ENDIF} e_log, e_input, g_window, g_sound, g_gfx, g_player, Math, g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture, - g_items, wadreader, e_graphics; + g_items, wadreader, e_graphics, g_touch; procedure g_Options_SetDefault(); var @@ -167,6 +167,8 @@ begin gShowMessages := True; gRevertPlayers := False; g_dbg_scale := 1.0; + g_touch_size := 1.0; + g_touch_fire := True; for i := 0 to e_MaxJoys-1 do e_JoystickDeadzones[i] := 8192; @@ -420,6 +422,9 @@ begin for i := 0 to e_MaxJoys-1 do e_JoystickDeadzones[i] := config.ReadInt('Joysticks', 'Deadzone' + IntToStr(i), 8192); + g_touch_size := Max(config.ReadInt('Touch', 'Size', 10) / 10, 0.1); + g_touch_fire := config.ReadBool('Touch', 'Fire', True); + g_GFX_SetMax(Min(config.ReadInt('Game', 'MaxParticles', 1000), 50000)); g_Shells_SetMax(Min(config.ReadInt('Game', 'MaxShells', 300), 600)); g_Gibs_SetMax(Min(config.ReadInt('Game', 'MaxGibs', 150), 500)); @@ -660,6 +665,9 @@ begin for i := 0 to e_MaxJoys-1 do config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]); + config.WriteInt('Touch', 'Size', Round(g_touch_size * 10)); + config.WriteBool('Touch', 'Fire', g_touch_fire); + with config do case gGibsCount of 0: config.WriteInt('Game', 'GibsCount', 0); diff --git a/src/game/g_touch.pas b/src/game/g_touch.pas index 52167bd..8519f0d 100644 --- a/src/game/g_touch.pas +++ b/src/game/g_touch.pas @@ -21,6 +21,11 @@ interface uses SDL2; + var + g_touch_size: Single; + g_touch_fire: Boolean; + + procedure g_Touch_Init; procedure g_Touch_ShowKeyboard(yes: Boolean); procedure g_Touch_HandleEvent(const ev: TSDL_TouchFingerEvent); procedure g_Touch_Draw; @@ -33,9 +38,8 @@ implementation var jab: Boolean; - size: Single; enabled: Boolean; - angleFireEnabled, angleFire: Boolean; + angleFire: Boolean; keyFinger: array [VK_FIRSTKEY..VK_LASTKEY] of Integer; procedure GetKeyRect(key: Word; out x, y, w, h: Integer; out founded: Boolean); @@ -47,7 +51,7 @@ implementation dpi := 96; founded := true; - sz := Trunc(size * dpi); + sz := Trunc(g_touch_size * dpi); sw := gScreenWidth; sh := gScreenHeight; if jab then begin @@ -176,6 +180,13 @@ implementation result := founded and (xx >= x) and (yy >= y) and (xx <= x + w) and (yy <= y + h); end; + procedure g_Touch_Init; + begin +{$IFNDEF HEADLESS} + enabled := SDL_GetNumTouchDevices() > 0 +{$ENDIF} + end; + procedure g_Touch_ShowKeyboard(yes: Boolean); begin {$IFNDEF HEADLESS} @@ -228,7 +239,7 @@ implementation end; (* emulate up+fire / donw+fire *) - if angleFireEnabled and (gGameSettings.GameType <> GT_NONE) then + if g_touch_fire and (gGameSettings.GameType <> GT_NONE) then begin if keyFinger[VK_UP] <> 0 then begin @@ -303,14 +314,9 @@ implementation end; initialization -{$IFDEF ANDROID} - 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_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_alt', @jab, 'althernative virtual buttons layout', 'althernative layout'); end. -- 2.29.2