Author: ilor
Date: Fri Jul  4 15:19:18 2008
New Revision: 27718

URL: http://svn.gna.org/viewcvs/wesnoth?rev=27718&view=rev
Log:
Split statistics_dialog from menu_events.cpp into its own source file

Added:
    trunk/src/statistics_dialog.cpp   (with props)
    trunk/src/statistics_dialog.hpp   (with props)
Modified:
    trunk/src/CMakeLists.txt
    trunk/src/Makefile.am
    trunk/src/SConscript
    trunk/src/menu_events.cpp
    trunk/src/menu_events.hpp

Modified: trunk/src/CMakeLists.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/CMakeLists.txt?rev=27718&r1=27717&r2=27718&view=diff
==============================================================================
--- trunk/src/CMakeLists.txt (original)
+++ trunk/src/CMakeLists.txt Fri Jul  4 15:19:18 2008
@@ -271,6 +271,7 @@
     sha1.cpp
     settings.cpp
     statistics.cpp
+    statistics_dialog.cpp
     team.cpp
     terrain_filter.cpp
     time_of_day.cpp

Modified: trunk/src/Makefile.am
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/Makefile.am?rev=27718&r1=27717&r2=27718&view=diff
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Fri Jul  4 15:19:18 2008
@@ -123,6 +123,7 @@
        sha1.cpp \
        settings.cpp \
        statistics.cpp \
+       statistics_dialog.cpp \
        team.cpp \
        terrain_filter.cpp \
        time_of_day.cpp \

Modified: trunk/src/SConscript
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=27718&r1=27717&r2=27718&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Fri Jul  4 15:19:18 2008
@@ -205,6 +205,7 @@
     sha1.cpp
     settings.cpp
     statistics.cpp
+       statistics_dialog.cpp
     team.cpp
     terrain_filter.cpp
     time_of_day.cpp

Modified: trunk/src/menu_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.cpp?rev=27718&r1=27717&r2=27718&view=diff
==============================================================================
--- trunk/src/menu_events.cpp (original)
+++ trunk/src/menu_events.cpp Fri Jul  4 15:19:18 2008
@@ -37,6 +37,8 @@
 #include "preferences_display.hpp"
 #include "replay.hpp"
 #include "sound.hpp"
+#include "statistics.hpp"
+#include "statistics_dialog.hpp"
 #include "team.hpp"
 #include "unit_display.hpp"
 #include "unit_types.hpp"
@@ -70,215 +72,10 @@
        }
 }
 
