- Sep 30, 2018
- 102
- 70
Ok, it follows a first thread about ToggleDict.
The first was simple but now, the reality is I have some conditions or some controls before using ToggleDict correctly.
I tried to use action instead of Toggle, but when I do it, I have no more the effects of textbutton style.
Ok, the following code works fine, except the conditions of "updateCounter" function are not applied.
I hope someone will understand what I want to do, maybe Toggle isn't the answer, I don't know.
In updateCounter, I tried "return [False, True]" thinking it can take the place of originals True, False arguments of Toggle, but in fact, I think the call of my function does nothing and ToggleDict uses its default values, True and False
The first was simple but now, the reality is I have some conditions or some controls before using ToggleDict correctly.
I tried to use action instead of Toggle, but when I do it, I have no more the effects of textbutton style.
Ok, the following code works fine, except the conditions of "updateCounter" function are not applied.
I hope someone will understand what I want to do, maybe Toggle isn't the answer, I don't know.
Python:
init python:
class Item:
def __init__(self, id, name=""):
self.id = id
self.name = name
def updateCounter(idToSelect):
if store.counterSelected != MAX_SELECT:
store.listSelected[idToSelect] = not(store.listSelected[idToSelect])
if store.listSelected[idToSelect] == True:
store.counterSelected += 1
return [True, False]
elif store.counterSelected != 0:
store.counterSelected -= 1
return [False, True]
elif store.listSelected[idToSelect] == True:
store.listSelected[idToSelect] = False
if store.counterSelected != 0:
store.counterSelected -= 1
return [False, True]
return [False, True]
define listItems = [(Item(0, name="Item01")), (Item(1, name="Item02")), (Item(2, name="Item03")), (Item(3, name="Item04")), (Item(4, name="Item05"))]
default listSelected = dict()
default counterSelected = 0
define MAX_SELECT = 3
label start():
python:
for _var in listItems:
store.listSelected[_var.id] = False
call screen selectItems(listItems)
screen selectItems(listOf):
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
key "game_menu" action [Rollback(),With( dissolve)]
screen displayItems(listOf):
$ _xpos = 860
$ _ypos = 220
for eltItems in range(len(listOf)):
textbutton listOf[eltItems].name xpos _xpos ypos _ypos:
action [ToggleDict( listSelected, eltItems, Function(updateCounter,eltItems))]
style "displayItems_button"
$ _ypos += 35
# For debug
text "{color=#ffffff}counterSelected = [counterSelected] {/color}"
style displayItems_button is button
style displayItems_button_text is button_text:
idle_color "#000000" # BLACK NORMAL
hover_color "#ffffff" # WHITE HOVER
selected_idle_color "#550001" # RED SELECTED
selected_hover_color "#550001" # RED SELECTED