2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* SelectionTab.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "SelectionTab.h"
|
|
|
|
#include "CSelectionBase.h"
|
|
|
|
#include "CLobbyScreen.h"
|
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CPlayerInterface.h"
|
|
|
|
#include "../CServerHandler.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-04-27 19:21:06 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2023-08-17 09:56:50 +02:00
|
|
|
#include "../gui/WindowHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/CComponent.h"
|
|
|
|
#include "../widgets/Buttons.h"
|
2024-05-12 12:24:13 +02:00
|
|
|
#include "../widgets/CTextInput.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/MiscWidgets.h"
|
|
|
|
#include "../widgets/ObjectLists.h"
|
2023-05-30 16:31:45 +02:00
|
|
|
#include "../widgets/Slider.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../windows/GUIClasses.h"
|
|
|
|
#include "../windows/InfoWindows.h"
|
2023-09-30 15:05:12 +02:00
|
|
|
#include "../windows/CMapOverview.h"
|
2023-02-01 20:42:06 +02:00
|
|
|
#include "../render/CAnimation.h"
|
2023-08-14 23:08:20 +02:00
|
|
|
#include "../render/IImage.h"
|
2023-09-04 17:01:44 +02:00
|
|
|
#include "../render/IRenderHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
#include "../../CCallback.h"
|
|
|
|
|
2023-04-30 00:03:50 +02:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
2024-08-31 13:00:36 +02:00
|
|
|
#include "../../lib/IGameSettings.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../../lib/filesystem/Filesystem.h"
|
2023-06-25 21:28:24 +02:00
|
|
|
#include "../../lib/campaign/CampaignState.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../../lib/mapping/CMapInfo.h"
|
2023-05-24 01:05:59 +02:00
|
|
|
#include "../../lib/mapping/CMapHeader.h"
|
2023-05-24 00:14:06 +02:00
|
|
|
#include "../../lib/mapping/MapFormat.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../../lib/texts/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/texts/TextOperations.h"
|
2023-08-17 09:56:50 +02:00
|
|
|
#include "../../lib/TerrainHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-08-08 00:38:13 +02:00
|
|
|
bool mapSorter::operator()(const std::shared_ptr<ElementInfo> aaa, const std::shared_ptr<ElementInfo> bbb)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-08 00:38:13 +02:00
|
|
|
if(aaa->isFolder || bbb->isFolder)
|
2023-08-08 02:04:06 +02:00
|
|
|
{
|
|
|
|
if(aaa->isFolder != bbb->isFolder)
|
|
|
|
return (aaa->isFolder > bbb->isFolder);
|
|
|
|
else
|
2023-09-02 19:04:06 +02:00
|
|
|
{
|
|
|
|
if(boost::algorithm::starts_with(aaa->folderName, "..") || boost::algorithm::starts_with(bbb->folderName, ".."))
|
|
|
|
return boost::algorithm::starts_with(aaa->folderName, "..");
|
2023-08-08 02:04:06 +02:00
|
|
|
return boost::ilexicographical_compare(aaa->folderName, bbb->folderName);
|
2023-09-02 19:04:06 +02:00
|
|
|
}
|
2023-08-08 02:04:06 +02:00
|
|
|
}
|
2023-08-08 00:38:13 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
auto a = aaa->mapHeader.get();
|
|
|
|
auto b = bbb->mapHeader.get();
|
|
|
|
if(a && b) //if we are sorting scenarios
|
|
|
|
{
|
|
|
|
switch(sortBy)
|
|
|
|
{
|
|
|
|
case _format: //by map format (RoE, WoG, etc)
|
|
|
|
return (a->version < b->version);
|
|
|
|
break;
|
|
|
|
case _loscon: //by loss conditions
|
2023-06-18 12:51:11 +02:00
|
|
|
return (a->defeatIconIndex < b->defeatIconIndex);
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
case _playerAm: //by player amount
|
2024-01-10 00:38:54 +02:00
|
|
|
int playerAmntB;
|
|
|
|
int humenPlayersB;
|
|
|
|
int playerAmntA;
|
|
|
|
int humenPlayersA;
|
2018-01-05 19:21:07 +02:00
|
|
|
playerAmntB = humenPlayersB = playerAmntA = humenPlayersA = 0;
|
|
|
|
for(int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
if(a->players[i].canHumanPlay)
|
|
|
|
{
|
|
|
|
playerAmntA++;
|
|
|
|
humenPlayersA++;
|
|
|
|
}
|
|
|
|
else if(a->players[i].canComputerPlay)
|
|
|
|
{
|
|
|
|
playerAmntA++;
|
|
|
|
}
|
|
|
|
if(b->players[i].canHumanPlay)
|
|
|
|
{
|
|
|
|
playerAmntB++;
|
|
|
|
humenPlayersB++;
|
|
|
|
}
|
|
|
|
else if(b->players[i].canComputerPlay)
|
|
|
|
{
|
|
|
|
playerAmntB++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(playerAmntB != playerAmntA)
|
|
|
|
return (playerAmntA < playerAmntB);
|
|
|
|
else
|
|
|
|
return (humenPlayersA < humenPlayersB);
|
|
|
|
break;
|
|
|
|
case _size: //by size of map
|
|
|
|
return (a->width < b->width);
|
|
|
|
break;
|
|
|
|
case _viccon: //by victory conditions
|
2023-06-18 12:51:11 +02:00
|
|
|
return (a->victoryIconIndex < b->victoryIconIndex);
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
case _name: //by name
|
2023-09-27 22:53:13 +02:00
|
|
|
return boost::ilexicographical_compare(a->name.toString(), b->name.toString());
|
2018-01-05 19:21:07 +02:00
|
|
|
case _fileName: //by filename
|
|
|
|
return boost::ilexicographical_compare(aaa->fileURI, bbb->fileURI);
|
2024-01-07 21:17:44 +02:00
|
|
|
case _changeDate: //by changedate
|
|
|
|
return aaa->lastWrite < bbb->lastWrite;
|
2018-01-05 19:21:07 +02:00
|
|
|
default:
|
2023-09-27 22:53:13 +02:00
|
|
|
return boost::ilexicographical_compare(a->name.toString(), b->name.toString());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else //if we are sorting campaigns
|
|
|
|
{
|
|
|
|
switch(sortBy)
|
|
|
|
{
|
|
|
|
case _numOfMaps: //by number of maps in campaign
|
2023-06-26 00:07:55 +02:00
|
|
|
return aaa->campaign->scenariosCount() < bbb->campaign->scenariosCount();
|
2018-01-05 19:21:07 +02:00
|
|
|
case _name: //by name
|
2023-09-27 22:53:13 +02:00
|
|
|
return boost::ilexicographical_compare(aaa->campaign->getNameTranslated(), bbb->campaign->getNameTranslated());
|
2018-01-05 19:21:07 +02:00
|
|
|
default:
|
2023-09-27 22:53:13 +02:00
|
|
|
return boost::ilexicographical_compare(aaa->campaign->getNameTranslated(), bbb->campaign->getNameTranslated());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 11:04:05 +02:00
|
|
|
// pick sorting order based on selection
|
|
|
|
static ESortBy getSortBySelectionScreen(ESelectionScreen Type)
|
|
|
|
{
|
|
|
|
switch(Type)
|
|
|
|
{
|
|
|
|
case ESelectionScreen::newGame:
|
|
|
|
return ESortBy::_name;
|
|
|
|
case ESelectionScreen::loadGame:
|
|
|
|
case ESelectionScreen::saveGame:
|
|
|
|
return ESortBy::_fileName;
|
|
|
|
case ESelectionScreen::campaignList:
|
|
|
|
return ESortBy::_name;
|
|
|
|
}
|
|
|
|
// Should not reach here. But let's not crash the game.
|
|
|
|
return ESortBy::_name;
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
SelectionTab::SelectionTab(ESelectionScreen Type)
|
2023-10-21 02:12:34 +02:00
|
|
|
: CIntObject(LCLICK | SHOW_POPUP | KEYBOARD | DOUBLECLICK), callOnSelect(nullptr), tabType(Type), selectionPos(0), sortModeAscending(true), inputNameRect{32, 539, 350, 20}, curFolder(""), currentMapSizeFilter(0), showRandom(false)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2024-01-07 21:17:44 +02:00
|
|
|
|
2021-05-08 11:04:05 +02:00
|
|
|
generalSortingBy = getSortBySelectionScreen(tabType);
|
2024-04-11 12:22:41 +02:00
|
|
|
sortingBy = _format;
|
2021-05-08 11:04:05 +02:00
|
|
|
|
2024-01-07 21:17:44 +02:00
|
|
|
bool enableUiEnhancements = settings["general"]["enableUiEnhancements"].Bool();
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
if(tabType != ESelectionScreen::campaignList)
|
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
background = std::make_shared<CPicture>(ImagePath::builtin("SCSELBCK.bmp"), 0, 6);
|
2018-01-05 19:21:07 +02:00
|
|
|
pos = background->pos;
|
2024-05-12 16:17:49 +02:00
|
|
|
inputName = std::make_shared<CTextInput>(inputNameRect, Point(-32, -25), ImagePath::builtin("GSSTRIP.bmp"));
|
|
|
|
inputName->setFilterFilename();
|
2022-11-26 23:12:20 +02:00
|
|
|
labelMapSizes = std::make_shared<CLabel>(87, 62, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[510]);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-02-29 13:45:08 +02:00
|
|
|
// TODO: Global constants?
|
2024-05-18 21:59:28 +02:00
|
|
|
constexpr std::array sizes = {CMapHeader::MAP_SIZE_SMALL, CMapHeader::MAP_SIZE_MIDDLE, CMapHeader::MAP_SIZE_LARGE, CMapHeader::MAP_SIZE_XLARGE, 0};
|
|
|
|
constexpr std::array filterIconNmes = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"};
|
|
|
|
constexpr std::array filterShortcuts = { EShortcut::MAPS_SIZE_S, EShortcut::MAPS_SIZE_M, EShortcut::MAPS_SIZE_L, EShortcut::MAPS_SIZE_XL, EShortcut::MAPS_SIZE_ALL };
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
for(int i = 0; i < 5; i++)
|
2024-05-18 21:59:28 +02:00
|
|
|
buttonsSortBy.push_back(std::make_shared<CButton>(Point(158 + 47 * i, 46), AnimationPath::builtin(filterIconNmes[i]), CGI->generaltexth->zelp[54 + i], std::bind(&SelectionTab::filter, this, sizes[i], true), filterShortcuts[i]));
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2024-05-18 21:59:28 +02:00
|
|
|
constexpr std::array xpos = {23, 55, 88, 121, 306, 339};
|
|
|
|
constexpr std::array sortIconNames = {"SCBUTT1.DEF", "SCBUTT2.DEF", "SCBUTCP.DEF", "SCBUTT3.DEF", "SCBUTT4.DEF", "SCBUTT5.DEF"};
|
|
|
|
constexpr std::array sortShortcuts = { EShortcut::MAPS_SORT_PLAYERS, EShortcut::MAPS_SORT_SIZE, EShortcut::MAPS_SORT_FORMAT, EShortcut::MAPS_SORT_NAME, EShortcut::MAPS_SORT_VICTORY, EShortcut::MAPS_SORT_DEFEAT };
|
2018-01-05 19:21:07 +02:00
|
|
|
for(int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
ESortBy criteria = (ESortBy)i;
|
|
|
|
if(criteria == _name)
|
|
|
|
criteria = generalSortingBy;
|
|
|
|
|
2024-05-18 21:59:28 +02:00
|
|
|
buttonsSortBy.push_back(std::make_shared<CButton>(Point(xpos[i], 86), AnimationPath::builtin(sortIconNames[i]), CGI->generaltexth->zelp[107 + i], std::bind(&SelectionTab::sortBy, this, criteria), sortShortcuts[i]));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int positionsToShow = 18;
|
|
|
|
std::string tabTitle;
|
|
|
|
switch(tabType)
|
|
|
|
{
|
|
|
|
case ESelectionScreen::newGame:
|
|
|
|
tabTitle = CGI->generaltexth->arraytxt[229];
|
|
|
|
break;
|
|
|
|
case ESelectionScreen::loadGame:
|
|
|
|
tabTitle = CGI->generaltexth->arraytxt[230];
|
|
|
|
break;
|
|
|
|
case ESelectionScreen::saveGame:
|
|
|
|
positionsToShow = 16;
|
|
|
|
tabTitle = CGI->generaltexth->arraytxt[231];
|
|
|
|
break;
|
|
|
|
case ESelectionScreen::campaignList:
|
|
|
|
tabTitle = CGI->generaltexth->allTexts[726];
|
2023-07-03 18:24:12 +02:00
|
|
|
setRedrawParent(true); // we use parent background so we need to make sure it's will be redrawn too
|
2018-01-05 19:21:07 +02:00
|
|
|
pos.w = parent->pos.w;
|
|
|
|
pos.h = parent->pos.h;
|
|
|
|
pos.x += 3;
|
|
|
|
pos.y += 6;
|
|
|
|
|
2024-05-18 21:59:28 +02:00
|
|
|
buttonsSortBy.push_back(std::make_shared<CButton>(Point(23, 86), AnimationPath::builtin("CamCusM.DEF"), CButton::tooltip(), std::bind(&SelectionTab::sortBy, this, _numOfMaps), EShortcut::MAPS_SORT_MAPS));
|
|
|
|
buttonsSortBy.push_back(std::make_shared<CButton>(Point(55, 86), AnimationPath::builtin("CamCusL.DEF"), CButton::tooltip(), std::bind(&SelectionTab::sortBy, this, _name), EShortcut::MAPS_SORT_NAME));
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-01-07 21:17:44 +02:00
|
|
|
if(enableUiEnhancements)
|
|
|
|
{
|
2024-05-18 21:59:28 +02:00
|
|
|
auto sortByDate = std::make_shared<CButton>(Point(371, 85), AnimationPath::builtin("selectionTabSortDate"), CButton::tooltip("", CGI->generaltexth->translate("vcmi.lobby.sortDate")), std::bind(&SelectionTab::sortBy, this, ESortBy::_changeDate), EShortcut::MAPS_SORT_CHANGEDATE);
|
2024-02-28 22:24:19 +02:00
|
|
|
sortByDate->setOverlay(std::make_shared<CPicture>(ImagePath::builtin("lobby/selectionTabSortDate")));
|
|
|
|
buttonsSortBy.push_back(sortByDate);
|
2024-01-07 21:17:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
for(int i = 0; i < positionsToShow; i++)
|
2024-06-04 18:09:25 +02:00
|
|
|
listItems.push_back(std::make_shared<ListItem>(Point(30, 129 + i * 25)));
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
labelTabTitle = std::make_shared<CLabel>(205, 28, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, tabTitle);
|
2024-01-07 21:17:44 +02:00
|
|
|
slider = std::make_shared<CSlider>(Point(372, 86 + (enableUiEnhancements ? 30 : 0)), (tabType != ESelectionScreen::saveGame ? 480 : 430) - (enableUiEnhancements ? 30 : 0), std::bind(&SelectionTab::sliderMove, this, _1), positionsToShow, (int)curItems.size(), 0, Orientation::VERTICAL, CSlider::BLUE);
|
2023-05-29 12:08:08 +02:00
|
|
|
slider->setPanningStep(24);
|
2023-06-22 22:49:38 +02:00
|
|
|
|
|
|
|
// create scroll bounds that encompass all area in this UI element to the left of slider (including area of slider itself)
|
|
|
|
// entire screen can't be used in here since map description might also have slider
|
|
|
|
slider->setScrollBounds(Rect(pos.x - slider->pos.x, 0, slider->pos.x + slider->pos.w - pos.x, slider->pos.h ));
|
2018-01-05 19:21:07 +02:00
|
|
|
filter(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::toggleMode()
|
|
|
|
{
|
|
|
|
if(CSH->isGuest())
|
|
|
|
{
|
|
|
|
allItems.clear();
|
|
|
|
curItems.clear();
|
|
|
|
if(slider)
|
|
|
|
slider->block(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(tabType)
|
|
|
|
{
|
|
|
|
case ESelectionScreen::newGame:
|
2023-08-09 01:54:09 +02:00
|
|
|
{
|
|
|
|
inputName->disable();
|
|
|
|
auto files = getFiles("Maps/", EResType::MAP);
|
2023-08-23 14:07:50 +02:00
|
|
|
files.erase(ResourcePath("Maps/Tutorial.tut", EResType::MAP));
|
2023-08-09 01:54:09 +02:00
|
|
|
parseMaps(files);
|
|
|
|
break;
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
case ESelectionScreen::loadGame:
|
|
|
|
inputName->disable();
|
2023-07-09 14:30:47 +02:00
|
|
|
parseSaves(getFiles("Saves/", EResType::SAVEGAME));
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ESelectionScreen::saveGame:
|
2023-07-09 14:30:47 +02:00
|
|
|
parseSaves(getFiles("Saves/", EResType::SAVEGAME));
|
2018-01-05 19:21:07 +02:00
|
|
|
inputName->enable();
|
2023-08-11 23:56:20 +02:00
|
|
|
inputName->activate();
|
2018-01-05 19:21:07 +02:00
|
|
|
restoreLastSelection();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ESelectionScreen::campaignList:
|
|
|
|
parseCampaigns(getFiles("Maps/", EResType::CAMPAIGN));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(slider)
|
|
|
|
{
|
|
|
|
slider->block(false);
|
|
|
|
filter(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CSH->campaignStateToSend)
|
|
|
|
{
|
|
|
|
CSH->setCampaignState(CSH->campaignStateToSend);
|
|
|
|
CSH->campaignStateToSend.reset();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
restoreLastSelection();
|
|
|
|
}
|
|
|
|
}
|
2020-10-01 10:38:06 +02:00
|
|
|
slider->setAmount((int)curItems.size());
|
2018-01-05 19:21:07 +02:00
|
|
|
updateListItems();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
2023-07-09 16:55:39 +02:00
|
|
|
void SelectionTab::clickReleased(const Point & cursorPosition)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-07-08 13:33:04 +02:00
|
|
|
int line = getLine();
|
2022-05-07 11:56:34 +02:00
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
if(line != -1)
|
|
|
|
{
|
|
|
|
select(line);
|
|
|
|
}
|
2024-05-12 16:17:49 +02:00
|
|
|
#ifdef VCMI_MOBILE
|
2023-07-08 13:33:04 +02:00
|
|
|
// focus input field if clicked inside it
|
|
|
|
else if(inputName && inputName->isActive() && inputNameRect.isInside(cursorPosition))
|
|
|
|
inputName->giveFocus();
|
2021-03-24 20:02:12 +02:00
|
|
|
#endif
|
2023-07-08 13:33:04 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2022-05-07 11:56:34 +02:00
|
|
|
|
2023-04-27 19:21:06 +02:00
|
|
|
void SelectionTab::keyPressed(EShortcut key)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
int moveBy = 0;
|
2023-02-02 18:02:25 +02:00
|
|
|
switch(key)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-28 13:22:03 +02:00
|
|
|
case EShortcut::MOVE_UP:
|
2018-01-05 19:21:07 +02:00
|
|
|
moveBy = -1;
|
|
|
|
break;
|
2023-04-28 13:22:03 +02:00
|
|
|
case EShortcut::MOVE_DOWN:
|
2018-01-05 19:21:07 +02:00
|
|
|
moveBy = +1;
|
|
|
|
break;
|
2023-04-28 13:22:03 +02:00
|
|
|
case EShortcut::MOVE_PAGE_UP:
|
2020-10-01 10:38:06 +02:00
|
|
|
moveBy = -(int)listItems.size() + 1;
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
2023-04-28 13:22:03 +02:00
|
|
|
case EShortcut::MOVE_PAGE_DOWN:
|
2020-10-01 10:38:06 +02:00
|
|
|
moveBy = +(int)listItems.size() - 1;
|
2018-01-05 19:21:07 +02:00
|
|
|
break;
|
2023-04-28 13:22:03 +02:00
|
|
|
case EShortcut::MOVE_FIRST:
|
2018-01-05 19:21:07 +02:00
|
|
|
select(-slider->getValue());
|
|
|
|
return;
|
2023-04-28 13:22:03 +02:00
|
|
|
case EShortcut::MOVE_LAST:
|
2020-10-01 10:38:06 +02:00
|
|
|
select((int)curItems.size() - slider->getValue());
|
2018-01-05 19:21:07 +02:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2020-10-01 10:38:06 +02:00
|
|
|
select((int)selectionPos - slider->getValue() + moveBy);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void SelectionTab::clickDouble(const Point & cursorPosition)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-08 02:04:06 +02:00
|
|
|
int position = getLine();
|
2023-08-10 22:15:32 +02:00
|
|
|
int itemIndex = position + slider->getValue();
|
2023-08-08 02:04:06 +02:00
|
|
|
|
2023-08-10 22:15:32 +02:00
|
|
|
if(itemIndex >= curItems.size())
|
2023-08-08 02:04:06 +02:00
|
|
|
return;
|
|
|
|
|
2024-05-10 18:05:59 +02:00
|
|
|
auto clickedItem = curItems[itemIndex];
|
|
|
|
auto selectedItem = getSelectedMapInfo();
|
|
|
|
|
|
|
|
if (clickedItem != selectedItem)
|
|
|
|
{
|
|
|
|
// double-click BUT player hit different item than he had selected
|
|
|
|
// ignore - clickReleased would still trigger and update selection.
|
|
|
|
// After which another (3rd) click if it happens would still register as double-click
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-12 19:51:18 +02:00
|
|
|
if(itemIndex >= 0 && curItems[itemIndex]->isFolder)
|
2023-09-12 20:28:54 +02:00
|
|
|
{
|
|
|
|
select(position);
|
2023-08-08 02:04:06 +02:00
|
|
|
return;
|
2023-09-12 20:28:54 +02:00
|
|
|
}
|
2023-08-08 02:04:06 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
if(getLine() != -1) //double clicked scenarios list
|
|
|
|
{
|
2023-07-08 13:33:04 +02:00
|
|
|
(static_cast<CLobbyScreen *>(parent))->buttonStart->clickPressed(cursorPosition);
|
|
|
|
(static_cast<CLobbyScreen *>(parent))->buttonStart->clickReleased(cursorPosition);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-20 01:53:33 +02:00
|
|
|
void SelectionTab::showPopupWindow(const Point & cursorPosition)
|
|
|
|
{
|
2023-07-20 22:05:09 +02:00
|
|
|
int position = getLine();
|
2023-07-20 01:53:33 +02:00
|
|
|
int py = position + slider->getValue();
|
2023-07-20 22:05:09 +02:00
|
|
|
|
2023-07-20 02:20:54 +02:00
|
|
|
if(py >= curItems.size())
|
|
|
|
return;
|
2023-07-20 22:05:09 +02:00
|
|
|
|
2023-08-08 23:46:30 +02:00
|
|
|
if(!curItems[py]->isFolder)
|
2024-07-15 00:51:41 +02:00
|
|
|
{
|
2024-08-10 14:59:22 +02:00
|
|
|
std::string creationDateTime;
|
|
|
|
std::string author;
|
|
|
|
std::string mapVersion;
|
|
|
|
if(tabType != ESelectionScreen::campaignList)
|
|
|
|
{
|
|
|
|
author = curItems[py]->mapHeader->author.toString() + (!curItems[py]->mapHeader->authorContact.toString().empty() ? (" <" + curItems[py]->mapHeader->authorContact.toString() + ">") : "");
|
|
|
|
mapVersion = curItems[py]->mapHeader->mapVersion.toString();
|
|
|
|
creationDateTime = tabType == ESelectionScreen::newGame && curItems[py]->mapHeader->creationDateTime ? TextOperations::getFormattedDateTimeLocal(curItems[py]->mapHeader->creationDateTime) : curItems[py]->date;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
author = curItems[py]->campaign->getAuthor() + (!curItems[py]->campaign->getAuthorContact().empty() ? (" <" + curItems[py]->campaign->getAuthorContact() + ">") : "");
|
|
|
|
mapVersion = curItems[py]->campaign->getCampaignVersion();
|
|
|
|
creationDateTime = curItems[py]->campaign->getCreationDateTime() ? TextOperations::getFormattedDateTimeLocal(curItems[py]->campaign->getCreationDateTime()) : curItems[py]->date;
|
|
|
|
}
|
|
|
|
|
2024-06-29 13:13:59 +02:00
|
|
|
GH.windows().createAndPushWindow<CMapOverview>(
|
|
|
|
curItems[py]->getNameTranslated(),
|
|
|
|
curItems[py]->fullFileURI,
|
2024-07-15 00:51:41 +02:00
|
|
|
creationDateTime,
|
|
|
|
author,
|
2024-08-10 14:59:22 +02:00
|
|
|
mapVersion,
|
2024-06-29 13:13:59 +02:00
|
|
|
ResourcePath(curItems[py]->fileURI),
|
|
|
|
tabType
|
|
|
|
);
|
2024-07-15 00:51:41 +02:00
|
|
|
}
|
2023-09-12 20:28:54 +02:00
|
|
|
else
|
|
|
|
CRClickPopup::createAndPush(curItems[py]->folderName);
|
2023-07-20 01:53:33 +02:00
|
|
|
}
|
|
|
|
|
2023-08-10 22:15:32 +02:00
|
|
|
auto SelectionTab::checkSubfolder(std::string path)
|
2023-08-08 00:38:13 +02:00
|
|
|
{
|
2023-08-11 01:49:10 +02:00
|
|
|
struct Ret
|
|
|
|
{
|
|
|
|
std::string folderName;
|
|
|
|
std::string baseFolder;
|
|
|
|
bool parentExists;
|
|
|
|
bool fileInFolder;
|
|
|
|
} ret;
|
2023-08-10 22:15:32 +02:00
|
|
|
|
|
|
|
ret.parentExists = (curFolder != "");
|
|
|
|
ret.fileInFolder = false;
|
2023-08-08 00:38:13 +02:00
|
|
|
|
|
|
|
std::vector<std::string> filetree;
|
|
|
|
// delete first element (e.g. 'MAPS')
|
2023-08-08 02:04:06 +02:00
|
|
|
boost::split(filetree, path, boost::is_any_of("/"));
|
2023-08-08 00:38:13 +02:00
|
|
|
filetree.erase(filetree.begin());
|
2023-08-08 02:04:06 +02:00
|
|
|
std::string pathWithoutPrefix = boost::algorithm::join(filetree, "/");
|
|
|
|
|
2023-08-11 20:09:41 +02:00
|
|
|
if(!filetree.empty())
|
|
|
|
{
|
|
|
|
filetree.pop_back();
|
|
|
|
ret.baseFolder = boost::algorithm::join(filetree, "/");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret.baseFolder = "";
|
2023-08-08 00:38:13 +02:00
|
|
|
|
2023-08-10 22:15:32 +02:00
|
|
|
if(boost::algorithm::starts_with(ret.baseFolder, curFolder))
|
2023-08-08 00:38:13 +02:00
|
|
|
{
|
2023-08-10 22:15:32 +02:00
|
|
|
std::string folder = ret.baseFolder.substr(curFolder.size());
|
2023-08-08 00:38:13 +02:00
|
|
|
|
2023-08-08 02:04:06 +02:00
|
|
|
if(folder != "")
|
|
|
|
{
|
|
|
|
boost::split(filetree, folder, boost::is_any_of("/"));
|
2023-08-10 22:15:32 +02:00
|
|
|
ret.folderName = filetree[0];
|
2023-08-08 02:04:06 +02:00
|
|
|
}
|
2023-08-08 00:38:13 +02:00
|
|
|
}
|
|
|
|
|
2023-08-08 02:04:06 +02:00
|
|
|
if(boost::algorithm::starts_with(pathWithoutPrefix, curFolder))
|
|
|
|
if(boost::count(pathWithoutPrefix.substr(curFolder.size()), '/') == 0)
|
2023-08-10 22:15:32 +02:00
|
|
|
ret.fileInFolder = true;
|
2023-08-08 02:04:06 +02:00
|
|
|
|
2023-08-11 01:49:10 +02:00
|
|
|
return ret;
|
2023-07-20 01:53:33 +02:00
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
// A new size filter (Small, Medium, ...) has been selected. Populate
|
|
|
|
// selMaps with the relevant data.
|
|
|
|
void SelectionTab::filter(int size, bool selectFirst)
|
|
|
|
{
|
2023-08-09 00:13:02 +02:00
|
|
|
if(size == -1)
|
2023-08-10 22:15:32 +02:00
|
|
|
size = currentMapSizeFilter;
|
|
|
|
currentMapSizeFilter = size;
|
2023-08-09 00:13:02 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
curItems.clear();
|
|
|
|
|
2023-08-08 23:46:30 +02:00
|
|
|
for(auto elem : allItems)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-08 23:46:30 +02:00
|
|
|
if((elem->mapHeader && (!size || elem->mapHeader->width == size)) || tabType == ESelectionScreen::campaignList)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-10-21 02:12:34 +02:00
|
|
|
if(showRandom)
|
|
|
|
curFolder = "RANDOMMAPS/";
|
|
|
|
|
2023-08-11 23:56:20 +02:00
|
|
|
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(elem->originalFileURI);
|
2023-08-07 00:10:06 +02:00
|
|
|
|
2023-10-21 02:12:34 +02:00
|
|
|
if((showRandom && baseFolder != "RANDOMMAPS") || (!showRandom && baseFolder == "RANDOMMAPS"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(parentExists && !showRandom)
|
2023-08-08 23:46:30 +02:00
|
|
|
{
|
|
|
|
auto folder = std::make_shared<ElementInfo>();
|
2023-08-08 00:38:13 +02:00
|
|
|
folder->isFolder = true;
|
2023-08-10 23:52:16 +02:00
|
|
|
folder->folderName = ".. (" + curFolder + ")";
|
|
|
|
auto itemIt = boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return boost::starts_with(e->folderName, ".."); });
|
2023-08-10 22:15:32 +02:00
|
|
|
if (itemIt == curItems.end()) {
|
2023-08-08 00:38:13 +02:00
|
|
|
curItems.push_back(folder);
|
2023-08-10 22:15:32 +02:00
|
|
|
}
|
2023-08-08 23:46:30 +02:00
|
|
|
}
|
2023-08-07 00:10:06 +02:00
|
|
|
|
2024-01-17 14:50:00 +02:00
|
|
|
auto folder = std::make_shared<ElementInfo>();
|
2023-08-08 23:46:30 +02:00
|
|
|
folder->isFolder = true;
|
|
|
|
folder->folderName = folderName;
|
2023-08-10 22:15:32 +02:00
|
|
|
auto itemIt = boost::range::find_if(curItems, [folder](std::shared_ptr<ElementInfo> e) { return e->folderName == folder->folderName; });
|
|
|
|
if (itemIt == curItems.end() && folderName != "") {
|
2023-08-08 23:46:30 +02:00
|
|
|
curItems.push_back(folder);
|
2023-08-07 00:10:06 +02:00
|
|
|
}
|
2023-08-08 23:46:30 +02:00
|
|
|
|
|
|
|
if(fileInFolder)
|
2018-01-05 19:21:07 +02:00
|
|
|
curItems.push_back(elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(curItems.size())
|
|
|
|
{
|
|
|
|
slider->block(false);
|
2020-10-01 10:38:06 +02:00
|
|
|
slider->setAmount((int)curItems.size());
|
2018-01-05 19:21:07 +02:00
|
|
|
sort();
|
|
|
|
if(selectFirst)
|
|
|
|
{
|
2023-08-09 00:13:02 +02:00
|
|
|
int firstPos = boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return !e->isFolder; }) - curItems.begin();
|
|
|
|
if(firstPos < curItems.size())
|
|
|
|
{
|
|
|
|
slider->scrollTo(firstPos);
|
|
|
|
callOnSelect(curItems[firstPos]);
|
|
|
|
selectAbs(firstPos);
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-09 00:13:02 +02:00
|
|
|
updateListItems();
|
|
|
|
redraw();
|
2018-01-05 19:21:07 +02:00
|
|
|
slider->block(true);
|
|
|
|
if(callOnSelect)
|
|
|
|
callOnSelect(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::sortBy(int criteria)
|
|
|
|
{
|
|
|
|
if(criteria == sortingBy)
|
|
|
|
{
|
|
|
|
sortModeAscending = !sortModeAscending;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sortingBy = (ESortBy)criteria;
|
|
|
|
sortModeAscending = true;
|
|
|
|
}
|
|
|
|
sort();
|
|
|
|
|
2023-08-08 02:04:06 +02:00
|
|
|
selectAbs(-1);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::sort()
|
|
|
|
{
|
|
|
|
if(sortingBy != generalSortingBy)
|
|
|
|
std::stable_sort(curItems.begin(), curItems.end(), mapSorter(generalSortingBy));
|
|
|
|
std::stable_sort(curItems.begin(), curItems.end(), mapSorter(sortingBy));
|
|
|
|
|
2023-08-15 20:19:13 +02:00
|
|
|
int firstMapIndex = boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return !e->isFolder; }) - curItems.begin();
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!sortModeAscending)
|
2023-08-15 20:19:13 +02:00
|
|
|
std::reverse(std::next(curItems.begin(), firstMapIndex), curItems.end());
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
updateListItems();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::select(int position)
|
|
|
|
{
|
|
|
|
if(!curItems.size())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// New selection. py is the index in curItems.
|
|
|
|
int py = position + slider->getValue();
|
|
|
|
vstd::amax(py, 0);
|
|
|
|
vstd::amin(py, curItems.size() - 1);
|
|
|
|
|
|
|
|
selectionPos = py;
|
|
|
|
|
|
|
|
if(position < 0)
|
2023-05-30 17:10:22 +02:00
|
|
|
slider->scrollBy(position);
|
2018-01-05 19:21:07 +02:00
|
|
|
else if(position >= listItems.size())
|
2023-05-30 17:10:22 +02:00
|
|
|
slider->scrollBy(position - (int)listItems.size() + 1);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-08-08 00:38:13 +02:00
|
|
|
if(curItems[py]->isFolder) {
|
2023-08-10 23:52:16 +02:00
|
|
|
if(boost::starts_with(curItems[py]->folderName, ".."))
|
2023-08-08 02:04:06 +02:00
|
|
|
{
|
|
|
|
std::vector<std::string> filetree;
|
|
|
|
boost::split(filetree, curFolder, boost::is_any_of("/"));
|
2023-08-09 20:27:24 +02:00
|
|
|
filetree.pop_back();
|
|
|
|
filetree.pop_back();
|
2023-08-08 02:04:06 +02:00
|
|
|
curFolder = filetree.size() > 0 ? boost::algorithm::join(filetree, "/") + "/" : "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
curFolder += curItems[py]->folderName + "/";
|
2023-08-09 00:13:02 +02:00
|
|
|
filter(-1);
|
2023-08-08 23:46:30 +02:00
|
|
|
slider->scrollTo(0);
|
2023-08-09 00:13:02 +02:00
|
|
|
|
2023-08-09 00:41:13 +02:00
|
|
|
int firstPos = boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return !e->isFolder; }) - curItems.begin();
|
|
|
|
if(firstPos < curItems.size())
|
|
|
|
{
|
|
|
|
selectAbs(firstPos);
|
|
|
|
}
|
|
|
|
|
2023-08-08 00:38:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
rememberCurrentSelection();
|
|
|
|
|
2023-05-17 22:22:45 +02:00
|
|
|
if(inputName && inputName->isActive())
|
2023-07-12 08:12:59 +02:00
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
auto filename = *CResourceHandler::get()->getResourceName(ResourcePath(curItems[py]->fileURI, EResType::SAVEGAME));
|
2018-01-05 19:21:07 +02:00
|
|
|
inputName->setText(filename.stem().string());
|
|
|
|
}
|
2023-07-12 08:10:02 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
updateListItems();
|
2023-07-12 08:10:02 +02:00
|
|
|
redraw();
|
2018-01-05 19:21:07 +02:00
|
|
|
if(callOnSelect)
|
|
|
|
callOnSelect(curItems[py]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::selectAbs(int position)
|
|
|
|
{
|
2023-08-08 02:04:06 +02:00
|
|
|
if(position == -1)
|
|
|
|
position = boost::range::find_if(curItems, [](std::shared_ptr<ElementInfo> e) { return !e->isFolder; }) - curItems.begin();
|
2018-01-05 19:21:07 +02:00
|
|
|
select(position - slider->getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::sliderMove(int slidPos)
|
|
|
|
{
|
|
|
|
if(!slider)
|
|
|
|
return; // ignore spurious call when slider is being created
|
|
|
|
updateListItems();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::updateListItems()
|
|
|
|
{
|
|
|
|
// elemIdx is the index of the maps or saved game to display on line 0
|
|
|
|
// slider->capacity contains the number of available screen lines
|
|
|
|
// slider->positionsAmnt is the number of elements after filtering
|
|
|
|
int elemIdx = slider->getValue();
|
|
|
|
for(auto item : listItems)
|
|
|
|
{
|
|
|
|
if(elemIdx < curItems.size())
|
|
|
|
{
|
|
|
|
item->updateItem(curItems[elemIdx], elemIdx == selectionPos);
|
|
|
|
elemIdx++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->updateItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-04 18:29:01 +02:00
|
|
|
bool SelectionTab::receiveEvent(const Point & position, int eventType) const
|
|
|
|
{
|
|
|
|
// FIXME: widget should instead have well-defined pos so events will be filtered using standard routine
|
2023-07-04 20:35:26 +02:00
|
|
|
return getLine(position - pos.topLeft()) != -1;
|
2023-07-04 18:29:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int SelectionTab::getLine() const
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-01-27 00:27:06 +02:00
|
|
|
Point clickPos = GH.getCursorPosition() - pos.topLeft();
|
2023-07-04 18:29:01 +02:00
|
|
|
return getLine(clickPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SelectionTab::getLine(const Point & clickPos) const
|
|
|
|
{
|
|
|
|
int line = -1;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
// Ignore clicks on save name area
|
|
|
|
int maxPosY;
|
|
|
|
if(tabType == ESelectionScreen::saveGame)
|
|
|
|
maxPosY = 516;
|
|
|
|
else
|
|
|
|
maxPosY = 564;
|
|
|
|
|
|
|
|
if(clickPos.y > 115 && clickPos.y < maxPosY && clickPos.x > 22 && clickPos.x < 371)
|
|
|
|
{
|
|
|
|
line = (clickPos.y - 115) / 25; //which line
|
|
|
|
}
|
|
|
|
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::selectFileName(std::string fname)
|
|
|
|
{
|
|
|
|
boost::to_upper(fname);
|
2023-08-11 23:56:20 +02:00
|
|
|
|
|
|
|
for(int i = (int)allItems.size() - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if(allItems[i]->fileURI == fname)
|
|
|
|
{
|
|
|
|
auto [folderName, baseFolder, parentExists, fileInFolder] = checkSubfolder(allItems[i]->originalFileURI);
|
|
|
|
curFolder = baseFolder != "" ? baseFolder + "/" : "";
|
|
|
|
}
|
|
|
|
}
|
2023-08-08 23:46:30 +02:00
|
|
|
|
2024-05-16 13:16:14 +02:00
|
|
|
filter(-1);
|
|
|
|
|
2020-10-01 10:38:06 +02:00
|
|
|
for(int i = (int)curItems.size() - 1; i >= 0; i--)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
if(curItems[i]->fileURI == fname)
|
|
|
|
{
|
2023-05-30 17:10:22 +02:00
|
|
|
slider->scrollTo(i);
|
2018-01-05 19:21:07 +02:00
|
|
|
selectAbs(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-28 18:00:52 +02:00
|
|
|
selectAbs(-1);
|
|
|
|
|
2024-04-20 18:57:53 +02:00
|
|
|
if(tabType == ESelectionScreen::saveGame && inputName->getText().empty())
|
2024-04-16 21:21:20 +02:00
|
|
|
inputName->setText("NEWGAME");
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2024-05-16 13:16:14 +02:00
|
|
|
void SelectionTab::selectNewestFile()
|
|
|
|
{
|
|
|
|
time_t newestTime = 0;
|
|
|
|
std::string newestFile = "";
|
2024-06-01 13:48:30 +02:00
|
|
|
for(int i = static_cast<int>(allItems.size()) - 1; i >= 0; i--)
|
2024-05-16 13:16:14 +02:00
|
|
|
if(allItems[i]->lastWrite > newestTime)
|
|
|
|
{
|
|
|
|
newestTime = allItems[i]->lastWrite;
|
|
|
|
newestFile = allItems[i]->fileURI;
|
|
|
|
}
|
|
|
|
selectFileName(newestFile);
|
|
|
|
}
|
|
|
|
|
2023-08-08 00:38:13 +02:00
|
|
|
std::shared_ptr<ElementInfo> SelectionTab::getSelectedMapInfo() const
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-08 23:46:30 +02:00
|
|
|
return curItems.empty() || curItems[selectionPos]->isFolder ? nullptr : curItems[selectionPos];
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::rememberCurrentSelection()
|
|
|
|
{
|
2023-08-08 00:38:13 +02:00
|
|
|
if(getSelectedMapInfo()->isFolder)
|
|
|
|
return;
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
// TODO: this can be more elegant
|
|
|
|
if(tabType == ESelectionScreen::newGame)
|
|
|
|
{
|
|
|
|
Settings lastMap = settings.write["general"]["lastMap"];
|
|
|
|
lastMap->String() = getSelectedMapInfo()->fileURI;
|
|
|
|
}
|
|
|
|
else if(tabType == ESelectionScreen::loadGame)
|
|
|
|
{
|
|
|
|
Settings lastSave = settings.write["general"]["lastSave"];
|
|
|
|
lastSave->String() = getSelectedMapInfo()->fileURI;
|
|
|
|
}
|
|
|
|
else if(tabType == ESelectionScreen::campaignList)
|
|
|
|
{
|
|
|
|
Settings lastCampaign = settings.write["general"]["lastCampaign"];
|
|
|
|
lastCampaign->String() = getSelectedMapInfo()->fileURI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SelectionTab::restoreLastSelection()
|
|
|
|
{
|
|
|
|
switch(tabType)
|
|
|
|
{
|
|
|
|
case ESelectionScreen::newGame:
|
|
|
|
selectFileName(settings["general"]["lastMap"].String());
|
|
|
|
break;
|
|
|
|
case ESelectionScreen::campaignList:
|
|
|
|
selectFileName(settings["general"]["lastCampaign"].String());
|
|
|
|
break;
|
|
|
|
case ESelectionScreen::loadGame:
|
2024-05-16 13:16:14 +02:00
|
|
|
selectNewestFile();
|
|
|
|
break;
|
2018-01-05 19:21:07 +02:00
|
|
|
case ESelectionScreen::saveGame:
|
|
|
|
selectFileName(settings["general"]["lastSave"].String());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-20 14:46:40 +02:00
|
|
|
bool SelectionTab::isMapSupported(const CMapInfo & info)
|
|
|
|
{
|
|
|
|
switch (info.mapHeader->version)
|
|
|
|
{
|
|
|
|
case EMapFormat::ROE:
|
2024-08-31 13:00:36 +02:00
|
|
|
return CGI->engineSettings()->getValue(EGameSettings::MAP_FORMAT_RESTORATION_OF_ERATHIA)["supported"].Bool();
|
2023-05-20 14:46:40 +02:00
|
|
|
case EMapFormat::AB:
|
2024-08-31 13:00:36 +02:00
|
|
|
return CGI->engineSettings()->getValue(EGameSettings::MAP_FORMAT_ARMAGEDDONS_BLADE)["supported"].Bool();
|
2023-05-20 14:46:40 +02:00
|
|
|
case EMapFormat::SOD:
|
2024-08-31 13:00:36 +02:00
|
|
|
return CGI->engineSettings()->getValue(EGameSettings::MAP_FORMAT_SHADOW_OF_DEATH)["supported"].Bool();
|
2024-08-31 22:05:36 +02:00
|
|
|
case EMapFormat::CHR:
|
2024-08-31 13:00:36 +02:00
|
|
|
return CGI->engineSettings()->getValue(EGameSettings::MAP_FORMAT_CHRONICLES)["supported"].Bool();
|
2023-05-20 14:46:40 +02:00
|
|
|
case EMapFormat::WOG:
|
2024-08-31 13:00:36 +02:00
|
|
|
return CGI->engineSettings()->getValue(EGameSettings::MAP_FORMAT_IN_THE_WAKE_OF_GODS)["supported"].Bool();
|
2023-05-20 14:46:40 +02:00
|
|
|
case EMapFormat::HOTA:
|
2024-08-31 13:00:36 +02:00
|
|
|
return CGI->engineSettings()->getValue(EGameSettings::MAP_FORMAT_HORN_OF_THE_ABYSS)["supported"].Bool();
|
2023-05-20 14:46:40 +02:00
|
|
|
case EMapFormat::VCMI:
|
2024-08-31 13:00:36 +02:00
|
|
|
return CGI->engineSettings()->getValue(EGameSettings::MAP_FORMAT_JSON_VCMI)["supported"].Bool();
|
2023-05-20 14:46:40 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
void SelectionTab::parseMaps(const std::unordered_set<ResourcePath> & files)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
logGlobal->debug("Parsing %d maps", files.size());
|
|
|
|
allItems.clear();
|
|
|
|
for(auto & file : files)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-08-08 00:38:13 +02:00
|
|
|
auto mapInfo = std::make_shared<ElementInfo>();
|
2018-01-05 19:21:07 +02:00
|
|
|
mapInfo->mapInit(file.getName());
|
|
|
|
|
2023-05-20 14:46:40 +02:00
|
|
|
if (isMapSupported(*mapInfo))
|
2018-01-05 19:21:07 +02:00
|
|
|
allItems.push_back(mapInfo);
|
|
|
|
}
|
|
|
|
catch(std::exception & e)
|
|
|
|
{
|
|
|
|
logGlobal->error("Map %s is invalid. Message: %s", file.getName(), e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
void SelectionTab::parseSaves(const std::unordered_set<ResourcePath> & files)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
for(auto & file : files)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2023-08-08 00:38:13 +02:00
|
|
|
auto mapInfo = std::make_shared<ElementInfo>();
|
2018-01-05 19:21:07 +02:00
|
|
|
mapInfo->saveInit(file);
|
|
|
|
|
|
|
|
// Filter out other game modes
|
2024-01-21 16:48:36 +02:00
|
|
|
bool isCampaign = mapInfo->scenarioOptionsOfSave->mode == EStartMode::CAMPAIGN;
|
2018-01-05 19:21:07 +02:00
|
|
|
bool isMultiplayer = mapInfo->amountOfHumanPlayersInSave > 1;
|
2023-08-09 13:29:48 +02:00
|
|
|
bool isTutorial = boost::to_upper_copy(mapInfo->scenarioOptionsOfSave->mapname) == "MAPS/TUTORIAL";
|
2018-01-05 19:21:07 +02:00
|
|
|
switch(CSH->getLoadMode())
|
|
|
|
{
|
|
|
|
case ELoadMode::SINGLE:
|
2024-05-21 17:15:18 +02:00
|
|
|
if(isCampaign || isTutorial)
|
2018-01-05 19:21:07 +02:00
|
|
|
mapInfo->mapHeader.reset();
|
|
|
|
break;
|
|
|
|
case ELoadMode::CAMPAIGN:
|
|
|
|
if(!isCampaign)
|
|
|
|
mapInfo->mapHeader.reset();
|
|
|
|
break;
|
2023-08-09 13:29:48 +02:00
|
|
|
case ELoadMode::TUTORIAL:
|
|
|
|
if(!isTutorial)
|
|
|
|
mapInfo->mapHeader.reset();
|
|
|
|
break;
|
2024-05-21 17:15:18 +02:00
|
|
|
case ELoadMode::MULTI:
|
2018-01-05 19:21:07 +02:00
|
|
|
if(!isMultiplayer)
|
|
|
|
mapInfo->mapHeader.reset();
|
|
|
|
break;
|
2024-05-21 17:15:18 +02:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
mapInfo->mapHeader.reset();
|
|
|
|
break;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
allItems.push_back(mapInfo);
|
|
|
|
}
|
|
|
|
catch(const std::exception & e)
|
|
|
|
{
|
|
|
|
logGlobal->error("Error: Failed to process %s: %s", file.getName(), e.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
void SelectionTab::parseCampaigns(const std::unordered_set<ResourcePath> & files)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
allItems.reserve(files.size());
|
|
|
|
for(auto & file : files)
|
|
|
|
{
|
2023-08-08 00:38:13 +02:00
|
|
|
auto info = std::make_shared<ElementInfo>();
|
2018-01-05 19:21:07 +02:00
|
|
|
//allItems[i].date = std::asctime(std::localtime(&files[i].date));
|
|
|
|
info->fileURI = file.getName();
|
|
|
|
info->campaignInit();
|
2023-06-26 00:07:55 +02:00
|
|
|
if(info->campaign)
|
2023-04-09 01:24:40 +02:00
|
|
|
allItems.push_back(info);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unordered_set<ResourcePath> SelectionTab::getFiles(std::string dirURI, EResType resType)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
boost::to_upper(dirURI);
|
|
|
|
CResourceHandler::get()->updateFilteredFiles([&](const std::string & mount)
|
|
|
|
{
|
|
|
|
return boost::algorithm::starts_with(mount, dirURI);
|
|
|
|
});
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
std::unordered_set<ResourcePath> ret = CResourceHandler::get()->getFilteredFiles([&](const ResourcePath & ident)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
return ident.getType() == resType && boost::algorithm::starts_with(ident.getName(), dirURI);
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-06-04 18:09:25 +02:00
|
|
|
SelectionTab::ListItem::ListItem(Point position)
|
2018-01-05 19:21:07 +02:00
|
|
|
: CIntObject(LCLICK, position)
|
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2024-06-08 09:35:13 +02:00
|
|
|
pictureEmptyLine = std::make_shared<CPicture>(ImagePath::builtin("camcust"), Rect(25, 121, 349, 26), -8, -14);
|
2024-01-08 00:42:48 +02:00
|
|
|
labelName = std::make_shared<CLabel>(184, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, "", 185);
|
2018-01-05 19:21:07 +02:00
|
|
|
labelName->setAutoRedraw(false);
|
2022-11-26 23:12:20 +02:00
|
|
|
labelAmountOfPlayers = std::make_shared<CLabel>(8, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
2018-01-05 19:21:07 +02:00
|
|
|
labelAmountOfPlayers->setAutoRedraw(false);
|
2022-11-26 23:12:20 +02:00
|
|
|
labelNumberOfCampaignMaps = std::make_shared<CLabel>(8, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
2018-01-05 19:21:07 +02:00
|
|
|
labelNumberOfCampaignMaps->setAutoRedraw(false);
|
2022-11-26 23:12:20 +02:00
|
|
|
labelMapSizeLetter = std::make_shared<CLabel>(41, 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
2018-01-05 19:21:07 +02:00
|
|
|
labelMapSizeLetter->setAutoRedraw(false);
|
|
|
|
// FIXME: This -12 should not be needed, but for some reason CAnimImage displaced otherwise
|
2023-08-23 14:07:50 +02:00
|
|
|
iconFolder = std::make_shared<CPicture>(ImagePath::builtin("lobby/iconFolder.png"), -8, -12);
|
2024-06-04 18:09:25 +02:00
|
|
|
iconFormat = std::make_shared<CAnimImage>(AnimationPath::builtin("SCSELC.DEF"), 0, 0, 59, -12);
|
|
|
|
iconVictoryCondition = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRVICT.DEF"), 0, 0, 277, -12);
|
|
|
|
iconLossCondition = std::make_shared<CAnimImage>(AnimationPath::builtin("SCNRLOSS.DEF"), 0, 0, 310, -12);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-08-08 00:38:13 +02:00
|
|
|
void SelectionTab::ListItem::updateItem(std::shared_ptr<ElementInfo> info, bool selected)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
if(!info)
|
|
|
|
{
|
|
|
|
labelAmountOfPlayers->disable();
|
|
|
|
labelMapSizeLetter->disable();
|
2023-08-10 23:37:19 +02:00
|
|
|
iconFolder->disable();
|
|
|
|
pictureEmptyLine->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
iconFormat->disable();
|
|
|
|
iconVictoryCondition->disable();
|
|
|
|
iconLossCondition->disable();
|
|
|
|
labelNumberOfCampaignMaps->disable();
|
|
|
|
labelName->disable();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto color = selected ? Colors::YELLOW : Colors::WHITE;
|
2023-08-08 00:38:13 +02:00
|
|
|
if(info->isFolder)
|
|
|
|
{
|
|
|
|
labelAmountOfPlayers->disable();
|
|
|
|
labelMapSizeLetter->disable();
|
2023-08-10 23:37:19 +02:00
|
|
|
iconFolder->enable();
|
|
|
|
pictureEmptyLine->enable();
|
|
|
|
iconFormat->disable();
|
2023-08-08 00:38:13 +02:00
|
|
|
iconVictoryCondition->disable();
|
|
|
|
iconLossCondition->disable();
|
|
|
|
labelNumberOfCampaignMaps->disable();
|
|
|
|
labelName->enable();
|
2024-01-08 01:08:05 +02:00
|
|
|
labelName->setMaxWidth(316);
|
2023-08-08 00:38:13 +02:00
|
|
|
labelName->setText(info->folderName);
|
|
|
|
labelName->setColor(color);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-08 01:08:05 +02:00
|
|
|
labelName->enable();
|
2023-06-26 00:07:55 +02:00
|
|
|
if(info->campaign)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
labelAmountOfPlayers->disable();
|
|
|
|
labelMapSizeLetter->disable();
|
2023-08-10 23:37:19 +02:00
|
|
|
iconFolder->disable();
|
|
|
|
pictureEmptyLine->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
iconFormat->disable();
|
|
|
|
iconVictoryCondition->disable();
|
|
|
|
iconLossCondition->disable();
|
|
|
|
labelNumberOfCampaignMaps->enable();
|
|
|
|
std::ostringstream ostr(std::ostringstream::out);
|
2023-06-26 00:07:55 +02:00
|
|
|
ostr << info->campaign->scenariosCount();
|
2018-01-05 19:21:07 +02:00
|
|
|
labelNumberOfCampaignMaps->setText(ostr.str());
|
|
|
|
labelNumberOfCampaignMaps->setColor(color);
|
2024-01-08 01:08:05 +02:00
|
|
|
labelName->setMaxWidth(316);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
labelNumberOfCampaignMaps->disable();
|
|
|
|
std::ostringstream ostr(std::ostringstream::out);
|
|
|
|
ostr << info->amountOfPlayersOnMap << "/" << info->amountOfHumanControllablePlayers;
|
|
|
|
labelAmountOfPlayers->enable();
|
|
|
|
labelAmountOfPlayers->setText(ostr.str());
|
|
|
|
labelAmountOfPlayers->setColor(color);
|
|
|
|
labelMapSizeLetter->enable();
|
|
|
|
labelMapSizeLetter->setText(info->getMapSizeName());
|
|
|
|
labelMapSizeLetter->setColor(color);
|
2023-08-10 23:37:19 +02:00
|
|
|
iconFolder->disable();
|
|
|
|
pictureEmptyLine->disable();
|
2018-01-05 19:21:07 +02:00
|
|
|
iconFormat->enable();
|
2023-05-20 16:34:39 +02:00
|
|
|
iconFormat->setFrame(info->getMapSizeFormatIconId());
|
2018-01-05 19:21:07 +02:00
|
|
|
iconVictoryCondition->enable();
|
|
|
|
iconVictoryCondition->setFrame(info->mapHeader->victoryIconIndex, 0);
|
|
|
|
iconLossCondition->enable();
|
|
|
|
iconLossCondition->setFrame(info->mapHeader->defeatIconIndex, 0);
|
2024-01-08 01:08:05 +02:00
|
|
|
labelName->setMaxWidth(185);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
labelName->setText(info->getNameForList());
|
|
|
|
labelName->setColor(color);
|
|
|
|
}
|