Adding a pop-up menu
Let's use a pop-up menu to add the game playing mechanics needed by a Black Jack player.
Add a Pop-up Menu part to the free-form surface. Add two Menu Choice parts to the pop-up menu part. Change the labels on the menu choices to Flip selected and Take a card. Connect the container's menu attribute to the pop-up menu's self attribute.
Switch to the Script Editor view and add the following public instance script:
flipSelected
"Flip the selected cards in the container."
(self subpartNamed: 'Container Details1')
selectedItems do: :card |
card flip].
(self subpartNamed: 'Container Details1')
refreshItems:
(self subpartNamed: 'Container Details1') selectedItems.
Complete the part by making the following connections:
1. Connect the toggle button's selection attribute to the container's refreshEntireListOnChange attribute.
2. Connect the Flip selected menu item's clicked event to the flipSelected script.
3. Connect the Take a card menu item's clicked event to the Card Deck variable's deal:to: action. Complete this connection by setting its parameters as follows:
a. Open the connection's settings and enter 1 in the count field.
b. Connect the Player Hand variable's self attribute to the connection's aCardDeck attribute.
When you are done, your connections should look like this:
Connections to menus
Save the part and close the Composition Editor for the BlackJackPlayerView part.
Last modified date: 06/11/2018