The code I used in Elven Relations's combat engine was this:
Code: Select all
ui.bar(range=1.0, value=times[ThisChar], xmaximum=100, ymaximum=13, left_bar=Frame("ActionBar_full.png", 13, 0), right_bar=Frame("ActionBar_empty.png", 13, 0), thumb=None, thumb_shadow=None)
The "value" (times[ThisChar] in my case) is how far along to chop the image, relative to the "range". In my case, I had "range" of 1.0, so the "value" was taken as a fraction of 1.0: 0.0 says "use none of the left_bar and all of the right_bar"; 1.0 says "use all of the left bar and none of the right_bar"; 0.2 says "use the left-hand 20% of the left_bar and the right-hand 80% of the right_bar", etc.
If you define some other variable like "motivation_max", to be something like 100, then you can have your "motivation" variable vary between 0 and 100, as long as you supply "motivation_max" as the "range" parameter.
- How do I Show/Hide it?
This is the same as any other UI element you want to only appear sometimes: inside the UI overlay function, hide it behind an "if" statement to see whether it should be showing, as defined by some other variable like "show_motivation". Then in your Ren'Py code, set that variable to True or False to show or hide the bar.
Code: Select all
init python:
def ui_motivation(): # this function will be called *every* time the text box is displayed
if show_motivation: # so we make it do nothing unless show_motivation is set
ui.bar(range=motivation_max, value=motivation, xmaximum=200, ymaximum=10, left_bar=Frame("motivation_left.png", 10, 0), right_bar=Frame("motivation_right.png", 10, 0), xalign=1.0, yalign=0.0)
config.overlay_functions.append(ui_motivation) # this is lined up with the "def" above, and tells Ren'Py to call the ui_motivation function every time it's about to display the text box
label start:
$ show_motivation = False
$ motivation_max = 100
$ motivation = 100
"Let's see how motivated I am..."
$ show_motivation = True
"Houah! Go for it, me!"
- How do I dictate how it will behave (say it will drain from left to right)
This is controlled by specifying the right thing for the left_bar, right_bar, and the value. As I've got it above, your value of "motivation" will indicate how far to the right the bar should be: so higher values will make the bar use more of the left_bar and less of the right_bar. If you want it the other way around, you can add the "bar_invert" parameter to the call to ui.bar, like this:
Code: Select all
ui.bar(bar_invert=True, range=motivation_max, value=motivation, ...
- Is it possible to create vertical ones?
- If vertical ones are possible... How do I dictate how it will behave (say it will drain from top to bottom)
As Jo'ogn linked, it is indeed. You just need to include the "bar_vertical" parameter in your call to ui.bar, like this:
Code: Select all
ui.bar(bar_vertical=True, range=motivation_max, value=motivation, top_bar=Frame("motivation_top.png", 10, 0), bottom_bar=Frame("motivation_bottom.png", 10, 0), xalign=1.0, yalign=0.0)
- May I request a copy/paste code so I can study it in greater detail (with comments if possible)
I've included some scraps of code above. I'm afraid I haven't tested them, but I hope they're useful.