RenPy中文空间

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1628|回复: 4

[已解决] Grid overfull的难题

[复制链接]
发表于 2021-8-23 18:31:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
做了一个背包物品框。想设置多个页面。就是可以左右翻页,一个页面放五六十个物品还放不下,要放到第二页第三页。类似有些多个页面的CG画廊或存档的。

[RenPy] 纯文本查看 复制代码
style inventory_label:
    xalign 0.2

default inventory = []              #两个初始定义为下面的物品栏所需
default selected_item = None

image square_small:
    "inven/square.png"
    size (40,40)

style slot:
    background Frame("square_small", 0, 0)
    minimum (60,60)
    maximum (60,60)                                #整体框架大小

init python:
    items_rows = 10
    items_cols = 10
    items_page = 0

screen 物品(u):
    style_prefix "inventory"
    add "images/icon/装备框_id.png"
    modal True

    frame background None xpos 210:
        grid items_rows items_cols:
            ypos 58
            spacing -22
            $ i = 0
            $ next_items_page = items_page + 1
            $ previous_items_page = items_page - 1
            $ items_cells = items_rows * items_cols
            if next_items_page >= int(len(inventory)/items_cells):
                $ next_items_page = 5                                #enter (last page number -1) here
            if previous_items_page < 1:
                $ previous_items_page = 0
            for item in inventory:
                if isinstance(item, KeyItem):
                    add "bg Keyitem"
                imagebutton idle item.img action SetVariable("selected_item", item)

            for j in range(i, (items_page+1)*items_cells):                    #we need this to fully fill the grid
                frame:
                    style "slot"

    if len(inventory)>items_cells:
        imagebutton xpos 1 ypos 319:
            auto "gui/Partners_menu_previous_%s.png"
            focus_mask True
            action [SetVariable('items_page', previous_items_page), ShowTransient("队友")]
            hovered [Play ("test_one", "audio/ui/click.mp3")]

        imagebutton xpos 1240 ypos 319:
            auto "gui/Partners_menu_next_%s.png"
            focus_mask True
            action [SetVariable('items_page', next_items_page), ShowTransient("队友")]
            hovered [Play ("test_one", "audio/ui/click.mp3")]



不过执行的是老是显示Grid overfull。查了一个,是items_rows 和items_cols 值的问题。有大神知道这个值的设定需要服从什么规律吗?
谢谢!
发表于 2021-8-24 09:07:34 | 显示全部楼层
本帖最后由 被诅咒的章鱼 于 2021-8-24 09:09 编辑

规则的话,grid中的元素数量,必须正好等于行数乘列数的积。
楼主遇到的问题,其实是用别人的代码出现的吧……

grid定义中的两个for循环,被设计用来填满整个网格(总共100格)。
第1个for循环查看inventory列表,并填入里面的元素。在初始状态,inventory是空的,不填任何元素。
第2个for循环本来是用来填空格子的。正确的数值应该直接写 items_cells

此外,这段代码中有很多其他槽点,比如:
各种随意使用的中文字符;
局部变量作用域混乱;
按钮的hovered播放音频不用hover_sound……等……
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-26 11:06:08 | 显示全部楼层
谢谢版主。代码的确是参考了一个游戏里的进行修改。不过版主提到的方法解决不了问题啊
回复 支持 反对

使用道具 举报

发表于 2021-8-27 09:02:58 | 显示全部楼层
把参考游戏的代码发出来看看。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-8-28 21:30:41 | 显示全部楼层
谢谢楼主提醒。找了原来的参考代码,还真找到了遗漏的地方。这是游戏《呃啊!Capybara》里的代码,如下

[RenPy] 纯文本查看 复制代码
# Item Gallery

