CMainMenu.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /*
  2. * CMainMenu.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 "CMainMenu.h"
  12. #include "CCampaignScreen.h"
  13. #include "CreditsScreen.h"
  14. #include "../lobby/CBonusSelection.h"
  15. #include "../lobby/CSelectionBase.h"
  16. #include "../lobby/CLobbyScreen.h"
  17. #include "../gui/CursorHandler.h"
  18. #include "../windows/GUIClasses.h"
  19. #include "../gui/CGuiHandler.h"
  20. #include "../widgets/CComponent.h"
  21. #include "../widgets/Buttons.h"
  22. #include "../widgets/MiscWidgets.h"
  23. #include "../widgets/ObjectLists.h"
  24. #include "../widgets/TextControls.h"
  25. #include "../windows/InfoWindows.h"
  26. #include "../CServerHandler.h"
  27. #include "../CGameInfo.h"
  28. #include "../CMusicHandler.h"
  29. #include "../CVideoHandler.h"
  30. #include "../CPlayerInterface.h"
  31. #include "../Client.h"
  32. #include "../CMT.h"
  33. #include "../../CCallback.h"
  34. #include "../../lib/CGeneralTextHandler.h"
  35. #include "../../lib/JsonNode.h"
  36. #include "../../lib/serializer/Connection.h"
  37. #include "../../lib/serializer/CTypeList.h"
  38. #include "../../lib/filesystem/Filesystem.h"
  39. #include "../../lib/filesystem/CCompressedStream.h"
  40. #include "../../lib/VCMIDirs.h"
  41. #include "../../lib/mapping/CMap.h"
  42. #include "../../lib/CStopWatch.h"
  43. #include "../../lib/NetPacksLobby.h"
  44. #include "../../lib/CThreadHelper.h"
  45. #include "../../lib/CConfigHandler.h"
  46. #include "../../lib/GameConstants.h"
  47. #include "../../lib/CRandomGenerator.h"
  48. #include "../../lib/CondSh.h"
  49. #include "../../lib/mapping/CCampaignHandler.h"
  50. #if defined(SINGLE_PROCESS_APP) && defined(VCMI_ANDROID)
  51. #include "../../server/CVCMIServer.h"
  52. #include <SDL.h>
  53. #endif
  54. namespace fs = boost::filesystem;
  55. std::shared_ptr<CMainMenu> CMM;
  56. ISelectionScreenInfo * SEL;
  57. static void do_quit()
  58. {
  59. GH.pushUserEvent(EUserEvent::FORCE_QUIT);
  60. }
  61. CMenuScreen::CMenuScreen(const JsonNode & configNode)
  62. : CWindowObject(BORDERED), config(configNode)
  63. {
  64. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  65. background = std::make_shared<CPicture>(config["background"].String());
  66. if(config["scalable"].Bool())
  67. background->scaleTo(GH.screenDimensions());
  68. pos = background->center();
  69. for(const JsonNode & node : config["items"].Vector())
  70. menuNameToEntry.push_back(node["name"].String());
  71. for(const JsonNode & node : config["images"].Vector())
  72. images.push_back(CMainMenu::createPicture(node));
  73. //Hardcoded entry
  74. menuNameToEntry.push_back("credits");
  75. tabs = std::make_shared<CTabbedInt>(std::bind(&CMenuScreen::createTab, this, _1));
  76. tabs->type |= REDRAW_PARENT;
  77. }
  78. std::shared_ptr<CIntObject> CMenuScreen::createTab(size_t index)
  79. {
  80. if(config["items"].Vector().size() == index)
  81. return std::make_shared<CreditsScreen>(this->pos);
  82. else
  83. return std::make_shared<CMenuEntry>(this, config["items"].Vector()[index]);
  84. }
  85. void CMenuScreen::show(SDL_Surface * to)
  86. {
  87. if(!config["video"].isNull())
  88. CCS->videoh->update((int)config["video"]["x"].Float() + pos.x, (int)config["video"]["y"].Float() + pos.y, to, true, false);
  89. CIntObject::show(to);
  90. }
  91. void CMenuScreen::activate()
  92. {
  93. CCS->musich->playMusic("Music/MainMenu", true, true);
  94. if(!config["video"].isNull())
  95. CCS->videoh->open(config["video"]["name"].String());
  96. CIntObject::activate();
  97. }
  98. void CMenuScreen::deactivate()
  99. {
  100. if(!config["video"].isNull())
  101. CCS->videoh->close();
  102. CIntObject::deactivate();
  103. }
  104. void CMenuScreen::switchToTab(size_t index)
  105. {
  106. tabs->setActive(index);
  107. }
  108. void CMenuScreen::switchToTab(std::string name)
  109. {
  110. switchToTab(vstd::find_pos(menuNameToEntry, name));
  111. }
  112. size_t CMenuScreen::getActiveTab() const
  113. {
  114. return tabs->getActive();
  115. }
  116. //funciton for std::string -> std::function conversion for main menu
  117. static std::function<void()> genCommand(CMenuScreen * menu, std::vector<std::string> menuType, const std::string & string)
  118. {
  119. static const std::vector<std::string> commandType = {"to", "campaigns", "start", "load", "exit", "highscores"};
  120. static const std::vector<std::string> gameType = {"single", "multi", "campaign", "tutorial"};
  121. std::list<std::string> commands;
  122. boost::split(commands, string, boost::is_any_of("\t "));
  123. if(!commands.empty())
  124. {
  125. size_t index = std::find(commandType.begin(), commandType.end(), commands.front()) - commandType.begin();
  126. commands.pop_front();
  127. if(index > 3 || !commands.empty())
  128. {
  129. switch(index)
  130. {
  131. case 0: //to - switch to another tab, if such tab exists
  132. {
  133. size_t index2 = std::find(menuType.begin(), menuType.end(), commands.front()) - menuType.begin();
  134. if(index2 != menuType.size())
  135. return std::bind((void(CMenuScreen::*)(size_t))&CMenuScreen::switchToTab, menu, index2);
  136. break;
  137. }
  138. case 1: //open campaign selection window
  139. {
  140. return std::bind(&CMainMenu::openCampaignScreen, CMM, commands.front());
  141. break;
  142. }
  143. case 2: //start
  144. {
  145. switch(std::find(gameType.begin(), gameType.end(), commands.front()) - gameType.begin())
  146. {
  147. case 0:
  148. return std::bind(CMainMenu::openLobby, ESelectionScreen::newGame, true, nullptr, ELoadMode::NONE);
  149. case 1:
  150. return []() { GH.pushIntT<CMultiMode>(ESelectionScreen::newGame); };
  151. case 2:
  152. return std::bind(CMainMenu::openLobby, ESelectionScreen::campaignList, true, nullptr, ELoadMode::NONE);
  153. case 3:
  154. return std::bind(CInfoWindow::showInfoDialog, "Sorry, tutorial is not implemented yet\n", std::vector<std::shared_ptr<CComponent>>(), PlayerColor(1));
  155. }
  156. break;
  157. }
  158. case 3: //load
  159. {
  160. switch(std::find(gameType.begin(), gameType.end(), commands.front()) - gameType.begin())
  161. {
  162. case 0:
  163. return std::bind(CMainMenu::openLobby, ESelectionScreen::loadGame, true, nullptr, ELoadMode::SINGLE);
  164. case 1:
  165. return []() { GH.pushIntT<CMultiMode>(ESelectionScreen::loadGame); };
  166. case 2:
  167. return std::bind(CMainMenu::openLobby, ESelectionScreen::loadGame, true, nullptr, ELoadMode::CAMPAIGN);
  168. case 3:
  169. return std::bind(CInfoWindow::showInfoDialog, "Sorry, tutorial is not implemented yet\n", std::vector<std::shared_ptr<CComponent>>(), PlayerColor(1));
  170. }
  171. }
  172. break;
  173. case 4: //exit
  174. {
  175. return std::bind(CInfoWindow::showYesNoDialog, CGI->generaltexth->allTexts[69], std::vector<std::shared_ptr<CComponent>>(), do_quit, 0, PlayerColor(1));
  176. }
  177. break;
  178. case 5: //highscores
  179. {
  180. return std::bind(CInfoWindow::showInfoDialog, "Sorry, high scores menu is not implemented yet\n", std::vector<std::shared_ptr<CComponent>>(), PlayerColor(1));
  181. }
  182. }
  183. }
  184. }
  185. logGlobal->error("Failed to parse command: %s", string);
  186. return std::function<void()>();
  187. }
  188. std::shared_ptr<CButton> CMenuEntry::createButton(CMenuScreen * parent, const JsonNode & button)
  189. {
  190. std::function<void()> command = genCommand(parent, parent->menuNameToEntry, button["command"].String());
  191. std::pair<std::string, std::string> help;
  192. if(!button["help"].isNull() && button["help"].Float() > 0)
  193. help = CGI->generaltexth->zelp[(size_t)button["help"].Float()];
  194. int posx = static_cast<int>(button["x"].Float());
  195. if(posx < 0)
  196. posx = pos.w + posx;
  197. int posy = static_cast<int>(button["y"].Float());
  198. if(posy < 0)
  199. posy = pos.h + posy;
  200. auto result = std::make_shared<CButton>(Point(posx, posy), button["name"].String(), help, command, (int)button["hotkey"].Float());
  201. if (button["center"].Bool())
  202. result->moveBy(Point(-result->pos.w/2, -result->pos.h/2));
  203. return result;
  204. }
  205. CMenuEntry::CMenuEntry(CMenuScreen * parent, const JsonNode & config)
  206. {
  207. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  208. type |= REDRAW_PARENT;
  209. pos = parent->pos;
  210. for(const JsonNode & node : config["images"].Vector())
  211. images.push_back(CMainMenu::createPicture(node));
  212. for(const JsonNode & node : config["buttons"].Vector())
  213. {
  214. buttons.push_back(createButton(parent, node));
  215. buttons.back()->hoverable = true;
  216. buttons.back()->type |= REDRAW_PARENT;
  217. }
  218. }
  219. CMainMenuConfig::CMainMenuConfig()
  220. : campaignSets(JsonNode(ResourceID("config/campaignSets.json"))), config(JsonNode(ResourceID("config/mainmenu.json")))
  221. {
  222. }
  223. CMainMenuConfig & CMainMenuConfig::get()
  224. {
  225. static CMainMenuConfig config;
  226. return config;
  227. }
  228. const JsonNode & CMainMenuConfig::getConfig() const
  229. {
  230. return config;
  231. }
  232. const JsonNode & CMainMenuConfig::getCampaigns() const
  233. {
  234. return campaignSets;
  235. }
  236. CMainMenu::CMainMenu()
  237. {
  238. pos.w = GH.screenDimensions().x;
  239. pos.h = GH.screenDimensions().y;
  240. GH.defActionsDef = 63;
  241. menu = std::make_shared<CMenuScreen>(CMainMenuConfig::get().getConfig()["window"]);
  242. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  243. backgroundAroundMenu = std::make_shared<CFilledTexture>("DIBOXBCK", pos);
  244. }
  245. CMainMenu::~CMainMenu()
  246. {
  247. boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
  248. if(GH.curInt == this)
  249. GH.curInt = nullptr;
  250. }
  251. void CMainMenu::update()
  252. {
  253. if(CMM != this->shared_from_this()) //don't update if you are not a main interface
  254. return;
  255. if(GH.listInt.empty())
  256. {
  257. GH.pushInt(CMM);
  258. GH.pushInt(menu);
  259. menu->switchToTab(menu->getActiveTab());
  260. }
  261. // Handles mouse and key input
  262. GH.updateTime();
  263. GH.handleEvents();
  264. // check for null othervice crash on finishing a campaign
  265. // /FIXME: find out why GH.listInt is empty to begin with
  266. if(GH.topInt())
  267. GH.topInt()->show(screen);
  268. }
  269. void CMainMenu::openLobby(ESelectionScreen screenType, bool host, const std::vector<std::string> * names, ELoadMode loadMode)
  270. {
  271. CSH->resetStateForLobby(screenType == ESelectionScreen::newGame ? StartInfo::NEW_GAME : StartInfo::LOAD_GAME, names);
  272. CSH->screenType = screenType;
  273. CSH->loadMode = loadMode;
  274. GH.pushIntT<CSimpleJoinScreen>(host);
  275. }
  276. void CMainMenu::openCampaignLobby(const std::string & campaignFileName)
  277. {
  278. auto ourCampaign = std::make_shared<CCampaignState>(CCampaignHandler::getCampaign(campaignFileName));
  279. openCampaignLobby(ourCampaign);
  280. }
  281. void CMainMenu::openCampaignLobby(std::shared_ptr<CCampaignState> campaign)
  282. {
  283. CSH->resetStateForLobby(StartInfo::CAMPAIGN);
  284. CSH->screenType = ESelectionScreen::campaignList;
  285. CSH->campaignStateToSend = campaign;
  286. GH.pushIntT<CSimpleJoinScreen>();
  287. }
  288. void CMainMenu::openCampaignScreen(std::string name)
  289. {
  290. if(vstd::contains(CMainMenuConfig::get().getCampaigns().Struct(), name))
  291. {
  292. GH.pushIntT<CCampaignScreen>(CMainMenuConfig::get().getCampaigns()[name]);
  293. return;
  294. }
  295. logGlobal->error("Unknown campaign set: %s", name);
  296. }
  297. std::shared_ptr<CMainMenu> CMainMenu::create()
  298. {
  299. if(!CMM)
  300. CMM = std::shared_ptr<CMainMenu>(new CMainMenu());
  301. GH.terminate_cond->setn(false);
  302. return CMM;
  303. }
  304. std::shared_ptr<CPicture> CMainMenu::createPicture(const JsonNode & config)
  305. {
  306. return std::make_shared<CPicture>(config["name"].String(), (int)config["x"].Float(), (int)config["y"].Float());
  307. }
  308. CMultiMode::CMultiMode(ESelectionScreen ScreenType)
  309. : screenType(ScreenType)
  310. {
  311. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  312. background = std::make_shared<CPicture>("MUPOPUP.bmp");
  313. pos = background->center(); //center, window has size of bg graphic
  314. picture = std::make_shared<CPicture>("MUMAP.bmp", 16, 77);
  315. statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 465, 440, 18), 7, 465));
  316. playerName = std::make_shared<CTextInput>(Rect(19, 436, 334, 16), background->getSurface());
  317. playerName->setText(settings["general"]["playerName"].String());
  318. playerName->cb += std::bind(&CMultiMode::onNameChange, this, _1);
  319. buttonHotseat = std::make_shared<CButton>(Point(373, 78), "MUBHOT.DEF", CGI->generaltexth->zelp[266], std::bind(&CMultiMode::hostTCP, this));
  320. buttonHost = std::make_shared<CButton>(Point(373, 78 + 57 * 1), "MUBHOST.DEF", CButton::tooltip("Host TCP/IP game", ""), std::bind(&CMultiMode::hostTCP, this));
  321. buttonJoin = std::make_shared<CButton>(Point(373, 78 + 57 * 2), "MUBJOIN.DEF", CButton::tooltip("Join TCP/IP game", ""), std::bind(&CMultiMode::joinTCP, this));
  322. buttonCancel = std::make_shared<CButton>(Point(373, 424), "MUBCANC.DEF", CGI->generaltexth->zelp[288], [=](){ close();}, SDLK_ESCAPE);
  323. }
  324. void CMultiMode::hostTCP()
  325. {
  326. auto savedScreenType = screenType;
  327. close();
  328. GH.pushIntT<CMultiPlayers>(settings["general"]["playerName"].String(), savedScreenType, true, ELoadMode::MULTI);
  329. }
  330. void CMultiMode::joinTCP()
  331. {
  332. auto savedScreenType = screenType;
  333. close();
  334. GH.pushIntT<CMultiPlayers>(settings["general"]["playerName"].String(), savedScreenType, false, ELoadMode::MULTI);
  335. }
  336. void CMultiMode::onNameChange(std::string newText)
  337. {
  338. Settings name = settings.write["general"]["playerName"];
  339. name->String() = newText;
  340. }
  341. CMultiPlayers::CMultiPlayers(const std::string & firstPlayer, ESelectionScreen ScreenType, bool Host, ELoadMode LoadMode)
  342. : loadMode(LoadMode), screenType(ScreenType), host(Host)
  343. {
  344. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  345. background = std::make_shared<CPicture>("MUHOTSEA.bmp");
  346. pos = background->center(); //center, window has size of bg graphic
  347. std::string text = CGI->generaltexth->allTexts[446];
  348. boost::replace_all(text, "\t", "\n");
  349. textTitle = std::make_shared<CTextBox>(text, Rect(25, 20, 315, 50), 0, FONT_BIG, ETextAlignment::CENTER, Colors::WHITE); //HOTSEAT Please enter names
  350. for(int i = 0; i < inputNames.size(); i++)
  351. {
  352. inputNames[i] = std::make_shared<CTextInput>(Rect(60, 85 + i * 30, 280, 16), background->getSurface());
  353. inputNames[i]->cb += std::bind(&CMultiPlayers::onChange, this, _1);
  354. }
  355. buttonOk = std::make_shared<CButton>(Point(95, 338), "MUBCHCK.DEF", CGI->generaltexth->zelp[560], std::bind(&CMultiPlayers::enterSelectionScreen, this), SDLK_RETURN);
  356. buttonCancel = std::make_shared<CButton>(Point(205, 338), "MUBCANC.DEF", CGI->generaltexth->zelp[561], [=](){ close();}, SDLK_ESCAPE);
  357. statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 381, 348, 18), 7, 381));
  358. inputNames[0]->setText(firstPlayer, true);
  359. #ifndef VCMI_IOS
  360. inputNames[0]->giveFocus();
  361. #endif
  362. }
  363. void CMultiPlayers::onChange(std::string newText)
  364. {
  365. }
  366. void CMultiPlayers::enterSelectionScreen()
  367. {
  368. std::vector<std::string> names;
  369. for(auto name : inputNames)
  370. {
  371. if(name->getText().length())
  372. names.push_back(name->getText());
  373. }
  374. Settings name = settings.write["general"]["playerName"];
  375. name->String() = names[0];
  376. CMainMenu::openLobby(screenType, host, &names, loadMode);
  377. }
  378. CSimpleJoinScreen::CSimpleJoinScreen(bool host)
  379. {
  380. OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
  381. background = std::make_shared<CPicture>("MUDIALOG.bmp"); // address background
  382. pos = background->center(); //center, window has size of bg graphic (x,y = 396,278 w=232 h=212)
  383. textTitle = std::make_shared<CTextBox>("", Rect(20, 20, 205, 50), 0, FONT_BIG, ETextAlignment::CENTER, Colors::WHITE);
  384. inputAddress = std::make_shared<CTextInput>(Rect(25, 68, 175, 16), background->getSurface());
  385. inputPort = std::make_shared<CTextInput>(Rect(25, 115, 175, 16), background->getSurface());
  386. if(host && !settings["session"]["donotstartserver"].Bool())
  387. {
  388. textTitle->setText("Connecting...");
  389. startConnectThread();
  390. }
  391. else
  392. {
  393. textTitle->setText("Enter address:");
  394. inputAddress->cb += std::bind(&CSimpleJoinScreen::onChange, this, _1);
  395. inputPort->cb += std::bind(&CSimpleJoinScreen::onChange, this, _1);
  396. inputPort->filters += std::bind(&CTextInput::numberFilter, _1, _2, 0, 65535);
  397. buttonOk = std::make_shared<CButton>(Point(26, 142), "MUBCHCK.DEF", CGI->generaltexth->zelp[560], std::bind(&CSimpleJoinScreen::connectToServer, this), SDLK_RETURN);
  398. inputAddress->giveFocus();
  399. }
  400. inputAddress->setText(host ? CServerHandler::localhostAddress : CSH->getHostAddress(), true);
  401. inputPort->setText(boost::lexical_cast<std::string>(CSH->getHostPort()), true);
  402. buttonCancel = std::make_shared<CButton>(Point(142, 142), "MUBCANC.DEF", CGI->generaltexth->zelp[561], std::bind(&CSimpleJoinScreen::leaveScreen, this), SDLK_ESCAPE);
  403. statusBar = CGStatusBar::create(std::make_shared<CPicture>(background->getSurface(), Rect(7, 186, 218, 18), 7, 186));
  404. }
  405. void CSimpleJoinScreen::connectToServer()
  406. {
  407. textTitle->setText("Connecting...");
  408. buttonOk->block(true);
  409. GH.stopTextInput();
  410. startConnectThread(inputAddress->getText(), boost::lexical_cast<ui16>(inputPort->getText()));
  411. }
  412. void CSimpleJoinScreen::leaveScreen()
  413. {
  414. if(CSH->state == EClientState::CONNECTING)
  415. {
  416. textTitle->setText("Closing...");
  417. CSH->state = EClientState::CONNECTION_CANCELLED;
  418. }
  419. else if(GH.listInt.size() && GH.listInt.front().get() == this)
  420. {
  421. close();
  422. }
  423. }
  424. void CSimpleJoinScreen::onChange(const std::string & newText)
  425. {
  426. buttonOk->block(inputAddress->getText().empty() || inputPort->getText().empty());
  427. }
  428. void CSimpleJoinScreen::startConnectThread(const std::string & addr, ui16 port)
  429. {
  430. #if defined(SINGLE_PROCESS_APP) && defined(VCMI_ANDROID)
  431. // in single process build server must use same JNIEnv as client
  432. // as server runs in a separate thread, it must not attempt to search for Java classes (and they're already cached anyway)
  433. // https://github.com/libsdl-org/SDL/blob/main/docs/README-android.md#threads-and-the-java-vm
  434. CVCMIServer::reuseClientJNIEnv(SDL_AndroidGetJNIEnv());
  435. #endif
  436. boost::thread(&CSimpleJoinScreen::connectThread, this, addr, port);
  437. }
  438. void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port)
  439. {
  440. setThreadName("CSimpleJoinScreen::connectThread");
  441. if(!addr.length())
  442. CSH->startLocalServerAndConnect();
  443. else
  444. CSH->justConnectToServer(addr, port);
  445. if(GH.listInt.size() && GH.listInt.front().get() == this)
  446. {
  447. close();
  448. }
  449. }
  450. CLoadingScreen::CLoadingScreen(std::function<void()> loader)
  451. : CWindowObject(BORDERED, getBackground()), loadingThread(loader)
  452. {
  453. CCS->musich->stopMusic(5000);
  454. }
  455. CLoadingScreen::~CLoadingScreen()
  456. {
  457. loadingThread.join();
  458. }
  459. void CLoadingScreen::showAll(SDL_Surface * to)
  460. {
  461. //FIXME: filling screen with transparency? BLACK intended?
  462. //Rect rect(0, 0, to->w, to->h);
  463. //CSDL_Ext::fillRect(to, rect, Colors::TRANSPARENCY);
  464. CWindowObject::showAll(to);
  465. }
  466. std::string CLoadingScreen::getBackground()
  467. {
  468. const auto & conf = CMainMenuConfig::get().getConfig()["loading"].Vector();
  469. if(conf.empty())
  470. {
  471. return "loadbar";
  472. }
  473. else
  474. {
  475. return RandomGeneratorUtil::nextItem(conf, CRandomGenerator::getDefault())->String();
  476. }
  477. }