mirror of
https://github.com/bryanthaboi/gen1recomp
synced 2026-09-26 21:35:42 -04:00
CLOSES #1562, CLOSES #1804, CLOSES #1805, CLOSES #1810, CLOSES #1811, CLOSES #1814, CLOSES #1817, CLOSES #1818, CLOSES #1819, CLOSES #1821, CLOSES #1826, CLOSES #1827, CLOSES #1829, CLOSES #1833, CLOSES #1840, CLOSES #1842, CLOSES #1845, CLOSES #1846, CLOSES #1847, CLOSES #1848, CLOSES #1849, CLOSES #1853, CLOSES #1858, CLOSES #1862
This commit is contained in:
@@ -28,6 +28,52 @@ local MAX_COLS = 18
|
||||
-- pokegold constants/ram_constants.asm: TEXT_DELAY_FAST/MED/SLOW = 1/3/5
|
||||
local NAME_DELAYS = { FAST = 1, MID = 3, SLOW = 5 }
|
||||
|
||||
-- TextCommand_PAUSE (home/text.asm:492-504): a mid-string wait callers
|
||||
-- embed as TextBox.PAUSE, stripped here and re-anchored after pagination.
|
||||
TextBox.PAUSE = "\1"
|
||||
local PAUSE_FRAMES = 30
|
||||
|
||||
local function glyphs(str)
|
||||
return #Font.split((str:gsub("[\n\v\f]", "")))
|
||||
end
|
||||
|
||||
local function stripPauses(text)
|
||||
if not text:find(TextBox.PAUSE, 1, true) then return text, nil end
|
||||
local out, marks, count, pos = {}, {}, 0, 1
|
||||
while true do
|
||||
local i = text:find(TextBox.PAUSE, pos, true)
|
||||
if not i then
|
||||
out[#out + 1] = text:sub(pos)
|
||||
break
|
||||
end
|
||||
local chunk = text:sub(pos, i - 1)
|
||||
out[#out + 1] = chunk
|
||||
count = count + glyphs(chunk)
|
||||
marks[#marks + 1] = count
|
||||
pos = i + 1
|
||||
end
|
||||
return table.concat(out), marks
|
||||
end
|
||||
|
||||
-- glyph offsets into the whole text -> [page][line][char]
|
||||
local function mapPauses(pages, marks)
|
||||
local at, acc, mi = {}, 0, 1
|
||||
for pi, page in ipairs(pages) do
|
||||
for li, line in ipairs(page) do
|
||||
local n = #Font.split(line)
|
||||
while mi <= #marks and marks[mi] <= acc + n do
|
||||
local ci = marks[mi] - acc
|
||||
at[pi] = at[pi] or {}
|
||||
at[pi][li] = at[pi][li] or {}
|
||||
at[pi][li][ci] = mi
|
||||
mi = mi + 1
|
||||
end
|
||||
acc = acc + n
|
||||
end
|
||||
end
|
||||
return at
|
||||
end
|
||||
|
||||
-- opts.choice: when the last page has typed out, a YES/NO ChoiceBox pops
|
||||
-- up over the still-visible text (YesNoChoicePokeCenter and friends);
|
||||
-- the box then closes and choice(yes) runs instead of onDone.
|
||||
@@ -81,7 +127,13 @@ function TextBox.new(game, text, onDone, opts)
|
||||
self.line1Y = (self.boxTy + 2) * 8
|
||||
self.line2Y = (self.boxTy + 4) * 8
|
||||
text = TextBox.substitute(game, text)
|
||||
local marks
|
||||
text, marks = stripPauses(text)
|
||||
self.pages = TextBox.paginate(text, self.maxCols)
|
||||
-- opts.pauseSounds[i] is the sfx the i-th marker fires once its wait is
|
||||
-- over (text_asm SFX_SWAP, engine/pokemon/learn_move.asm:210-213)
|
||||
self.pauseSounds = opts and opts.pauseSounds
|
||||
self.pauseAt = marks and mapPauses(self.pages, marks) or nil
|
||||
self.pageIndex = 1
|
||||
self.lineIndex = 1
|
||||
self.charIndex = 0
|
||||
@@ -297,6 +349,20 @@ function TextBox:update(dt)
|
||||
self.holdFrames = self.holdFrames - 1
|
||||
return
|
||||
end
|
||||
-- home/text.asm:492
|
||||
if self.pauseFrames then
|
||||
if self.pauseFrames > 0 then
|
||||
self.pauseFrames = self.pauseFrames - 1
|
||||
return
|
||||
end
|
||||
self.pauseFrames = nil
|
||||
local snd = self.pauseSounds and self.pauseSounds[self.pauseMark]
|
||||
if type(snd) == "function" then
|
||||
snd()
|
||||
elseif snd then
|
||||
require("src.core.Sound").play(self.game.data, snd)
|
||||
end
|
||||
end
|
||||
if self.done then
|
||||
-- opts.stay: the box is finished but stays up under whatever the caller
|
||||
-- pushed over it; StateStack updates the top state only, so this runs
|
||||
@@ -430,6 +496,15 @@ function TextBox:update(dt)
|
||||
self.charIndex = self.charIndex + 1
|
||||
local line = self.shown[#self.shown]
|
||||
line[#line + 1] = self.codes[self.charIndex]
|
||||
local marks = self.pauseAt and self.pauseAt[self.pageIndex]
|
||||
marks = marks and marks[self.lineIndex]
|
||||
if marks and marks[self.charIndex] then
|
||||
self.pauseMark = marks[self.charIndex]
|
||||
-- TextCommand_PAUSE reads hJoyHeld, so a held A/B skips the wait
|
||||
self.pauseFrames = (input:isDown("a") or input:isDown("b"))
|
||||
and 0 or PAUSE_FRAMES
|
||||
break
|
||||
end
|
||||
else
|
||||
-- line finished
|
||||
local page = self.pages[self.pageIndex]
|
||||
|
||||
Reference in New Issue
Block a user