Skip to content

Commit

Permalink
Allow auto-forward to work with multiple.
Browse files Browse the repository at this point in the history
The changes here store the text objects that are created as part
of a multiple say statement, then pass those into SayBehavior,
which will use them to determine how long the autoforward will
pause for.

Fixes #3744.
  • Loading branch information
renpytom committed Jul 8, 2022
1 parent b1cacdd commit e0b23d1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
27 changes: 20 additions & 7 deletions renpy/character.py
Expand Up @@ -414,9 +414,9 @@ def __call__(self):
for c in self.callback:
c("slow_done", interact=self.interact, type=self.type, **self.cb_args)

# This function takes care of repeatably showing the screen as part of
# an interaction.

# This is a queue for text that's going to be passed to the say behavior to
# set the AFM info.
afm_text_queue = [ ]

def display_say(
who,
Expand All @@ -440,13 +440,21 @@ def display_say(
multiple=None,
dtt=None):

global afm_text_queue

# Final is true if this statement should perform an interaction.

if multiple is None:
final = interact

afm_text_queue = [ ]

else:
step, total = multiple

if step == 1:
afm_text_queue = [ ]

if step == total:
final = interact
else:
Expand Down Expand Up @@ -602,10 +610,15 @@ def display_say(
else:
what_text = show_function(who, what_string)

if interact or what_string or (what_ctc is not None) or (behavior and afm):
if isinstance(what_text, tuple):
what_text = renpy.display.screen.get_widget(what_text[0], what_text[1], what_text[2])

if not multiple:
afm_text_queue = [ what_text ]
else:
afm_text_queue.append(what_text)

if isinstance(what_text, tuple):
what_text = renpy.display.screen.get_widget(what_text[0], what_text[1], what_text[2])
if interact or what_string or (what_ctc is not None) or (behavior and afm):

if not isinstance(what_text, renpy.text.text.Text): # @UndefinedVariable
raise Exception("The say screen (or show_function) must return a Text object.")
Expand Down Expand Up @@ -637,7 +650,7 @@ def display_say(
raise Exception("The displayable with id 'what' was not given the exact contents of the what variable given to the say screen.")

if behavior and afm:
behavior.set_text(what_text)
behavior.set_text(*afm_text_queue)

else:

Expand Down
32 changes: 21 additions & 11 deletions renpy/display/behavior.py
Expand Up @@ -586,7 +586,7 @@ class SayBehavior(renpy.display.layout.Null):
"""

focusable = True
text = None
text_tuple = None

dismiss_unfocused = [ 'dismiss_unfocused' ]

Expand All @@ -613,24 +613,34 @@ def __init__(self, default=True, afm=None, dismiss=[ 'dismiss' ], allow_dismiss=
def _tts_all(self):
raise renpy.display.tts.TTSRoot()

def set_text(self, text):
self.text = text
def set_text(self, *args):
self.text_tuple = args

try:
afm_text = text.text[0][text.start:text.end]
afm_text = renpy.text.extras.filter_text_tags(afm_text, allow=[])
self.afm_length = max(len(afm_text), 1)
except Exception:
self.afm_length = max(text.end - text.start, 1)
self.afm_length = 1
self.text_time = 0

for text in args:

try:
afm_text = text.text[0][text.start:text.end]
afm_text = renpy.text.extras.filter_text_tags(afm_text, allow=[])
self.afm_length += max(len(afm_text), 1)
except Exception:
self.afm_length += max(text.end - text.start, 1)

def event(self, ev, x, y, st):

if self.afm_length and renpy.game.preferences.afm_time and renpy.game.preferences.afm_enable:

afm_delay = (1.0 * (renpy.config.afm_bonus + self.afm_length) / renpy.config.afm_characters) * renpy.game.preferences.afm_time

if self.text is not None:
afm_delay += self.text.get_time()
if self.text_tuple is not None:
max_time = 0

for t in self.text_tuple:
max_time = max(max_time, t.get_time())

afm_delay += max_time

if st > afm_delay:
if renpy.config.afm_callback:
Expand Down

0 comments on commit e0b23d1

Please sign in to comment.