Ren'py 系统设置界面修改(一)
本文修改全部位于screens.rpy
文件中
参考资料
特别感谢renpy官方交流群群友倾情相助
视频教程
查看源代码
打开screens.rpy
文件,你可以在708行看到如下代码
1 | ## 设置屏幕 ######################################################################## |
自定义
我们先确定系统设置界面的功能,这里我分为六部分
由于imagebutton
使用效果不佳,同时为给用户提示当前设置,我们使用if
语句对当前环境变量进行判断,不过有些未给出的变量需要我们自定义
全屏窗口切换
修改为如下代码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.fullscreen == False:
imagebutton:
idle "fullscreen.png"
hover "hover_fullscreen.png"
action Preference("display", "fullscreen")
imagebutton:
idle "hover_window.png"
action Preference("display", "window")
## 全屏状态下
else:
imagebutton:
idle "hover_fullscreen.png"
action Preference("display", "fullscreen")
imagebutton:
idle "window.png"
hover "hover_window.png"
action Preference("display", "window")
是否显示转场
修改为如下代码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.transitions == 2:
imagebutton:
idle "on.png"
action Preference("transitions", "all")
imagebutton:
idle "hover_off.png"
hover "off.png"
action Preference("transitions", "none")
## 忽略所有转场
if preferences.transitions == 0:
imagebutton:
idle "hover_on.png"
hover "on.png"
action Preference("transitions", "all")
imagebutton:
idle "off.png"
action Preference("transitions", "none")
忽略转场实际上忽略的是with
从句的效果
鼠标自动移动
添加如下代码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.mouse_move == True:
imagebutton:
idle "on.png"
action Preference("automatic move", "enable")
imagebutton:
idle "hover_off.png"
hover "off.png"
action Preference("automatic move", "disable")
## 禁止鼠标自动移动
else:
imagebutton:
idle "hover_on.png"
hover "on.png"
action Preference("automatic move", "enable")
imagebutton:
idle "off.png"
action Preference("automatic move", "disable")
来到screens.rpy
文件第1121行,你会看到如下代码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## 确认屏幕 ########################################################################
##
## 当 Ren'Py 需要询问用户有关确定或取消的问题时,会调用确认屏幕。
##
## https://doc.renpy.cn/zh-CN/screen_special.html#confirm
screen confirm(message, yes_action, no_action):
## 显示此屏幕时,确保其他屏幕无法输入。
modal True
zorder 200
style_prefix "confirm"
add "gui/overlay/confirm.png"
frame:
vbox:
xalign .5
yalign .5
spacing 45
label _(message):
style "confirm_prompt"
xalign 0.5
hbox:
xalign 0.5
spacing 150
textbutton _("确定") action yes_action
textbutton _("取消") action no_action
## 右键点击退出并答复 no(取消)。
key "game_menu" action no_action
style confirm_frame is gui_frame
style confirm_prompt is gui_prompt
style confirm_prompt_text is gui_prompt_text
style confirm_button is gui_medium_button
style confirm_button_text is gui_medium_button_text
style confirm_frame:
background Frame([ "gui/confirm_frame.png", "gui/frame.png"], gui.confirm_frame_borders, tile=gui.frame_tile)
padding gui.confirm_frame_borders.padding
xalign .5
yalign .5
style confirm_prompt_text:
textalign 0.5
layout "subtitle"
style confirm_button:
properties gui.button_properties("confirm_button")
style confirm_button_text:
properties gui.text_properties("confirm_button")
添加如下代码1
on "show" action MouseMove(850,570)
这里添加的是没有自定义的参数,可以等自定义确认界面后再做修改
已读文本变色
添加如下代码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 text_color_changeable==True:
imagebutton:
idle "on.png"
action SetVariable("text_color_changeable", True)
imagebutton:
idle "hover_off.png"
hover "off.png"
action SetVariable("text_color_changeable", False)
## 禁止已读文本变色
else:
imagebutton:
idle "hover_on.png"
hover "on.png"
action SetVariable("text_color_changeable", True)
imagebutton:
idle "off.png"
action SetVariable("text_color_changeable", False)
自定义变量1
2## 已读文本变色
default text_color_changeable=True
say
界面修改为如下代码1
2
3
4
5
6
7
8
9
10
11
12
13## 已读文本变色
if text_color_changeable==True:
## 已被查看(不包括当前文本)
if renpy.is_seen(ever = True):
text what id "what" color "#FFFF00"
## 未被查看
else:
text what id "what" color "#fff"
## 不允许已读文本变色
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
26vbox:
spacing 10
hbox:
spacing 10
add "label.png"
text "已选选项变色" color "#4e021f"
hbox:
spacing 20
## 允许已选选项变色
if choice_color_changeable==True:
imagebutton:
idle "on.png"
action SetVariable("choice_color_changeable", True)
imagebutton:
idle "hover_off.png"
hover "off.png"
action SetVariable("choice_color_changeable", False)
## 禁止已选选项变色
else:
imagebutton:
idle "hover_on.png"
hover "on.png"
action SetVariable("choice_color_changeable", True)
imagebutton:
idle "off.png"
action SetVariable("choice_color_changeable", False)
自定义变量1
2## 已选选项变色
default choice_color_changeable=True
来到screens.rpy
文件第195行,你会看到如下代码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## 选择屏幕 ########################################################################
##
## 此屏幕用于显示由 menu 语句生成的游戏内选项。参数 items 是一个对象列表,每个对
## 象都有字幕和动作字段。
##
## https://doc.renpy.cn/zh-CN/screen_special.html#choice
screen choice(items):
style_prefix "choice"
vbox:
for i in items:
textbutton i.caption action i.action
style choice_vbox is vbox
style choice_button is button
style choice_button_text is button_text
style choice_vbox:
xalign 0.5
ypos 405
yanchor 0.5
spacing gui.choice_spacing
style choice_button is default:
properties gui.button_properties("choice_button")
style choice_button_text is default:
properties gui.text_properties("choice_button")
添加如下代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19vbox:
for i in items:
## 允许已选选项变色
if choice_color_changeable==True:
## 已选选项
if i.chosen:
textbutton i.caption:
text_color "#FFFF00"
action i.action
## 未选选项
else:
textbutton i.caption:
text_color "#fff"
action i.action
## 禁止已选选项变色
else:
textbutton i.caption:
text_color "#fff"
action i.action
侧边栏存档读档
添加如下代码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
28vbox:
spacing 10
xpos 750
ypos 207
hbox:
spacing 10
add "label.png"
text "侧边存档读档栏显示" color "#4e021f"
hbox:
spacing 20
## 允许侧边栏存档读档显示
if side_save_load==True:
imagebutton:
idle "on.png"
action SetVariable("side_save_load", True)
imagebutton:
idle "hover_off.png"
hover "off.png"
action SetVariable("side_save_load", False)
## 禁止侧边栏存档读档显示
else:
imagebutton:
idle "hover_on.png"
hover "on.png"
action SetVariable("side_save_load", True)
imagebutton:
idle "off.png"
action SetVariable("side_save_load", False)
自定义变量1
2
3
4## 侧边栏存档读档
default side_save =True
default side_load =False
default side_save_load=True
新建界面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## 鼠标位于侧边栏显示侧边栏存档
init python:
config.overlay_screens.append("mini_save_show_area")
## 鼠标位置判定
screen mini_save_show_area():
zorder 250
mousearea:
area (1820, 0, 150, 1080)
hovered Show("mini_save_load")
unhovered Hide("mini_save_load")
## 侧边栏存档读档
screen mini_save_load():
zorder 200
if side_save_load==True:
if side_save ==True:
vbox:
xalign 1.0
xoffset 420
## 切换存档读档
imagebutton:
idle "load.png"
xoffset -50
hover "load_hover.png"
action [SetVariable("side_load", True),SetVariable("side_save", False)]
imagebutton:
idle "up.png"
hover "up_hover.png"
action FilePagePrevious(max=9,wrap=True,auto=False,quick=False)
# 存档槽总数
grid 1 gui.file_slot_cols*gui.file_slot_rows*9:
style_prefix "slot"
spacing -150
for i in range(gui.file_slot_cols * gui.file_slot_rows):
$ slot = i + 1
button:
action FileSave(slot)
#存档按钮背景图
background "mini_bg.png"
#存档按钮悬停图
hover_background "mini_bg_hover.png"
#存档编号
text FileSlotName(slot, gui.file_slot_cols * gui.file_slot_rows):
size 30
tooltip [FileSaveName(slot)]
hovered [SetVariable("ToolTipSlot", int(FileSlotName(slot, gui.file_slot_cols * gui.file_slot_rows)))]
unhovered [SetVariable("ToolTipSlot", None)]
imagebutton:
align (1.0,0.8)
yoffset -15
xoffset -5
idle "down.png"
hover "down_hover.png"
action FilePageNext(max=9,wrap=True,auto=False,quick=False)
if side_load ==True:
vbox:
xalign 1.0
xoffset 420
imagebutton:
xoffset -50
idle "save.png"
hover "save_hover.png"
action [SetVariable("side_load", False),SetVariable("side_save", True)]
imagebutton:
idle "up.png"
hover "up_hover.png"
action FilePagePrevious(max=9,wrap=True,auto=False,quick=False)
# 存档槽总数
grid 1 gui.file_slot_cols*gui.file_slot_rows*9:
style_prefix "slot"
spacing -150
for i in range(gui.file_slot_cols * gui.file_slot_rows):
$ slot = i + 1
button:
action FileLoad(slot)
#存档按钮背景图
background "mini_bg.png"
#存档按钮悬停图
hover_background "mini_bg_hover.png"
#存档编号
text FileSlotName(slot, gui.file_slot_cols * gui.file_slot_rows):
size 30
tooltip [FileSaveName(slot)]
hovered [SetVariable("ToolTipSlot", int(FileSlotName(slot, gui.file_slot_cols * gui.file_slot_rows)))]
unhovered [SetVariable("ToolTipSlot", None)]
imagebutton:
align (1.0,0.8)
yoffset -15
xoffset -5
idle "down.png"
hover "down_hover.png"
action FilePageNext(max=9,wrap=True,auto=False,quick=False)
$ tooltip = GetTooltip()
if tooltip:
for i in range(gui.file_slot_cols * gui.file_slot_rows):
$ slot = i + 1
frame:
xpos 1300
background "gui/button/slot_hover_background.png" at tip
add renpy.slot_screenshot(f"{1 + int((ToolTipSlot-1) / 9)}-{1 + (int(ToolTipSlot-1) % 9)}") xysize(231,130) xoffset 6 yoffset 72
frame:
background None
xysize(210,110)
xoffset 240
yoffset 65
text tooltip at tip size 25 color "#fff" outlines [(2,"#000000",0,0)]
这里的悬停提示可能会与底部菜单的悬停提示有所冲突,可修改为如下代码
1 | if tooltip and side_save_load ==False: |
必要部分
添加返回按钮,返回标题菜单和结束游戏按钮1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18hbox:
align (1.0,1.0)
xoffset -50
yoffset -50
spacing 20
if not main_menu:
imagebutton:
idle "return_title.png"
hover "return_title_hover.png"
action MainMenu()
imagebutton:
idle "end_game.png"
hover "end_game_hover.png"
action Quit()
imagebutton:
idle "return_game.png"
hover "return_game_hover.png"
action Return()
建议
新建一个rpy
文件,用于存放自定义变量
新建txt
文本文档,直接修改文件后缀即可