Individual Bar Colors?

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
Belgerum
Regular
Posts: 110
Joined: Thu Nov 06, 2014 12:24 am
Skype: belgerum09
Soundcloud: Belgerum
itch: Belgerum
Contact:

Individual Bar Colors?

#1 Post by Belgerum »

I was playing around with the Ren'py tutorial's status frame, I'm just wondering if it's possible to have two differently colored bars next to each other by specifying the individual property of one over the default style. Below is the code I've got, and the style properties make both of the bars the same color, though I think I'd like it if I could make the "HP" bar red, and the "MP" bar blue. Is that possible?

Code: Select all

init python:

    def stats_frame(name, level, hp, maxhp, mp, maxmp, **properties):

        ui.frame(xfill=False, yminimum=100, xpadding=10, ypadding=10, **properties)

        ui.hbox() # (name, "HP", bar) from (level, hp, maxhp)
        ui.vbox() # name from ("HP", bar)

        ui.text(name, size=25)

        ui.hbox() # "HP" from bar
        ui.text("HP", size=20, ypos=5)
        ui.bar(maxhp, hp,
               xmaximum=200)
        ui.close()
        
        ui.hbox() # "MP" from bar
        ui.text("MP", size=20, ypos=5)
        ui.bar(maxmp, mp,
               xmaximum=200)
        ui.close()
        ui.close()

        ui.vbox() # Level from (hp/maxhp)

        ui.text("Lv. %d" % level, xalign=0.5, size=25)
        ui.text("%d/%d" % (hp, maxhp), xalign=0.5, size=20, ypos=5)
        ui.text("%d/%d" % (mp, maxmp), xalign=0.5, size=20, ypos=5)

        ui.close()
        ui.close()

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Individual Bar Colors?

#2 Post by trooper6 »

You are using really, really outdated code. The current thing is to use screen language.
The documentation is here: http://www.renpy.org/doc/html/screens.html

There is a bar tutorial here as well: http://lemmasoft.renai.us/forums/viewto ... r+tutorial
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Belgerum
Regular
Posts: 110
Joined: Thu Nov 06, 2014 12:24 am
Skype: belgerum09
Soundcloud: Belgerum
itch: Belgerum
Contact:

Re: Individual Bar Colors?

#3 Post by Belgerum »

Thanks for the links, and the heads up on the outdated code. After looking through the screen language, and using trial and error tests, I think I've managed to make the code a bit more up to date.

However, I still can't find any answer about the individually colored bars. In the bar tutorial post you linked, there is no mention of color anywhere in the properties listing, but I'd like to think it must be defined SOMEWHERE, since the Style properties can apply color to all the bars at once.

Again, here's the code I have, now in screen language, and I'm looking to have the "HP" bar colored red, and the "MP" bar colored blue.

Code: Select all

screen stats_frame(name, level, hp, maxhp, mp, maxmp, xcoord, ycoord):
    frame:
        xpadding 18 ypadding 18
        xalign xcoord
        yalign ycoord
        hbox:
            vbox:
                text name size 25 ypos -5
                hbox:
                    vbox:
                        text "HP " size 20 xmaximum 200
                        text "MP " size 20 ypos 5 xmaximum 200
                    vbox:
                        bar value StaticValue(hp, maxhp) xmaximum 200
                        bar value StaticValue(mp, maxmp) xmaximum 200 ypos 5
            vbox:
                text "Lv. [level]" size 25 xalign 1.0 ypos -5
                text "[hp]/[maxhp]" size 20 xalign 1.0
                text "[mp]/[maxmp]" size 20 xalign 1.0 ypos 5

label start:
show screen stats_frame("Player", 5, 23, 50, 4, 30, 0.15, 0.15)
"Sample Text"

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Individual Bar Colors?

#4 Post by Kia »

an old bar from my first game that is still on hold. I hope it helps you.

Code: Select all

            bar value playerxp range 1000 align(0.5, 0.0) xysize(1.0, 6) left_bar "#ffffffaa"  right_bar "#FFFF0099" thumb None hovered showhover

User avatar
Belgerum
Regular
Posts: 110
Joined: Thu Nov 06, 2014 12:24 am
Skype: belgerum09
Soundcloud: Belgerum
itch: Belgerum
Contact:

Re: Individual Bar Colors?

#5 Post by Belgerum »

Thanks for your input, but unfortunately, this does not help me much.

Using the "left_bar" and "right_bar" properties as colors definitely gives me those colors for the bar, but it doesn't allow for the use of the styled bar image. For example, using the "austen" theme with the default widget color set to red, I can use the below code to create a display that looks like the attached screencap.

Code: Select all

