-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandDialog.cpp
More file actions
207 lines (170 loc) · 6.03 KB
/
CommandDialog.cpp
File metadata and controls
207 lines (170 loc) · 6.03 KB
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
200
201
202
203
204
205
206
207
#include "CommandDialog.h"
#include "ui_CommandDialog.h"
#include "MainWindow.h"
#include "TwitchBotDialog.h"
#include <QDebug>
#define PARENT ((MainWindow *)parentWidget())
#define COMMAND_LIST ((MainWindow *)parentWidget())->getQTwitchBotData()
CommandDialog::CommandDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CommandDialog)
{
ui->setupUi(this);
ui->responseEdit_1->hide();
ui->responseEdit_2->hide();
ui->responseEdit_3->hide();
ui->responseEdit_4->hide();
ui->DialogOutputNum->setMaximum(4);
ui->DialogOutputNum->setMinimum(1);
for (int i = 0; i < COMMAND_LIST->size(); ++i)
{
ui->commandSelect->addItem(COMMAND_LIST->at(i).command);
}
connect(ui->addDialog, SIGNAL(clicked(bool)), this, SLOT(createAddDialogWin()));
}
CommandDialog::~CommandDialog()
{
// Save on exit
this->clearFocus();
// Cleanup
if (dataToSend != nullptr)
{
delete dataToSend;
}
delete ui;
}
// For now only support 4 random resposes associated with 1 command
// And now I collapse it and never look at it again because that was lazy programming :P
void CommandDialog::on_DialogOutputNum_valueChanged(int arg1)
{
if (arg1 >= 1)
{
ui->responseEdit_1->show();
}
if (arg1 >= 2)
{
ui->responseEdit_2->show();
}
if (arg1 >= 3)
{
ui->responseEdit_3->show();
}
if (arg1 >= 4)
{
ui->responseEdit_4->show();
}
if (arg1 < 4)
{
ui->responseEdit_4->hide();
}
if (arg1 < 3)
{
ui->responseEdit_3->hide();
}
if (arg1 < 2)
{
ui->responseEdit_2->hide();
}
if (arg1 < 1)
{
ui->responseEdit_1->hide();
}
}
void CommandDialog::syncDialogData()
{
if (COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses.size() >= 1)
ui->responseEdit_1->setText(COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses[0]);
if (COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses.size() >= 2)
ui->responseEdit_2->setText(COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses[1]);
if (COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses.size() >= 3)
ui->responseEdit_3->setText(COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses[2]);
if (COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses.size() >= 4)
ui->responseEdit_4->setText(COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses[3]);
dataToSend->command = ui->commandSelect->currentText();
ui->DialogOutputNum->setValue(COMMAND_LIST->at(ui->commandSelect->currentIndex()).responses.size());
}
void CommandDialog::saveData()
{
// For debugging
vector<UserCommandData> *commandPtr = COMMAND_LIST;
int i = ui->commandSelect->currentIndex();
// Nested if statements to avoid the "assert" statement that they have
if (COMMAND_LIST->size() > 0)
if (COMMAND_LIST->at(i).responses.size() != ui->DialogOutputNum->value())
COMMAND_LIST->at(i).responses.resize(ui->DialogOutputNum->value());
// Existing commands
if (i < COMMAND_LIST->size())
{
if (COMMAND_LIST->at(i).command == ui->commandSelect->currentText())
{
if (COMMAND_LIST->at(i).responses.size() >= 1 && ui->responseEdit_1->toPlainText().size() >= 1)
COMMAND_LIST->at(i).responses[0] = (ui->responseEdit_1->toPlainText());
if (COMMAND_LIST->at(i).responses.size() >= 2 && ui->responseEdit_2->toPlainText().size() >= 1)
COMMAND_LIST->at(i).responses[1] = (ui->responseEdit_2->toPlainText());
if (COMMAND_LIST->at(i).responses.size() >= 3 && ui->responseEdit_3->toPlainText().size() >= 1)
COMMAND_LIST->at(i).responses[2] = (ui->responseEdit_3->toPlainText());
if (COMMAND_LIST->at(i).responses.size() == 4 && ui->responseEdit_4->toPlainText().size() >= 1)
COMMAND_LIST->at(i).responses[3] = (ui->responseEdit_4->toPlainText());
}
}
// New command
else
{
if (dataToSend->responses.size() >= 1 && ui->responseEdit_1->toPlainText().size() >= 1)
dataToSend->responses[0] = ui->responseEdit_1->toPlainText();
if (dataToSend->responses.size() >= 2 && ui->responseEdit_2->toPlainText().size() >= 1)
dataToSend->responses[1] = ui->responseEdit_2->toPlainText();
if (dataToSend->responses.size() >= 3 && ui->responseEdit_3->toPlainText().size() >= 1)
dataToSend->responses[2] = ui->responseEdit_3->toPlainText();
if (dataToSend->responses.size() >= 4 && ui->responseEdit_4->toPlainText().size() >= 1)
dataToSend->responses[3] = ui->responseEdit_4->toPlainText();
}
for (int i = 0; i < dataToSend->responses.size(); ++i)
{
qDebug() << dataToSend->responses[i];
}
// If it isn't a duplicate append it
if (PARENT->confirmNotDuplicate(*dataToSend))
{
COMMAND_LIST->push_back(*dataToSend);
}
delete dataToSend;
dataToSend = new UserCommandData();
}
void CommandDialog::addDialogOption(const QString &value)
{
ui->commandSelect->addItem(value);
}
void CommandDialog::createAddDialogWin()
{
TwitchBotDialog *b = new TwitchBotDialog(this);
b->show();
b->exec();
delete b;
}
void CommandDialog::on_commandSelect_currentIndexChanged(int index)
{
// If we selected a new command
if (index + 1 > COMMAND_LIST->size())
{
// no data to sync
ui->responseEdit_1->clear();
ui->responseEdit_2->clear();
ui->responseEdit_3->clear();
ui->responseEdit_4->clear();
saveData();
}
// If we selected an existing command
else
{
syncDialogData();
}
}
void CommandDialog::on_deleteButton_released()
{
COMMAND_LIST->erase(COMMAND_LIST->begin() + ui->commandSelect->currentIndex());
}
void CommandDialog::on_forceSave_clicked()
{
saveData();
}