init python:

    # Galleries settings - start

    # List the item gallery images here:
    gallery_item_items = ["clock", "shopsign", "sealstamp01", "cake", "invitation", "memento", "flower",
                         "vial",
                         "coffee", "bullet01", "blueprints", "cal", "mask", "pudding",
                         "pendant01", "pendant02", "mill", "pendant03", "pendant04", "sealstamp02",
                         "rifle", "dinner", "bullet02", "goldfish", "gown", "food", "memento02",
                         "souffle", "veil", "bouquet",
                         "bletter", "flowertrap", "dlletter", "glasses", "cape", "dportrait", "strawberrym", "sudoku", "lemontea", "bullet03", "pendant05", "dress",
                         "xbox", "wpump", "eaglehuntress", "mcookie", "weagle", "apple", "teatin", "manonsucre", "takeout", "anotebook", "venerec", "anurn",]

    # How many rows and columns in the gallery screens?
    gal_item_rows = 10
    gal_item_cols = 10

    # Thumbnail size in pixels:
    thumbnail_x1 = 60
    thumbnail_y1 = 60

    # Galleries settings - end

    gal_item_cells = gal_item_rows * gal_item_cols
    g_item = Gallery()
    for gal_item in gallery_item_items:
        g_item.button(gal_item + " butt")
        g_item.image(LiveComposite((800, 600), (0, 0), "ui/showitem_background.jpg", (250, 165), ImageReference(gal_item)))
        g_item.unlock(gal_item)
    g_item.transition = fade
    item_page = 0

init +1 python:
    # Here we create the thumbnails.
    for gal_item in gallery_item_items:
        renpy.image (gal_item + " butt", im.Scale(ImageReference(gal_item), thumbnail_x1, thumbnail_y1))
        renpy.image (gal_item + " butt dis", im.Grayscale(ImageReference(gal_item + " butt")))

screen item_gallery:
    tag menu

    add "ui/item_gallery_ground.jpg"
    imagebutton auto "ui/game_menu_return_%s.png" xpos 420 ypos 516 focus_mask True action ShowMenu("extra") hovered [Play ("test_two", "sd/click.wav")]
    imagebutton auto "ui/game_menu_quit_%s.png" xpos 610 ypos 515 focus_mask True action Quit() hovered [ Play ("test_three", "sd/click.wav") ]
    imagebutton auto "ui/game_menu_main_%s.png" xpos 45 ypos 525 focus_mask True action Return() hovered [ Play ("test_one", "sd/click.wav")]


    frame background None xpos 143:
        grid gal_item_rows gal_item_cols:
            ypos 50
            $ i = 0
            $ next_item_page = item_page + 1
            $ previous_item_page = item_page - 1
            if next_item_page >= int(len(gallery_item_items)/gal_item_cells):
                $ next_item_page = 1 #enter (last page number -1) here
            if previous_item_page < 1:
                $ previous_item_page = 0

            for gal_item in gallery_item_items:
                $ i += 1
                if i <= (item_page+1)*gal_item_cells and i>item_page*gal_item_cells:
                    add g_item.make_button(gal_item + " butt", gal_item + " butt", gal_item + " butt dis",
                    xalign=0.5, yalign=0.5, idle_border=None, background=None, bottom_margin=15)
            for j in range(i, (item_page+1)*gal_item_cells): #we need this to fully fill the grid
                null

    if len(gallery_item_items)>gal_item_cells:
        imagebutton auto "ui/cg_menu_previous_%s.png" xpos 28 ypos 200 focus_mask True action [SetVariable('item_page', previous_item_page), ShowMenu("item_gallery")] hovered [Play ("test_one", "sd/click.wav")]
        imagebutton auto "ui/cg_menu_next_%s.png" xpos 727 ypos 200 focus_mask True action [SetVariable('item_page', next_item_page), ShowMenu("item_gallery")] hovered [Play ("test_one", "sd/click.wav")]


回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|RenPy中文空间 ( 苏ICP备17067825号 | 苏公网安备 32092302000068号 )

GMT+8, 2022-6-28 02:11 , Processed in 0.027889 second(s), 12 queries , File On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表