Page 1 of 1

Tried to have randomized styles

Posted: Thu Jan 30, 2020 11:39 am
by Sehaf
So, Tried to do some heavy experimenting with the choice meny, this is what I made.

Code: Select all

screen choice(items):

    frame:
        style "other_frame"
        xalign 0.5
        yalign 0.5
    
        hbox:
            xmaximum 650
            
            viewport id "men_bar":
                xalign 0.5 yalign 0.5
                xysize (600, 400) #Could shorten hight as it not to clip in the image
                
                #scrollbars "vertical" style "viewport_menu"
                #spacing 5
                
                draggable True
                #edgescroll (100, 500)
                mousewheel True
                arrowkeys True
                
                window:
                    at choice_menu_transition ###Added as test to see if I can transition them in and out?
                    style "menu_window"
                    #xalign 0.5
                    yalign 0.5
                    
                    vbox:
                        style "menu"
                        spacing 2
                        
                        for caption, action, chosen in items:
                    
                            if action:
                        
                                #This is the test code
                                $ randomSTYLE = renpy.random.randint(1, 3)
                                if randomSTYLE == 1:
                                    button:
                                        action action
                                        style "menu_choice_button"
                            
                                        text caption style "menu_choice"
                                        
                                elif randomSTYLE == 2:
                                    button:
                                        action action
                                        style "button_test2"
                            
                                        text caption style "button_text_test2"
                                elif randomSTYLE == 3:
                                    button:
                                        action action
                                        style "button_test3"
                            
                                        text caption style "button_text_test3"
                                    
#                                button:
#                                    action action
#                                    style "menu_choice_button"
#                            
#                                    text caption style "menu_choice"
                            
                            else:
                                text caption style "menu_caption"

                    
                        
            bar value YScrollValue("men_bar") ymaximum 400 style "viewport_menu"

And while it technickly works, it jumps around, so that the styles shift around while I'm reading the options. The idea was simply to have not all buttons look statickly the same. Any Ideas????

Re: Tried to have randomized styles

Posted: Thu Jan 30, 2020 2:47 pm
by namastaii
What happens if you take out the "if action" line (and fix the code's indentation after that)?

Re: Tried to have randomized styles

Posted: Thu Jan 30, 2020 10:11 pm
by philat
Handling randomization in screens is more of a headache than it's probably worth, tbh. Pulling the randomization OUT of the screen is the easier solution. Didn't run this, but it should work. *shrug*

Code: Select all

screen choice(items, randomSTYLE==1): # note the keyword argument passed into the screen (or if not passed in, set to 1 by default)

    frame:
        style "other_frame"
        xalign 0.5
        yalign 0.5
    
        hbox:
            xmaximum 650
            
            viewport id "men_bar":
                xalign 0.5 yalign 0.5
                xysize (600, 400) #Could shorten hight as it not to clip in the image
                
                #scrollbars "vertical" style "viewport_menu"
                #spacing 5
                
                draggable True
                #edgescroll (100, 500)
                mousewheel True
                arrowkeys True
                
                window:
                    at choice_menu_transition ###Added as test to see if I can transition them in and out?
                    style "menu_window"
                    #xalign 0.5
                    yalign 0.5
                    
                    vbox:
                        style "menu"
                        spacing 2
                        
                        for caption, action, chosen in items:
                    
                            if action:
                                button:
                                    action action
                                    style "menu_choice_button"
                                    
                                    if randomSTYLE == 1:
                                        text caption style "menu_choice"
                                    elif randomSTYLE == 2:
                                        text caption style "button_text_test2"
                                    elif randomSTYLE == 3:
                                        text caption style "button_text_test3"
                            else:
                                text caption style "menu_caption"
                    
                        
            bar value YScrollValue("men_bar") ymaximum 400 style "viewport_menu"

label start:
    menu (randomSTYLE = renpy.random.randint(1,3)): # menu arguments: https://www.renpy.org/doc/html/menus.html#menu-arguments
        "Caption"
        "Option1":
            pass
        "Option2":
            pass