File: tutorial_screens.rpy

package info (click to toggle)
renpy 8.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 81,768 kB
  • sloc: python: 44,587; ansic: 13,708; javascript: 308; makefile: 41; sh: 13
file content (662 lines) | stat: -rw-r--r-- 20,272 bytes parent folder | download
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
################################################################################
# Stats screen.
#
# This displays RPG-like statistics.
################################################################################

default player_hp = 15
default player_hp_max = 42
default eileen_hp = 100
default eileen_hp_max = 100

default player_lv = 4
default eileen_lv = 99

# This screen displays a single stat.
screen single_stat(name, hp, hp_max, lv, xalign):

    frame:
        xalign xalign

        vbox:
            spacing 5

            hbox:
                text "[name!t]" min_width 220
                text _(" Lv. [lv]")

            hbox:
                text _("HP"):
                    min_width 40
                    yalign 0.5

                bar:
                    value AnimatedValue(hp, hp_max, 1.0)
                    xmaximum 180
                    ysize 26


                text " [hp]/[hp_max]":
                    yalign 0.5


# This screen uses single_stat to display two stats at once.
screen stats():
    use single_stat(_("Player"), player_hp, player_hp_max, player_lv, 0.0)
    use single_stat(_("Eileen"), eileen_hp, eileen_hp_max, eileen_lv, 1.0)


################################################################################
# Day picker
#
# This code displays a day picker, including statistics and a way of choosing
# an action for each period of the day.
################################################################################


# This constant defines the periods in the day.
define day_periods = [ _('Morning'), _('Afternoon'), _('Evening') ]

# This constant defines what to do in each period.
define day_choices = [ _('Study'), _('Exercise'), _('Eat'), _('Drink'), _('Be Merry') ]

# This is a dictionary mapping a period to a
default day_plan = {
    'Morning' : 'Eat',
    'Afternoon' : 'Drink',
    'Evening' : 'Be Merry'
    }

# These variables display statistics to the player.
default stat_strength = 10
default stat_intelligence = 25
default stat_moxie = 100
default stat_chutzpah = 75

# These styles are used to style the various stats.
style stat_text is default:
    min_width 200
    text_align 1.0
    yalign 0.5

style stat_hbox is hbox:
    spacing 10

style stat_vbox:
    spacing 5


# This is the day planner screen. It displays the

screen day_planner():

    # This vbox organizes everything.
    vbox:

        spacing 5

        # A frame containing all the stats.
        frame:
            style_prefix "stat"
            xpadding 150
            xfill True

            vbox:

                hbox:
                    text _("Strength")
                    bar value StaticValue(stat_strength, 100)

                hbox:
                    text _("Intelligence")
                    bar value StaticValue(stat_strength, 100)

                hbox:
                    text _("Moxie")
                    bar value StaticValue(stat_strength, 100)

                hbox:
                    text _("Chutzpah")
                    bar value StaticValue(stat_strength, 100)


        # A grid of three frames, one for each of the periods in the day.
        grid 3 1:

            spacing 5
            xfill True

            for p in day_periods:

                frame:
                    xfill True

                    vbox:
                        label p

                        null height 5

                        for i in day_choices:
                            textbutton i action SetDict(day_plan, p, i)

        # This is a grid containing two empty space and the done button,
        # so everything lines up.
        grid 3 1:
            xfill True
            spacing 5

            null

            frame:
                textbutton _("Done"):
                    action Return(True)
                    xfill True

                    text_xalign 0.5

            null





label tutorial_screens:

    e "Screens are the most powerful part of Ren'Py. Screens let you customize the out-of-game interface, and create new in-game interface components."

label screens_menu:

    $ reset_example()

    menu:

        e "What would you like to know about screens?"

        "What screens can do.":
            call screens_demo

        "How to show screens.":
            call screens_showing

        "Passing parameters to screens.":
            call screens_parameters

        "Screen properties.":
            call screens_properties

        "Special screen statements.":
            call screens_control

        "Using other screens.":
            call screen_use

        "That's it.":
            return

    jump screens_menu