-std::vector<std::string> create_unit_table(const 
statistics::stats::str_int_map& m, unsigned int team)
-{
-       std::vector<std::string> table;
-       for(statistics::stats::str_int_map::const_iterator i = m.begin(); i != 
m.end(); ++i) {
-               const unit_type_data::unit_type_map::const_iterator type = 
unit_type_data::types().find(i->first);
-               if(type == unit_type_data::types().end()) {
-                       continue;
-               }
-
-               std::stringstream str;
-
-               str << IMAGE_PREFIX << type->second.image();
-#ifndef LOW_MEM
-               str << "~RC(" << type->second.flag_rgb() << ">" << team << ")";
-#endif
-               str << COLUMN_SEPARATOR << type->second.type_name() << 
COLUMN_SEPARATOR << i->second << "\n";
-               table.push_back(str.str());
-       }
-
-       return table;
-}
-
-class statistics_dialog : public gui::dialog
-{
-public:
-       statistics_dialog(game_display &disp, const std::string& title, const 
unsigned int team,
-               const std::string& player);
-       ~statistics_dialog();
-protected:
-       void action(gui::dialog_process_info &dp_info);
-private:
-       void make_damage_line(std::vector<std::string>&,const 
std::string&,const long long&,const long long&,const long long&,const long 
long&);
-       gui::dialog_button *detail_btn_;
-       std::string player_name_;
-       statistics::stats stats_;
-       unsigned int team_num_;
-       std::vector<int> unit_count_;
-};
-
-void statistics_dialog::action(gui::dialog_process_info &dp_info)
-{
-       int sel = get_menu().selection();
-       bool has_details = sel < 5 && sel >= 0 && unit_count_[sel] > 0;
-       detail_btn_->enable(has_details);
-       if(dp_info.double_clicked && has_details) {
-               set_result(sel);
-       } else if(dp_info.new_key_down && !dp_info.key_down) {
-               set_result(gui::CLOSE_DIALOG);
-       }
-
-       // Prepare the sub-dialog for Statistic Details
-       std::string title;
-       std::vector<std::string> items_sub;
-       switch(result()) {
-       case gui::CLOSE_DIALOG:
-               break;
-       case 0:
-               items_sub = create_unit_table(stats_.recruits, team_num_);
-               title = _("Recruits");
-               break;
-       case 1:
-               items_sub = create_unit_table(stats_.recalls, team_num_);
-               title = _("Recalls");
-               break;
-       case 2:
-               items_sub = create_unit_table(stats_.advanced_to, team_num_);
-               title = _("Advancements");
-               break;
-       case 3:
-               items_sub = create_unit_table(stats_.deaths, team_num_);
-               title = _("Losses");
-               break;
-       case 4:
-               items_sub = create_unit_table(stats_.killed, team_num_);
-               //! @todo FIXME? Perhaps killed units shouldn't have the same 
team-color as your own.
-               title = _("Kills");
-               break;
-       default:
-               break;
-       }
-       if (items_sub.empty() == false) {
-               gui::dialog d(get_display(), title + " (" + player_name_ + ")", 
"", gui::CLOSE_ONLY);
-               d.set_menu(items_sub);
-               d.show();
-               dp_info.clear_buttons();
-               set_result(gui::CONTINUE_DIALOG);
-       }
-}
-
-statistics_dialog::statistics_dialog(game_display &disp, const std::string& 
title,
-const unsigned int team, const std::string& player)
-: dialog(disp, title, "", gui::NULL_DIALOG), player_name_(player),
-team_num_(team), unit_count_(5,0)
-{
-       detail_btn_ = new gui::standard_dialog_button(disp.video(), 
_("Details"), 0 , false);
-       add_button(detail_btn_, gui::dialog::BUTTON_EXTRA);
-       add_button(new gui::standard_dialog_button(disp.video(), _("Close"), 1, 
true),
-                               gui::dialog::BUTTON_STANDARD);
-
-       stats_ = statistics::calculate_stats(0, team_num_);
-       int n;
-       std::vector<std::string> items;
-       // Prepare the menu items
-       {
-               std::stringstream str;
-               n = statistics::sum_str_int_map(stats_.recruits);
-               unit_count_[0] = n;
-               str << _("Recruits") << COLUMN_SEPARATOR << n;
-               items.push_back(str.str());
-       }
-       {
-               std::stringstream str;
-               n = statistics::sum_str_int_map(stats_.recalls);
-               unit_count_[1] = n;
-               str << _("Recalls") << COLUMN_SEPARATOR << n;
-               items.push_back(str.str());
-       }
-       {
-               std::stringstream str;
-               n = statistics::sum_str_int_map(stats_.advanced_to);
-               unit_count_[2] = n;
-        str << _("Advancements") << COLUMN_SEPARATOR << n;
-               items.push_back(str.str());
-       }
-       {
-               std::stringstream str;
-               n = statistics::sum_str_int_map(stats_.deaths);
-               unit_count_[3] = n;
-               str << _("Losses") << COLUMN_SEPARATOR << n;
-               items.push_back(str.str());
-       }
-       {
-               std::stringstream str;
-               n = statistics::sum_str_int_map(stats_.killed);
-               unit_count_[4] = n;
-               str << _("Kills") << COLUMN_SEPARATOR << n;
-               items.push_back(str.str());
-       }
-       items.push_back("");
-       {
-               std::stringstream str;
-        str << font::BOLD_TEXT << _("Damage")
-                   << COLUMN_SEPARATOR << _("Over All") << COLUMN_SEPARATOR
-                   << COLUMN_SEPARATOR
-                   << COLUMN_SEPARATOR << _("This Turn");
-               items.push_back(str.str());
-       }
-
-       statistics_dialog::make_damage_line(items, _("Inflicted"),
-                       stats_.damage_inflicted,
-                       stats_.expected_damage_inflicted,
-                       stats_.turn_damage_inflicted,
-                       stats_.turn_expected_damage_inflicted);
-       statistics_dialog::make_damage_line(items, _("Taken"),
-                       stats_.damage_taken,
-                       stats_.expected_damage_taken,
-                       stats_.turn_damage_taken,
-                       stats_.turn_expected_damage_taken);
-       items.push_back("New stats:");
-
-       statistics_dialog::make_damage_line(items, _("Inflicted"),
-                       stats_.damage_inflicted,
-                       stats_.new_expected_damage_inflicted,
-                       stats_.turn_damage_inflicted,
-                       stats_.new_turn_expected_damage_inflicted);
-       statistics_dialog::make_damage_line(items, _("Taken"),
-                       stats_.damage_taken,
-                       stats_.new_expected_damage_taken,
-                       stats_.turn_damage_taken,
-                       stats_.new_turn_expected_damage_taken);
-       set_menu(items);
-}
-
-statistics_dialog::~statistics_dialog()
-{
-}
-
-void statistics_dialog::make_damage_line(std::vector<std::string>& items,
-                                        const std::string& header,
-                                        const long long& damage,
-                                        const long long& expected,
-                                        const long long& turn_damage,
-                                        const long long& turn_expected)
-{
-       const int dsa = statistics::stats::desimal_shift * damage
-                     - expected;
-       const int dst = statistics::stats::desimal_shift * turn_damage
-                     - turn_expected;
-
-       std::stringstream str;
-       str << header << COLUMN_SEPARATOR
-               << damage << " / "
-               << (expected/100 / (double)statistics::stats::desimal_shift * 
100.0)
-               << COLUMN_SEPARATOR
-               << ((dsa > 0) ? "+" : "")
-               << ((expected == 0) ? 0
-                               : 100 * dsa / expected)
-               << "%" << COLUMN_SEPARATOR
-               << COLUMN_SEPARATOR
-               << turn_damage << " / "
-               << (turn_expected/100 / 
(double)statistics::stats::desimal_shift * 100.0)
-               << COLUMN_SEPARATOR
-               << ((dst > 0) ? "+" : "")
-               << ((turn_expected == 0) ? 0
-                               : 100 * dst / turn_expected)
-               << "%";
-       items.push_back(str.str());
-
-}
+
+
+
+
 
 } // end anonymous namespace
 

