-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrainingtimer.cpp
143 lines (123 loc) · 3.91 KB
/
trainingtimer.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
#include <QLoggingCategory>
#include <QMessageBox>
Q_LOGGING_CATEGORY(log_trainingTimer, "Training Timer")
#define sDebug() qCDebug(log_trainingTimer())
#include "trainingtimer.h"
#include "ui_trainingtimer.h"
TrainingTimer::TrainingTimer(QWidget *parent) : QWidget(parent), ui(new Ui::TrainingTimer)
{
ui->setupUi(this);
oldAddressValue = 0;
timer.setInterval(20);
connect(&timer, &QTimer::timeout, this, &TrainingTimer::onTimerTick);
/*QTimer* piko = new QTimer(this);
piko->setInterval(1000);
connect(piko, &QTimer::timeout, this, [=]() {
readyToTime = true;
onSavestateLoaded();
});
piko->start();*/
readyToTime = false;
firstMemoryTick = true;
firstLoad = true;
}
TrainingTimer::~TrainingTimer()
{
}
bool TrainingTimer::loadPreset(const QString &path)
{
return configDialog.loadPresets(path);
}
void TrainingTimer::setHandler(HandleStuff *stuff)
{
disconnect(this, &TrainingTimer::memoryPresetChanged, handler, &HandleStuff::setMemoryToWatch);
handler = stuff;
connect(this, &TrainingTimer::memoryPresetChanged, handler, &HandleStuff::setMemoryToWatch);
connect(handler, &HandleStuff::loadStateFinished, this, &TrainingTimer::onSavestateLoaded);
connect(handler, &HandleStuff::controllerLoadStateFinished, this, &TrainingTimer::onSavestateLoaded);
connect(handler, &HandleStuff::gotMemoryValue, this, &TrainingTimer::onMemoryRequestDone);
connect(handler, &HandleStuff::newGameLoaded, this, [=] {
if (handler->hasMemoryWatch())
{
if (handler->gameInfos().memoryPreset.domain.isEmpty() == false)
{
configDialog.setPreset(handler->gameInfos().memoryPreset);
ui->memoryCheckcheckBox->setEnabled(true);
}
ui->configPushButton->setEnabled(true);
} else {
ui->memoryCheckcheckBox->setEnabled(false);
ui->configPushButton->setEnabled(false);
}
});
}
void TrainingTimer::onSavestateLoaded()
{
setLabelTime(ui->lastLoadClock);
readyToTime = true;
timer.start();
startedTime = QDateTime::currentDateTime();
firstMemoryTick = true;
if (firstLoad)
{
if (handler->hasMemoryWatch() && ui->memoryCheckcheckBox->isChecked())
{
sDebug() << "Starting memory watch";
handler->startMemoryWatch();
}
firstLoad = false;
}
sDebug() << startedTime;
}
void TrainingTimer::onMemoryRequestDone(quint64 value)
{
if (firstMemoryTick)
{
oldAddressValue = value;
firstMemoryTick = false;
}
else {
sDebug() << "Got Value : " << QString::number(value, 16) << " Old Value " << QString::number(oldAddressValue, 16);
if (value != oldAddressValue)
{
setLabelTime(ui->memoryClock);
oldAddressValue = value;
}
}
}
void TrainingTimer::onTimerTick()
{
if (readyToTime)
setLabelTime(ui->mainClock);
}
void TrainingTimer::setLabelTime(QLabel* label)
{
QTime time(0, 0 , 0);
//sDebug() << "MS to" << startedTime.msecsTo(QDateTime::currentDateTime());
time = time.addMSecs(startedTime.msecsTo(QDateTime::currentDateTime()));
//sDebug() << time;
label->setText(time.toString("mm:ss:zzz"));
}
void TrainingTimer::on_configPushButton_clicked()
{
auto ok = configDialog.exec();
if (ok == QDialog::Accepted)
{
emit memoryPresetChanged(configDialog.currentPreset());
}
}
void TrainingTimer::on_memoryCheckcheckBox_stateChanged(int state)
{
ui->memoryClock->setEnabled(state == Qt::Checked);
handler->saveMemoryCheck(state == Qt::Checked);
if (state != Qt::Checked)
{
ui->memoryClock->setText("-");
if (handler->hasMemoryWatch())
handler->stopMemoryWatch();
} else {
ui->memoryClock->setText("00:00:00");
/*if (handler->hasMemoryWatch())
handler->startMemoryWatch();*/
}
}