label screens_demo:

    e "Screens are how we create the user interface in Ren'Py. With the exception of images and transitions, everything you see comes from a screen."

    e "When I'm speaking to you, I'm using the 'say' screen. It's responsible for taking dialogue and presenting it to the player."

    menu:

        e "And when the menu statement displays an in-game choice, the 'choice' screen is used. Got it?"

        "Yes.":
            pass

        "I do.":
            pass

    e "Text input uses the 'input' screen, NVL mode uses the 'nvl' screen, and so on."

    e "More than one screen can be displayed at once. For example, the buttons at the bottom - Back, History, Skip, and so on - are all displayed by a quick_menu screen that's shown all of the time."

    e "There are a lot of special screens, like 'main_menu', 'load', 'save', and 'preferences'. Rather than list them all here, I'll {a=https://www.renpy.org/doc/html/screen_special.html}send you to the documentation{/a}."

    e "In a newly created project, all these screens live in screens.rpy. You can edit that file in order to change them."

    e "You aren't limited to these screens either. In Ren'Py, you can make your own screens, and use them for your game's interface."

    $ player_hp = 15

    show screen stats
    with dissolve

    e "For example, in an RPG like visual novel, a screen can display the player's statistics."

    $ player_hp = 42

    e "Which reminds me, I should probably heal you."

    hide screen stats
    show screen day_planner

    with dissolve

    e "Complex screens can be the basis of whole game mechanics. A stats screen like this can be the basis of dating and life-sims."

    hide screen day_planner
    with dissolve

    e "While screens might be complex, they're really just the result of a lot of simple parts working together to make something larger than all of them."

    return




label screens_showing:

    example large noshow:
        screen simple_screen():
            frame:
                xalign 0.5 ypos 50
                vbox:
                    text _("This is a screen.")
                    textbutton _("Okay"):
                        action Return(True)


    e "Here's an example of a very simple screen. The screen statement is used to tell Ren'Py this is a screen, and its name is simple_screen." id screens_showing_1b51e9a4

    e "Inside the screen statement, lines introduces displayables such as frame, vbox, text, and textbutton; or properties like action, xalign, and ypos."

    show screen simple_screen
    with dissolve

    e "I'll work from the inside out to describe the statements. But first, I'll show the screen so you can see it in action."

    e "The text statement is used to display the text provided."

    e "The textbutton statement introduces a button that can be clicked. When the button is clicked, the provided action is run."

    e "Both are inside a vbox, which means vertical box, statement - that places the text on top of the button."

    e "And that is inside a frame that provides the background and borders. The frame has an at property that takes a transform giving its position."

    hide screen simple_screen
    hide example
    with dissolve

    e "There are a trio of statements that are used to display screens."

    example:
        show screen simple_screen

        e "The first is the show screen statement, which displays a screen and lets Ren'Py keep going."

        e "The screen will stay shown until it is hidden."

        hide screen simple_screen

        e "Hiding a screen is done with the hide screen statement."

    show example call_screen

    e "The call screen statement stops Ren'Py from executing script until the screen either returns a value, or jumps the script somewhere else."

    e "Since we can't display dialogue at the same time, you'll have to click 'Okay' to continue."

    hide example

    example call_screen hide:
        call screen simple_screen

    e "When a call screen statement ends, the screen is automatically hidden."

    e "Generally, you use show screen to show overlays that are up all the time, and call screen to show screens the player interacts with for a little while."

    return


label screens_parameters:

    example large noshow:
        screen parameter_screen(message, okay=Return(True), cancel=Return(False)):
            frame:
                xalign 0.5 ypos 50
                vbox:
                    text "[message!t]"
                    textbutton _("Okay"):
                        action okay
                    textbutton _("Cancel"):
                        action cancel

    example hide show_parameter_screen:
        show screen parameter_screen(_("Hello, world."), cancel=Notify(_("You can't cancel this.")))

    with dissolve

    e "Here's an example of a screen that takes three parameters. The message parameter is a message to show, while the okay and cancel actions are run when the appropriate button is chosen."

    e "While the message parameter always has to be supplied, the okay and cancel parameters have default values that are used if no argument is given."

    e "Each parameter is a variable that is defined inside the screen. Inside the screen, these variables take priority over those used in the rest of Ren'Py."

    show example show_parameter_screen

    e "When a screen is shown, arguments can be supplied for each of the parameters. Arguments can be given by position or by name."

    example:
        show screen parameter_screen(_("Shiro was here."))

    with dissolve

    e "Parameters let us change what a screen displays, simply by re-showing it with different arguments."

    hide screen parameter_screen
    with dissolve

    show example call_parameter_screen

    e "The call screen statement can also take arguments, much like show screen does."

    hide example

    example hide call_parameter_screen:
        call screen parameter_screen(_("Click either button to continue."))

    return


