Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 119908
Collapse All | Expand All

(-)xmoto-0.1.10-orig/src/Game.cpp (-6 / +6 lines)
Lines 1263-1274 Link Here
1263
1263
1264
    /* Controls */
1264
    /* Controls */
1265
    m_Config.createVar( "ControllerMode1",        "Keyboard" );
1265
    m_Config.createVar( "ControllerMode1",        "Keyboard" );
1266
    m_Config.createVar( "KeyDrive1",              "Up" );
1266
    m_Config.createVar( "KeyDrive1",              "273" );
1267
    m_Config.createVar( "KeyBrake1",              "Down" );
1267
    m_Config.createVar( "KeyBrake1",              "274" );
1268
    m_Config.createVar( "KeyFlipLeft1",           "Left" );
1268
    m_Config.createVar( "KeyFlipLeft1",           "276" );
1269
    m_Config.createVar( "KeyFlipRight1",          "Right" );
1269
    m_Config.createVar( "KeyFlipRight1",          "275" );
1270
    m_Config.createVar( "KeyChangeDir1",          "Space" );
1270
    m_Config.createVar( "KeyChangeDir1",          "32" );
1271
        
1271
1272
    m_Config.createVar( "JoyIdx1",                "-1" );
1272
    m_Config.createVar( "JoyIdx1",                "-1" );
1273
    m_Config.createVar( "JoyAxisPrim1",           "" );
1273
    m_Config.createVar( "JoyAxisPrim1",           "" );
1274
    m_Config.createVar( "JoyAxisPrimMax1",        "" );
1274
    m_Config.createVar( "JoyAxisPrimMax1",        "" );
(-)xmoto-0.1.10-orig/src/Game.h (-1 / +1 lines)
Lines 244-250 Link Here
244
      
244
      
245
      void _SimpleMessage(const std::string &Msg);
245
      void _SimpleMessage(const std::string &Msg);
246
      
246
      
247
      int _IsKeyInUse(const std::string &Key);
247
      int _IsKeyInUse(int nKey);
248
  };
248
  };
249
249
250
};
250
};
(-)xmoto-0.1.10-orig/src/GameMenus.cpp (-16 / +31 lines)
Lines 662-672 Link Here
662
    
662
    
663
    UIListEntry *p;
663
    UIListEntry *p;
664
    
664
    
665
    p = pList->addEntry(GAMETEXT_DRIVE); p->Text.push_back(m_Config.getString("KeyDrive1"));
665
    p = pList->addEntry(GAMETEXT_DRIVE);
666
    p = pList->addEntry(GAMETEXT_BRAKE); p->Text.push_back(m_Config.getString("KeyBrake1"));
666
    p->pvUser = (void*) m_Config.getInteger("KeyDrive1");
667
    p = pList->addEntry(GAMETEXT_FLIPLEFT); p->Text.push_back(m_Config.getString("KeyFlipLeft1"));
667
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
668
    p = pList->addEntry(GAMETEXT_FLIPRIGHT); p->Text.push_back(m_Config.getString("KeyFlipRight1"));
668
669
    p = pList->addEntry(GAMETEXT_CHANGEDIR); p->Text.push_back(m_Config.getString("KeyChangeDir1"));
669
    p = pList->addEntry(GAMETEXT_BRAKE);
670
    p->pvUser = (void*) m_Config.getInteger("KeyBrake1");
671
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
672
673
    p = pList->addEntry(GAMETEXT_FLIPLEFT);
674
    p->pvUser = (void*) m_Config.getInteger("KeyFlipLeft1");
675
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
676
677
    p = pList->addEntry(GAMETEXT_FLIPRIGHT);
678
    p->pvUser = (void*) m_Config.getInteger("KeyFlipRight1");
679
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
680
681
    p = pList->addEntry(GAMETEXT_CHANGEDIR);
682
    p->pvUser = (void*) m_Config.getInteger("KeyChangeDir1");
683
    p->Text.push_back(m_InputHandler.keyToString((int) p->pvUser));
670
  }
684
  }
671
  
685
  
