Author Topic: Zelda: Book of Mudora  (Read 22191 times)

Diarandor

  • Hero Member
  • *****
  • Posts: 700
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda: Book of Mudora
« Reply #135 on: April 11, 2017, 10:55:51 pm »
First we need to fix the spacing issue that occurs when giving the text a different color in the textbox script

I agree, but I have no idea of how that could be fixed now.
(Probably the new functions "drawable:get_pixels()" of Solarus 1.6 will allow us to find a solution to get the correct number of spaces needed. But until then, no idea.)

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1008
    • View Profile
Re: Zelda: Book of Mudora
« Reply #136 on: April 11, 2017, 10:59:09 pm »
Can you tell me again what was wrong and why detecting two-byte characters did not work?

wrightmat

  • Full Member
  • ***
  • Posts: 218
    • View Profile
Re: Zelda: Book of Mudora
« Reply #137 on: April 12, 2017, 03:13:01 am »
I switched to a monospace font with the new version. I haven't encountered any more spacing issues with the English version.

Diarandor

  • Hero Member
  • *****
  • Posts: 700
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda: Book of Mudora
« Reply #138 on: April 12, 2017, 04:28:47 am »
-Link of the issue in github:
https://github.com/MetalES/Project-Zelda/issues/46

(Note that I have not worked directly on the code to solve this problem.)

Summary of what we already know: our current scripts only work correctly for monospaced fonts with no multi-byte characters (accents and other characters, like Japanese characters, are giving problems since their lenght is not gotten correctly with Lua functions like "string:lenght()", etc).

-Christopho suggested to use "text_surface:get_size()". I didn't understand what he meant at that moment, but now I think I understand what he meant, and his idea is probably the solution that may solve this problem. Of course, part of the code has to be rewritten in a different manner. At first I thought that the size of a text surface was something fixed, like a bounding box, but that's not true, since the API says: "The size is determined by the text and the font".

I think we have two possibilities:

1) One solution should be to get the position and size of the last text surface to obtain the position of the new text surface to be created (when we make a color change).

2) Another solution is to get the size of the text surface and use it to compute the number of spaces that we need to add in the other overlapping surfaces.

Remark: The second solution may be slightly simpler, maybe, but for that one we need to know before the size of a space character, which may depend on the font and size. An easy way to get this is to compute it once (maybe when the script is started), which can be done in this way: create a text surface, write a space, get the size, and then destroy the surface.

@MetalZelda: if you have time these days, could you try some of these two solutions to test if this solves the problem?

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1008
    • View Profile
Re: Zelda: Book of Mudora
« Reply #139 on: April 12, 2017, 09:02:12 am »
3) Just use a monospaced font and detect characters that use two bytes.

llamazing

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
Re: Zelda: Book of Mudora
« Reply #140 on: April 12, 2017, 02:19:33 pm »
In my Cythera project I was able to colorize words that the player can click on to advance the dialog with no problems, and I was using a ttf font that was not monospaced. My dialog script is pretty complicated, but it probably wouldn't be too hard to extract just the part where I colorized the text.

My method was to write all the text to text surfaces, one text surface per line of text. I kept track of the starting and ending position of each word to colorize using text_surface:get_text(), querying it as I added each word to the text_surface. Then I had one regular surface to draw the text on, and moving left to right for each text_surface I redrew the text_surface onto the surface up until the point where the color changed, then changed the color of the text_surface and redrew the next text onto the main surface until the next color change, etc.

Diarandor

  • Hero Member
  • *****
  • Posts: 700
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda: Book of Mudora
« Reply #141 on: April 12, 2017, 04:59:21 pm »
I think llamazing's solution is solution "1)". It has the advantage of working with non-monospaced fonts.

Diarandor

  • Hero Member
  • *****
  • Posts: 700
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda: Book of Mudora
« Reply #142 on: April 12, 2017, 05:58:34 pm »
We should probably make a new version of the script using that technic (which works with any type of font and size, including non-monospaced fonts), and make it "official".

Another question is: should we use the same syntax as the "official" one to change colors or maybe use a different one? The syntax I used was ${surface_name} to change surface, and $[color_name] or $[(r, g, b)] to change color of the current surface; the initial surface has "default" as name. We could use instead a syntax more similar to LaTeX if you prefer, with another $ at the end of each command, etc.

This is probably a bad place of the forum to discuss about this.

wrightmat

  • Full Member
  • ***
  • Posts: 218
    • View Profile
Re: Zelda: Book of Mudora
« Reply #143 on: April 13, 2017, 02:54:56 pm »
Haha, yeah, we could start a new topic to discuss in more depth. I stuck with the $[color_name] syntax and defined any of the colors I used in the scripts. I preferred this method because then all of my colors and tags were consistent and I didn't have to remember RGB values. Adding another $ just seems unnecessary to me, and it's more to parse out in the script.

Diarandor

  • Hero Member
  • *****
  • Posts: 700
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Zelda: Book of Mudora
« Reply #144 on: April 13, 2017, 05:47:23 pm »
Maybe we can continue in this old topic where this discussion began:
http://forum.solarus-games.org/index.php/topic,312.msg1201.html#msg1201