Changeset 9880 in orxonox.OLD for trunk/src/lib/event
- Timestamp:
- Oct 10, 2006, 3:42:31 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/event/key_mapper.cc
r9869 r9880 74 74 */ 75 75 KeyMapper::KeyMapping KeyMapper::map[] = { 76 {&KeyMapper::PEV_FORWARD, CONFIG_NAME_PLAYER_FORWARD, SDLK_w},77 {&KeyMapper::PEV_BACKWARD, CONFIG_NAME_PLAYER_BACKWARD, SDLK_s},78 {&KeyMapper::PEV_UP, CONFIG_NAME_PLAYER_UP, SDLK_r},79 {&KeyMapper::PEV_DOWN, CONFIG_NAME_PLAYER_DOWN, SDLK_f},80 {&KeyMapper::PEV_LEFT, CONFIG_NAME_PLAYER_LEFT, SDLK_a},81 {&KeyMapper::PEV_RIGHT, CONFIG_NAME_PLAYER_RIGHT, SDLK_d},82 {&KeyMapper::PEV_ROLL_RIGHT, CONFIG_NAME_PLAYER_ROLL_LEFT, SDLK_z},83 {&KeyMapper::PEV_ROLL_LEFT, CONFIG_NAME_PLAYER_ROLL_RIGHT, SDLK_c},84 {&KeyMapper::PEV_STRAFE_LEFT, "StrafeLeft", SDLK_q},85 {&KeyMapper::PEV_STRAFE_RIGHT, "StrafeRight", SDLK_e},86 {&KeyMapper::PEV_JUMP, "Jump", SDLK_SPACE},87 88 {&KeyMapper::PEV_FIRE1, CONFIG_NAME_PLAYER_FIRE, EV_MOUSE_BUTTON_LEFT},89 {&KeyMapper::PEV_FIRE2, "Fire2", EV_MOUSE_BUTTON_RIGHT},90 {&KeyMapper::PEV_NEXT_WEAPON, CONFIG_NAME_PLAYER_NEXT_WEAPON, EV_MOUSE_BUTTON_WHEELUP},91 {&KeyMapper::PEV_PREVIOUS_WEAPON, CONFIG_NAME_PLAYER_PREV_WEAPON, EV_MOUSE_BUTTON_WHEELDOWN},92 93 {&KeyMapper::PEV_CHANGE_SHIP, CONFIG_NAME_PLAYER_CHANGE_SHIP, SDLK_g},94 95 96 {&KeyMapper::PEV_VIEW0, CONFIG_NAME_VIEW0, SDLK_1},97 {&KeyMapper::PEV_VIEW1, CONFIG_NAME_VIEW1, SDLK_2},98 {&KeyMapper::PEV_VIEW2, CONFIG_NAME_VIEW2, SDLK_3},99 {&KeyMapper::PEV_VIEW3, CONFIG_NAME_VIEW3, SDLK_4},100 {&KeyMapper::PEV_VIEW4, CONFIG_NAME_VIEW4, SDLK_5},101 {&KeyMapper::PEV_VIEW5, CONFIG_NAME_VIEW5, SDLK_6},102 103 {&KeyMapper::PEV_NEXT_WORLD, CONFIG_NAME_NEXT_WORLD, SDLK_x},104 {&KeyMapper::PEV_PREVIOUS_WORLD, CONFIG_NAME_PREV_WORLD, SDLK_z},105 106 {&KeyMapper::PEV_PAUSE, CONFIG_NAME_PAUSE, SDLK_p},107 {&KeyMapper::PEV_QUIT, CONFIG_NAME_QUIT, SDLK_ESCAPE},108 {NULL, "", 0}109 };76 {&KeyMapper::PEV_FORWARD, CONFIG_NAME_PLAYER_FORWARD, SDLK_w}, 77 {&KeyMapper::PEV_BACKWARD, CONFIG_NAME_PLAYER_BACKWARD, SDLK_s}, 78 {&KeyMapper::PEV_UP, CONFIG_NAME_PLAYER_UP, SDLK_r}, 79 {&KeyMapper::PEV_DOWN, CONFIG_NAME_PLAYER_DOWN, SDLK_f}, 80 {&KeyMapper::PEV_LEFT, CONFIG_NAME_PLAYER_LEFT, SDLK_a}, 81 {&KeyMapper::PEV_RIGHT, CONFIG_NAME_PLAYER_RIGHT, SDLK_d}, 82 {&KeyMapper::PEV_ROLL_RIGHT, CONFIG_NAME_PLAYER_ROLL_LEFT, SDLK_z}, 83 {&KeyMapper::PEV_ROLL_LEFT, CONFIG_NAME_PLAYER_ROLL_RIGHT, SDLK_c}, 84 {&KeyMapper::PEV_STRAFE_LEFT, "StrafeLeft", SDLK_q}, 85 {&KeyMapper::PEV_STRAFE_RIGHT, "StrafeRight", SDLK_e}, 86 {&KeyMapper::PEV_JUMP, "Jump", SDLK_SPACE}, 87 88 {&KeyMapper::PEV_FIRE1, CONFIG_NAME_PLAYER_FIRE, EV_MOUSE_BUTTON_LEFT}, 89 {&KeyMapper::PEV_FIRE2, "Fire2", EV_MOUSE_BUTTON_RIGHT}, 90 {&KeyMapper::PEV_NEXT_WEAPON, CONFIG_NAME_PLAYER_NEXT_WEAPON, EV_MOUSE_BUTTON_WHEELUP}, 91 {&KeyMapper::PEV_PREVIOUS_WEAPON, CONFIG_NAME_PLAYER_PREV_WEAPON, EV_MOUSE_BUTTON_WHEELDOWN}, 92 93 {&KeyMapper::PEV_CHANGE_SHIP, CONFIG_NAME_PLAYER_CHANGE_SHIP, SDLK_g}, 94 95 96 {&KeyMapper::PEV_VIEW0, CONFIG_NAME_VIEW0, SDLK_1}, 97 {&KeyMapper::PEV_VIEW1, CONFIG_NAME_VIEW1, SDLK_2}, 98 {&KeyMapper::PEV_VIEW2, CONFIG_NAME_VIEW2, SDLK_3}, 99 {&KeyMapper::PEV_VIEW3, CONFIG_NAME_VIEW3, SDLK_4}, 100 {&KeyMapper::PEV_VIEW4, CONFIG_NAME_VIEW4, SDLK_5}, 101 {&KeyMapper::PEV_VIEW5, CONFIG_NAME_VIEW5, SDLK_6}, 102 103 {&KeyMapper::PEV_NEXT_WORLD, CONFIG_NAME_NEXT_WORLD, SDLK_x}, 104 {&KeyMapper::PEV_PREVIOUS_WORLD, CONFIG_NAME_PREV_WORLD, SDLK_z}, 105 106 {&KeyMapper::PEV_PAUSE, CONFIG_NAME_PAUSE, SDLK_p}, 107 {&KeyMapper::PEV_QUIT, CONFIG_NAME_QUIT, SDLK_ESCAPE}, 108 {NULL, "", 0} 109 }; 110 110 111 111 … … 124 124 */ 125 125 KeyMapper::~KeyMapper () 126 { 127 } 126 {} 128 127 129 128 … … 140 139 void KeyMapper::loadKeyBindings(IniParser* iniParser) 141 140 { 142 if( !iniParser->getSection (CONFIG_SECTION_CONTROL)) 141 IniParser::Section* section = iniParser->getSection (CONFIG_SECTION_CONTROL); 142 if( section == NULL) 143 143 { 144 144 PRINTF(1)("Could not find key bindings " CONFIG_SECTION_CONTROL "\n"); … … 147 147 int* index; 148 148 149 iniParser->firstVar(); 150 while( iniParser->getCurrentName() != "" ) 151 { 152 PRINTF(3)("Keys: Parsing %s, %s now.\n", iniParser->getCurrentName().c_str(), iniParser->getCurrentValue().c_str()); 149 150 for(IniParser::Entry::iterator entry = section->begin(); 151 entry != section->end(); 152 ++entry) 153 { 154 PRINTF(3)("Keys: Parsing %s, %s now.\n", (*entry).name().c_str(), (*entry).value().c_str()); 153 155 // map the name to an sdl index 154 index = nameToIndex ( iniParser->getCurrentValue());156 index = nameToIndex ((*entry).value()); 155 157 // map the index to a internal name 156 this->mapKeys(iniParser->getCurrentName(), index); 157 iniParser->nextVar(); 158 this->mapKeys((*entry).name(), index); 158 159 } 159 160 160 161 161 162 // PARSE MISC SECTION 162 // if( !iniParser->getSection (CONFIG_SECTION_MISC_KEYS))163 // {164 // PRINTF(1)("Could not find key bindings" CONFIG_SECTION_MISC_KEYS "\n");165 // return;166 // }167 //168 // iniParser->firstVar();169 // while( iniParser->getCurrentName() != "" )170 // {171 // PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue());172 // index = nameToIndex (iniParser->getCurrentValue());173 // this->mapKeys(iniParser->getCurrentName(), index);174 // iniParser->nextVar();175 // }163 // if( !iniParser->getSection (CONFIG_SECTION_MISC_KEYS)) 164 // { 165 // PRINTF(1)("Could not find key bindings" CONFIG_SECTION_MISC_KEYS "\n"); 166 // return; 167 // } 168 // 169 // iniParser->firstVar(); 170 // while( iniParser->getCurrentName() != "" ) 171 // { 172 // PRINTF(3)("MISC: Parsing %s, %s now.\n", iniParser->getCurrentName(), iniParser->getCurrentValue()); 173 // index = nameToIndex (iniParser->getCurrentValue()); 174 // this->mapKeys(iniParser->getCurrentName(), index); 175 // iniParser->nextVar(); 176 // } 176 177 } 177 178 … … 205 206 coord[1] = -1; 206 207 int c; 207 if( (c = keynameToSDLK (name)) != -1) { 208 coord[1] = c; 209 coord[0] = 0; 210 } 211 if( (c = buttonnameToSDLB (name)) != -1) { 212 coord[1] = c; 213 coord[0] = 1; 214 } 208 if( (c = keynameToSDLK (name)) != -1) 209 { 210 coord[1] = c; 211 coord[0] = 0; 212 } 213 if( (c = buttonnameToSDLB (name)) != -1) 214 { 215 coord[1] = c; 216 coord[0] = 1; 217 } 215 218 return coord; 216 219 } … … 225 228 { 226 229 for( int i = 0; map[i].pValue != NULL; ++i ) 230 { 231 if( name == map[i].pName) 227 232 { 228 if( name == map[i].pName)233 if( index[0] == 0) 229 234 { 230 if( index[0] == 0) 231 { 232 *map[i].pValue = index[1]; 233 PRINTF(4)("Mapping %s to '%s' (id %i)\n", name.c_str(), SDLKToKeyname(index[1]).c_str(), index[1]); 234 break; 235 } 236 else { 237 *map[i].pValue = index[1]; 238 PRINTF(4)("Mapping %s to '%s' (id %i)\n", name.c_str(), SDLBToButtonname(index[1]).c_str(), index[1]); 239 break; 240 } 235 *map[i].pValue = index[1]; 236 PRINTF(4)("Mapping %s to '%s' (id %i)\n", name.c_str(), SDLKToKeyname(index[1]).c_str(), index[1]); 237 break; 238 } 239 else 240 { 241 *map[i].pValue = index[1]; 242 PRINTF(4)("Mapping %s to '%s' (id %i)\n", name.c_str(), SDLBToButtonname(index[1]).c_str(), index[1]); 243 break; 241 244 } 242 245 } 246 } 243 247 } 244 248 … … 251 255 PRINT(0)("\n==========================| KeyMapper::debug() |===\n"); 252 256 for(int i = 0; map[i].pValue != NULL; ++i) 253 254 255 257 { 258 PRINT(0)("%s = %i\n",map[i].pName.c_str(), *map[i].pValue); 259 } 256 260 PRINT(0)("=======================================================\n"); 257 261 }
Note: See TracChangeset
for help on using the changeset viewer.