Crossfire Server, Trunk
CREMessagePanel.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 "CREMessagePanel.h"
15 #include "CREFilterDefinition.h"
16 #include "MessageFile.h"
17 #include "CREMapInformation.h"
18 #include "MessageManager.h"
19 #include "CREMessageItemModel.h"
23 #include "CREStringListDelegate.h"
24 
26 {
27  Q_ASSERT(manager != NULL);
29 
30  addTab(tr("Details"));
31 
32  myPath = addLineEdit(tr("Path:"), "path", false);
33  addLineEdit(tr("Location:"), "location", false);
34 
35  myModel = new CREMessageItemModel(this);
36  myRules = new QTableView();
37  myRules->setWordWrap(true);
38  myRules->setModel(myModel);
39  myRules->setSelectionMode(QAbstractItemView::SingleSelection);
40  myRules->setSelectionBehavior(QAbstractItemView::SelectRows);
41  myRules->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
42  myRules->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
43 
44  myRules->setItemDelegateForColumn(0, new CREMultilineItemDelegate(myRules, true, true));
46  myRules->setItemDelegateForColumn(2, new CREPlayerRepliesDelegate(myRules));
47  myRules->setItemDelegateForColumn(3, new CREStringListDelegate(myRules));
49  myRules->setItemDelegateForColumn(5, new CREMultilineItemDelegate(myRules, true, true));
50  myRules->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
51 
52  connect(myRules->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(currentRowChanged(const QModelIndex&, const QModelIndex&)));
53  addWidget(tr("Message rules (blue: uses token set by current rule as pre-condition, red: rule that sets token for pre-condition of current rule)"), myRules, false, nullptr, nullptr);
54 
55  QHBoxLayout* buttons = new QHBoxLayout();
56 
57  QPushButton* add = new QPushButton(tr("insert rule"), this);
58  buttons->addWidget(add);
59  connect(add, SIGNAL(clicked(bool)), this, SLOT(onAddRule(bool)));
60  QPushButton* remove = new QPushButton(tr("remove rule"), this);
61  buttons->addWidget(remove);
62  connect(remove, SIGNAL(clicked(bool)), this, SLOT(onDeleteRule(bool)));
63 
64  QPushButton* up = new QPushButton(tr("move up"), this);
65  buttons->addWidget(up);
66  connect(up, SIGNAL(clicked(bool)), this, SLOT(onMoveUp(bool)));
67  QPushButton* down = new QPushButton(tr("move down"), this);
68  buttons->addWidget(down);
69  connect(down, SIGNAL(clicked(bool)), this, SLOT(onMoveDown(bool)));
70 
71  QPushButton* copy = new QPushButton(tr("copy"), this);
72  buttons->addWidget(copy);
73  connect(copy, SIGNAL(clicked(bool)), this, SLOT(onDuplicate(bool)));
74 
75  QPushButton* reset = new QPushButton(tr("reset all changes"), this);
76  buttons->addWidget(reset);
77  connect(reset, SIGNAL(clicked(bool)), this, SLOT(onReset(bool)));
78 
79  myLayout->addLayout(buttons, myLayout->rowCount(), 0, 1, 2);
80 
81  addTab(tr("Use"));
82  myUse = new QTreeWidget(this);
83  addWidget(tr("Use"), myUse, false, nullptr, nullptr);
84 
85  myOriginal = nullptr;
86 }
87 
89 {
90  delete myOriginal;
91 }
92 
94 {
95  if (!myItem) {
96  return;
97  }
98  /* can only change path when new file is created */
99  myPath->setReadOnly(myItem->path() != "<new file>");
100 
101  /* so the change handler won't do anything */
102  auto save = myItem;
103  myItem = NULL;
104  myModel->setMessage(save);
105  myItem = save;
106 
107  myUse->clear();
108 
109  QTreeWidgetItem* root = NULL;
110  if (myItem->maps().length() > 0)
111  {
112  root = new QTreeWidgetItem(myUse, QStringList(tr("Maps")));
113  root->setExpanded(true);
114  foreach(CREMapInformation* map, myItem->maps())
115  {
116  new QTreeWidgetItem(root, QStringList(map->path()));
117  }
118  root = NULL;
119  }
120 
122  {
123  bool got = false;
124  foreach(MessageRule* rule, file->rules())
125  {
126  QStringList includes = rule->include();
127  foreach(QString include, includes)
128  {
129  if (include.isEmpty())
130  continue;
131 
132  if (!include.startsWith('/'))
133  {
134  int last = file->path().lastIndexOf(QDir::separator());
135  if (last == -1)
136  continue;
137  include = file->path().left(last + 1) + include;
138  }
139 
140  if (include == myItem->path())
141  {
142  if (root == NULL)
143  {
144  root = new QTreeWidgetItem(myUse, QStringList(tr("Messages")));
145  root->setExpanded(true);
146  }
147 
148  new QTreeWidgetItem(root, QStringList(file->path()));
149 
150  got = true;
151  break;
152  }
153 
154  if (got)
155  break;
156  }
157  }
158 
159  if (got)
160  break;
161  }
162 
163  delete myOriginal;
165 }
166 
167 void CREMessagePanel::currentRowChanged(const QModelIndex& current, const QModelIndex& /*previous*/)
168 {
170 }
171 
173 {
174  int row = myRules->selectionModel()->currentIndex().row() + 1;
175  myModel->insertRows(row, 1);
176  myRules->selectionModel()->select(myModel->index(row, 0, QModelIndex()), QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
177 }
178 
180 {
181  myModel->removeRows(myRules->selectionModel()->currentIndex().row(), 1);
182 }
183 
185 {
186  int index = myRules->currentIndex().row();
187  if (index <= 0 || index >= myItem->rules().size())
188  return;
189 
190  myModel->moveUpDown(index, true);
191  myRules->setCurrentIndex(myModel->index(index - 1, 0, QModelIndex()));
192 }
193 
195 {
196  int index = myRules->currentIndex().row();
197  if (index < 0 || index >= myItem->rules().size() - 1)
198  return;
199 
200  myModel->moveUpDown(index, false);
201  myRules->setCurrentIndex(myModel->index(index + 1, 0, QModelIndex()));
202 }
203 
205 {
206  int index = myRules->currentIndex().row();
207  if (index < 0 || index >= myItem->rules().size())
208  return;
209 
211  myRules->setCurrentIndex(myModel->index(index + 1, 0, QModelIndex()));
212 }
213 
215 {
216  if (!myItem)
217  return;
218  if (QMessageBox::question(this, "Confirm reset", "Reset message to its initial values?") != QMessageBox::StandardButton::Yes)
219  return;
220 
222  updateItem();
223 }
MessageFile::duplicate
MessageFile * duplicate() const
Definition: MessageFile.cpp:137
MessageFile.h
CREMessageItemModel
Definition: CREMessageItemModel.h:26
CREMessagePanel::myOriginal
MessageFile * myOriginal
Definition: CREMessagePanel.h:43
CREMultilineItemDelegate.h
MessageFile::rules
QList< MessageRule * > & rules()
Definition: MessageFile.cpp:266
sunnista.got
def got
Definition: sunnista.py:87
MessageManager::messages
QList< MessageFile * > & messages()
Definition: MessageManager.cpp:51
CREPlayerRepliesDelegate.h
AssetWrapperPanel::myLayout
QGridLayout * myLayout
Definition: AssetWrapperPanel.h:56
CREMessageItemModel::setSelectedRule
void setSelectedRule(const QModelIndex &index)
Definition: CREMessageItemModel.cpp:32
root
static char root[500]
Definition: mapper.cpp:304
mad_mage_user.file
file
Definition: mad_mage_user.py:15
CREMessagePanel.h
CREMessageItemModel::moveUpDown
void moveUpDown(int row, bool up)
Definition: CREMessageItemModel.cpp:316
AssetWrapperPanel::addLineEdit
QLineEdit * addLineEdit(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:74
CREMessagePanel::CREMessagePanel
CREMessagePanel(const MessageManager *manager, QWidget *parent)
Definition: CREMessagePanel.cpp:25
CREMessagePanel::onAddRule
void onAddRule(bool)
Definition: CREMessagePanel.cpp:172
disinfect.map
map
Definition: disinfect.py:4
CREMessagePanel::myModel
CREMessageItemModel * myModel
Definition: CREMessagePanel.h:46
CREMessageItemModel::setMessage
void setMessage(MessageFile *message)
Definition: CREMessageItemModel.cpp:25
CREMessagePanel::myUse
QTreeWidget * myUse
Definition: CREMessagePanel.h:48
CREMessagePanel::myRules
QTableView * myRules
Definition: CREMessagePanel.h:45
AssetSWrapperPanel< MessageFile >::myItem
MessageFile * myItem
Definition: AssetWrapperPanel.h:126
MessageFile::path
QString path
Definition: MessageFile.h:71
CREMessagePanel::updateItem
virtual void updateItem() override
Definition: CREMessagePanel.cpp:93
buttons
TIPS on SURVIVING Crossfire is populated with a wealth of different monsters These monsters can have varying immunities and attack types In some of them can be quite a bit smarter than others It will be important for new players to learn the abilities of different monsters and learn just how much it will take to kill them This section discusses how monsters can interact with players Most monsters in the game are out to mindlessly kill and destroy the players These monsters will help boost a player s after he kills them When fighting a large amount of monsters in a single attempt to find a narrower hallway so that you are not being attacked from all sides Charging into a room full of Beholders for instance would not be open the door and fight them one at a time For there are several maps designed for them Find these areas and clear them out All throughout these a player can find signs and books which they can read by stepping onto them and hitting A to apply the book sign These messages will help the player to learn the system One more always keep an eye on your food If your food drops to your character will soon so BE CAREFUL ! NPCs Non Player Character are special monsters which have intelligence Players may be able to interact with these monsters to help solve puzzles and find items of interest To speak with a monster you suspect to be a simply move to an adjacent square to them and push the double ie Enter your and press< Return > You can also use say if you feel like typing a little extra Other NPCs may not speak to but display intelligence with their movement Some monsters can be and may attack the nearest of your enemies Others can be in that they follow you around and help you in your quest to kill enemies and find treasure SPECIAL ITEMS There are many special items which can be found in of these the most important may be the signs all a player must do is apply the handle In the case of buttons
Definition: survival-guide.txt:57
AssetSWrapperPanel
Definition: AssetWrapperPanel.h:113
AssetWrapperPanel::addTab
void addTab(const QString &title)
Definition: AssetWrapperPanel.cpp:36
MessageFile::maps
QList< CREMapInformation * > & maps()
Definition: MessageFile.cpp:271
CREPrePostConditionDelegate
Definition: CREPrePostConditionDelegate.h:47
CREMapInformation
Definition: CREMapInformation.h:27
PrePostWidget::PreConditions
@ PreConditions
Definition: CREPrePostList.h:27
CREMessageItemModel::removeRows
virtual bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Definition: CREMessageItemModel.cpp:297
CREPrePostConditionDelegate.h
CREMultilineItemDelegate
Definition: CREMultilineItemDelegate.h:19
CREMessagePanel::onDuplicate
void onDuplicate(bool)
Definition: CREMessagePanel.cpp:204
MessageFile
Definition: MessageFile.h:68
CREMessageItemModel::insertRows
virtual bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
Definition: CREMessageItemModel.cpp:280
CREMessagePanel::myMessageManager
const MessageManager * myMessageManager
Definition: CREMessagePanel.h:42
CREMessagePanel::~CREMessagePanel
virtual ~CREMessagePanel()
Definition: CREMessagePanel.cpp:88
npc_dialog.index
int index
Definition: npc_dialog.py:102
CREFilterDefinition.h
reset
Python Guilds Quick outline Add a guild(mapmakers) this is still a problem *after dropping the token to gain access to the stove a woodfloor now appears which is Toolshed Token(found in Guild_HQ) *Note also have multiple gates in place to protect players and items from the mana explosion drop x for Jewelers room *Jewelers room works just need to determine what x is drop x for Thaumaturgy room *Thaumaturgy room works just need to determine what x is drop gold dropping the Firestar named fearless allows access to but I suspect that the drop location of the chest is not as intended because the player is in the way once you enter the chest the exit back to the basement is things such as the message et al reside on teleporters which then transport items to the map as they are when the map is reset(which is normal)
CREStringListDelegate
Definition: CREStringListDelegate.h:21
CREMessagePanel::myPath
QLineEdit * myPath
Definition: CREMessagePanel.h:44
CREMessagePanel::currentRowChanged
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
Definition: CREMessagePanel.cpp:167
MessageManager
Definition: MessageManager.h:25
CREMessagePanel::onReset
void onReset(bool)
Definition: CREMessagePanel.cpp:214
CREStringListDelegate.h
CREMessageItemModel::duplicateRow
void duplicateRow(int row)
Definition: CREMessageItemModel.cpp:333
MessageRule
Definition: MessageFile.h:25
CREPlayerRepliesDelegate
Definition: CREPlayerRepliesDelegate.h:21
connect
Definition: connect.py:1
PrePostWidget::PostConditions
@ PostConditions
Definition: CREPrePostList.h:27
MessageFile::copy
void copy(const MessageFile *other)
Definition: MessageFile.cpp:147
replace.current
current
Definition: replace.py:64
npc_dialog.rule
rule
Definition: npc_dialog.py:108
AssetWrapperPanel::addWidget
T * addWidget(const QString &label, T *widget, bool sideBySide, const char *property, const char *widgetProperty)
Definition: AssetWrapperPanel.h:64
manager
static AssetsManager * manager
Definition: assets.cpp:60
CREMapInformation.h
CREMessageItemModel.h
CREMessageItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const override
Definition: CREMessageItemModel.cpp:143
CREMessagePanel::onMoveUp
void onMoveUp(bool)
Definition: CREMessagePanel.cpp:184
CREMessagePanel::onMoveDown
void onMoveDown(bool)
Definition: CREMessagePanel.cpp:194
CREMessagePanel::onDeleteRule
void onDeleteRule(bool)
Definition: CREMessagePanel.cpp:179
MessageManager.h