label screens_properties:

    e "There are a few properties that can be applied to a screen itself."

    example large:
        screen modal_example():
            modal True

            frame:
                xalign 0.5 ypos 50
                textbutton _("Close This Screen"):
                     action Hide("modal_example")

    e "When the modal property is true, you can't interact with things beneath the screen. You'll have to click 'Close This Screen' before you can continue."

    example:
        screen a_tag_screen():
            tag tag_screen

            frame:
                xalign 0.33 ypos 50
                text _("A Tag Screen")

        screen b_tag_screen():
            tag tag_screen

            frame:
                xalign 0.66 ypos 50
                text _("B Tag Screen")


    e "When a screen has the tag property, it's treated like the tag part of an image name. Here, I'm showing a_tag_screen."

    show screen b_tag_screen

    e "When I show b_tag_screen, it replaces a_tag_screen."

    e "This is useful in the game and main menus, where you want the load screen to replace the preferences screen. By default, all those screens have tag menu."

    show eileen concerned

    e "For some reason, tag takes a name, and not an expression. It's too late to change it."

    show eileen happy
    with None

    hide screen b_tag_screen

    example noshow:
        screen zorder_100_screen():
            zorder 100
            frame:
                xalign 0.5 xoffset 50 ypos 70
                text "Zorder 100"

        screen zorder_0_screen():
            frame:
                xalign 0.5 ypos 50
                text "Zorder 0"

        show screen zorder_100_screen
        show screen zorder_0_screen

    with dissolve

    e "The zorder property controls the order in which screens overlap each other. The larger the zorder number, the closer the screen is to the player."

    e "By default, a screen has a zorder of 0. When two screens have the same zorder number, the screen that is shown second is closer to the player."



    hide screen zorder_100_screen
    hide screen zorder_0_screen

    example nohide:

        screen variant_screen():
            variant "small"
            frame:
                xalign 0.5 ypos 50
                text _("You're on a small device.")

        screen variant_screen():
            frame:
                xalign 0.5 ypos 50
                text _("You're not on a small device.")

    e "The variant property selects a screen based on the properties of the device it's running on."

    e "In this example, the first screen will be used for small devices like telephones, and the other screen will be used for tablets and computers."


    example:

        screen style_prefix_screen():
            style_prefix "red"

            frame:
                xalign 0.5 ypos 50
                text _("This text is red.")

        style red_frame:
            background "#440000d9"

        style red_text:
            color "#ffc0c0"


    e "Finally, the style_prefix property specifies a prefix that's applied to the styles in the screen."

    e "When the 'red' prefix is given, the frame gets the 'red_frame' style, and the text gets the 'red_text' style."

    e "This can save a lot of typing when styling screens with many displayables in them."

    hide example

    return

label warp_screen_displayables:
    $ renpy.pop_call()
    jump screen_displayables

