Trying to fit more text into a text parser.

Started by Perpetuall, Wed 03/07/2024 08:20:45

Previous topic - Next topic

Perpetuall

Hello,
I am working on an RPG where you have to exorcise or summon demons using a memorized scripture or incantation.
I am using the Text Parser template as the base for my game. The idea being that the player has to type in the required verses to make the character say them, which causes damage to the demon.
The problem I am having is; the text parser is only one line long, and the verses are often much longer than what will fit in the box.
I redesigned the parser GUI to be much bigger, and adjusted the font size, and changed the resolution of my game, but there still isn't enough space in the box for some of the longer verses to fit, unless I shrink the font way too small to read comfortably.
And as I understand it, there's no way to make a line break in the parser without submitting the entry. There was a LineBreak module, but the link is broken.
Is there a way around this, or do I just have to work with what I have?

I would prefer there to be a way to type out a full paragraph, instead of a single line. If it were possible, it would be nice to be able to type out the verse and have the character say it as it's being typed... but I'm just thinking of ways to make the text fit. I wonder if there was a way to make the font shrink as I type more? So it is legible unless I start running out of room?
Anyway, I am sure I will have more questions as I go. I am a newbie at this.  :-D
Your input is much appreciated.

EDIT: I think I solved the problem, by painstakingly downloading free fonts until I found one that would fit into the text parser better without losing legibility. However, I would still like to hear any suggestions anyone may have about how they'd go about implementing this general idea. Thanks

Khris

That template is very old and I'm not sure how much use it'll be.

Typing a paragraph of text is possible but requires some programming. It's easier if the user cannot move the cursor i.e. just backspace typos.
Adjusting the font size is also possible if you draw the text to a dynamic sprite but requires importing a font a various sizes beforehand.

GUI labels support line breaks, so you need code that listens to keypresses and appends the character to a label.
This can be handled with a flag or GUI visibility check indicating to on_key_press that the label is currently visible and any keypress should be directed there.

Like this:

Code: ags
function handleParser(eKeyCode k) {
  lblParser.Text = String.Format("%s%c", lblParser.Text, k); // not a full solution
}

function on_key_press(eKeyCode k) {

  if (gParser.Visible) {
    handleParser(k);  
    return;
  }

  // existing key handling here
}

Crimson Wizard

#2
For the proper Unicode support you must handle 2 events:
- on_key_press - for service keys
- on_text_input - for typing printable characters

Explanation is here:
https://adventuregamestudio.github.io/ags-manual/Globalfunctions_Event.html#on_text_input

Code: ags
function handleParser(eKeyCode k, int ch) {
  if (k == eKeyReturn) {
    lblParser.Text = lblParser.Text.AppendChar('\n'); // add a linebreak
  }
  else if (k == eKeyBackspace) {
    if (lblParser.Text.Length > 0) // truncate by 1 character
      lblParser.Text = lblParser.Text.Truncate(lblParser.Text.Length - 1);
  }
  else if (ch != 0) {
    lblParser.Text = lblParser.Text.AppendChar(ch); // append a printable character
  }
}

function on_key_press(eKeyCode k) {

  if (gParser.Visible) {
    handleParser(k, 0); // handle service keys
    ClaimEvent(); // prevent other scripts getting this key press
    return;
  }

}

function on_text_input(int ch) {

  if (gParser.Visible) {
    handleParser(eKeyNone, ch); // handle printable characters
    ClaimEvent(); // prevent other scripts getting this character event
    return;
  }

}


EDIT: The above script is practically how TextBox is working internally in the AGS engine.

Perpetuall

#3
Thanks for the help!

Still working out the best way to go about doing this... Gosh, I've been feeling foggy lately.  ???
But I've made a little progress.  8-) I'll let you know when I have more questions.... Much obliged

SMF spam blocked by CleanTalk