Repository navigation
Expand file tree
/
Copy patheditor_encountertemplate.cpp
More file actions
75 lines (67 loc) · 2.22 KB
/
Copy patheditor_encountertemplate.cpp
File metadata and controls
75 lines (67 loc) · 2.22 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
#include "editor_encountertemplate.h"
#include "ui_editor_encountertemplate.h"
#include <QMenu>
editor_EncounterTemplate::editor_EncounterTemplate(QWidget *parent)
: QWidget(parent), ui(new Ui::editor_EncounterTemplate)
{
ui->setupUi(this);
}
editor_EncounterTemplate::editor_EncounterTemplate(PathTrackerStruct* data, EncounterTemplate* encounter, QWidget *parent)
: QWidget(parent)
, ui(new Ui::editor_EncounterTemplate)
, m_data(data)
, m_encounter(encounter)
{
ui->setupUi(this);
PopulatePawnCombo();
RefreshPawnList();
ui->PawnList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->PawnList, &QListWidget::customContextMenuRequested,
this, &editor_EncounterTemplate::ShowPawnContextMenu);
}
editor_EncounterTemplate::~editor_EncounterTemplate()
{
delete ui;
}
void editor_EncounterTemplate::PopulatePawnCombo()
{
ui->PawnCombo->clear();
for (PawnTemplate* tmpl : m_data->allPawnTemplates())
ui->PawnCombo->addItem(tmpl->name, tmpl->id);
}
void editor_EncounterTemplate::RefreshPawnList()
{
ui->PawnList->clear();
if (!m_encounter) return;
for (const QString& id : m_encounter->pawnTemplateIds) {
PawnTemplate* tmpl = m_data->findPawnTemplate(id);
QString label = tmpl ? tmpl->name : id;
QListWidgetItem* item = new QListWidgetItem(label, ui->PawnList);
item->setData(Qt::UserRole, id);
}
}
void editor_EncounterTemplate::on_PawnAddButton_clicked()
{
if (!m_encounter) return;
QString id = ui->PawnCombo->currentData().toString();
if (id.isEmpty()) return;
m_encounter->addPawnTemplate(id);
RefreshPawnList();
emit Save();
}
void editor_EncounterTemplate::ShowPawnContextMenu(const QPoint& pos)
{
QListWidgetItem* item = ui->PawnList->itemAt(pos);
if (!item) return;
int row = ui->PawnList->row(item);
QMenu menu(this);
QAction* removeAction = menu.addAction("Remove Pawn");
connect(removeAction, &QAction::triggered, [this, row, item]() {
if (row >= 0 && row < m_encounter->pawnTemplateIds.size()) {
m_encounter->pawnTemplateIds.removeAt(row);
delete item;
emit Save();
}
});
menu.exec(ui->PawnList->mapToGlobal(pos));
}