-
Notifications
You must be signed in to change notification settings - Fork 6
/
huntimagegenerator.cpp
199 lines (165 loc) · 6.55 KB
/
huntimagegenerator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "huntimagegenerator.h"
#include "globals.h"
#include <QDebug>
#include <QPainter>
#include <QFontMetrics>
#include <QApplication>
#include <QClipboard>
#include <QDate>
#include <QMimeData>
namespace Yate {
HuntImageGenerator::HuntImageGenerator(QString path, NightInfo &night, QString host, QSet<QString> squad, QObject *parent)
: QObject{parent}, path_(path), night_(night), host_(host), squad_(squad)
{
}
QImage* HuntImageGenerator::generateImage()
{
qDebug() << "Generating summary image.";
int numSets = night_.validRunCount();
int setHeight = 233;
int capHeight = setHeight / 3;
int summaryHeight = capHeight / 1.5;
int footerHeight = capHeight / 2;
int imageWidth = 1200;
int imageHeight = numSets * setHeight + summaryHeight + footerHeight;
QImage *pix = new QImage(imageWidth, imageHeight, QImage::Format_ARGB32_Premultiplied);
QPainter painter(pix);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::TextAntialiasing, true);
painter.setPen(QPen(QColor(SUMMARY_COLOR_LIMBS), 3));
painter.setBrush(QColor(SUMMARY_COLOR_LIMBS));
QFont font = painter.font();
// font.setFamily("Courier New");
font.setFamily("Roboto Mono");
font.setPointSize(20);
QFontMetrics fm(font);
painter.setFont(font);
painter.fillRect(0, 0, pix->width(), pix->height(), QColor(SUMMARY_COLOR_BG));
int topOffset = 0;
int fw, fh;
int textYOffset = 10;
int spaceWidth = QFontMetrics(painter.font()).horizontalAdvance(" ");
QString text;
text = "Squad";
font.setBold(true);
fm = QFontMetrics(font);
painter.setFont(font);
int xpos = 5;
int ypos = topOffset + summaryHeight / 2 + 4;
painter.setPen(QPen(QColor(SUMMARY_COLOR_TITLE), 2));
painter.drawText(xpos, ypos, text);
xpos += fm.horizontalAdvance(text) + 2 * spaceWidth;
QStringList squadList;
squadList.append(host_);
for(auto &m: squad_) {
if (m.trimmed() != "") {
squadList.append(m);
}
}
text = squadList.join(", ");
QString nightRes = night_.getNightResult();
if (nightRes.size()) {
text = text + " (" + nightRes + ")";
}
painter.setPen(QPen(QColor(SUMMARY_COLOR_LIMBS), 2));
painter.drawText(xpos, ypos, text);
painter.setPen(QPen(QColor(SUMMARY_COLOR_AVERAGE), 2));
QString txtAvg = night_.getAverage();
text = txtAvg;
painter.drawText(imageWidth - fm.horizontalAdvance(text) - 5, ypos, text);
painter.setPen(QPen(QColor(SUMMARY_COLOR_TITLE), 2));
text = "Average";
painter.drawText(imageWidth - fm.horizontalAdvance(txtAvg) - spaceWidth - fm.horizontalAdvance(text) - 5, ypos, text);
topOffset += summaryHeight;
font.setBold(false);
painter.setFont(font);
painter.setPen(QPen(QColor(SUMMARY_COLOR_LIMBS), 3));
painter.drawLine(0, topOffset, imageWidth, topOffset);
for(int i = 0; i < night_.runs().size(); i++) {
auto &set = night_.run(i);
if (set.getNumberOfCaps() || set.getNumberOfKills()) {
for (int j = 0; j < 3; j++) {
auto cap = set.capInfoByIndex(j);
if (cap.valid()) {
text = HuntInfo::eidolonName(j, true);
fm = QFontMetrics(painter.font());
xpos = 5;
fw = fm.horizontalAdvance(text);
int ypos = topOffset + capHeight/2 + textYOffset;
painter.setPen(QPen(QColor(SUMMARY_COLOR_TITLE), 2));
painter.drawText(xpos, ypos, text);
xpos += fw + 2 * spaceWidth;
QStringList limbsVals;
QString ws = FORMAT_NUMBER(cap.waterShield());
while (ws.size() < 6) {
ws = ws + " ";
}
limbsVals.append(ws);
for(auto &l: cap.limbBreaks()) {
QString limbStr = FORMAT_NUMBER(l);
limbsVals.append(limbStr);
}
text = limbsVals.join(" ");
painter.setPen(QPen(QColor(SUMMARY_COLOR_LIMBS), 2));
painter.drawText(xpos, ypos, text);
if (cap.result() == CapState::InComplete || cap.result() == CapState::Spawned) {
text = "Incomplete";
} else {
text = HuntInfo::timestampToProgressString(cap.lastLimbProgressTime()) + " [" + FORMAT_NUMBER(cap.capshotTime()) + "] (" + (cap.result() == CapState::Capture? "Captured": "Killed") + ")";
}
font.setFamily("Robot Mono Medium");
font.setBold(true);
painter.setFont(font);
painter.setPen(QPen(QColor(SUMMARY_COLOR_LAST_LIMB), 2));
fm = QFontMetrics(font);
fw = fm.horizontalAdvance(text);
painter.drawText(imageWidth - fw - 5, ypos, text);
font.setFamily("Robot Mono");
font.setBold(false);
fm = QFontMetrics(font);
painter.setFont(font);
}
topOffset += capHeight;
if (j != 2) {
painter.setPen(QPen(QColor(SUMMARY_COLOR_LIMBS), 1));
painter.drawLine(0, topOffset, imageWidth, topOffset);
}
}
painter.setPen(QPen(QColor(SUMMARY_COLOR_LIMBS), 3));
painter.drawLine(0, topOffset, imageWidth, topOffset);
}
}
painter.setPen(QPen(QColor(SUMMARY_COLOR_LIMBS), 2));
font.setPointSize(14);
painter.setFont(font);
QString ver = QCoreApplication::applicationVersion();
if (ver.count(".") == 3) {
auto verDiv = ver.split(".");
verDiv.pop_back();
ver = verDiv.join(".");
}
text = "Generated by YATE " + ver + " (" + QDate::currentDate().toString("MMM dd, yyyy") + ")";
fm = QFontMetrics(font);
fw = fm.horizontalAdvance(text);
fh = fm.height();
topOffset += footerHeight - fh/2;
painter.drawText(imageWidth/2 - fw/2, topOffset, text);
qDebug() << "Summary image generated.";
return pix;
}
void HuntImageGenerator::exportImage()
{
auto img = generateImage();
qDebug() << "Saving image to " << path_;
img->save(path_);
delete img;
emit exportFinished(true);
}
void HuntImageGenerator::generateAndEmit()
{
auto img = generateImage();
qDebug() << "Emitting generated image.";
emit generateFinished(*img);
delete img;
}
}