1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 #ifndef __SCOREBOARDRENDERER_H__
14 #define __SCOREBOARDRENDERER_H__
15 
16 #include "common.h"
17 
18 /* system interface headers */
19 #include <string>
20 #include <vector>
21 
22 /* common interface headers */
23 #include "bzfgl.h"
24 
25 /* local interface headers */
26 #include "Player.h"
27 
28 
29 /**
30  * ScoreboardRenderer:
31  *  Encapsulates information about rendering the scoreboard display.
32  */
33 class ScoreboardRenderer
34 {
35 public:
36     ScoreboardRenderer();
37     ~ScoreboardRenderer();
38 
39     void      setDim(bool);
40     void    setWindowSize (float x, float y, float width, float height);
41     void      render(bool forceDisplay);
42     static Player* getLeader(std::string *label = NULL);
43 
44     static const int HUNT_NONE = 0;
45     static const int HUNT_SELECTING = 1;
46     static const int HUNT_ENABLED = 2;
47     void    setHuntState(int _state);
48     int         getHuntState() const;
49     void      setHuntNextEvent ();    // invoked when 'down' button pressed
50     void      setHuntPrevEvent ();    // invoked when 'up' button pressed
51     void      setHuntSelectEvent ();      // invoked when 'fire' button pressed
52     void    huntKeyEvent (bool isAdd);  // invoked when '7' or 'U' is pressed
53     void    clearHuntedTanks ();
54     void    huntReset ();        // invoked when joining a server
55 
56     static void    setAlwaysTeamScore (bool onoff);
57     static bool    getAlwaysTeamScore ();
58 
59     static void    setSort (int _sortby);
60     static int     getSort ();
61     static const char **getSortLabels();
62     static const int SORT_SCORE = 0;
63     static const int SORT_NORMALIZED = 1;
64     static const int SORT_REVERSE = 2;
65     static const int SORT_CALLSIGN = 3;
66     static const int SORT_TKS = 4;
67     static const int SORT_TKRATIO = 5;
68     static const int SORT_TEAM = 6;
69     static const int SORT_MYRATIO = 7;
70     static const int SORT_MAXNUM = SORT_MYRATIO;
71 
setTeamScoreY(float val)72     void setTeamScoreY ( float val )
73     {
74         teamScoreYVal = val;
75     }
setRoaming(bool val)76     void setRoaming ( bool val )
77     {
78         roaming = val;
79     }
80 
81     // does not include observers
82     static void getPlayerList(std::vector<Player*>& players);
83 
84 protected:
85     void hudColor3fv(const GLfloat*);
86     void renderTeamScores (float y, float x, float dy);
87     void renderScoreboard();
88     void renderCtfFlags();
89     void drawRoamTarget(float x0, float y0, float x1, float y1);
90     void drawPlayerScore(const Player*,
91                          float x1, float x2, float x3, float xs, float y,
92                          int mottoLen, bool huntInd);
93     static const char *sortLabels[SORT_MAXNUM+2];
94     static int sortMode;
95     static bool alwaysShowTeamScore;
96     void   stringAppendNormalized (std::string *s, float n);
97 
98 private:
99     void setMinorFontSize(float height);
100     void setLabelsFontSize(float height);
101     static int teamScoreCompare(const void* _a, const void* _b);
102     static int sortCompareCp(const void* _a, const void* _b);
103     static int sortCompareI2(const void* _a, const void* _b);
104     static Player** newSortedList(int sortType, bool obsLast, int *_numPlayers=NULL);
105     void exitSelectState (void);
106 
107 private:
108     float winX;
109     float winY;
110     float winWidth;
111     float winHeight;
112 
113     bool dim;
114     int huntPosition;
115     bool huntSelectEvent;
116     int huntPositionEvent;
117     int huntState;
118     bool huntAddMode;    // valid only if state == SELECTING
119     float teamScoreYVal;
120     bool roaming;
121 
122     GLfloat messageColor[3];
123     int minorFontFace;
124     float minorFontSize;
125     int labelsFontFace;
126     float labelsFontSize;
127 
128     float scoreLabelWidth;
129     float killsLabelWidth;
130     float teamScoreLabelWidth;
131     float teamCountLabelWidth;
132     float huntArrowWidth;
133     float huntPlusesWidth;
134     float huntedArrowWidth;
135     float tkWarnRatio;
136 
137     static std::string scoreSpacingLabel;
138     static std::string scoreLabel;
139     static std::string killSpacingLabel;
140     static std::string killLabel;
141     static std::string teamScoreSpacingLabel;
142     static std::string playerLabel;
143     static std::string teamCountSpacingLabel;
144     int numHunted;
145 };
146 
147 
148 #endif /* __SCOREBOARDRENDERER_H__ */
149 
150 // Local Variables: ***
151 // mode: C++ ***
152 // tab-width: 4 ***
153 // c-basic-offset: 4 ***
154 // indent-tabs-mode: nil ***
155 // End: ***
156 // ex: shiftwidth=4 tabstop=4
157