Fix cmake download path
[supertux.git] / src / control / input_manager.cpp
index f9d87d1..ce612d4 100644 (file)
@@ -1,6 +1,6 @@
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>,
-//                2007 Ingo Ruhnke <grumbel@gmx.de>
+//           2007,2014 Ingo Ruhnke <grumbel@gmail.com>
 //
 //  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
 
 #include <iostream>
 
-#include "control/keyboard_manager.hpp"
-#include "control/joystick_manager.hpp"
 #include "control/game_controller_manager.hpp"
+#include "control/joystick_manager.hpp"
+#include "control/keyboard_manager.hpp"
 #include "gui/menu_manager.hpp"
 #include "lisp/list_iterator.hpp"
 #include "supertux/gameconfig.hpp"
 #include "util/gettext.hpp"
+#include "util/log.hpp"
 #include "util/writer.hpp"
 
-InputManager::InputManager() :
+InputManager::InputManager(KeyboardConfig& keyboard_config,
+                           JoystickConfig& joystick_config) :
   controller(new Controller),
   m_use_game_controller(true),
-  keyboard_manager(new KeyboardManager(this)),
-  joystick_manager(new JoystickManager(this)),
+  keyboard_manager(new KeyboardManager(this, keyboard_config)),
+  joystick_manager(new JoystickManager(this, joystick_config)),
   game_controller_manager(new GameControllerManager(this))
 {
 }
@@ -48,31 +50,9 @@ InputManager::get_controller()
 }
 
 void
-InputManager::read(const Reader& lisp)
-{
-  const lisp::Lisp* keymap_lisp = lisp.get_lisp("keymap");
-  if (keymap_lisp) 
-  {
-    keyboard_manager->read(keymap_lisp);
-  }
-
-  const lisp::Lisp* joystick_lisp = lisp.get_lisp(_("joystick"));
-  if (joystick_lisp) 
-  {
-    joystick_manager->read(joystick_lisp);
-  }
-}
-
-void
-InputManager::write(Writer& writer)
+InputManager::use_game_controller(bool v)
 {
-  writer.start_list("keymap");
-  keyboard_manager->write(writer);
-  writer.end_list("keymap");
-
-  writer.start_list("joystick");
-  joystick_manager->write(writer);
-  writer.end_list("joystick");
+  m_use_game_controller = v;
 }
 
 void
@@ -114,11 +94,11 @@ InputManager::process_event(const SDL_Event& event)
       break;
 
     case SDL_JOYDEVICEADDED:
-      if (!m_use_game_controller) joystick_manager->on_joystick_added(event.jdevice.which);
+      joystick_manager->on_joystick_added(event.jdevice.which);
       break;
 
     case SDL_JOYDEVICEREMOVED:
-      if (!m_use_game_controller) joystick_manager->on_joystick_removed(event.jdevice.which);
+      joystick_manager->on_joystick_removed(event.jdevice.which);
       break;
 
     case SDL_CONTROLLERAXISMOTION:
@@ -134,17 +114,17 @@ InputManager::process_event(const SDL_Event& event)
       break;
 
     case SDL_CONTROLLERDEVICEADDED:
-      std::cout << "SDL_CONTROLLERDEVICEADDED" << std::endl;
-      if (m_use_game_controller) game_controller_manager->on_controller_added(event.cdevice.which);
+      log_debug << "SDL_CONTROLLERDEVICEADDED" << std::endl;
+      game_controller_manager->on_controller_added(event.cdevice.which);
       break;
 
     case SDL_CONTROLLERDEVICEREMOVED:
-      std::cout << "SDL_CONTROLLERDEVICEREMOVED" << std::endl;
-      if (m_use_game_controller) game_controller_manager->on_controller_removed(event.cdevice.which);
+      log_debug << "SDL_CONTROLLERDEVICEREMOVED" << std::endl;
+      game_controller_manager->on_controller_removed(event.cdevice.which);
       break;
 
     case SDL_CONTROLLERDEVICEREMAPPED:
-      std::cout << "SDL_CONTROLLERDEVICEREMAPPED" << std::endl;
+      log_debug << "SDL_CONTROLLERDEVICEREMAPPED" << std::endl;
       break;
 
     default: