View | Details | Raw Unified
Collapse All | Expand All

(-) xmoto-0.1.10-orig/src/Game.cpp (-6 / +6 lines)
 Lines 1263-1274    Link Here 
    /* Controls */
    /* Controls */
    m_Config.createVar( "ControllerMode1",        "Keyboard" );
    m_Config.createVar( "ControllerMode1",        "Keyboard" );
    m_Config.createVar( "KeyDrive1",              "Up" );
    m_Config.createVar( "KeyDrive1",              "273" );
    m_Config.createVar( "KeyBrake1",              "Down" );
    m_Config.createVar( "KeyBrake1",              "274" );
    m_Config.createVar( "KeyFlipLeft1",           "Left" );
    m_Config.createVar( "KeyFlipLeft1",           "276" );
    m_Config.createVar( "KeyFlipRight1",          "Right" );
    m_Config.createVar( "KeyFlipRight1",          "275" );
    m_Config.createVar( "KeyChangeDir1",          "Space" );
    m_Config.createVar( "KeyChangeDir1",          "32" );
        
    m_Config.createVar( "JoyIdx1",                "-1" );
    m_Config.createVar( "JoyIdx1",                "-1" );
    m_Config.createVar( "JoyAxisPrim1",           "" );
    m_Config.createVar( "JoyAxisPrim1",           "" );
    m_Config.createVar( "JoyAxisPrimMax1",        "" );
    m_Config.createVar( "JoyAxisPrimMax1",        "" );
(-) xmoto-0.1.10-orig/src/Game.h (-1 / +1 lines)
 Lines 244-250    Link Here 
      
      
      void _SimpleMessage(const std::string &Msg);
      void _SimpleMessage(const std::string &Msg);
      
      
      int _IsKeyInUse(const std::string &Key);
      int _IsKeyInUse(int nKey);
  };
  };
};
};
(-) xmoto-0.1.10-orig/src/GameMenus.cpp (-16 / +31 lines)
 Lines 662-672    Link Here 
    
    
    UIListEntry *p;
    UIListEntry *p;
    
    
    p = pList->addEntry(GAMETEXT_DRIVE); p->Text.push_back(m_Config.getString("KeyDrive1"));
    p = pList->addEntry(GAMETEXT_DRIVE);
    p = pList->addEntry(GAMETEXT_BRAKE); p->Text.push_back(m_Config.getString("KeyBrake1"));
    p->pvUser = (void*) m_Config.getInteger("KeyDrive1");
    p = pList->addEntry(GAMETEXT_FLIPLEFT); p->Text.push_back(m_Config.getString("KeyFlipLeft1"));
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
    p = pList->addEntry(GAMETEXT_FLIPRIGHT); p->Text.push_back(m_Config.getString("KeyFlipRight1"));
    p = pList->addEntry(GAMETEXT_CHANGEDIR); p->Text.push_back(m_Config.getString("KeyChangeDir1"));
    p = pList->addEntry(GAMETEXT_BRAKE);
    p->pvUser = (void*) m_Config.getInteger("KeyBrake1");
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
    p = pList->addEntry(GAMETEXT_FLIPLEFT);
    p->pvUser = (void*) m_Config.getInteger("KeyFlipLeft1");
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
    p = pList->addEntry(GAMETEXT_FLIPRIGHT);
    p->pvUser = (void*) m_Config.getInteger("KeyFlipRight1");
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
    p = pList->addEntry(GAMETEXT_CHANGEDIR);
    p->pvUser = (void*) m_Config.getInteger("KeyChangeDir1");
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
  }
  }
  
  
  /*===========================================================================
  /*===========================================================================
 Lines 1277-1287    Link Here 
  /*===========================================================================
  /*===========================================================================
  Change a key config/joystick stuff
  Change a key config/joystick stuff
  ===========================================================================*/
  ===========================================================================*/
  int GameApp::_IsKeyInUse(const std::string &Key) {
  int GameApp::_IsKeyInUse(int nKey) {
    UIList *pActionList = (UIList *)m_pOptionsWindow->getChild("OPTIONS_TABS:CONTROLS_TAB:KEY_ACTION_LIST");
    UIList *pActionList = (UIList *)m_pOptionsWindow->getChild("OPTIONS_TABS:CONTROLS_TAB:KEY_ACTION_LIST");
    for(int i=0;i<pActionList->getEntries().size();i++) {
    for(int i=0;i<pActionList->getEntries().size();i++) {
      if(pActionList->getEntries()[i]->Text[1] == Key) return i;
      if(pActionList->getEntries()[i]->pvUser == (void*) nKey) return i;
    }
    }
    return -1;
    return -1;
  }
  }
 Lines 1329-1340    Link Here 
      
      
      while(1) {
      while(1) {
        /* Wait for a key */
        /* Wait for a key */
        std::string NewKey = m_InputHandler.waitForKey();
        int NewKey = m_InputHandler.waitForKey();
        if(NewKey == "<<QUIT>>") {
        if(NewKey < 0) {
          /* Quit! */
          /* Quit! */
          quit();
          quit();
        }        
        }        
        else if(NewKey == "<<CANCEL>>" || NewKey == "") {
        else if(NewKey == 0) {
          /* Do nothing */
          /* Do nothing */
          break;
          break;
        }
        }
 Lines 1343-1349    Link Here 
          int nAlreadyUsedBy = _IsKeyInUse(NewKey);
          int nAlreadyUsedBy = _IsKeyInUse(NewKey);
          
          
          if(nAlreadyUsedBy<0 || nAlreadyUsedBy == nSel) {
          if(nAlreadyUsedBy<0 || nAlreadyUsedBy == nSel) {
            pActionList->getEntries()[nSel]->Text[1] = NewKey;        
            pActionList->getEntries()[nSel]->pvUser = (void*) NewKey;
            pActionList->getEntries()[nSel]->Text[1] = m_InputHandler.keyToString(NewKey);
            break;
            break;
          }
          }
          else {
          else {
 Lines 1717-1727    Link Here 
    else if(pJoystickControl->getChecked()) m_Config.setString("ControllerMode1","Joystick1");
    else if(pJoystickControl->getChecked()) m_Config.setString("ControllerMode1","Joystick1");
    
    
    for(int i=0;i<pActionList->getEntries().size();i++) {
    for(int i=0;i<pActionList->getEntries().size();i++) {
      if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_DRIVE) m_Config.setString("KeyDrive1",pActionList->getEntries()[i]->Text[1]);
      if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_DRIVE) m_Config.setInteger("KeyDrive1",(int) pActionList->getEntries()[i]->pvUser);
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_BRAKE) m_Config.setString("KeyBrake1",pActionList->getEntries()[i]->Text[1]);
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_BRAKE) m_Config.setInteger("KeyBrake1",(int) pActionList->getEntries()[i]->pvUser);
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_FLIPLEFT) m_Config.setString("KeyFlipLeft1",pActionList->getEntries()[i]->Text[1]);
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_FLIPLEFT) m_Config.setInteger("KeyFlipLeft1",(int) pActionList->getEntries()[i]->pvUser);
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_FLIPRIGHT) m_Config.setString("KeyFlipRight1",pActionList->getEntries()[i]->Text[1]);
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_FLIPRIGHT) m_Config.setInteger("KeyFlipRight1",(int) pActionList->getEntries()[i]->pvUser);
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_CHANGEDIR) m_Config.setString("KeyChangeDir1",pActionList->getEntries()[i]->Text[1]);
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_CHANGEDIR) m_Config.setInteger("KeyChangeDir1",(int) pActionList->getEntries()[i]->pvUser);
    }
    }
    
    
    m_Config.setBool("EngineSoundEnable",pEnableEngineSoundButton->getChecked());
    m_Config.setBool("EngineSoundEnable",pEnableEngineSoundButton->getChecked());
