<commit_before>#include "game/skirmish/gui/mapselectionwindow.hpp"

#include "gui/ng/listwidget.hpp"

#include "game/skirmish/mapmanager.hpp"

namespace qrw
{

MapSelectionWindow::MapSelectionWindow(MapManager& mapManager)
	: mapManager_(mapManager)
{
	mapNameList_ = new namelessgui::ListWidget();
	mapNameList_->signalItemSelected.connect([this] (const std::string& mapName) { slotMapSelectionChanged(mapName); });
	mapNameList_->setPosition({0, 0});
	addWidget(mapNameList_);

	mapPreview_ = new namelessgui::RectangularWidget();
	mapPreview_->setFillColor(sf::Color::Transparent);
	mapPreview_->setAnchor({0, 0});
	mapPreview_->setParentAnchor({0.4, 0});
	mapPreview_->setRelativePosition({5, 5});
	mapPreview_->setVisible(true);
	addWidget(mapPreview_);

	// Initialize map list
	auto mapNames = mapManager_.getMapList();
	for(auto& mapName : mapNames)
		mapNameList_->addItem(mapName);
}

const std::string& MapSelectionWindow::getSelectedMapName() const
{
	return selectedMapName_;
}

void MapSelectionWindow::setSize(const sf::Vector2f& size)
{
	RectangularWidget::setSize(size);
	mapNameList_->setSize({size.x * 0.4f, size.y - 5.0f});

	maxMapPreviewSize_ = {size.x * 0.6f - 10.0f, size.y - 10.0f};
	updateMapPreviewSize();
}

void MapSelectionWindow::slotMapSelectionChanged(const std::string& mapName)
{
	selectedMapName_ = mapName;

	sf::Texture* texture = mapManager_.loadMapPreview(selectedMapName_);
	mapPreview_->setTexture(texture);
	mapPreview_->setFillColor(sf::Color::White);
	updateMapPreviewSize();
}

void MapSelectionWindow::updateMapPreviewSize()
{
	if(mapPreview_->getTexture() == nullptr) return;

	sf::Vector2f sizeMapPreview = maxMapPreviewSize_;
	sf::Vector2f sizeTexture(mapPreview_->getTexture()->getSize().x, mapPreview_->getTexture()->getSize().y);

	// Only resize if texture is valid and possible preview size is > zero<commit_msg>Revert "Hide MapPreview if no map is present."<commit_after>#include "game/skirmish/gui/mapselectionwindow.hpp"

#include "gui/ng/listwidget.hpp"

#include "game/skirmish/mapmanager.hpp"

namespace qrw
{

MapSelectionWindow::MapSelectionWindow(MapManager& mapManager)
	: mapManager_(mapManager)
{
	mapNameList_ = new namelessgui::ListWidget();
	mapNameList_->signalItemSelected.connect([this] (const std::string& mapName) { slotMapSelectionChanged(mapName); });
	mapNameList_->setPosition({0, 0});
	addWidget(mapNameList_);

	mapPreview_ = new namelessgui::RectangularWidget();
	mapPreview_->setFillColor(sf::Color::White);
	mapPreview_->setAnchor({0, 0});
	mapPreview_->setParentAnchor({0.4, 0});
	mapPreview_->setRelativePosition({5, 5});
	mapPreview_->setVisible(true);
	addWidget(mapPreview_);

	// Initialize map list
	auto mapNames = mapManager_.getMapList();
	for(auto& mapName : mapNames)
		mapNameList_->addItem(mapName);
}

const std::string& MapSelectionWindow::getSelectedMapName() const
{
	return selectedMapName_;
}

void MapSelectionWindow::setSize(const sf::Vector2f& size)
{
	RectangularWidget::setSize(size);
	mapNameList_->setSize({size.x * 0.4f, size.y - 5.0f});

	maxMapPreviewSize_ = {size.x * 0.6f - 10.0f, size.y - 10.0f};
	updateMapPreviewSize();
}

void MapSelectionWindow::slotMapSelectionChanged(const std::string& mapName)
{
	selectedMapName_ = mapName;

	sf::Texture* texture = mapManager_.loadMapPreview(selectedMapName_);
	mapPreview_->setTexture(texture);

	updateMapPreviewSize();
}

void MapSelectionWindow::updateMapPreviewSize()
{
	if(mapPreview_->getTexture() == nullptr) return;

	sf::Vector2f sizeMapPreview = maxMapPreviewSize_;
	sf::Vector2f sizeTexture(mapPreview_->getTexture()->getSize().x, mapPreview_->getTexture()->getSize().y);

	// Only resize if texture is valid and possible preview size is > zero
{'fraction_non_alphanumeric': 0.14208826695371368, 'fraction_numerical': 0.012917115177610334, 'mean_word_length': 7.2052980132450335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3303942', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1194, 'n_words': 207}