forked from ddnet/ddnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 buttons are only shown when they are usable depending on the context. 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 player. 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 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. 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 HUD, showing the spectator HUD, opening team and team chat, voting yes/no, and zooming. Once the dummy is connected, a button for swapping between main and dummy is shown. Long pressing the hamburger menu button will open the regular menu. The emoticon and spectator HUDs 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 HUD. 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: 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, instead of buttons appearing outside the screen or not being aligned with the right side. - Shape: rectangle or circle. - Visibility: an array of predefined visibility classes can be selected and the button is only shown if all conditions are met. An empty array means that the button is always shown. - Behavior: either predefined (hard-coded) behavior identified by an ID, or generic console commands (binds). Predefined behavior is only used where necessary, all other buttons are represented as generic binds. 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: - Checkbox for toggling the virtual joystick (temporary until controls can be adjusted more generically). - Checkbox for toggling entities. - Buttons to open the local and remote consoles. - Button to close the menu (more convenient than using the back button if it's not always shown). Currently missing: - UI for adjusting the button layout. - Various decisions and code cleanup TODOs in `CTouchControls`.
- Loading branch information
Showing
21 changed files
with
1,858 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,292 @@ | ||
{ | ||
"direct-touch-ingame": true, | ||
"direct-touch-spectate": true, | ||
"touch-buttons": [ | ||
{ | ||
"x": 0, | ||
"y": 833333, | ||
"w": 200000, | ||
"h": 166667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"ingame" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Left", | ||
"command": "+left" | ||
} | ||
}, | ||
{ | ||
"x": 200000, | ||
"y": 833333, | ||
"w": 200000, | ||
"h": 166667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"ingame" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Right", | ||
"command": "+right" | ||
} | ||
}, | ||
{ | ||
"x": 100000, | ||
"y": 666667, | ||
"w": 200000, | ||
"h": 166667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"ingame" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Jump", | ||
"command": "+jump" | ||
} | ||
}, | ||
{ | ||
"x": 116667, | ||
"y": 16667, | ||
"w": 83333, | ||
"h": 83333, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"ingame" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "← Weapon", | ||
"command": "+prevweapon" | ||
} | ||
}, | ||
{ | ||
"x": 200000, | ||
"y": 16667, | ||
"w": 83333, | ||
"h": 83333, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"ingame" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Weapon →", | ||
"command": "+nextweapon" | ||
} | ||
}, | ||
{ | ||
"x": 16667, | ||
"y": 16667, | ||
"w": 83333, | ||
"h": 83333, | ||
"shape": "rect", | ||
"visibilities": [ | ||
], | ||
"behavior": { | ||
"type": "predefined", | ||
"id": "extra-menu" | ||
} | ||
}, | ||
{ | ||
"x": 300000, | ||
"y": 16667, | ||
"w": 83333, | ||
"h": 83333, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"extra-menu", | ||
"zoom-allowed" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Zoom out", | ||
"command": "zoom-" | ||
} | ||
}, | ||
{ | ||
"x": 383333, | ||
"y": 16667, | ||
"w": 83333, | ||
"h": 83333, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"extra-menu", | ||
"zoom-allowed" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Default zoom", | ||
"command": "zoom" | ||
} | ||
}, | ||
{ | ||
"x": 466667, | ||
"y": 16667, | ||
"w": 83333, | ||
"h": 83333, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"extra-menu", | ||
"zoom-allowed" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Zoom in", | ||
"command": "zoom+" | ||
} | ||
}, | ||
{ | ||
"x": 16667, | ||
"y": 133333, | ||
"w": 83333, | ||
"h": 66667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"extra-menu" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Scoreboard", | ||
"command": "+scoreboard" | ||
} | ||
}, | ||
{ | ||
"x": 116667, | ||
"y": 133333, | ||
"w": 83333, | ||
"h": 66667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"ingame", | ||
"extra-menu" | ||
], | ||
"behavior": { | ||
"type": "predefined", | ||
"id": "emoticon" | ||
} | ||
}, | ||
{ | ||
"x": 116667, | ||
"y": 133333, | ||
"w": 83333, | ||
"h": 66667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"spectate", | ||
"extra-menu" | ||
], | ||
"behavior": { | ||
"type": "predefined", | ||
"id": "spectate" | ||
} | ||
}, | ||
{ | ||
"x": 216667, | ||
"y": 133333, | ||
"w": 83333, | ||
"h": 66667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"extra-menu" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Chat", | ||
"command": "chat all" | ||
} | ||
}, | ||
{ | ||
"x": 316667, | ||
"y": 133333, | ||
"w": 83333, | ||
"h": 66667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"extra-menu" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Chat team", | ||
"command": "chat team" | ||
} | ||
}, | ||
{ | ||
"x": 16667, | ||
"y": 333333, | ||
"w": 83333, | ||
"h": 66667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"extra-menu", | ||
"vote-active" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Vote yes", | ||
"command": "vote yes" | ||
} | ||
}, | ||
{ | ||
"x": 116667, | ||
"y": 333333, | ||
"w": 83333, | ||
"h": 66667, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"extra-menu", | ||
"vote-active" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Vote no", | ||
"command": "vote no" | ||
} | ||
}, | ||
{ | ||
"x": 766667, | ||
"y": 16667, | ||
"w": 100000, | ||
"h": 100000, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"dummy-connected" | ||
], | ||
"behavior": { | ||
"type": "bind", | ||
"label": "Toggle dummy", | ||
"command": "toggle cl_dummy 0 1" | ||
} | ||
}, | ||
{ | ||
"x": 883333, | ||
"y": 16667, | ||
"w": 100000, | ||
"h": 100000, | ||
"shape": "rect", | ||
"visibilities": [ | ||
"ingame" | ||
], | ||
"behavior": { | ||
"type": "predefined", | ||
"id": "swap-action" | ||
} | ||
}, | ||
{ | ||
"x": 750000, | ||
"y": 583333, | ||
"w": 233333, | ||
"h": 400000, | ||
"shape": "circle", | ||
"visibilities": [ | ||
"joystick" | ||
], | ||
"behavior": { | ||
"type": "predefined", | ||
"id": "joystick-action" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.