/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Patrick Boenzli co-programmer: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_EVENT #include "event.h" using namespace std; /** \brief standard constructor \todo this constructor is not jet implemented - do it */ KeyMapper::KeyMapper () { this->setClassID(CL_KEY_MAPPER, "KeyMapper"); } /** \brief standard deconstructor */ KeyMapper::~KeyMapper () { // delete what has to be deleted here } /** \brief loads new key bindings from a file \param filename: The path and name of the file to load the bindings from */ void KeyMapper::loadKeyBindings (const char* fileName) { FILE* stream; PRINTF(4)("Loading key bindings from %s\n", fileName); // remove old bindings if present if( this->keyAliases != NULL) { free (this->keyAliases); this->keyAliases = NULL; } // create parser IniParser parser(fileName); if( parser.getSection (CONFIG_SECTION_PLAYER "1") == -1) { PRINTF(1)("Could not find key bindings " CONFIG_SECTION_PLAYER"1 in %s\n", fileName); return; } // allocate empty lookup table this->keyAliases = (KeyBindings*) calloc (1, sizeof (KeyBindings)); char namebuf[256]; char valuebuf[256]; memset (namebuf, 0, 256); memset (valuebuf, 0, 256); int* index; while( parser.nextVar (namebuf, valuebuf) != -1) { //index = nameToIndex (valuebuf); int c; if( (c = keynameToSDLK (valuebuf)) != -1) { index[1] = c; index[0] = 0; } if( (c = buttonnameToSDLB (valuebuf)) != -1) { index[1] = c; index[0] = 1; } switch( index[0]) { case 0: PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf); strcpy (this->keyAliases->keys[index[1]], namebuf); break; case 1: PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf); strcpy (this->keyAliases->buttons[index[1]], namebuf); break; default: break; } memset (namebuf, 0, 256); memset (valuebuf, 0, 256); } // PARSE MISC SECTION if( parser.getSection (CONFIG_SECTION_MISC_KEYS) == -1) { PRINTF(1)("Could not find key bindings in %s\n", fileName); return; } while( parser.nextVar (namebuf, valuebuf) != -1) { //index = nameToIndex (valuebuf); int c; if( (c = keynameToSDLK (valuebuf)) != -1) { index[1] = c; index[0] = 0; } if( (c = buttonnameToSDLB (valuebuf)) != -1) { index[1] = c; index[0] = 1; } switch( index[0]) { case 0: PRINTF(4)("Key binding %d(%s) set to %s\n", index[1], SDLKToKeyname( index[1]), namebuf); strcpy (keyAliases->keys[index[1]], namebuf); break; case 1: PRINTF(4)("Button binding %d(%s) set to %s\n", index[1], SDLBToButtonname( index[1]), namebuf); strcpy (keyAliases->buttons[index[1]], namebuf); break; default: break; } memset (namebuf, 0, 256); memset (valuebuf, 0, 256); } }