Ren'py 历史记录界面修改
本文主要修改文件为screens.rpy
文件
更新日志
1 | # 滚轮下滑关闭历史记录 |
参考代码如下
1 | if len(_history_list)<3: |
参考资料
视频教程
查看源代码
打开screens.rpy
文件,你可以在866行看到如下代码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## 历史屏幕 ########################################################################
##
## 这是一个向用户显示对话历史的屏幕。虽然此屏幕没有什么特别之处,但它必须访问储
## 存在 _history_list 中的对话历史记录。
##
## https://doc.renpy.cn/zh-CN/history.html
screen history():
tag menu
## 避免预缓存此屏幕,因为它可能非常大。
predict False
use game_menu(_("历史"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0, spacing=gui.history_spacing):
style_prefix "history"
## 记录列表
for h in _history_list:
window:
## 此代码可确保如果 history_height 为 None 时仍可正常显示条目。
has fixed:
yfit True
## 如果有名字
if h.who:
label h.who:
style "history_name"
substitute False
## 从 Character 对象中获取叙述角色的文字颜色,如果设置了
## 的话。
if "color" in h.who_args:
text_color h.who_args["color"]
## 对话
$ what = renpy.filter_text_tags(h.what, allow=gui.history_allow_tags)
text what:
substitute False
if not _history_list:
label _("尚无对话历史记录。")
## 此代码决定了允许在历史记录屏幕上显示哪些标签。
define gui.history_allow_tags = { "alt", "noalt", "rt", "rb", "art" }
style history_window is empty
style history_name is gui_label
style history_name_text is gui_label_text
style history_text is gui_text
style history_label is gui_label
style history_label_text is gui_label_text
style history_window:
xfill True
ysize gui.history_height
style history_name:
xpos gui.history_name_xpos
xanchor gui.history_name_xalign
ypos gui.history_name_ypos
xsize gui.history_name_width
style history_name_text:
min_width gui.history_name_width
textalign gui.history_name_xalign
style history_text:
xpos gui.history_text_xpos
ypos gui.history_text_ypos
xanchor gui.history_text_xalign
xsize gui.history_text_width
min_width gui.history_text_width
textalign gui.history_text_xalign
layout ("subtitle" if gui.history_text_xalign else "tex")
style history_label:
xfill True
style history_label_text:
xalign 0.5
自定义
默认界面总体而言还是比较简单单调的,我们稍作修改,示例代码如下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## 历史屏幕 ########################################################################
##
## 这是一个向用户显示对话历史的屏幕。虽然此屏幕没有什么特别之处,但它必须访问储
## 存在 _history_list 中的对话历史记录。
##
## https://www.renpy.cn/doc/history.html
screen history():
tag menu
## 避免预缓存此屏幕,因为它可能非常大。
predict False
#添加历史记录背景图
add "history_bg.png"
frame:
style"history_frame_style"
frame:
style"history_window_frame_style"
vpgrid id "history_list":
#行数
cols 1
#视口初始垂直偏移量
yinitial 1.0
mousewheel True
draggable True
pagekeys True
side_xfill True
for h in _history_list:
window:
# 背景默认为对话框
background None
# 高度
ysize 200
if h.who:
# 角色名字
label h.who:
xoffset 100
substitute False
text_color "#fff"
text_outlines [(3, "#000000", 0, 0)]
# 历史记录
$ what = renpy.filter_text_tags(h.what, allow=gui.history_allow_tags)
text what:
color "#ffffff"
outlines [(3, "#000000", 0, 0)]
xoffset 250
if not _history_list:
label _("尚无对话历史记录。")
# 滚动条
vbar:
xsize 44
ysize 570
align (0.95, 0.5)
base_bar "history_bar.png"
thumb Frame("thumb.png",xysize=(44,44))
thumb_offset 14
value YScrollValue("history_list")
# 返回按钮
imagebutton:
align (0.95, 0.9)
idle "return.png"
hover "return_hover.png"
action Return()
#新添加样式
style history_frame_style:
left_padding 200 #左边距
right_padding 0 #右边距
style history_window_frame_style:
top_padding 185 #顶部边距
bottom_padding 150 #底部边距
xfill True
## 此代码决定了允许在历史记录屏幕上显示哪些标签。
define gui.history_allow_tags = { "alt", "noalt", "rt", "rb", "art" }
style history_window is empty
style history_name is gui_label
style history_name_text is gui_label_text
style history_text is gui_text
style history_label is gui_label
style history_label_text is gui_label_text
style history_window:
xfill True
ysize gui.history_height
style history_name:
xpos gui.history_name_xpos
xanchor gui.history_name_xalign
ypos gui.history_name_ypos
xsize gui.history_name_width
style history_name_text:
min_width gui.history_name_width
textalign gui.history_name_xalign
style history_text:
xpos gui.history_text_xpos
ypos gui.history_text_ypos
xanchor gui.history_text_xalign
xsize gui.history_text_width
min_width gui.history_text_width
textalign gui.history_text_xalign
layout ("subtitle" if gui.history_text_xalign else "tex")
style history_label:
xfill True
style history_label_text:
xalign 0.5
优化
到这里比较基础的部分就完成了,接下来我们添加一些功能选项
历史记录跳转
添加如下代码
1 | # 跳转按钮 |
添加角色头像
添加如下代码
1 | # 添加头像,如果你在对话框中的头像合适的话,可以直接写为side [h.image_tag] |
角色语音重播
添加如下代码
1 | #语音重播 |
滚轮上滑打开历史记录
say
界面添加如下代码1
key "mousedown_4" action ShowMenu('history')
滚轮下滑返回游戏
添加如下代码
1 | # 滚轮下滑关闭历史记录 |
vpgrid
内1
yadjustment history_bar_pos
直达顶部底部
添加如下代码1
2
3
4
5
6
7
8
9
10
11
12
13# 返回顶部
imagebutton:
idle "top.png"
hover "top_hover.png"
action Function(history_bar_pos.change,0)
# 返回底部
imagebutton:
idle "buttom.png"
hover "buttom_hover.png"
insensitive "top.png"
# 历史记录最大块数乘高度
action Function(history_bar_pos.change,config.history_length*200)
GUI
在gui.rpy
文件中有一些有关历史记录界面的设置,你可以在317行左右看到
我修改后的代码如下1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24## 历史 ##########################################################################
##
## 历史记录屏幕显示玩家已经阅读过的对话。
## Ren'Py 将保留的对话历史块数。
define config.history_length = 250
## 历史屏幕条目的高度,或设置为 None 以使高度变量自适应。
define gui.history_height = 210
## Additional space to add between history screen entries.
define gui.history_spacing = 0
## 所指定叙述角色的标签的坐标、宽度和对齐方式。
define gui.history_name_xpos = 233
define gui.history_name_ypos = 0
define gui.history_name_width = 233
define gui.history_name_xalign = 1.0
## 对话文本的坐标、宽度和对齐方式。
define gui.history_text_xpos = 255
define gui.history_text_ypos = 3
define gui.history_text_width = 1110
define gui.history_text_xalign = 0.0