statistics.hpp 4.4 KB

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