I'm starting my re-organization of the GameGUI now in the
gamegui_rewrite_2007 branch.

My first task is to cleanup the keyboard handling, so that its coherent, and
ultimately more flexible. What I've done is make a class like this:

///This class is meant to do keyboard management, handling keyboard
shortcuts, layouts and such for GameGUI
class KeyboardManager
{
public:
   ///Constructs a keyboard manager
   KeyboardManager();

   ///Returns the integer action accossiatted with the provided key. Often
it may be
   ///nothing, or it may wait for another key to be pressed, etc.
   Uint32 getAction(SDLKey key);

   ///Sets the defaults for a keyboard layout
   void setToDefaults();

   ///Saves the keyboard layout
   void saveKeyboardLayout();

   ///Loads the keyboard layout
   void loadKeyboardLayout();
private:
   std::map<SDLKey, Uint32> singleKeys;
   std::map<SDLKey, std::map<SDLKey, Uint32> > comboKeys;
   SDLKey lastPressedComboKey;
};

Its basic right now, doesn't have support for Ctrl/Shift/Alt combinations
(but will if they are needed), but handles the basic need for organization.
Everything keyboard related will go through this class and its layouts. You
might be wondering about the Uint32's that are reffering to actions. They
are hear:

///This namespace stores everything related to the key actions that can
occur at key-press
///in GameGUI
namespace GameGUIKeyActions
{
   ///Initiates the names and reverse names for each key action
   void init();

   ///This is the enum of key actions
   enum
   {
       DoNothing = 0,
       ShowMainMenu,
       UpgradeBuilding,
   };

   ///Gets the name of a key-action from the integer
   const std::string getName(Uint32 action);

   ///Reverses a name of a key action back to its integer
   const Uint32 getAction(const std::string& name);

   extern std::vector<std::string> names;
   extern std::map<std::string, Uint32> keys;
};

The design is simple, similar in feel to the IntBuildingType classes. The
idea hear is that every sort of action done by a keyboard will be in that
list. The getName function returns a simple, English name for the action,
which is used when writing to a layout file, and when referencing
translation texts, analogous to the way they are used now in the settings
screen.

I decided to go this route as (while some consider it not very clean), its
very easily maintained and easy to understand, and it can easily be
completely customized for internationalization. If you have suggestions,
please offer.

--
Really. I'm not lieing. Bradley Arsenault.
_______________________________________________
glob2-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/glob2-devel

Reply via email to