Crossfire Server, Trunk
CREQuestPanel.cpp
Go to the documentation of this file.
1 #include "CREQuestPanel.h"
2 #include "CRERegionPanel.h"
3 #include "CREQuestItemModel.h"
5 #include "CRETreeItemQuest.h"
7 #include "CREMapInformation.h"
8 #include "MessageManager.h"
9 #include "CREMessagePanel.h"
10 #include "MessageFile.h"
11 #include "assets.h"
12 #include "AssetsManager.h"
13 #include "FaceComboBox.h"
14 #include "ResourcesManager.h"
15 #include "CREPrePostList.h"
17 
18 CREQuestPanel::CREQuestPanel(CREMapInformationManager* mapManager, MessageManager* messageManager, ResourcesManager *resources, QWidget* parent) : CRETPanel(parent)
19 {
20  Q_ASSERT(mapManager);
21  Q_ASSERT(messageManager);
22  myMapManager = mapManager;
23  myMessageManager = messageManager;
24  myResources = resources;
25 
26  QVBoxLayout* main = new QVBoxLayout(this);
27  QTabWidget* tab = new QTabWidget(this);
28  main->addWidget(tab);
29 
30  QWidget* details = new QWidget(this);
31  tab->addTab(details, tr("Details"));
32 
33  QGridLayout* layout = new QGridLayout(details);
34 
35  int line = 1;
36  layout->addWidget(new QLabel(tr("Code:"), this), line, 1);
37  myCode = new QLineEdit();
38  layout->addWidget(myCode, line++, 2);
39 
40  layout->addWidget(new QLabel(tr("Title:"), this), line, 1);
41  myTitle = new QLineEdit();
42  layout->addWidget(myTitle, line++, 2);
43 
44  layout->addWidget(new QLabel(tr("Face:"), this), line, 1);
45  myFace = new FaceComboBox(this, true);
46  layout->addWidget(myFace, line++, 2);
47 
48  myCanRestart = new QCheckBox(tr("this quest can be done multiple times"));
49  layout->addWidget(myCanRestart, line++, 1, 1, 2);
50 
51  myIsSystem = new QCheckBox(tr("System quest, not listed to players"));
52  layout->addWidget(myIsSystem, line++, 1, 1, 2);
53 
54  layout->addWidget(new QLabel(tr("Parent:"), this), line, 1);
55  myParent = new QComboBox(this);
56  layout->addWidget(myParent, line++, 2);
57  myParent->addItem(tr("(none)"));
58 
59  QStringList codes;
60  getManager()->quests()->each([&] (auto quest) { codes.append(quest->quest_code); });
61  codes.sort();
62  myParent->addItems(codes);
63 
64  layout->addWidget(new QLabel(tr("Quest file:"), this), line, 1);
65  myFile = new QComboBox(this);
66  layout->addWidget(myFile, line++, 2);
67 
68  myFile->setInsertPolicy(QComboBox::InsertAlphabetically);
69  myFile->setEditable(true);
70  myFile->addItem("");
71  auto files = myResources->questOrigins();
72  for (auto file : files) {
73  myFile->addItem(file.first.data());
74  }
75 
76  QTabWidget *dc = new QTabWidget(details);
77  myDescription = new QTextEdit(this);
78  dc->addTab(myDescription, "Player description");
79  myComment = new QPlainTextEdit(this);
80  dc->addTab(myComment, "Developer description");
81 
82  layout->addWidget(dc, line++, 1, 1, 2);
83 
84  layout->addWidget(new QLabel(tr("Steps:"), this), line++, 1, 1, 2);
85 
86  myStepsModel = new CREQuestItemModel(this);
87  connect(myStepsModel, SIGNAL(questModified(quest_definition *)), resources, SLOT(questModified(quest_definition *)));
88  mySteps = new QTreeView(this);
89  mySteps->setRootIsDecorated(false);
90  mySteps->setWordWrap(true);
91  mySteps->setModel(myStepsModel);
92  mySteps->setItemDelegateForColumn(3, new CREPrePostConditionDelegate(mySteps, CREPrePostList::SetWhen, messageManager));
93  mySteps->setSelectionMode(QAbstractItemView::SingleSelection);
94 
95  layout->addWidget(mySteps, line++, 1, 1, 2);
96 
97  QHBoxLayout* buttons = new QHBoxLayout();
98 
99  QPushButton* add = new QPushButton(tr("add step"), this);
100  connect(add, SIGNAL(clicked(bool)), myStepsModel, SLOT(addStep(bool)));
101  buttons->addWidget(add);
102  QPushButton* del = new QPushButton(tr("remove step"), this);
103  connect(del, SIGNAL(clicked(bool)), this, SLOT(deleteStep(bool)));
104  buttons->addWidget(del);
105 
106  QPushButton* up = new QPushButton(tr("move up"), this);
107  connect(up, SIGNAL(clicked(bool)), this, SLOT(moveUp(bool)));
108  buttons->addWidget(up);
109  QPushButton* down = new QPushButton(tr("move down"), this);
110  connect(down, SIGNAL(clicked(bool)), this, SLOT(moveDown(bool)));
111  buttons->addWidget(down);
112 
113  layout->addLayout(buttons, line++, 1, 1, 2);
114 
115  myUse = new QTreeWidget(this);
116  tab->addTab(myUse, tr("Use"));
117  myUse->setHeaderLabel(tr("Used by..."));
118 
119  myQuest = NULL;
120  myCurrentStep = NULL;
121 }
122 
124 {
125 }
126 
128 {
129  myQuest = quest;
130  myCurrentStep = NULL;
131 
132  myCode->setText(quest->quest_code);
133  myTitle->setText(quest->quest_title);
134  myFace->setFace(quest->face);
135  myCanRestart->setChecked(quest->quest_restart);
136  myIsSystem->setChecked(quest->quest_is_system);
137  myDescription->setText(quest->quest_description);
138  myComment->setPlainText(quest->quest_comment);
139 
140  auto origin = myResources->originOfQuest(myQuest);
141  myFile->setEditText(QString::fromStdString(origin));
142  myFile->setEnabled(origin.empty());
143 
144  if (quest->parent)
145  {
146  int idx = myParent->findText(quest->parent->quest_code);
147  if (idx != -1)
148  myParent->setCurrentIndex(idx);
149  }
150  else
151  myParent->setCurrentIndex(0);
152 
153  displaySteps();
154 
155  myUse->clear();
156  QTreeWidgetItem* root = NULL;
158  if (!maps.empty())
159  {
160  root = new QTreeWidgetItem(myUse, QStringList(tr("Maps")));
161  root->setExpanded(true);
162  foreach(CREMapInformation* map, maps)
163  {
164  new QTreeWidgetItem(root, QStringList(map->path()));
165  }
166  root = NULL;
167  }
168 
170  {
171  bool got = false;
172  foreach(MessageRule* rule, message->rules())
173  {
174  QList<QStringList> conditions = rule->preconditions();
175  conditions.append(rule->postconditions());
176  foreach(QStringList list, conditions)
177  {
178  if (list.size() > 1 && (list[0] == "quest" || list[0] == "questdone") && list[1] == quest->quest_code)
179  {
180  if (root == NULL)
181  {
182  root = new QTreeWidgetItem(myUse, QStringList(tr("Messages")));
183  root->setExpanded(true);
184  }
185 
186  new QTreeWidgetItem(root, QStringList(message->path()));
187  got = true;
188  break;
189  }
190  }
191 
192  if (got)
193  break;
194  }
195  }
196 }
197 
199 {
200  if (!myQuest)
201  return;
202 
203  FREE_AND_COPY(myQuest->quest_code, myCode->text().toStdString().data());
204  FREE_AND_COPY(myQuest->quest_title, myTitle->text().toStdString().data());
205  myQuest->face = myFace->face();
206  myQuest->quest_restart = myCanRestart->isChecked();
207  myQuest->quest_is_system = myIsSystem->isChecked();
208  FREE_AND_COPY(myQuest->quest_description, myDescription->toPlainText().toStdString().data());
209  FREE_AND_COPY(myQuest->quest_comment, myComment->toPlainText().trimmed().toStdString().data());
210  if (myResources->originOfQuest(myQuest).empty() && !myFile->currentText().isEmpty()) {
211  myResources->assetDefined(myQuest, myFile->currentText().toStdString());
212  }
213  if (myParent->currentIndex() == 0)
214  {
215  myQuest->parent = NULL;
216  }
217  else
218  myQuest->parent = getManager()->quests()->get(myParent->currentText().toStdString());
219 
221 }
222 
224 {
226 }
227 
229 {
230  if (myQuest == NULL)
231  return;
232 
233  if (!mySteps->currentIndex().isValid())
234  return;
235 
236  myStepsModel->removeRow(mySteps->currentIndex().row());
237 }
238 
240 {
241  if (myQuest == NULL)
242  return;
243 
244  if (!mySteps->currentIndex().isValid())
245  return;
246 
247  myStepsModel->moveUp(mySteps->currentIndex().row());
248 }
249 
251 {
252  if (myQuest == NULL)
253  return;
254 
255  if (!mySteps->currentIndex().isValid())
256  return;
257 
258  myStepsModel->moveDown(mySteps->currentIndex().row());
259 }
CREQuestItemModel.h
CRETPanel
Definition: CREPanel.h:20
CREMessagePanel.h
CREQuestItemModel::moveUp
void moveUp(int step)
Definition: CREQuestItemModel.cpp:256
CREQuestPanel::myMapManager
CREMapInformationManager * myMapManager
Definition: CREQuestPanel.h:36
layout
Definition: main.c:85
maps
static std::unordered_map< std::string, mapzone * > maps
Definition: citylife.cpp:93
CREPrePostList.h
FaceComboBox
Definition: FaceComboBox.h:11
sunnista.got
def got
Definition: sunnista.py:87
CREQuestPanel::mySteps
QTreeView * mySteps
Definition: CREQuestPanel.h:51
MessageManager.h
ResourcesManager
Definition: ResourcesManager.h:28
AssetsManager.h
CREMapInformation.h
ResourcesManager::questModified
void questModified(quest_definition *quest)
Definition: ResourcesManager.cpp:177
CREQuestPanel::myMessageManager
MessageManager * myMessageManager
Definition: CREQuestPanel.h:37
CREQuestPanel::deleteStep
void deleteStep(bool)
Definition: CREQuestPanel.cpp:228
guildoracle.list
list
Definition: guildoracle.py:87
CREPrePostConditionDelegate
Definition: CREPrePostConditionDelegate.h:35
CREQuestPanel::~CREQuestPanel
virtual ~CREQuestPanel()
Definition: CREQuestPanel.cpp:123
quest_definition::quest_description
sstring quest_description
Definition: quest.h:45
root
static char root[500]
Definition: mapper.cpp:305
mad_mage_user.file
file
Definition: mad_mage_user.py:15
FaceComboBox::face
const Face * face() const
Definition: FaceComboBox.cpp:37
MessageManager::messages
QList< MessageFile * > & messages()
Definition: MessageManager.cpp:40
CREQuestPanel::myFace
FaceComboBox * myFace
Definition: CREQuestPanel.h:43
MessageFile
Definition: MessageFile.h:55
CRERegionPanel.h
quest_definition::quest_is_system
bool quest_is_system
Definition: quest.h:50
getManager
AssetsManager * getManager()
Definition: assets.cpp:329
CREQuestItemModel::setQuest
void setQuest(quest_definition *quest)
Definition: CREQuestItemModel.cpp:18
CREQuestPanel::CREQuestPanel
CREQuestPanel(CREMapInformationManager *mapManager, MessageManager *messageManager, ResourcesManager *resources, QWidget *parent)
Definition: CREQuestPanel.cpp:18
quest_definition::quest_title
sstring quest_title
Definition: quest.h:44
quest_definition::quest_comment
sstring quest_comment
Definition: quest.h:46
CREQuestPanel::setItem
virtual void setItem(quest_definition *quest) override
Definition: CREQuestPanel.cpp:127
CREMapInformation
Definition: CREMapInformation.h:13
quest
Definition: quest.py:1
is_valid_types_gen.line
line
Definition: is_valid_types_gen.py:34
main
main(int argc, char *argv)
Definition: land.c:277
disinfect.map
map
Definition: disinfect.py:4
CREQuestPanel::myQuest
quest_definition * myQuest
Definition: CREQuestPanel.h:39
CREQuestPanel::myResources
ResourcesManager * myResources
Definition: CREQuestPanel.h:38
quest_definition::face
const Face * face
Definition: quest.h:48
CREQuestPanel::myCode
QLineEdit * myCode
Definition: CREQuestPanel.h:41
CREQuestPanel::myIsSystem
QCheckBox * myIsSystem
Definition: CREQuestPanel.h:46
FaceComboBox::setFace
void setFace(const Face *face)
Definition: FaceComboBox.cpp:32
quest_definition::quest_code
sstring quest_code
Definition: quest.h:43
CREQuestPanel::myComment
QPlainTextEdit * myComment
Definition: CREQuestPanel.h:49
AssetsManager::quests
Quests * quests()
Definition: AssetsManager.h:71
quest_definition::parent
struct quest_definition * parent
Definition: quest.h:52
FREE_AND_COPY
#define FREE_AND_COPY(sv, nv)
Definition: global.h:202
ResourcesManager::assetDefined
virtual void assetDefined(const archt *arch, const std::string &filename) override
Definition: ResourcesManager.h:42
ResourcesManager::questOrigins
const std::map< std::string, std::set< const quest_definition * > > & questOrigins() const
Definition: ResourcesManager.h:48
CREQuestPanel.h
MessageManager
Definition: MessageManager.h:12
CREQuestPanel::myTitle
QLineEdit * myTitle
Definition: CREQuestPanel.h:42
CREQuestPanel::myCurrentStep
QuestStep * myCurrentStep
Definition: CREQuestPanel.h:40
AssetsCollection::get
T * get(const Key &name)
Definition: AssetsCollection.h:66
CREQuestPanel::myParent
QComboBox * myParent
Definition: CREQuestPanel.h:47
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
CREPrePostList::SetWhen
@ SetWhen
Definition: CREPrePostList.h:18
CREMapInformationManager.h
ResourcesManager.h
CREQuestPanel::myDescription
QTextEdit * myDescription
Definition: CREQuestPanel.h:48
diamondslots.message
string message
Definition: diamondslots.py:57
MessageFile.h
CREQuestPanel::moveDown
void moveDown(bool)
Definition: CREQuestPanel.cpp:250
CREMultilineItemDelegate.h
CREQuestItemModel
Definition: CREQuestItemModel.h:15
CREQuestPanel::myUse
QTreeWidget * myUse
Definition: CREQuestPanel.h:52
CRETreeItemQuest.h
quest_definition
Definition: quest.h:42
assets.h
CREQuestItemModel::moveDown
void moveDown(int step)
Definition: CREQuestItemModel.cpp:289
FaceComboBox.h
CREQuestPanel::moveUp
void moveUp(bool)
Definition: CREQuestPanel.cpp:239
CREQuestPanel::myFile
QComboBox * myFile
Definition: CREQuestPanel.h:44
CREMapInformationManager::getMapsForQuest
QList< CREMapInformation * > getMapsForQuest(const quest_definition *quest)
Definition: CREMapInformationManager.cpp:377
CREQuestPanel::displaySteps
void displaySteps()
Definition: CREQuestPanel.cpp:223
CREQuestPanel::myCanRestart
QCheckBox * myCanRestart
Definition: CREQuestPanel.h:45
CREPrePostConditionDelegate.h
connect
Definition: connect.py:1
quest_definition::quest_restart
int quest_restart
Definition: quest.h:47
CREMapInformationManager
Definition: CREMapInformationManager.h:16
CREQuestPanel::commitData
virtual void commitData() override
Definition: CREQuestPanel.cpp:198
npc_dialog.rule
rule
Definition: npc_dialog.py:108
ResourcesManager::originOfQuest
std::string originOfQuest(const quest_definition *quest) const
Definition: ResourcesManager.h:49
MessageRule
Definition: MessageFile.h:12
CREQuestPanel::myStepsModel
CREQuestItemModel * myStepsModel
Definition: CREQuestPanel.h:50