forked from RenpyRemix/speech-bubbles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
speech_bubbles.rpy
489 lines (336 loc) · 13.6 KB
/
speech_bubbles.rpy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
## To view example in your game add
##
## call speech_bubble_example
##
## somewhere in your running label script
###########################################
# #
# To use in your game #
# #
# Create your characters and set them #
# to use the speech bubble screen. #
# The example at the end has a couple #
# of characters to see how. #
# Maybe delete the example bits (at #
# the end of this file) once happy #
# #
###########################################
###################
# #
# Styles #
# #
###################
#
# https://github.com/RenpyRemix/speech-bubbles/blob/master/explain_frames.md
#
# Characters who use the speech bubbles will need their what_style pointed
# at a style similar to this
#
# The first two settings are quite important. They let the bubbles
# shrink to the text bounds and position the first letter
style bubble_speech_text:
xsize None # needed - otherwise it uses a gui setting
align (0,0) # also likely needed
# just standard font specific stuff
color "#F00"
# font ""
kerning -1.0
size 26
bold True
# A rotated version of the bubble image
image speech_bubble_90:
# using contains so it rotates before crop
contains:
"images/speech_bubble.png"
rotate_pad False
transform_anchor True
anchor (0.0, 1.0)
rotate 90.0
# crop (as rotation increased the size)
crop (0, 0, 135, 130)
# Styles for the different frames
# Each direction the tail points uses different values so has its own style
style bubble_speech_baseright_frame:
# our background picture
background Frame(
"images/speech_bubble.png",
left = Borders(32, 33, 88, 80)
)
# These are the distance between the text area and frame outer edge
left_padding 24
top_padding 22
right_padding 23
bottom_padding 73
# We *could* do all that in one line with
# padding (24, 22, 23, 73) # (left, top, right, base)
minimum (121, 114)
# Now the anchor (the pixel of this widget to place at the stated pos)
# This should generally reflect where the end of the tail lies
anchor (1.0, 1.0)
# You could add a slight offset if wanted (so show_pos is on the tail)
offset (12, 7)
style bubble_speech_baseleft_frame:
# our background picture
background Frame(
Transform("images/speech_bubble.png", xzoom=-1),
left = Borders(88, 33, 32, 80)
)
# The distance between content and outer edge (left, top, right, base)
padding (23, 22, 24, 73)
minimum (121, 114)
anchor (0.0, 1.0)
offset (-12, 7)
style bubble_speech_topright_frame:
# our background picture
background Frame(
Transform("images/speech_bubble.png", yzoom=-1),
left = Borders(32, 80, 88, 33)
)
# The distance between content and outer edge (left, top, right, base)
padding (24, 73, 23, 22)
minimum (121, 114)
anchor (1.0, 0.0)
offset (12, -7)
style bubble_speech_topleft_frame:
# our background picture
background Frame(
Transform("images/speech_bubble.png", zoom=-1),
left = Borders(88, 80, 32, 33)
)
# The distance between content and outer edge (left, top, right, base)
padding (23, 73, 24, 22)
minimum (121, 114)
anchor (0.0, 0.0)
offset (-12, -7)
style bubble_speech_leftbase_frame:
# our background picture
background Frame(
"speech_bubble_90",
left = Borders(80, 32, 33, 88)
)
# The distance between content and outer edge (left, top, right, base)
padding (73, 24, 22, 23)
minimum (114, 121)
anchor (0.0, 1.0)
offset (-7, 12)
style bubble_speech_lefttop_frame:
# our background picture
background Frame(
Transform("speech_bubble_90", yzoom=-1),
left = Borders(80, 88, 33, 32)
)
# The distance between content and outer edge (left, top, right, base)
padding (73, 23, 22, 24)
minimum (114, 121)
anchor (0.0, 0.0)
offset (-7, -12)
style bubble_speech_righttop_frame:
# our background picture
background Frame(
Transform("speech_bubble_90", zoom=-1),
left = Borders(33, 88, 80, 32)
)
# The distance between content and outer edge (left, top, right, base)
padding (22, 23, 73, 24)
minimum (114, 121)
anchor (1.0, 0.0)
offset (7, -12)
style bubble_speech_rightbase_frame:
# our background picture
background Frame(
Transform("speech_bubble_90", xzoom=-1),
left = Borders(33, 32, 80, 88)
)
# The distance between content and outer edge (left, top, right, base)
padding (22, 24, 73, 23)
minimum (114, 121)
anchor (1.0, 1.0)
offset (7, 12)
# Just one to test we can pass (show_type="bubble_thought") and have it
# pick up a different style
style bubble_thought_baseright_frame is bubble_speech_baseright_frame:
alt "Thinking"
####################
# #
# Screens #
# & #
# Python #
# #
####################
#
# You probably will not need to edit this part
#
# Except maybe the callback if you want the default
# values to be different
#
# https://github.com/RenpyRemix/speech-bubbles/blob/master/explain_screens.md
#
default retained_dialogues = []
init python:
# This is just a list of style names that we want to remember for when
# multiple dialogues (bubbles) appear at once
retained_styles = (
renpy.screenlang.text_property_names
+ renpy.screenlang.position_property_names)
#This function gets called after each dialogue is shown
# It is responsible for calculating what will be shown with the
# next dialogue
def hide_dialogue(current_dialogue=None, screen="bubble_say"):
"""
Decrease all `retain` values by one and rebuild global
shown_dialogues only from those set to still be shown
Then add the current dialogue if it has been set to retain
"""
global retained_dialogues
next_retained_dialogues = []
for k in retained_dialogues:
k[1] -= 1
if k[1] > 0:
next_retained_dialogues.append(k)
retained_dialogues = next_retained_dialogues
if current_dialogue and not current_dialogue[0][0].endswith('.rpym'):
# This is where you could add a feature so one dialogue could
# alter setting for a retained dialogue (such as move it)
if current_dialogue[1] > 0:
# retain this one, so add it to the global
# first mirror the style applied to the text and add it
# to the kwargs
widget = renpy.get_widget(screen, 'what')
if widget:
widget_style = {
k : getattr(widget.style, k)
for k in dir(widget.style)
if k in retained_styles
}
current_dialogue[-1]['what_style'] = widget_style
retained_dialogues.append(list(current_dialogue))
# We use this callback so we can use simple arguments rather than
# keywords each time
def say_arguments_callback(who, *args, **kwargs):
if hasattr(who, "screen") and who.screen == "bubble_say":
# First we convert any passed args into kwargs
# (if the named kwarg has not been set)
#
# Args are a utility to pass common values quickly
# (xpos, ypos, tail)
if not "show_pos" in kwargs:
# Default POS as a list Not tuple
kwargs['show_pos'] = list(kwargs.get('show_pos', (800, 400)))
if args and args[0] is not None:
kwargs['show_pos'][0] = args[0]
if len(args) > 1 and args[1] is not None:
kwargs['show_pos'][1] = args[1]
if not "show_tail" in kwargs:
# Default tail style
kwargs['show_tail'] = 'baseright'
if len(args) > 2 and args[2] is not None:
kwargs['show_tail'] = args[2]
# You could amend to pass others as args too
kwargs['show_type'] = kwargs.get('show_type', "bubble_speech")
kwargs['show_xmax'] = kwargs.get('show_xmax', 320)
#kwargs['show_xmin'] = kwargs.get('show_xmin', 0)
kwargs['interact'] = kwargs.get('interact', True)
return (), kwargs
config.say_arguments_callback = say_arguments_callback
screen bubble_say(who, what, **kwargs):
# This is the main container screen
# It uses child screens to display each bubble, one for
# each dialogue that is set to be shown at this time
# A tuple of information about the current dialogue line
$ current_dialogue = (
renpy.get_filename_line(),
kwargs.pop('retain', 0),
who,
what,
kwargs )
# First the older (retained) dialogues
for old_dialogue in retained_dialogues:
$ old_who, old_what, old_kwargs = old_dialogue[2:]
use bubble_subscreen(old_who, **old_kwargs):
# Just standard Text here, no id needed
# Styled to match how the 'retained' line was shown
add Text(old_what, **old_kwargs['what_style'])
# The current line (including the "what" id)
use bubble_subscreen(who, **kwargs):
text what id "what"
# When this screen is hidden (at the next interaction from the player)
# we pass the tuple of current dialogue info to the function
on "hide":
action Function(hide_dialogue, current_dialogue)
screen bubble_subscreen(who, **kwargs):
# Each line of dialogue is shown in one of these subscreens
# To use the correct Frame style we can pass keywords
# show_type = the prefix part of the style
# show_tail = the suffix part of the style
#
# The prefix_suffix then can use _frame as a style name
style_prefix "{}_{}".format(kwargs['type'], kwargs['tail'])
fixed:
pos kwargs['pos']
frame:
xmaximum kwargs['xmax']
# set the min width as show_xmin if passed else use default
# (do not set smaller than the frame settings though)
if "xmin" in kwargs:
xminimum kwargs['xmin']
# this single word tells this screen where to use
# the indented widgets/attributes (the text part)
transclude
if check_bubble_positions:
add Solid('#FFF', xysize=(2, 40), anchor=(1, 20))
add Solid('#FFF', xysize=(40, 2), anchor=(20, 1))
# Utility settings to draw a white cross at the specified 'show_pos'
# Maybe useful to setup Frame styles or fine tune positions
default check_bubble_positions = False
# On/Off toggle of the white cross using [Alt] + [c] keys together
init python:
if config.developer:
config.underlay.append(
renpy.Keymap(
alt_K_c = lambda: renpy.run(
ToggleVariable("check_bubble_positions"))))
###########################################
# #
# You can delete the example characters #
# and label below once happy #
# #
###########################################
#####################
# #
# Characters #
# & #
# Sample #
# #
#####################
#
# https://github.com/RenpyRemix/speech-bubbles/blob/master/explain_usage.md
#
define speech_bubble_a = Character(
"Amber",
screen="bubble_say",
what_color="#282",
what_style="bubble_speech_text",
show_tail="leftbase")
define speech_bubble_k = Character(
"Kaori",
screen="bubble_say",
who_color="#FDD",
what_style="bubble_speech_text")
label speech_bubble_example:
$ quick_menu = False
window hide
scene expression "#777"
speech_bubble_k """A few lines showing the
speech bubble system in action...""" (950, 300, "righttop")
speech_bubble_a "Style default (baseright)
\nYou can press Alt+C to show the used pos" (640, 320, show_xmax=500, what_color="#888")
speech_bubble_k "Style baseleft" (640, 320, "baseleft")
speech_bubble_a "Style leftbase" (640, 320, "leftbase")
speech_bubble_k "Style lefttop" (640, 320, "lefttop")
speech_bubble_a "Style topleft" (640, 320, "topleft")
speech_bubble_k "Style topright" (640, 320, "topright")
speech_bubble_a "Style righttop" (640, 320, "righttop")
speech_bubble_k "Style rightbase" (640, 320, "rightbase")
speech_bubble_a "... and back to the game" (
640, 320, show_type="bubble_thought")
return