ddnet/data
Robert Müller fe2f73b518 Add ingame touch controls
Add new client component `CTouchControls` for playing the game with touch inputs. The touch controls can be enabled/disabled with the config variable `cl_touch_controls`, which defaults to `1` on Android and `0` on other platforms. The touch controls consist of various on-screen touch buttons. The different buttons are only shown when they are usable depending on the context. The touch button configuration is stored in `touch_controls.json`.

Default touch button configuration
----------------------------------

Movement buttons for left, right and jump actions are arranged in a `⊥`-pattern similar to WASD controls.

For the fire and hook action, two modes are implemented:

1. Direct touch input: the mouse is moved exactly where the player touches on the screen.
2. Virtual joystick: a button is used to emulate a joystick, which moves the mouse relative to the center of the screen.

In either mode, a button is used to switch between the active actions (fire and hook). While the virtual joystick is being held down, this button uses the other action directly instead of switching it.

The direct touch input mode can be enabled/disabled separately for ingame/spectating, to prevent accidental direct touch input when using a joystick.

When spectating, direct touch input is used to allow panning the map directly like in an image/map viewer. Virtual joysticks can also be used to pan the map while spectating.

Two separate buttons are shown to switch to the previous and next weapons.

A hamburger menu button `☰` is used to toggle the visibility of lesser used touch buttons. This includes buttons for showing the scoreboard, showing the emoticon selector, showing the spectator menu, opening team and team chat, voting yes/no, and zooming. Long pressing the hamburger menu button will open the regular menu.

When the dummy is connected, a button for swapping between main and dummy is shown.

The emoticon selector and spectator menu are activated with the respective touch buttons and can be deactivated by touching outside of them or by using the back-button, as toggling them while the ingame touch button is pressed down is currently not feasible and also inconvenient at least for using the spectator menu.

Touch button configuration format
---------------------------------

The default button layout described above is loaded from `data/touch_controls.json`. This layout can be overridden by creating `touch_controls.json` in the user directory. The following button properties are adjustable:

- Position and size (attributes `x`, `y`, `w`, `h`): the X/Y position and width/height are integers on a 1,000,000² grid. The unit grid values are converted to screen grid values at runtime in relation to the aspect ratio of the screen. This means buttons may appear stretched if the resolution is changed, but it allows us to provide a reasonable default for slightly different aspect ratios. If we save the absolute position instead, we would have the problem of buttons appearing outside the screen or not being aligned on different aspect ratios.
- Shape (attribute `shape`): determines the shape of the button being rendered.
    - `"rect"`: rectangle shape.
    - `"circle"`: circle shape. The button size will automatically be adjusted so that width and height are identical.
- Visibility (attribute `visibilities`): an array of predefined visibility classes can be selected and the button is only shown if all conditions are satisfied. An empty array means that the button is always shown. The following visibility classes are defined:
    - `"ingame"`: player is ingame, i.e. not spectating.
    - `"extra-menu"`, `"extra-menu-2"`, ..., `"extra-menu-5"`: the extra menu with the given number is activated.
    - `"zoom-allowed"`: zoom is allowed on the this server.
    - `"vote-active"`: a vote is currently active.
    - `"dummy-allowed"`: dummy is allowed on this server.
    - `"dummy-connected"`: dummy is currently connected.
    - `"rcon-authed"`: player is currently authed in rcon.
    - All visibility classes can be inverted by prefixing them with `-`, e.g. `"-ingame"` is satisfied when the player is not ingame, i.e. spectating.
- Behavior (attribute `behavior`): an object which describes the behavior of this touch button when it is activated/deactivated as well as its label. The attribute `type` is used to differentiate which type of behavior is used. The behavior is either predefined (hard-coded) or a generic console command (bind). Predefined behavior is only used where necessary, all other buttons are represented as generic binds.
    - Predefined behavior (attribute `type` set to `"predefined"`): The attribute `id` is set to a fixed string value which determines the specific predefined behavior. The following predefined behaviors exist:
        - `"ingame-menu"`: Opens the ingame menu immediately when released.
        - `"extra-menu"`: The extra menu button which toggles visibility of buttons with `"extra-menu"`, `"extra-menu-2"`, `"extra-menu-3"` etc. visibilities. Also opens the normal menu on long press.
            - The attribute `"number"` specifies an integer between 1 and 5 to associate this button with the respective visibilities `"extra-menu"`, `"extra-menu-2"`, ..., `"extra-menu-5"`.
        - `"emoticon"`: Opens the emoticon selector (this does not work with binds).
        - `"spectate"`: Opens the spectator menu (this does not work with binds).
        - `"swap-action"`: Swaps the active action (fire and hook) for direct touch input and virtual joysticks.
        - `"use-action"`: Uses the active action with the current aiming position.
        - `"joystick-action"`: Virtual joystick which uses the active action.
        - `"joystick-fire"`: Virtual joystick which always uses fire.
        - `"joystick-hook"`: Virtual joystick which always uses hook.
    - Bind behavior (attribute `type` set to `"bind"`). Buttons with this behavior work like regular key binds.
        - The attribute `"label"` specifies as a string the label of the button.
        - The attribute `"label-type"` specifies as a string the type of the label of the button, i.e. how the attribute `"label"` is interpreted:
            - `"plain"`: Label is used as is.
            - `"localized"`: Label is localized. Only usable for the default buttons for which there are translations available.
            - `"icon"`: Icon font is used for the label. Icons must be encoded using `\uXXXX`, e.g. `\uf3ce` for the mobile phone icon.
        - The attribute `"command"` specifies as a string the command to execute in the console like a bind when this button is used.

