Ren'py 系统设置界面修改(二)
本文修改全部位于screens.rpy文件中
参考资料
视频教程
新建界面
先新建一个界面,添加必要部分,参考代码如下
| 1 | screen message(): | 
功能选项
文字显示速度
由于文字显示速度只受preferences.text_cps影响,但我们需要至少常规模式下文本显示速度和自动模式下文本显示速度两个选项,所以采用自定义变量的方法实现
- 自定义变量 1 
 2
 3
 4## 常规模式下文本显示速度 
 default normal_text_cps=50
 ## 自动模式下文本显示速度
 default afm_text_cps = 50
- say界面中添加如下代码- 1 
 2
 3
 4
 5
 6- ## 常规文本显示速度 
 if not _preferences.afm_enable:
 $ preferences.text_cps = normal_text_cps
 ## 自动模式下文本显示速度
 else:
 $ preferences.text_cps = afm_text_cps
- 添加如下代码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
 45vbox: 
 xpos 100
 yalign 0.5
 spacing 50
 vbox:
 spacing 10
 hbox:
 spacing 10
 add "label.png"
 text "文本显示速度" color "#4e021f"
 
 hbox:
 spacing 5
 bar:
 value VariableValue("normal_text_cps",range=100)
 xsize 425
 right_bar "volume.png"
 left_bar "volume_left.png"
 thumb "thu.png"
 frame:
 background "volume_num.png"
 text "[normal_text_cps]" xoffset 10 yoffset -8
 vbox:
 xpos 750
 yoffset -73
 yalign 0.5
 spacing 50
 vbox:
 spacing 10
 hbox:
 spacing 10
 add "label.png"
 text "自动模式文本阅读速度" color "#4e021f"
 hbox:
 spacing 5
 bar:
 value VariableValue("afm_text_cps",range=100)
 xsize 425
 right_bar "volume.png"
 left_bar "volume_left.png"
 thumb "thu.png"
 frame:
 background "volume_num.png"
 text "[afm_text_cps]" xoffset 10 yoffset -8
自动模式下等待时间
添加如下代码即可1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18vbox:
    spacing 10
    hbox:
        spacing 10
        add "label.png"
        text "自动模式速度" color "#4e021f" 
    hbox:
        spacing 5
        bar:
            value Preference("auto-forward time",range=100)
            xsize 425
            right_bar "volume.png"
            left_bar "volume_left.png"
            thumb "thu.png"
        frame:
            background "volume_num.png"
            $ auto_text_speed=int(preferences.afm_time)
            text "[auto_text_speed]" xoffset 10 yoffset -8
自动模式下是否等待语音播放完毕
添加如下代码即可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
26vbox:
    spacing 10
    hbox:
        spacing 10
        add "label.png"
        text "自动模式下是否等待语音播放完毕" color "#4e021f" 
    hbox:
        spacing 20 
        ## 等待语音播放完毕
        if preferences.wait_voice ==True:
            imagebutton:
                idle "on.png"
                action Preference("wait for voice", "enable")
            imagebutton:
                idle "hover_off.png"
                hover "off.png"
                action Preference("wait for voice", "disable") 
        ## 不等待语音播放完毕
        else:
            imagebutton:
                idle "hover_on.png"
                hover "on.png"
                action Preference("wait for voice", "enable")
            imagebutton:
                idle "off.png"
                action Preference("wait for voice", "disable") 
对话框透明度
- 自定义变量 - 1 
 2- ## 对话框不透明度 
 default persistent.textbox_transparency = 0.2
- say界面中做出如下修改- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15- ## 文本框透明度 
 $ textbox_alpha = 1 - persistent.textbox_transparency
 window:
 id "window"
 ## 调节对话框透明度
 background Image(im.Alpha("gui/textbox.png", textbox_alpha), xalign=0.5, yalign=1.0)
 
 if who is not None:
 window:
 id "namebox"
 ## 调节姓名框透明度
 background Image(im.Alpha("gui/namebox.png", textbox_alpha))
 style "namebox"
 text who id "who" xoffset 60 yoffset -30
