Cycle and preview fonts in game.
Posted: Sun Jul 25, 2021 12:15 am
Instead of changing the font filename every time in code, then tabbing back into Ren'py waiting for it to refresh, now you can just press hotkeys in game to cycle through and preview fonts from a specified font folder.
Example of use:
1. Create a fonts folder in your game directory, and put all fonts in there.
2. Add this code to the screen main_menu() like this, or anywhere else you want to preview a font with your game's text.
3. Now press the u and i hotkeys at the main menu to preview all the fonts for your main menu logo. This code can be used anywhere in game to preview any text with a style.
Keep in mind, putting this part in a style does not work.
Instead you have to put it in the button's properties like this:
Example of use:
1. Create a fonts folder in your game directory, and put all fonts in there.
2. Add this code to the screen main_menu() like this, or anywhere else you want to preview a font with your game's text.
Code: Select all
# screens.rpy
########## [1/4] ADD THIS BLOCK ###########
init python:
import re
# this gets a dir list of files
def file_list(dir=""):
list = renpy.list_files()
rv = []
for f in list:
if re.match(dir,f):
rv.append(f[(len(dir)):])
return rv
########## /ADD THIS BLOCK ###########
########## [2/4] ADD THIS VARIABLE ###########
default cycleFontIndex = 0
screen main_menu():
################ [3/4] ADD THIS BLOCK ############
# access all fonts in the fonts folder in the game directory
$ files = file_list("fonts")
# hotkeys that you can change if you want that change index value
key "i" action SetVariable('cycleFontIndex', cycleFontIndex+1)
key "u" action SetVariable('cycleFontIndex', cycleFontIndex-1)
vbox:
# debug to verify the index is working and font files are successfully accessed
text str(cycleFontIndex)
text str(files[cycleFontIndex])
##################/ADD THIS BLOCK ##################
if gui.show_name:
vbox:
style "main_menu_vbox"
text "[config.name!t]":
font "fonts" + files[cycleFontIndex] ########## [4/4] ADD THIS FONT STYLE ###########
style "main_menu_title"
Keep in mind, putting this part in a style does not work.
Code: Select all
font "fonts" + files[cycleFontIndex]
Code: Select all
textbutton "Test":
text_font "fonts" + files[cycleFontIndex]
action NullAction()