[SOLVED]imagebutton generators, for whatsapp emulator

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
Dr_arell
Regular
Posts: 70
Joined: Sun Feb 23, 2020 11:24 pm
Deviantart: DarellArt
Contact:

[SOLVED]imagebutton generators, for whatsapp emulator

#1 Post by Dr_arell »

hello, im making a phone which has an directory, where it will contain multiple clickable contacts
what im trying to emulate is something like the whatsapp homepage just to give you an idea

each contact, will have an image a name and an action , the action is obviously what it does when you click it, and wont be shown.
all these 3 must be linked to a element in a list, so everytime i append a new element to a list it duplicates it but with different image name and action


let me try to do an example

Code: Select all

$ contacts_unlocked = ["Joel",]

Code: Select all

screen contacts():
    imagebutton:
        idle "/images/Screen resources/Navigation/contact_layout.png"
        action  Jump("conversation with" ----------------Joel---------------) focus_mask True
        add "/images/Screen resource/Profile pictures/-----------Joel-------------.png"
and appending a new name, lets say michael

Code: Select all

 contacts_unlocked.append("Michael")
would spit out something like this (what you see in -----------blahblah----------- is linked to the list)

Code: Select all

    imagebutton:
        idle "/images/Screen resources/Navigation/contact_layout.png"
        action  Jump("conversation with" -------------Michael-------------) focus_mask True
        add "/images/Screen resource/Profile pictures/-----------Michael----------[/color].png"
        
it is basically a clone but using the second element in the list, i was thinking of using a for loop but i'm very green on those, if theres a better way to achieve the same result please let me know, it has to be a generator of a clickable imagebutton, that changes image, name and action as the list goes on.

if you have no idea what im talking about, knowing how to plug the string element from a list in the image path and in the imagebutton action is equally helpful.

once im done with the whole cellphone i will try to share it for the whole community, not only this part but the whole thing!!
Last edited by Dr_arell on Sat Feb 20, 2021 11:42 pm, edited 1 time in total.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: imagebutton generators, for whatsapp emulator

#2 Post by gas »

You must take a breath, take a tea, take a nap, look at Buddha for one hour, look at a cat two hours and then realize the drama.

You must use Classes.
You don't know how they work? Time to study.
They are usefull whatever engine/language you'll ever use.

Create all the relative objects and add them to a list.
Then, in the screen, you'll use a for cycle that scan all the objects in the objects list and populate a grid/vbox/whatever.
Don't use an imagebutton, but a BUTTON (see the docs): this allow you to determine the single picture to add using a parameter (a button is just a clickable area, you can add whatever inside of it).

After clicking, you must return some value to process, and there I can hardly figure out how you can come to a result if your python is so basic.
(I hardly doubt the community will benefit of something you're asking the same community how to do it... But who knows, thank you).
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Dr_arell
Regular
Posts: 70
Joined: Sun Feb 23, 2020 11:24 pm
Deviantart: DarellArt
Contact:

Re: imagebutton generators, for whatsapp emulator

#3 Post by Dr_arell »

yeah, one of the things that crossed my mind is using classes but i dont have much experience with objects i have used them before but i always get stuck sooner or later, i just prefer avoiding them, ill try with what you said and see what comes up

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: imagebutton generators, for whatsapp emulator

#4 Post by gas »

Dr_arell wrote: Tue Feb 16, 2021 1:28 am yeah, one of the things that crossed my mind is using classes but i dont have much experience with objects i have used them before but i always get stuck sooner or later, i just prefer avoiding them, ill try with what you said and see what comes up
Good luck. Once you get a grasp on the concept, you stop thinking of strings and stuff and you'll see the world made by classes XD. Too much powerfull in comparison.

It's easy.
An object is a memory space in your device. It's created by calling a class, that determine the "content" of the object. A class can be used to create any number of similar objects.
The harder part to understand is that: when you create an object, python simply pick a "mostly random" memory space and create the object inside of it. You don't know where it is, but for sure is somewhere.

Code: Select all

init python:
    class Contact(object):
        def __init__(self,name, image, act):
            self.name = name
            self.image = image
            self.act =  act
There's nothing special here, it's you that decide such parameters. One, ten, thousands, whatever.
The class do nothing on his own, is just a tool you'll create to use later. So, later, you can type:

Code: Select all

default jhon = Contact(name = "John", image ="image.png", act = 0)
And bam! This Contact object exist inside the device memory. Don't mind, when you turn off the game the objects just... dieeee.
Once an object is created you can retrieve and manipulate the object parameters EXACTLY like variables, but prepending the object name you gave.

So, for example

Code: Select all

jhon.name
is equal "Jhon".

So, at this early level, objects are nothing but a more convenient way to store group of similar data. Nothing magical.

This is the base. Not just a base, this is THE base if you want to do ANY POSSIBLE coding in your life. Really. Is since 1970 that computers work this way.
Python is also really sweet as an object oriented introduction, you can find many easy tutorials around.
After a while (one week?) you can code your wazzappa clone on your own.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Dr_arell
Regular
Posts: 70
Joined: Sun Feb 23, 2020 11:24 pm
Deviantart: DarellArt
Contact:

Re: imagebutton generators, for whatsapp emulator

#5 Post by Dr_arell »

yes i dont think the basic object knoledge will be a problem what got me confused was the Button instead of imagebutton, to my knowledge theres only imagemap, imagebutton, and textbutton

i got the idea, do a for loop inside a screen, making it so it refers to the object image and object name and then the list just provides which one, is that what u mean maybe?

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: imagebutton generators, for whatsapp emulator

#6 Post by zmook »

Dr_arell wrote: Tue Feb 16, 2021 2:18 am yes i dont think the basic object knoledge will be a problem what got me confused was the Button instead of imagebutton, to my knowledge theres only imagemap, imagebutton, and textbutton

i got the idea, do a for loop inside a screen, making it so it refers to the object image and object name and then the list just provides which one, is that what u mean maybe?
The basic Button is documented here: https://www.renpy.org/doc/html/screens. ... ton#button

You want your data structure to be a list of Contact objects. Do a for loop over the contact_list, and for each contact add a button to a vpgrid. Something like this (though, honestly, this one just uses tuples to store the button data. Defining a proper class is more flexible and much better for readability.):

Code: Select all

    vpgrid:
        cols 3
        spacing 10
        align(0.5, 0.5)
 
        for gimage in imgGalleryMenuDict[imgGalleryDay][imgGalleryPage]:
            if gimage[1]:
                frame:
                    xysize(300,175)
                    imagebutton:
                        idle Transform(gimage[0], zoom=0.15)
                        hover Transform(im.MatrixColor(gimage[0], im.matrix.brightness(0.2)), zoom=0.15)
                        action Show("largeImage", lImage=gimage[0])
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: munni