Dynamic Toolbar and TabViews Wide
Work Area > Dynamic Toolbar and TabViews

This document is under construction, or I should say, it's just like a diary or note...

Preferences.jpg SIZE:441x368(?KB)

How long does it take to make a preference window like this from scratch? Prpbably about a half day? Then you are a great programmer. In MiniKidsGames, it takes only a few minutes. Only a several lines of code wille make the sheet in this preference window. Moreover, the toolbar is customizable so you can change the order of icons, size, and stuff like that.

To make this possible, I wrote some RubyCocoa classes that dynamically create a toolbar and tab views that collaborate one another (source code is available from MinikidsGames' svn repository). These classes collect all the subclasses of Game to read preference names, options, and default values. It, then, automatically creates the preference window with a toolbar and tab-viewed per-game preference sheets. Every UI controls is aligned automatically so no extra nib files or other external files are needed. All you have to do is to write the code like this:

# The code that generates the preference sheet above
class Words < Game
 # (snip)
 def self.title() "Words And Images" end
 def self.titleImage() "Words" end
 def self.getPreferenceItems()
   return [SelectablePreference.new('Speed', ['slow', 'normal', 'fast'], 'normal'),
           BoolPreference.new('Shadow', true),
           BoolPreference.new('Speech', true),
           BoolPreference.new('Sound', true),
           StringPreference.new('Name', 'Tat'),
           PathPreference.new('BGM', 'WordsGame.m4a'),
           FontPreference.new('Font', 'Marker Felt')]
  end
end

The heart of this code is the PreferenceItem objects (like BoolPreference or StringPreference). Preferenceitem represents preference name, default value, and available options (if needed). The Toolbar class also referes to the title and the image of each game for showing these on the preference window. You don't have to worry about loading and saving the preferences, MiniKidsGames will do that for you. Moreover, most of the options are effective on-the-fly.

Before I create this one, I tried both XmlToolbar and SS_PrefsController. Though these help developers a lot in creating such a preference window, it's not enough for me since developers need to write some code to make their own preference sheets. Moreover, sometimes they need to create some nib files or xml files to connect the toolbar and tabviews. As I want MiniKidsGames (and The Game Framework) to be more fun-to-develop environment, I don't want to make game developers write a few hundres lines of code and xml / nib files. What I really want is more dynamic preference window that requires only the representation of preference items, just like this one does.

I'm working on adding more PreferenceItems such as TableView, ListView or things like that. I hope I have more time to do this soon.

To be continued, hopefully

Leave a comment

Begin the comment with //pukiwiki if you want to write a comment in PukiWiki format.

You must be logged in to post a comment.