playersdiagram.h
1 //------------------------------------------------------------------------------
2 // playerdiagram.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 #ifndef __PLAYERS_DIAGRAM_H_
24 #define __PLAYERS_DIAGRAM_H_
25 
26 #include "serverapi/player.h"
27 #include "serverapi/serverptr.h"
28 #include <QPixmap>
29 #include <utility>
30 
31 class Server;
32 class QImage;
33 
35 {
36 public:
37  QString name;
38  QString displayName;
39 
41  PlayersDiagramStyle(QString name)
42  : name(name)
43  {
44  displayName = name.toLower();
45  displayName[0] = displayName[0].toUpper();
46  }
47  PlayersDiagramStyle(QString name, QString displayName)
48  : name(std::move(name)), displayName(std::move(displayName)) {}
49 };
50 
51 class PlayersDiagram : public QObject
52 {
53  Q_OBJECT
54  Q_DISABLE_COPY(PlayersDiagram)
55 
56 public:
57  static QList<PlayersDiagramStyle> availableSlotStyles();
63  static void loadImages(const QString &style);
64  static bool isNumericStyle(const QString &style);
65 
66  PlayersDiagram(ServerCPtr server);
67 
68  ~PlayersDiagram() override;
69 
70  QPixmap pixmap() const
71  {
72  return diagram;
73  }
74 
75 protected:
76  enum PlayerType
77  {
78  Bot,
79  Human
80  };
81 
82  static QImage openImage, openSpecImage, botImage, playerImage, spectatorImage;
83 
92  QImage colorizePlayer(QImage image, const QColor &color);
93 
94  void draw();
95  void drawTeam(PlayerType playerType, int team, int howMany);
96  void drawPictures(const QImage &image, int howMany);
97 
98  void obtainPlayerNumbers();
99 
100  int numBotsOnTeam[MAX_TEAMS];
101  int numBotsWithoutTeam;
102  int numFreeJoinSlots;
103  int numFreeSpectatorSlots;
104  int numHumansWithoutTeam;
105  int numHumansOnTeam[MAX_TEAMS];
106  int numSpectators;
107 
108 private:
109  static const QString DEFAULT_STYLE;
110  static QString currentlyLoadedStyle;
111 
112  ServerCPtr server;
113  QPixmap diagram;
114  QPainter *painter;
115  int position;
116  int slotSize;
117 
118  static QImage loadImage(const QString &style, const QString &name);
119  static QStringList stylePaths();
120 };
121 
122 #endif