Crossfire Server, Trunk
CREPixmap.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 <Qt>
14 #include "CREPixmap.h"
15 
16 #include "global.h"
17 #include "face.h"
18 #include "image.h"
19 
20 #include "assets.h"
21 #include "AssetsManager.h"
22 #include "CRESettings.h"
23 
24 QHash<uint16_t, QIcon> CREPixmap::allFaces;
31 
33 {
34  myTreasureIcon = new QIcon(":resources/treasure_list.png");
35  myTreasureOneIcon = new QIcon(":resources/treasureone_list.png");
36  myTreasureYesIcon = new QIcon(":resources/treasure_yes.png");
37  myTreasureNoIcon = new QIcon(":resources/treasure_no.png");
38 
40  faceset = getManager()->facesets()->get(settings.facesetToDisplay().toStdString());
41  myUseFaceFallback = settings.facesetUseFallback();
42 }
43 
44 void CREPixmap::setFaceset(const QString& prefix)
45 {
46  faceset = getManager()->facesets()->get(prefix.toStdString());
47  allFaces.clear();
49  settings.setFacesetToDisplay(prefix);
50 }
51 
53 {
54  myUseFaceFallback = use;
55  allFaces.clear();
57  settings.setFacesetUseFallback(use);
58 }
59 
61 {
62  allFaces.clear();
63 }
64 
65 QIcon CREPixmap::getIcon(uint16_t faceNumber)
66 {
67  return CREPixmap::getIcon(faceset, faceNumber);
68 }
69 
70 QIcon CREPixmap::getIcon(const Face *face) {
71  if (!face) {
72  return QIcon();
73  }
74  return getIcon(faceset, face->number);
75 }
76 
77 QIcon CREPixmap::getIcon(const face_sets *faceset, uint16_t faceNumber)
78 {
79  if (faceNumber == (uint16_t)-1) {
80  return QIcon();
81  }
82  if (!allFaces.contains(faceNumber))
83  {
84  QPixmap face;
85 
86  if (faceset->allocated >= faceNumber && faceset->faces[faceNumber].datalen > 0)
87  {
88  if (face.loadFromData((uchar*)faceset->faces[faceNumber].data, faceset->faces[faceNumber].datalen))
89  {
90  QIcon icon(face.scaled(32, 32, Qt::KeepAspectRatio));
91  allFaces[faceNumber] = icon;
92  }
93  }
94  else if (myUseFaceFallback && faceset->fallback)
95  {
96  return getIcon(faceset->fallback, faceNumber);
97  }
98  }
99  return allFaces[faceNumber];
100 }
101 
103 {
104  Q_ASSERT(myTreasureIcon);
105  return *myTreasureIcon;
106 }
107 
109 {
110  Q_ASSERT(myTreasureOneIcon);
111  return *myTreasureOneIcon;
112 }
113 
115 {
116  Q_ASSERT(myTreasureYesIcon);
117  return *myTreasureYesIcon;
118 }
119 
121 {
122  Q_ASSERT(myTreasureNoIcon);
123  return *myTreasureNoIcon;
124 }
CREPixmap::setFaceset
static void setFaceset(const QString &prefix)
Definition: CREPixmap.cpp:44
Face
Definition: face.h:14
CREPixmap::allFaces
static QHash< uint16_t, QIcon > allFaces
Definition: CREPixmap.h:41
global.h
castle_read.prefix
string prefix
Definition: castle_read.py:31
settings
struct Settings settings
Definition: init.cpp:139
uchar
#define uchar
Definition: re-cmp.h:42
CREPixmap::setUseFacesetFallback
static void setUseFacesetFallback(bool use)
Definition: CREPixmap.cpp:52
AssetsManager.h
face.h
CREPixmap::getTreasureIcon
static QIcon getTreasureIcon()
Definition: CREPixmap.cpp:102
CREPixmap::getIcon
static QIcon getIcon(uint16_t faceNumber)
Definition: CREPixmap.cpp:65
face_sets::allocated
size_t allocated
Definition: image.h:25
CREPixmap::myTreasureYesIcon
static QIcon * myTreasureYesIcon
Definition: CREPixmap.h:44
CREPixmap::myTreasureOneIcon
static QIcon * myTreasureOneIcon
Definition: CREPixmap.h:43
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
CREPixmap::myTreasureNoIcon
static QIcon * myTreasureNoIcon
Definition: CREPixmap.h:45
CREPixmap::faceset
static face_sets * faceset
Definition: CREPixmap.h:25
CREPixmap::getTreasureYesIcon
static QIcon getTreasureYesIcon()
Definition: CREPixmap.cpp:114
Face::number
uint16_t number
Definition: face.h:15
CRESettings.h
face_info::data
uint8_t * data
Definition: image.h:11
AssetsCollection::get
T * get(const Key &name)
Definition: AssetsCollection.h:89
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:21
CREPixmap::getTreasureOneIcon
static QIcon getTreasureOneIcon()
Definition: CREPixmap.cpp:108
assets.h
face_info::datalen
uint16_t datalen
Definition: image.h:12
CREPixmap::myUseFaceFallback
static bool myUseFaceFallback
Definition: CREPixmap.h:46
CREPixmap::init
static void init()
Definition: CREPixmap.cpp:32
CREPixmap::clearFaceCache
static void clearFaceCache()
Definition: CREPixmap.cpp:60
face_sets
Definition: image.h:17
CREPixmap::getTreasureNoIcon
static QIcon getTreasureNoIcon()
Definition: CREPixmap.cpp:120
CREPixmap.h
face_sets::faces
face_info * faces
Definition: image.h:26
CREPixmap::myTreasureIcon
static QIcon * myTreasureIcon
Definition: CREPixmap.h:42