Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial support for UTF-8 text input #8098

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft

Add initial support for UTF-8 text input #8098

wants to merge 8 commits into from

Conversation

ihhub
Copy link
Owner

@ihhub ihhub commented Dec 2, 2023

As of now only CP-1251 is being implemented (as @Branikolog was eating my brain too much). You can test changes by using your OS keyboard layout and try to type one of CP-1251 languages. For example, Player Name in the multiplayer mode.

Note: SDL interprets Ctrl + Key combination as not a text input and falls back to English keyboard.

relates to #7933, #6845 and #6207

@ihhub ihhub added improvement New feature, request or improvement ui UI/GUI related stuff logic Things related to game logic labels Dec 2, 2023
@ihhub ihhub added this to the 1.0.11 milestone Dec 2, 2023
@ihhub ihhub self-assigned this Dec 2, 2023
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

src/engine/char_encoding.h Show resolved Hide resolved
src/engine/localevent.h Outdated Show resolved Hide resolved
src/engine/localevent.h Outdated Show resolved Hide resolved
src/engine/localevent.cpp Outdated Show resolved Hide resolved
src/engine/char_encoding.cpp Show resolved Hide resolved
src/engine/char_encoding.cpp Show resolved Hide resolved
src/engine/char_encoding.h Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Clang-Tidy found issue(s) with the introduced code (1/1)

src/engine/localevent.h Outdated Show resolved Hide resolved
src/engine/localevent.h Outdated Show resolved Hide resolved
@Branikolog
Copy link
Collaborator

Hi, @ihhub !
Russian and Belarussian works well.
But when I select English as game language and try to add some symbols, while my system input language is set as Russian or Belarussian - nothing happens. In master branch I can still type, no matter what language input was chosen. We should have an opened issue for MAC users only in issues section. With this PR the issue is valid for Win too now.

@oleg-derevenetz
Copy link
Collaborator

oleg-derevenetz commented Dec 3, 2023

Hi @Branikolog

But when I select English as game language and try to add some symbols, while my system input language is set as Russian or Belarussian - nothing happens.

When you select English as game language, no Russian or Belarussian fonts exist, so when Russian or Belarussian symbols are coming from the keyboard, they are ignored.

In master branch I can still type

In master branch UTF-8 does not come from the keyboard.

@Branikolog
Copy link
Collaborator

Hello, @oleg-derevenetz .

In master branch UTF-8 does not come from the keyboard.

I'm just speaking as a common user. :)
For me personally current implementation for English is less convenient, than the one from master branch.

If the game language is set as English, it is implied, that no other languages could be used to type texts. So I expect only Latin symbols to appear. In that case I feel there's no need to select exactly English within OS to type, since no other symbols are allowed. We've already had some complains on MAC, as I mentioned above, that game forces user to switch OS input language to be able to add text.
To sum up, I suggest for "English" game language add always Latin symbols, no matter what text input was set within OS. If it's possible, for sure.
For such languages as Russian and Belarussian everything works fine for me in this PR.

@oleg-derevenetz
Copy link
Collaborator

oleg-derevenetz commented Dec 3, 2023

Hi @ihhub there are my observations:

  1. This doesn't work on Linux. No "key press" events are generated for non-English languages, thus, if ( le.KeyPress() ) { checks doesn't work;
  2. On Android, when SDL_StartTextInput() is called, the Android native virtual keyboard appears on the screen. But you still cannot enter characters using this virtual keyboard (even English ones!) because "key press" events are not generated either.

@ihhub
Copy link
Owner Author

ihhub commented Dec 3, 2023

Hi @oleg-derevenetz , thanks for the notes! I will try to test on Android and on Linux. Most likely these OSes behave differently from Windows.

@oleg-derevenetz
Copy link
Collaborator

@Branikolog

To sum up, I suggest for "English" game language add always Latin symbols, no matter what text input was set within OS. If it's possible, for sure.

