#include <keyboard.h>
Collaboration diagram for Keyboard:
Public Types | |
KEY_PRESSED | |
KEY_RELEASED | |
KEY_REFRESH | |
enum | Key_Event_t { KEY_PRESSED, KEY_RELEASED, KEY_REFRESH } |
Public Member Functions | |
Keyboard () | |
void | HandleKeyEvent (const SDL_Event *event) |
void | Reset () |
void | TestCamera () |
void | Refresh () |
void | SetKeyAction (int key, Action::Action_t at) |
int | GetKeyAssociatedToAction (Action::Action_t at) |
Private Member Functions | |
void | HandleKeyPressed (const Action::Action_t &action) |
void | HandleKeyReleased (const Action::Action_t &action) |
Private Attributes | |
std::map< int, Action::Action_t > | layout |
bool | PressedKeys [Action::ACTION_LAST] |
Static Private Attributes | |
static Keyboard * | singleton |
Definition at line 31 of file keyboard.h.
Definition at line 47 of file keyboard.h.
00048 { 00049 KEY_PRESSED, 00050 KEY_RELEASED, 00051 KEY_REFRESH 00052 } Key_Event_t ;
Keyboard::Keyboard | ( | ) |
Definition at line 52 of file keyboard.cpp.
00053 { 00054 //Disable repeated events when a key is kept down 00055 SDL_EnableKeyRepeat(0,0); 00056 }
int Keyboard::GetKeyAssociatedToAction | ( | Action::Action_t | at | ) |
Definition at line 70 of file keyboard.cpp.
00071 { 00072 std::map<int, Action::Action_t>::iterator it; 00073 for (it= layout.begin(); it != layout.end(); it++) { 00074 if (it->second == at) { 00075 return it->first; 00076 } 00077 } 00078 return 0; 00079 }
void Keyboard::HandleKeyEvent | ( | const SDL_Event * | event | ) |
Definition at line 82 of file keyboard.cpp.
00083 { 00084 //Handle input text for Chat session in Network game 00085 //While player writes, it cannot control the game. 00086 if(GameLoop::GetInstance()->chatsession.CheckInput()){ 00087 GameLoop::GetInstance()->chatsession.HandleKey(event); 00088 return; 00089 } 00090 00091 std::map<int, Action::Action_t>::iterator it = layout.find(event->key.keysym.sym); 00092 00093 if ( it == layout.end() ) 00094 return; 00095 00096 Action::Action_t action = it->second; 00097 00098 //We can perform the next actions, only if the player is played localy: 00099 if(ActiveTeam().IsLocal()) 00100 { 00101 00102 if(action <= Action::ACTION_NEXT_CHARACTER) 00103 { 00104 switch (action) { 00105 // case Action::ACTION_ADD: 00106 // if (lance_grenade.time < 15) 00107 // lance_grenade.time ++; 00108 // break ; 00109 00110 // case Action::ACTION_SUBSTRACT: 00111 // if (lance_grenade.time > 1) 00112 // lance_grenade.time --; 00113 // break ; 00114 default: 00115 break ; 00116 } 00117 } 00118 00119 Key_Event_t event_type; 00120 switch( event->type) 00121 { 00122 case SDL_KEYDOWN: 00123 event_type = KEY_PRESSED;break; 00124 case SDL_KEYUP: 00125 event_type = KEY_RELEASED;break; 00126 default: 00127 return; 00128 } 00129 if(event_type == KEY_PRESSED) 00130 HandleKeyPressed(action); 00131 if(event_type == KEY_RELEASED) 00132 HandleKeyReleased(action); 00133 00134 if ((ActiveTeam().GetWeapon().override_keys && 00135 ActiveTeam().GetWeapon().IsActive()) || ActiveTeam().GetWeapon().force_override_keys) 00136 { 00137 ActiveTeam().AccessWeapon().HandleKeyEvent(action, event_type); 00138 return ; 00139 } 00140 ActiveCharacter().HandleKeyEvent( action, event_type); 00141 } 00142 else 00143 { 00144 Key_Event_t event_type; 00145 switch( event->type) 00146 { 00147 case SDL_KEYDOWN: event_type = KEY_PRESSED;break; 00148 case SDL_KEYUP: event_type = KEY_RELEASED;break; 00149 default: return; 00150 } 00151 //Current player is on the network 00152 if(event_type == KEY_RELEASED) 00153 HandleKeyReleased(action); 00154 } 00155 }
Here is the call graph for this function:
Here is the caller graph for this function:
void Keyboard::HandleKeyPressed | ( | const Action::Action_t & | action | ) | [private] |
Definition at line 158 of file keyboard.cpp.
00159 { 00160 PressedKeys[action] = true ; 00161 00162 if (GameLoop::GetInstance()->ReadState() == GameLoop::PLAYING && 00163 ActiveTeam().GetWeapon().CanChangeWeapon()) 00164 { 00165 int weapon_sort = -1; 00166 00167 switch(action) { 00168 case Action::ACTION_WEAPONS1: 00169 weapon_sort = 1; 00170 break; 00171 00172 case Action::ACTION_WEAPONS2: 00173 weapon_sort = 2; 00174 break; 00175 00176 case Action::ACTION_WEAPONS3: 00177 weapon_sort = 3; 00178 break; 00179 00180 case Action::ACTION_WEAPONS4: 00181 weapon_sort = 4; 00182 break; 00183 00184 case Action::ACTION_WEAPONS5: 00185 weapon_sort = 5; 00186 break; 00187 00188 case Action::ACTION_WEAPONS6: 00189 weapon_sort = 6; 00190 break; 00191 00192 case Action::ACTION_WEAPONS7: 00193 weapon_sort = 7; 00194 break; 00195 00196 case Action::ACTION_WEAPONS8: 00197 weapon_sort = 8; 00198 break; 00199 00200 case Action::ACTION_NEXT_CHARACTER: 00201 if (GameMode::GetInstance()->AllowCharacterSelection()) { 00202 Action * next_character = new Action(Action::ACTION_NEXT_CHARACTER); 00203 next_character->StoreActiveCharacter(); 00204 ActiveTeam().NextCharacter(); 00205 next_character->StoreActiveCharacter(); 00206 ActionHandler::GetInstance()->NewAction(next_character); 00207 } 00208 return ; 00209 00210 default: 00211 break ; 00212 } 00213 00214 if ( weapon_sort > 0 ) 00215 { 00216 Weapon::Weapon_type weapon; 00217 if (Config::GetInstance()->GetWeaponsList()->GetWeaponBySort(weapon_sort, weapon)) 00218 ActionHandler::GetInstance()->NewAction(new Action(Action::ACTION_CHANGE_WEAPON, weapon)); 00219 00220 return; 00221 } 00222 } 00223 }
Here is the call graph for this function:
Here is the caller graph for this function:
void Keyboard::HandleKeyReleased | ( | const Action::Action_t & | action | ) | [private] |
Definition at line 226 of file keyboard.cpp.
00227 { 00228 PressedKeys[action] = false ; 00229 00230 // We manage here only actions which are active on KEY_RELEASED event. 00231 Interface * interface = Interface::GetInstance(); 00232 00233 switch(action) // Convert to int to avoid a warning 00234 { 00235 case Action::ACTION_QUIT: 00236 Game::GetInstance()->SetEndOfGameStatus( true ); 00237 return; 00238 00239 case Action::ACTION_PAUSE: 00240 ActionHandler::GetInstance()->NewAction(new Action(Action::ACTION_PAUSE)); 00241 return; 00242 00243 case Action::ACTION_FULLSCREEN: 00244 AppWormux::GetInstance()->video.ToggleFullscreen(); 00245 return; 00246 case Action::ACTION_CHAT: 00247 if(network.IsConnected()) 00248 GameLoop::GetInstance()->chatsession.ShowInput(); 00249 return; 00250 case Action::ACTION_CENTER: 00251 00252 CharacterCursor::GetInstance()->FollowActiveCharacter(); 00253 camera.FollowObject (&ActiveCharacter(), true, true, true); 00254 return; 00255 00256 case Action::ACTION_TOGGLE_INTERFACE: 00257 interface->EnableDisplay (!interface->IsDisplayed()); 00258 return; 00259 default: 00260 return; 00261 } 00262 00263 if( ! ActiveTeam().IsLocal()) 00264 return; 00265 00266 switch(action) { 00267 case Action::ACTION_TOGGLE_WEAPONS_MENUS: 00268 interface->weapons_menu.SwitchDisplay(); 00269 return; 00270 00271 default: 00272 break ; 00273 } 00274 }
Here is the call graph for this function:
Here is the caller graph for this function:
void Keyboard::Refresh | ( | ) |
Definition at line 277 of file keyboard.cpp.
00278 { 00279 //Treat KEY_REFRESH events: 00280 for (int i = Action::ACTION_FIRST; i < Action::ACTION_LAST; i++) 00281 if(PressedKeys[i]) 00282 { 00283 if (ActiveTeam().GetWeapon().override_keys && 00284 ActiveTeam().GetWeapon().IsActive()) 00285 { 00286 ActiveTeam().AccessWeapon().HandleKeyEvent(static_cast<Action::Action_t>(i), KEY_REFRESH); 00287 } 00288 else 00289 { 00290 ActiveCharacter().HandleKeyEvent(static_cast<Action::Action_t>(i),KEY_REFRESH); 00291 } 00292 } 00293 }
Here is the call graph for this function:
Here is the caller graph for this function:
void Keyboard::Reset | ( | ) |
Definition at line 58 of file keyboard.cpp.
00059 { 00060 for (int i = Action::ACTION_FIRST; i != Action::ACTION_LAST; i++) 00061 PressedKeys[i] = false ; 00062 }
Here is the caller graph for this function:
void Keyboard::SetKeyAction | ( | int | key, | |
Action::Action_t | at | |||
) |
Definition at line 64 of file keyboard.cpp.
00065 { 00066 layout[key] = at; 00067 }
Here is the caller graph for this function:
void Keyboard::TestCamera | ( | ) |
std::map<int, Action::Action_t> Keyboard::layout [private] |
Definition at line 34 of file keyboard.h.
bool Keyboard::PressedKeys[Action::ACTION_LAST] [private] |
Definition at line 35 of file keyboard.h.
Keyboard* Keyboard::singleton [static, private] |
Definition at line 37 of file keyboard.h.