Crossfire Server, Trunk  R20513
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 }
8 
9 #include "CREFacePanel.h"
10 #include "CREUtils.h"
11 #include "CRESmoothFaceMaker.h"
12 
14 static const char *const colorname[] = {
15  "black", /* 0 */
16  "white", /* 1 */
17  "blue", /* 2 */
18  "red", /* 3 */
19  "orange", /* 4 */
20  "light_blue", /* 5 */
21  "dark_orange", /* 6 */
22  "green", /* 7 */
23  "light_green", /* 8 */
24  "grey", /* 9 */
25  "brown", /* 10 */
26  "yellow", /* 11 */
27  "khaki" /* 12 */
28 };
29 
30 
32 {
33  myFace = 0;
34 
35  QGridLayout* layout = new QGridLayout(this);
36 
37  myUsing = new QTreeWidget(this);
38  myUsing->setColumnCount(1);
39  myUsing->setHeaderLabel(tr("Used by"));
40  myUsing->setIconSize(QSize(32, 32));
41  layout->addWidget(myUsing, 1, 1, 3, 2);
42 
43  myColor = new QComboBox(this);
44  layout->addWidget(myColor, 4, 2);
45  layout->addWidget(new QLabel("Magicmap color: "), 4, 1);
46 
47  for(uint color = 0; color < sizeof(colorname) / sizeof(*colorname); color++)
48  myColor->addItem(colorname[color], color);
49 
50  myFile = new QLineEdit(this);
51  myFile->setReadOnly(true);
52  layout->addWidget(myFile, 5, 2);
53  layout->addWidget(new QLabel("Original file: "), 5, 1);
54 
55  mySave = new QPushButton(tr("Save face"));
56  layout->addWidget(mySave, 6, 1);
57  connect(mySave, SIGNAL(clicked(bool)), this, SLOT(saveClicked(bool)));
58 
59  QPushButton* smooth = new QPushButton(tr("Make smooth base"), this);
60  layout->addWidget(smooth, 6, 2);
61  connect(smooth, SIGNAL(clicked(bool)), this, SLOT(makeSmooth(bool)));
62 }
63 
65 {
66  Q_ASSERT(face);
67  myFace = face;
68 
69  myUsing->clear();
70 
71  QTreeWidgetItem* root = NULL;
72 
73  const archt* arch;
74  sstring key;
75 
76  for (arch = first_archetype; arch; arch = arch->more ? arch->more : arch->next)
77  {
78  key = object_get_value(&arch->clone, "identified_face");
79  if (arch->clone.face == myFace || (key && strcmp(face->name, key) == 0))
80  {
81  if (root == NULL)
82  {
83  root = CREUtils::archetypeNode(NULL);
84  myUsing->addTopLevelItem(root);
85  root->setExpanded(true);
86  }
87  CREUtils::archetypeNode(arch, root);
88  }
89  }
90 
91  root = NULL;
92 
93  const Animations* anim;
94 
95  // "bug" animation is zero, don't forget that shift
96  for (int a = 0; a <= num_animations; a++)
97  {
98  anim = &animations[a];
99  for (int face = 0; face < anim->num_animations; face++)
100  {
101  if (anim->faces[face] == myFace)
102  {
103  if (root == NULL)
104  {
105  root = CREUtils::animationNode(NULL);
106  myUsing->addTopLevelItem(root);
107  root->setExpanded(true);
108  }
109  CREUtils::animationNode(anim, root);
110  break;
111  }
112  }
113  }
114 
115  root = NULL;
116 
117  const artifactlist* list;
118  const artifact* arti;
119 
120  for (list = first_artifactlist; list; list = list->next)
121  {
122  for (arti = list->items; arti; arti = arti->next)
123  {
124  if (arti->item->face == myFace)
125  {
126  if (!root)
127  {
128  root = CREUtils::artifactNode(NULL);
129  myUsing->addTopLevelItem(root);
130  root->setExpanded(true);
131  }
132 
133  CREUtils::artifactNode(arti, root);
134  }
135  }
136  }
137 
138  myColor->setCurrentIndex(myFace->magicmap);
139 }
141 {
142 }
143 
145 {
146  CRESmoothFaceMaker maker;
147  maker.setSelectedFace(myFace->number);
148  maker.setAutoClose();
149  maker.exec();
150 }
QTreeWidget * myUsing
Definition: CREFacePanel.h:23
static QTreeWidgetItem * animationNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:182
static QTreeWidgetItem * archetypeNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:15
static QTreeWidgetItem * artifactNode(QTreeWidgetItem *parent)
Definition: CREUtils.cpp:42
EXTERN int num_animations
Definition: global.h:166
struct artifactstruct * items
Artifacts for this type.
Definition: artifact.h:30
const char * object_get_value(const object *op, const char *const key)
Get an extra value by key.
Definition: object.c:4246
object clone
An object from which to do object_copy()
Definition: object.h:470
void saveClicked(bool)
Global type definitions and header inclusions.
void setSelectedFace(int face)
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:465
uint16_t number
This is the image id.
Definition: face.h:15
const char * name
Face name, as used by archetypes and such.
Definition: face.h:20
struct artifactliststruct * next
Next list of artifacts.
Definition: artifact.h:29
static const char *const colorname[]
Image-related structures.
static char root[500]
Path to store generated files.
Definition: mapper.c:365
virtual void setItem(const New_Face *face)
struct archt * more
Next part of a linked object.
Definition: object.h:469
This represents one animation.
Definition: face.h:26
uint8_t num_animations
How many different faces to animate, size of the faces array.
Definition: face.h:28
const New_Face * myFace
Definition: CREFacePanel.h:21
Face-related structures.
EXTERN Animations * animations
Definition: global.h:165
uint8_t magicmap
Color to show this in magic map.
Definition: face.h:18
This represents all archetypes for one particular object type.
Definition: artifact.h:26
EXTERN artifactlist * first_artifactlist
First artifact.
Definition: global.h:121
QComboBox * myColor
Definition: CREFacePanel.h:24
This is one artifact, ie one special item.
Definition: artifact.h:14
QLineEdit * myFile
Definition: CREFacePanel.h:25
const char * sstring
Strings that should be manipulated through add_string() and free_string().
Definition: global.h:40
const New_Face ** faces
The actual faces for the animation.
Definition: face.h:31
struct archt * next
Next archetype in a linked list.
Definition: object.h:467
New face structure - this enforces the notion that data is face by face only - you can not change the...
Definition: face.h:14
void setAutoClose(bool autoClose=true)
object * item
Special values of the artifact.
Definition: artifact.h:15
const New_Face * face
Face with colors.
Definition: object.h:332
QPushButton * mySave
Definition: CREFacePanel.h:26
void makeSmooth(bool)
EXTERN archetype * first_archetype
First archetype.
Definition: global.h:122
struct artifactstruct * next
Next artifact in the list.
Definition: artifact.h:18
Definition: main.c:88