The Battle for Wesnoth  1.19.7+dev
game_stats.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2024
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 <string>
24 #include <vector>
25 
26 
27 namespace gui2::dialogs
28 {
29 
30 class game_stats : public modal_dialog
31 {
32 public:
33  game_stats(const display_context& board, const team& viewing_team, int& selected_side_number);
34 
35  static bool execute(game_board& board, const team viewing_team, int& selected_side_number)
36  {
37  if(std::all_of(board.teams().begin(), board.teams().end(), [](team& team) { return team.hidden(); })) {
38  show_transient_message("", _("No visible sides found."));
39  return false;
40  }
41 
42  return game_stats(board, viewing_team, selected_side_number).show();
43  }
44 
45 private:
46  // TODO: don't like having this
48 
50 
51  std::vector<team_data> team_data_;
52 
54 
55  unit_const_ptr get_leader(const int side);
56 
57  void on_tab_select();
58 
59  virtual const std::string& window_id() const override;
60 
61  virtual void pre_show() override;
62 
63  virtual void post_show() override;
64 };
65 
66 } // namespace dialogs
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
Game board class.
Definition: game_board.hpp:47
virtual const std::vector< team > & teams() const override
Definition: game_board.hpp:80
virtual const std::string & window_id() const override
The ID of the window to build.
game_stats(const display_context &board, const team &viewing_team, int &selected_side_number)
Definition: game_stats.cpp:42
unit_const_ptr get_leader(const int side)
Definition: game_stats.cpp:50
const team & viewing_team_
Definition: game_stats.hpp:49
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition: game_stats.cpp:252
std::vector< team_data > team_data_
Definition: game_stats.hpp:51
static bool execute(game_board &board, const team viewing_team, int &selected_side_number)
Definition: game_stats.hpp:35
const display_context & board_
Definition: game_stats.hpp:47
virtual void pre_show() override
Actions to be taken before showing the window.
Definition: game_stats.cpp:67
Abstract base class for all modal dialogs.
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:75
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