Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OpenRaider.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*!
  2. * \file src/OpenRaider.cpp
  3. * \brief Main Game Object
  4. *
  5. * \author xythobuz
  6. */
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <assert.h>
  10. #include <dirent.h>
  11. #include "WindowSDL.h"
  12. #include "config.h"
  13. #include "utils/strings.h"
  14. #include "utils/time.h"
  15. #include "OpenRaider.h"
  16. #define MAX_MS_PER_FRAME (1000 / MAXIMUM_FPS)
  17. OpenRaider::OpenRaider() {
  18. mInit = false;
  19. mRunning = false;
  20. mBaseDir = NULL;
  21. mPakDir = NULL;
  22. mAudioDir = NULL;
  23. mDataDir = NULL;
  24. mMapListFilled = false;
  25. mMenu = new Menu();
  26. mConsole = new Console();
  27. mSound = new Sound();
  28. mWindow = new WindowSDL();
  29. for (int i = 0; i < ActionEventCount; i++)
  30. keyBindings[i] = unknown;
  31. }
  32. OpenRaider::~OpenRaider() {
  33. if (mMenu)
  34. delete mMenu;
  35. if (mConsole)
  36. delete mConsole;
  37. if (mSound)
  38. delete mSound;
  39. if (mWindow)
  40. delete mWindow;
  41. if (mBaseDir)
  42. delete mBaseDir;
  43. if (mPakDir)
  44. delete mPakDir;
  45. if (mAudioDir)
  46. delete mAudioDir;
  47. if (mDataDir)
  48. delete mDataDir;
  49. while (mMapList.size() > 0) {
  50. delete [] mMapList.back();
  51. mMapList.pop_back();
  52. }
  53. }
  54. int OpenRaider::loadConfig(const char *config) {
  55. assert(config != NULL);
  56. assert(config[0] != '\0');
  57. char *configFile = fullPath(config, 0);
  58. mConsole->print("Loading config from \"%s\"...", configFile);
  59. FILE *f = fopen(configFile, "r");
  60. if (f == NULL) {
  61. mConsole->print("Could not open file!");
  62. return -1;
  63. }
  64. char buffer[256];
  65. while (fgets(buffer, 256, f) != NULL) {
  66. int error = command(buffer);
  67. if (error != 0) {
  68. mConsole->print("Error Code: %d", error);
  69. }
  70. }
  71. fclose(f);
  72. return 0;
  73. }
  74. int OpenRaider::command(const char *command) {
  75. assert(command != NULL);
  76. assert(command[0] != '\0');
  77. int returnValue = 0;
  78. char *cmd = bufferString("%s", command);
  79. size_t length = strlen(cmd);
  80. // Command ends at '\n' or # when a comment begins
  81. for (size_t i = 0; i < length; i++) {
  82. if (cmd[i] == '\n' || cmd[i] == '#') {
  83. cmd[i] = '\0';
  84. break;
  85. }
  86. }
  87. char *token = strtok(cmd, " \t");
  88. if (token != NULL) {
  89. // token is the command to execute
  90. // get arguments
  91. std::vector<char *> args;
  92. char *next;
  93. while ((next = strtok(NULL, " \t")) != NULL) {
  94. args.push_back(next);
  95. }
  96. // Execute
  97. returnValue = this->command(token, &args);
  98. }
  99. free(cmd);
  100. return returnValue;
  101. }
  102. int OpenRaider::command(const char *command, std::vector<char *> *args) {
  103. assert(command != NULL);
  104. assert(command[0] != '\0');
  105. assert(args != NULL);
  106. if (strcmp(command, "set") == 0) {
  107. if (args->size() != 2) {
  108. mConsole->print("Invalid use of set-command");
  109. return -2;
  110. } else {
  111. return set(args->at(0), args->at(1));
  112. }
  113. } else if (strcmp(command, "bind") == 0) {
  114. if (args->size() != 2) {
  115. mConsole->print("Invalid use of bind-command");
  116. return -3;
  117. } else {
  118. return bind(args->at(0), args->at(1));
  119. }
  120. } else if (strcmp(command, "quit") == 0) {
  121. exit(0);
  122. } else if (strcmp(command, "help") == 0) {
  123. if (args->size() == 0) {
  124. mConsole->print("Available commands:");
  125. mConsole->print(" set");
  126. mConsole->print(" bind");
  127. mConsole->print(" help");
  128. mConsole->print(" quit");
  129. mConsole->print("Use help COMMAND to get additional info");
  130. } else if (args->size() == 1) {
  131. return help(args->at(0));
  132. } else {
  133. mConsole->print("Invalid use of help-command");
  134. return -5;
  135. }
  136. } else {
  137. mConsole->print("Unknown command: %s ", command);
  138. return -1;
  139. }
  140. return 0;
  141. }
  142. int OpenRaider::help(const char *cmd) {
  143. if (strcmp(cmd, "set") == 0) {
  144. mConsole->print("set-Command Usage:");
  145. mConsole->print(" set VAR VAL");
  146. mConsole->print("Available Variables:");
  147. mConsole->print(" basedir STRING");
  148. mConsole->print(" pakdir STRING");
  149. mConsole->print(" audiodir STRING");
  150. mConsole->print(" datadir STRING");
  151. mConsole->print(" font STRING");
  152. mConsole->print(" gldriver STRING");
  153. mConsole->print(" size \"INTxINT\"");
  154. mConsole->print(" fullscreen BOOL");
  155. mConsole->print(" audio BOOL");
  156. mConsole->print(" volume BOOL");
  157. mConsole->print(" mouse_x FLOAT");
  158. mConsole->print(" mouse_y FLOAT");
  159. mConsole->print("Enclose STRINGs with \"\"!");
  160. mConsole->print("size expects a STRING in the specified format");
  161. } else if (strcmp(cmd, "bind") == 0) {
  162. mConsole->print("bind-Command Usage:");
  163. mConsole->print(" bind ACTION KEY");
  164. mConsole->print("Available Actions:");
  165. mConsole->print(" menu");
  166. mConsole->print(" console");
  167. mConsole->print(" forward");
  168. mConsole->print(" backward");
  169. mConsole->print(" left");
  170. mConsole->print(" right");
  171. mConsole->print(" jump");
  172. mConsole->print(" crouch");
  173. mConsole->print(" use");
  174. mConsole->print(" holster");
  175. mConsole->print("Key-Format:");
  176. mConsole->print(" 'a' or '1' for character/number keys");
  177. mConsole->print(" \"leftctrl\" for symbols and special keys");
  178. } else {
  179. mConsole->print("No help available for %s", cmd);
  180. return -1;
  181. }
  182. return 0;
  183. }
  184. char *OpenRaider::expandDirectoryNames(const char *s) {
  185. const char *base = "$(basedir)";
  186. const char *pak = "$(pakdir)";
  187. const char *audio = "$(audiodir)";
  188. const char *data = "$(datadir)";
  189. if (mBaseDir != NULL) {
  190. if (strstr(s, base) != NULL) {
  191. return stringReplace(s, base, mBaseDir);
  192. }
  193. }
  194. if (mPakDir != NULL) {
  195. if (strstr(s, pak) != NULL) {
  196. return stringReplace(s, pak, mPakDir);
  197. }
  198. }
  199. if (mAudioDir != NULL) {
  200. if (strstr(s, audio) != NULL) {
  201. return stringReplace(s, audio, mAudioDir);
  202. }
  203. }
  204. if (mDataDir != NULL) {
  205. if (strstr(s, data) != NULL) {
  206. return stringReplace(s, data, mDataDir);
  207. }
  208. }
  209. return NULL;
  210. }
  211. #define CHANGE_DIR_WITH_EXPANSION(a) do { \
  212. char *quotes = stringRemoveQuotes(value); \
  213. char *tmp = expandDirectoryNames(quotes); \
  214. if (tmp == NULL) { \
  215. a = fullPath(quotes, 0); \
  216. } else { \
  217. a = fullPath(tmp, 0); \
  218. delete [] tmp; \
  219. } \
  220. delete [] quotes; \
  221. } while(false)
  222. int OpenRaider::set(const char *var, const char *value) {
  223. if (strcmp(var, "size") == 0) {
  224. // value has format like "\"1024x768\""
  225. unsigned int w = DEFAULT_WIDTH, h = DEFAULT_HEIGHT;
  226. if (sscanf(value, "\"%dx%d\"", &w, &h) != 2) {
  227. mConsole->print("set-size-Error: Invalid value (%s)", value);
  228. return -2;
  229. }
  230. mWindow->setSize(w, h);
  231. } else if (strcmp(var, "fullscreen") == 0) {
  232. bool fullscreen = false;
  233. if (readBool(value, &fullscreen) != 0) {
  234. mConsole->print("set-fullscreen-Error: Invalid value (%s)", value);
  235. return -3;
  236. }
  237. mWindow->setFullscreen(fullscreen);
  238. } else if (strcmp(var, "gldriver") == 0) {
  239. mWindow->setDriver(value);
  240. } else if (strcmp(var, "audio") == 0) {
  241. bool audio = false;
  242. if (readBool(value, &audio) != 0) {
  243. mConsole->print("set-audio-Error: Invalid value (%s)", value);
  244. return -4;
  245. }
  246. mSound->setEnabled(audio);
  247. } else if (strcmp(var, "volume") == 0) {
  248. float vol = 1.0f;
  249. if (sscanf(value, "%f", &vol) != 1) {
  250. mConsole->print("set-volume-Error: Invalid value (%s)", value);
  251. return -5;
  252. }
  253. mSound->setVolume(vol);
  254. } else if (strcmp(var, "mouse_x") == 0) {
  255. float sense = 1.0f;
  256. if (sscanf(value, "%f", &sense) != 1) {
  257. mConsole->print("set-mouse_x-Error: Invalid value (%s)", value);
  258. return -6;
  259. }
  260. //! \todo mouse support
  261. } else if (strcmp(var, "mouse_y") == 0) {
  262. float sense = 1.0f;
  263. if (sscanf(value, "%f", &sense) != 1) {
  264. mConsole->print("set-mouse_y-Error: Invalid value (%s)", value);
  265. return -7;
  266. }
  267. //! \todo mouse support
  268. } else if (strcmp(var, "basedir") == 0) {
  269. CHANGE_DIR_WITH_EXPANSION(mBaseDir);
  270. } else if (strcmp(var, "pakdir") == 0) {
  271. CHANGE_DIR_WITH_EXPANSION(mPakDir);
  272. } else if (strcmp(var, "audiodir") == 0) {
  273. CHANGE_DIR_WITH_EXPANSION(mAudioDir);
  274. } else if (strcmp(var, "datadir") == 0) {
  275. CHANGE_DIR_WITH_EXPANSION(mDataDir);
  276. } else if (strcmp(var, "font") == 0) {
  277. char *quotes = stringReplace(value, "\"", "");
  278. char *tmp = expandDirectoryNames(quotes);
  279. if (tmp == NULL) {
  280. mWindow->setFont(quotes);
  281. } else {
  282. mWindow->setFont(tmp);
  283. delete [] tmp;
  284. }
  285. delete [] quotes;
  286. } else {
  287. mConsole->print("set-Error: Unknown variable (%s = %s)", var, value);
  288. return -1;
  289. }
  290. return 0;
  291. }
  292. int OpenRaider::bind(const char *action, const char *key) {
  293. const char *tmp = action;
  294. if (action[0] == '+')
  295. tmp++;
  296. if (strcmp(tmp, "menu") == 0) {
  297. return bind(menu, key);
  298. } else if (strcmp(tmp, "console") == 0) {
  299. return bind(console, key);
  300. } else if (strcmp(tmp, "forward") == 0) {
  301. return bind(forward, key);
  302. } else if (strcmp(tmp, "backward") == 0) {
  303. return bind(backward, key);
  304. } else if (strcmp(tmp, "left") == 0) {
  305. return bind(left, key);
  306. } else if (strcmp(tmp, "right") == 0) {
  307. return bind(right, key);
  308. } else if (strcmp(tmp, "jump") == 0) {
  309. return bind(jump, key);
  310. } else if (strcmp(tmp, "crouch") == 0) {
  311. return bind(crouch, key);
  312. } else if (strcmp(tmp, "use") == 0) {
  313. return bind(use, key);
  314. } else if (strcmp(tmp, "holster") == 0) {
  315. return bind(holster, key);
  316. } else {
  317. mConsole->print("bind-Error: Unknown action (%s --> %s)", key, action);
  318. return -1;
  319. }
  320. }
  321. int OpenRaider::bind(ActionEvents action, const char *key) {
  322. assert(action != ActionEventCount);
  323. assert(key != NULL);
  324. assert(key[0] != '\0');
  325. size_t length = strlen(key);
  326. if ((key[0] == '\'') && (key[length - 1] == '\'') && (length == 3)) {
  327. // Literal character like w, a, s, d, 0, 1...
  328. char c = key[1];
  329. if (((c >= '0') && (c <= '9'))
  330. || ((c >= 'a') && (c <= 'z'))) {
  331. keyBindings[action] = (KeyboardButton)c;
  332. } else {
  333. mConsole->print("bind-\'\'-Error: Unknown key (%s)", key);
  334. return -1;
  335. }
  336. } else if ((key[0] == '\"') && (key[length - 1] == '\"')) {
  337. // Special characters like tilde, esc, quote...
  338. char *tmp = stringRemoveQuotes(key);
  339. if (strcmp(tmp, "quote") == 0) {
  340. keyBindings[action] = quote;
  341. } else if (strcmp(tmp, "backslash") == 0) {
  342. keyBindings[action] = quote;
  343. } else if (strcmp(tmp, "backspace") == 0) {
  344. keyBindings[action] = backspace;
  345. } else if (strcmp(tmp, "capslock") == 0) {
  346. keyBindings[action] = capslock;
  347. } else if (strcmp(tmp, "comma") == 0) {
  348. keyBindings[action] = comma;
  349. } else if (strcmp(tmp, "del") == 0) {
  350. keyBindings[action] = del;
  351. } else if (strcmp(tmp, "up") == 0) {
  352. keyBindings[action] = up;
  353. } else if (strcmp(tmp, "down") == 0) {
  354. keyBindings[action] = down;
  355. } else if (strcmp(tmp, "left") == 0) {
  356. keyBindings[action] = KeyboardButton::left;
  357. } else if (strcmp(tmp, "right") == 0) {
  358. keyBindings[action] = KeyboardButton::right;
  359. } else if (strcmp(tmp, "end") == 0) {
  360. keyBindings[action] = end;
  361. } else if (strcmp(tmp, "equals") == 0) {
  362. keyBindings[action] = equals;
  363. } else if (strcmp(tmp, "escape") == 0) {
  364. keyBindings[action] = escape;
  365. } else if (strcmp(tmp, "f1") == 0) {
  366. keyBindings[action] = f1;
  367. } else if (strcmp(tmp, "f2") == 0) {
  368. keyBindings[action] = f2;
  369. } else if (strcmp(tmp, "f3") == 0) {
  370. keyBindings[action] = f3;
  371. } else if (strcmp(tmp, "f4") == 0) {
  372. keyBindings[action] = f4;
  373. } else if (strcmp(tmp, "f5") == 0) {
  374. keyBindings[action] = f5;
  375. } else if (strcmp(tmp, "f6") == 0) {
  376. keyBindings[action] = f6;
  377. } else if (strcmp(tmp, "f7") == 0) {
  378. keyBindings[action] = f7;
  379. } else if (strcmp(tmp, "f8") == 0) {
  380. keyBindings[action] = f8;
  381. } else if (strcmp(tmp, "f9") == 0) {
  382. keyBindings[action] = f9;
  383. } else if (strcmp(tmp, "f10") == 0) {
  384. keyBindings[action] = f10;
  385. } else if (strcmp(tmp, "f11") == 0) {
  386. keyBindings[action] = f11;
  387. } else if (strcmp(tmp, "f12") == 0) {
  388. keyBindings[action] = f12;
  389. } else if (strcmp(tmp, "backquote") == 0) {
  390. keyBindings[action] = backquote;
  391. } else if (strcmp(tmp, "home") == 0) {
  392. keyBindings[action] = home;
  393. } else if (strcmp(tmp, "insert") == 0) {
  394. keyBindings[action] = insert;
  395. } else if (strcmp(tmp, "leftalt") == 0) {
  396. keyBindings[action] = leftalt;
  397. } else if (strcmp(tmp, "leftctrl") == 0) {
  398. keyBindings[action] = leftctrl;
  399. } else if (strcmp(tmp, "leftbracket") == 0) {
  400. keyBindings[action] = leftbracket;
  401. } else if (strcmp(tmp, "leftgui") == 0) {
  402. keyBindings[action] = leftgui;
  403. } else if (strcmp(tmp, "leftshift") == 0) {
  404. keyBindings[action] = leftshift;
  405. } else if (strcmp(tmp, "minus") == 0) {
  406. keyBindings[action] = minus;
  407. } else if (strcmp(tmp, "numlock") == 0) {
  408. keyBindings[action] = numlock;
  409. } else if (strcmp(tmp, "pagedown") == 0) {
  410. keyBindings[action] = pagedown;
  411. } else if (strcmp(tmp, "pageup") == 0) {
  412. keyBindings[action] = pageup;
  413. } else if (strcmp(tmp, "pause") == 0) {
  414. keyBindings[action] = pause;
  415. } else if (strcmp(tmp, "dot") == 0) {
  416. keyBindings[action] = dot;
  417. } else if (strcmp(tmp, "rightalt") == 0) {
  418. keyBindings[action] = rightalt;
  419. } else if (strcmp(tmp, "rightctrl") == 0) {
  420. keyBindings[action] = rightctrl;
  421. } else if (strcmp(tmp, "enter") == 0) {
  422. keyBindings[action] = enter;
  423. } else if (strcmp(tmp, "rightgui") == 0) {
  424. keyBindings[action] = rightgui;
  425. } else if (strcmp(tmp, "rightbracket") == 0) {
  426. keyBindings[action] = rightbracket;
  427. } else if (strcmp(tmp, "rightshift") == 0) {
  428. keyBindings[action] = rightshift;
  429. } else if (strcmp(tmp, "scrolllock") == 0) {
  430. keyBindings[action] = scrolllock;
  431. } else if (strcmp(tmp, "semicolon") == 0) {
  432. keyBindings[action] = semicolon;
  433. } else if (strcmp(tmp, "slash") == 0) {
  434. keyBindings[action] = slash;
  435. } else if (strcmp(tmp, "space") == 0) {
  436. keyBindings[action] = space;
  437. } else if (strcmp(tmp, "tab") == 0) {
  438. keyBindings[action] = tab;
  439. } else if (strcmp(tmp, "leftmouse") == 0) {
  440. keyBindings[action] = leftmouse;
  441. } else if (strcmp(tmp, "middlemouse") == 0) {
  442. keyBindings[action] = middlemouse;
  443. } else if (strcmp(tmp, "rightmouse") == 0) {
  444. keyBindings[action] = rightmouse;
  445. } else {
  446. mConsole->print("bind-\"\"-Error: Unknown key (%s)", key);
  447. delete [] tmp;
  448. return -2;
  449. }
  450. delete [] tmp;
  451. } else {
  452. mConsole->print("bind-Error: Unknown key (%s)", key);
  453. return -3;
  454. }
  455. return 0;
  456. }
  457. void OpenRaider::loadPakFolderRecursive(const char *dir) {
  458. struct dirent *ep;
  459. DIR *pakDir;
  460. pakDir = opendir(dir);
  461. if (pakDir != NULL) {
  462. while ((ep = readdir(pakDir)) != NULL) {
  463. if (ep->d_type == DT_DIR) {
  464. if ((strcmp(".", ep->d_name) != 0)
  465. && (strcmp("..", ep->d_name) != 0)) {
  466. char *tmp = bufferString("%s%s", dir, ep->d_name);
  467. char *next = fullPath(tmp, '/');
  468. loadPakFolderRecursive(next);
  469. delete next;
  470. delete tmp;
  471. }
  472. } else {
  473. char *fullPathMap = bufferString("%s%s", dir, ep->d_name);
  474. char *lowerPath = bufferString("%s", fullPathMap);
  475. for (char *p = lowerPath; *p; ++p) *p = (char)tolower(*p);
  476. // Check for valid extension
  477. if (stringEndsWith(lowerPath, ".phd")
  478. || stringEndsWith(lowerPath, ".tr2")
  479. || stringEndsWith(lowerPath, ".tr4")
  480. || stringEndsWith(lowerPath, ".trc")) {
  481. //if (m_tombraider.checkMime(fullPathMap) == 0) {
  482. // mConsole->print("Validated pak: '%s'", fullPathMap);
  483. // Just load relative filename
  484. mMapList.push_back(bufferString("%s", (fullPathMap + strlen(mPakDir))));
  485. //} else {
  486. // mConsole->print("ERROR: pak file '%s' not found or invalid", fullPathMap);
  487. //}
  488. }
  489. delete [] lowerPath;
  490. delete [] fullPathMap;
  491. }
  492. }
  493. closedir(pakDir);
  494. } else {
  495. mConsole->print("Could not open PAK dir %s!", dir);
  496. }
  497. }
  498. void OpenRaider::fillMapList() {
  499. char *tmp = fullPath(mPakDir, '/');
  500. loadPakFolderRecursive(tmp);
  501. delete [] tmp;
  502. mMapListFilled = true;
  503. }
  504. int OpenRaider::initialize() {
  505. assert(mInit == false);
  506. assert(mRunning == false);
  507. // Initialize Windowing
  508. if (mWindow->initialize() != 0)
  509. return -1;
  510. // Initialize OpenGL
  511. if (mWindow->initializeGL() != 0)
  512. return -2;
  513. // Initialize window font
  514. if (mWindow->initializeFont() != 0)
  515. return -3;
  516. // Initialize sound
  517. if (mSound->initialize() != 0)
  518. return -4;
  519. mMenu->setVisible(true);
  520. mInit = true;
  521. return 0;
  522. }
  523. void OpenRaider::run() {
  524. assert(mInit == true);
  525. assert(mRunning == false);
  526. mRunning = true;
  527. while (mRunning) {
  528. clock_t startTime = systemTimerGet();
  529. mWindow->eventHandling();
  530. // Temp Debug
  531. glClearColor(0.25f, 0.75f, 0.25f, 1.0f);
  532. glClear(GL_COLOR_BUFFER_BIT);
  533. mWindow->glEnter2D();
  534. mConsole->display();
  535. mMenu->display();
  536. mWindow->glExit2D();
  537. // Put on screen
  538. mWindow->swapBuffersGL();
  539. // Fill map list after first render pass,
  540. // so menu *loading screen* is visible
  541. if (!mMapListFilled)
  542. fillMapList();
  543. clock_t stopTime = systemTimerGet();
  544. if (MAX_MS_PER_FRAME > (stopTime - startTime))
  545. mWindow->delay(MAX_MS_PER_FRAME - (stopTime - startTime));
  546. }
  547. }
  548. void OpenRaider::handleKeyboard(KeyboardButton key, bool pressed) {
  549. if ((keyBindings[menu] == key) && pressed) {
  550. mMenu->setVisible(!mMenu->isVisible());
  551. } else if (!mMenu->isVisible()) {
  552. if ((keyBindings[console] == key) && pressed) {
  553. mConsole->setVisible(!mConsole->isVisible());
  554. } else if (!mConsole->isVisible()) {
  555. if (keyBindings[forward] == key) {
  556. } else if (keyBindings[backward] == key) {
  557. } else if (keyBindings[left] == key) {
  558. } else if (keyBindings[right] == key) {
  559. } else if (keyBindings[jump] == key) {
  560. } else if (keyBindings[crouch] == key) {
  561. } else if (keyBindings[use] == key) {
  562. } else if (keyBindings[holster] == key) {
  563. }
  564. } else {
  565. mConsole->handleKeyboard(key, pressed);
  566. }
  567. } else {
  568. mMenu->handleKeyboard(key, pressed);
  569. }
  570. }
  571. void OpenRaider::handleText(char *text, bool notFinished) {
  572. if ((mConsole->isVisible()) && (!mMenu->isVisible())) {
  573. mConsole->handleText(text, notFinished);
  574. }
  575. }
  576. void OpenRaider::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
  577. if (mMenu->isVisible()) {
  578. mMenu->handleMouseClick(x, y, button, released);
  579. }
  580. }
  581. void OpenRaider::handleMouseMotion(int xrel, int yrel) {
  582. }
  583. void OpenRaider::handleMouseScroll(int xrel, int yrel) {
  584. if ((mConsole->isVisible()) && (!mMenu->isVisible())) {
  585. mConsole->handleMouseScroll(xrel, yrel);
  586. }
  587. }