new ui wip

This commit is contained in:
mrbesen 2022-07-02 17:44:29 +02:00
parent 9f1449d7f5
commit ffb980e672
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
10 changed files with 90 additions and 127 deletions

View File

@ -7,7 +7,7 @@
#include <thread>
#include <vector>
#include <opencv2/opencv.hpp>
#include <QPixmap>
#include "datadragonimagecache.h"
#include "memoryimagecache.h"
@ -15,7 +15,7 @@
class DataDragon : public RestClient {
public:
using notifyImgfunc_t = std::function<void(cv::Mat)>;
using notifyImgfunc_t = std::function<void(QPixmap)>;
DataDragon(const std::string& locale);
~DataDragon();
@ -45,7 +45,7 @@ public:
// might block until champ data is available
const std::vector<ChampData>& getChamps();
// might block until image is downloaded
cv::Mat getImage(const std::string& champid, ImageType imgtype = ImageType::SQUARE);
QPixmap getImage(const std::string& champid, ImageType imgtype = ImageType::SQUARE);
void getImageAsnyc(const std::string& champid, notifyImgfunc_t func, ImageType imgtype = ImageType::SQUARE);
// might block until champ data is available
const ChampData& getBestMatchingChamp(const std::string& name, int* count = nullptr);

View File

@ -2,14 +2,14 @@
#include <string>
#include <QByteArray>
#include <opencv2/opencv.hpp>
#include <QPixmap>
class DataDragonImageCache {
public:
DataDragonImageCache(const std::string& folderextra, const std::string& imageext = ".jpg");
~DataDragonImageCache();
cv::Mat getImage(const std::string& name);
QPixmap getImage(const std::string& name);
void addImageRaw(const QByteArray& arr, const std::string& name);
private:
std::string getFilepath(const std::string& name) const;

View File

@ -2,20 +2,20 @@
#include <functional>
#include <string>
#include <opencv2/opencv.hpp>
#include <QPixmap>
class MemoryImageCache {
public:
MemoryImageCache(size_t maxsize = 25);
void addImage(cv::Mat, const std::string& title, int type);
cv::Mat getImage(const std::string& title, int type);
void addImage(QPixmap, const std::string& title, int type);
QPixmap getImage(const std::string& title, int type);
private:
void cleanUp();
struct CachedImage {
time_t lastaccessed = 0;
cv::Mat imageref;
QPixmap imageref;
std::string title;
int type;

View File

@ -48,7 +48,7 @@ private:
Ui::StageSettings *ui;
DataDragon* dd = nullptr;
int currentdisplayedChampKey = -1;
cv::Mat img;
QPixmap img;
};
#endif // STAGESETTINGS_H

View File

@ -50,16 +50,16 @@ const std::vector<DataDragon::ChampData>& DataDragon::getChamps() {
return champs;
}
cv::Mat DataDragon::getImage(const std::string& champid, ImageType imgtype) {
QPixmap DataDragon::getImage(const std::string& champid, ImageType imgtype) {
if(champid.empty()) return {};
// query mem cache
cv::Mat img = memcache.getImage(champid, (int) imgtype);
if(!img.empty()) return img;
QPixmap img = memcache.getImage(champid, (int) imgtype);
if(!img.isNull()) return img;
// query HDD cache
img = cache[(int) imgtype].getImage(champid);
if(!img.empty()) {
if(!img.isNull()) {
// update mem cache
memcache.addImage(img, champid, (int) imgtype);
return img;
@ -84,11 +84,8 @@ cv::Mat DataDragon::getImage(const std::string& champid, ImageType imgtype) {
// store HDD cache
cache[(int) imgtype].addImageRaw(arr, champid);
// convert byte array to image data
cv::Mat rawData(1, arr.size(), CV_8UC1, (void*) arr.data());
cv::Mat decodedImage = cv::imdecode(rawData, cv::IMREAD_COLOR);
cv::cvtColor(decodedImage, decodedImage, cv::COLOR_BGR2RGB);
QPixmap decodedImage;
decodedImage.loadFromData(arr);
// store mem cache
memcache.addImage(decodedImage, champid, (int) imgtype);
@ -274,7 +271,7 @@ void DataDragon::threadLoop() {
tasks.pop_front();
}
cv::Mat img = getImage(t.champid, t.type);
QPixmap img = getImage(t.champid, t.type);
t.func(img);
}
}

View File

@ -1,6 +1,7 @@
#include "datadragonimagecache.h"
#include <QFile>
#include <QPixmap>
#include <Log.h>
@ -14,11 +15,8 @@ DataDragonImageCache::DataDragonImageCache(const std::string& folderextra, const
}
DataDragonImageCache::~DataDragonImageCache() {}
cv::Mat DataDragonImageCache::getImage(const std::string& name) {
auto img = cv::imread(getFilepath(name));
if(!img.empty())
cv::cvtColor(img, img, cv::COLOR_BGR2RGB);
return img;
QPixmap DataDragonImageCache::getImage(const std::string& name) {
return QPixmap(QString::fromStdString(getFilepath(name)));
}
void DataDragonImageCache::addImageRaw(const QByteArray& arr, const std::string& name) {

View File

@ -86,7 +86,7 @@ void LolAutoAccept::innerRun() {
auto start = std::chrono::high_resolution_clock::now();
auto phase = clientapi->getGameflowPhase();
Log::debug << "current Gameflowphase: " << phase;
Log::info << "current Gameflowphase: " << phase;
// do processing
if(phase == ClientAPI::GameflowPhase::READYCHECK) {
@ -106,7 +106,7 @@ void LolAutoAccept::innerRun() {
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> dur = (end-start);
//if(dur.count() > 1e-5)
Log::info << "iteration took: " << (dur.count() * 1000) << " ms";
Log::note << "iteration took: " << (dur.count() * 1000) << " ms";
std::this_thread::sleep_for(std::chrono::milliseconds(1200));
}
@ -190,11 +190,11 @@ void LolAutoAccept::champSelect() {
ClientAPI::Position pos = me ? me->position : ClientAPI::Position::INVALID;
Log::info << "cellid: " << cellid << " position: " << pos << " counter: " << session.counter << " timer: timeleftip: " << session.timer.adjustedTimeLeftInPhase << " totaltimephase: " << session.timer.totalTimeInPhase;
Log::debug << "cellid: " << cellid << " position: " << pos << " counter: " << session.counter << " timer: timeleftip: " << session.timer.adjustedTimeLeftInPhase << " totaltimephase: " << session.timer.totalTimeInPhase;
// find actions for own cell
auto ownactions = getOwnActions(cellid, session.actions);
Log::note << "ownactions: " << ownactions.size();
Log::debug << "ownactions: " << ownactions.size();
// try to prepick champ
Log::info << "champselectphase: " << session.timer.phase;

View File

@ -5,7 +5,7 @@
MemoryImageCache::MemoryImageCache(size_t maxsize) : maxsize(maxsize) {}
void MemoryImageCache::addImage(cv::Mat img, const std::string& title, int type) {
void MemoryImageCache::addImage(QPixmap img, const std::string& title, int type) {
auto it = std::find_if(cache.begin(), cache.end(), getImageMatcher(title, type));
if(it == cache.end()) {
// insert new
@ -19,7 +19,7 @@ void MemoryImageCache::addImage(cv::Mat img, const std::string& title, int type)
it->imageref = img;
}
cv::Mat MemoryImageCache::getImage(const std::string& title, int type) {
QPixmap MemoryImageCache::getImage(const std::string& title, int type) {
auto it = std::find_if(cache.begin(), cache.end(), getImageMatcher(title, type));
if(it == cache.end()) {
return {};

View File

@ -35,11 +35,11 @@ void StageSettings::setState(bool b) {
}
QString StageSettings::getChampion() const {
return ui->lineEdit->text();
return ""; // ui->lineEdit->text();
}
void StageSettings::setChampion(const QString& str) {
ui->lineEdit->setText(str);
// ui->lineEdit->setText(str);
championChangedinternal(str);
}
@ -58,7 +58,7 @@ void StageSettings::championChangedinternal(const QString& str) {
if(cd.key != currentdisplayedChampKey) {
applyChampion(cd);
}
ui->champcount->setText(tr("Champions matched: %1").arg(QString::fromStdString(std::to_string(count))));
//ui->champcount->setText(tr("Champions matched: %1").arg(QString::fromStdString(std::to_string(count))));
} else {
emit championChanged(str);
}
@ -69,35 +69,39 @@ void StageSettings::toggledinternal(int state) {
}
void StageSettings::rescaleImage() {
if(img.empty()) {
ui->champImg->setPixmap(QPixmap());
if(img.isNull()) {
//ui->champImg->setPixmap(QPixmap());
return;
}
auto qimg = QImage((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);
auto p = QPixmap::fromImage(qimg);
//auto qimg = QImage((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);
// auto p = QPixmap::fromImage(qimg);
// get label dimensions
int w = ui->champImg->width();
int h = ui->champImg->height();
//int w = ui->champImg->width();
//int h = ui->champImg->height();
// set a scaled pixmap to a w x h window keeping its aspect ratio
ui->champImg->setPixmap(p.scaled(w, h, Qt::KeepAspectRatio)); //
//ui->champImg->setPixmap(p.scaled(w, h, Qt::KeepAspectRatio)); //
}
void StageSettings::applyChampion(const DataDragon::ChampData& cd) {
dd->getImageAsnyc(cd.id, [this, cd](cv::Mat img) {
dd->getImageAsnyc(cd.id, [this, cd](QPixmap img) {
this->img = img;
currentdisplayedChampKey = cd.key;
rescaleImage();
QIcon icon(this->img);
ui->championList->addItem(new QListWidgetItem(icon, "Champ", nullptr, 0));
emit championChanged(QString::fromStdString(cd.name));
});
if(cd.key >= 0) {
#define QS(A) arg(QString::fromStdString(A))
ui->champImg->setToolTip(tr("Champion: %1\nType: %2\nTitle: %3\nID: %4").QS(cd.name).QS(cd.partype).QS(cd.title).arg(cd.key));
//ui->champImg->setToolTip(tr("Champion: %1\nType: %2\nTitle: %3\nID: %4").QS(cd.name).QS(cd.partype).QS(cd.title).arg(cd.key));
#undef QS
} else {
ui->champImg->setToolTip("");
//ui->champImg->setToolTip("");
}
}

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>250</height>
<width>762</width>
<height>859</height>
</rect>
</property>
<property name="sizePolicy">
@ -44,66 +44,6 @@
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Champion:</string>
</property>
</widget>
</item>
<item row="0" column="2" rowspan="3">
<widget class="QLabel" name="champImg">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>4</width>
<height>4</height>
</size>
</property>
<property name="baseSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QCheckBox" name="checkBox">
<property name="text">
@ -111,13 +51,54 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="champcount">
<property name="text">
<string/>
<item row="1" column="0">
<widget class="QListWidget" name="championList">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>150</height>
</size>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addChampion">
<property name="text">
<string>Add Champion</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="moveup">
<property name="text">
<string>Move Up</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="movedown">
<property name="text">
<string>Move Down</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeChampion">
<property name="text">
<string>Remove Champion</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
@ -125,26 +106,9 @@
</widget>
<tabstops>
<tabstop>checkBox</tabstop>
<tabstop>lineEdit</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>lineEdit</sender>
<signal>textEdited(QString)</signal>
<receiver>StageSettings</receiver>
<slot>championChangedinternal(QString)</slot>
<hints>
<hint type="sourcelabel">
<x>193</x>
<y>212</y>
</hint>
<hint type="destinationlabel">
<x>250</x>
<y>329</y>
</hint>
</hints>
</connection>
<connection>
<sender>checkBox</sender>
<signal>stateChanged(int)</signal>