Add Navigation Imagebuttons with Text? [Solved]

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
Katy133
Miko-Class Veteran
Posts: 704
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Add Navigation Imagebuttons with Text? [Solved]

#1 Post by Katy133 »

I'm trying to add images behind the text buttons in the Main Menu and Game Menu (aka the Navigation screen). The images are .png files of an idle button and a hover button. So far, I've programmed textbuttons in the Navigation screen. But how would I add imagebuttons with text?

A work-around I used to use would be to save buttons with the text already printed onto them. But here, that would add a huge amount of images to make (an idle and hover image for each button, timed by how many buttons with text you want). Plus, it would stop people from being able to change the font for accessibility purposes.

Is there a way to combine text with imagebuttons?

This is the navigation screen:

Code: Select all

screen navigation():

    vbox:
        style_prefix "navigation"

        xpos gui.navigation_xpos
        yalign 0.5

        spacing gui.navigation_spacing

        if main_menu:

            textbutton _("Start") action Start()

        else:

            textbutton _("History") action ShowMenu("history")

            textbutton _("Save") action ShowMenu("save")

        textbutton _("Load") action ShowMenu("load")

        textbutton _("Options") action ShowMenu("preferences")

        if renpy.variant("pc"):

            ## Help isn't necessary or relevant to mobile devices.
            textbutton _("Help") action ShowMenu("help")
        
        textbutton _("About") action ShowMenu("about")

        if _in_replay:

            textbutton _("End Replay") action EndReplay(confirm=True)

        elif not main_menu:

            textbutton _("Main Menu") action MainMenu()
        
        if renpy.variant("pc"):

            ## The quit button is banned on iOS and unnecessary on Android.
            #textbutton _("Quit") action Quit(confirm=not main_menu)
            #Add confirm choice in Main Menu
            textbutton _("Quit") action Quit(confirm=True)


style navigation_button is gui_button
style navigation_button_text is gui_button_text

style navigation_button:
    size_group "navigation"
    properties gui.button_properties("navigation_button")

style navigation_button_text:
    properties gui.button_text_properties("navigation_button")
Last edited by Katy133 on Sat Apr 13, 2019 9:11 pm, edited 1 time in total.
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Add Navigation Imagebuttons with Text?

#2 Post by Imperf3kt »

Sure!
You just need to use an idle_foreground and hover_foreground

Here is an example imagebutton.

Code: Select all

    imagebutton:
        auto 'gui/button/button_base_%s.png'
        hover_foreground Text("yourText", xalign=0.5, yalign=0.5)
        idle_foreground Text("yourText", xalign=0.5, yalign=0.5)
        action yourAction
I use it in a project to make something like this with just two images (_hover and _idle versions of the same image)
Image

You could change the font, color, size, etc even.
Last edited by Imperf3kt on Sat Apr 13, 2019 7:00 pm, edited 2 times in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Chiligoat
Regular
Posts: 31
Joined: Thu Mar 21, 2019 7:42 pm
Projects: Witches 4 Hire
Location: Sweden
Contact:

Re: Add Navigation Imagebuttons with Text?

#3 Post by Chiligoat »

Imperf3kt wrote: Sat Apr 13, 2019 5:18 pm Sure!
You just need to use an idle_foreground and hover_foreground
You are a lifesaver. I was looking for something like this just hours ago and figured, eh, I'll just make do without image backgrounds and go with plain textbuttons, and here you are. Thanks!

User avatar
Katy133
Miko-Class Veteran
Posts: 704
Joined: Sat Nov 16, 2013 1:21 pm
Completed: Eight Sweets, The Heart of Tales, [redacted] Life, Must Love Jaws, A Tune at the End of the World, Three Guys That Paint, The Journey of Ignorance, Portal 2.5.
Projects: The Butler Detective
Tumblr: katy-133
Deviantart: Katy133
Soundcloud: Katy133
itch: katy133
Location: Canada
Contact:

Re: Add Navigation Imagebuttons with Text?

#4 Post by Katy133 »

Imperf3kt wrote: Sat Apr 13, 2019 5:18 pm Sure!
You just need to use an idle_foreground and hover_foreground

Here is an example imagebutton.

Code: Select all

    imagebutton:
        auto 'gui/button/button_base_%s.png'
        hover_foreground Text("yourText", xalign=0.5, yalign=0.5)
        idle_foreground Text("yourText", xalign=0.5, yalign=0.5)
        action yourAction
I use it in a project to make something like this with just two images (_hover and _idle versions of the same image)
[img]

You could change the font, color, size, etc even.
Thank you SO much, Imperf3kt! I was able to get the effects I wanted with your help!

I deleted this line:

Code: Select all

#textbutton _("Start") action Start()
And replaced it with this, based on your code:

Code: Select all

imagebutton:
                auto "gui/side menu button %s.png"
                idle_foreground Text("Start", font="HoboStd.otf", color="#e066a3", size=40, xalign=0.5, yalign=0.5)
                hover_foreground Text("Start", font="HoboStd.otf", color="#cc0066", size=40, xalign=0.5, yalign=0.5)
                action Start()
I also changed the font/position of the Return button:

Code: Select all

style return_button is navigation_button
#style return_button_text is navigation_button_text
style return_button_text:
    idle_color "#ffffff"

Code: Select all

style return_button:
    #xpos gui.navigation_xpos
    xpos 90
    yalign 1.0
    #yoffset -30
ImageImage

My Website, which lists my visual novels.
Become a patron on my Patreon!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot]