Little used features screen Load/Save

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Little used features screen Load/Save

#1 Post by Andredron »

1) Adding a flashing New sign to the loading screen
FileNewest https://www.renpy.org/doc/html/screen_a ... FileNewest

Code: Select all


transform transform_save_label_new:
    pause 0.5
    linear .5 alpha 0.3
    pause 0.5
    linear .5 alpha 1.0
    repeat
    
###Screen

for i in range(1):
    $ slot = i + 1                                                                                   
    if FileNewest(slot):
          button:                         
                text "New" at transform_save_label_new                                   
Or:

Code: Select all

screen load_save_slot:
    
    $ file_text = "% 2s. %s\n%s" % (
                        FileSlotName(number, 3),
                        FileTime(number, empty=_("     Empty Slot")),
                        FileSaveName(number))

    add FileScreenshot(number) xpos 26 ypos 37
    
    if FileNewest(number):
        add "assets/images/menu/icon_new.png" xpos 26 ypos 37
    
    text file_text xpos 51 ypos 302 size 24 color "#940707" font "assets/fonts/lithos_pro.ttf"
    
    #key "save_delete" action FileDelete(number)
https://www.renpy.cn/forum.php?mod=view ... a=page%3D4

https://renpymemo.hateblo.jp/entry/2023/12/31/213844


2) Enter a name for the save

viewtopic.php?f=8&t=47676&p=521818&hili ... me#p521818
Or:
viewtopic.php?p=295961#p295961

https://renpymemo.hateblo.jp/entry/2024/01/20/005654

3)Screenshot of saving your image (Root)

viewtopic.php?f=8&t=56914&p=519355&hili ... me#p519355


4)Additional information to save add

https://patreon.renpy.org/save-metadata ... n-metadata

viewtopic.php?f=8&t=42718


5) A crutch to solve problems with breaking saves
Autor - Alexey Butorin
https://vk.com/@miosion_pub-reshenie-po ... i-na-renpy

We write the code to send the player to a specific "label".

Code: Select all

python:
    if persistent.jump_to:
        j = persistent.jump_to
        persistent.jump_to = False
        renpy.jump(j)
In options.rpy or where it is convenient, we write the following code

Recording data for memories

Code: Select all

init -998 python:
    def _on_save(json):
        json['game_version'] = config.version
        json['jump_chapter'] = current_chapter
    config.save_json_callbacks = [_on_save]
Create a screen similar to the "confirm" screen:

Image

. At the beginning of script.rpy or wherever it is convenient, we write the following code:

Code: Select all

init:
    $ current_chapter = "start"
#===============================================================================================================
init python:
    from __future__ import absolute_import
    from __future__ import division
    from __future__ import print_function
    from __future__ import unicode_literals

    def save_is_compatible(name, page=None):
        
        save_json = FileJson(name=name, page=page)
        
        if save_json is None:
            return None
        else:
            save_version = save_json.get('game_version', '')
            return save_version

    def what_chapter(name, page=None):
        save_json = FileJson(name=name, page=page)
        
        if save_json is None:
            return "start"
        else:
            labels = renpy.get_all_labels()
            to_chapter = save_json.get('jump_chapter', '')
            if to_chapter in labels:
                return to_chapter
            else:
                return "start"
In "file_slots" we write the following action instead of the standard one:


https://sun9-52.userapi.com/impg/rkgaZp ... type=album

Voila! Now, creating a new assembly and updating it, we change the version of the game and when the player tries to load the save, he will receive such a notification, of course, he can be modified, you can set a different action or simply delete the save file, but I think that this is a little wrong.


Link to finished project
https://disk.yandex.ru/d/RpdqgJrqDlQLDg

6) How to round the edges of a save image

Code: Select all

add AlphaMask (FileScreenshot(slot), "alpha.png") xalign 0.5
where alpha.png is the mask to clip on

7)Time spent in the save game
viewtopic.php?t=40407

8)Button Delete
viewtopic.php?f=8&t=59207
viewtopic.php?p=487545#p487545

button not to be displayed on empty slots - viewtopic.php?f=8&t=67276

9) Confirm menu in "Load" of Title menu
confirm argument in FileSave and FileLoad prompt for confirmation before loading the file only if not at the main menu, and only before overwriting existing save file.

Code: Select all

# action for load file asking prompt even if at the main menu
... Confirm("Loading will lose unsaved progress.\n Are you sure you want to do this",FileLoad(slot, confirm = False)))
# action for save file asking prompt even if slot is empty
... Confirm("Are you sure you want to save on this slot?\n This action will overwrite previous save if it existed?",FileSave(slot, confirm = False))

