lantus / devilution-nx

Diablo for the Nintendo Switch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keyboard for entering name

erfg12 opened this issue · comments

A keyboard is needed for entering a name and creating a multiplayer game.

Since we are already using SDL_TEXTINPUT we might just need to setup SDL_SetTextInputRect and give it focuse. At least that is what I expect for the other platforms that use a virtual keyboard.

SDL_TEXTINPUT is not implemented in the SDL2 port on Switch so nothing will happen there.

Luckily the Horizon OS virtual keyboard is quite easy to use on switch.

Simplest thing I used before (Julius Switch port) is to just map the virtual keyboard to "plus" key. If the user pushes the plus key, the virtual keyboard comes up. After pressing done on the virtual keyboard, SDL keydown and SDL keyup events are pushed into the SDL event queue to simulate the keyboard input corresponding to the string the user entered into the virtual keyboard.

I usually push a few hundred backspace and delete keypress events into the queue before pushing the actual characters from the software keyboard into the queue. This is to erase whatever was present in whatever textbox might have been active when the keyboard was summoned. It is a bit hacky but usually works.

Example "start text input" code from Julius (called whenever plus key is pressed down):
https://github.com/bvschaik/julius/blob/7ecc21b570abba068db788a446bc1dc03e5d5695/src/platform/switch/switch_input.c#L342

And here is the "push key event" function used by above:
https://github.com/bvschaik/julius/blob/7ecc21b570abba068db788a446bc1dc03e5d5695/src/platform/switch/switch_input.c#L468

Plus the code here to summon the keyboard and receive a string from it: https://github.com/bvschaik/julius/blob/7ecc21b570abba068db788a446bc1dc03e5d5695/src/platform/switch/switch_keyboard.c .

Another option: instead of mapping the plus key to bring up the virtual keyboard, one could bring it up on every SDL_TEXTINPUT event (or SDL_StartTextInput or whatever the function is called), but even then I would proceed the same way as above (pushing SDL_key events).

I just implemented this via Pull Request #17