Monday 4 October 2010

Menus

Terrastrom v1.0.4 is well on its way, and with it comes prototype menus. This is proving particularly difficult to implement in a generic way, but it's coming along. I have created a Menu class, which hopefully will eventually deal with everything navigation.

I started working on this when I realised I will need pop-up menus for basically every interaction the game will ever do, so it made sense to get this done before continuing with the inventory. Hopefully soon we will begin to see several options when selecting a map object (e.g. talk, attack, pick up, info, etc), and similar when choosing a bag object (drop, eat...).

Because it works with delegates, a menu item can do essentially anything I can think of. This includes creating submenus, which I've just got working. When a new submenu is created, the focus swaps to it without removing the old menu, and the constructor automatically passes a reference to the parent menu, so it can deal with "Back" without having to store any info of how we got to where we are at in the menu.

It's not much to look at, but this was one of the cleverest pieces of code I've written so far so I'm pretty proud. It will feature fairly ubiquitously in the control scheme going forward. It's customisable so the menu panel images, spacing, text position and so on can all be unique to each menu, and it even has support for an optional sprite to go with the text (not shown here).

No comments:

Post a Comment