Crossfire Server, Trunk
CREQuestPanel.cpp
Go to the documentation of this file.
1 #include "CREQuestPanel.h"
2 #include "CREQuestItemModel.h"
5 #include "CREMapInformation.h"
6 #include "MessageManager.h"
7 #include "CREMessagePanel.h"
8 #include "MessageFile.h"
9 #include "assets.h"
10 #include "AssetsManager.h"
11 #include "FaceComboBox.h"
12 #include "ResourcesManager.h"
13 #include "CREPrePostList.h"
15 #include "assets/AssetModel.h"
16 #include "HelpManager.h"
17 
18 CREQuestPanel::CREQuestPanel(CREMapInformationManager* mapManager, MessageManager* messageManager, ResourcesManager *resources, AssetModel *model, 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  myCode->setReadOnly(true);
39  layout->addWidget(myCode, line++, 2);
40 
41  layout->addWidget(new QLabel(tr("Title:"), this), line, 1);
42  myTitle = new QLineEdit();
43  layout->addWidget(myTitle, line++, 2);
44 
45  layout->addWidget(new QLabel(tr("Face:"), this), line, 1);
46  myFace = new FaceComboBox(this, true);
47  layout->addWidget(myFace, line++, 2);
48 
49  myCanRestart = new QCheckBox(tr("This quest can be done multiple times"));
50  layout->addWidget(myCanRestart, line++, 1, 1, 2);
51 
52  myIsSystem = new QCheckBox(tr("System quest, not listed to players"));
53  layout->addWidget(myIsSystem, line++, 1, 1, 2);
54 
55  layout->addWidget(new QLabel(tr("Parent:"), this), line, 1);
56  myParent = new QComboBox(this);
57  layout->addWidget(myParent, line++, 2);
58  myParent->addItem(tr("(none)"));
59 
60  QStringList codes;
61  getManager()->quests()->each([&] (auto quest) { codes.append(quest->quest_code); });
62  codes.sort();
63  myParent->addItems(codes);
64 
65  layout->addWidget(new QLabel(tr("Quest file:"), this), line, 1);
66  myFile = new QComboBox(this);
67  layout->addWidget(myFile, line++, 2);
68 
69  myFile->setInsertPolicy(QComboBox::InsertAlphabetically);
70  myFile->setEditable(true);
71  myFile->addItem("");
72  auto files = myResources->questOrigins();
73  for (auto file : files) {
74  myFile->addItem(file.first.data());
75  }
76 
77  QTabWidget *dc = new QTabWidget(details);
78  myDescription = new QTextEdit(this);
79  dc->addTab(myDescription, "Player description");
80  myComment = new QPlainTextEdit(this);
81  dc->addTab(myComment, "Developer description");
82 
83  layout->addWidget(dc, line++, 1, 1, 2);
84 
85  layout->addWidget(new QLabel(tr("Steps:"), this), line++, 1, 1, 2);
86 
87  myStepsModel = new CREQuestItemModel(this);
88  connect(myStepsModel, SIGNAL(questModified(quest_definition *)), resources, SLOT(questModified(quest_definition *)));
89  mySteps = new QTreeView(this);
90  mySteps->setRootIsDecorated(false);
91  mySteps->setWordWrap(true);
92  mySteps->setModel(myStepsModel);
93  mySteps->setItemDelegateForColumn(3, new CREPrePostConditionDelegate(mySteps, CREPrePostList::SetWhen, messageManager));
94  mySteps->setSelectionMode(QAbstractItemView::SingleSelection);
95 
96  layout->addWidget(mySteps, line++, 1, 1, 2);
97 
98  QHBoxLayout* buttons = new QHBoxLayout();
99 
100  QPushButton* add = new QPushButton(tr("add step"), this);
101  connect(add, SIGNAL(clicked(bool)), myStepsModel, SLOT(addStep(bool)));
102  buttons->addWidget(add);
103  QPushButton* del = new QPushButton(tr("remove step"), this);
104  connect(del, SIGNAL(clicked(bool)), this, SLOT(deleteStep(bool)));
105  buttons->addWidget(del);
106 
107  QPushButton* up = new QPushButton(tr("move up"), this);
108  connect(up, SIGNAL(clicked(bool)), this, SLOT(moveUp(bool)));
109  buttons->addWidget(up);
110  QPushButton* down = new QPushButton(tr("move down"), this);
111  connect(down, SIGNAL(clicked(bool)), this, SLOT(moveDown(bool)));
112  buttons->addWidget(down);
113 
114  layout->addLayout(buttons, line++, 1, 1, 2);
115 
116  auto useView = new QTreeView(this);
117  tab->addTab(useView, tr("Use"));
118  myUse = new UseFilterAssetModel(this);
119  myUse->setSourceModel(model);
120  useView->setModel(myUse);
121 
122  myQuest = NULL;
123  myCurrentStep = NULL;
124 
125  HelpManager::setHelpId(this, "quests");
126 }
127 
129 {
130 }
131 
133 {
134  myQuest = quest;
135  myCurrentStep = NULL;
136 
137  myCode->setText(quest->quest_code);
138  myTitle->setText(quest->quest_title);
139  myFace->setFace(quest->face);
140  myCanRestart->setChecked(quest->quest_restart);
141  myIsSystem->setChecked(quest->quest_is_system);
142  myDescription->setText(quest->quest_description);
143  myComment->setPlainText(quest->quest_comment);
144 
145  auto origin = myResources->originOfQuest(myQuest);
146  myFile->setEditText(QString::fromStdString(origin));
147  myFile->setEnabled(origin.empty());
148 
149  if (quest->parent)
150  {
151  int idx = myParent->findText(quest->parent->quest_code);
152  if (idx != -1)
153  myParent->setCurrentIndex(idx);
154  }
155  else
156  myParent->setCurrentIndex(0);
157 
158  displaySteps();
159 
160  myUse->setFilter(myResources->wrap(quest, nullptr));
161 }
162 
164 {
165  if (!myQuest)
166  return;
167 
168  FREE_AND_COPY(myQuest->quest_code, myCode->text().toStdString().data());
169  FREE_AND_COPY(myQuest->quest_title, myTitle->text().toStdString().data());
170  myQuest->face = myFace->face();
171  myQuest->quest_restart = myCanRestart->isChecked();
172  myQuest->quest_is_system = myIsSystem->isChecked();
173  FREE_AND_COPY(myQuest->quest_description, myDescription->toPlainText().toStdString().data());
174  FREE_AND_COPY(myQuest->quest_comment, myComment->toPlainText().trimmed().toStdString().data());
175  if (myResources->originOfQuest(myQuest).empty() && !myFile->currentText().isEmpty()) {
176  myResources->assetDefined(myQuest, myFile->currentText().toStdString());
177  }
178  if (myParent->currentIndex() == 0)
179  {
180  myQuest->parent = NULL;
181  }
182  else
183  myQuest->parent = getManager()->quests()->get(myParent->currentText().toStdString());
184 
186 }
187 
189 {
191 }
192 
194 {
195  if (myQuest == NULL)
196  return;
197 
198  if (!mySteps->currentIndex().isValid())
199  return;
200 
201  myStepsModel->removeRow(mySteps->currentIndex().row());
202 }
203 
205 {
206  if (myQuest == NULL)
207  return;
208 
209  if (!mySteps->currentIndex().isValid())
210  return;
211 
212  myStepsModel->moveUp(mySteps->currentIndex().row());
213 }
214 
216 {
217  if (myQuest == NULL)
218  return;
219 
220  if (!mySteps->currentIndex().isValid())
221  return;
222 
223  myStepsModel->moveDown(mySteps->currentIndex().row());
224 }
CREQuestItemModel.h
CRETPanel
Definition: CREPanel.h:18
CREMessagePanel.h
CREQuestItemModel::moveUp
void moveUp(int step)
Definition: CREQuestItemModel.cpp:256
CREQuestPanel::myMapManager
CREMapInformationManager * myMapManager
Definition: CREQuestPanel.h:38
layout
Definition: main.c:85
CREPrePostList.h
FaceComboBox
Definition: FaceComboBox.h:11
CREQuestPanel::mySteps
QTreeView * mySteps
Definition: CREQuestPanel.h:53
MessageManager.h
ResourcesManager
Definition: ResourcesManager.h:67
AssetsManager.h
CREMapInformation.h
ResourcesManager::questModified
void questModified(quest_definition *quest)
Definition: ResourcesManager.cpp:189
CREQuestPanel::myMessageManager
MessageManager * myMessageManager
Definition: CREQuestPanel.h:39
CREQuestPanel::deleteStep
void deleteStep(bool)
Definition: CREQuestPanel.cpp:193
CREPrePostConditionDelegate
Definition: CREPrePostConditionDelegate.h:35
CREQuestPanel::~CREQuestPanel
virtual ~CREQuestPanel()
Definition: CREQuestPanel.cpp:128
quest_definition::quest_description
sstring quest_description
Definition: quest.h:45
ResourcesManager::wrap
ArchetypeWrapper * wrap(archt *arch, AssetWrapper *parent)
Definition: ResourcesManager.h:112
mad_mage_user.file
file
Definition: mad_mage_user.py:15
CREQuestPanel::myUse
UseFilterAssetModel * myUse
Definition: CREQuestPanel.h:54
CREQuestPanel::myFace
FaceComboBox * myFace
Definition: CREQuestPanel.h:45
quest_definition::quest_is_system
bool quest_is_system
Definition: quest.h:50
UseFilterAssetModel::setFilter
void setFilter(AssetWrapper *asset)
Definition: AssetModel.cpp:185
getManager
AssetsManager * getManager()
Definition: assets.cpp:333
CREQuestItemModel::setQuest
void setQuest(quest_definition *quest)
Definition: CREQuestItemModel.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:132
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
CREQuestPanel::myQuest
quest_definition * myQuest
Definition: CREQuestPanel.h:41
CREQuestPanel::myResources
ResourcesManager * myResources
Definition: CREQuestPanel.h:40
quest_definition::face
const Face * face
Definition: quest.h:48
CREQuestPanel::myCode
QLineEdit * myCode
Definition: CREQuestPanel.h:43
CREQuestPanel::myIsSystem
QCheckBox * myIsSystem
Definition: CREQuestPanel.h:48
HelpManager.h
FaceComboBox::setFace
void setFace(const Face *face)
Definition: FaceComboBox.cpp:33
quest_definition::quest_code
sstring quest_code
Definition: quest.h:43
UseFilterAssetModel
Definition: AssetModel.h:40
CREQuestPanel::myComment
QPlainTextEdit * myComment
Definition: CREQuestPanel.h:51
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:203
ResourcesManager::assetDefined
virtual void assetDefined(const archt *arch, const std::string &filename) override
Definition: ResourcesManager.h:88
ResourcesManager::questOrigins
const std::map< std::string, std::set< const quest_definition * > > & questOrigins() const
Definition: ResourcesManager.h:97
AssetModel
Definition: AssetModel.h:14
AssetModel.h
CREQuestPanel.h
MessageManager
Definition: MessageManager.h:13
CREQuestPanel::myTitle
QLineEdit * myTitle
Definition: CREQuestPanel.h:44
CREQuestPanel::myCurrentStep
QuestStep * myCurrentStep
Definition: CREQuestPanel.h:42
AssetsCollection::get
T * get(const Key &name)
Definition: AssetsCollection.h:66
CREQuestPanel::myParent
QComboBox * myParent
Definition: CREQuestPanel.h:49
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
CREPrePostList::SetWhen
@ SetWhen
Definition: CREPrePostList.h:18
CREMapInformationManager.h
HelpManager::setHelpId
static void setHelpId(QWidget *widget, const QString &id)
Definition: HelpManager.cpp:46
ResourcesManager.h
CREQuestPanel::myDescription
QTextEdit * myDescription
Definition: CREQuestPanel.h:50
MessageFile.h
CREQuestPanel::moveDown
void moveDown(bool)
Definition: CREQuestPanel.cpp:215
CREMultilineItemDelegate.h
CREQuestItemModel
Definition: CREQuestItemModel.h:15
quest_definition
Definition: quest.h:42
assets.h
CREQuestItemModel::moveDown
void moveDown(int step)
Definition: CREQuestItemModel.cpp:289
CREQuestPanel::CREQuestPanel
CREQuestPanel(CREMapInformationManager *mapManager, MessageManager *messageManager, ResourcesManager *resources, AssetModel *model, QWidget *parent)
Definition: CREQuestPanel.cpp:18
FaceComboBox::face
const Face face
Definition: FaceComboBox.h:15
FaceComboBox.h
CREQuestPanel::moveUp
void moveUp(bool)
Definition: CREQuestPanel.cpp:204
CREQuestPanel::myFile
QComboBox * myFile
Definition: CREQuestPanel.h:46
CREQuestPanel::displaySteps
void displaySteps()
Definition: CREQuestPanel.cpp:188
CREQuestPanel::myCanRestart
QCheckBox * myCanRestart
Definition: CREQuestPanel.h:47
CREPrePostConditionDelegate.h
connect
Definition: connect.py:1
quest_definition::quest_restart
int quest_restart
Definition: quest.h:47
CREMapInformationManager
Definition: CREMapInformationManager.h:17
CREQuestPanel::commitData
virtual void commitData() override
Definition: CREQuestPanel.cpp:163
ResourcesManager::originOfQuest
std::string originOfQuest(const quest_definition *quest) const
Definition: ResourcesManager.h:98
CREQuestPanel::myStepsModel
CREQuestItemModel * myStepsModel
Definition: CREQuestPanel.h:52