(-) xmoto-0.1.10-orig/src/Input.cpp (-76 / +13 lines)
 Lines 38-112    Link Here 
    "ChangeDirection", ACTION_CHANGEDIR,         
    "ChangeDirection", ACTION_CHANGEDIR,         
    NULL
    NULL
  };
  };
  /* Key code to string table */  
  InputKeyMap InputHandler::m_KeyMap[] = {
    "Up",              SDLK_UP,
    "Down",            SDLK_DOWN,
    "Left",            SDLK_LEFT,
    "Right",           SDLK_RIGHT,
    "Space",           SDLK_SPACE,
    "A",               SDLK_a,
    "B",               SDLK_b,
    "C",               SDLK_c,
    "D",               SDLK_d,
    "E",               SDLK_e,
    "F",               SDLK_f,
    "G",               SDLK_g,
    "H",               SDLK_h,
    "I",               SDLK_i,
    "J",               SDLK_j,
    "K",               SDLK_k,
    "L",               SDLK_l,
    "M",               SDLK_m,
    "N",               SDLK_n,
    "O",               SDLK_o,
    "P",               SDLK_p,
    "Q",               SDLK_q,
    "R",               SDLK_r,
    "S",               SDLK_s,
    "T",               SDLK_t,
    "U",               SDLK_u,
    "V",               SDLK_v,
    "W",               SDLK_w,
    "X",               SDLK_x,
    "Y",               SDLK_y,
    "Z",               SDLK_z,
    "1",               SDLK_1,
    "2",               SDLK_2,
    "3",               SDLK_3,
    "4",               SDLK_4,
    "5",               SDLK_5,
    "6",               SDLK_6,
    "7",               SDLK_7,
    "8",               SDLK_8,
    "9",               SDLK_9,
    "0",               SDLK_0,
    /* TODO: add more */
    NULL    
  };
  
  
  /*===========================================================================
  /*===========================================================================
  Easy translation between keys and their codes
  Easy translation between keys and their codes
  ===========================================================================*/  
  ===========================================================================*/  
  std::string InputHandler::_KeyToString(int nKey) {
  std::string InputHandler::keyToString(int nKey) {
    int i=0;
    return SDL_GetKeyName((SDLKey) nKey);
    while(m_KeyMap[i].pcKey != NULL) {
      if(m_KeyMap[i].nKey == nKey) return m_KeyMap[i].pcKey;
      i++;
    }
    
    return ""; /* unknown! */
  }
  
  int InputHandler::_StringToKey(const std::string &s) {
    int i=0;
    while(m_KeyMap[i].pcKey != NULL) {
      if(s == m_KeyMap[i].pcKey) return m_KeyMap[i].nKey;
      i++;
    }
    
    return -1;
  }
  }
  /*===========================================================================
  /*===========================================================================
 Lines 251-259    Link Here 
  /*===========================================================================
  /*===========================================================================
  Read configuration
  Read configuration
  ===========================================================================*/  
  ===========================================================================*/  
  std::string InputHandler::waitForKey(void) {
  int InputHandler::waitForKey(void) {
    /* Start waiting for a key */
    /* Start waiting for a key */
    std::string Ret = "";
    int Ret = 0;
    
    
    bool bWait = true;
    bool bWait = true;
    while(bWait) {
    while(bWait) {
 Lines 264-275    Link Here 
      while(SDL_PollEvent(&Event)) {
      while(SDL_PollEvent(&Event)) {
        switch(Event.type) {
        switch(Event.type) {
          case SDL_QUIT:
          case SDL_QUIT:
            return "<<QUIT>>";
            return -1;
          case SDL_KEYDOWN:
          case SDL_KEYDOWN:
            if(Event.key.keysym.sym == SDLK_ESCAPE) return "<<CANCEL>>";
            if(Event.key.keysym.sym == SDLK_ESCAPE) return 0;
          
          
            Ret = _KeyToString(Event.key.keysym.sym);
            Ret = (int) Event.key.keysym.sym;
            if(Ret != "") bWait = false;
            if(Ret != 0) bWait = false;
            break;
            break;
        }
        }
      }
      }
 Lines 298-308    Link Here 
        /* We're using the keyboard */
        /* We're using the keyboard */
        m_ControllerModeID1 = CONTROLLER_MODE_KEYBOARD;
        m_ControllerModeID1 = CONTROLLER_MODE_KEYBOARD;
        
        
        m_nDriveKey1 = _StringToKey(pConfig->getString("KeyDrive1"));
        m_nDriveKey1 = pConfig->getInteger("KeyDrive1");
        m_nBrakeKey1 = _StringToKey(pConfig->getString("KeyBrake1"));
        m_nBrakeKey1 = pConfig->getInteger("KeyBrake1");
        m_nPullBackKey1 = _StringToKey(pConfig->getString("KeyFlipLeft1"));
        m_nPullBackKey1 = pConfig->getInteger("KeyFlipLeft1");
        m_nPushForwardKey1 = _StringToKey(pConfig->getString("KeyFlipRight1"));
        m_nPushForwardKey1 = pConfig->getInteger("KeyFlipRight1");
        m_nChangeDirKey1 = _StringToKey(pConfig->getString("KeyChangeDir1"));
        m_nChangeDirKey1 = pConfig->getInteger("KeyChangeDir1");
        
        
        /* All good? */
        /* All good? */
        if(m_nDriveKey1<0 || m_nBrakeKey1<0 || m_nPullBackKey1<0 ||
        if(m_nDriveKey1<0 || m_nBrakeKey1<0 || m_nPullBackKey1<0 ||
(-) xmoto-0.1.10-orig/src/Input.h (-5 / +4 lines)
 Lines 88-97    Link Here 
      /* Methods */
      /* Methods */
      void configure(UserConfig *pConfig);
      void configure(UserConfig *pConfig);
      void handleInput(InputEventType Type,int nKey,BikeController *pController);
      void handleInput(InputEventType Type,int nKey,BikeController *pController);
      std::string waitForKey(void);
      int waitForKey(void);
      void updateInput(BikeController *pController);
      void updateInput(BikeController *pController);
      void init(UserConfig *pConfig);
      void init(UserConfig *pConfig);
      void uninit(void);
      void uninit(void);
      
      /* Helpers */
      std::string keyToString(int nKey);
    
    
    private:
    private:
 Lines 125-134    Link Here 
      static InputActionType m_ActionTypeTable[];
      static InputActionType m_ActionTypeTable[];
      static InputKeyMap m_KeyMap[];
      static InputKeyMap m_KeyMap[];
      
      
      /* Helpers */
      std::string _KeyToString(int nKey);
      int _StringToKey(const std::string &s);
      
      /* Set default config */
      /* Set default config */
      void _SetDefaultConfig(void);
      void _SetDefaultConfig(void);
  };
  };