1 /**********************************************************************
2  *
3  *   FreeDoko a Doppelkopf-Game
4  *
5  *   Copyright (C) 2001 – 2018 by Diether Knof and Borg Enders
6  *
7  *   This program is free software; you can redistribute it and/or
8  *   modify it under the terms of the GNU General Public License as
9  *   published by the Free Software Foundation; either version 2 of
10  *   the License, or (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  *   You can find this license in the file 'gpl.txt'.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  *   MA  02111-1307  USA
22  *
23  *  Contact:
24  *    Diether Knof dknof@posteo.de
25  *
26  **********************************************************************/
27 
28 #ifdef USE_UI_GTKMM
29 
30 #pragma once
31 
32 #include "base.h"
33 #include "widgets/sticky_dialog.h"
34 
35 #include "../../game/specialpoint.h"
36 class Party;
37 class Player;
38 class PlayersDb;
39 class TLWcount;
40 
41 #include <gtkmm/treemodel.h>
42 #include <gtkmm/treestore.h>
43 namespace Gtk {
44 class TreeView;
45 } // namespace Gtk
46 namespace UI_GTKMM_NS {
47 /**
48  ** window with the player db
49  **
50  ** @todo   only update the heuristics at the end of a game,
51  **         so that the human player can get no additional information
52  **         (p.e. with 'only valid card')
53  **/
54 class PlayersDB : public Base, public Gtk::StickyDialog {
55   enum class Statistic {
56     total,
57     won,
58     lost,
59     percent_won
60   }; // enum Statistic
61   static constexpr Statistic statistic_all[] = {
62     Statistic::total,
63     Statistic::won,
64     Statistic::lost,
65     Statistic::percent_won,
66   };
67   static string to_string(Statistic statistic);
68   static string gettext(Statistic statistic);
69 
70   // model for the data
71   struct PlayersDBModel : public Gtk::TreeModel::ColumnRecord {
72       PlayersDBModel(unsigned playerno);
73 
74       Gtk::TreeModelColumn<Glib::ustring> type;
75       vector<Gtk::TreeModelColumn<Glib::ustring> > statistic;
76   }; // struct PlayersDBModel : public Gtk::TreeModel::ColumnRecord
77 
78   public:
79   explicit PlayersDB(Base* parent);
80   ~PlayersDB() override;
81 
82   PlayersDB() = delete;
83   PlayersDB(PlayersDB const&) = delete;
84   PlayersDB& operator=(PlayersDB const&) = delete;
85 
86   void party_close();
87   void game_finished();
88 
89   void update_db();
90   void name_changed(Player const& player);
91 
92   private:
93   void init();
94   void recreate_db();
95   void set_statistic(Statistic statistic);
96 
97   void clear_db();
98 
99   // returns a string representing the data
100   Glib::ustring statistic_data(TLWcount const& tlwcount) const;
101   // returns a string representing the data
102   Glib::ustring heuristic_statistic_data(unsigned total,
103                                          unsigned num) const;
104 
105   // a key has been pressed
106   bool on_key_press_event(GdkEventKey* key) override;
107 
108   private:
109   AutoDisconnector disconnector_;
110 
111   Statistic statistic = Statistic::total;
112 
113   std::unique_ptr<PlayersDBModel> players_db_model;
114   Glib::RefPtr<Gtk::TreeStore> players_db_list;
115   Gtk::TreeView* players_db_treeview = nullptr;
116 
117   Gtk::TreeModel::Row ranking;
118   Gtk::TreeModel::Row average_game_points;
119   Gtk::TreeModel::Row average_game_trick_points;
120   Gtk::TreeModel::Row games;
121   Gtk::TreeModel::Row games_marriage;
122   Gtk::TreeModel::Row games_poverty;
123   Gtk::TreeModel::Row games_solo;
124   Gtk::TreeModel::Row games_solo_color;
125   Gtk::TreeModel::Row games_solo_picture;
126   Gtk::TreeModel::Row games_solo_picture_single;
127   Gtk::TreeModel::Row games_solo_picture_double;
128   vector<Gtk::TreeModel::Row> game;
129   Gtk::TreeModel::Row specialpoints;
130   Gtk::TreeModel::Row specialpoints_winning;
131   Gtk::TreeModel::Row specialpoints_announcement;
132   std::map<Specialpoint::Type, Gtk::TreeModel::Row> specialpoint;
133   Gtk::TreeModel::Row heuristics;
134   Gtk::TreeModel::Row heuristics_general;
135   Gtk::TreeModel::Row heuristics_poverty;
136   Gtk::TreeModel::Row heuristics_solo;
137   Gtk::TreeModel::Row heuristics_solo_color;
138   Gtk::TreeModel::Row heuristics_solo_picture;
139   Gtk::TreeModel::Row heuristics_solo_meatless;
140   vector<Gtk::TreeModel::Row> heuristic;
141 }; // class PlayersDB : public Base, public Gtk::StickyDialog
142 
143 } // namespace UI_GTKMM_NS
144 
145 #endif // #ifdef USE_UI_GTKMM
146