Пример инвентаря (кликабельный)

Материал из Ren'Py Wiki
Перейти к навигации Перейти к поиску

init -2 python:
    items = []
    # здесь может быть любой обработчик нажатия кнопки из списка
    def SelectItem(index):
        # сюда ставить код обработчика на питоне
        return index
    # получить имя файла
    def GetFN(index=0):
        global items
        if (index >= 0) and (index < len(items)):
            fn, hn = items[index]
            return "inventory/" + fn + ".png"
        else :
            return ""
    # получить подсказку
    def GetHint(index=0):
        global items
        if (index >= 0) and (index < len(items)):
            fn, hn = items[index]
            return hn
        else :
            return ""
 
init:
    image bg world1 = "bg_world1.png"
    image mario = "mario.png"
    $ invent = False
 
screen inventory:
    zorder 111
    default tt = Tooltip(" ")
    frame:
        xalign 1.0
        background Solid("#0000")
        xmaximum 130
        ymaximum 450
        xfill True
        vbox :
            imagebutton auto "inventory/bag_%s.png" action SetVariable("invent", not invent)
            if invent:
                text tt.value
                hbox:
                    viewport id "box":
                        yinitial 9999
                        xmaximum 0.9
                        mousewheel True
                        draggable True
                        vbox :
                            for i in range(0, len(items)):
                                imagebutton :
                                    idle Image(GetFN(i))
                                    hover Image(GetFN(i))
                                    hovered tt.Action(GetHint(i))
                                    action SelectItem(i)
                    vbar yfill True value YScrollValue("box")
 
label start:
    scene black
    $ items = [("coin", "Денюжка"), ("flower", "Цветочег"), ("goomba", "Гумба")]
    show screen inventory
    scene bg world1
    show mario
    with dissolve
    "Нажми на чемоданчик. Затем жми на экран."
    $ items.extend([("mushroom", "Грыбок"), ("plant", "Сорняк"), ("star", "Звёздочка")])
    "В инвентарь добавлено три предмета."
    return

На главную страницу Книга рецептов Энциклопедии Ren'Py Renpy для чайников Вернуться к началу статьи