[RenPy] 纯文本查看 复制代码
class ProportionalScale(im.ImageBase):
'''Resizes a renpy image to f ...[/quote]
[mw_shl_code=renpy,true]init python:
## Images are declared using an auto-generating function
## 使用自动生成函数声明图像
class ProportionalScale(im.ImageBase):
'''Resizes a renpy image to fit into the specified width and height.
The aspect ratio of the image will be conserved.'''
#调整renpy图像的大小以适应指定的宽度和高度。
#长宽比的图像将被保存。
def __init__(self, imgname, maxwidth, maxheight, bilinear=True, **properties):
img = im.image(imgname)
super(ProportionalScale, self).__init__(img, maxwidth, maxheight, bilinear, **properties)
self.imgname = imgname
self.image = img
self.maxwidth = int(maxwidth)
self.maxheight = int(maxheight)
self.bilinear = bilinear
def load(self):
child = im.cache.get(self.image)
width, height = child.get_size()
ratio = min(self.maxwidth/float(width), self.maxheight/float(height))
width = ratio * width
height = ratio * height
if self.bilinear:
try:
renpy.display.render.blit_lock.acquire()
rv = renpy.display.scale.smoothscale(child, (width, height))
finally:
renpy.display.render.blit_lock.release()
else:
try:
renpy.display.render.blit_lock.acquire()
rv = renpy.display.pgrender.transform_scale(child, (newwidth, newheight))
finally:
renpy.display.render.blit_lock.release()
return rv
def predict_files(self):
return self.image.predict_files()
def declare(name, img, method=None, x=config.screen_width, y=config.screen_height, wide=False, gallery=True, unlock=False):
# img is the complete image path (from the game folder root) img是完整的图像路径(来自游戏文件夹根目录)
# if wide:
# y = int(y*0.8)
if method == "s": # Scale method (image will fit the exact target dimensions - not proportional) 比例尺法(图像将适合准确的目标尺寸-不成比例)
renpy.image(name, im.Scale(img, x, y))
elif method == "p": # ProportionalScale method (image will fit the target dimensions while preserving its aspect ratio) 比例比例尺法(图像拟合目标尺寸,同时保持长宽比)
renpy.image(name, ProportionalScale(img,x, y))
elif method == "f": # Factor Scale (image dimensions will change proportionately to float numbers x and y) 因子比例(图像尺寸将按比例变化为浮点数x和y)
# Foolproofing
if x == config.screen_width:
x = 1.0
if y == config.screen_height:
y = 1.0
renpy.image(name, im.FactorScale(img, x, y))
else: # No change to the original image 原图不变
renpy.image(name, img)
if unlock:
unlock_pic(name)
if gallery: # Returns image name if the image is to be stored in a gallery 如果要将图像存储在图库中,则返回图像名称
return name
else:
return None
# 声明多个
def declare_multiple(base_name, base_img, method=None, start=0, finish=0, series=[], x=config.screen_width, y=config.screen_height, wide=False, gallery=True, unlock=False, loud=False):
r = []
if not series:
series = range(start, finish+1)
for nb in series:
name, img = base_name % str(nb), base_img % str(nb)
r.append(declare(name, img, method=method, x=x, y=y, wide=wide, gallery=gallery, unlock=unlock))
return r # Python 2.7 won't allow me to unpack it. Darn. Python 2.7不允许我打开它。该死的。
#### IMAGE DECLARATIONS 图像的声明####
# These dicts are used for generating CG galleries. Pictures will be displayed in the order they appear. Pictures with 'gallery' set to False will not appear in galleries.
# Each key is a separate button
# 这些dicts用于生成CG图库。图片将按照它们出现的顺序显示。将“gallery”设置为False的图片将不会出现在画廊中。
# 每个键都是一个单独的按钮
game_image_dict = {
## BACKGROUNDS 背景图片##
"bg" : [
declare("bg 1", "images/bg/1.png", "p", wide=True),
declare("bg 2", "images/bg/2.png", "p", wide=True),
declare("bg 3", "images/bg/3.png", "p", wide=True),
declare("bg 4", "images/bg/4.png", "p", wide=True),
declare("bg 5", "images/bg/5.png", "p", wide=True),
declare("bg 6", "images/bg/6.png", "p", wide=True),
declare("bg 7", "images/bg/7.png", "p", wide=True),
declare("bg 8", "images/bg/8.png", "p", wide=True),
declare("bg 9", "images/bg/9.png", "p", wide=True),
declare("bg 10", "images/bg/10.png", "p", wide=True),
],
}
#添加图片(名字,图片路径,图片格式,图片数量,方法(s、p、f)),
#图片为1.png,2.png时img = "comic/cltg2/
#xxx1.png,xxx2png时img = "comic/cltg2/xxx"
#或者修改代码
def add_image(name,img_path,format,num,method):
img_list = []
a = 1
while a <= num:
name1 = name + "_" +str(a)
img1 = img_path + str(a) + format
method1 = method
b = declare(name1,img1,method1,wide=True)
img_list.append(b)
a += 1
return img_list
#添加cltg2到game_iamge_dict
game_image_dict["z1"] = add_image("z1","images/comic/z1/",".png",46,"p")
game_image_dict["z2"] = add_image("z2","images/comic/z2/",".png",59,"p")
game_image_dict["cltg1"] = add_image("cltg1","images/comic/cltg1/",".png",46,"p")
game_image_dict["cltg2"] = add_image("cltg2","images/comic/cltg2/",".png",41,"p")