Wednesday, February 24, 2010

GUI & Map Editor - A Match Made In Heaven?

Now I don't no if you have ever tried to make a game using Allegro & C++, but if you have it probably starts something like this:
  1. Great idea!
  2. Some sort of very rough mental planning
  3. Sit down to code
  4. Realise you need something to make the levels with because your levels are going cool storing them in a text file just wont cut it
  5. Now you realise you need to program some sort of GUI interface because hard coding everything is ugly and a pain in the arse to edit
  6. Get bored and realise your game wasn't so great after all
Well, that's my usual pattern any way. If you've been there I feel for you, but luckily for me things are really coming along! I'm not sure if it's the few years break I have in between programming that forces me to relearn a few things, and lose some of my previous bad habits, or if it's just this time things make a little more sense.



The video above shows some of the progress I've made, but doesn't really do it justice. Most of the important things are in the code. As you can see things are very far from being finished let alone polished so forgive the rubbish graphics and let me explain a little bit about how the GUI works, I'll use the moveable GUI Window in the video as an example.

The GUI Window is derived from a GUI Object. The only addition the Window has (you might have guessed), is that it's drawn with a background and title bar and can be moved around. The GUI Object itself has a vector of GUI Elements which it looks after by calling their respective input, logic and drawing routines. When each GUI Element is added to the GUI Object it's given a callback function which is triggered (depending on its own conditions, for example the "Buttons" you see in the video is a mouse click) within either the elements logic or input functions. This keeps everything nice and encapsualted so all the engine has to worry about is calling the GUI Objects input,logic,draw functions. I hope at least some of that made sense, it felt like a right mouthful.

The main aim of the GUI system is so that elements add specialised functionality through the way their callback functions are triggered, and the objects themselves (which handle the elements) can use these to create more complicated GUI Objects. I will have some examples of these in my next update, most likely the scrollbar, which will be made up of 2 GUI Elements, the 2 buttons at either end. I will add functionality for the drawing of the bar and position within the object itself (or atleast that's what I think in my head anyway).

I won't go on about the map just yet, because that's still way to incomplete, but you might have noticed I have the save and load functions working correctly (even if it is only the map name you see changing).

So until the next time, if you can't be good, be careful!

No comments:

Post a Comment