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