Here is how I would do the script:
I used center horizontal alignment because it looked better. I had to adjust the x-coordinates to compensate, see my comments.
I went the route of manual line breaks using \n. The disadvantage is you have to ensure none of your lines of text exceed 22 characters or it will get clipped. But it also gives you more control of choosing where the line break occurs. With the other method you might get a first line that is really long and a second line that is only one short word.
Here are your string.dat strings with the \n breaks added:
text{ key = "0", value = "Find the chart salesman\nin Ballast Harbor" }
text{ key = "a1", value = "Get some whisky from\nthe secret stash" }
text{ key = "a2", value = "Meet Juglan\nat the pier" }
text{ key = "a3", value = "Investigate the Sodden\nCormorant Tavern" }
text{ key = "a4", value = "Explore Spruce Head" }
text{ key = "a5", value = "Investigate Briarwood\nDistillery" }
text{ key = "a6", value = "Find a keyhole\non Kingsdown Isle" }
text{ key = "a7", value = "Find clues in\nHourglass Fort" }
text{ key = "b1", value = "Find the chart salesman\nin Ballast Harbor" }
text{ key = "b2", value = "Return the\nstolen charts" }
text{ key = "b3", value = "Find a keyhole\nfor Mallow's Key" }
Also note that you can use the following notation in string.dat if you prefer. It might make it easier to tell if you've exceeded 22 characters on a given line. With this style, the line break is an actual line break rather than \n.
For splitting the strings into lines I borrowed the line iterator from the ATTP dialog box script. Look up iterators if you are having trouble following how it works.
Code (lua) Select
pause_infra = {}
local current_log = sol.surface.create(138,72) --22 characters across, 4+ lines tall
local text_surface = sol.text_surface.create({
vertical_alignment = "top",
horizontal_alignment = "center",
font = "oceansfont",
})
--note that a size is not specified for a text surface, it will be as big as the text it contains
--Returns iterator to split text at line breaks
local function line_it(text)
assert(type(text)=="string", "Bad argument #1 to 'line_it' (string expected, got "..type(text)..")")
text = text:gsub("\r\n", "\n"):gsub("\r", "\n").."\n" --convert instances of \r to \n and add line break to end
return text:gmatch("([^\n]*)\n") -- Each line including empty ones.
end
function pause_infra:update_game(game)
current_log:clear() --erase any previous content on surface
local log_a_text = game:get_value("quest_log_a") --the string saved to the game value "quest_log_a" should match a key in strings.dat
local next_line = line_it(sol.language.get_string(log_a_text)) --gets localized string in current language
text_surface:set_text(next_line()) --line 1 of quest_log_a
text_surface:draw(current_log, 69, 0) --renders first line of quest_log_a text and draws on current_log surface
--x value 69 because horizontal alignment is center (138/2 = 69)
text_surface:set_text(next_line()) --line 2 of quest_log_a
text_surface:draw(current_log, 69, 16)
--NOTE: if quest_log_a contains more than 2 lines of text then the extra lines do not get drawn
local log_b_text = game:get_value("quest_log_b")
next_line = line_it(sol.language.get_string(log_b_text))
text_surface:set_text(next_line()) --line 1 of quest_log_b
text_surface:draw(current_log, 69, 39)
text_surface:set_text(next_line()) --line 2 of quest_log_b
text_surface:draw(current_log, 69, 55)
--Now current_log contains and image rendered from text strings of log A & log B (up to 4 lines)
--content won't change while pause menu open
end
local pause_img = sol.surface.create("hud/pause_infra.png")
function pause_infra:on_draw(dst_surface)
--draw menu architecture
pause_img:draw(dst_surface)
--draw quest log
current_log:draw(dst_surface, 167, 27) --specify coordinates for where you want to draw it on the screen
end
I used center horizontal alignment because it looked better. I had to adjust the x-coordinates to compensate, see my comments.
I went the route of manual line breaks using \n. The disadvantage is you have to ensure none of your lines of text exceed 22 characters or it will get clipped. But it also gives you more control of choosing where the line break occurs. With the other method you might get a first line that is really long and a second line that is only one short word.
Here are your string.dat strings with the \n breaks added:
text{ key = "0", value = "Find the chart salesman\nin Ballast Harbor" }
text{ key = "a1", value = "Get some whisky from\nthe secret stash" }
text{ key = "a2", value = "Meet Juglan\nat the pier" }
text{ key = "a3", value = "Investigate the Sodden\nCormorant Tavern" }
text{ key = "a4", value = "Explore Spruce Head" }
text{ key = "a5", value = "Investigate Briarwood\nDistillery" }
text{ key = "a6", value = "Find a keyhole\non Kingsdown Isle" }
text{ key = "a7", value = "Find clues in\nHourglass Fort" }
text{ key = "b1", value = "Find the chart salesman\nin Ballast Harbor" }
text{ key = "b2", value = "Return the\nstolen charts" }
text{ key = "b3", value = "Find a keyhole\nfor Mallow's Key" }
Also note that you can use the following notation in string.dat if you prefer. It might make it easier to tell if you've exceeded 22 characters on a given line. With this style, the line break is an actual line break rather than \n.
Code (lua) Select
text{ key = "0", value = [[
Find the chart salesman
in Ballast Harbor
]]}
For splitting the strings into lines I borrowed the line iterator from the ATTP dialog box script. Look up iterators if you are having trouble following how it works.