Advertisement
Guest User

Untitled

a guest
Feb 20th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.29 KB | None | 0 0
  1. # readback.rpy
  2.  
  3. init -3 python:
  4. # config.game_menu.insert(1,( "text_history", u"Text History", ui.jumps("text_history_screen"), 'not main_menu'))
  5.  
  6. # Styles.
  7.  
  8. style.readback_window = Style(style.nvl_window)
  9. '''style.readback_window.xmaximum = 760
  10. style.readback_window.ymaximum = 500
  11. style.readback_window.align = (.5, .5)'''
  12.  
  13. style.readback_frame.background = None
  14. style.readback_frame.xpadding = 10
  15. style.readback_frame.xmargin = 5
  16. style.readback_frame.ymargin = 5
  17.  
  18. style.readback_text.color = "#ffdd7d"
  19.  
  20. '''style.create("readback_button", "readback_text")
  21. style.readback_button.background = None
  22.  
  23. style.create("readback_button_text", "readback_text")
  24. style.readback_button_text.selected_color = "#f12"
  25. style.readback_button_text.hover_color = "#f12"'''
  26.  
  27. style.readback_label_text.bold = True
  28. style.readback_label_text.color = "#ffffff"
  29.  
  30. # starts adding new config variables
  31. config.locked = False
  32.  
  33. # Configuration Variable for Text History
  34. config.readback_buffer_length = 100 # number of lines stored
  35. config.readback_full = False # True = completely replaces rollback, False = readback accessible from game menu only (dev mode)
  36. config.readback_disallowed_tags = ["size"] # a list of tags that will be removed in the text history
  37. config.readback_choice_prefix = ">> " # this is prefixed to the choices the user makes in readback
  38.  
  39. # end
  40. config.locked = True
  41.  
  42. init -2 python:
  43.  
  44. # Two custom characters that store what they said
  45. class ReadbackADVCharacter(ADVCharacter):
  46. def do_done(self, who, what, who_args):
  47. store_say(who, what, who_args)
  48. store.current_voice = ''
  49. return
  50.  
  51. class ReadbackNVLCharacter(NVLCharacter):
  52. def do_done(self, who, what, who_args):
  53. store_say(who, what, who_args)
  54. store.current_voice = ''
  55. return
  56.  
  57. # this enables us to show the current line in readback without having to bother the buffer with raw shows
  58. def say_wrapper(who, what, **kwargs):
  59. store_current_line(who, what)
  60. return renpy.show_display_say(who, what, **kwargs)
  61.  
  62. config.nvl_show_display_say = say_wrapper
  63.  
  64. adv = ReadbackADVCharacter(show_function=say_wrapper)
  65. nvl = ReadbackNVLCharacter()
  66. NVLCharacter = ReadbackNVLCharacter
  67.  
  68. ## readback
  69. readback_buffer = []
  70. current_line = None
  71. current_voice = None
  72.  
  73. def store_say(who, what, who_args):
  74. say_color = " "
  75. try:
  76. say_color = '#%02x%02x%02x' % who_args['color'][0:3]
  77. except:
  78. pass
  79. global readback_buffer, current_voice
  80. new_line = (who, preparse_say_for_store(what), current_voice, say_color)
  81. readback_buffer = readback_buffer + [new_line]
  82. readback_prune()
  83.  
  84. def store_current_line(who, what):
  85. global current_line, current_voice
  86. current_line = (who, preparse_say_for_store(what), current_voice, " ")
  87.  
  88. # remove text tags from dialogue lines
  89. disallowed_tags_regexp = ""
  90. for tag in config.readback_disallowed_tags:
  91. if disallowed_tags_regexp != "":
  92. disallowed_tags_regexp += "|"
  93. disallowed_tags_regexp += "{"+tag+"=.*?}|{"+tag+"}|{/"+tag+"}"
  94.  
  95. import re
  96. remove_tags_expr = re.compile(disallowed_tags_regexp) # remove tags undesirable in readback
  97. def preparse_say_for_store(input):
  98. global remove_tags_expr
  99. if input:
  100. return re.sub(remove_tags_expr, "", input)
  101.  
  102. def readback_prune():
  103. global readback_buffer
  104. while len(readback_buffer) > config.readback_buffer_length:
  105. del readback_buffer[0]
  106.  
  107. # keymap overriding to show text_history.
  108. #def readback_catcher():
  109. #ui.add(renpy.Keymap(rollback=(SetVariable("yvalue", 1.0), ShowMenu("text_history"))))
  110. #ui.add(renpy.Keymap(rollforward=ui.returns(None)))
  111.  
  112. #if config.readback_full:
  113. #config.rollback_enabled = False
  114. #config.overlay_functions.append(readback_catcher)
  115.  
  116. # Text History Screen.
  117. screen text_history:
  118.  
  119. tag menu
  120.  
  121. if not current_line and len(readback_buffer) == 0 and d2_cardgame_block_rollback:
  122. $ lines_to_show = []
  123.  
  124. elif not current_line and len(readback_buffer) == 0:
  125. $ lines_to_show = []
  126.  
  127. elif current_line and len(readback_buffer) == 0:
  128. $ lines_to_show = [current_line]
  129.  
  130. elif current_line and not ( current_line == readback_buffer[-1] or False
  131. if len(readback_buffer) == 1 else (current_line == readback_buffer[-2]) ):
  132. $ lines_to_show = readback_buffer# + [current_line]
  133.  
  134. else:
  135. $ lines_to_show = readback_buffer
  136.  
  137.  
  138. #$ adj = NewAdj(changed = store_yvalue, step = 300)
  139.  
  140. button style "blank_button" xpos 0 ypos 0 xfill True yfill True action Return()
  141.  
  142. window background Frame(get_image("gui/choice/"+persistent.timeofday+"/choice_box.png"),50,50) xmaximum 0.83 xalign 0.01 yalign 0.01 left_padding 75 right_padding 75 bottom_padding 50 top_padding 50:
  143. style_group "readback"
  144.  
  145. side "c t r":
  146. viewport id "readback":
  147. draggable True
  148. mousewheel True
  149. scrollbars None
  150. yinitial 1.0
  151.  
  152. #frame:
  153.  
  154. #$ vp = ui.viewport(mousewheel = True, draggable=True, offsets=(0.0, yvalue), yadjustment = adj)
  155.  
  156. vbox:
  157. null height 10
  158.  
  159. python:
  160. count=1
  161. total=0
  162.  
  163. mass = lines_to_show
  164. for i in mass:
  165. if i[1]:
  166. if not i[2]:
  167. total+=1
  168. #renpy.log("line = %s" % i[1])
  169.  
  170. for line in lines_to_show:
  171.  
  172. if line[0] and line[0] != " ":
  173.  
  174. if line[3] and line[3] != " ":
  175. python:
  176. sayer = line[0]
  177.  
  178.  
  179.  
  180. text sayer color line[3]
  181.  
  182. else:
  183. text line[0]
  184.  
  185. if line[1]:
  186. # if there's no voice just log a dialogue
  187. if not line[2]:
  188. python:
  189. cn=total-count
  190. count+=1
  191. if persistent.font_size == "small":
  192. textbutton __(line[1]) text_size 28 style "log_button" text_style "log_button_text" action FunctionCallback(do_rollback,cn)
  193. elif persistent.font_size == "large":
  194. textbutton __(line[1]) text_size 35 style "log_button" text_style "log_button_text" action FunctionCallback(do_rollback,cn)
  195. else:
  196. null height 1
  197.  
  198. # else, dialogue will be saved as a button of which plays voice when clicked
  199. else:
  200. textbutton line[1] action Play("voice", line[2] )
  201.  
  202. null height 10
  203. python:
  204. count=None
  205. total=None
  206. mass=None
  207.  
  208.  
  209. $ vbar_null = Frame(get_image("gui/settings/vbar_null.png"),0,0)
  210.  
  211. bar value XScrollValue("readback") left_bar "images/misc/none.png" right_bar "images/misc/none.png" thumb "images/misc/none.png" hover_thumb "images/misc/none.png"
  212. vbar value YScrollValue("readback") bottom_bar vbar_null top_bar vbar_null thumb "images/gui/settings/vthumb.png" thumb_offset -12 xalign 1.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement