Space Walk board game
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.
 
 

58 lines
1.3 KiB

  1. #include <ncurses.h> // A_REVERSE
  2. #include <sstream> // istringstream
  3. #include <vector>
  4. #include "inputoutput.h"
  5. #include "messagebox.h"
  6. MessageBox::MessageBox(std::string message) :
  7. MessageBox(message, "") {
  8. }
  9. MessageBox::MessageBox(std::string message, std::string title) {
  10. // Split message on newline
  11. std::vector<std::string> lines;
  12. std::istringstream strStream(message);
  13. std::string tmpStr;
  14. while (std::getline(strStream, tmpStr, '\n')) {
  15. lines.push_back(tmpStr);
  16. }
  17. int rows;
  18. int cols;
  19. Window::getMaXYZ(stdscr, rows, cols);
  20. // Calculate window dimension and size
  21. int winRows = lines.size() + 8;
  22. int winCols = cols * 0.9;
  23. int y = (rows - winRows) / 2;
  24. int x = (cols - winCols) / 2;
  25. this->setWindow(winRows, winCols, y, x);
  26. // Print title
  27. title = IO::untrim(!title.empty() ? title : "Message", winCols - 2);
  28. this->print(title, 0, 0, A_REVERSE);
  29. // Print the message line by line
  30. y = (winRows - lines.size()) / 2 - 1;
  31. for (auto l : lines) {
  32. this->setYX(y, 0);
  33. this->printCenter(l);
  34. y++;
  35. }
  36. this->setYX(winRows - 3, 0);
  37. this->printCenter("Press <Space> to continue ",
  38. COLOR_PAIR(PAIR_GRAY_BLACK_BRIGHT));
  39. this->render();
  40. // Press space to continue
  41. while(!IO::getQuit()) {
  42. IO::update();
  43. if (IO::getKeyName() == " ") {
  44. break;
  45. }
  46. }
  47. }