- 添加如下代码 - 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18- vbox: 
 spacing 10
 hbox:
 spacing 10
 add "label.png"
 text "对话框透明度" color "#4e021f"
 hbox:
 spacing 5
 bar:
 value FieldValue(persistent, "textbox_transparency", range=1.0, style="slider")
 xsize 425
 right_bar "volume.png"
 left_bar "volume_left.png"
 thumb "thu.png"
 frame:
 background "volume_num.png"
 $ textbox_alpha=int(persistent.textbox_transparency*100)
 text "[textbox_alpha]" xoffset 10 yoffset -8
preference为声明为持久化变量的标识,在设置界面中,请尽量使用持久化数据
文字阴影
- 自定义变量 - 1 
 2- ## 文字阴影 
 default text_shadow = True
- say界面中做出如下修改- 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- ## 已读文本变色 
 if text_color_changeable == True:
 ## 有文字阴影
 if text_shadow == True:
 ## 已被查看(不包括当前文本)
 if renpy.is_seen(ever = True):
 text what id "what" color "#FFFF00" outlines [(4,"#000000",0,0)]
 ## 未被查看
 else:
 text what id "what" color "#fff" outlines [(4,"#000000",0,0)]
 ## 无文字阴影
 else:
 ## 已被查看(不包括当前文本)
 if renpy.is_seen(ever = True):
 text what id "what" color "#FFFF00"
 ## 未被查看
 else:
 text what id "what" color "#fff"
 ## 不允许已读文本变色
 else:
 ## 有文字阴影
 if text_shadow == True:
 text what id "what" color "#fff" outlines [(4,"#000000",0,0)]
 ## 无文字阴影
 else:
 text what id "what" color "#fff"
- 添加如下代码 - 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- vbox: 
 spacing 10
 hbox:
 spacing 10
 add "label.png"
 text "文本阴影" color "#4e021f"
 hbox:
 spacing 20
 ## 有文本阴影
 if text_shadow==True:
 imagebutton:
 idle "on.png"
 action SetVariable("text_shadow", True)
 imagebutton:
 idle "hover_off.png"
 hover "off.png"
 action SetVariable("text_shadow", False)
 ## 无文本阴影
 else:
 imagebutton:
 idle "hover_on.png"
 hover "on.png"
 action SetVariable("text_shadow", True)
 imagebutton:
 idle "off.png"
 action SetVariable("text_shadow", False)
快进设置
添加如下代码即可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
26vbox:
    spacing 10
    hbox:
        spacing 10
        add "label.png"
        text "快进未读文本" color "#4e021f" 
    hbox:
        spacing 20 
        ## 仅已读文本
        if preferences.skip_unseen == False:
            imagebutton:
                idle "only_read.png"
                action Preference("skip", "seen")
            imagebutton:
                idle "all_hover.png"
                hover "all.png"
                action Preference("skip", "all")
        ## 全部
        else:
            imagebutton:
                idle "only_read_hover.png"
                hover "only_read.png"
                action Preference("skip", "seen")
            imagebutton:
                idle "all.png"
                action Preference("skip", "all")
语音中断
添加如下代码即可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
26vbox:
    spacing 10
    hbox:
        spacing 10
        add "label.png"
        text "语音中断" color "#4e021f" 
    hbox:
        spacing 20 
        ## 语音中断
        if preferences.voice_sustain ==False:
            imagebutton:
                idle "on.png"
                action Preference("voice sustain", "disable") 
            imagebutton:
                idle "hover_off.png"
                hover "off.png"
                action Preference("voice sustain", "enable")
        ## 不中断
        else:
            imagebutton:
                idle "hover_on.png"
                hover "on.png"
                action Preference("voice sustain", "disable") 
            imagebutton:
                idle "off.png"
                action Preference("voice sustain", "enable")
