runepage icons fuzzy matching
This commit is contained in:
parent
b919a64ae6
commit
adcf715694
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "clientapi.h"
|
#include "clientapi.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "datadragon.h"
|
||||||
#include "runeaspekt.h"
|
#include "runeaspekt.h"
|
||||||
#include "runestyle.h"
|
#include "runestyle.h"
|
||||||
|
|
||||||
|
@ -13,7 +14,6 @@ namespace Ui {
|
||||||
class RunePageList;
|
class RunePageList;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DataDragon;
|
|
||||||
class DropEvent;
|
class DropEvent;
|
||||||
class ClientAPI;
|
class ClientAPI;
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ private slots:
|
||||||
private:
|
private:
|
||||||
void clearItems();
|
void clearItems();
|
||||||
void addRunepageItem(QString name, int id, const ::RunePage& rp, bool isCurrent = false);
|
void addRunepageItem(QString name, int id, const ::RunePage& rp, bool isCurrent = false);
|
||||||
|
const DataDragon::ChampData& findChamp(const QString& name);
|
||||||
|
|
||||||
QString getRuneDescription(const ::RunePage& runepage);
|
QString getRuneDescription(const ::RunePage& runepage);
|
||||||
QString getRuneText(uint32_t id);
|
QString getRuneText(uint32_t id);
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
#include "clipboardpopup.h"
|
#include "clipboardpopup.h"
|
||||||
#include "datadragon.h"
|
|
||||||
#include "runeeditor.h"
|
#include "runeeditor.h"
|
||||||
|
|
||||||
RunePageList::RunePageList(QWidget* parent) : QListWidget(parent), ui(new Ui::RunePageList) {
|
RunePageList::RunePageList(QWidget* parent) : QListWidget(parent), ui(new Ui::RunePageList) {
|
||||||
|
@ -201,12 +200,10 @@ void RunePageList::addRunepageItem(QString name, int id, const ::RunePage& rp, b
|
||||||
item->setData(RoleId, (uint) id);
|
item->setData(RoleId, (uint) id);
|
||||||
item->setData(RolePointer, (qulonglong) new ::RunePage(rp));
|
item->setData(RolePointer, (qulonglong) new ::RunePage(rp));
|
||||||
|
|
||||||
if(dd) {
|
const DataDragon::ChampData& champData = findChamp(name);
|
||||||
const DataDragon::ChampData& champData = dd->getBestMatchingChamp(name);
|
if(champData.key != -1) {
|
||||||
if(champData.key != -1) {
|
QPixmap iamge = dd->getImage(champData.id);
|
||||||
QPixmap iamge = dd->getImage(champData.id);
|
item->setIcon(iamge);
|
||||||
item->setIcon(iamge);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString tooltipStr;
|
QString tooltipStr;
|
||||||
|
@ -223,6 +220,48 @@ void RunePageList::addRunepageItem(QString name, int id, const ::RunePage& rp, b
|
||||||
addItem(item);
|
addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DataDragon::ChampData& RunePageList::findChamp(const QString& name) {
|
||||||
|
if(!dd) {
|
||||||
|
return DataDragon::EMPTYCHAMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try direct
|
||||||
|
int count = 0;
|
||||||
|
const DataDragon::ChampData& directChampData = dd->getBestMatchingChamp(name, &count);
|
||||||
|
if(directChampData.key != -1) {
|
||||||
|
return directChampData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// not specific
|
||||||
|
if(count > 1) {
|
||||||
|
return DataDragon::EMPTYCHAMP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// try for substrings
|
||||||
|
static const QRegularExpression splittingRegex("\\W+");
|
||||||
|
QStringList list = name.split(splittingRegex, QString::SplitBehavior::SkipEmptyParts);
|
||||||
|
QSet<int> matchedIds;
|
||||||
|
const DataDragon::ChampData* lastMatched = nullptr;
|
||||||
|
for(const QString& entry : list) {
|
||||||
|
count = 0;
|
||||||
|
const DataDragon::ChampData& splitChampData = dd->getBestMatchingChamp(entry, &count);
|
||||||
|
if(count == 1) {
|
||||||
|
matchedIds.insert(splitChampData.key);
|
||||||
|
lastMatched = &splitChampData;
|
||||||
|
} else if(count > 1) {
|
||||||
|
// not specific
|
||||||
|
return DataDragon::EMPTYCHAMP;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(lastMatched && matchedIds.size() == 1) {
|
||||||
|
return *lastMatched;
|
||||||
|
}
|
||||||
|
|
||||||
|
// not specific or not found
|
||||||
|
return DataDragon::EMPTYCHAMP;
|
||||||
|
}
|
||||||
|
|
||||||
QString RunePageList::getRuneDescription(const ::RunePage& runepage) {
|
QString RunePageList::getRuneDescription(const ::RunePage& runepage) {
|
||||||
QString outStr;
|
QString outStr;
|
||||||
outStr.reserve(100);
|
outStr.reserve(100);
|
||||||
|
|
Loading…
Reference in New Issue