Bind coordinates to screenshot thumbnail

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 535
Joined: Thu Dec 28, 2017 2:37 pm
Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
Location: Russia
Contact:

Bind coordinates to screenshot thumbnail

#1 Post by Andredron » Sat Sep 03, 2022 7:53 pm

Good afternoon, I have a problem with the file_slots screen

I can't reproduce buttons with the save date, and so that when I hover over the save button, the screenshot thumbnail changes.

Help me figure out what needs to be done

Code: Select all

[s]screen file_slots(title):
    add "save_mm"
    add "save_mm2"
    fixed:
        grid 1 10:
            xfill True
            transpose True
            spacing 10
            for i in range(1, 11):
                button:
                    action FileAction(i)
                    add FileScreenshot(i) xalign 0.69 yalign 0.36
                    text FileTime(i, format=_("{#file_time}%A, %d %B %Y, %H:%M"), empty=_("Пустой слот")):
                        xalign 0.13 yalign 0.2
                        style "slot_time_text"
                    text FileSaveName(i):
                        xalign 0.13 yalign 0.2
                        style "slot_name_text"
                    
In file gui.rpy, We can resize the screenshot thumbnail there and button sizes, with number of columns and rows

Code: Select all

## Save slot button.
define gui.slot_button_width = 173
define gui.slot_button_height = 129
define gui.slot_button_borders = Borders(7, 7, 7, 7)
define gui.slot_button_text_size = 9
define gui.slot_button_text_xalign = 0.5
define gui.slot_button_text_idle_color = gui.idle_small_color
define gui.slot_button_text_selected_idle_color = gui.selected_color
define gui.slot_button_text_selected_hover_color = gui.hover_color

## The width and height of the thumbnail used by the save slot.
define config.thumbnail_width = 160
define config.thumbnail_height = 125

## Number of columns and rows in the slots table.
define gui.file_slot_cols = 1
define gui.file_slot_rows = 10[/s]
[/s]
Attachments
bandicam 2022-09-04 02-50-03-165.jpg
There has been such a misunderstanding
bandicam 2022-09-03 12-17-55-626.jpg
What do I want to get
Last edited by Andredron on Sun Sep 04, 2022 5:07 am, edited 2 times in total.
I'm writing a Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Help me to register in QQ International

Honest Critique

User avatar
enaielei
Regular
Posts: 114
Joined: Fri Sep 17, 2021 2:09 am
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Bind coordinates to screenshot thumbnail

#2 Post by enaielei » Sat Sep 03, 2022 11:56 pm

Try to use a screen variable to store the slot number when hover event using SetScreenVariable.
Then add the thumbnail FileScreenshot using the stored slot number and place it outside the loop.

User avatar
Andredron
Miko-Class Veteran
Posts: 535
Joined: Thu Dec 28, 2017 2:37 pm
Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
Location: Russia
Contact:

Re: Bind coordinates to screenshot thumbnail

#3 Post by Andredron » Sun Sep 04, 2022 2:45 am

enaielei wrote:
Sat Sep 03, 2022 11:56 pm
Try to use a screen variable to store the slot number when hover event using SetScreenVariable.
Then add the thumbnail FileScreenshot using the stored slot number and place it outside the loop.
Thank you, I solved the problem with displaying files, but the screenshot thumbnail disappeared,

Image

Code: Select all

screen file_slots(title):
    add "save_mm"
    add "save_mm2"
    default current_file = 0
    if current_file != 0:
        add FileScreenshot(current_file) xalign 0.69 yalign 0.36

    fixed:
        grid 1 10:
            xfill True
            transpose True
            spacing 10
            $ rows = 10
            for i in range(1, rows + 1):
                button:
                    action FileAction(i)
                    hovered SetScreenVariable("current_file", i)
                    unhovered SetScreenVariable("current_file", 0)
                    xfill True
                    $ file_time = FileTime(i, format=_("%A, %d %B %Y, %H:%M"), empty=_("Пустой слот"))
                    $ file_name = FileSlotName(i, rows)
                    text "{vspace=3}[file_name][file_time!t]"
I'm writing a Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Help me to register in QQ International

Honest Critique

User avatar
enaielei
Regular
Posts: 114
Joined: Fri Sep 17, 2021 2:09 am
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Bind coordinates to screenshot thumbnail

