Crossfire Server, Trunk
CREPixmap.cpp
Go to the documentation of this file.
1 #include <Qt>
2 #include "CREPixmap.h"
3 
4 extern "C" {
5 #include "global.h"
6 #include "face.h"
7 #include "image.h"
8 }
9 
10 #include "assets.h"
11 #include "AssetsManager.h"
12 #include "CRESettings.h"
13 
14 QHash<uint16_t, QIcon> CREPixmap::allFaces;
21 
23 {
24  myTreasureIcon = new QIcon(":resources/treasure_list.png");
25  myTreasureOneIcon = new QIcon(":resources/treasureone_list.png");
26  myTreasureYesIcon = new QIcon(":resources/treasure_yes.png");
27  myTreasureNoIcon = new QIcon(":resources/treasure_no.png");
28 
30  faceset = getManager()->facesets()->get(settings.facesetToDisplay().toStdString());
31  myUseFaceFallback = settings.facesetUseFallback();
32 }
33 
34 void CREPixmap::setFaceset(const QString& prefix)
35 {
36  faceset = getManager()->facesets()->get(prefix.toStdString());
37  allFaces.clear();
39  settings.setFacesetToDisplay(prefix);
40 }
41 
43 {
44  myUseFaceFallback = use;
45  allFaces.clear();
47  settings.setFacesetUseFallback(use);
48 }
49 
51 {
52  allFaces.clear();
53 }
54 
55 QIcon CREPixmap::getIcon(uint16_t faceNumber)
56 {
57  return CREPixmap::getIcon(faceset, faceNumber);
58 }
59 
60 QIcon CREPixmap::getIcon(const face_sets *faceset, uint16_t faceNumber)
61 {
62  if (!allFaces.contains(faceNumber))
63  {
64  QPixmap face;
65 
66  if (faceset->allocated >= faceNumber && faceset->faces[faceNumber].datalen > 0)
67  {
68  if (face.loadFromData((uchar*)faceset->faces[faceNumber].data, faceset->faces[faceNumber].datalen))
69  {
70  QIcon icon(face.scaled(32, 32, Qt::KeepAspectRatio));
71  allFaces[faceNumber] = icon;
72  }
73  }
74  else if (myUseFaceFallback && faceset->fallback)
75  {
76  return getIcon(faceset->fallback, faceNumber);
77  }
78  }
79  return allFaces[faceNumber];
80 }
81 
83 {
84  Q_ASSERT(myTreasureIcon);
85  return *myTreasureIcon;
86 }
87 
89 {
90  Q_ASSERT(myTreasureOneIcon);
91  return *myTreasureOneIcon;
92 }
93 
95 {
96  Q_ASSERT(myTreasureYesIcon);
97  return *myTreasureYesIcon;
98 }
99 
101 {
102  Q_ASSERT(myTreasureNoIcon);
103  return *myTreasureNoIcon;
104 }
CREPixmap::setFaceset
static void setFaceset(const QString &prefix)
Definition: CREPixmap.cpp:34
CREPixmap::allFaces
static QHash< uint16_t, QIcon > allFaces
Definition: CREPixmap.h:28
global.h
castle_read.prefix
string prefix
Definition: castle_read.py:31
uchar
#define uchar
Definition: re-cmp.h:42
CREPixmap::setUseFacesetFallback
static void setUseFacesetFallback(bool use)
Definition: CREPixmap.cpp:42
AssetsManager.h
face.h
CREPixmap::getTreasureIcon
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:82
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:55
face_sets::allocated
size_t allocated
Definition: image.h:25
CREPixmap::myTreasureYesIcon
static QIcon * myTreasureYesIcon
Definition: CREPixmap.h:31
CREPixmap::myTreasureOneIcon
static QIcon * myTreasureOneIcon
Definition: CREPixmap.h:30
getManager
AssetsManager * getManager()
Definition: assets.cpp:329
CREPixmap::myTreasureNoIcon
static QIcon * myTreasureNoIcon
Definition: CREPixmap.h:32
settings
struct Settings settings
Definition: init.c:39
CREPixmap::faceset
static face_sets * faceset
Definition: CREPixmap.h:13
CREPixmap::getTreasureYesIcon
static QIcon getTreasureYesIcon()
Definition: CREPixmap.cpp:94
CRESettings.h
face_info::data
uint8_t * data
Definition: image.h:11
AssetsCollection::get
T * get(const Key &name)
Definition: AssetsCollection.h:66
AssetsManager::facesets
Facesets * facesets()
Definition: AssetsManager.h:65
image.h
face_sets::fallback
struct face_sets * fallback
Definition: image.h:21
CRESettings
Definition: CRESettings.h:9
CREPixmap::getTreasureOneIcon
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:88
assets.h
face_info::datalen
uint16_t datalen
Definition: image.h:12
CREPixmap::myUseFaceFallback
static bool myUseFaceFallback
Definition: CREPixmap.h:33
CREPixmap::init
static void init()
Definition: CREPixmap.cpp:22
CREPixmap::clearFaceCache
static void clearFaceCache()
Definition: CREPixmap.cpp:50
face_sets
Definition: image.h:17
CREPixmap::getTreasureNoIcon
static QIcon getTreasureNoIcon()
Definition: CREPixmap.cpp:100
CREPixmap.h
face_sets::faces
face_info * faces
Definition: image.h:26
CREPixmap::myTreasureIcon
static QIcon * myTreasureIcon
Definition: CREPixmap.h:29