Open Source Tomb Raider Engine
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Menu.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*!
  2. * \file src/Menu.cpp
  3. * \brief Menu 'overlay'
  4. *
  5. * \author xythobuz
  6. */
  7. #ifdef __APPLE__
  8. #include <OpenGL/gl.h>
  9. #include <OpenGL/glu.h>
  10. #else
  11. #include <GL/gl.h>
  12. #include <GL/glu.h>
  13. #endif
  14. #include "config.h"
  15. #include "main.h"
  16. #include "Menu.h"
  17. #include "utils/strings.h"
  18. Menu::Menu() {
  19. mVisible = false;
  20. mCursor = 0;
  21. mMin = 0;
  22. mainText.text = bufferString(VERSION);
  23. mainText.color[0] = 0xFF;
  24. mainText.color[1] = 0xFF;
  25. mainText.color[2] = 0xFF;
  26. mainText.color[3] = 0xFF;
  27. mainText.scale = 1.2f;
  28. mainText.y = 10;
  29. mainText.w = 0;
  30. mainText.h = 0;
  31. }
  32. Menu::~Menu() {
  33. delete [] mainText.text;
  34. }
  35. void Menu::setVisible(bool visible) {
  36. mVisible = visible;
  37. }
  38. bool Menu::isVisible() {
  39. return mVisible;
  40. }
  41. void Menu::displayMapList() {
  42. // Estimate displayable number of items
  43. int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
  44. // Select which part of the list to show
  45. int min, max;
  46. if (((int)mCursor - (items / 2)) > 0)
  47. min = mCursor - (items / 2);
  48. else
  49. min = 0;
  50. if ((mCursor + (items / 2)) < gOpenRaider->mMapList.size())
  51. max = mCursor + (items / 2);
  52. else
  53. max = gOpenRaider->mMapList.size();
  54. while ((max - min) < items) {
  55. if (min > 0)
  56. min--;
  57. else if (max < ((int)gOpenRaider->mMapList.size()))
  58. max++;
  59. else
  60. break;
  61. }
  62. mMin = min;
  63. for (int i = 0; i < (max - min); i++) {
  64. char *map = gOpenRaider->mMapList[i + min];
  65. unsigned char color[4] = {0xFF, 0xFF, 0xFF, 0xFF};
  66. if ((i + min) == (int)mCursor) {
  67. // Less greem & red --> highlight in red
  68. color[1] = 0x42;
  69. color[2] = 0x42;
  70. }
  71. gOpenRaider->mWindow->drawText(25, 100 + (25 * i), 0.75f, color, "%s", map);
  72. }
  73. }
  74. void Menu::display() {
  75. Window *window = gOpenRaider->mWindow;
  76. unsigned char color[4] = {0xFF, 0xFF, 0xFF, 0xFF};
  77. if (mVisible) {
  78. // Draw half-transparent *overlay*
  79. glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
  80. glDisable(GL_TEXTURE_2D);
  81. glRecti(0, 0, window->mWidth, window->mHeight);
  82. glEnable(GL_TEXTURE_2D);
  83. // Draw heading text
  84. mainText.x = (window->mWidth / 2) - (mainText.w / 2);
  85. window->writeString(&mainText);
  86. if (!gOpenRaider->mMapListFilled) {
  87. gOpenRaider->mWindow->drawText(25, (window->mHeight / 2) - 20, 0.75f, color, "Generating map list...");
  88. } else {
  89. if (gOpenRaider->mMapList.size() == 0) {
  90. gOpenRaider->mWindow->drawText(25, (window->mHeight / 2) - 20, 0.75f, color, "No maps found! See README.md");
  91. } else {
  92. // draw *play button* above list
  93. glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  94. glDisable(GL_TEXTURE_2D);
  95. glRecti(25, 25, 100, 75);
  96. glEnable(GL_TEXTURE_2D);
  97. color[0] = color[1] = color[2] = 0x00;
  98. gOpenRaider->mWindow->drawText(40, 35, 0.75f, color, "Play");
  99. color[0] = color[1] = color[2] = 0xFF;
  100. displayMapList();
  101. }
  102. }
  103. }
  104. }
  105. void Menu::handleKeyboard(KeyboardButton key, bool pressed) {
  106. if (!pressed)
  107. return;
  108. if (key == up) {
  109. if (mCursor > 0)
  110. mCursor--;
  111. else
  112. mCursor = gOpenRaider->mMapList.size() - 1;
  113. } else if (key == down) {
  114. if (mCursor < (gOpenRaider->mMapList.size() - 1))
  115. mCursor++;
  116. else
  117. mCursor = 0;
  118. } else if (key == right) {
  119. int i = 10;
  120. if (mCursor > (gOpenRaider->mMapList.size() - 11))
  121. i = gOpenRaider->mMapList.size() - 1 - mCursor;
  122. while (i-- > 0)
  123. handleKeyboard(down, true);
  124. } else if (key == left) {
  125. int i = 10;
  126. if (mCursor < 10)
  127. i = mCursor;
  128. while (i-- > 0)
  129. handleKeyboard(up, true);
  130. } else if (key == enter) {
  131. }
  132. }
  133. void Menu::handleMouseClick(unsigned int x, unsigned int y, KeyboardButton button, bool released) {
  134. int items = (gOpenRaider->mWindow->mHeight - 110) / 25;
  135. if ((!released) || (button != leftmouse))
  136. return;
  137. if ((y >= 100) && (y <= (unsigned int)(100 + (25 * items)))) {
  138. y -= 100;
  139. mCursor = mMin + (y / 25);
  140. } else if ((y >= 25) && (y <= 100) && (x >= 25) && (x <= 125)) {
  141. // Play button
  142. mCursor = 0;
  143. }
  144. }