This is how my textbox looks like: This is my code so far:Alaina93 wrote:I'd like to create a history screen for my game, which is a 1280x800 resolution screen. I want to be able to have a scroll bar, but the scroll bar keeps changing the more text there is, so it kind of gets hidden when there's too much text.
I'd like a history box like in the VN Taraadin by Cyanide Tea. With a functioning scroll bar, and text that is very neatly divided etc.
Code: Select all
# readback.rpy
# drop in readback module for Ren'Py by delta
# simplified/updated around Ren'Py version 6.13.12
# this file is licensed under the terms of the WTFPL
# see http://sam.zoy.org/wtfpl/COPYING for details
init -3 python:
# Styles.
style.readback_window.xminimum = 800
style.readback_window.yminimum = 700
style.readback_window.align = (0, 0)
style.readback_frame.background = "black.png"
style.readback_frame.align = (0, 0)
style.create("readback_button", "readback_text")
style.readback_button.background = None
style.readback_text.color = "#fff"
style.readback_text.size = 21
style.readback_label.align = (0, 0)
style.create("readback_button_text", "readback_text")
style.readback_button_text.selected_color = "#f12"
style.readback_button_text.hover_color = "#f12"
style.readback_label_text.bold = False
style.readback_label_text.size = 40
style.readback_label_text.font = "fonts/Tangerine_R.ttf"
style.readback_label_text.color = "#FF4277"
# starts adding new config variables
config.locked = False
# Configuration Variable for Text History
config.readback_buffer_length = 100 # number of lines stored
config.readback_full = True # completely replaces rollback, False = readback accessible from game menu only (dev mode)
config.readback_disallowed_tags = ["size"] # a list of tags that will be removed in the text history
config.readback_choice_prefix = ">> " # this is prefixed to the choices the user makes in readback
# end
config.locked = True
init -2 python:
# Two custom characters that store what they said
class ReadbackADVCharacter(ADVCharacter):
def do_done(self, who, what):
store_say(who, what)
super(ReadbackADVCharacter, self).do_done(who, what)
return
def do_extend(self):
delete_last_line()
super(ReadbackADVCharacter, self).do_extend()
return
class ReadbackNVLCharacter(NVLCharacter):
def do_done(self, who, what):
store_say(who, what)
super(ReadbackNVLCharacter, self).do_done(who, what)
return
def do_extend(self):
delete_last_line()
super(ReadbackNVLCharacter, self).do_extend()
return
adv = ReadbackADVCharacter()
nvl = ReadbackNVLCharacter()
NVLCharacter = ReadbackNVLCharacter
# overwriting standard menu handler
# Overwriting menu functions makes Text History log choice which users choose.
def menu(items, **add_input):
rv = renpy.display_menu(items, **add_input)
# logging menu choice label.
for label, val in items:
if rv == val:
store_say(None, config.readback_choice_prefix + label)
return rv
# Overwriting nvl menu function
builtin_nvl_menu = nvl_menu
def nvl_menu(items):
rv = builtin_nvl_menu(items)
for label, val in items:
if rv == val:
store_say(None, config.readback_choice_prefix + label)
return rv
readback_buffer = []
def store_say(who, what):
global readback_buffer
new_line = (preparse_say_for_store(who), preparse_say_for_store(what))
readback_buffer.append(new_line)
readback_prune()
def delete_last_line():
global readback_buffer
del readback_buffer[-1]
# remove text tags from dialogue lines
disallowed_tags_regexp = ""
for tag in config.readback_disallowed_tags:
if disallowed_tags_regexp != "":
disallowed_tags_regexp += "|"
disallowed_tags_regexp += "{"+tag+"=.*?}|{"+tag+"}|{/"+tag+"}"
import re
readback_remove_tags_expr = re.compile(disallowed_tags_regexp) # remove tags undesirable in readback
def preparse_say_for_store(input):
global readback_remove_tags_expr
if input:
return re.sub(readback_remove_tags_expr, "", input)
def readback_prune():
global readback_buffer
while len(readback_buffer) > config.readback_buffer_length:
del readback_buffer[0]
# keymap overriding to show text_history.
def readback_catcher():
ui.add(renpy.Keymap(rollback=(SetVariable("readback_yvalue", 1.0), ShowMenu("text_history"))))
ui.add(renpy.Keymap(rollforward=ui.returns(None)))
if config.readback_full:
config.rollback_enabled = False
config.overlay_functions.append(readback_catcher)
init python:
readback_yvalue = 1.0
class ReadbackAdj(ui.adjustment):
def change(self,value):
if value > self._range and self._value == self._range:
return Return()
else:
return ui.adjustment.change(self, value)
def readback_store_yvalue(y):
global readback_yvalue
readback_yvalue = int(y)
# Text History Screen.
screen text_history:
tag menu
$ adj = ReadbackAdj(changed = readback_store_yvalue, step = 300)
window:
style_group "readback"
side "c r":
frame:
$ ui.viewport(mousewheel = True, offsets=(0.0, readback_yvalue), yadjustment = adj)
vbox:
null height 10
for line in readback_buffer:
if line[0]:
label line[0]
text line[1]
null height 10
bar adjustment adj style 'vscrollbar'
imagebutton idle "resume_idle.png" hover "resume_hover.png" xpos 0 ypos 0 focus_mask True action Return()