Page 1 of 1

Position choice boxes based on order in a spaced circle

Posted: Tue May 26, 2020 5:38 pm
by abysswatcher
I was wondering if there is a way where I could arrange choice boxes into a circle formation by specifying like:

Code: Select all

if i==1:
xalign 0.5 yalign 0.5
you get the gist and so I was wondering how I would do that since I want to position the buttons around a circle based on their enumerate value.

Re: Position choice boxes based on their enumerate

Posted: Tue May 26, 2020 6:18 pm
by Imperf3kt
I looked up the definition of 'enumerate', but I'm still confused.
Do you want a fixed number of buttons positioned in a circle, or are you trying to make buttons only appear in certain positions and not all the buttons will be used sometimes so you need them to move one space clockwise / anticlockwise when an empty space is present?

Re: Position choice boxes based on their enumerate

Posted: Tue May 26, 2020 6:50 pm
by abysswatcher
Imperf3kt wrote: Tue May 26, 2020 6:18 pm I looked up the definition of 'enumerate', but I'm still confused.
Do you want a fixed number of buttons positioned in a circle, or are you trying to make buttons only appear in certain positions and not all the buttons will be used sometimes so you need them to move one space clockwise / anticlockwise when an empty space is present?
I am looking at the latter. So I want the first button to appear in one position, the second button in another position and so on. No all of them will be used so I will need to move the spaces to make them balanced. I'm trying to see how I can achieve that.

Re: Position choice boxes based on order in a spaced circle

Posted: Tue May 26, 2020 8:28 pm
by gas
Step 1:
You should know in advance what buttons to show. So the best thing to do is to have a list or something like that.
So, for example, computing the active locations or the available commands and put them in a list.

Step 2:
This one show your list of buttons automatically arranged as a circle, whatever their number.
viewtopic.php?f=8&t=25604#p313971

Re: Position choice boxes based on order in a spaced circle

Posted: Wed May 27, 2020 3:34 am
by abysswatcher
So I did some digging and tried out some methods and came out with this:

Code: Select all

screen choice(items):
    style_prefix "choice"
    $import math
    $center_x = 960
    $center_y = 540
    $radius = 400
    $button_idx = 0
    $button_info = [("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction()),
                    ("gui/button/choice_idle_background.png", "gui/button/choice_hover_background.png", NullAction())]
    for i in items:
      $angle = button_idx * math.pi * 2 / len(button_info)
      $x = math.cos(angle) * radius + center_x
      $y = math.sin(angle) * radius + center_y
      textbutton i.caption action i.action xanchor 0.5 yanchor 0.5 xpos int(x) ypos int(y)
      $button_idx += 1
    add "gui/choice_circle.png" xpos 960 ypos 540
The only issue is this if the text caption is longer or shorter it affects how far away from the center it is which can make some wobbly circles. How would I make sure that the beginning of the textbutton always hugs a tight circle? ANother issue is the overlap that occurs when the caption is long. How can I avoid overlap? Is there a way I can make sure with the length of the caption I can change the calculations?

Re: Position choice boxes based on order in a spaced circle

Posted: Wed May 27, 2020 6:48 am
by gas
Try to solve the issue by setting a fixed size for buttons.

Code: Select all

textbutton i.caption action i.action xanchor 0.5 yanchor 0.5 xpos int(x) ypos int(y) xsize 150 text_align 0.5
The xsize property set a fixed size for all buttons. Change it to your needs.
As for longer texts, there's no way to solve the issue of having a very long text compared to others. Why not use abbreviations? So, for example, Instead of EASTERN EUROPE you can use E-EUROPE. That's the only way that come to my mind for a good ergonomy.