So I'm working on a system that can take a long string of essentially any length, then correctly display it in any rectangle's dimensions that you specify, as well as "animating" that text being written out.
I've got it basically working (see gif above), but there are still some weird edge-cases I'm having trouble fixing.
I also know that other people have expressed interest in having a system like this in their game, so I would like turn this into a public portable library that could be imported into essentially any project.
The issue is I am a very novice programmer, so I'd need some help making the code a little more portable and less embedded with my game code, and I also don't know much about making/maintaining a public GitHub repo.
I'll attach my current project in it's entirety which you should be able to build and run in the simulator or on device to see what I have so far. It's a Noble Engine project, so the scene structure may seem odd if you aren't familiar with that already.
I'm kind-of halfway through a C-API text box. I want to have up/down scrolling when the text is too big for the box. I also want different text justifications - left, centre & full. (I guess I'd do right-just too, for those that need it).
My desired end-goal would be a library/function that the user can give;
a string of arbitrary length
a rect that will contain the text (so proper newlines and paginating can be determined)
x,y for the top left corner of the rect
a font to use
what speed to reveal the text at
(bonus: also handle a nineslice background for the text to be drawn on)
then the function/library would handle properly formatting that input string into lines/pages, no matter how long or short, and would also handle "animating" the dialogue box to reveal one letter at a time.
the player could then "skip" the reveal animation with a button, and if it was all already revealed the button would start the next page.
Yes, (again, there are some Noble Engine features at play here, which is part of the "de-coupling" that will need done to make this more modular) but I currently have it set up so that all my entities are frozen and the Noble Input handler is changed to "DialogueInput" which doesn't allow movement or any interaction other than advancing the dialogue box.
And I didn't even realize there was a "USA" spelling for dialog, but I'm definitely not from the UK
Ok, I'm out of time. But my first thoughts are to pack all the "Text Box" stuff into it's own class/object, that will clearly separate the local text box variables from the Overworld parent object. ( I'm slow, because I have to learn the Lua syntax as I read. )
I can't see the cause of any issues yet, not familiar enough with it.
Ok, back in 8 hours or so... who knows what this day will bring.
I've been doing that @UrlOfSandwich! I started with Nick's code he shared on discord and have broken it into a few "wrap" and "paginate" steps. This was for 300, 60 rect:
local windowWidth, windowHeight = 300, 120
local text = Paginate.read("filename")
local wrapped = Paginate.wrap(text, windowWidth)
local paginated = Paginate.paginate(wrapped, Paginate.getRows(windowHeight))
Graphics.imageWithText(paginated[3], windowWidth, windowHeight):draw(2, 2)
local window = Paginate.window(wrapped, 2, Paginate.getRows(windowHeight))
Graphics.imageWithText(window, windowWidth, windowHeight):draw(2, 2)
Graphics.drawRect(2, 2, windowWidth, windowHeight)
Edit: read probably shouldn’t be in the paginate tools, for dialogue you’d call wrap and then paginate for each line so there wouldn’t be a need to read an entire file
I also can’t help but to think that Paginate isn’t the best make for this particular script. Something like Atropos would be cool if it wasn’t such a niche reference lol
window lets you set an initial index and limits the output to a single “page”. You could do the same thing manually by creating a new table with the desired lines and passing them to paginate, but I figured window would be useful if you wanted a panel of text that allows the user to scroll line by line.
I used imageWithText because it lets you “render” the text once and then draw the image instead of having to do all the text drawing every frame. Not really important for example code but that’s what I’m using in my own stuff so I used it there too
ALSO! A wishlist item would be for the dialogue to work like BotW dialogue boxes:
Hold A to speed up text, press A to start animating next line
Tap B to draw rest of text immediately, Press B to show all of next line immediately
It’s kinda subtle but I thought the difference was nice when I was skipping dialogue on my second playthrough