- Sep 30, 2018
- 102
- 70
Code first, explain following
Goal is to have list of textbutton which represents list of spells (for sample). you can choose 5 out of 10 by clicking the textbutton.
Clicking textbutton should changed font of button and particularly increase _counter
What happened here :
at beginning, all datas in list_select are false, normal. But when you click one button, all datas are assigned to True when only the one that is clicked takes the good style "checkbox_button".
So, action seems to be executed for each elt in the loop, while rest of textbutton is correctly assign at the only one I click.
Why, why, why ? An idea ?
Python:
default _var = None
default _counter = 0
default list_select = dict()
label start:
python:
for _var in listOfSpells:
store.list_select[_var.id] = False
call screen setupHero(listOfSpells, maxItems=5)
screen setupHero(listOf, maxItems=1):
modal True
zorder 200
add "gui/overlay/confirm.png"
add "gui/setup.png" pos (800, 100) size (950,600)
use displayItems(listOf)
textbutton _("Ok") action [Return(True), With( dissolve)] xpos 950 ypos 610
textbutton _("Cancel") action [Rollback(),With( dissolve)] xpos 1500 ypos 610
## Right-click and escape answer "no".
key "game_menu" action [Rollback(),With( dissolve)]
screen displayItems(listOf):
$ _var = 0
$ _xpos = 860
$ _ypos = 220
for _var in range(len(listOf)):
textbutton listOf[_var].name xpos _xpos ypos _ypos:
action [ToggleDict( list_select, _var, True, False ), updateCounter()]
style "checkbox_button"
hovered ShowTransient("ttSelectItems", msg=listOf[_var].description)
unhovered Hide("ttSelectItems")
$ _ypos += 35
# For debug
text "{color=#ffffff}_counter = [_counter] {/color}"
python:
def updateCounter():
store._counter = 0
for _var in store.list_select:
if store.list_select[_var] == True:
store._counter += 1
Clicking textbutton should changed font of button and particularly increase _counter
What happened here :
at beginning, all datas in list_select are false, normal. But when you click one button, all datas are assigned to True when only the one that is clicked takes the good style "checkbox_button".
So, action seems to be executed for each elt in the loop, while rest of textbutton is correctly assign at the only one I click.
Why, why, why ? An idea ?
Last edited: