Help with a conditional style

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
ShadoStalk3r
Newbie
Posts: 9
Joined: Mon Oct 29, 2018 6:17 am
Contact:

Help with a conditional style

#1 Post by ShadoStalk3r »

Hi all, I need help with a conditional style. I have a style named "navigation_btn" which is called for my main menu buttons which are aligned to the left. It works fine in the preferences screen. But I'm trying to center the text in the buttons but only when the main_menu screen is shown.

My style:

Code: Select all

style navigation_btn:
	xoffset 100
	yoffset 25
	color "#ffffff80"
	
style navigation_btn_hover:
	xoffset 100
	yoffset 25
	color "#fff"
	
style navigation_btn_center:
	xalign 0.5
	xoffset 100
	yoffset 25
	color "#ffffff80"
My button:

Code: Select all

imagebutton:
	idle "gui/button/navigation/blank.png"
	foreground Text(_("NEW GAME"), style ="navigation_btn")
	hover_foreground Text(_("NEW GAME"), style ="navigation_btn_hover")
	hovered Play("sound",guisfx_button_hover)
	action Start()
I want it so that while renpy.get_screen("main_menu") is true, the style of the buttons gets "xalign 0.5" appended to it, then back to default when in the preferences menu.

Something like:

Code: Select all

if renpy.get_screen("main_menu"):
	style navigation_btn is navigation_btn_center
else:
	style navigation_btn is default
I feel like I've tried everything but can't figure it out.

ShadoStalk3r
Newbie
Posts: 9
Joined: Mon Oct 29, 2018 6:17 am
Contact:

Re: Help with a conditional style

#2 Post by ShadoStalk3r »

I've managed to do it with this:

Code: Select all

imagebutton:
	idle "gui/button/navigation/blank.png"
	if renpy.get_screen("main_menu"):
		foreground Text(_("NEW GAME"), style ="navigation_btn_center")
		hover_foreground Text(_("NEW GAME"), style ="navigation_btn_hover_center")
	else:
		foreground Text(_("NEW GAME"), style ="navigation_btn")
		hover_foreground Text(_("NEW GAME"), style ="navigation_btn_hover")
	hovered Play("sound",guisfx_button_hover)
	action Start()
	

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]