renpy/doc/cookbook/New CG Gallery

From Ren'Py Visual Novel Engine

Jump to: navigation, search

Contents

New CG Gallery

This page is obsolete; see http://www.renpy.org/doc/html/rooms.html instead.

This is a rewritten CG gallery, supporting more sophisticated forms of unlocking. To use it, download new_gallery.rpy, and add it to your game directory. You'll then need to create a Gallery object, and call the show() method on it, after configuring the gallery and adding buttons. This is often done inside a single label, which can be added to config.main_menu.

This requires 6.6.0 or later (not in compat-mode) to run.

Example

init:
    # Position the navigation on the right side of the screen.
    $ style.gallery_nav_frame.xpos = 800 - 10
    $ style.gallery_nav_frame.xanchor = 1.0
    $ style.gallery_nav_frame.ypos = 12

    # Add the gallery to the main menu.
    $ config.main_menu.insert(2, ('Gallery', "gallery", "True"))

# The entry point to the gallery code.
label gallery:
    python hide:

        # Construct a new gallery object.
        g = Gallery()

        # The image used for locked buttons.
        g.locked_button = "gallery_locked.png"

        # The background of a locked image.
        g.locked_background = "gallery_lockedbg.jpg"

        # Frames added over unlocked buttons, in hover and idle states.
        g.hover_border = "gallery_hover.png"
        g.idle_border = "gallery_idle.png"

        # An images used as the background of the various gallery pages.
        g.background = "gallery_background.jpg"

        # Lay out the gallery images on the screen.
        # These settings lay images out 3 across and 4 down.
        # The upper left corner of the gird is at xpos 10, ypos 20.
        # They expect button images to be 155x112 in size.
        g.grid_layout((3, 4), (10, 12), (160, 124))

        # Show the background page.
        g.page("Backgrounds")

        # Our first button is a picture of the beach.
        g.button("thumb_beach.jpg")
        #
        # These show images, if they have been unlocked. The image name must
        # have been defined using an image statement.
        g.unlock_image("bg beach daytime")
        g.unlock_image("bg beach nighttime")
        #
        # This shows a displayable...
        g.display("beach_sketch.jpg")
        # ... if all prior images have been show.
        g.allprior()

        # A second set of images.
        g.button("thumb_lighthouse.jpg")
        g.unlock_image("bg lighthouse day")
        g.unlock_image("bg lighthouse night")
        g.display("lighthouse_sketch.jpg")
        g.allprior()



        # We can use g.page to introduce a second page.
        g.page("Characters")

        g.button("thumb_eileen.jpg")
        #
        # Note that we can give image and unlock image more than one image
        # at a time.
        g.unlock_image("bg lighthouse day", "eileen day happy")
        g.unlock_image("bg lighthouse day", "eileen day mad")



        # Another page, this one for concept art.
        g.page("Concept Art")

        g.button("thumb_concepts.jpg")
        #
        # We can apply conditions to buttons as well as to images.
        # The "condition" condition checks an arbitrary expression.
        g.condition("persistent.beat_game")
        #
        g.display("concept1.jpg")
        g.display("concept2.jpg")
        g.display("concept3.jpg")


        # Now, show the gallery.
        g.show()

    return

Documentation

Function: Gallery ():

Creates a new gallery object.

Method: Gallery.page (name, background=None):

Creates a new page, and adds it to the gallery. Buttons will be added to this page.

name - The name of the page.

background - If not None, a displayable giving the background of this page. If None, the background is taken from the background field of the gallery object.

Method: Gallery.button (idle, hover=None, locked=None, **properties):

Creates a button, adding it to the current page. Images and conditions will be added to this button. The button is unlocked if all conditions added to it are true, and at least one image associated with it is unlocked.

idle - A displayable that is used when this button is not focused.

hover - A displayable that is used when this button is focused.

If hover is specified, it is used. Otherwise, the idle picture is displayed, and the idle_border and hover_border are used to create a button on top of that image.

