基于楼主草稿,做了一点修改:
[RenPy] 纯文本查看 复制代码 init python:
##预定义角色信息
##角色1
name_1 = "name1"
intro_1 = "introduction1"
loveness_1 = 0
sprite_1 = "sprite_1.png"
##角色2
name_2 = "name2"
intro_2 = "introduction2"
loveness_2 = 0
sprite_2 = "sprite_2.png"
##角色3
name_3 = "name3"
intro_3 = "introduction3"
loveness_3 = 0
sprite_3 = "sprite_3.png"
##好感度条图片
loveness_bar_l = "gui/bar/love.png"
loveness_bar_r = "gui/bar/loveb.png"
loveness_bar_size = (425,109)
##关闭按钮图片
close_button = "gui/button/close_%s.png"
class CharacterStatus:
def __init__(self, name, intro, loveness, sprite, **kwargs):
self.name = name
self.intro = intro
self.loveness = loveness
self.sprite = sprite
def improve(self, n):
self.loveness = min(100, self.loveness+n)
def deteriorate(self, n):
self.loveness = max(0, self.loveness-n)
#新建角色状态对象
chara_1 = CharacterStatus(name_1, intro_1, loveness_1, sprite_1)
chara_2 = CharacterStatus(name_2, intro_2, loveness_2, sprite_2)
chara_3 = CharacterStatus(name_3, intro_3, loveness_3, sprite_3)
chara_list = [chara_1, chara_2, chara_3]
character_counter = len(chara_list)
character_index = 0
image bg grey = "#505050"
screen chara_status:
tag menu
add "bg grey"
hbox:
xalign 0.3
spacing 30
add chara_list[character_index].sprite
vbox:
xalign 0.65
yalign 0.5
spacing 20
text chara_list[character_index].name xalign 0.5 yalign 0.5
text chara_list[character_index].intro xalign 0.5 yalign 0.5
## str(chara_list[character_index].loveness) xalign 0.5 yalign 0.5
bar:
value chara_list[character_index].loveness
range 100
left_bar loveness_bar_l
right_bar loveness_bar_r
xysize loveness_bar_size
textbutton "<" xalign 0.1 yalign 0.5 action SetVariable("character_index", (character_index+character_counter-1)%character_counter)
textbutton ">" xalign 0.9 yalign 0.5 action SetVariable("character_index", (character_index+1)%character_counter)
imagebutton:
auto close_button
action Return()
xalign 0.9
yalign 0.1
解释一下几个要点:
1. 定义一个角色状态类(CharacterStatus)的好处是扩展性好,后续可以加很多东西进去。
2. 脚本中定义可视组件的顺序是实际渲染的顺序,先定义的底层。所以关闭和翻页按钮要写在角色的立绘和文本信息后面,防止按钮被图片盖住。
3. 角色信息的样式和布局还是需要再改改才行……
另外,用vpgrid大概可以把所有角色信息都展开在一个组件中,翻页按钮实现平移的动效……等我想想再补充一个……
|