Crossfire Server, Trunk  R20513
CREQuestPanel.cpp
Go to the documentation of this file.
1 #include "CREQuestPanel.h"
2 #include "CRERegionPanel.h"
3 #include "Quest.h"
4 #include "QuestManager.h"
5 #include "CREQuestItemModel.h"
7 #include "CRETreeItemQuest.h"
8 #include "CREMapInformation.h"
9 #include "MessageManager.h"
10 #include "CREMessagePanel.h"
11 #include "MessageFile.h"
12 
14 {
15  Q_ASSERT(manager);
16  Q_ASSERT(messageManager);
17  myQuestManager = manager;
18  myMessageManager = messageManager;
19 
20  QVBoxLayout* main = new QVBoxLayout(this);
21  QTabWidget* tab = new QTabWidget(this);
22  main->addWidget(tab);
23 
24  QWidget* details = new QWidget(this);
25  tab->addTab(details, tr("Details"));
26 
27  QGridLayout* layout = new QGridLayout(details);
28 
29  int line = 1;
30  layout->addWidget(new QLabel(tr("Code:"), this), line, 1);
31  myCode = new QLineEdit();
32  layout->addWidget(myCode, line++, 2);
33 
34  layout->addWidget(new QLabel(tr("Title:"), this), line, 1);
35  myTitle = new QLineEdit();
36  layout->addWidget(myTitle, line++, 2);
37 
38  layout->addWidget(new QLabel(tr("Face:"), this), line, 1);
39  myFace = new QLineEdit();
40  layout->addWidget(myFace, line++, 2);
41 
42  myCanRestart = new QCheckBox(tr("this quest can be done multiple times"));
43  layout->addWidget(myCanRestart, line++, 1, 1, 2);
44 
45  layout->addWidget(new QLabel(tr("Parent:"), this), line, 1);
46  myParent = new QComboBox(this);
47  layout->addWidget(myParent, line++, 2);
48  myParent->addItem(tr("(none)"));
49 
50  QStringList codes;
51  foreach(const Quest* quest, manager->quests())
52  {
53  codes.append(quest->code());
54  }
55  codes.sort();
56  myParent->addItems(codes);
57 
58  layout->addWidget(new QLabel(tr("Quest file:"), this), line, 1);
59  myFile = new QComboBox(this);
60  layout->addWidget(myFile, line++, 2);
61 
62  myFile->setInsertPolicy(QComboBox::InsertAlphabetically);
63  myFile->setEditable(true);
64  myFile->addItem("");
65  QStringList files = myQuestManager->getFiles();
66  files.sort();
67  myFile->addItems(files);
68 
69  layout->addWidget(new QLabel(tr("Description:"), this), line++, 1, 1, 2);
70  myDescription = new QTextEdit();
71  layout->addWidget(myDescription, line++, 1, 1, 2);
72 
73 
74  layout->addWidget(new QLabel(tr("Steps:"), this), line++, 1, 1, 2);
75 
76  myStepsModel = new CREQuestItemModel(this);
78  mySteps = new QTreeView(this);
79  mySteps->setRootIsDecorated(false);
80  mySteps->setWordWrap(true);
81  mySteps->setModel(myStepsModel);
82  mySteps->setItemDelegateForColumn(1, delegate);
83  mySteps->setItemDelegateForColumn(3, delegate);
84  mySteps->setSelectionMode(QAbstractItemView::SingleSelection);
85 
86  layout->addWidget(mySteps, line++, 1, 1, 2);
87 
88  QHBoxLayout* buttons = new QHBoxLayout();
89 
90  QPushButton* add = new QPushButton(tr("add step"), this);
91  connect(add, SIGNAL(clicked(bool)), myStepsModel, SLOT(addStep(bool)));
92  buttons->addWidget(add);
93  QPushButton* del = new QPushButton(tr("remove step"), this);
94  connect(del, SIGNAL(clicked(bool)), this, SLOT(deleteStep(bool)));
95  buttons->addWidget(del);
96 
97  QPushButton* up = new QPushButton(tr("move up"), this);
98  connect(up, SIGNAL(clicked(bool)), this, SLOT(moveUp(bool)));
99  buttons->addWidget(up);
100  QPushButton* down = new QPushButton(tr("move down"), this);
101  connect(down, SIGNAL(clicked(bool)), this, SLOT(moveDown(bool)));
102  buttons->addWidget(down);
103 
104  layout->addLayout(buttons, line++, 1, 1, 2);
105 
106  myUse = new QTreeWidget(this);
107  tab->addTab(myUse, tr("Use"));
108  myUse->setHeaderLabel(tr("Used by..."));
109 
110  myQuest = NULL;
111  myCurrentStep = NULL;
112 }
113 
115 {
116 }
117 
119 {
120  myQuest = quest;
121  myCurrentStep = NULL;
122 
123  myCode->setText(quest->code());
124  myTitle->setText(quest->title());
125  myFace->setText(quest->face());
126  myCanRestart->setChecked(quest->canRestart());
127  myDescription->setText(quest->description());
128 
129  QString file = myQuestManager->getQuestFile(myQuest);
130  myFile->setEditText(file);
131  myFile->setEnabled(file.isEmpty());
132 
133  if (quest->parent() != NULL)
134  {
135  int idx = myParent->findText(quest->parent()->code());
136  if (idx != -1)
137  myParent->setCurrentIndex(idx);
138  }
139  else
140  myParent->setCurrentIndex(0);
141 
142  displaySteps();
143 
144  myUse->clear();
145  QTreeWidgetItem* root = NULL;
146  if (quest->maps().length() > 0)
147  {
148  root = new QTreeWidgetItem(myUse, QStringList(tr("Maps")));
149  root->setExpanded(true);
150  foreach(CREMapInformation* map, quest->maps())
151  {
152  new QTreeWidgetItem(root, QStringList(map->path()));
153  }
154  root = NULL;
155  }
156 
157  foreach(MessageFile* message, myMessageManager->messages())
158  {
159  bool got = false;
160  foreach(MessageRule* rule, message->rules())
161  {
162  QList<QStringList> conditions = rule->preconditions();
163  conditions.append(rule->postconditions());
164  foreach(QStringList list, conditions)
165  {
166  if (list.size() > 1 && (list[0] == "quest" || list[0] == "questdone") && list[1] == quest->code())
167  {
168  if (root == NULL)
169  {
170  root = new QTreeWidgetItem(myUse, QStringList(tr("Messages")));
171  root->setExpanded(true);
172  }
173 
174  new QTreeWidgetItem(root, QStringList(message->path()));
175  got = true;
176  break;
177  }
178  }
179 
180  if (got)
181  break;
182  }
183  }
184 }
185 
187 {
188  if (!myQuest)
189  return;
190 
191  myQuest->setCode(myCode->text());
192  myQuest->setTitle(myTitle->text());
193  myQuest->setFace(myFace->text());
194  myQuest->setRestart(myCanRestart->isChecked());
195  myQuest->setDescription(myDescription->toPlainText());
196  if (myQuestManager->getQuestFile(myQuest).isEmpty())
197  myQuestManager->setQuestFile(myQuest, myFile->currentText());
198  if (myParent->currentIndex() == 0)
199  {
200  myQuest->setParent(NULL);
201  }
202  else
204 }
205 
207 {
209 }
210 
212 {
213  if (myQuest == NULL)
214  return;
215 
216  if (!mySteps->currentIndex().isValid())
217  return;
218 
219  myStepsModel->removeRow(mySteps->currentIndex().row());
220 }
221 
223 {
224  if (myQuest == NULL)
225  return;
226 
227  if (!mySteps->currentIndex().isValid())
228  return;
229 
230  myStepsModel->moveUp(mySteps->currentIndex().row());
231 }
232 
234 {
235  if (myQuest == NULL)
236  return;
237 
238  if (!mySteps->currentIndex().isValid())
239  return;
240 
241  myStepsModel->moveDown(mySteps->currentIndex().row());
242 }
QTreeWidget * myUse
Definition: CREQuestPanel.h:42
CREQuestPanel(QuestManager *manager, MessageManager *messageManager)
void setRestart(bool restart)
Definition: Quest.cpp:130
QList< MessageFile * > & messages()
QComboBox * myParent
Definition: CREQuestPanel.h:38
const QList< QStringList > & postconditions() const
Definition: MessageFile.cpp:66
const Quest * parent() const
Definition: Quest.cpp:166
const QList< QStringList > & preconditions() const
Definition: MessageFile.cpp:56
Definition: Quest.h:32
const QString & code() const
Definition: Quest.cpp:63
QString getQuestFile(Quest *quest) const
void setTitle(const QString &title)
Definition: Quest.cpp:81
QuestManager * myQuestManager
Definition: CREQuestPanel.h:29
void moveDown(bool)
virtual void setItem(Quest *quest)
QTreeView * mySteps
Definition: CREQuestPanel.h:41
const QString & face() const
Definition: Quest.cpp:89
int main(int argc, char *argv[])
Definition: main.c:159
const QString & description() const
Definition: Quest.cpp:112
CREQuestItemModel * myStepsModel
Definition: CREQuestPanel.h:40
QCheckBox * myCanRestart
Definition: CREQuestPanel.h:37
QList< MessageRule * > & rules()
const QString & title() const
Definition: Quest.cpp:76
Quest * findByCode(const QString &code)
void setDescription(const QString &description)
Definition: Quest.cpp:117
void setQuestFile(Quest *quest, const QString &file)
static char root[500]
Path to store generated files.
Definition: mapper.c:365
MessageManager * myMessageManager
Definition: CREQuestPanel.h:30
QLineEdit * myFace
Definition: CREQuestPanel.h:35
QLineEdit * myTitle
Definition: CREQuestPanel.h:34
void moveUp(bool)
QLineEdit * myCode
Definition: CREQuestPanel.h:33
bool canRestart() const
Definition: Quest.cpp:125
void setCode(const QString &code)
Definition: Quest.cpp:68
QuestStep * myCurrentStep
Definition: CREQuestPanel.h:32
void setParent(Quest *parent)
Definition: Quest.cpp:171
QComboBox * myFile
Definition: CREQuestPanel.h:36
QTextEdit * myDescription
Definition: CREQuestPanel.h:39
QList< const Quest * > quests() const
Quest * myQuest
Definition: CREQuestPanel.h:31
QStringList getFiles() const
void deleteStep(bool)
virtual ~CREQuestPanel()
void setQuest(Quest *quest)
const QString & path() const
virtual void commitData()
void moveDown(int step)
void setFace(const QString &face)
Definition: Quest.cpp:94
Definition: main.c:88
QList< CREMapInformation * > & maps()
Definition: Quest.cpp:180