Providing visual information for an item
Whenever a portable container displays or repaints an item in the container, it signals the visualInfoRequested event. You can create an event-to-script connection for this event to change what the container displays for the item. Of course, if no such connection exists, the container uses the defaults specified in its settings notebook to display the item. Let's take advantage of this event to show an icon for the card's suit whenever it is face-up or the icon representing the back of the card when it is face-down.
Switch to the Script Editor view for the BlackJackGameView part and add a playerCount instance variable. You will use this variable later when creating a player's hand. When you are through, the class definition looks like the following:
AbtAppBldrView subclass: #BlackJackGameView
instanceVariableNames: 'playerCount '
classVariableNames: ''
poolDictionaries: ''
Add the following public instance script:
cardIcon: infoData
"Set the icon and label for the card item."
| card |
card := infoData item.
infoData icon: card icon.
infoData label: card faceValue.
Any script that is connected to the visualInfoRequested event must support a parameter, which is the object that represents the item to the container. This object has several attributes including:
The item in the ordered collection that this object represents
The icon to be used when displaying the item
The label to be used when displaying the item
The script you just added gets the infoData's item attribute, which is a card, and then queries the card object to get the icon and label attributes to be used to display the item.
Switch back to the Composition Editor view and connect the container's visualInfoRequested event to the cardIcon: script. Save the part and then select Test iconto test it. You should be able to distinguish the four suits in the deck by the icons used for each card. Flip the deck and all the cards will show the same icon with no label for the card.
Last modified date: 06/11/2018