Last active
January 29, 2024 05:54
-
-
Save shawna-p/3a12772369af03b85b25196275412868 to your computer and use it in GitHub Desktop.
Preview Slow CPS in Ren'Py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Response to/Adapted from methanoliver https://gist.github.com/methanoliver/bbb026b2c6daeb9b7aae508314e30cfd | |
## and Lezalith: https://gist.github.com/Lezalith/f6ea469f10f10d21f53c2c5f592cd12f | |
## This is a version specifically geared towards display on the preferences screen. | |
init -10 python: | |
class PreviewSlowText(renpy.Displayable): | |
""" | |
A class to display a preview of the current CPS settings. | |
Attributes: | |
----------- | |
text : string | |
The text to display for this displayable preview. | |
properties : dict | |
Optional keyword arguments that will be applied to the text | |
to style it. | |
""" | |
def __init__(self, text, **properties): | |
super(PreviewSlowText, self).__init__() | |
# Store original arguments for recreating the Text child later | |
self.original_text = text | |
self.original_properties = properties | |
# Text displayable that represents PreviewSlowText. | |
self.current_child = self.new_text() | |
# The "start time" of the animation | |
self.start_st = None | |
# The current st of the animation | |
self.current_st = 0 | |
def new_text(self): | |
"""Create a new Text object with the current CPS.""" | |
return Text(self.original_text, slow_cps=preferences.text_cps, | |
**self.original_properties) | |
def update_cps(self): | |
"""Update the displayable to show the text at the new CPS.""" | |
self.current_child = self.new_text() | |
self.start_st = self.current_st | |
def render(self, width, height, st, at): | |
"""Render the text to the screen.""" | |
# Record when this animation is starting | |
if self.start_st is None: | |
self.start_st = st | |
# Keep track of the current st | |
self.current_st = st | |
# Trigger this function again when possible, | |
# to test and/or update all of this stuff again. | |
renpy.redraw(self, 0) | |
# Create a render (canvas). | |
render = renpy.Render(width, height) | |
# Calculate the "virtual" start time | |
new_st = st - self.start_st | |
# Place the Text child onto it, with the adjusted st | |
render.place(self.current_child, st=new_st, at=at) | |
# Return the render. | |
return render | |
## Sample in the preferences screen | |
screen preferences(): | |
tag menu | |
default slow_text_preview = PreviewSlowText("This is a preview for the CPS") ## NEW! | |
vbox: | |
style_prefix "slider" | |
label _("Text Speed") | |
bar value Preference("text speed"): | |
released Function(slow_text_preview.update_cps) ## NEW! | |
add slow_text_preview ## NEW! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment