Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #1538
This is a recreation of #2440.
Added following API to the script:
The Touch.TouchPointers[] indexed property has an underlying list that only grows during a game session, but never shrinks or resets. It cannot be preallocated, because the backend does not always have ability to tell how many pointers / fingers are supported by the connected touch devices. That is why it starts at zero size, and keep growing as more simultaneous touches are detected.
TouchPointer struct describes a single "touch move" by a Nth pointing device, whatever that might be (a finger, or a mouse in case of mouse to touch emulation, etc). It's ID matches the index of TouchPointers[]. IsDown tells whether this pointer is currently down (touches the sensor device), and where at. More properties could be added later if necessary.
Normally user should iterate over TouchPointers array, looking for the states of all recorded TouchPointers, and maybe remember their states and compare with the last saved state to see how they are changed.
Because multiple touch events may occur within a single game frame, there are 3 new script callbacks supported, that let to react to them with more precision:
where "int pointer" argument is the TouchPointer index, and x,y is the new/last position of a pointer.
Other additions: added
eInputTouch
to InputType enum for consistency.NOTES on implementation.
I had to create duplicate "touch" events recorded as SDL_UserEvent in our input queue. Primary reason is that input queue is processed with a delay, and our internal "pointer id" cannot be reliably calculated anymore after the finger is unpressed. So it has to be recorded along with the event in queue. This user event stores AGS_TouchPointerEventData with pointer id, and a position already in absolute window coordinates (SDL finger events have it in [0,1] relative coordinates).
At the time touch events do not affect anything in game state, rather than calling script callbacks. I.e. they do not skip display boxes, cutscenes etc. But this may be implemented later.
(At least display boxes skip must be implemented, I suppose, as no script is run when they are shown, so user cannot script their removal with a touch.)
TODO
Besides few things mentioned above, I think we may benefit from a config setting that enables mouse-to-touch emulation, so that one could test at least 1 finger touch without having a touch device.