сonfirm = False to avoid prompting user for confirmation twice in case of overwriting file or loading file if not at main menu.

10) To prevent values from being reset after each boot
https://www.renpy.org/doc/html/save_loa ... after-load

Code: Select all

screen edit_value:
    hbox:
        text "[value]"
        textbutton "+" action SetVariable("value", value + 1)
        textbutton "-" action SetVariable("value", value - 1)
        textbutton "+" action Return(True)

label start:
    $ value = 0
    $ renpy.retain_after_load()
    call screen edit_value
11)Loading screen loads last save page
viewtopic.php?p=549947#p549947

12) Add a sound effect when you save a file
Go to the file_slots screen found in screens.rpy, then in the button with action FileAction, you can go add

Code: Select all

button:
  action FileAction(slot)
  activate_sound "sound.mp3"

13)So that the current song fades out while loading
viewtopic.php?p=529474#p529474

Or add a label:

Code: Select all

label after_load:
    stop music fadeout 2.0
    return
14)The load button is not active until there is at least 1 save
viewtopic.php?p=505283#p505283

Before the test, don't forget to clear your renpy data
Windows - C:\Documents and Settings\Admin\Application Data\RenPy

15)Disable question about overwrite save
viewtopic.php?p=492279#p492279

16)The correct way when hover a notification to implement (not Uncle Mugen's example)
viewtopic.php?p=489643#p489643

17)Set up "cloud notifications"
viewtopic.php?p=486646#p486646

18)1 single screenshot for save list
viewtopic.php?f=51&t=25981

19) "New game" button to be replaced with a "Continue" button when there is a save game to load, and it would load the most recent save file
viewtopic.php?f=8&t=65758

20) How to add total time played to save/load screen
viewtopic.php?f=8&t=40407

21) players could lock a game state
viewtopic.php?t=33375

22) loading screen where the player is reminded of what happened at a previous point in the plot
viewtopic.php?t=68121&sid=82960992cec5b ... c1ee04411d

23) When downloading, automatically go to label.
viewtopic.php?t=42438

24) FormScreenshot

Code: Select all

### In any ".rpy" file, declare a class:
init python:

    class FormScreenshot(renpy.Displayable):

        __author__ = "Vladya"

        def __init__(self, name, empty=None, page=None, form=None):

            super(FormScreenshot, self).__init__()
            self.screenshot_pic = FileScreenshot(name, empty, page)
            self.form = renpy.easy.displayable_or_none(form)

        def render(self, width, height, st, at):

            scrSurf = renpy.render(self.screenshot_pic, width, height, st, at)
            xs, ys = map(int, scrSurf.get_size())
            renderObject = renpy.Render(xs, ys)

            if not self.form:
                renderObject.blit(scrSurf, (0, 0))
                return renderObject

            fx, fy = renpy.render(self.form, width, height, st, at).get_size()
            xzoom = float(xs) / fx
            yzoom = float(ys) / fy

            _form = Transform(self.form, zoom=min(xzoom, yzoom))
            _form_screenshot = AlphaMask(
                self.screenshot_pic,
                Transform(_form, zoom=.95)
            )

            for d in (_form, _form_screenshot):
                d_surf = renpy.render(d, width, height, st, at)
                xsize, ysize = d_surf.get_size()
                xpos = (xs * .5) - (xsize * .5)
                ypos = (ys * .5) - (ysize * .5)
                xpos, ypos = map(int, (xpos, ypos))
                renderObject.blit(d_surf, (xpos, ypos))

            renpy.redraw(self, 0)
            return renderObject

### Next, go to screen.rpy and there in the "file_picker" screenshot we look for a line like:
### add FileScreenshot(i)
### Change it to:
###  add FormScreenshot(i, form="form.png")
### Where "form.png" is a picture of the shape we need to convert the screenshot.
25) add alfamask

Code: Select all

action FileAction(slot)
                        vbox:
                            $ store.save_name = persistent.name
                            #add FileScreenshot(slot) xalign 0.5  # original code
                            add AlphaMask(FileScreenshot(slot), mask=Frame("gui/mask_image.png", 0, 0, 0, 0, tile=False))  #changes I made for masking the image (it just makes rounded corners)
                            text FileTime(slot, format=_("{#file_time}%A, %B %d %Y, %H:%M"), empty=_("empty slot")):
                                style "slot_time_text"
You may be interested in the following materials:

Post Reply

Who is online

Users browsing this forum: No registered users