Laserlicht 2 months ago
parent
commit
768b233813
1 changed files with 8 additions and 6 deletions
  1. 8 6
      client/lobby/RandomMapTab.cpp

+ 8 - 6
client/lobby/RandomMapTab.cpp

@@ -141,16 +141,18 @@ RandomMapTab::RandomMapTab():
 	//set combo box callbacks
 	if(auto w = widget<ComboBox>("templateList"))
 	{
-		w->onConstructItems = [](std::vector<const void *> & curItems){
+		auto getTemplates = [](){
 			auto templates = LIBRARY->tplh->getTemplates();
-		
 			boost::range::sort(templates, [](const CRmgTemplate * a, const CRmgTemplate * b){
 				return a->getName() < b->getName();
 			});
+			return templates;
+		};
 
+		w->onConstructItems = [getTemplates](std::vector<const void *> & curItems){
 			curItems.push_back(nullptr); //default template
 			
-			for(auto & t : templates)
+			for(auto & t : getTemplates())
 				curItems.push_back(t);
 		};
 		
@@ -166,14 +168,14 @@ RandomMapTab::RandomMapTab():
 			return std::string("");
 		};
 
-		w->addCallback([this]()
+		w->addCallback([this, getTemplates]() // no real dropdown... - instead open dialog
 		{
 			std::vector<std::string> texts;
 			texts.push_back(readText(variables["randomTemplate"]));
-			for(auto & t : LIBRARY->tplh->getTemplates())
+			for(auto & t : getTemplates())
 				texts.push_back(t->getName());
 
-			ENGINE->windows().popWindows(1); // no real dropdown...
+			ENGINE->windows().popWindows(1);
 			ENGINE->windows().createAndPushWindow<CObjectListWindow>(texts, nullptr, LIBRARY->generaltexth->translate("vcmi.lobby.templatesSelect.hover"), LIBRARY->generaltexth->translate("vcmi.lobby.templatesSelect.help"), [this](int index){
 				widget<ComboBox>("templateList")->setItem(index);
 				templateIndex = index;