Crossfire Server, Trunk
FacesetsPanel.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 <QtWidgets>
14 
15 #include "FacesetsPanel.h"
16 
17 #include "assets.h"
18 #include "AssetsManager.h"
19 #include "LicenseManager.h"
20 #include "FacesetsWrapper.h"
21 
22 FacesetsPanel::FacesetsPanel(QWidget* parent, LicenseManager *licenseManager) : AssetTWrapperPanel(parent), myLicenseManager(licenseManager) {
23  addLabel(tr("Prefix:"), "prefix");
24  addLabel(tr("Full name:"), "fullname");
25  addLabel(tr("Fallback:"), "fallback");
26  addLabel(tr("Size:"), "size");
27  addLabel(tr("Extension:"), "extension");
28  addWidget(tr("Defined faces:"), myImages = new QLabel(this), true, nullptr, nullptr);
29  addWidget(tr("License information:"), myLicenses = new QLabel(this), true, nullptr, nullptr);
31 }
32 
34  size_t count = 0, total = getManager()->faces()->count(), licenses = 0;
35 
36  getManager()->faces()->each([&] (const Face * face) {
37  if (face->number < myItem->allocated && myItem->faces[face->number].datalen > 0) {
38  count++;
39  if (myLicenseManager->getForFace(face->name).count(myItem->prefix) > 0) {
40  licenses++;
41  }
42  }
43  });
44 
45  uint8_t percent = count * 100 / total;
46  if (percent == 100 && count < total)
47  percent = 99;
48 
49  myImages->setText(QString(tr("%1 out of %2 (%3%)")).arg(count).arg(total).arg(percent));
50 
51  percent = licenses * 100 / count;
52  if (percent == 100 && licenses < count)
53  percent = 99;
54  myLicenses->setText(QString(tr("%1 faces have license information out of %2 (%3%)")).arg(licenses).arg(count).arg(percent));
55 }
AssetsCollection::count
size_t count() const
Definition: AssetsCollection.h:80
Face
Definition: face.h:14
FacesetsPanel.h
AssetsManager.h
FacesetsPanel::myLicenses
QLabel * myLicenses
Definition: FacesetsPanel.h:38
FacesetsPanel::FacesetsPanel
FacesetsPanel(QWidget *parent, LicenseManager *licenseManager)
Definition: FacesetsPanel.cpp:22
mail_login.total
total
Definition: mail_login.py:30
face_sets::allocated
size_t allocated
Definition: image.h:25
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
AssetWrapperPanel::addLabel
QLabel * addLabel(const QString &label, const char *property, bool wrapText=false)
Definition: AssetWrapperPanel.cpp:68
LicenseManager.h
AssetTWrapperPanel
Definition: AssetWrapperPanel.h:92
Face::number
uint16_t number
Definition: face.h:15
AssetWrapperPanel::addBottomFiller
void addBottomFiller()
Definition: AssetWrapperPanel.cpp:154
AssetsManager::faces
Faces * faces()
Definition: AssetsManager.h:39
FacesetsWrapper.h
disinfect.count
int count
Definition: disinfect.py:7
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
AssetTWrapperPanel< face_sets >::myItem
face_sets * myItem
Definition: AssetWrapperPanel.h:106
LicenseManager
Definition: LicenseManager.h:25
AssetWrapperPanel::addWidget
T * addWidget(const QString &label, T *widget, bool sideBySide, const char *property, const char *widgetProperty)
Definition: AssetWrapperPanel.h:64
assets.h
face_info::datalen
uint16_t datalen
Definition: image.h:12
FacesetsPanel::updateItem
virtual void updateItem() override
Definition: FacesetsPanel.cpp:33
FacesetsPanel::myImages
QLabel * myImages
Definition: FacesetsPanel.h:37
face_sets::faces
face_info * faces
Definition: image.h:26