672
  /*===========================================================================
686
  /*===========================================================================
Lines 1277-1287 Link Here
1277
  /*===========================================================================
1291
  /*===========================================================================
1278
  Change a key config/joystick stuff
1292
  Change a key config/joystick stuff
1279
  ===========================================================================*/
1293
  ===========================================================================*/
1280
  int GameApp::_IsKeyInUse(const std::string &Key) {
1294
  int GameApp::_IsKeyInUse(int nKey) {
1281
    UIList *pActionList = (UIList *)m_pOptionsWindow->getChild("OPTIONS_TABS:CONTROLS_TAB:KEY_ACTION_LIST");
1295
    UIList *pActionList = (UIList *)m_pOptionsWindow->getChild("OPTIONS_TABS:CONTROLS_TAB:KEY_ACTION_LIST");
1282
1296
1283
    for(int i=0;i<pActionList->getEntries().size();i++) {
1297
    for(int i=0;i<pActionList->getEntries().size();i++) {
1284
      if(pActionList->getEntries()[i]->Text[1] == Key) return i;
1298
      if(pActionList->getEntries()[i]->pvUser == (void*) nKey) return i;
1285
    }
1299
    }
1286
    return -1;
1300
    return -1;
1287
  }
1301
  }
Lines 1329-1340 Link Here
1329
      
1343
      
1330
      while(1) {
1344
      while(1) {
1331
        /* Wait for a key */
1345
        /* Wait for a key */
1332
        std::string NewKey = m_InputHandler.waitForKey();
1346
        int NewKey = m_InputHandler.waitForKey();
1333
        if(NewKey == "<<QUIT>>") {
1347
        if(NewKey < 0) {
1334
          /* Quit! */
1348
          /* Quit! */
1335
          quit();
1349
          quit();
1336
        }        
1350
        }        
1337
        else if(NewKey == "<<CANCEL>>" || NewKey == "") {
1351
        else if(NewKey == 0) {
1338
          /* Do nothing */
1352
          /* Do nothing */
1339
          break;
1353
          break;
1340
        }
1354
        }
Lines 1343-1349 Link Here
1343
          int nAlreadyUsedBy = _IsKeyInUse(NewKey);
1357
          int nAlreadyUsedBy = _IsKeyInUse(NewKey);
1344
          
1358
          
1345
          if(nAlreadyUsedBy<0 || nAlreadyUsedBy == nSel) {
1359
          if(nAlreadyUsedBy<0 || nAlreadyUsedBy == nSel) {
1346
            pActionList->getEntries()[nSel]->Text[1] = NewKey;        
1360
            pActionList->getEntries()[nSel]->pvUser = (void*) NewKey;
1361
            pActionList->getEntries()[nSel]->Text[1] = m_InputHandler.keyToString(NewKey);
1347
            break;
1362
            break;
1348
          }
1363
          }
1349
          else {
1364
          else {
Lines 1717-1727 Link Here
1717
    else if(pJoystickControl->getChecked()) m_Config.setString("ControllerMode1","Joystick1");
1732
    else if(pJoystickControl->getChecked()) m_Config.setString("ControllerMode1","Joystick1");
1718
    
1733
    
1719
    for(int i=0;i<pActionList->getEntries().size();i++) {
1734
    for(int i=0;i<pActionList->getEntries().size();i++) {
1720
      if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_DRIVE) m_Config.setString("KeyDrive1",pActionList->getEntries()[i]->Text[1]);
1735
      if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_DRIVE) m_Config.setInteger("KeyDrive1",(int) pActionList->getEntries()[i]->pvUser);
1721
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_BRAKE) m_Config.setString("KeyBrake1",pActionList->getEntries()[i]->Text[1]);
1736
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_BRAKE) m_Config.setInteger("KeyBrake1",(int) pActionList->getEntries()[i]->pvUser);
1722
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_FLIPLEFT) m_Config.setString("KeyFlipLeft1",pActionList->getEntries()[i]->Text[1]);
1737
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_FLIPLEFT) m_Config.setInteger("KeyFlipLeft1",(int) pActionList->getEntries()[i]->pvUser);
1723
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_FLIPRIGHT) m_Config.setString("KeyFlipRight1",pActionList->getEntries()[i]->Text[1]);
1738
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_FLIPRIGHT) m_Config.setInteger("KeyFlipRight1",(int) pActionList->getEntries()[i]->pvUser);
1724
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_CHANGEDIR) m_Config.setString("KeyChangeDir1",pActionList->getEntries()[i]->Text[1]);
1739
      else if(pActionList->getEntries()[i]->Text[0] == GAMETEXT_CHANGEDIR) m_Config.setInteger("KeyChangeDir1",(int) pActionList->getEntries()[i]->pvUser);
