Добавил привязку действий к событиям
за баллы канала и за донаты можено можно выполнять списки действий, за каждое событие свой набор
This commit is contained in:
+140
-1
@@ -169,6 +169,11 @@ uGeneral::uGeneral(QWidget *parent)
|
||||
m_createChatDialog = new FCreateChat(db, this);
|
||||
|
||||
initializeNotificationSounds();
|
||||
|
||||
// connect(ui->cbDonateList, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &uGeneral::on_cbDonateList_currentIndexChanged);
|
||||
// connect(ui->btnLinksAdd, &QPushButton::clicked, this, &uGeneral::on_btnLinksAdd_clicked);
|
||||
// connect(ui->btnLinksDel, &QPushButton::clicked, this, &uGeneral::on_btnLinksDel_clicked);
|
||||
updateLinksList();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@@ -3294,6 +3299,7 @@ void uGeneral::on_btnCRGet_clicked()
|
||||
ui->sbCRCost->setValue(0);
|
||||
ui->btnCREdit->setEnabled(false);
|
||||
ui->btnCRDelete->setEnabled(false);
|
||||
updateDonateList();
|
||||
}
|
||||
|
||||
|
||||
@@ -3492,7 +3498,9 @@ void uGeneral::on_btnCRDelete_clicked()
|
||||
QMessageBox::critical(this, "Ошибка", "Не удалось удалить награду. Проверьте подключение к Twitch и права токена.");
|
||||
return;
|
||||
}
|
||||
|
||||
db->deleteLinksForEvent("reward", title);
|
||||
updateDonateList();
|
||||
updateLinksList();
|
||||
// 7. Уведомляем об успехе
|
||||
QMessageBox::information(this, "Успех", "Награда успешно удалена.");
|
||||
|
||||
@@ -3721,6 +3729,7 @@ void uGeneral::updateActionsTable()
|
||||
ui->sgActions->setItem(row, 0, typeItem);
|
||||
ui->sgActions->setItem(row, 1, new QTableWidgetItem(paramStr));
|
||||
}
|
||||
updateActionsList();
|
||||
}
|
||||
|
||||
void uGeneral::clearActionInputs()
|
||||
@@ -3745,6 +3754,7 @@ void uGeneral::updateDonationTriggersTable()
|
||||
// Сохраним id в UserRole первого столбца для удаления
|
||||
ui->sgDotateTriggers->item(row, 0)->setData(Qt::UserRole, t.id);
|
||||
}
|
||||
updateDonateList();
|
||||
}
|
||||
|
||||
void uGeneral::on_btnDonateAdd_clicked()
|
||||
@@ -3773,11 +3783,17 @@ void uGeneral::on_btnDonateDel_clicked()
|
||||
}
|
||||
|
||||
int id = ui->sgDotateTriggers->item(row, 0)->data(Qt::UserRole).toInt();
|
||||
QString name = ui->sgDotateTriggers->item(row, 0)->text(); // ← добавляем эту строку
|
||||
|
||||
if (QMessageBox::question(this, "Подтверждение", "Удалить выбранный триггер?") == QMessageBox::Yes) {
|
||||
m_donationManager->deleteTrigger(id);
|
||||
db->deleteLinksForEvent("donation", name);
|
||||
updateDonateList(); // обновляем список событий
|
||||
updateLinksList(); // обновляем список связей для текущего события
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void uGeneral::on_sgDotateTriggers_cellDoubleClicked(int row, int column)
|
||||
{
|
||||
Q_UNUSED(column);
|
||||
@@ -3786,3 +3802,126 @@ void uGeneral::on_sgDotateTriggers_cellDoubleClicked(int row, int column)
|
||||
ui->lineEdit->setText(name);
|
||||
ui->lineEdit_2->setText(rule);
|
||||
}
|
||||
|
||||
|
||||
void uGeneral::updateDonateList()
|
||||
{
|
||||
ui->cbDonateList->clear();
|
||||
|
||||
// Награды
|
||||
for (int row = 0; row < ui->sgCustomRewards->rowCount(); ++row) {
|
||||
QString name = ui->sgCustomRewards->item(row, 0)->text();
|
||||
QVariantMap data;
|
||||
data["type"] = "reward";
|
||||
data["name"] = name;
|
||||
ui->cbDonateList->addItem("Награды: " + name, data);
|
||||
}
|
||||
|
||||
// Триггеры донатов
|
||||
for (int row = 0; row < ui->sgDotateTriggers->rowCount(); ++row) {
|
||||
QString name = ui->sgDotateTriggers->item(row, 0)->text();
|
||||
QVariantMap data;
|
||||
data["type"] = "donation";
|
||||
data["name"] = name;
|
||||
ui->cbDonateList->addItem("Донаты: " + name, data);
|
||||
}
|
||||
}
|
||||
|
||||
void uGeneral::updateActionsList()
|
||||
{
|
||||
ui->cbActionsList->clear();
|
||||
auto actions = m_actionManager->getAllActions(); // предполагается, что такой метод есть
|
||||
for (const ActionData &a : actions) {
|
||||
QString typeStr;
|
||||
switch (a.type) {
|
||||
case 0: typeStr = "Нажатие"; break;
|
||||
case 1: typeStr = "Звук"; break;
|
||||
case 2: typeStr = "Уведомление"; break;
|
||||
default: typeStr = "Неизвестно";
|
||||
}
|
||||
QString param = (a.type == 0) ? a.keyCombination :
|
||||
(a.type == 1) ? QFileInfo(a.audioFile).fileName() : a.notificationTitle;
|
||||
ui->cbActionsList->addItem(typeStr + ": " + param, a.id);
|
||||
}
|
||||
}
|
||||
|
||||
void uGeneral::updateLinksList()
|
||||
{
|
||||
ui->lvLinks->clear();
|
||||
int idx = ui->cbDonateList->currentIndex();
|
||||
if (idx < 0) return;
|
||||
|
||||
QVariant data = ui->cbDonateList->itemData(idx);
|
||||
if (!data.isValid()) return;
|
||||
QVariantMap map = data.toMap();
|
||||
QString eventType = map["type"].toString();
|
||||
QString eventName = map["name"].toString();
|
||||
|
||||
QList<EventActionLink> links = db->getLinksForEvent(eventType, eventName);
|
||||
for (const EventActionLink &link : links) {
|
||||
ActionData action = m_actionManager->getAction(link.actionId);
|
||||
if (action.id < 0) continue;
|
||||
QString typeStr;
|
||||
switch (action.type) {
|
||||
case 0: typeStr = "Нажатие"; break;
|
||||
case 1: typeStr = "Звук"; break;
|
||||
case 2: typeStr = "Уведомление"; break;
|
||||
}
|
||||
QString param = (action.type == 0) ? action.keyCombination :
|
||||
(action.type == 1) ? QFileInfo(action.audioFile).fileName() : action.notificationTitle;
|
||||
QListWidgetItem *item = new QListWidgetItem(typeStr + ": " + param);
|
||||
item->setData(Qt::UserRole, link.id); // храним ID связи для удаления
|
||||
ui->lvLinks->addItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void uGeneral::on_cbDonateList_currentIndexChanged(int index)
|
||||
{
|
||||
Q_UNUSED(index);
|
||||
updateLinksList();
|
||||
}
|
||||
|
||||
void uGeneral::on_btnLinksAdd_clicked()
|
||||
{
|
||||
int eventIdx = ui->cbDonateList->currentIndex();
|
||||
int actionIdx = ui->cbActionsList->currentIndex();
|
||||
|
||||
if (eventIdx < 0 || actionIdx < 0) {
|
||||
QMessageBox::warning(this, "Ошибка", "Выберите событие и действие");
|
||||
return;
|
||||
}
|
||||
|
||||
QVariant eventData = ui->cbDonateList->itemData(eventIdx);
|
||||
if (!eventData.isValid()) return;
|
||||
QVariantMap map = eventData.toMap();
|
||||
QString eventType = map["type"].toString();
|
||||
QString eventName = map["name"].toString();
|
||||
int actionId = ui->cbActionsList->itemData(actionIdx).toInt();
|
||||
qDebug() << "НАЖАЛ КНОПКУ";
|
||||
if (!db->saveEventActionLink(eventType, eventName, actionId)) {
|
||||
QMessageBox::critical(this, "Ошибка", "Не удалось добавить связь:\n" + db->lastError());
|
||||
} else {
|
||||
updateLinksList();
|
||||
}
|
||||
}
|
||||
|
||||
void uGeneral::on_btnLinksDel_clicked()
|
||||
{
|
||||
int row = ui->lvLinks->currentRow();
|
||||
if (row < 0) {
|
||||
QMessageBox::warning(this, "Ошибка", "Выберите связь для удаления");
|
||||
return;
|
||||
}
|
||||
|
||||
QListWidgetItem *item = ui->lvLinks->item(row);
|
||||
int linkId = item->data(Qt::UserRole).toInt();
|
||||
|
||||
if (QMessageBox::question(this, "Подтверждение", "Удалить выбранную связь?") == QMessageBox::Yes) {
|
||||
if (!db->deleteEventActionLink(linkId)) {
|
||||
QMessageBox::critical(this, "Ошибка", "Не удалось удалить связь:\n" + db->lastError());
|
||||
} else {
|
||||
updateLinksList(); // ← перезагружаем список
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user