bryanedds

Well, I've hit a wall with my game's development, and since there was no GUI with XNA 1.0, I've decided to go ahead and make my own GUI system. I implemented a lot of mechanics for my game, but I need greater interaction to proceed development in a sane manner.

So far I've just implemented the text drawing stuff from scratch. It uses only monospace fonts generated with BMFontGenerator without using the generated .xml file. It's decidedly minimal to use only monospace fonts, but keep in mind two things - 1) my particular game doesn't require anything more robust than monospace fonts and 2) a game's engine should be designed around the game's specifc requirements. Otherwise you're scope creepin. I remind myself constantly not to let cool tech get in the way of my cooler game.

Tomarrow I'll probably bust out the GUI border system. I've still not decided how to handle events yet... I have my own purely OO way of doing things that work great in any OO langauge, and I pause to use c# built-in event facilities (events, delegates, etc). I just don't see why I would use those facilities when I can seem to more easily and simply do events in a classical OO way... No broke, no fix...

GUI development could be a bit of a trudge... but oh well :P At least XNA will make it as rapid a trudge as possible! If anyone would like to help out, let me know on this thread. I've implemented two GUI systems from scratch in C++ before, so I know pretty well what I'm doing :)




Re: XNA Game Studio Express Starting work on my GUI system

Jim Perry

I've started doing the same thing as the games I have planned need dialogs at the very least. I'd be happy to contribute so we all could benefit. Let me know what you need and I'll see what I can do.




Re: XNA Game Studio Express Starting work on my GUI system

andyfraser

Can I suggest that high on the list of priorities for a UI would be that it is skinnable. I think it is really important that the UI match the style of the game and it also means that all our XNA games don't look the same

Andy





Re: XNA Game Studio Express Starting work on my GUI system

Jim Perry

 andyfraser wrote:
Can I suggest that high on the list of priorities for a UI would be that it is skinnable. I think it is really important that the UI match the style of the game and it also means that all our XNA games don't look the same

Agreed! This is a priority IMO and probably not tough to take into account. Coming up with layout requirements for allowing skins shouldn't be difficult.

edit: this article might be something to take into consideration.






Re: XNA Game Studio Express Starting work on my GUI system

bryanedds

Skins are a definite.

Jim, I'll give you an e-mail :)






Re: XNA Game Studio Express Starting work on my GUI system

bryanedds

I checked the website you linked to. It's structured somewhat similar to my last GUI system. Probably the most contraversial thing about my GUI system is that it will only use the GameComponent framework in a minimal way. The GUIManager (to which only one GuiScreen can be set at a time) will be an actual GameComponent, but the actual GuiComponents and GuiScreens won't touch the GameComponent interfaces or classes. I have my own way of doing these things at that level. So if you can dig that, you may still want to help me out with my GUI stuff :)


As I said, I'll give you an e-mail :)






Re: XNA Game Studio Express Starting work on my GUI system

Jim Perry

It's fine if the GuiScreens aren't components. The manager being one is probably good enough. Looking forward to coming up with something. If you want to chat on IRC or some such about it let me know, maybe the #mdxinfo channel on irc.afternet.org. I'm usually there almost every night with the nick of Machaira.




Re: XNA Game Studio Express Starting work on my GUI system

Glenn Wilson

One thing I would like to suggest is that if you are going to start a group project or the like on a GUI system that we think of starting a community project on www.codeplex.com for an XNA GUI.

Any Thoughts.






Re: XNA Game Studio Express Starting work on my GUI system

bryanedds

Great suggestion. I've visited the site. Quite nice. You want to help with the GUI system too I need to crank out the core framework, then I'll be ready to get some other hands on the deck to make the high level components and such. Shouldn't take long at all.






Re: XNA Game Studio Express Starting work on my GUI system

bryanedds

Well, I've finished the GUI border system. It uses Sprites from my 2.5D engine, so it can be 2D animated or use 3D models. I took extra care with the start of the GUI skinning system. It allows SkinnableEntities like GuiComponent to be tracked and dynamically reskinned with the call of a single method. To change from an animated 2D skin to a 3D modeled skin for all of your GuiComponents require only two method calls. Quite nice so far, and extremely usable and extensible.

I also finished the GuiBackground object too. It's works the same as the GuiBorder in terms of power and skinability.

Looks like it's time to go ahead and make the actual GuiComponent class now ;)






Re: XNA Game Studio Express Starting work on my GUI system

Jim Perry

Sweet. Can't wait to get some controls up and running.




Re: XNA Game Studio Express Starting work on my GUI system

bryanedds

One thing that is going to be an interesting challenge is making the GUI work well with game pad input. I'm guessing that directional input could be used as a special sort of "directional tabbing" between components with the Accept and Cancel buttons being automatically mapped to certain game pad buttons. If anyone has any thoughts about this approach, or ideas on a different approach, please let me know :)

Another problem is that mouse events can be skipped when the frame rate runs low. Because the mouse state is polled, I'm pretty sure that a mouse click during a skipped frame won't be detectable by checking the mouse state. Are there actual mouse events that I can listen to instead of relying on the polled mouse state Or am I just imagining this problem