1725
    }
1740
    }
1726
    
1741
    
1727
    m_Config.setBool("EngineSoundEnable",pEnableEngineSoundButton->getChecked());
1742
    m_Config.setBool("EngineSoundEnable",pEnableEngineSoundButton->getChecked());
(-)xmoto-0.1.10-orig/src/Input.cpp (-76 / +13 lines)
Lines 38-112 Link Here
38
    "ChangeDirection", ACTION_CHANGEDIR,         
38
    "ChangeDirection", ACTION_CHANGEDIR,         
39
    NULL
39
    NULL
40
  };
40
  };
41
42
  /* Key code to string table */  
43
  InputKeyMap InputHandler::m_KeyMap[] = {
44
    "Up",              SDLK_UP,
45
    "Down",            SDLK_DOWN,
46
    "Left",            SDLK_LEFT,
47
    "Right",           SDLK_RIGHT,
48
    "Space",           SDLK_SPACE,
49
    "A",               SDLK_a,
50
    "B",               SDLK_b,
51
    "C",               SDLK_c,
52
    "D",               SDLK_d,
53
    "E",               SDLK_e,
54
    "F",               SDLK_f,
55
    "G",               SDLK_g,
56
    "H",               SDLK_h,
57
    "I",               SDLK_i,
58
    "J",               SDLK_j,
59
    "K",               SDLK_k,
60
    "L",               SDLK_l,
61
    "M",               SDLK_m,
62
    "N",               SDLK_n,
63
    "O",               SDLK_o,
64
    "P",               SDLK_p,
65
    "Q",               SDLK_q,
66
    "R",               SDLK_r,
67
    "S",               SDLK_s,
68
    "T",               SDLK_t,
69
    "U",               SDLK_u,
70
    "V",               SDLK_v,
71
    "W",               SDLK_w,
72
    "X",               SDLK_x,
73
    "Y",               SDLK_y,
74
    "Z",               SDLK_z,
75
    "1",               SDLK_1,
76
    "2",               SDLK_2,
77
    "3",               SDLK_3,
78
    "4",               SDLK_4,
79
    "5",               SDLK_5,
80
    "6",               SDLK_6,
81
    "7",               SDLK_7,
82
    "8",               SDLK_8,
83
    "9",               SDLK_9,
84
    "0",               SDLK_0,
85
    /* TODO: add more */
86
    NULL    
87
  };
88
  
41
  
89
  /*===========================================================================
42
  /*===========================================================================
90
  Easy translation between keys and their codes
43
  Easy translation between keys and their codes
91
  ===========================================================================*/  
44
  ===========================================================================*/  
92
  std::string InputHandler::_KeyToString(int nKey) {
45
  std::string InputHandler::keyToString(int nKey) {
93
    int i=0;
46
    return SDL_GetKeyName((SDLKey) nKey);
94
    while(m_KeyMap[i].pcKey != NULL) {
95
      if(m_KeyMap[i].nKey == nKey) return m_KeyMap[i].pcKey;
96
      i++;
97
    }
98
    
99
    return ""; /* unknown! */
100
  }
101
  
102
  int InputHandler::_StringToKey(const std::string &s) {
103
    int i=0;
104
    while(m_KeyMap[i].pcKey != NULL) {
105
      if(s == m_KeyMap[i].pcKey) return m_KeyMap[i].nKey;
106
      i++;
107
    }
108
    
109
    return -1;
110
  }
47
  }
111
48
112
  /*===========================================================================
49
  /*===========================================================================
Lines 251-259 Link Here
251
  /*===========================================================================
188
  /*===========================================================================
252
  Read configuration
189
  Read configuration
253
  ===========================================================================*/  
190
  ===========================================================================*/  
