display champion images

This commit is contained in:
mrbesen 2022-04-23 00:39:45 +02:00
parent a806c60a40
commit 41ecc12e75
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
9 changed files with 166 additions and 9 deletions

View File

@ -14,6 +14,7 @@ public:
struct ChampData {
public:
ChampData();
ChampData(const QJsonObject& source);
std::string name;
@ -32,7 +33,9 @@ public:
const std::string& getVersion();
const std::vector<ChampData>& getChamps();
cv::Mat getImage(const std::string& champid, ImageType imgtype = ImageType::SQUARE);
const ChampData& getBestMatchingChamp(const std::string& name);
static const ChampData EMPTYCHAMP;
protected:
std::string getCDNString() const;
QByteArray requestRaw(const std::string& url);

View File

@ -4,6 +4,7 @@
#include <QMainWindow>
#include <thread>
#include "datadragon.h"
#include "lolautoaccept.h"
QT_BEGIN_NAMESPACE
@ -28,9 +29,13 @@ private slots:
void pickedited(const QString&);
private:
// returns empty string on no match
const DataDragon::ChampData& getBestMatchingChamp(const std::string& name);
Ui::MainWindow *ui;
LolAutoAccept& lolaa;
std::thread lolaathread;
DataDragon dd;
};
#endif // MAINWINDOW_H

View File

@ -3,6 +3,8 @@
#include <QWidget>
#include "datadragon.h"
namespace Ui {
class StageSettings;
}
@ -26,6 +28,11 @@ public:
QString getChampion() const;
void setChampion(const QString& str);
void setDataDragon(DataDragon* dd);
void resizeEvent(QResizeEvent *event) override;
private slots:
void championChangedinternal(const QString& str);
void toggledinternal(int state);
@ -35,7 +42,12 @@ signals:
void championChanged(const QString&);
private:
void rescaleImage();
Ui::StageSettings *ui;
DataDragon* dd = nullptr;
int currentdisplayedChampKey;
cv::Mat img;
};
#endif // STAGESETTINGS_H

View File

@ -11,6 +11,7 @@
static const std::string BASEURL = "https://ddragon.leagueoflegends.com/";
const DataDragon::ChampData DataDragon::EMPTYCHAMP;
static size_t arrayWriteCallback(char* contents, size_t size, size_t nmemb, void* userdata) {
if(userdata) {
@ -52,6 +53,8 @@ DataDragon::DataDragon() {
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, arrayWriteCallback);
}
DataDragon::ChampData::ChampData() : key(-1) {}
DataDragon::ChampData::ChampData(const QJsonObject& source) {
name = getValue<std::string>(source, "name", "");
id = getValue<std::string>(source, "id", "");
@ -139,9 +142,26 @@ cv::Mat DataDragon::getImage(const std::string& champid, ImageType imgtype) {
}
cv::Mat decodedImage = cv::imdecode(rawData, cv::IMREAD_COLOR);
cv::cvtColor(decodedImage, decodedImage, cv::COLOR_BGR2RGB);
return decodedImage;
}
static std::string toLower(const std::string& in) {
return QString::fromStdString(in).toLower().toStdString();
}
const DataDragon::ChampData& DataDragon::getBestMatchingChamp(const std::string& name) {
getChamps();
// for now: just check for a perfect hit
std::string lower = toLower(name);
for(const ChampData& it : champs) {
if(toLower(it.id) == lower || toLower(it.name) == lower) {
return it;
}
}
return EMPTYCHAMP;
}
std::string DataDragon::getCDNString() const {
return "cdn/" + version + "/";
}

View File

@ -207,6 +207,7 @@ void LolAutoAccept::run() {
void LolAutoAccept::stop() {
shouldrun = false;
state = State::LOBBY;
}
void LolAutoAccept::stopJoinThread() {

View File

@ -1,11 +1,16 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <Log.h>
#include <future>
MainWindow::MainWindow(LolAutoAccept& lolaa, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), lolaa(lolaa) {
ui->setupUi(this);
ui->prepickstage->setDataDragon(&dd);
ui->banstage->setDataDragon(&dd);
ui->pickstage->setDataDragon(&dd);
}
MainWindow::~MainWindow() {

View File

@ -1,9 +1,13 @@
#include "stagesettings.h"
#include "ui_stagesettings.h"
#include <Log.h>
StageSettings::StageSettings(QWidget *parent) : QWidget(parent), ui(new Ui::StageSettings) {
ui->setupUi(this);
setMinimumSize(ui->gridLayout->minimumSize());
rescaleImage();
}
StageSettings::~StageSettings() {
@ -35,10 +39,44 @@ void StageSettings::setChampion(const QString& str) {
ui->lineEdit->setText(str);
}
void StageSettings::setDataDragon(DataDragon* dd_) {
dd = dd_;
}
void StageSettings::resizeEvent([[maybe_unused]] QResizeEvent* event) {
rescaleImage();
}
void StageSettings::championChangedinternal(const QString& str) {
emit championChanged(str);
if(dd) {
const DataDragon::ChampData& cd = dd->getBestMatchingChamp(str.toStdString());
if(cd.key > 0) {
Log::info << "bestmatching: " << cd;
if(cd.key != currentdisplayedChampKey) {
img = dd->getImage(cd.id);
rescaleImage();
currentdisplayedChampKey = cd.key;
}
}
}
}
void StageSettings::toggledinternal(int state) {
emit toggled(state == Qt::CheckState::Checked);
}
void StageSettings::rescaleImage() {
if(img.empty()) return;
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();
// set a scaled pixmap to a w x h window keeping its aspect ratio
ui->champImg->setPixmap(p.scaled(w, h, Qt::KeepAspectRatio)); //
}

View File

@ -6,20 +6,26 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>400</width>
<height>635</height>
</rect>
</property>
<property name="windowTitle">
<string>LoL-Auto-Accept</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>731</width>
<width>381</width>
<height>491</height>
</rect>
</property>
@ -44,7 +50,7 @@
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -66,7 +72,7 @@
<item>
<widget class="StageSettings" name="banstage" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -88,7 +94,7 @@
<item>
<widget class="StageSettings" name="pickstage" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
<sizepolicy hsizetype="Minimum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -115,7 +121,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>400</width>
<height>24</height>
</rect>
</property>

View File

@ -7,15 +7,39 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>250</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>300</width>
<height>130</height>
</size>
</property>
<property name="baseSize">
<size>
<width>300</width>
<height>130</height>
</size>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string notr="true"/>
</property>
@ -29,6 +53,12 @@
</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>160</width>
@ -44,6 +74,43 @@
</property>
</widget>
</item>
<item row="0" column="2" rowspan="2">
<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>
</layout>
</widget>
</item>