screen stats_frame(name, level, hp, maxhp, mp, maxmp, xcoord, ycoord):
    frame:
        xpadding 18 ypadding 18
        xalign xcoord
        yalign ycoord
        hbox:
            vbox:
                text name size 25 ypos -5
                hbox:
                    vbox:
                        text "HP " size 20 xmaximum 200
                        text "MP " size 20 ypos 5 xmaximum 200
                    vbox:
                        bar value StaticValue(hp, maxhp) xmaximum 200
                        bar value StaticValue(mp, maxmp) xmaximum 200 ypos 5 left_bar "#ffffffaa"  right_bar "#FFFF0099"
            vbox:
                text "Lv. [level]" size 25 xalign 1.0 ypos -5
                text "[hp]/[maxhp]" size 20 xalign 1.0
                text "[mp]/[maxmp]" size 20 xalign 1.0 ypos 5

label start:
show screen stats_frame("Player", 5, 23, 50, 4, 30, 0.15, 0.15)
"Sample Text"
Image

The default style color for all widgets in the theme gets applied to the HP bar, making it red, or any color the user defines.

The MP bar, using the "left_bar" and "right_bar" properties, has the right colors as individually defined, but it doesn't use the bar image from the theme.

Since the user can describe what color they want the default bar (and other widgets) to be with a statement in the "options.rpy" file, I would like to think there is a way to describe a bar with an individual coloring that still uses the rest of the theme, but I don't have any idea how I would do so.

I've tried adding things to the bar statement such as:

Code: Select all

bar value StaticValue(hp, maxhp) xmaximum 200 color "#FF1500"

Code: Select all

bar value StaticValue(hp, maxhp) xmaximum 200 widget_color "#FF1500"
...but nothing seems to work with the bar statement correctly.

User avatar
Kia
Eileen-Class Veteran
Posts: 1040
Joined: Fri Aug 01, 2014 7:49 am
Deviantart: KiaAzad
Discord: Kia#6810
Contact:

Re: Individual Bar Colors?

#6 Post by Kia »

well i usually change the whole style and design my own but if you want to keep the style you need to apply the style but since I don't know how to apply the color to a bar I suggest the old trick:
go to renpy-6.99.4-sdk\renpy\common\_theme_austen folder and take the bar template recolor and use it for the 2nd bar.

User avatar
Belgerum
Regular
Posts: 110
Joined: Thu Nov 06, 2014 12:24 am
Skype: belgerum09
Soundcloud: Belgerum
itch: Belgerum
Contact:

Re: Individual Bar Colors?

#7 Post by Belgerum »

Well, I suppose that does work... I managed to get a blue bar to go against the theme by manually putting in substitute images. For reference, here's the code I used:

Code: Select all

screen stats_frame(name, level, hp, maxhp, mp, maxmp, xcoord, ycoord):
    frame:
        xpadding 18 ypadding 18
        xalign xcoord
        yalign ycoord
        hbox:
            vbox:
                text name size 25 ypos -5
                hbox:
                    vbox:
                        text "HP " size 20 xmaximum 200
                        text "MP " size 20 ypos 5 xmaximum 200
                    vbox:
                        bar value StaticValue(hp, maxhp) xmaximum 200
                        bar value StaticValue(mp, maxmp) xmaximum 200 ypos 5 left_bar Frame("Objects/blue bar full.png", 12, 12)  right_bar Frame("Objects/blue bar empty.png", 12, 12) thumb "Objects/blue bar thumb.png"
            vbox:
                text "Lv. [level]" size 25 xalign 1.0 ypos -5
                text "[hp]/[maxhp]" size 20 xalign 1.0
                text "[mp]/[maxmp]" size 20 xalign 1.0 ypos 5
...But it takes a lot of hassle to manually recolor each bar part and reference them in the script each time I want to recolor a bar, and the new images take up extra space in the file directory.

As you mention, Kia, I do indeed plan on changing the style instead of just using a default, but it would be very nice if I could just have one set of bar images that ren'py could recolor individually in the script, instead of having to make an entirely new set of files for each variation. Even if you don't know how, do you know if it's even possible?

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Individual Bar Colors?

#8 Post by philat »

I had to poke around the common files a bit to find how renpy does it by default, but this seems to work. Obviously replace the images.

Code: Select all

screen testingbars():
    vbox:
        bar: # red
            xsize 500
            value 50
            range 100
            left_bar Frame(im.Twocolor("_theme_diamond/dslider_full.png", "#f00", "#f00"), 12, 0)
            right_bar Frame(im.Twocolor("_theme_diamond/dslider_empty.png", "#f00", "#f00"), 12, 0)
        bar: # white
            xsize 500
            value 50
            range 100
            left_bar Frame(im.Twocolor("_theme_diamond/dslider_full.png", "#fff", "#fff"), 12, 0)
            right_bar Frame(im.Twocolor("_theme_diamond/dslider_empty.png", "#fff", "#fff"), 12, 0)
        bar: # default
            xsize 500
            value 50
            range 100

User avatar
Belgerum
Regular
Posts: 110
Joined: Thu Nov 06, 2014 12:24 am
Skype: belgerum09
Soundcloud: Belgerum
itch: Belgerum
Contact:

Re: Individual Bar Colors?

#9 Post by Belgerum »

That was exactly what I was looking for, philat! Thanks a lot!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]