forked from brianuuu/AutoControllerHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmartprogramsetting.cpp
More file actions
248 lines (209 loc) · 6.58 KB
/
smartprogramsetting.cpp
File metadata and controls
248 lines (209 loc) · 6.58 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "smartprogramsetting.h"
#include "ui_smartprogramsetting.h"
SmartProgramSetting::SmartProgramSetting(QWidget *parent) :
QWidget(parent),
ui(new Ui::SmartProgramSetting)
{
ui->setupUi(this);
this->layout()->setSizeConstraint(QLayout::SetMinimumSize);
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
m_settings = new QSettings("brianuuu", "AutoControllerHelper", this);
m_path = m_settings->value("DefaultDirectory", QString()).toString();
// System
ui->CB_PreventUpdate->setChecked(m_settings->value("PreventUpdate", false).toBool());
ui->CB_DateArrangement->setCurrentIndex(m_settings->value("DateArrangement", 0).toInt());
ui->CurrentDate->setDate(QDate::currentDate());
ui->CB_GameLanguage->setCurrentIndex(m_settings->value("GameLanguage", 0).toInt());
// Sound
m_defaultPlayer.setMedia(QUrl("qrc:/resources/Sounds/06-caught-a-pokemon.mp3"));
ui->GB_Sound->setChecked(m_settings->value("SoundEnable", false).toBool());
ui->LE_Sound->setText(m_settings->value("SoundFileDirectory", QString()).toString());
bool customSound = m_settings->value("CustomSound", false).toBool();
if (customSound)
{
ui->RB_CustomSound->setChecked(true);
}
else
{
ui->RB_DefaultSound->setChecked(true);
}
SetCustomSoundEnabled();
// Stream Counter
ui->GB_Stream->setChecked(m_settings->value("StreamCounterEnable", false).toBool());
ui->CB_ExcludePrefix->setChecked(m_settings->value("StreamCounterExcludePrefix", false).toBool());
// Others
ui->CB_LogSave->setChecked(m_settings->value("LogAutosave", true).toBool());
}
SmartProgramSetting::~SmartProgramSetting()
{
delete ui;
}
void SmartProgramSetting::closeEvent(QCloseEvent *event)
{
m_settings->setValue("DefaultDirectory", m_path);
// System
m_settings->setValue("PreventUpdate", ui->CB_PreventUpdate->isChecked());
m_settings->setValue("DateArrangement", ui->CB_DateArrangement->currentIndex());
m_settings->setValue("GameLanguage", ui->CB_GameLanguage->currentIndex());
// Sound
m_settings->setValue("SoundEnable", ui->GB_Sound->isChecked());
m_settings->setValue("SoundFileDirectory", ui->LE_Sound->text());
m_settings->setValue("CustomSound", ui->RB_CustomSound->isChecked());
if (m_customSound)
{
m_customSound->stop();
}
m_defaultPlayer.stop();
// Stream Counter
m_settings->setValue("StreamCounterEnable", ui->GB_Stream->isChecked());
m_settings->setValue("StreamCounterExcludePrefix", ui->CB_ExcludePrefix->isChecked());
// Others
m_settings->setValue("LogAutosave", ui->CB_LogSave->isChecked());
}
bool SmartProgramSetting::isPreventUpdate()
{
return ui->CB_PreventUpdate->isChecked();
}
DateArrangement SmartProgramSetting::getDateArrangement()
{
return (DateArrangement)ui->CB_DateArrangement->currentIndex();
}
QDate SmartProgramSetting::getDate()
{
return ui->CurrentDate->date();
}
GameLanguage SmartProgramSetting::getGameLanguage()
{
return (GameLanguage)ui->CB_GameLanguage->currentIndex();
}
bool SmartProgramSetting::ensureTrainedDataExist()
{
QString languagePrefix = PokemonDatabase::getGameLanguagePrefix(getGameLanguage());
return QFile::exists(QString(RESOURCES_PATH) + "Tesseract/" + languagePrefix + ".traineddata");
}
bool SmartProgramSetting::isSoundEnabled()
{
return ui->GB_Sound->isChecked();
}
void SmartProgramSetting::playSound()
{
if (!isSoundEnabled()) return;
// Stop sound
if (m_customSound)
{
m_customSound->stop();
}
m_defaultPlayer.stop();
// Play sound
if (ui->RB_CustomSound->isChecked())
{
QString const sound = ui->LE_Sound->text();
if (!sound.isEmpty() && QFile::exists(sound))
{
if (m_customSound && m_customSound->fileName() != sound)
{
delete m_customSound;
}
if (!m_customSound)
{
m_customSound = new QSound(sound, this);
}
m_customSound->play();
}
}
else
{
m_defaultPlayer.play();
}
}
bool SmartProgramSetting::isStreamCounterEnabled()
{
return ui->GB_Stream->isChecked();
}
bool SmartProgramSetting::isStreamCounterExcludePrefix()
{
return ui->CB_ExcludePrefix->isChecked();
}
bool SmartProgramSetting::isLogAutosave()
{
return ui->CB_LogSave->isChecked();
}
bool SmartProgramSetting::isLogDebugCommand()
{
return ui->CB_LogDebugCommands->isChecked();
}
bool SmartProgramSetting::isLogDebugColor()
{
return ui->CB_LogDebugColor->isChecked();
}
void SmartProgramSetting::on_CB_DateArrangement_currentIndexChanged(int index)
{
DateArrangement da = (DateArrangement)index;
switch (da)
{
case DA_JP:
ui->CurrentDate->setDisplayFormat("yyyy/MM/dd");
break;
case DA_EU:
ui->CurrentDate->setDisplayFormat("dd/MM/yyyy");
break;
case DA_US:
ui->CurrentDate->setDisplayFormat("MM/dd/yyyy");
break;
}
}
void SmartProgramSetting::on_CB_GameLanguage_currentIndexChanged(int index)
{
if (!ensureTrainedDataExist())
{
QString languageName = PokemonDatabase::getGameLanguageName(getGameLanguage());
QMessageBox::warning(this, "Warning", "Language trained data for '" + languageName + "' for Tesseract is missing, please goto 'Resources/Tesseract' folder and follow the instructions in README.md", QMessageBox::Ok);
}
}
void SmartProgramSetting::on_PB_CurrentDate_clicked()
{
ui->CurrentDate->setDate(QDate::currentDate());
}
void SmartProgramSetting::on_RB_DefaultSound_clicked()
{
SetCustomSoundEnabled();
}
void SmartProgramSetting::on_RB_CustomSound_clicked()
{
SetCustomSoundEnabled();
}
void SmartProgramSetting::on_PB_Sound_clicked()
{
QString path = "";
if (!m_path.isEmpty())
{
path = m_path;
}
QString file = QFileDialog::getOpenFileName(this, tr("Select Custom Sound"), path, "Sounds (*.mp3 *.wav)");
if (file == Q_NULLPTR) return;
// Save directory
QFileInfo info(file);
m_path = info.dir().absolutePath();
ui->LE_Sound->setText(file);
int index = file.lastIndexOf('\\');
if (index == -1) index = file.lastIndexOf('/');
SetCustomSoundEnabled();
}
void SmartProgramSetting::on_PB_PlaySound_clicked()
{
playSound();
}
void SmartProgramSetting::SetCustomSoundEnabled()
{
if (ui->RB_CustomSound->isChecked())
{
// TODO: read media file
ui->LE_Sound->setEnabled(true);
ui->PB_Sound->setEnabled(true);
}
else
{
ui->LE_Sound->setEnabled(false);
ui->PB_Sound->setEnabled(false);
}
}