#4 Post by enaielei » Sun Sep 04, 2022 3:26 am

Its probably because of your condition that makes the screenshot not to show.
I suggest removing the condition for the screenshot since FileScreenshot already handles empty slots with a Null displayable.
FileScreenshot(name, empty=None, page=None, slot=False)
Returns the screenshot associated with the given file. If the file is not loadable, then empty is returned, unless it's None, in which case, a Null displayable is created.

The return value is a displayable.

User avatar
Andredron
Miko-Class Veteran
Posts: 535
Joined: Thu Dec 28, 2017 2:37 pm
Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
Location: Russia
Contact:

Re: Bind coordinates to screenshot thumbnail

#5 Post by Andredron » Sun Sep 04, 2022 3:34 am

enaielei wrote:
Sun Sep 04, 2022 3:26 am
Its probably because of your condition that makes the screenshot not to show.
I suggest removing the condition for the screenshot since FileScreenshot already handles empty slots with a Null displayable.
FileScreenshot(name, empty=None, page=None, slot=False)
Returns the screenshot associated with the given file. If the file is not loadable, then empty is returned, unless it's None, in which case, a Null displayable is created.

The return value is a displayable.
viewtopic.php?f=51&t=25981#p317940
It did not help, I used the old code as the basis through the search for SetScreenVariable

and the old code is not friendly with gui
I'm writing a Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Help me to register in QQ International

Honest Critique

User avatar
enaielei
Regular
Posts: 114
Joined: Fri Sep 17, 2021 2:09 am
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Bind coordinates to screenshot thumbnail

#6 Post by enaielei » Sun Sep 04, 2022 3:41 am

How about trying to create a new save and see if your current code works when hovering that new save?

User avatar
Andredron
Miko-Class Veteran
Posts: 535
Joined: Thu Dec 28, 2017 2:37 pm
Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
Location: Russia
Contact:

Re: Bind coordinates to screenshot thumbnail

#7 Post by Andredron » Sun Sep 04, 2022 4:13 am

Earned

Code: Select all

define file_slots_current_file = 0
    
screenfile_slots(title):
      
    if file_slots_current_file > 0:
        add FileScreenshot(file_slots_current_file) pos(440,175)
    
    if file_slots_current_file < 0:
        add FileScreenshot(abs(file_slots_current_file), page = "quick") pos(440,175)

    fixed pos(50,100):
        vbox_wrap True:
            xfill True
            # transpose True
            spacing-29
            $rows = 10
            for i in range(1, rows + 1):
                button:
                    action FileAction(i)
                    hovered [SetVariable("file_slots_current_file", i)]
                    unhovered [SetVariable("file_slots_current_file", 0)]
                    
                    fixed fit_first True:
                        # add FileScreenshot(i)

                        xfill True
                        #$ file_name = FileSlotName(i, rows)
                        $ file_time = FileTime(i, empty=_("Empty Slot."))
                        $save_name = FileSaveName(i)
                        text "[file_time!t]\n[save_name!t]"

    fixed pos(50,389): ###qsave
        vbox_wrap True:
            xfill True
            # transpose True
            spacing -30
            $rows=1
            for i in range(1, rows + 1):
                button:
                    action FileLoad(1, confirm=False, page="quick", newest=True)
                    hovered [SetVariable("file_slots_current_file",-1)]
                    unhovered [SetVariable("file_slots_current_file", 0)]
                 
                    fixed fit_first True:

                        xfill True
                        #$ file_name = FileSlotName(i, rows)
                        $ file_time = FileTime(i, empty=_("Empty Slot."), page = "quick")
                        $ save_name = FileSaveName(i, page = "quick")
                        text "[file_time!t]\n[save_name!t]"
                        
    textbutton _("Return"):
        xalign 0.95 yalign 0.92
        text_outlines [ (absolute(1), "#333333", absolute(1), absolute(1)) ]
        actionReturn()
thank you for helping
Attachments
bandicam 2022-09-04 11-12-16-372.jpg
I'm writing a Renpy textbook (in Russian). https://disk.yandex.ru/i/httNEajU7iFWHA (all information is out of date) Update 22.06.18

Help me to register in QQ International

Honest Critique

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]