-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheventeditor.cpp
More file actions
144 lines (128 loc) · 3.64 KB
/
eventeditor.cpp
File metadata and controls
144 lines (128 loc) · 3.64 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
#include "eventeditor.h"
#include "ui_eventeditor.h"
#include "xmlutils.h"
#include <QFileDialog>
EventEditor::EventEditor(QWidget *parent, GameLineInfo const& gli,
QDir base) :
QDialog(parent),
ui(new Ui::EventEditor),
m_basePath(std::move(base)),
m_gli(gli),
m_variant(nullptr),
m_refreshing(false)
{
ui->setupUi(this);
ui->patternLineEdit->setText(m_gli.m_regex.pattern());
ui->channelLineEdit->setText(m_gli.m_channel);
ui->loopingEnabledCheckBox->setChecked(m_gli.m_loop);
ui->thresholdComboBox->setCurrentIndex(
MkEnum<Threshold>(Nothing, Everything, m_gli.m_threshold)
);
ui->delaySpinBox->setValue(m_gli.m_delay);
ui->concurrencySpinBox->setValue(m_gli.m_concurrency);
ui->timeoutSpinBox->setValue(m_gli.m_timeout);
ui->probabilitySpinBox->setValue(m_gli.m_probability);
m_refreshing = true;
for(SoundVariant& sv : m_gli.m_variants)
{
ui->variantComboBox->addItem(sv.m_relfilename);
}
m_refreshing = false;
on_variantComboBox_currentIndexChanged(ui->variantComboBox->currentIndex());
}
GameLineInfo& EventEditor::GetGLI()
{
return m_gli;
}
EventEditor::~EventEditor()
{
delete ui;
}
void EventEditor::on_randomLRBalanceCheckBox_stateChanged(int)
{
ui->lRBalanceDoubleSpinBox->setEnabled(!ui->randomLRBalanceCheckBox->isChecked());
if(m_variant)
// These values don't matter
m_variant->m_rngBalance = std::make_shared<RandomDouble>(0.0,0.0);
else
m_variant->m_rngBalance.reset();
}
void EventEditor::on_variantComboBox_currentIndexChanged(int index)
{
if(index >= 0 && index < m_gli.m_variants.size())
{
m_variant = &(m_gli.m_variants[index]);
m_refreshing = true;
ui->fileLineEdit->setText(m_variant->m_relfilename);
ui->weightSpinBox->setValue(m_variant->m_weight);
ui->volumeDoubleSpinBox->setValue(m_variant->m_volume);
ui->lRBalanceDoubleSpinBox->setValue(m_variant->m_balance);
ui->randomLRBalanceCheckBox->setChecked(
m_variant->m_rngBalance.get() != nullptr
);
m_refreshing = false;
ui->variantGroupBox->setEnabled(true);
}
else
{
ui->variantGroupBox->setEnabled(false);
}
}
void EventEditor::on_fileLineEdit_textChanged(QString const& arg1)
{
if(m_variant && !m_refreshing)
{
m_variant->m_relfilename = arg1;
int ix = ui->variantComboBox->currentIndex();
if(ix >= 0 && ix < ui->variantComboBox->count())
ui->variantComboBox->setItemText(ix, arg1);
}
}
void EventEditor::on_weightSpinBox_valueChanged(int arg1)
{
if(m_variant && !m_refreshing)
m_variant->m_weight = arg1;
}
void EventEditor::on_volumeDoubleSpinBox_valueChanged(double arg1)
{
if(m_variant && !m_refreshing)
m_variant->m_volume = arg1;
}
void EventEditor::on_lRBalanceDoubleSpinBox_valueChanged(double arg1)
{
if(m_variant && !m_refreshing)
m_variant->m_balance = arg1;
}
void EventEditor::on_deleteVariantButton_clicked()
{
int row = ui->variantComboBox->currentIndex();
if(row < 0 || row >= m_gli.m_variants.size())
return;
m_variant = nullptr;
ui->variantComboBox->removeItem(row);
m_gli.m_variants.removeAt(row);
}
void EventEditor::on_newVariantButton_clicked()
{
SoundVariant sv;
sv.m_relfilename = "New Sound";
sv.m_weight = DEFAULT_SOUND_WEIGHT;
sv.m_volume = 1.f;
sv.m_balance = 0.f;
m_gli.m_variants.push_back(sv);
ui->variantComboBox->addItem(sv.m_relfilename);
ui->variantComboBox->setCurrentIndex(ui->variantComboBox->count() - 1);
}
void EventEditor::on_browseFileButton_clicked()
{
if(!m_variant)
return;
QString r = QFileDialog::getOpenFileName(this, tr("Browse Sound File..."),
m_basePath.canonicalPath(),
QString("Sound files (*.wav *.mp3 *.ogg *.flac;;All Files (*)")
);
if(!r.isEmpty())
{
ui->fileLineEdit->setText(m_basePath.relativeFilePath(r));
}
}