label screens_control:

    e "The screen language has a few statements that do things other than show displayables. If you haven't seen the section on {a=jump:warp_screen_displayables}Screen Displayables{/a} yet, you might want to check it out, then come back here."

    example large:
        screen single_python_screen():

            $ message = _("Hello, World.")

            frame:
                xalign 0.5 ypos 50
                vbox:
                    text "[message!t]"

    e "The python statement works just about the same way it does in the script. A single line of Python is introduced with a dollar sign. This line is run each time the screen updates."

    example large:
        screen block_python_screen():

            python:
                message1 = _("Hello, World.")
                message2 = _("It's good to meet you.")

            frame:
                xalign 0.5 ypos 50
                vbox:
                    text "[message1!t]"
                    text "[message2!t]"

    e "Similarly, the python statement introduces an indented block of python statements. But there is one big difference in Python in screens and Python in scripts."

    e "The Python you use in screens isn't allowed to have side effects. That means that it can't do things like change the value of a variable."

    e "The reason for this is that Ren'Py will run a screen, and the Python in it, during screen prediction."

    example large:

        screen default_screen():

            default n = 0

            frame:
                xalign 0.5 ypos 50
                vbox:
                    text "n = [n]"
                    textbutton _("Increase") action SetScreenVariable("n", n + 1)

    e "The default statement lets you set the value of a screen variable the first time the screen runs. This value can be changed with the SetScreenVariable and ToggleScreenVariable actions."

    e "The default statement differs from the Python statement in that it is only run once. Python runs each time the screen updates, and hence the variable would never change value."


    example large:

        screen if_screen():

            default n = 0

            frame:
                xalign 0.5 ypos 50
                vbox:
                    if n > 2:
                        text "n = [n]" color "#cfc"
                    else:
                        text "n = [n]" color "#fcc"

                    textbutton _("Increase") action SetScreenVariable("n", n + 1)

    e "The if statement works like it does in script, running one block if the condition is true and another if the condition is false."

    example large:

        screen for_screen():

            $ landings = [ _("Earth"), _("Moon"), _("Mars") ]

            frame:
                xalign 0.5 ypos 50

                vbox:
                    for i in landings:
                        textbutton "[i!t]" action Return(i)

    e "The for statement takes a list of values, and iterates through them, running the block inside the for loop with the variable bound to each list item."

    example large:

        screen on_key_screen():

            frame:
                xalign 0.5 ypos 50

                text _("Now press 'a'.")

            on "show" action Notify(_("The screen was just shown."))

            key "a" action Notify(_("You pressed the 'a' key."))


    e "The on and key statements probably only make sense at the top level of the screen."

    e "The on statement makes the screen run an action when an event occurs. The 'show' event happens when the screen is first shown, and the 'hide' event happens when it is hidden."

    e "The key event runs an event when a key is pressed."

    hide example

    return

label screen_use:

    e "The screen language use statement lets you include a screen inside another. This can be useful to prevent duplication inside screens."

    example large:

        screen duplicate_stats():
            frame:
                xalign 0.5 ypos 50
                vbox:
                    text _("Health") xalign 0.5
                    bar value StaticValue(90, 100) xalign 0.5 xsize 250

                    null height 15

                    text _("Magic") xalign 0.5
                    bar value StaticValue(42, 100) xalign 0.5 xsize 250

    e "Take for example this screen, which shows two stat entries. There's already a lot of duplication there, and if we had more stats, there would be more."

    example large:

        screen using_stats():
            frame:
                xalign 0.5 ypos 50
                vbox:
                    use stat(_("Health"), 90)
                    null height 15
                    use stat(_("Magic"), 42)

        screen stat(name, amount):

            text name xalign 0.5
            bar value StaticValue(amount, 100) xalign 0.5 xsize 250

    e "Here, we moved the statements that show the text and bar into a second screen, and the use statement includes that screen in the first one."

    e "The name and amount of the stat are passed in as arguments to the screen, just as is done in the call screen statement."

    e "By doing it this way, we control the amount of duplication, and can change the stat in one place."

    example large:

        screen transclusion_example():

            use boilerplate():
                text _("There's not much left to see.")

        screen boilerplate():
            frame:
                xalign 0.5 ypos 50

                vbox:
                    transclude

    e "The transclude statement goes one step further, by letting the use statement take a block of screen language statements."

    e "When the included screen reaches the transclude statement it is replaced with the block from the use statement."

    e "The boilerplate screen is included in the first one, and the text from the first screen is transcluded into the boilerplate screen."

    e "Use and transclude are complex, but very powerful. If you think about it, 'use boilerplate' is only one step removed from writing your own Screen Language statement."

    hide example
    return