Modified: trunk/src/menu_events.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/menu_events.hpp?rev=27718&r1=27717&r2=27718&view=diff
==============================================================================
--- trunk/src/menu_events.hpp (original)
+++ trunk/src/menu_events.hpp Fri Jul  4 15:19:18 2008
@@ -21,7 +21,6 @@
 #include "show_dialog.hpp"
 #include "display.hpp"
 #include "floating_textbox.hpp"
-#include "statistics.hpp"
 #include "widgets/textbox.hpp"
 
 class game_state;

Added: trunk/src/statistics_dialog.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/statistics_dialog.cpp?rev=27718&view=auto
==============================================================================
--- trunk/src/statistics_dialog.cpp (added)
+++ trunk/src/statistics_dialog.cpp Fri Jul  4 15:19:18 2008
@@ -1,0 +1,218 @@
+/* $Id$ */
+/*
+   Copyright (C) 2006 - 2008 by Joerg Hinrichs <[EMAIL PROTECTED]>
+   wesnoth playturn Copyright (C) 2003 by David White <[EMAIL PROTECTED]>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License version 2
+   or at your option any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+#include "gettext.hpp"
+#include "marked-up_text.hpp"
+#include "statistics.hpp"
+#include "statistics_dialog.hpp"
+#include "unit_types.hpp"
+#include "wml_separators.hpp"
+
+#include <sstream>
+
+namespace {
+std::vector<std::string> create_unit_table(const 
statistics::stats::str_int_map& m, unsigned int team)
+{
+       std::vector<std::string> table;
+       for(statistics::stats::str_int_map::const_iterator i = m.begin(); i != 
m.end(); ++i) {
+               const unit_type_data::unit_type_map::const_iterator type = 
unit_type_data::types().find(i->first);
+               if(type == unit_type_data::types().end()) {
+                       continue;
+               }
+
+               std::stringstream str;
+
+               str << IMAGE_PREFIX << type->second.image();
+#ifndef LOW_MEM
+               str << "~RC(" << type->second.flag_rgb() << ">" << team << ")";
+#endif
+               str << COLUMN_SEPARATOR << type->second.type_name() << 
COLUMN_SEPARATOR << i->second << "\n";
+               table.push_back(str.str());
+       }
+
+       return table;
+}
+} //end anonymous namespace
+
+void statistics_dialog::action(gui::dialog_process_info &dp_info)
+{
+       int sel = get_menu().selection();
+       bool has_details = sel < 5 && sel >= 0 && unit_count_[sel] > 0;
+       detail_btn_->enable(has_details);
+       if(dp_info.double_clicked && has_details) {
+               set_result(sel);
+       } else if(dp_info.new_key_down && !dp_info.key_down) {
+               set_result(gui::CLOSE_DIALOG);
+       }
+
+       // Prepare the sub-dialog for Statistic Details
+       std::string title;
+       std::vector<std::string> items_sub;
+       switch(result()) {
+       case gui::CLOSE_DIALOG:
+               break;
+       case 0:
+               items_sub = create_unit_table(stats_.recruits, team_num_);
+               title = _("Recruits");
+               break;
+       case 1:
+               items_sub = create_unit_table(stats_.recalls, team_num_);
+               title = _("Recalls");
+               break;
+       case 2:
+               items_sub = create_unit_table(stats_.advanced_to, team_num_);
+               title = _("Advancements");
+               break;
+       case 3:
+               items_sub = create_unit_table(stats_.deaths, team_num_);
+               title = _("Losses");
+               break;
+       case 4:
+               items_sub = create_unit_table(stats_.killed, team_num_);
+               //! @todo FIXME? Perhaps killed units shouldn't have the same 
team-color as your own.
+               title = _("Kills");
+               break;
+       default:
+               break;
+       }
+       if (items_sub.empty() == false) {
+               gui::dialog d(get_display(), title + " (" + player_name_ + ")", 
"", gui::CLOSE_ONLY);
+               d.set_menu(items_sub);
+               d.show();
+               dp_info.clear_buttons();
+               set_result(gui::CONTINUE_DIALOG);
+       }
+}
+
+statistics_dialog::statistics_dialog(game_display &disp, const std::string& 
title,
+       const unsigned int team, const std::string& player)
+: dialog(disp, title, "", gui::NULL_DIALOG), player_name_(player),
+team_num_(team), unit_count_(5,0)
+{
+       detail_btn_ = new gui::standard_dialog_button(disp.video(), 
_("Details"), 0 , false);
+       add_button(detail_btn_, gui::dialog::BUTTON_EXTRA);
+       add_button(new gui::standard_dialog_button(disp.video(), _("Close"), 1, 
true),
+                               gui::dialog::BUTTON_STANDARD);
+
+       stats_ = statistics::calculate_stats(0, team_num_);
+       int n;
+       std::vector<std::string> items;
+       // Prepare the menu items
+       {
+               std::stringstream str;
+               n = statistics::sum_str_int_map(stats_.recruits);
+               unit_count_[0] = n;
+               str << _("Recruits") << COLUMN_SEPARATOR << n;
+               items.push_back(str.str());
+       }
+       {
+               std::stringstream str;
+               n = statistics::sum_str_int_map(stats_.recalls);
+               unit_count_[1] = n;
+               str << _("Recalls") << COLUMN_SEPARATOR << n;
+               items.push_back(str.str());
+       }
+       {
+               std::stringstream str;
+               n = statistics::sum_str_int_map(stats_.advanced_to);
+               unit_count_[2] = n;
+        str << _("Advancements") << COLUMN_SEPARATOR << n;
+               items.push_back(str.str());
+       }
+       {
+               std::stringstream str;
+               n = statistics::sum_str_int_map(stats_.deaths);
+               unit_count_[3] = n;
+               str << _("Losses") << COLUMN_SEPARATOR << n;
+               items.push_back(str.str());
+       }
+       {
+               std::stringstream str;
+               n = statistics::sum_str_int_map(stats_.killed);
+               unit_count_[4] = n;
+               str << _("Kills") << COLUMN_SEPARATOR << n;
+               items.push_back(str.str());
+       }
+       items.push_back("");
+       {
+               std::stringstream str;
+        str << font::BOLD_TEXT << _("Damage")
+                   << COLUMN_SEPARATOR << _("Over All") << COLUMN_SEPARATOR
+                   << COLUMN_SEPARATOR
+                   << COLUMN_SEPARATOR << _("This Turn");
+               items.push_back(str.str());
+       }
+
+       statistics_dialog::make_damage_line(items, _("Inflicted"),
+                       stats_.damage_inflicted,
+                       stats_.expected_damage_inflicted,
+                       stats_.turn_damage_inflicted,
+                       stats_.turn_expected_damage_inflicted);
+       statistics_dialog::make_damage_line(items, _("Taken"),
+                       stats_.damage_taken,
+                       stats_.expected_damage_taken,
+                       stats_.turn_damage_taken,
+                       stats_.turn_expected_damage_taken);
+       items.push_back("New stats:");
+
+       statistics_dialog::make_damage_line(items, _("Inflicted"),
+                       stats_.damage_inflicted,
+                       stats_.new_expected_damage_inflicted,
+                       stats_.turn_damage_inflicted,
+                       stats_.new_turn_expected_damage_inflicted);
+       statistics_dialog::make_damage_line(items, _("Taken"),
+                       stats_.damage_taken,
+                       stats_.new_expected_damage_taken,
+                       stats_.turn_damage_taken,
+                       stats_.new_turn_expected_damage_taken);
+       set_menu(items);
+}
+
+statistics_dialog::~statistics_dialog()
+{
+}
+
+void statistics_dialog::make_damage_line(std::vector<std::string>& items,
+                                        const std::string& header,
+                                        const long long& damage,
+                                        const long long& expected,
+                                        const long long& turn_damage,
+                                        const long long& turn_expected)
+{
+       const int dsa = statistics::stats::desimal_shift * damage
+                     - expected;
+       const int dst = statistics::stats::desimal_shift * turn_damage
+                     - turn_expected;
+
+       std::stringstream str;
+       str << header << COLUMN_SEPARATOR
+               << damage << " / "
+               << (expected/100 / (double)statistics::stats::desimal_shift * 
100.0)
+               << COLUMN_SEPARATOR
+               << ((dsa > 0) ? "+" : "")
+               << ((expected == 0) ? 0
+                               : 100 * dsa / expected)
+               << "%" << COLUMN_SEPARATOR
+               << COLUMN_SEPARATOR
+               << turn_damage << " / "
+               << (turn_expected/100 / 
(double)statistics::stats::desimal_shift * 100.0)
+               << COLUMN_SEPARATOR
+               << ((dst > 0) ? "+" : "")
+               << ((turn_expected == 0) ? 0
+                               : 100 * dst / turn_expected)
+               << "%";
+       items.push_back(str.str());
+
+}

Propchange: trunk/src/statistics_dialog.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/src/statistics_dialog.cpp
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'

Added: trunk/src/statistics_dialog.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/statistics_dialog.hpp?rev=27718&view=auto
==============================================================================
--- trunk/src/statistics_dialog.hpp (added)
+++ trunk/src/statistics_dialog.hpp Fri Jul  4 15:19:18 2008
@@ -1,0 +1,39 @@
+/* $Id$ */
+/*
+   Copyright (C) 2006 - 2008 by Joerg Hinrichs <[EMAIL PROTECTED]>
+   wesnoth playturn Copyright (C) 2003 by David White <[EMAIL PROTECTED]>
+   Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License version 2
+   or at your option any later version.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY.
+
+   See the COPYING file for more details.
+*/
+
+#include "construct_dialog.hpp"
+#include "game_display.hpp"
+#include "statistics.hpp"
+
+#include <vector>
+#include <string>
+
+
+class statistics_dialog : public gui::dialog
+{
+public:
+       statistics_dialog(game_display &disp, const std::string& title, const 
unsigned int team,
+               const std::string& player);
+       ~statistics_dialog();
+protected:
+       void action(gui::dialog_process_info &dp_info);
+private:
+       void make_damage_line(std::vector<std::string>&,const 
std::string&,const long long&,const long long&,const long long&,const long 
long&);
+       gui::dialog_button *detail_btn_;
+       std::string player_name_;
+       statistics::stats stats_;
+       unsigned int team_num_;
+       std::vector<int> unit_count_;
+};

Propchange: trunk/src/statistics_dialog.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/src/statistics_dialog.hpp
------------------------------------------------------------------------------
    svn:keywords = 'Author Date Id Revision'


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to