Chat log - Adding like, message and report buttons

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
Kinmoku
Miko-Class Veteran
Posts: 560
Joined: Mon Aug 11, 2014 9:39 am
Completed: One Night Stand
Projects: Love IRL, Memories
Tumblr: gamesbykinmoku
itch: kinmoku
Location: Germany
Contact:

Chat log - Adding like, message and report buttons

#1 Post by Kinmoku » Tue May 05, 2020 10:38 am

Hi all. I'm using the Ren'py Chat Log code https://poorlifechoices.itch.io/renpy-chatlog and have it working how I like. However, I want to add some buttons: like, message and report.

Like simply adds a number to the one shown.
Message opens up another screen where you can type a message and post.
Report opens up another screen where you can report someone.

I have got the buttons in place with the graphics, but I am unsure how to do each task as it needs to like/ message/ report the user clicked on.

Here's my code:

Code: Select all

label start:
    # Initialize the chat log
    default mylog = ChatLog()

    show screen logframe(mylog)

    # Add a message to the chat log.
    $ mylog.add_chat(msg="Hello World", nick="KoolDog", avatar="images/avatars/kool_dog.png")
    
    pause 1
    
    $ mylog.add_chat(msg="Hey KD! How are you?", nick="Kinmoku", avatar="images/avatars/kinmoku.png")

    
In screens:

Code: Select all

screen chat_log(log):
    viewport id "chatlog":
        xpos 332
        ypos 92
        ysize 800
        yadjustment log.adjustment()
        mousewheel True
        draggable True
        yinitial 1.0
        python:
            # Thanks to mangoduck at
            # https://lemmasoft.renai.us/forums/viewtopic.php?t=32584 for this
            # flash of insight for auto scrolling
            log.adjustment().value = chat_infinity_float
        vbox:
            spacing 20

            for type, kwargs in log.history():
                use expression type pass (**kwargs)

# Defines a single line of the chat log.
# The format is Discord-like.
# avatar nick
#   "    msg
screen chat_entry(msg="", nick=None, avatar=None):
    hbox:
        spacing 40
        if avatar != None:
            add avatar
        vbox:
            if nick != None:
                text nick
            text msg
            
        vbox:
            yalign 1.0
            spacing 8
            button:
                background "images/button_likes.png"
                text "{color=#000}1{/color}" xpos 54 ypos -5
            button:
                background "images/button_messages.png"
                action Show("message_user")
                text "{color=#000}0{/color}" xpos 54 ypos -5
            button:
                background "images/button_report.png"
                action Show("report_user")
                text "{color=#000}Report{/color}" xpos 10 ypos -5
                
                
screen logframe(log):
    frame:
        use chat_log(log)

                
For "Like", I'd like to be able to set the number of likes with $ mylog.add_chat, as it will be different for every user's message. Pushing the button will make the number go up as well, though only once.

"Message" has a number as well, which will go up if you type a message.

"Report" needs the user's name in the screen text. I tried to do this but it didn't work. I'm unsure how to pull this out from what I have.

Code: Select all

screen report_user(msg="", nick=None, avatar=None):
    vbox:
        xalign 0.5
        yalign 0.5
        
        text "Do you want to report user"
        if nick != None:
            text nick
Sorry there is a lot of different things going on here. Does anyone have any ideas? I can share more code of how the ChatLog works if needed.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], _ticlock_