Crossfire Server, Trunk
CREFacePanel.cpp
Go to the documentation of this file.
1 #include <Qt>
2 
3 extern "C" {
4 #include "global.h"
5 #include "face.h"
6 #include "image.h"
7 #include "quest.h"
8 }
9 
10 #include "CREFacePanel.h"
11 #include "CREUtils.h"
12 #include "CRESmoothFaceMaker.h"
13 #include "assets.h"
14 #include "AssetsManager.h"
15 #include "LicenseManager.h"
17 #include "Quests.h"
18 
20 static const char *const colorname[] = {
21  "black", /* 0 */
22  "white", /* 1 */
23  "blue", /* 2 */
24  "red", /* 3 */
25  "orange", /* 4 */
26  "light_blue", /* 5 */
27  "dark_orange", /* 6 */
28  "green", /* 7 */
29  "light_green", /* 8 */
30  "grey", /* 9 */
31  "brown", /* 10 */
32  "yellow", /* 11 */
33  "khaki" /* 12 */
34 };
35 
36 
38 {
39  myMaps = maps;
40  myFace = 0;
41 
42  QGridLayout* layout = new QGridLayout(this);
43 
44  myUsing = new QTreeWidget(this);
45  myUsing->setColumnCount(1);
46  myUsing->setHeaderLabel(tr("Used by"));
47  myUsing->setIconSize(QSize(32, 32));
48  layout->addWidget(myUsing, 1, 1, 3, 2);
49 
50  myLicenses = new QTreeWidget(this);
51  myLicenses->setColumnCount(2);
52  myLicenses->setHeaderLabels(QStringList(tr("License field")) << "Value");
53  myLicenses->setIconSize(QSize(32, 32));
54  myLicenses->setRootIsDecorated(false);
55  layout->addWidget(myLicenses, 1, 3, 3, 2);
56 
57  myColor = new QComboBox(this);
58  layout->addWidget(new QLabel("Magicmap color: "), 4, 1);
59  layout->addWidget(myColor, 4, 2, 1, 3);
60 
61  for(uint color = 0; color < sizeof(colorname) / sizeof(*colorname); color++)
62  myColor->addItem(colorname[color], color);
63 
64  myFile = new QLineEdit(this);
65  myFile->setReadOnly(true);
66  layout->addWidget(new QLabel("Original file: "), 5, 1);
67  layout->addWidget(myFile, 5, 2, 1, 3);
68 
69  mySave = new QPushButton(tr("Save face"));
70  layout->addWidget(mySave, 6, 1);
71  connect(mySave, SIGNAL(clicked(bool)), this, SLOT(saveClicked(bool)));
72 
73  QPushButton* smooth = new QPushButton(tr("Make smooth base"), this);
74  layout->addWidget(smooth, 6, 2, 1, 3);
75  connect(smooth, SIGNAL(clicked(bool)), this, SLOT(makeSmooth(bool)));
76 }
77 
78 static bool treasureContains(const treasure *t, const archetype *arch)
79 {
80  while (t)
81  {
82  if (t->item == arch)
83  return true;
84  if (t->name) {
85  auto other = getManager()->treasures()->find(t->name);
86  if (other && treasureContains(other->items, arch))
87  return true;
88  }
89  if (t->next_yes && treasureContains(t->next_yes, arch))
90  return true;
91  if (t->next_no && treasureContains(t->next_no, arch))
92  return true;
93  t = t->next;
94  }
95  return false;
96 }
97 
98 static bool isValidArchFlesh(const archetype *arch, const Face *fleshFace)
99 {
100  if (!arch || !arch->clone.randomitems || !fleshFace)
101  return false;
102 
103  std::vector<const archetype *> sources;
104  getManager()->archetypes()->each([&sources, &fleshFace] (const archetype *candidate) {
105  if (candidate->clone.face == fleshFace)
106  sources.push_back(candidate);
107  });
108 
109  for (auto source : sources)
110  {
111  if (treasureContains(arch->clone.randomitems->items, source))
112  return true;
113  }
114 
115  return false;
116 }
117 
118 void CREFacePanel::setItem(const Face* face)
119 {
120  Q_ASSERT(face);
121  myFace = face;
122 
123  myUsing->clear();
124 
125  QTreeWidgetItem* root = NULL;
126 
127  getManager()->archetypes()->each([this, &root] (archetype *arch)
128  {
129  auto key = object_get_value(&arch->clone, "identified_face");
130  if (arch->clone.face == myFace || (key && strcmp(myFace->name, key) == 0))
131  {
132  if (root == NULL)
133  {
135  myUsing->addTopLevelItem(root);
136  root->setExpanded(true);
137  }
139  }
140  });
141 
142  size_t pos = 0;
143  std::string name(face->name);
144  while ((pos = name.find('_', pos)) != std::string::npos)
145  {
146  auto arch = getManager()->archetypes()->find(name.substr(0, pos));
147  auto flesh = getManager()->faces()->find(name.substr(pos + 1));
148  if (isValidArchFlesh(arch, flesh))
149  {
150  if (root == NULL)
151  {
153  myUsing->addTopLevelItem(root);
154  root->setExpanded(true);
155  }
156  auto node = CREUtils::archetypeNode(arch, root);
157  node->setText(0, node->text(0) + " (flesh face)");
158  }
159  pos++;
160  }
161 
162  root = NULL;
163 
164  getManager()->animations()->each([this, &root] (Animations *anim)
165  {
166  for (int face = 0; face < anim->num_animations; face++)
167  {
168  if (anim->faces[face] == myFace)
169  {
170  if (root == NULL)
171  {
172  root = CREUtils::animationNode(NULL);
173  myUsing->addTopLevelItem(root);
174  root->setExpanded(true);
175  }
177  break;
178  }
179  }
180  });
181 
182  root = NULL;
183 
184  const artifactlist* list;
185  const artifact* arti;
186 
187  for (list = first_artifactlist; list; list = list->next)
188  {
189  for (arti = list->items; arti; arti = arti->next)
190  {
191  if (arti->item->face == myFace)
192  {
193  if (!root)
194  {
196  myUsing->addTopLevelItem(root);
197  root->setExpanded(true);
198  }
199 
201  }
202  }
203  }
204 
205  root = NULL;
206  getManager()->faces()->each([this, &root] (const Face *face) {
207  if (face->smoothface == myFace)
208  {
209  if (!root)
210  {
211  root = CREUtils::faceNode(NULL);
212  root->setText(0, root->text(0) + " (as smoothed face)");
213  myUsing->addTopLevelItem(root);
214  root->setExpanded(true);
215  }
216 
217  CREUtils::faceNode(face, root);
218  }
219  });
220 
221  root = NULL;
222  getManager()->messages()->each([this, &root] (const GeneralMessage *message)
223  {
224  if (myFace == message->face)
225  {
226  if (!root)
227  {
228  root = CREUtils::generalMessageNode();
229  myUsing->addTopLevelItem(root);
230  root->setExpanded(true);
231  }
232 
234  }
235  });
236 
237  root = NULL;
238  getManager()->quests()->each([&] (auto quest) {
239  if (myFace == quest->face)
240  {
241  if (!root)
242  {
243  root = CREUtils::questsNode();
244  myUsing->addTopLevelItem(root);
245  root->setExpanded(true);
246  }
247 
249  }
250  });
251 
252  root = NULL;
253  auto maps = myMaps->getFaceUse(myFace);
254  for (const auto map : maps)
255  {
256  if (!root)
257  {
258  root = CREUtils::mapNode(nullptr);
259  myUsing->addTopLevelItem(root);
260  root->setExpanded(true);
261  }
262 
264  }
265 
266  myColor->setCurrentIndex(myFace->magicmap);
267 
268  myLicenses->clear();
269 
270  auto licenses = LicenseManager::get()->getForFace(myFace->name);
271  for (auto l : licenses) {
272  QTreeWidgetItem *wi = new QTreeWidgetItem(QStringList(QString(l.first.c_str())));
273  for (auto p : l.second) {
274  auto twi = new QTreeWidgetItem(wi, QStringList(p.first.c_str()) << p.second.c_str());
275  twi->setToolTip(1, p.second.c_str());
276  }
277  myLicenses->addTopLevelItem(wi);
278  wi->setExpanded(true);
279  }
280 }
282 {
283 }
284 
286 {
287  CRESmoothFaceMaker maker;
288  maker.setSelectedFace(myFace);
289  maker.setAutoClose();
290  maker.exec();
291 }
Face::name
sstring name
Definition: face.h:19
Face
Definition: face.h:14
CRETPanel
Definition: CREPanel.h:20
global.h
banquet.l
l
Definition: banquet.py:164
GeneralMessage
Definition: book.h:44
CREFacePanel::mySave
QPushButton * mySave
Definition: CREFacePanel.h:29
obj::face
const Face * face
Definition: object.h:334
layout
Definition: main.c:85
maps
static std::unordered_map< std::string, mapzone * > maps
Definition: citylife.cpp:93
AssetsManager::messages
Messages * messages()
Definition: AssetsManager.h:59
CREUtils::generalMessageNode
static QTreeWidgetItem * generalMessageNode()
Definition: CREUtils.cpp:262
archininventory.arch
arch
DIALOGCHECK MINARGS 1 MAXARGS 1
Definition: archininventory.py:16
AssetsManager.h
face.h
CREUtils::faceNode
static QTreeWidgetItem * faceNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:187
CREUtils::archetypeNode
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:14
CREUtils.h
guildoracle.list
list
Definition: guildoracle.py:87
AssetsManager::animations
AllAnimations * animations()
Definition: AssetsManager.h:49
CREUtils::artifactNode
static QTreeWidgetItem * artifactNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:40
root
static char root[500]
Definition: mapper.cpp:305
first_artifactlist
EXTERN artifactlist * first_artifactlist
Definition: global.h:118
LicenseManager::get
static LicenseManager * get()
Definition: LicenseManager.cpp:29
CREUtils::mapNode
static QTreeWidgetItem * mapNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:220
smoking_pipe.color
color
Definition: smoking_pipe.py:5
CREFacePanel::myUsing
QTreeWidget * myUsing
Definition: CREFacePanel.h:26
getManager
AssetsManager * getManager()
Definition: assets.cpp:329
treasurestruct
Definition: treasure.h:63
AssetsCollection::find
T * find(const Key &name)
Definition: AssetsCollection.h:85
treasureContains
static bool treasureContains(const treasure *t, const archetype *arch)
Definition: CREFacePanel.cpp:78
LicenseManager.h
archt
Definition: object.h:468
object_get_value
const char * object_get_value(const object *op, const char *const key)
Definition: object.c:4354
quest
Definition: quest.py:1
CREFacePanel::setItem
virtual void setItem(const Face *face) override
Definition: CREFacePanel.cpp:118
disinfect.map
map
Definition: disinfect.py:4
CREFacePanel::myColor
QComboBox * myColor
Definition: CREFacePanel.h:27
CREUtils::questNode
static QTreeWidgetItem * questNode(const quest_definition *quest, QTreeWidgetItem *parent)
Definition: CREUtils.cpp:235
AssetsManager::treasures
Treasures * treasures()
Definition: AssetsManager.h:54
CREFacePanel::makeSmooth
void makeSmooth(bool)
Definition: CREFacePanel.cpp:285
artifactstruct::next
struct artifactstruct * next
Definition: artifact.h:18
AssetsManager::quests
Quests * quests()
Definition: AssetsManager.h:71
AssetsManager::faces
Faces * faces()
Definition: AssetsManager.h:39
artifactliststruct
Definition: artifact.h:26
Quests.h
Face::smoothface
struct Face * smoothface
Definition: face.h:18
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:135
animate.anim
string anim
Definition: animate.py:20
LicenseManager::getForFace
LicenseItems getForFace(const std::string &face)
Definition: LicenseManager.cpp:82
image.h
AssetsManager::archetypes
Archetypes * archetypes()
Definition: AssetsManager.h:44
artifactstruct
Definition: artifact.h:14
CREMapInformationManager.h
CREFacePanel::CREFacePanel
CREFacePanel(QWidget *parent, CREMapInformationManager *maps)
Definition: CREFacePanel.cpp:37
diamondslots.message
string message
Definition: diamondslots.py:57
animations_struct
Definition: face.h:25
CREFacePanel::myFile
QLineEdit * myFile
Definition: CREFacePanel.h:28
CRESmoothFaceMaker
Definition: CRESmoothFaceMaker.h:11
quest.h
Floor.t
t
Definition: Floor.py:62
isValidArchFlesh
static bool isValidArchFlesh(const archetype *arch, const Face *fleshFace)
Definition: CREFacePanel.cpp:98
archt::clone
object clone
Definition: object.h:472
assets.h
CRESmoothFaceMaker::setAutoClose
void setAutoClose(bool autoClose=true)
Definition: CRESmoothFaceMaker.cpp:61
CREFacePanel::myMaps
CREMapInformationManager * myMaps
Definition: CREFacePanel.h:23
artifactstruct::item
object * item
Definition: artifact.h:15
castle_read.key
key
Definition: castle_read.py:64
CREUtils::animationNode
static QTreeWidgetItem * animationNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:200
colorname
static const char *const colorname[]
Definition: CREFacePanel.cpp:20
connect
Definition: connect.py:1
CRESmoothFaceMaker.h
CREMapInformationManager
Definition: CREMapInformationManager.h:16
CREFacePanel.h
CREFacePanel::myLicenses
QTreeWidget * myLicenses
Definition: CREFacePanel.h:30
CRESmoothFaceMaker::setSelectedFace
void setSelectedFace(const Face *face)
Definition: CRESmoothFaceMaker.cpp:51
CREFacePanel::myFace
const Face * myFace
Definition: CREFacePanel.h:24
give.name
name
Definition: give.py:27
CREFacePanel::saveClicked
void saveClicked(bool)
Definition: CREFacePanel.cpp:281