CreditsScreen.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * CreditsScreen.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "CreditsScreen.h"
  12. #include "../mainmenu/CMainMenu.h"
  13. #include "../gui/CGuiHandler.h"
  14. #include "../widgets/TextControls.h"
  15. #include "../widgets/ObjectLists.h"
  16. #include "../../lib/filesystem/Filesystem.h"
  17. CreditsScreen::CreditsScreen()
  18. : positionCounter(0)
  19. {
  20. addUsedEvents(LCLICK | RCLICK);
  21. type |= REDRAW_PARENT;
  22. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  23. pos.w = CMM->menu->pos.w;
  24. pos.h = CMM->menu->pos.h;
  25. auto textFile = CResourceHandler::get()->load(ResourceID("DATA/CREDITS.TXT"))->readAll();
  26. std::string text((char *)textFile.first.get(), textFile.second);
  27. size_t firstQuote = text.find('\"') + 1;
  28. text = text.substr(firstQuote, text.find('\"', firstQuote) - firstQuote);
  29. credits = std::make_shared<CMultiLineLabel>(Rect(pos.w - 350, 0, 350, 600), FONT_CREDITS, CENTER, Colors::WHITE, text);
  30. credits->scrollTextTo(-600); // move all text below the screen
  31. }
  32. void CreditsScreen::show(SDL_Surface * to)
  33. {
  34. CIntObject::show(to);
  35. positionCounter++;
  36. if(positionCounter % 2 == 0)
  37. credits->scrollTextBy(1);
  38. //end of credits, close this screen
  39. if(credits->textSize.y + 600 < positionCounter / 2)
  40. clickRight(false, false);
  41. }
  42. void CreditsScreen::clickLeft(tribool down, bool previousState)
  43. {
  44. clickRight(down, previousState);
  45. }
  46. void CreditsScreen::clickRight(tribool down, bool previousState)
  47. {
  48. CTabbedInt * menu = dynamic_cast<CTabbedInt *>(parent);
  49. assert(menu);
  50. menu->setActive(0);
  51. }