locked - A displayable which is displayed when this button is locked. If not specified, the displayable given by the locked_button field of the gallery object is used.

Additional keyword arguments are expected to be properties that are used to position the button. These take precedence over properties produced by the layout function of the gallery object.

Method: Gallery.image (*images):

This adds an image to be displayed by the gallery. It takes as an arguments one or more strings, giving image names to be displayed. (These image names should have been defined using the Ren'Py image statement.)

Conditions are added to this image. The image is unlocked if all all conditions are satisfied.


Method: Gallery.display (displayable):

This adds an image to be displayed by the gallery. It takes as an argument a displayable, which will be shown to the user.

Conditions are added to this image. The image is unlocked if all all conditions are satisfied.


Method: Gallery.show (page=0):

Shows the gallery to the user.

page the 0-based page number to show to the user. (So 0 is the first page, 1 is the second, and so on.)


Conditions

Conditions can be assigned to buttons or images in the gallery. Conditions are added to the last button or image defined. A button is unlocked if all of its conditions are satisfied and at least one of its images is unlocked. An image is unlocked if all of its conditions are satisfied.

Method: Gallery.unlock (*images):

This takes as its arguments one or more image names. It is satisfied if all named images have been shown to the user.

Method: Gallery.condition (expr):

This takes as an argument a python expression, as a string. The condition is satisfied if that expression evaluates to true.

Method: Gallery.allprior ():

Satisified if all prior images associated with the current button have been unlocked. This should only be used with images, not buttons.

Convenience

Method: Gallery.unlock_image (*images):

Equivalent to calling image and unlock with the same arguments. This defines an image that is shown only if all of the named images given as argumenst have been seen by the user.

Customization

Customization can be performed by setting fields on the gallery object.

layout - A function that takes two arguments, a 0-based button number and the number of buttons on the current page. It's expected to return a dictionary giving the placement properties for the numbered button.

The default layout function returns an empty dictionary, requiring buttons to be placed by hand.

Method: Gallery.grid_layout (gridsize, upperleft, offsets):

When called, replaces layout with a function that arranges buttons in a grid.

gridsize - A (columns, rows) pair, giving the number of columns and rows in the grid.

upperleft - A (x, y) pair, where x and y are the positions of the upper-left corder of the grid.

offsets - A (xoffset, yoffset) pair, where xoffset is the distance between (the upper-left corner of) buttons in the same row, and yoffset is the distance between buttons in the same column.

navigation - A function that is called with three arguments: The name of the current page, the 0-based number of the current page, and the total number of pages. This function should add ui elements to the screen that cause ui.interact to return either ("page", page_num), where page_num is the page that the user should next see, or ("return", 0), to cause Gallery.show to return.

The default navigation shows a frame containing buttons for each page, and one "Return" button.

locked_button - A displayable that is shown when a button is locked.

locked_image - A function that is called with two arguments: A 0-based image number, and the number of images in the current button. It is responsible for indicating to the user that the current image is locked. It should not cause an interaction to occur.

The default locked_image shows locked_background to the user, along with the words "Image number of number in page is locked.", where number is the 1-based number of the image.

locked_background - Used by the default locked_image, a background image that is displayed by a locked image.

idle_border - A displayable that is shown by an unfocused button when no hover parameter is given for that button.

hover_border - A displayable that is shown by a focused button when no hover parameter is given for that button.

transition - A transition that is used when showing gallery pages and gallery images.

Styles

The following styles are used by the default navigation function.

style.gallery_nav_frame (inherits from style.frame)
The style of the frame holding the gallery navigation. Use this to customize the look of the frame, and also to move the frame around on the screen.
style.gallery_nav_vbox (inherits from style.vbox)
The style of the vbox holding the gallery navigation functions.
style.gallery_nav_button (inherits from style.button)
The style of a gallery navigation button.
style.gallery_nav_button_text (inherits from style.button_text)
The style of the text of a gallery navigation button.
Personal tools