-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow_editor.cpp
More file actions
190 lines (164 loc) · 4.61 KB
/
mainwindow_editor.cpp
File metadata and controls
190 lines (164 loc) · 4.61 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "settings.h"
#include "soundlistener.h"
#include "sounddevice.h"
#include "xmlutils.h"
#include <QFileDialog>
#include <QCloseEvent>
#include <QMessageBox>
#include <QFile>
#include <iostream>
void MainWindow::closeEvent(QCloseEvent* event)
{
if(runDirtyUserCheck())
event->accept();
else
event->ignore();
}
bool MainWindow::runDirtyUserCheck()
{
if(!m_editorData
|| !m_editorData->m_dirty)
return true;
int rv = QMessageBox::question(this, tr("Do you want to save?"),
tr("A sound pack has been edited.\r\nDo you want to save it?"),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
QMessageBox::Cancel);
switch(rv)
{
case QMessageBox::Yes:
if(saveXML())
return true;
return false;
case QMessageBox::No:
return true;
default:
case QMessageBox::Cancel:
return false;
}
}
bool MainWindow::saveXML()
{
if(!m_editorData || !m_editorData->m_pack.m_valid)
return false;
QFileInfo qfi(ui->browseSoundPackLineEdit->text());
PackListInfo pack;
pack.m_filename = qfi.fileName();
pack.m_basepath = qfi.absolutePath();
pack.m_displayname = "EDITOR";
if(!SaveXMLPack(pack, m_editorData->m_pack))
{
QMessageBox::warning(this, tr("Error saving XML file"), tr("An error happened trying to save the XML file."));
return false;
}
m_editorData->m_dirty = false;
return true;
}
void MainWindow::on_actionSave_Pack_triggered()
{
saveXML();
}
void MainWindow::on_loadButton_clicked()
{
if(!runDirtyUserCheck())
return;
ui->eventsList->clear();
m_editorData.reset();
ui->saveButton->setEnabled(false);
ui->eventsGroup->setEnabled(false);
QFileInfo qfi(ui->browseSoundPackLineEdit->text());
PackListInfo pack;
pack.m_filename = qfi.fileName();
pack.m_basepath = qfi.absolutePath();
pack.m_displayname = "EDITOR";
std::unique_ptr<EditorData> newData(new EditorData);
ParseXMLPack(pack, newData->m_pack, true);
if(!newData->m_pack.m_valid)
{
QMessageBox::warning(this, tr("Error loading XML file"), tr("An error happened trying to load the XML file."));
return;
}
newData->m_pack.m_enabled = true;
newData->m_basedir = qfi.absoluteDir();
m_editorData.swap(newData);
ui->currentlyLoadedPackLabel->setText(m_editorData->m_pack.m_filename);
ui->saveButton->setEnabled(true);
ui->eventsGroup->setEnabled(true);
for(GameLineInfo& gli : m_editorData->m_pack.m_lineinfos)
{
ui->eventsList->addItem(gli.m_regex.pattern());
}
}
void MainWindow::on_browseSoundPackButton_clicked()
{
QString r = QFileDialog::getOpenFileName(this, tr("Browse XML file..."),
QString(), QString("XML Files (*.xml);;All Files (*)"), nullptr,
QFileDialog::DontResolveSymlinks);
if(!r.isEmpty())
ui->browseSoundPackLineEdit->setText(r);
if(!m_editorData)
on_loadButton_clicked();
}
void MainWindow::on_deleteSelEvent_clicked()
{
if(!m_editorData)
return;
int row = ui->eventsList->currentRow();
if(row < 0 || row >= m_editorData->m_pack.m_lineinfos.size())
return;
delete ui->eventsList->takeItem(row);
m_editorData->m_pack.m_lineinfos.removeAt(row);
m_editorData->m_dirty = true;
}
void MainWindow::on_editSelEvent_clicked()
{
if(!m_editorData)
return;
if(m_editorData->m_eventEditor)
return;
int row = ui->eventsList->currentRow();
if(row < 0 || row >= m_editorData->m_pack.m_lineinfos.size())
return;
QListWidgetItem* item = ui->eventsList->item(row);
if(!item)
return;
m_editorData->m_editItem = item;
m_editorData->m_editGLI = &(m_editorData->m_pack.m_lineinfos[row]);
m_editorData->m_eventEditor
= new EventEditor(this, *(m_editorData->m_editGLI), m_editorData->m_basedir);
connect(m_editorData->m_eventEditor, &QDialog::accepted,
this, &MainWindow::soundEdited);
m_editorData->m_eventEditor->show();
}
void MainWindow::soundEdited()
{
if(!m_editorData
|| !m_editorData->m_editGLI
|| !m_editorData->m_editItem
|| !m_editorData->m_eventEditor)
return;
m_editorData->m_dirty = true;
*(m_editorData->m_editGLI) = m_editorData->m_eventEditor->GetGLI();
m_editorData->m_editItem->setText(m_editorData->m_editGLI->m_regex.pattern());
m_editorData->m_editItem = nullptr;
m_editorData->m_editGLI = nullptr;
m_editorData->m_eventEditor = nullptr;
}
void MainWindow::on_createNewEvent_clicked()
{
if(!m_editorData)
return;
GameLineInfo gliNew;
gliNew.m_regex = QRegExp("^New Event$");
gliNew.m_channel = "sfx";
gliNew.m_loop = false;
gliNew.m_threshold = TH_DEFAULT;
gliNew.m_delay = 0;
gliNew.m_concurrency = 0;
gliNew.m_timeout = 0;
gliNew.m_probability = 100;
m_editorData->m_pack.m_lineinfos.push_back(gliNew);
ui->eventsList->addItem(gliNew.m_regex.pattern());
m_editorData->m_dirty = true;
}