1 | // SuperTux (Statistics module) |
2 | // Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt> |
3 | // Copyright (C) 2006 Ondrej Hosek <ondra.hosek@gmail.com> |
4 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de> |
5 | // |
6 | // This program is free software: you can redistribute it and/or modify |
7 | // it under the terms of the GNU General Public License as published by |
8 | // the Free Software Foundation, either version 3 of the License, or |
9 | // (at your option) any later version. |
10 | // |
11 | // This program is distributed in the hope that it will be useful, |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | // GNU General Public License for more details. |
15 | // |
16 | // You should have received a copy of the GNU General Public License |
17 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
18 | |
19 | #ifndef HEADER_SUPERTUX_SUPERTUX_STATISTICS_HPP |
20 | #define |
21 | |
22 | #include "video/color.hpp" |
23 | #include "video/surface_ptr.hpp" |
24 | |
25 | class DrawingContext; |
26 | class Level; |
27 | class SquirrelVM; |
28 | |
29 | /** This class is a layer between level and worldmap to keep |
30 | track of stuff like scores, and minor, but funny things, like |
31 | number of jumps and stuff */ |
32 | class Statistics final |
33 | { |
34 | private: |
35 | static Color ; |
36 | static Color text_color; |
37 | |
38 | public: |
39 | static std::string coins_to_string(int coins, int total_coins); |
40 | static std::string frags_to_string(int badguys, int total_badguys); |
41 | static std::string time_to_string(float time); |
42 | static std::string secrets_to_string(int secrets, int total_secrets); |
43 | |
44 | public: |
45 | enum Status { INVALID, ACCUMULATING, FINAL }; |
46 | |
47 | public: |
48 | Statistics(); /**< Creates new statistics, call reset() before counting */ |
49 | |
50 | /** serialize statistics object as squirrel table "statistics" */ |
51 | void serialize_to_squirrel(SquirrelVM& vm) const; |
52 | |
53 | /** unserialize statistics object from squirrel table "statistics" */ |
54 | void unserialize_from_squirrel(SquirrelVM& vm); |
55 | |
56 | void draw_worldmap_info(DrawingContext& context, float target_time); /**< draw worldmap stat HUD */ |
57 | void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, const SurfacePtr& backdrop); /**< draw panel shown during level's end sequence */ |
58 | |
59 | void init(const Level& level); |
60 | void finish(float time); |
61 | void invalidate(); |
62 | |
63 | Status get_status() const { return m_status; } |
64 | |
65 | public: |
66 | void update(const Statistics& stats); /**< Given another Statistics object finds the best of each one */ |
67 | bool completed(const Statistics& stats, const float target_time) const; /* Check if stats match total stats */ |
68 | |
69 | float get_time() const { return m_time; } |
70 | |
71 | private: |
72 | void calculate_max_caption_length(); |
73 | |
74 | private: |
75 | enum Status m_status; |
76 | |
77 | public: |
78 | int m_total_coins; /**< coins in level */ |
79 | int m_total_badguys; /**< (vincible) badguys in level */ |
80 | int m_total_secrets; /**< secret areas in level */ |
81 | |
82 | int m_coins; /**< coins collected */ |
83 | int m_badguys; /**< badguys actively killed */ |
84 | int m_secrets; /**< secret areas found */ |
85 | |
86 | private: |
87 | float m_time; /**< seconds needed */ |
88 | |
89 | private: |
90 | int m_max_width; /** < Gets the max width of a stats line, 255 by default */ |
91 | |
92 | /** Captions */ |
93 | std::string CAPTION_MAX_COINS; |
94 | std::string CAPTION_MAX_FRAGGING; |
95 | std::string CAPTION_MAX_SECRETS; |
96 | std::string CAPTION_BEST_TIME; |
97 | std::string CAPTION_TARGET_TIME; |
98 | |
99 | float WMAP_INFO_LEFT_X; |
100 | float WMAP_INFO_RIGHT_X; |
101 | float WMAP_INFO_TOP_Y1; |
102 | float WMAP_INFO_TOP_Y2; |
103 | |
104 | private: |
105 | Statistics(const Statistics&) = delete; |
106 | Statistics& operator=(const Statistics&) = delete; |
107 | }; |
108 | |
109 | #endif |
110 | |
111 | /* EOF */ |
112 | |