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/serverptr.h"
27 #include "serverapi/player.h"
28 #include <QPixmap>
29 
30 class Server;
31 class QImage;
32 
34 {
35 public:
36  QString name;
37  QString displayName;
38 
40  PlayersDiagramStyle(QString name)
41  : name(name)
42  {
43  displayName = name.toLower();
44  displayName[0] = displayName[0].toUpper();
45  }
46  PlayersDiagramStyle(QString name, QString displayName)
47  : name(name), displayName(displayName)
48  {}
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();
69 
70  QPixmap pixmap() const { return diagram; }
71 
72  protected:
73  enum PlayerType
74  {
75  Bot,
76  Human
77  };
78 
79  static QImage openImage, openSpecImage, botImage, playerImage, spectatorImage;
80 
89  QImage colorizePlayer(QImage image, const QColor &color);
90 
91  void draw();
92  void drawTeam(PlayerType playerType, int team, int howMany);
93  void drawPictures(const QImage &image, int howMany);
94 
95  void obtainPlayerNumbers();
96 
97  int numBotsOnTeam[MAX_TEAMS];
98  int numBotsWithoutTeam;
99  int numFreeJoinSlots;
100  int numFreeSpectatorSlots;
101  int numHumansWithoutTeam;
102  int numHumansOnTeam[MAX_TEAMS];
103  int numSpectators;
104 
105  private:
106  static const QString DEFAULT_STYLE;
107  static QString currentlyLoadedStyle;
108 
109  ServerCPtr server;
110  QPixmap diagram;
111  QPainter* painter;
112  int position;
113  int slotSize;
114 
115  static QImage loadImage(const QString &style, const QString &name);
116  static QStringList stylePaths();
117 };
118 
119 #endif
A representation of a server for a given game.
Definition: server.h:93