00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef KEYS_H
00020 #define KEYS_H
00021
00022 #include "SDL_events.h"
00023 #include "game.h"
00024
00025 #include <vector>
00026 #include <map>
00027 #include <string>
00028
00029 const int c_maxparams = 4;
00030
00031 struct Action;
00032 struct ActionType {
00033 const Action* action;
00034 int params[c_maxparams];
00035 };
00036
00037 struct ltSDLkeysym
00038 {
00039 bool operator()(SDL_keysym k1, SDL_keysym k2) const
00040 {
00041 if (k1.sym == k2.sym)
00042 return k1.mod < k2.mod;
00043 else
00044 return k1.sym < k2.sym;
00045 }
00046 };
00047
00048 typedef std::map<SDL_keysym, ActionType, ltSDLkeysym> KeyMap;
00049
00050 class KeyBinder {
00051 private:
00052 KeyMap bindings;
00053
00054 std::vector<std::string> keyhelp;
00055 std::vector<std::string> cheathelp;
00056 public:
00057 KeyBinder();
00058 ~KeyBinder();
00059
00060 void AddKeyBinding(SDLKey sym, int mod, const Action* action,
00061 int nparams, int* params);
00062
00063
00064 void DelKeyBinding(SDLKey sym, int mod);
00065
00066
00067 void Flush() { bindings.clear(); keyhelp.clear(); cheathelp.clear(); }
00068 bool DoAction(ActionType action, bool press);
00069 bool HandleEvent(SDL_Event &ev);
00070
00071 void LoadFromFile(const char* filename);
00072 void LoadDefaults();
00073
00074 void ShowHelp();
00075 void ShowCheatHelp();
00076
00077 private:
00078 void ParseText(char *text, int len);
00079 void ParseLine(char *line);
00080 void FillParseMaps();
00081 };
00082
00083 #endif