Crossfire Server, Trunk
AssetOriginAndCreationDialog.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 
14 #include "global.h"
15 
16 const char * const addTitles[] = {
17  QT_TRANSLATE_NOOP("AssetOriginAndCreationDialog", "Quest creation"),
18  QT_TRANSLATE_NOOP("AssetOriginAndCreationDialog", "Treasure creation"),
19 };
20 const char * const originTitles[] = {
21  QT_TRANSLATE_NOOP("AssetOriginAndCreationDialog", "Quest file definition"),
22  QT_TRANSLATE_NOOP("AssetOriginAndCreationDialog", "Treasure list file definition"),
23 };
24 const char * const names[] = {
25  QT_TRANSLATE_NOOP("AssetOriginAndCreationDialog", "quest"),
26  QT_TRANSLATE_NOOP("AssetOriginAndCreationDialog", "treasure"),
27 };
28 const char * const extensions[] = {
29  ".quests",
30  ".trs",
31 };
32 const bool isArch[] = {
33  false,
34  true,
35 };
36 
38  const std::vector<std::string> &origins, const std::vector<std::string> &assets) : myType(type), myAssets(assets) {
39  setModal(true);
40  setWindowTitle(tr(mode == CreateAsset ? addTitles[type] : originTitles[type]));
41  QGridLayout *layout = new QGridLayout(this);
42 
43  myRootDirectory = QString("%1/%2/").arg(settings.datadir, isArch[type] ? "arch" : settings.mapdir);
44 
45  layout->addWidget(new QLabel(tr("Code:")), 1, 0);
46  layout->addWidget(myCode = new QLineEdit(this), 1, 1, 1, 2);
47  if (mode == DefineOrigin) {
48  myCode->setReadOnly(true);
49  myCode->setText(code);
50  }
51 
52  QRadioButton *existing = new QRadioButton(tr("Add to an existing %1 file:").arg(names[type]), this);
53  layout->addWidget(existing, 2, 0);
54  myExistingFile = new QComboBox(this);
55  for (const auto &origin : origins) {
56  myExistingFile->addItem(QString::fromStdString(origin));
57  }
58  layout->addWidget(myExistingFile, 2, 1, 1, 2);
59 
60  QRadioButton *nqf = new QRadioButton(tr("Create a new %1 file:").arg(names[type]), this);
61  layout->addWidget(nqf, 3, 0);
62  myNewFile = new QLineEdit(this);
63  layout->addWidget(myNewFile, 3, 1);
64  auto browse = new QPushButton(tr("Browse..."), this);
65  layout->addWidget(browse, 3, 2);
66  connect(browse, &QAbstractButton::clicked, [this] () {
67  QFileDialog dlg;
68  if (myNewFile->text().isEmpty()) {
69  dlg.setDirectory(myRootDirectory);
70  } else {
71  dlg.selectFile(myNewFile->text());
72  }
73  dlg.setNameFilter(tr("%1 file (*%2);;All files (*.*)").arg(names[myType], extensions[myType]));
74  dlg.setAcceptMode(QFileDialog::AcceptSave);
75  dlg.setFileMode(QFileDialog::AnyFile);
76  if (dlg.exec() == QDialog::Accepted) {
77  myNewFile->setText(dlg.selectedFiles()[0]);
78  }
79  });
80 
81  connect(existing, &QAbstractButton::clicked, [this, browse] {
82  myExistingFile->setEnabled(true);
83  myNewFile->setEnabled(false);
84  browse->setEnabled(false);
85  });
86  connect(nqf, &QAbstractButton::clicked, [this, browse] {
87  myExistingFile->setEnabled(false);
88  myNewFile->setEnabled(true);
89  browse->setEnabled(true);
90  if (myNewFile->text().isEmpty()) {
91  browse->click();
92  }
93  });
94  existing->click();
95 
96  auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
97  connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
98  connect(buttons, &QDialogButtonBox::accepted, [this] () { validate(); });
99  layout->addWidget(buttons, 4, 0, 1, 3);
100 }
101 
103  if (!myCode->isReadOnly()) {
104  if (myCode->text().isEmpty()) {
105  QMessageBox::critical(this, tr("Empty required field"), tr("Please enter a code."));
106  myCode->setFocus();
107  return;
108  }
109  if (std::find(myAssets.cbegin(), myAssets.cend(), myCode->text().toStdString()) != myAssets.cend()) {
110  QMessageBox::critical(this, tr("Code already exists"), tr("The code you entered matches an existing code."));
111  myCode->setFocus();
112  return;
113  }
114  }
115  if (myNewFile->isEnabled()) {
116  if (myNewFile->text().isEmpty()) {
117  QMessageBox::critical(this, tr("Empty file"), tr("Please enter a file to define the %1 into.").arg(names[myType]));
118  myNewFile->setFocus();
119  return;
120  }
121  if (!myNewFile->text().startsWith(myRootDirectory)) {
122  if (QMessageBox::question(this, tr("File warning"), tr("The file seems to be outside the root directory for this kind of assets (%1).\nThis means the asset will not be visible to the game.\nAre you sure you want to use this file?").arg(myRootDirectory)) != QMessageBox::Yes) {
123  myNewFile->setFocus();
124  return;
125  }
126  }
127  if (!myNewFile->text().endsWith(extensions[myType])) {
128  if (QMessageBox::question(this, tr("File warning"), tr("The file does not end with '%1'.\nThis means the asset will not be visible to the game.\nAre you sure you want to use this file?").arg(extensions[myType])) != QMessageBox::Yes) {
129  myNewFile->setFocus();
130  return;
131  }
132  }
133  }
134  accept();
135 }
global.h
settings
struct Settings settings
Definition: init.cpp:139
isArch
const bool isArch[]
Definition: AssetOriginAndCreationDialog.cpp:32
layout
Definition: main.cpp:84
AssetOriginAndCreationDialog::AssetOriginAndCreationDialog
AssetOriginAndCreationDialog(Type type, Mode mode, const QString &code, const std::vector< std::string > &origins, const std::vector< std::string > &assets)
Definition: AssetOriginAndCreationDialog.cpp:37
AssetOriginAndCreationDialog::myRootDirectory
QString myRootDirectory
Definition: AssetOriginAndCreationDialog.h:42
originTitles
const char *const originTitles[]
Definition: AssetOriginAndCreationDialog.cpp:20
AssetOriginAndCreationDialog::myType
Type myType
Definition: AssetOriginAndCreationDialog.h:41
mode
linux kernel c mode(defun linux-c-mode() "C mode with adjusted defaults for use with the Linux kernel."(interactive)(c-mode)(c-set-style "K&R")(setq c-basic-offset 8))
AssetOriginAndCreationDialog::code
QString code() const
Definition: AssetOriginAndCreationDialog.h:37
AssetOriginAndCreationDialog::myCode
QLineEdit * myCode
Definition: AssetOriginAndCreationDialog.h:43
AssetOriginAndCreationDialog::Type
Type
Definition: AssetOriginAndCreationDialog.h:24
AssetOriginAndCreationDialog::validate
void validate()
Definition: AssetOriginAndCreationDialog.cpp:102
AssetOriginAndCreationDialog::myExistingFile
QComboBox * myExistingFile
Definition: AssetOriginAndCreationDialog.h:44
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
extensions
const char *const extensions[]
Definition: AssetOriginAndCreationDialog.cpp:28
names
const char *const names[]
Definition: AssetOriginAndCreationDialog.cpp:24
AssetOriginAndCreationDialog::Mode
Mode
Definition: AssetOriginAndCreationDialog.h:25
AssetOriginAndCreationDialog.h
AssetOriginAndCreationDialog::DefineOrigin
@ DefineOrigin
Definition: AssetOriginAndCreationDialog.h:25
Settings::mapdir
const char * mapdir
Definition: global.h:251
Settings::datadir
const char * datadir
Definition: global.h:248
addTitles
const char *const addTitles[]
Definition: AssetOriginAndCreationDialog.cpp:16
code
Crossfire Architecture the general intention is to enhance the enjoyability and playability of CF In this code
Definition: arch-handbook.txt:14
AssetOriginAndCreationDialog::CreateAsset
@ CreateAsset
Definition: AssetOriginAndCreationDialog.h:25
AssetOriginAndCreationDialog::myNewFile
QLineEdit * myNewFile
Definition: AssetOriginAndCreationDialog.h:45
connect
Definition: connect.py:1
AssetOriginAndCreationDialog::myAssets
std::vector< std::string > myAssets
Definition: AssetOriginAndCreationDialog.h:46
altar_valkyrie.accept
def accept(description)
Definition: altar_valkyrie.py:22
is_valid_types_gen.type
list type
Definition: is_valid_types_gen.py:25