254
  std::string InputHandler::waitForKey(void) {
191
  int InputHandler::waitForKey(void) {
255
    /* Start waiting for a key */
192
    /* Start waiting for a key */
256
    std::string Ret = "";
193
    int Ret = 0;
257
    
194
    
258
    bool bWait = true;
195
    bool bWait = true;
259
    while(bWait) {
196
    while(bWait) {
Lines 264-275 Link Here
264
      while(SDL_PollEvent(&Event)) {
201
      while(SDL_PollEvent(&Event)) {
265
        switch(Event.type) {
202
        switch(Event.type) {
266
          case SDL_QUIT:
203
          case SDL_QUIT:
267
            return "<<QUIT>>";
204
            return -1;
268
          case SDL_KEYDOWN:
205
          case SDL_KEYDOWN:
269
            if(Event.key.keysym.sym == SDLK_ESCAPE) return "<<CANCEL>>";
206
            if(Event.key.keysym.sym == SDLK_ESCAPE) return 0;
270
          
207
          
271
            Ret = _KeyToString(Event.key.keysym.sym);
208
            Ret = (int) Event.key.keysym.sym;
272
            if(Ret != "") bWait = false;
209
            if(Ret != 0) bWait = false;
273
            break;
210
            break;
274
        }
211
        }
275
      }
212
      }
Lines 298-308 Link Here
298
        /* We're using the keyboard */
235
        /* We're using the keyboard */
299
        m_ControllerModeID1 = CONTROLLER_MODE_KEYBOARD;
236
        m_ControllerModeID1 = CONTROLLER_MODE_KEYBOARD;
300
        
237
        
301
        m_nDriveKey1 = _StringToKey(pConfig->getString("KeyDrive1"));
238
        m_nDriveKey1 = pConfig->getInteger("KeyDrive1");
302
        m_nBrakeKey1 = _StringToKey(pConfig->getString("KeyBrake1"));
239
        m_nBrakeKey1 = pConfig->getInteger("KeyBrake1");
303
        m_nPullBackKey1 = _StringToKey(pConfig->getString("KeyFlipLeft1"));
240
        m_nPullBackKey1 = pConfig->getInteger("KeyFlipLeft1");
304
        m_nPushForwardKey1 = _StringToKey(pConfig->getString("KeyFlipRight1"));
241
        m_nPushForwardKey1 = pConfig->getInteger("KeyFlipRight1");
305
        m_nChangeDirKey1 = _StringToKey(pConfig->getString("KeyChangeDir1"));
242
        m_nChangeDirKey1 = pConfig->getInteger("KeyChangeDir1");
306
        
243
        
307
        /* All good? */
244
        /* All good? */
308
        if(m_nDriveKey1<0 || m_nBrakeKey1<0 || m_nPullBackKey1<0 ||
245
        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
88
      /* Methods */
88
      /* Methods */
89
      void configure(UserConfig *pConfig);
89
      void configure(UserConfig *pConfig);
90
      void handleInput(InputEventType Type,int nKey,BikeController *pController);
90
      void handleInput(InputEventType Type,int nKey,BikeController *pController);
91
      std::string waitForKey(void);
91
      int waitForKey(void);
92
      void updateInput(BikeController *pController);
92
      void updateInput(BikeController *pController);
93
      void init(UserConfig *pConfig);
93
      void init(UserConfig *pConfig);
94
      void uninit(void);
94
      void uninit(void);
95
      
96
      /* Helpers */
97
      std::string keyToString(int nKey);
95
    
98
    
96
    private:
99
    private:
97
100
Lines 125-134 Link Here
125
      static InputActionType m_ActionTypeTable[];
128
      static InputActionType m_ActionTypeTable[];
126
      static InputKeyMap m_KeyMap[];
129
      static InputKeyMap m_KeyMap[];
127
      
130
      
128
      /* Helpers */
129
      std::string _KeyToString(int nKey);
130
      int _StringToKey(const std::string &s);
131
      
132
      /* Set default config */
131
      /* Set default config */
133
      void _SetDefaultConfig(void);
132
      void _SetDefaultConfig(void);
134
  };
133
  };

Return to bug 119908