Crossfire Server, Trunk
CREPrePostList.cpp
Go to the documentation of this file.
1
/*
2
* Crossfire -- cooperative multi-player graphical RPG and adventure game
3
*
4
* Copyright (c) 2022 the Crossfire Development Team
5
*
6
* Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7
* welcome to redistribute it under certain conditions. For details, please
8
* see COPYING and LICENSE.
9
*
10
* The authors can be reached via e-mail at <crossfire@metalforge.org>.
11
*/
12
13
#include <QtWidgets>
14
#include "
CREPrePostList.h
"
15
#include "
CREPrePostConditionDelegate.h
"
16
17
PrePostWidget::PrePostWidget
(QWidget* parent,
Mode
mode,
const
MessageManager
*
manager
) : QWidget(parent), myMode(mode)
18
{
19
myList
=
new
QListWidget(parent);
20
myList
->setItemDelegate(
new
CREPrePostSingleConditionDelegate
(
myList
, mode,
manager
));
21
connect
(
myList
, &QListWidget::itemChanged,
this
, [&] () { emit
dataModified
(); });
22
23
QPushButton* addCondition =
new
QPushButton(tr(
"add"
),
this
);
24
connect
(addCondition, SIGNAL(clicked(
bool
)),
this
, SLOT(
onAddCondition
(
bool
)));
25
26
QPushButton* delCondition =
new
QPushButton(tr(
"delete"
),
this
);
27
connect
(delCondition, SIGNAL(clicked(
bool
)),
this
, SLOT(
onDeleteCondition
(
bool
)));
28
29
QPushButton* reset =
new
QPushButton(tr(
"reset changes"
),
this
);
30
connect
(reset, SIGNAL(clicked(
bool
)),
this
, SLOT(
onReset
(
bool
)));
31
32
QHBoxLayout* buttons =
new
QHBoxLayout();
33
buttons->addWidget(addCondition);
34
buttons->addWidget(delCondition);
35
buttons->addWidget(reset);
36
37
QVBoxLayout*
l
=
new
QVBoxLayout(
this
);
38
l
->addWidget(
myList
);
39
l
->addLayout(buttons);
40
setLayout(
l
);
41
}
42
43
QList<QStringList>
PrePostWidget::data
()
const
44
{
45
QList<QStringList>
value
;
46
for
(
int
i = 0; i <
myList
->count(); i++)
47
{
48
QListWidgetItem* wi =
myList
->item(i);
49
QStringList
data
= wi->data(Qt::UserRole).value<QStringList>();
50
if
(
myMode
==
SetWhen
)
51
data
.pop_front();
52
value
.append(
data
);
53
}
54
return
value
;
55
}
56
57
void
PrePostWidget::addItem
(
const
QStringList &
item
)
58
{
59
QStringList display(
item
);
60
if
(
myMode
==
SetWhen
)
61
display.pop_front();
62
QListWidgetItem* wi =
new
QListWidgetItem(display.join(
" "
));
63
wi->setData(Qt::UserRole, QVariant::fromValue(
item
));
64
wi->setFlags(wi->flags() | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
65
myList
->addItem(wi);
66
emit
dataModified
();
67
}
68
69
void
PrePostWidget::setData
(
const
QList<QStringList>&
data
)
70
{
71
myList
->clear();
72
for
(QStringList
item
:
data
)
73
{
74
if
(
myMode
==
SetWhen
&& !
item
.empty() &&
item
[0] !=
"quest"
)
75
item
.push_front(
"quest"
);
76
addItem
(
item
);
77
}
78
myOriginal
=
data
;
79
}
80
81
void
PrePostWidget::onAddCondition
(
bool
)
82
{
83
QStringList
item
;
84
item
<<
"quest"
;
85
addItem
(
item
);
86
myList
->setCurrentRow(
myList
->count() - 1);
87
myList
->edit(
myList
->currentIndex());
88
emit
dataModified
();
89
}
90
91
void
PrePostWidget::onDeleteCondition
(
bool
)
92
{
93
if
(
myList
->currentRow() == -1)
94
return
;
95
96
delete
myList
->takeItem(
myList
->currentRow());
97
emit
dataModified
();
98
}
99
100
void
PrePostWidget::onReset
(
bool
)
101
{
102
if
(QMessageBox::question(
this
,
"Confirm reset"
,
"Reset the conditions to their initial values, losing all changes?"
) != QMessageBox::StandardButton::Yes)
103
return
;
104
setData
(
myOriginal
);
105
emit
dataModified
();
106
}
107
108
CREPrePostList::CREPrePostList
(QWidget* parent,
PrePostWidget::Mode
mode,
const
MessageManager
*
manager
) : QDialog(parent) {
109
setModal(
true
);
110
switch
(mode) {
111
case
PrePostWidget::PreConditions
:
112
setWindowTitle(tr(
"Message pre-conditions"
));
113
break
;
114
case
PrePostWidget::PostConditions
:
115
setWindowTitle(tr(
"Message post-conditions"
));
116
break
;
117
case
PrePostWidget::SetWhen
:
118
setWindowTitle(tr(
"Step set when conditions are met"
));
119
break
;
120
}
121
122
auto
layout
=
new
QVBoxLayout(
this
);
123
myWidget
=
new
PrePostWidget
(
this
, mode,
manager
);
124
layout
->addWidget(
myWidget
);
125
}
PrePostWidget::onDeleteCondition
void onDeleteCondition(bool)
Definition:
CREPrePostList.cpp:91
PrePostWidget::myList
QListWidget * myList
Definition:
CREPrePostList.h:44
banquet.l
l
Definition:
banquet.py:164
layout
Definition:
main.cpp:84
CREPrePostList.h
PrePostWidget::PostConditions
@ PostConditions
Definition:
CREPrePostList.h:27
PrePostWidget::onReset
void onReset(bool)
Definition:
CREPrePostList.cpp:100
CREPrePostList::myWidget
PrePostWidget * myWidget
Definition:
CREPrePostList.h:64
PrePostWidget::dataModified
void dataModified()
PrePostWidget::SetWhen
@ SetWhen
Definition:
CREPrePostList.h:27
PrePostWidget::PreConditions
@ PreConditions
Definition:
CREPrePostList.h:27
PrePostWidget
Definition:
CREPrePostList.h:21
CREPrePostList::CREPrePostList
CREPrePostList(QWidget *parent, PrePostWidget::Mode mode, const MessageManager *manager)
Definition:
CREPrePostList.cpp:108
navar-midane_time.data
data
Definition:
navar-midane_time.py:11
PrePostWidget::myOriginal
QList< QStringList > myOriginal
Definition:
CREPrePostList.h:45
PrePostWidget::PrePostWidget
PrePostWidget(QWidget *parent, Mode mode, const MessageManager *manager)
Definition:
CREPrePostList.cpp:17
MessageManager
Definition:
MessageManager.h:25
PrePostWidget::onAddCondition
void onAddCondition(bool)
Definition:
CREPrePostList.cpp:81
item
Definition:
item.py:1
autojail.value
value
Definition:
autojail.py:6
PrePostWidget::Mode
Mode
Definition:
CREPrePostList.h:27
PrePostWidget::setData
void setData(const QList< QStringList > &data)
Definition:
CREPrePostList.cpp:69
PrePostWidget::data
QList< QStringList > data
Definition:
CREPrePostList.h:24
CREPrePostConditionDelegate.h
say.item
dictionary item
Definition:
say.py:149
connect
Definition:
connect.py:1
PrePostWidget::myMode
Mode myMode
Definition:
CREPrePostList.h:46
manager
static AssetsManager * manager
Definition:
assets.cpp:60
PrePostWidget::addItem
void addItem(const QStringList &item)
Definition:
CREPrePostList.cpp:57
CREPrePostSingleConditionDelegate
Definition:
CREPrePostConditionDelegate.h:23
crossfire-crossfire-server
utils
cre
CREPrePostList.cpp
Generated by
1.8.17