文本显示速度预览
- 新建界面 - 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- screen textbox_preview(): 
 tag preview
 frame:
 pos (750,750)
 background None
 ## 默认模式
 if text_normal:
 if text_shadow:
 text "文本展示速度\n这是文本播放时的速度":
 xoffset 20
 yoffset 10
 color "#fff"
 outlines [(2, "#000",0, 0)]
 slow_cps normal_text_cps
 else:
 text "文本展示速度\n这是文本播放时的速度":
 xoffset 20
 yoffset 10
 color "#fff"
 slow_cps normal_text_cps
 ## 自动模式
 elif text_auto:
 if text_shadow:
 text "自动模式速度\n这是自动模式下的速度":
 xoffset 20
 yoffset 10
 color "#fff"
 outlines [(2, "#000",0, 0)]
 slow_cps afm_text_cps
 else:
 text "自动模式速度\n这是自动模式下的速度":
 xoffset 20
 yoffset 10
 color "#fff"
 slow_cps afm_text_cps
 ## 不显示
 else:
 text ""
- 轮换时间 - 1 
 2
 3- ## 轮换时间 
 define textbox_preview_repeat_time = 3.0
 default countdown_time = 0.0
- 启用设置 - message界面中- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16- default display_preview = True 
 if display_preview:
 timer 0.2:
 action Show("textbox_preview")
 timer 2.0:
 repeat True
 action [Hide('textbox_preview'),SetVariable("countdown_time",textbox_preview_repeat_time+1.0),Show("textbox_preview")]
 $ box_alpha = 1 - persistent.textbox_transparency
 frame:
 xpos 750
 ypos 750
 background Image(im.Alpha("text_bg.png", box_alpha), xalign=0.5, yalign=1.0)
- 添加如下代码 - 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- vbox: 
 spacing 10
 hbox:
 spacing 10
 add "label.png"
 text "文字显示速度预览" color "#4e021f"
 hbox:
 spacing 20
 ## 默认模式
 if text_normal:
 imagebutton:
 idle "normal.png"
 action [SetVariable("text_normal", True),SetVariable("text_auto", False),SetVariable("text_none", False)]
 imagebutton:
 idle "auto_hover.png"
 hover "auto.png"
 action [SetVariable("text_normal", False),SetVariable("text_auto", True),SetVariable("text_none", False)]
 imagebutton:
 idle "none_hover.png"
 hover "none.png"
 action [SetVariable("text_normal", False),SetVariable("text_auto", False),SetVariable("text_none",True )]
 ## 自动模式
 elif text_auto:
 imagebutton:
 idle "normal_hover.png"
 hover "normal.png"
 action [SetVariable("text_normal", True),SetVariable("text_auto", False),SetVariable("text_none", False)]
 imagebutton:
 idle "auto.png"
 action [SetVariable("text_normal", False),SetVariable("text_auto", True),SetVariable("text_none", False)]
 imagebutton:
 idle "none_hover.png"
 hover "none.png"
 action [SetVariable("text_normal", False),SetVariable("text_auto", False),SetVariable("text_none",True )]
 ## 不显示
 else:
 imagebutton:
 idle "normal_hover.png"
 hover "normal.png"
 action [SetVariable("text_normal", True),SetVariable("text_auto", False),SetVariable("text_none", False)]
 imagebutton:
 idle "auto_hover.png"
 hover "auto.png"
 action [SetVariable("text_normal", False),SetVariable("text_auto", True),SetVariable("text_none", False)]
 imagebutton:
 idle "none.png"
 action [SetVariable("text_normal", False),SetVariable("text_auto", False),SetVariable("text_none",True )]
 
- 日志& - bug排查- 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12- ## 文字显示速度预览 
 ## 代码来源 https://www.renpy.cn/forum.php?mod=viewthread&tid=1067
 ##
 ## 问题 存在 bug 前往其他界面时文字会卡到其他界面
 ## 产生bug的原因 timer 语句不间断的 hide 与 show 行为
 ## 解决方法 前往其他界面的 action 行为中添加 Hide("textbox_preview")
 ##
 ##
 ## 2024.11.15
 ## 问题 添加背景后,文字显示于背景下方
 ## 解决方法 将 use textbox_preview 删去,第一个 timer 语句改为0.2s后显示 textbox_preview
 ## 最终效果还算理想






