mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
rework
This commit is contained in:
parent
e5627b4bb7
commit
5e1f1294e5
@ -41,8 +41,11 @@
|
|||||||
#include "../../lib/mapping/MapFormat.h"
|
#include "../../lib/mapping/MapFormat.h"
|
||||||
#include "../../lib/serializer/Connection.h"
|
#include "../../lib/serializer/Connection.h"
|
||||||
|
|
||||||
bool mapSorter::operator()(const std::shared_ptr<CMapInfo> aaa, const std::shared_ptr<CMapInfo> bbb)
|
bool mapSorter::operator()(const std::shared_ptr<ElementInfo> aaa, const std::shared_ptr<ElementInfo> bbb)
|
||||||
{
|
{
|
||||||
|
if(aaa->isFolder || bbb->isFolder)
|
||||||
|
return (aaa->isFolder > bbb->isFolder);
|
||||||
|
|
||||||
auto a = aaa->mapHeader.get();
|
auto a = aaa->mapHeader.get();
|
||||||
auto b = bbb->mapHeader.get();
|
auto b = bbb->mapHeader.get();
|
||||||
if(a && b) //if we are sorting scenarios
|
if(a && b) //if we are sorting scenarios
|
||||||
@ -130,7 +133,7 @@ static ESortBy getSortBySelectionScreen(ESelectionScreen Type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SelectionTab::SelectionTab(ESelectionScreen Type)
|
SelectionTab::SelectionTab(ESelectionScreen Type)
|
||||||
: CIntObject(LCLICK | SHOW_POPUP | KEYBOARD | DOUBLECLICK), callOnSelect(nullptr), tabType(Type), selectionPos(0), sortModeAscending(true), inputNameRect{32, 539, 350, 20}
|
: CIntObject(LCLICK | SHOW_POPUP | KEYBOARD | DOUBLECLICK), callOnSelect(nullptr), tabType(Type), selectionPos(0), sortModeAscending(true), inputNameRect{32, 539, 350, 20}, curFolder("")
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION;
|
OBJ_CONSTRUCTION;
|
||||||
|
|
||||||
@ -148,7 +151,7 @@ SelectionTab::SelectionTab(ESelectionScreen Type)
|
|||||||
int sizes[] = {36, 72, 108, 144, 0};
|
int sizes[] = {36, 72, 108, 144, 0};
|
||||||
const char * filterIconNmes[] = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"};
|
const char * filterIconNmes[] = {"SCSMBUT.DEF", "SCMDBUT.DEF", "SCLGBUT.DEF", "SCXLBUT.DEF", "SCALBUT.DEF"};
|
||||||
for(int i = 0; i < 5; i++)
|
for(int i = 0; i < 5; i++)
|
||||||
buttonsSortBy.push_back(std::make_shared<CButton>(Point(158 + 47 * i, 46), filterIconNmes[i], CGI->generaltexth->zelp[54 + i], std::bind(&SelectionTab::filter, this, sizes[i], true, "")));
|
buttonsSortBy.push_back(std::make_shared<CButton>(Point(158 + 47 * i, 46), filterIconNmes[i], CGI->generaltexth->zelp[54 + i], std::bind(&SelectionTab::filter, this, sizes[i], true)));
|
||||||
|
|
||||||
int xpos[] = {23, 55, 88, 121, 306, 339};
|
int xpos[] = {23, 55, 88, 121, 306, 339};
|
||||||
const char * sortIconNames[] = {"SCBUTT1.DEF", "SCBUTT2.DEF", "SCBUTCP.DEF", "SCBUTT3.DEF", "SCBUTT4.DEF", "SCBUTT5.DEF"};
|
const char * sortIconNames[] = {"SCBUTT1.DEF", "SCBUTT2.DEF", "SCBUTCP.DEF", "SCBUTT3.DEF", "SCBUTT4.DEF", "SCBUTT5.DEF"};
|
||||||
@ -214,7 +217,6 @@ void SelectionTab::toggleMode()
|
|||||||
{
|
{
|
||||||
allItems.clear();
|
allItems.clear();
|
||||||
curItems.clear();
|
curItems.clear();
|
||||||
curFolders.clear();
|
|
||||||
if(slider)
|
if(slider)
|
||||||
slider->block(true);
|
slider->block(true);
|
||||||
}
|
}
|
||||||
@ -336,15 +338,44 @@ void SelectionTab::showPopupWindow(const Point & cursorPosition)
|
|||||||
CRClickPopup::createAndPush(text);
|
CRClickPopup::createAndPush(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::tuple<std::string, bool> SelectionTab::checkSubfolder(std::string path)
|
||||||
|
{
|
||||||
|
std::string folderName = "";
|
||||||
|
bool parentExists = false;
|
||||||
|
|
||||||
|
std::string folder = boost::filesystem::path(path).parent_path().string();
|
||||||
|
std::vector<std::string> filetree;
|
||||||
|
|
||||||
|
// delete first element (e.g. 'MAPS')
|
||||||
|
boost::split(filetree, folder, boost::is_any_of("/"));
|
||||||
|
filetree.erase(filetree.begin());
|
||||||
|
folder = boost::algorithm::join(filetree, "/");
|
||||||
|
|
||||||
|
if(boost::algorithm::starts_with(folder, curFolder) && curFolder != "")
|
||||||
|
{
|
||||||
|
folder = folder.substr(curFolder.size());
|
||||||
|
if(boost::algorithm::starts_with(folder, "/"))
|
||||||
|
folder = folder.substr(1);
|
||||||
|
|
||||||
|
parentExists = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(folder != "")
|
||||||
|
{
|
||||||
|
boost::split(filetree, folder, boost::is_any_of("/"));
|
||||||
|
folderName = filetree[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return {folderName, parentExists};
|
||||||
|
}
|
||||||
|
|
||||||
// A new size filter (Small, Medium, ...) has been selected. Populate
|
// A new size filter (Small, Medium, ...) has been selected. Populate
|
||||||
// selMaps with the relevant data.
|
// selMaps with the relevant data.
|
||||||
void SelectionTab::filter(int size, bool selectFirst, std::string path)
|
void SelectionTab::filter(int size, bool selectFirst)
|
||||||
{
|
{
|
||||||
path = "AA";
|
std::string path = "";
|
||||||
|
|
||||||
|
|
||||||
curItems.clear();
|
curItems.clear();
|
||||||
curFolders.clear();
|
|
||||||
|
|
||||||
if(tabType == ESelectionScreen::campaignList)
|
if(tabType == ESelectionScreen::campaignList)
|
||||||
{
|
{
|
||||||
@ -357,32 +388,23 @@ void SelectionTab::filter(int size, bool selectFirst, std::string path)
|
|||||||
{
|
{
|
||||||
if(elem->mapHeader && (!size || elem->mapHeader->width == size))
|
if(elem->mapHeader && (!size || elem->mapHeader->width == size))
|
||||||
{
|
{
|
||||||
std::string folder = boost::filesystem::path(elem->fileURI).parent_path().string();
|
auto [folderName, parentExists] = checkSubfolder(elem->fileURI);
|
||||||
std::vector<std::string> filetree;
|
|
||||||
|
|
||||||
// delete first element (e.g. 'MAPS')
|
if(parentExists)
|
||||||
boost::split(filetree, folder, boost::is_any_of("/"));
|
|
||||||
filetree.erase(filetree.begin());
|
|
||||||
folder = boost::algorithm::join(filetree, "/");
|
|
||||||
|
|
||||||
// remove current dir
|
|
||||||
if(boost::algorithm::starts_with(folder, path))
|
|
||||||
{
|
{
|
||||||
folder = folder.substr(path.size());
|
auto folder = std::make_shared<ElementInfo>();
|
||||||
if(boost::algorithm::starts_with(folder, "/"))
|
folder->isFolder = true;
|
||||||
folder = folder.substr(1);
|
folder->folderName = "..";
|
||||||
|
if (std::find(curItems.begin(), curItems.end(), folder) == curItems.end()) {
|
||||||
if (std::find(curFolders.begin(), curFolders.end(), "..") == curFolders.end()) {
|
curItems.push_back(folder);
|
||||||
curFolders.push_back("..");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(folder != "")
|
auto folder = std::make_shared<ElementInfo>();
|
||||||
{
|
folder->isFolder = true;
|
||||||
boost::split(filetree, folder, boost::is_any_of("/"));
|
folder->folderName = folderName;
|
||||||
if (std::find(curFolders.begin(), curFolders.end(), filetree[0]) == curFolders.end()) {
|
if (std::find(curItems.begin(), curItems.end(), folder) == curItems.end() && folderName != "") {
|
||||||
curFolders.push_back(filetree[0]);
|
curItems.push_back(folder);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curItems.push_back(elem);
|
curItems.push_back(elem);
|
||||||
@ -441,7 +463,7 @@ void SelectionTab::sort()
|
|||||||
|
|
||||||
void SelectionTab::select(int position)
|
void SelectionTab::select(int position)
|
||||||
{
|
{
|
||||||
if(!(curFolders.size() + curItems.size()))
|
if(!curItems.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// New selection. py is the index in curItems.
|
// New selection. py is the index in curItems.
|
||||||
@ -458,6 +480,11 @@ void SelectionTab::select(int position)
|
|||||||
|
|
||||||
rememberCurrentSelection();
|
rememberCurrentSelection();
|
||||||
|
|
||||||
|
if(curItems[py]->isFolder) {
|
||||||
|
return;
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
if(inputName && inputName->isActive())
|
if(inputName && inputName->isActive())
|
||||||
{
|
{
|
||||||
auto filename = *CResourceHandler::get("local")->getResourceName(ResourceID(curItems[py]->fileURI, EResType::SAVEGAME));
|
auto filename = *CResourceHandler::get("local")->getResourceName(ResourceID(curItems[py]->fileURI, EResType::SAVEGAME));
|
||||||
@ -491,14 +518,9 @@ void SelectionTab::updateListItems()
|
|||||||
int elemIdx = slider->getValue();
|
int elemIdx = slider->getValue();
|
||||||
for(auto item : listItems)
|
for(auto item : listItems)
|
||||||
{
|
{
|
||||||
if(elemIdx < curFolders.size())
|
if(elemIdx < curItems.size())
|
||||||
{
|
{
|
||||||
item->updateItem(curFolders[elemIdx], elemIdx == selectionPos);
|
item->updateItem(curItems[elemIdx], elemIdx == selectionPos);
|
||||||
elemIdx++;
|
|
||||||
}
|
|
||||||
else if(elemIdx - curFolders.size() < curItems.size())
|
|
||||||
{
|
|
||||||
item->updateItem(curItems[elemIdx - curFolders.size()], elemIdx - curFolders.size() == selectionPos);
|
|
||||||
elemIdx++;
|
elemIdx++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -555,13 +577,16 @@ void SelectionTab::selectFileName(std::string fname)
|
|||||||
selectAbs(0);
|
selectAbs(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<CMapInfo> SelectionTab::getSelectedMapInfo() const
|
std::shared_ptr<ElementInfo> SelectionTab::getSelectedMapInfo() const
|
||||||
{
|
{
|
||||||
return curItems.empty() && selectionPos <= curFolders.size() ? nullptr : curItems[selectionPos - curFolders.size()];
|
return curItems.empty() ? nullptr : curItems[selectionPos];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionTab::rememberCurrentSelection()
|
void SelectionTab::rememberCurrentSelection()
|
||||||
{
|
{
|
||||||
|
if(getSelectedMapInfo()->isFolder)
|
||||||
|
return;
|
||||||
|
|
||||||
// TODO: this can be more elegant
|
// TODO: this can be more elegant
|
||||||
if(tabType == ESelectionScreen::newGame)
|
if(tabType == ESelectionScreen::newGame)
|
||||||
{
|
{
|
||||||
@ -624,12 +649,14 @@ void SelectionTab::parseMaps(const std::unordered_set<ResourceID> & files)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto mapInfo = std::make_shared<CMapInfo>();
|
auto mapInfo = std::make_shared<ElementInfo>();
|
||||||
mapInfo->mapInit(file.getName());
|
mapInfo->mapInit(file.getName());
|
||||||
|
|
||||||
if (isMapSupported(*mapInfo))
|
if (isMapSupported(*mapInfo))
|
||||||
|
{
|
||||||
allItems.push_back(mapInfo);
|
allItems.push_back(mapInfo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch(std::exception & e)
|
catch(std::exception & e)
|
||||||
{
|
{
|
||||||
logGlobal->error("Map %s is invalid. Message: %s", file.getName(), e.what());
|
logGlobal->error("Map %s is invalid. Message: %s", file.getName(), e.what());
|
||||||
@ -643,7 +670,7 @@ void SelectionTab::parseSaves(const std::unordered_set<ResourceID> & files)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto mapInfo = std::make_shared<CMapInfo>();
|
auto mapInfo = std::make_shared<ElementInfo>();
|
||||||
mapInfo->saveInit(file);
|
mapInfo->saveInit(file);
|
||||||
|
|
||||||
// Filter out other game modes
|
// Filter out other game modes
|
||||||
@ -679,14 +706,15 @@ void SelectionTab::parseCampaigns(const std::unordered_set<ResourceID> & files)
|
|||||||
allItems.reserve(files.size());
|
allItems.reserve(files.size());
|
||||||
for(auto & file : files)
|
for(auto & file : files)
|
||||||
{
|
{
|
||||||
auto info = std::make_shared<CMapInfo>();
|
auto info = std::make_shared<ElementInfo>();
|
||||||
//allItems[i].date = std::asctime(std::localtime(&files[i].date));
|
//allItems[i].date = std::asctime(std::localtime(&files[i].date));
|
||||||
info->fileURI = file.getName();
|
info->fileURI = file.getName();
|
||||||
info->campaignInit();
|
info->campaignInit();
|
||||||
if(info->campaign)
|
if(info->campaign) {
|
||||||
allItems.push_back(info);
|
allItems.push_back(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::unordered_set<ResourceID> SelectionTab::getFiles(std::string dirURI, int resType)
|
std::unordered_set<ResourceID> SelectionTab::getFiles(std::string dirURI, int resType)
|
||||||
{
|
{
|
||||||
@ -722,22 +750,7 @@ SelectionTab::ListItem::ListItem(Point position, std::shared_ptr<CAnimation> ico
|
|||||||
iconLossCondition = std::make_shared<CAnimImage>(iconsLoss, 0, 0, 310, -12);
|
iconLossCondition = std::make_shared<CAnimImage>(iconsLoss, 0, 0, 310, -12);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionTab::ListItem::updateItem(std::string folderName, bool selected)
|
void SelectionTab::ListItem::updateItem(std::shared_ptr<ElementInfo> info, bool selected)
|
||||||
{
|
|
||||||
labelAmountOfPlayers->disable();
|
|
||||||
labelMapSizeLetter->disable();
|
|
||||||
iconFormat->disable();
|
|
||||||
iconVictoryCondition->disable();
|
|
||||||
iconLossCondition->disable();
|
|
||||||
labelNumberOfCampaignMaps->disable();
|
|
||||||
labelName->enable();
|
|
||||||
labelName->setText(folderName);
|
|
||||||
auto color = selected ? Colors::YELLOW : Colors::WHITE;
|
|
||||||
labelName->setColor(color);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SelectionTab::ListItem::updateItem(std::shared_ptr<CMapInfo> info, bool selected)
|
|
||||||
{
|
{
|
||||||
if(!info)
|
if(!info)
|
||||||
{
|
{
|
||||||
@ -752,6 +765,20 @@ void SelectionTab::ListItem::updateItem(std::shared_ptr<CMapInfo> info, bool sel
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto color = selected ? Colors::YELLOW : Colors::WHITE;
|
auto color = selected ? Colors::YELLOW : Colors::WHITE;
|
||||||
|
if(info->isFolder)
|
||||||
|
{
|
||||||
|
labelAmountOfPlayers->disable();
|
||||||
|
labelMapSizeLetter->disable();
|
||||||
|
iconFormat->disable();
|
||||||
|
iconVictoryCondition->disable();
|
||||||
|
iconLossCondition->disable();
|
||||||
|
labelNumberOfCampaignMaps->disable();
|
||||||
|
labelName->enable();
|
||||||
|
labelName->setText(info->folderName);
|
||||||
|
labelName->setColor(color);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(info->campaign)
|
if(info->campaign)
|
||||||
{
|
{
|
||||||
labelAmountOfPlayers->disable();
|
labelAmountOfPlayers->disable();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CSelectionBase.h"
|
#include "CSelectionBase.h"
|
||||||
|
#include "../../lib/mapping/CMapInfo.h"
|
||||||
|
|
||||||
class CSlider;
|
class CSlider;
|
||||||
class CLabel;
|
class CLabel;
|
||||||
@ -19,12 +20,21 @@ enum ESortBy
|
|||||||
_playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName
|
_playerAm, _size, _format, _name, _viccon, _loscon, _numOfMaps, _fileName
|
||||||
}; //_numOfMaps is for campaigns
|
}; //_numOfMaps is for campaigns
|
||||||
|
|
||||||
|
class ElementInfo : public CMapInfo
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ElementInfo() : CMapInfo() { }
|
||||||
|
~ElementInfo() { }
|
||||||
|
std::string folderName = "";
|
||||||
|
bool isFolder = false;
|
||||||
|
};
|
||||||
|
|
||||||
/// Class which handles map sorting by different criteria
|
/// Class which handles map sorting by different criteria
|
||||||
class mapSorter
|
class mapSorter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ESortBy sortBy;
|
ESortBy sortBy;
|
||||||
bool operator()(const std::shared_ptr<CMapInfo> aaa, const std::shared_ptr<CMapInfo> bbb);
|
bool operator()(const std::shared_ptr<ElementInfo> aaa, const std::shared_ptr<ElementInfo> bbb);
|
||||||
mapSorter(ESortBy es) : sortBy(es){};
|
mapSorter(ESortBy es) : sortBy(es){};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,8 +51,7 @@ class SelectionTab : public CIntObject
|
|||||||
std::shared_ptr<CLabel> labelName;
|
std::shared_ptr<CLabel> labelName;
|
||||||
|
|
||||||
ListItem(Point position, std::shared_ptr<CAnimation> iconsFormats, std::shared_ptr<CAnimation> iconsVictory, std::shared_ptr<CAnimation> iconsLoss);
|
ListItem(Point position, std::shared_ptr<CAnimation> iconsFormats, std::shared_ptr<CAnimation> iconsVictory, std::shared_ptr<CAnimation> iconsLoss);
|
||||||
void updateItem(std::string folderName, bool selected = false);
|
void updateItem(std::shared_ptr<ElementInfo> info = {}, bool selected = false);
|
||||||
void updateItem(std::shared_ptr<CMapInfo> info = {}, bool selected = false);
|
|
||||||
};
|
};
|
||||||
std::vector<std::shared_ptr<ListItem>> listItems;
|
std::vector<std::shared_ptr<ListItem>> listItems;
|
||||||
|
|
||||||
@ -52,12 +61,11 @@ class SelectionTab : public CIntObject
|
|||||||
std::shared_ptr<CAnimation> iconsLossCondition;
|
std::shared_ptr<CAnimation> iconsLossCondition;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<std::shared_ptr<CMapInfo>> allItems;
|
std::vector<std::shared_ptr<ElementInfo>> allItems;
|
||||||
std::vector<std::shared_ptr<CMapInfo>> curItems;
|
std::vector<std::shared_ptr<ElementInfo>> curItems;
|
||||||
std::vector<std::string> curFolders;
|
|
||||||
std::string curFolder;
|
std::string curFolder;
|
||||||
size_t selectionPos;
|
size_t selectionPos;
|
||||||
std::function<void(std::shared_ptr<CMapInfo>)> callOnSelect;
|
std::function<void(std::shared_ptr<ElementInfo>)> callOnSelect;
|
||||||
|
|
||||||
ESortBy sortingBy;
|
ESortBy sortingBy;
|
||||||
ESortBy generalSortingBy;
|
ESortBy generalSortingBy;
|
||||||
@ -74,7 +82,7 @@ public:
|
|||||||
void showPopupWindow(const Point & cursorPosition) override;
|
void showPopupWindow(const Point & cursorPosition) override;
|
||||||
bool receiveEvent(const Point & position, int eventType) const override;
|
bool receiveEvent(const Point & position, int eventType) const override;
|
||||||
|
|
||||||
void filter(int size, bool selectFirst = false, std::string path = "MAPS"); //0 - all
|
void filter(int size, bool selectFirst = false); //0 - all
|
||||||
void sortBy(int criteria);
|
void sortBy(int criteria);
|
||||||
void sort();
|
void sort();
|
||||||
void select(int position); //position: <0 - positions> position on the screen
|
void select(int position); //position: <0 - positions> position on the screen
|
||||||
@ -84,7 +92,7 @@ public:
|
|||||||
int getLine() const;
|
int getLine() const;
|
||||||
int getLine(const Point & position) const;
|
int getLine(const Point & position) const;
|
||||||
void selectFileName(std::string fname);
|
void selectFileName(std::string fname);
|
||||||
std::shared_ptr<CMapInfo> getSelectedMapInfo() const;
|
std::shared_ptr<ElementInfo> getSelectedMapInfo() const;
|
||||||
void rememberCurrentSelection();
|
void rememberCurrentSelection();
|
||||||
void restoreLastSelection();
|
void restoreLastSelection();
|
||||||
|
|
||||||
@ -98,6 +106,8 @@ private:
|
|||||||
ESelectionScreen tabType;
|
ESelectionScreen tabType;
|
||||||
Rect inputNameRect;
|
Rect inputNameRect;
|
||||||
|
|
||||||
|
std::tuple<std::string, bool> checkSubfolder(std::string path);
|
||||||
|
|
||||||
bool isMapSupported(const CMapInfo & info);
|
bool isMapSupported(const CMapInfo & info);
|
||||||
void parseMaps(const std::unordered_set<ResourceID> & files);
|
void parseMaps(const std::unordered_set<ResourceID> & files);
|
||||||
void parseSaves(const std::unordered_set<ResourceID> & files);
|
void parseSaves(const std::unordered_set<ResourceID> & files);
|
||||||
|
Loading…
Reference in New Issue
Block a user