Getting text from a function to center in a window.

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
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Getting text from a function to center in a window.

#1 Post by NocturneLight »

I was setting up a second window at the top of the screen to show information for the player and succeeded. I've gotten it to say whatever I input in the code.

I have one thing that annoys me though. When it displays, it looks like this:

Summer 10
5 days remaining



As you can see, the text aligns to the left. I'd like for the Summer 10 portion to be centered with the 5 days remaining portion.

When screens and functions are involved how would one go about doing this? Or is it even possible to do such a thing?

I've posted what I think is the relevant code to help solve this. I appreciate the help.

Code: Select all

init python:
        def retrieveSeasonDate(Season, Date, DateDeadline):
                if Season == 1:
                    Month = "Spring"
                elif Season == 2:
                    Month = "Summer"
                elif Season == 3:
                    Month = "Fall"
                elif Season == 4:
                    Month = "Winter"
                elif Date >= 15:
                    string = "You dun goofed up. Change the date."
                    
                    
                if Date >= 1 and Date <= 15 and DateDeadline >= 1 and DateDeadline <= 15:
                    DaysRemaining = DateDeadline - Date

                string = "{font=berylium rg.ttf}{size=+5}" + Month + " " + str(Date) + "{/size}\n" + str(DaysRemaining) + " days remaining{/font}"
                return string

Code: Select all

label DayOne:
    scene Green
    with Dissolve(2.0)

$ date = retrieveSeasonDate(2,10,15)
show screen info
"Testing."
"Testing. Testing."
hide screen info

Code: Select all

screen info():
    vbox:
        xalign 0.5 
        yalign 0.0
        add "logo.thumbnail.png"
    vbox:
        xalign 0.5
        yalign 0.0
        text "[date]" 
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

jw2pfd
Regular
Posts: 87
Joined: Tue Sep 18, 2012 9:55 pm
Location: DFW, TX, USA
Contact:

Re: Getting text from a function to center in a window.

#2 Post by jw2pfd »

The easiest way is to have each line be a different element. You want to start with changing what you return from the function:

Code: Select all

                a = "{size=+5}" + Month + " " + str(Date) + "{/size}"
                b = str(DaysRemaining) + " days remaining"
                return a, b
This doesn't affect how your function is called, but only what is returned. This returns a tuple instead of a single string. In your screen code, then you break it into two different elements like this:

Code: Select all

screen info():
    vbox:
        xalign 0.5
        yalign 0.0
        add "logo.thumbnail.png"
    vbox:
        xalign 0.5
        yalign 0.0
        text "[date[0]]" xalign 0.5 font "berylium rg.ttf"  #I removed the font tag from the string earlier and put it here
        text "[date[1]]" xalign 0.5 font "berylium rg.ttf"
You can edit the style properties for each line of text separately and properties like alignment are relative to the element that they are in which is a vbox in this case.

User avatar
NocturneLight
Regular
Posts: 163
Joined: Thu Jun 30, 2016 1:20 pm
Projects: Unsound Minds: The Clarevine Epoch
Organization: Reminiscent 64
Tumblr: Reminiscent64
itch: Reminiscent64
Location: Texas
Contact:

Re: Getting text from a function to center in a window.

#3 Post by NocturneLight »

jw2pfd wrote:The easiest way is to have each line be a different element. You want to start with changing what you return from the function:

Code: Select all

                a = "{size=+5}" + Month + " " + str(Date) + "{/size}"
                b = str(DaysRemaining) + " days remaining"
                return a, b
This doesn't affect how your function is called, but only what is returned. This returns a tuple instead of a single string. In your screen code, then you break it into two different elements like this:

Code: Select all

screen info():
    vbox:
        xalign 0.5
        yalign 0.0
        add "logo.thumbnail.png"
    vbox:
        xalign 0.5
        yalign 0.0
        text "[date[0]]" xalign 0.5 font "berylium rg.ttf"  #I removed the font tag from the string earlier and put it here
        text "[date[1]]" xalign 0.5 font "berylium rg.ttf"
You can edit the style properties for each line of text separately and properties like alignment are relative to the element that they are in which is a vbox in this case.

That definitely centered it. Thanks again!
The Old Guard is at His Limit. The time is near to usher in the New Guard.

The Great Horror is soon to be free.

Clarevine is the key.


"Unsound Minds: The Clarevine Epoch" is a yuri visual novel that shatters english visual novel norms and aims to blend Christianity and the Cthulhu Mythos to tell a deep and dark story that you'll enjoy. You can follow the Kickstarter here.

Stay sound and persist through the chaos,
NocturneLight

Post Reply

Who is online

Users browsing this forum: Google [Bot]