Polish letters in AGS

Started by Jack Orlando, Sun 25/02/2018 17:37:17

Previous topic - Next topic

Jack Orlando

Hello!
I am currently trying to create my first game in AGS and I stumbled on a problem.
Polish language has "strange" letters, like Š›, Ã,,‡, Š‚, Šº, and Š¼.  When I use them in dialogue they are replaced by "?" signs.
Is there some way to add polish letters to AGS?

Crimson Wizard

#1
First of all, AGS is a strictly ANSI program (non Unicode) and requires ANSI-compliant fonts. You need to use font which corresponds to Polish ANSI codepage.
I am not an expert there, but from the quick searching it may be ANSI-1250.
You would need to find or create a font (i.e. use some font editor to copy letters to proper indexes) that corresponds to it.

You may also find some information about AGS font support in this article: http://www.adventuregamestudio.co.uk/wiki/Fonts

Jack Orlando

Thank you for a quick reply!
Problem resolved!

Whyshchuck

Hello,

I would like to extend issue a little.
I'm also writing the game in Polish and managed to draw new characters using font editor and then type type them using ASCII codes.
Problem starts as I want to add textbox to my game.
If player is asked to enter his name, and wants to write "Šukasz", he will just type ALT+L... ukasz. But ALT+L refers to character further than 256 (it will be displayed and saved in string as "^ukasz").
How to make Textbox which will edit input in real time and replace one character with another?

Thanks!


Snarky

Until recently I'd say it couldn't be done, but you might be in luck: You could probably use the TextField module I just published, and hack the HandleKeyPress function with some special-case logic for the key-combinations you're interested in. However, it might behave unpredictably on other keyboard layouts or language locales.

Whyshchuck

Thanks for your response, Snarky.

Your module looks extremely useful. I will experiment with it a bit next days, and will try to give you some feedback.

Whyshchuck

Snarky, I've experimented a bit with your script.
While 1.1.0 was crashing, 1.2.0 is working but I still can't manage to find the way to exchange keycode.

I've tried something like this:
      if (keycode == eKeyL && IsKeyPressed(372) == true)
and this:
      if (keycode == 77 && IsKeyPressed(372) == true)
but as I understand, AGS doesn't see pressed L, while ALT pressed, because it see them together as producing different keycode (I don't know how to check what exactly).
Maybe you have any idea how I can solve this problem. Maybe there is some way to check, what keycode is hidden behind Alt+particular characters.

Thanks!

Crimson Wizard

Quote from: Whyshchuck on Sat 14/04/2018 13:56:18Maybe there is some way to check, what keycode is hidden behind Alt+particular characters.

In theory you could simply Display them:   Display("keycode: %d", keycode).
Alternatively, you may even write the keycodes to the text file (using File API in AGS), then press all letters you are curious about in a row.
But idk how useful or convenient this approach (and its results) may be.

Snarky

There are a couple of ways to do this. The easiest is to just check the Alt+L key combination directly. To figure out the keycode, you could simply add a Display() call to the top of the function:

Code: ags
Display("The keycode pressed is %d",keycode);


However, if you look here, you can find the relevant values:

Code: ags
#define ALT_OFFSET (-236)
#define ALT_RANGE_START 301
#define ALT_RANGE_END 326


This means that keycodes between 301 and 326 are ALT+letter combinations, and you get the keycode value of the letter itself by subtracting 236. Since L is 76, Alt+L=76+236=312.

If you need more button combinations than just Alt+L, you should probably use something like the IsKeyPressedCombi() function in that code to handle them together.

Whyshchuck

I think that it may be fault of windows setup, but Display shows keycode 94 for all letters out of the 256 char table: Š‚, Š, Š›, Ã,,‡, Å Å¡, Ã,,† etc...
I've tried to switch keyboard to english, but it's even worse: AGS doesn't see ALT pressed and shows Š‚ as 76, Š› as 86, so as l and s

Snarky, I will try to force it with your functions. Thanks

Snarky

I don't see how that would give a different result, but sure, try it.

Meanwhile I've edited the thread title because I find it annoying to see the title claiming the issue is solved when it's not.

Crimson Wizard

Quote from: Snarky on Sat 14/04/2018 17:43:12
Meanwhile I've edited the thread title because I find it annoying to see the title claiming the issue is solved when it's not.

Original thread was about displaying letters, which was solved.

User input is a separate thing here, since there is no guarantee that AGS does it correctly. It may for instance switch any keycode that it does not support to some smaller value. I recall seeing some weird stuff in keycode handling code.

Imho one alternative that might be tried here is to script custom key input handling, not relying on key_press function and keycodes it receives, but checking IsKeyPressed in repeatedly_execute.

Whyshchuck

Quote from: Crimson Wizard on Sat 14/04/2018 18:13:01
Imho one alternative that might be tried here is to script custom key input handling, not relying on key_press function and keycodes it receives, but checking IsKeyPressed in repeatedly_execute.

That was great suggestion. I've managed to mix Snarky's script with kecode rules and additional iskeypressed conditions and it works, while
- it can be simplified, as I created separate condition for lower-case and upper-case of every letter
- 211 is Š, 243 is Š‚, 212 is Ã,,† and 244 is Ã,,‡
- it needs multiplication for other diacritic signs
Code: ags

      if (keycode == 94)
      {
        if ((IsKeyPressed(eKeyL)) && (IsKeyPressed (404)))
        {

          _textFieldTexts[id] = _textFieldTexts[id].InsertChar(211, this._caretIndex);
          this._caretIndex++;
          this.UpdateDisplay();
        }
        
        else if (IsKeyPressed(eKeyL))
        {
          _textFieldTexts[id] = _textFieldTexts[id].InsertChar(243, this._caretIndex);
          this._caretIndex++;
          this.UpdateDisplay();
        }
        if ((IsKeyPressed(eKeyC)) && (IsKeyPressed (404)))
        {
          _textFieldTexts[id] = _textFieldTexts[id].InsertChar(212, this._caretIndex);
          this._caretIndex++;
        this.UpdateDisplay();
        }
        else if (IsKeyPressed(eKeyC))
        {

          _textFieldTexts[id] = _textFieldTexts[id].InsertChar(244, this._caretIndex);
          this._caretIndex++;
        this.UpdateDisplay();
        }
}

SMF spam blocked by CleanTalk