若无特殊说明,默认是在script.rpy文件中进行编写

参考资料

Ren’py官方文档相关链接:

  1. 画廊
  2. 常规解锁判断
  3. 周目解锁判断

视频教程

基础部分

进阶操作

前提条件

同音乐空间一样,想要实现画廊需要一些前提条件,详见下述代码

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

#画廊/CG鉴赏

#背景图片
image gallery_background:
"gallery_background.png"
size (1920, 1080)


#前提条件
init python:

g = Gallery()

g.button("bg")#类似于标签
g.image("bg01.png")#真正的图片
g.unlock_image("bg03.png")#差分

g.button("cg")
g.condition("persistent.unlock_1")#解锁限制
g.image("cg01.png")

#未解锁
g.button("unlock")


#更多图像请自行添加

# 图像切换使用的转场。
g.transition = dissolve

#如果选择翻页功能可以不加
default p = ui.adjustment()

界面编写

前提条件编写完成后,我们就可以着手编写画廊界面了,这里我提供了滚动条样式和翻页样式两种常用形式,请自行选择你想要那种效果

滚动条式界面(推荐)

以下代码适用于滚动条式界面,请选择好你想要的效果。

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

#鉴赏界面

screen gallery:

tag menu
add "gallery_background"

#可拖动条
vbar:
xysize (10, 680)
align (0.9, 0.5)
value YScrollValue("cg_list")

viewport id "cg_list":
mousewheel True #垂直滚动
xysize (1500, 680)
align (0.5, 0.5)
draggable True #鼠标拖动可滚动视口
yadjustment p #快速定位

vbox:
#间距
spacing 60

text "角色1" size 40

#网格布局
grid 4 3 id "bg":
spacing 60


#判断是否解锁
if renpy.seen_image("bg05"):
add g.make_button("bg", "smbg03.png")
else:
add g.make_button("unlock", "unknow.png")
if renpy.seen_image("bg03"):
add g.make_button("bg", "smbg03.png")
else:
add g.make_button("unlock", "unknow.png")
if renpy.seen_image("bg03"):
add g.make_button("bg", "smbg03.png")
else:
add g.make_button("unlock", "unknow.png")
if renpy.seen_image("bg03"):
add g.make_button("bg", "smbg03.png")
else:
add g.make_button("unlock", "unknow.png")

#由于全加判断语句导致代码太长,以下暂不添加判断
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")

add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")

text "角色2" size 40

grid 4 3 id "cg":
spacing 60
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")

add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")

add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")


#更多图像请自行添加

#快速定位选项
vbox:
#请自行根据图像高度和间距计算数值
textbutton "角色1" action Function(p.change,0)
textbutton "角色2" action Function(p.change,799)

#更多角色请自行添加


#返回按钮
textbutton "返回":
align (0.0, 0.98)
action Return()

翻页式界面

以下代码适用于翻页式界面,请选择好你想要的效果。

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
screen gallery(page=0):

tag menu
add "gallery_background"

viewport:
xysize (1500, 680)
align (0.5, 0.5)

vbox:
spacing 60
#页数判断
if (page == 0):
grid 3 1:
spacing 60
#由于全部添加会导致代码很长,以下只展示三张图片,请自行添加判断语句
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")


if (page == 1):
grid 3 1:
spacing 60
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")


if (page == 2):
grid 3 1:
spacing 60
add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")


#更多页面请自行添加

#底部按钮
hbox:
xalign 0.5 yalign 0.9
spacing 60
#请自行根据你的CG数量进行条件判断
if page < 2:
textbutton "下一页" action Show("gallery",page=(page+1))
else:
textbutton "下一页" action NullAction()

textbutton "1" action Show("gallery",page=0)
textbutton "2" action Show("gallery",page=1)
textbutton "3" action Show("gallery",page=2)

if page > 0:
textbutton "上一页" action Show("gallery",page=(page-1))
else:
textbutton "上一页" action NullAction()

#返回按钮
textbutton "返回":
align (0.0, 0.98)
action Return()

如果想添加快速定位功能,请进一步定义角色名_page,并修改为以下代码(只显示需要修改的代码)

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
#进入画廊默认界面
screen gallery(角色1_page=0)

viewport:
xysize (1500, 680)
align (0.5, 0.5)

vbox:
spacing 60
#页数判断
if (角色1_page == 0):
grid 3 1:
spacing 60
#由于全部添加会导致代码很长,以下只展示三张图片,请自行添加判断语句
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
vbox:
#请自行根据你的CG数量进行条件判断
textbutton "下一页" action Show("gallery",角色1_page=(角色1_page+1))
textbutton "上一页" action Show("gallery",角色1_page=(角色1_page-1))

if (角色1_page == 1):
grid 3 1:
spacing 60
add g.make_button("bg", "smbg03.png")
add g.make_button("bg", "smbg03.png")
add g.make_button("cg", "smcg01.png")
vbox:
#请自行根据你的CG数量进行条件判断
textbutton "下一页" action Show("gallery",角色1_page=(角色1_page+1))
textbutton "上一页" action Show("gallery",角色1_page=(角色1_page-1))


if (角色2_page=0):
grid 3 1:
spacing 60
add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")
add g.make_button("cg", "smcg01.png")
vbox:
#请自行根据你的CG数量进行条件判断
textbutton "下一页" action Show("gallery",角色2_page=(角色2_page+1))
textbutton "上一页" action Show("gallery",角色2_page=(角色2_page-1))

#更多页面请自行添加

#添加快速定位选项
vbox:
textbutton "角色1" action Show("gallery",角色1_page=0)
textbutton "角色2" action Show("gallery",角色2_page=0)

#更多角色请自行添加

周目解锁

添加如下代码:

1
2
3
4
init python:
if persistent.unlock_1 == None:
persistent.unlock_1 ==False
#更多条件限制请自行添加

在某一结局内添加如下代码:

1
2
3
#解锁条件1
$ persistent.unlock_1 = True
#更多周目请自行添加

添加入口

完成上述操作后,我们还需要添加主界面进入按钮,打开screens.rpy,找到screen navigation()(287行左右),在合适位置添加下面的代码

1
textbutton "画廊" action ShowMenu("gallery")

现在运行游戏,即可在主界面看到画廊进入按钮,请检查各功能是否可用。