Adding preference (with correct styling) [PART 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
kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Adding preference (with correct styling) [PART SOLVED]

#1 Post by kivik »

Hi there

This is sort of a two part question:

In my game I'm having performance issues on my laptop for some of the effects (fullscreen resolution cloud fog effects with animations) so I decided to add a persistent variable to toggle the animations.

Part 1:
Then I decided it'd be useful to add it as an option in the preference menu. Easy enough, I just copy some code from the preference screen, used SetField to update the persistent variable instead.

The Problem:
I want to indicate what the current performance is set to and highlight (or dim the other) the buttons accordingly. I've tried:

Code: Select all

style k_pref_button_on is pref_button:
    color "#fff"
style k_pref_button_off is pref_button:
    color "#555"

Code: Select all

textbutton _("Normal effects"):
    action SetField(persistent,"performance", "high")
    if persistent.performance == "high":
        style "k_pref_button_on"
    else:
        style "k_pref_button_off"
textbutton _("Low effects"):
    action SetField(persistent,"performance", "low")
    if persistent.performance == "low":
        style "k_pref_button_on"
    else:
        style "k_pref_button_off"
Aside from the fact that it doesn't work (the condition always returns True), the button text is also now aligned to the left instead of center.


Part 2:
My second question is really whether I can optimise the performance in general? Even when using a 160x100 png file (with alpha transparency) using the following loop, my laptop noticeably heats up:

Code: Select all

image fog headache heavy:
    "assets/fog-1.png"
    size (1280, 800)
    linear 2 alpha 0.5
    linear 2 alpha 1.0
    repeat
Based on what I read previously on the forum, am I right in guessing that the problem is the image transformation in real time (instead of pre-loaded)?

Thank you!
Last edited by kivik on Fri Aug 26, 2016 5:40 am, edited 1 time in total.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Adding preference (with correct styling) [SOLVED]

#2 Post by kivik »

Okay so I found out about the "selected_color" tag, and here's what got it working:

Code: Select all

#override the default colours
style pref_button_text:
    selected_color "#fff"
    color "#888"
Then for the actual preference fields:

Code: Select all

textbutton _("Normal effects"):
    action [SetField(persistent,"performance", "high"), SelectedIf(persistent.performance=="high")]
textbutton _("Low effects"):
    action [SetField(persistent,"performance", "low"), SelectedIf(persistent.performance=="low")]

So the preference buttons are working as expected now, but I'm still wondering if anyone could help with the performance issue please?

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: Adding preference (with correct styling) [PART SOLVED]

#3 Post by xavimat »

For the Part 1. I think you do not need to worry about SelectedIf. In those cases renpy highlights it automatically (see the preferences screen, the window/full_screen options, for example)
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: Adding preference (with correct styling) [PART SOLVED]

#4 Post by kivik »

xavimat wrote:For the Part 1. I think you do not need to worry about SelectedIf. In those cases renpy highlights it automatically (see the preferences screen, the window/full_screen options, for example)
Cool thanks! I assumed the built in Preference ones had built in styles assigned! The code just gets shorter and shorter :)

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]