Help for taskbar-stats-screen and use of grid

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
IcebearGN
Newbie
Posts: 1
Joined: Sat Aug 12, 2023 8:30 am
Deviantart: icebeargn
Contact:

Help for taskbar-stats-screen and use of grid

#1 Post by IcebearGN »

I'm just starting out and familiarizing myself with Renpy. I understand the basics and have actually already solved my problem. But surely there must be a better and simpler way to do this!

As you can see in the picture, I have several fields that represent values. This is not an inventory with items (well maybe it is)... this are different point values, similar to properties.

I tried to display the whole thing using a grid, but it didn't work the way I wanted it to. The individual values should be centered in the fields and the text in them should also be centered.

Image

Code: Select all

screen Taskbar():

    modal True
    zorder 10

    add "System/Taskbar/Taskbar.png" xpos 1 ypos 1

    text "[Day]" xpos 16 ypos 20 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Weekday]" xpos 85 ypos 22 color "#F80" bold True size 18 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Time]:00" xpos 236 ypos 22 color "#F80" bold True size 18 outlines[(absolute(2), "#000", absolute(0), absolute(0))]

    bar:
        value AP
        range APmax
        left_bar "System/Taskbar/Task_AP_02.png"
        right_bar "System/Taskbar/Task_AP_01.png"
        xysize(204,39)
        xpos 315
        ypos 14

    imagebutton:
        xpos 540
        ypos 9
        auto "System/Taskbar/Btn_Task_Stats_%s.png"
        hovered [Play("sound", "audio/SND_Click_01.mp3")]
        action Show("StatsUI")


screen StatsUI:

    modal True
    zorder 11

    add "System/Taskbar/BG_Stats.png" xpos 1 ypos 100

    imagebutton:
        xpos 540
        ypos 110
        auto "System/Taskbar/Btn_Close_%s.png"
        hovered [Play("sound", "audio/SND_Click_01.mp3")]
        action Hide("StatsUI")

    # better use a grid... but how???
    text "[Item1]" xpos 40 ypos 730 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Item2]" xpos 115 ypos 730 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Item1]" xpos 190 ypos 730 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Item2]" xpos 270 ypos 730 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Item1]" xpos 340 ypos 730 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Item2]" xpos 415 ypos 730 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Item1]" xpos 485 ypos 730 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]
    text "[Item2]" xpos 560 ypos 730 color "#F80" bold True size 22 outlines[(absolute(2), "#000", absolute(0), absolute(0))]

I went through some videos and explanations here in the forum, but... couldn't get it right. If anyone can help me make it easier to implement, I would be grateful.

User avatar
enaielei
Veteran
Posts: 333
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: Help for taskbar-stats-screen and use of grid

#2 Post by enaielei »

Use python lists and loops.

Code: Select all

default items = [1, 2, 3, 4, 5] # store items in a collection like lists

init python:
    import math

screen test():
    default cols = 3
    default rows = math.ceil(len(items) / cols) # automatically identify the number of rows based on the no. of itmes and specified no. of columns for the grid

    grid cols rows:
        for i in range(cols * rows): # fill up the grid by looping
            if i < len(items):
                $ item = items[i] # access the item via list index
                text "Item: [item]"
            else:
                null # use null display to fill out empty cells

Post Reply

Who is online

Users browsing this forum: Google [Bot], halnye