Learn Objective-C on the Mac - Mark Dalrymple [58]
Next, let’s tackle the Allowed Character Classes checkboxes. For each of these, we’ll make up a new key name, and use it to bind the Selected status to a value in the user’s application preferences. Click on the first cell, Paladin. You should see that the Inspector title changes to Button Cell Bindings. If not, click on the button again until you get there. Now bind this button cell’s Value attribute to the “characterClassAllowedPaladin” key. Repeat these steps for each of the remaining button cells, binding each of them via Shared User Defaults Controller with the appropriate key name. Bard should be bound with the “characterClassAllowedBard,” Fighter with “characterClassAllowedFighter,” and so on. When you get to Magic-User, for the sake of consistency, use the key name “characterClassAllowedMagicUser,” leaving out the “-” symbol.
Bindings for Monster Generation
Now switch over to the Monster Generation tab. Bind the Value of the slider to “monsterBootyFrequency,” and do the same for the small text field to the right. Then configure the checkboxes, the same way you did on the Character Generation tab. Click on the Orc checkbox until the checkbox itself is selected, and bind its Value to “monsterTypeAllowedOrc.” Continue through the rest of the checkboxes, binding the Value for each of them to the appropriate key name: “monsterTypeAllowedGoblin,” “monsteryTypeAllowedOgre,” and so on.
Bindings for Dungeon Generation
Finally, switch to the Dungeon Generation tab, which contains just three slider and text field pairs. To the right of the Tunnel Twistiness label, configure the Value bindings for both the slider and the text field to “dungeonTunnelTwistiness.” Bind both of the Monster Frequency controls’ Values to “dungeonMonsterFrequency,” and both of the Treasure Frequency controls’ Values to “dungeonTreasureFrequency.”
Create the Main Window
Now it’s time to pay some attention to our main window, which will contain buttons the user can click to generate the characters, monsters, and dungeons, and text fields to display the results. Click the main window’s title bar (or double-click its icon in the main window if it’s not already visible) and bring up the Size Inspector (⌘3). Change the window size to 731 by 321, then switch to the Attributes Inspector (⌘1) and click to turn off the Resize checkbox, which will give us one less thing to worry about. This application displays a limited data set, so there’s no reason for the user to make the window any bigger. We’re now going to create three sets of GUI components, one set for each of the three types of data we’re dealing with. We’ll manually lay out the first set, then duplicate it for the other two.
First we’ll create a text field inside a box for displaying results. Go to the Library window and enter “nsbox” into the search field. Look for the Box in the results, and drag one of these out to your window. While the new box is selected, switch back to the Size Inspector, and set the box’s size to 227 by 247. While you’re at it, go ahead and set each of its X and Y values to 20. This puts the box in the lower-left corner of the window, in the position it would be in if you dragged it to the lower left and let it sit where the blue guidelines recommend. Then switch back to the Attributes Inspector, and set the Title Position to “None” so that the title won’t be shown.
Now, go back to the Library and search for “label.” One of the results is Wrapping Label; grab that, drag it so that it is directly overlapping the box you created, and let go. Doing this puts it “inside the box.” Once it’s there, expand the label to fill the box, by first dragging its bottom left corner down to the lower left, then dragging its top right corner to the upper right. In both cases, the blue guidelines will show up when you’re just the right distance from the edge of the box. Finally, triple-click to select the text (“Multiline Label”) in the text field, and press