Re: XNA Game Studio Express Starting work on my GUI system

waheyluggage

Hi
 
I've worked on a cross platform (PC\Consoles) gui system before and the what I did was run everything off a fake internal mouse pointer.  For the PC the pointer position and buttons were fed in from the actual mouse whereas the consoles had two options...
 
1) Attach the pointer to directional controls or an analogue stick.  This gave you one of those clumsy mice that are controlled by a pad and attach a pad button to left\right\middle clicks.  This would get you a cross platform fuctioning interface albeit a clumsy one.
 
Or...
 
2) Move the (invisible) pointer to the center of a button.  Each button had a set of controls which would tell it what to do when a direction was pressed.  Imagine a menu that looked like...
 
  START
   HELP
   QUIT
 
And the code for these two buttons was...
 
// if I press Down while on the startButton move the pointer to the center of the helpButton, if I press Up wrap round to the quitButton.
GuiButton_SetDownPressedAction( startButton, helpButton );
GuiButton_SetUpPressedAction( startButton, quitButton );
 
// if I press Down while on the helpButton move the pointer to the center of the quitButton, if I press Up move to the startButton.
GuiButton_SetDownPressedAction( helpButton, quitButton );
GuiButton_SetUpPressedAction( helpButton, helpButton );
 
// if I press Up while on the quitButton move the pointer to the center of the helpButton, if I press Down wrap round to the startButton.
GuiButton_SetDownPressedAction( quitButton, startButton);
GuiButton_SetUpPressedAction( quitButton, helpButton );
 
This way you could still tie everything to a mouse controlled system so all your highlights, click messages, etc would still work, you just set up the button presses to act like shortcuts.  On a PC you could either not fire those events or make the keyboard fire them.
 
 
Button presses were handled the same, I went for a callback similar to the windows one where events were passed in so you'd attach a callback to a created window then if you press 'action' (for the PC this was mouse left click and console it was button A) everything would work like a charm.  Essentially the only difference between the console and PC was having those Up, Down, Left, Right, etc set up to tell the gui where to move the mouse to.  We tied those into the cursors\gamepad n the PC so you could operate the menus without needing the mouse if it suited the game. 
 
Another thing we added was a default button when a window got focus.  This was a message sent to the callback so you'd set the current pointer position to 'startButton' so that would be highlighted when you first began. 
 
A list control was added by having it create a window and add, subtract buttons to it.  The window would scroll when it needed to and the pad events were set up automatically as it was obvious which ones go to which.  There was a flag to say whether it should wrap and that was it.  A drop down box was exactly the same but was only visible when you clicked the drop down item.  We did tinker with having the controller events set themselves up automatically but found with all the different uses the GUI was getting it was difficult to get it right all of the time.  Sometimes what seemed like a logical jump turned out to be one you just didn't want to make.  It also had troubles with the example above where you want a menu to wrap around. 
 
The last thing was something we had to stick to which was while on a menu screen like the frontend in the bottom right corner for a console you'd have something like a picture of a start button with "OK" so when you pressed Start it would continue past that screen.  On the PC it would be clumsy having to press a button that simulated start so we made it a standard button you click on.  While the actual thing was a button, there wasn't a pad control set up that would allow the console user to get to it by pressing a direction as this would be clumsy for them.  The solution was to set up a pad press to activate that button and behave like a click.
 
eg..
GuiButton_SetActivate( okButton, PAD_START );
 
and we had the same for a back button which was displayed in the lower left corner...
GuiButton_SetActivate( backButton, PAD_BACK );
 
We could also have PAD_START activated by pressing Enter on the keyboard for the PC and PAD_Back by pressing Escape (or by using a PC pad).  Internally it just moved the pointer to the button it was on and send a click message.
 
Phew - I've rambled on a bit but I hope it's given you a few ideas. 
 




Re: XNA Game Studio Express Starting work on my GUI system

Jim Perry

For a window the developer should pick which buttons are the Accept and Cancel (normally A and B). As far as tabbing, that's another thing the developer of the window would specify, it's not something we need to worry about. It could be something as simple as a Hashtable with a tab order index and control reference for the key/value.

XNA doesn't provide any mouse events, it's all driven off polling. I can imagine someone would press a control faster than can be detected unless the game is realllllyyyyy slow, in which case, the player has bigger problems than the GUI.






Re: XNA Game Studio Express Starting work on my GUI system

bryanedds

Thanks for all of the ideas guys!

Unfortunately, I got stuck on some ugly side issues today. But everything seems to be cleared(ish) up now. I started working on the main GuiComponent, but got stuck. Now I can resume moving forward.

One thing neat I've just implemented is a virtual pixel system. It allows everything to stay the same size no matter what resolution the game is in. Right now the virtual pixels go from (0,0) to (128,96). Such a low max might be exhibit too little granularity, so I may make it (1280, 96). This helps not only with the GUI system, but with everything else in the game. I really should not have put off making this for so long, but... meh. So it goes :)

I'm thinking about omitting the Model portion of the MVC design for the GUI system. I've made two GUI systems, and the whole time I have not ONCE used the model in any useful way. Theoretically, the Model component looks handy and neat... but it just never gets used! We'll see how it goes :)