Ingame menu buttons
-------------------

In addition to the separate on-screen touch controls, a second row is added to the main page of the ingame menu when `cl_touch_controls` is enabled for less frequently used functions which are otherwise not usable without a keyboard:

- Buttons to open the local and remote consoles. Opening the local console without the touch controls is useful because error messages would be shown there if the touch controls configuration could not be loaded.
- Button to close the menu, which is more convenient than using the virtual back button if it's not always shown.
- Checkbox for toggling the touch controls editor UI (see below).

Ingame touch controls editor
----------------------------

The user interface to adjust the touch controls is rendered over the main screen of the ingame menu when enabled. For now, the implementation of the touch controls editor is limited to basic configuration management functions.

- Saving the configuration to the `touch_controls.json` file in config directory.
- Discarding the current changes by reloading the `touch_controls.json` file from config directory.
- Restoring the default configuration by reloading the `touch_controls.json` file from data directory.
- Displaying whether there are unsaved changes.
- Importing and exporting the configuration from and to the clipboard. This is the only way to edit the configuration on newer Android versions, as editing files within apps' storage is not possible anymore.

Furthermore, the global touch controls settings can be adjusted in this UI:

- Direct touch input can be enabled/disabled separately while ingame and while spectating.

While the touch controls editor is active, all buttons are shown regardless of their visibility, to better support arranging the buttons.

Future tasks
------------

- Implement more usable UI for adjusting the button layout.
- Add `color` property to touch buttons to adjust the default background color?
- Support zooming gesture.
- Optimize touch button rendering using text and quad containers.
2024-09-08 11:08:23 +02:00
..
assets Revert "Add comic emoticons by Ravie" 2023-03-01 00:10:37 +01:00
audio Rename rifle to laser 2019-11-22 15:37:18 +01:00
communityicons Add tabs for favorite communities, separate country/type filters 2024-02-03 21:12:23 +01:00
countryflags Fix country flags MW and MQ not being loaded anymore 2023-09-13 18:56:10 +02:00
editor Rename grass_main_0.7 to ddnet_grass 2024-08-18 10:32:33 +08:00
fonts Add font index, support font family variants depending on language 2023-08-01 19:30:25 +02:00
languages Update brazilian_portuguese.txt 2024-09-02 16:02:39 -03:00
mapres Merge pull request #8751 from ChillerDragon/pr_grass_main_07_vanilla 2024-08-18 08:18:31 +00:00
maps Add check for correct finish time in integration_test.sh 2024-04-21 23:24:16 +02:00
maps7 Update Tutorial map by unique_2 2022-10-03 10:17:13 +02:00
menuimages Revert "Dilate & optimize non-dilated images" 2021-02-03 20:40:10 +01:00
shader Fix multi sampling accuracy 2023-12-17 10:39:28 +01:00
skins additional optimization 2023-09-11 17:23:39 -04:00
skins7 fix 0.7 feet offset 2024-08-19 15:34:44 +02:00
themes Fix winter theme 2023-09-20 15:04:38 +02:00
arrow.png Optimize PNGs 2016-04-27 01:27:57 +02:00
autoexec_server.cfg Remove unused commands from autoexec cfg 2023-10-01 11:42:58 +02:00
blob.png Merge remote-tracking branch 'timakro/new_hookthrough' 2016-04-27 18:59:51 +02:00
censorlist.txt Implement censoring words on server 2020-09-18 19:18:08 +02:00
console.png Optimize PNGs 2016-04-27 01:27:57 +02:00
console_bar.png Optimize PNGs 2016-04-27 01:27:57 +02:00
deadtee.png Add 0.7 client support 2024-08-10 14:50:42 +02:00
debug_font.png Optimize PNGs 2016-04-27 01:27:57 +02:00
emoticons.png Revert "Dilate & optimize non-dilated images" 2021-02-03 20:40:10 +01:00
extras.png simplify the snowflake 2022-06-30 00:02:51 +02:00
game.png Move ninja shield to other position (fixes #5047) 2022-04-30 11:42:26 +02:00
gui_buttons.png Optimize PNGs 2016-04-27 01:27:57 +02:00
gui_cursor.png 0.7 cursor 2020-09-15 16:18:12 +02:00
gui_icons.png Revert "Dilate & optimize non-dilated images" 2021-02-03 20:40:10 +01:00
gui_logo.png Revert "Dilate & optimize non-dilated images" 2021-02-03 20:40:10 +01:00
hud.png new lock indic. partially closes ddnet#8467 2024-07-09 17:32:06 +02:00
particles.png Revert "Dilate & optimize non-dilated images" 2021-02-03 20:40:10 +01:00
race_flag.png Add finish info messages. 2023-11-26 17:29:40 +01:00
strong_weak.png change name file 2021-08-14 18:40:58 +05:00
touch_controls.json Add ingame touch controls 2024-09-08 11:08:23 +02:00
wordlist.txt Generate passphrase for save-code 2020-06-15 11:14:15 +02:00