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 20KB

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