Please see my notes above. If no key information comes for non-English symbols (only their UTF-8 symbol codes) there is no way to match these UTF-8 symbols to corresponding English symbols on the same keyboard keys (i.e. й->q, ц->w) unless you have an information about keyboard layout, and the ways to obtain this information are highly system-dependent (and maybe even flavor-dependent in case of Linux, because some flavors use X Window and some use Wayland), therefore, it's hardly worth it.

@oleg-derevenetz
Copy link
Collaborator

Hi @ihhub

I will try to test on Android and on Linux. Most likely these OSes behave differently from Windows.

Also please note that, although I couldn't verify it, there will be issues with national symbols in file names on Linux. Although Linux filesystems (such as EXT3) are encoding-agnostic (i.e. they treat file names just as an array of bytes), particular apps (e.g. shell) will treat file names according to their locale settings (set via LC_* environment variables) and most likely they won't understand CP1251 file names, because most likely their locales are set to UTF-8.

@ihhub
Copy link
Owner Author

ihhub commented Dec 3, 2023

Hi @oleg-derevenetz , I believe we shouldn't allow to enter non-English names for files at the moment.

@Branikolog
Copy link
Collaborator

@oleg-derevenetz and @ihhub

@Branikolog

Please see my notes above. If no key information comes for non-English symbols (only their UTF-8 symbol codes) there is no way to match these UTF-8 symbols to corresponding English symbols on the same keyboard keys (i.e. й->q, ц->w) unless you have an information about keyboard layout, and the ways to obtain this information are highly system-dependent (and maybe even flavor-dependent in case of Linux, because some flavors use X Window and some use Wayland), therefore, it's hardly worth it.

I actually don't know how exactly things happen in the code regarding to symbol codes.
I just express my opinion as a potential user of fheroes2 engine.
If things I was talking above are not possible to implement by creating a proper logic or using a combination of new code for non-English languages selected and the old code related to text input for English game language only, then I can approve this PR, as It brings more benefits, than losses. 💯
But I believe, there could be complains from Windows users on forcing them to switch OS language input, same as I've already had from MAC users.

@oleg-derevenetz
Copy link
Collaborator

But I believe, there could be complains from Windows users on forcing them to switch OS language input, same as I've already had from MAC users.

Complaints like "I just told my OS that I want to enter non-English letters, but your program should magically turn these non-English letters into English letters" seem absurd to me. It's not worth the effort. If someone wants this behavior, they can implement it themselves and offer a pull request. Good luck to them with the support of the entire zoo of devices and OS for this.

@Districh-ru
Copy link
Collaborator

Hi, @ihhub. The CP1251 letters works good for me (Win10), but I cannot input some symbols:
изображение

@ihhub
Copy link
Owner Author

ihhub commented Dec 4, 2023

Hi @Branikolog , what was before doesn't mean it was correct. We will see what we could do about this.

@Districh-ru , most likely it is because out CP-1251 font does not contain all symbols.

@ihhub ihhub marked this pull request as draft December 4, 2023 08:17
@ihhub ihhub modified the milestones: 1.0.11, 1.1.0 Dec 23, 2023
ihhub added a commit that referenced this pull request Dec 24, 2023
relates to #8098

If a user has active CAPS LOCK and uses SHIFT while typing, the letters must be non-capital.
Copy link

sonarcloud bot commented Dec 24, 2023

Quality Gate Failed Quality Gate failed

Failed conditions

1 New Major Issues (required ≤ 0)
1 New Critical Issues (required ≤ 0)

See analysis details on SonarCloud

idea Catch issues before they fail your Quality Gate with our IDE extension SonarLint SonarLint

@ihhub ihhub modified the milestones: 1.1.0, 1.1.1 May 22, 2024
@ihhub ihhub modified the milestones: 1.1.1, 1.1.2 Jul 13, 2024
@ihhub ihhub modified the milestones: 1.1.2, 1.1.3 Sep 15, 2024
@ihhub ihhub modified the milestones: 1.1.3, 1.1.4 Oct 23, 2024
@ihhub ihhub modified the milestones: 1.1.4, 1.1.5 Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement New feature, request or improvement logic Things related to game logic ui UI/GUI related stuff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants