The Battle for Wesnoth  1.17.17+dev
game_stats.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2023
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "game_board.hpp"
18 #include "gettext.hpp"
21 #include "team.hpp"
22 
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 class display;
28 class team;
29 struct team_data;
30 
31 namespace gui2::dialogs
32 {
33 
34 class game_stats : public modal_dialog
35 {
36 public:
37  game_stats(const display_context& board, const int viewing_team, int& selected_side_number);
38 
39  static bool execute(game_board& board, const int viewing_team, int& selected_side_number)
40  {
41  if(std::all_of(board.teams().begin(), board.teams().end(), [](team& team) { return team.hidden(); })) {
42  show_transient_message("", _("No visible sides found."));
43  return false;
44  }
45 
46  return game_stats(board, viewing_team, selected_side_number).show();
47  }
48 
49 private:
50  // TODO: don't like having this
52 
54 
55  std::vector<team_data> team_data_;
56 
58 
59  unit_const_ptr get_leader(const int side);
60 
61  void on_tab_select();
62 
63  virtual const std::string& window_id() const override;
64 
65  virtual void pre_show(window& window) override;
66 
67  virtual void post_show(window& window) override;
68 };
69 
70 } // namespace dialogs
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
Definition: display.hpp:87
Game board class.
Definition: game_board.hpp:53
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:86
virtual const std::string & window_id() const override
The ID of the window to build.
game_stats(const display_context &board, const int viewing_team, int &selected_side_number)
Definition: game_stats.cpp:50
static bool execute(game_board &board, const int viewing_team, int &selected_side_number)
Definition: game_stats.hpp:39
unit_const_ptr get_leader(const int side)
Definition: game_stats.cpp:58
const team & viewing_team_
Definition: game_stats.hpp:53
std::vector< team_data > team_data_
Definition: game_stats.hpp:55
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: game_stats.cpp:75
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: game_stats.cpp:259
const display_context & board_
Definition: game_stats.hpp:51
Abstract base class for all modal dialogs.
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:67
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:76
static std::string _(const char *str)
Definition: gettext.hpp:93
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
std::shared_ptr< const unit > unit_const_ptr
Definition: ptr.hpp:27