src/menu/results_menu.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Results menu
00020  *****************************************************************************/
00021 
00022 #include "results_menu.h"
00023 
00024 #include "../team/results.h"
00025 #include "../character/character.h"
00026 #include "../include/app.h"
00027 #include "../tool/i18n.h"
00028 #include "../tool/string_tools.h"
00029 
00030 #define DEF_MARGIN    16
00031 #define DEF_BORDER    8
00032 #define DEF_SIZE      32
00033 #define USE_MOST      1
00034 
00035 const Point2i BorderSize(DEF_BORDER, DEF_BORDER);
00036 const Vector2<double> Zoom(1.7321, 1.7321);
00037 const Point2i DefSize(DEF_SIZE, DEF_SIZE);
00038 
00039 class ResultBox : public HBox
00040 {
00041 private:
00042   Box   *type_box;
00043   Box   *name_box;
00044   Label *name_lbl;
00045   Box   *score_box;
00046   Label *score_lbl;
00047 
00048 public:
00049   ResultBox(const Rectanglei &rect, bool _visible,
00050             const char* type_name, Font& font,
00051             const Point2i& type_size,
00052             const Point2i& name_size,
00053             const Point2i& score_size);
00054   // Hopefully no need for ~ResultBox() as it automatically
00055   // destroy child widgets by inheriting from HBox
00056   void SetResult(const std::string& name, int score);
00057 };
00058 
00059 ResultBox::ResultBox(const Rectanglei &rect, bool _visible,
00060                      const char *type_name, Font& font,
00061                      const Point2i& type_size,
00062                      const Point2i& name_size,
00063                      const Point2i& score_size)
00064   : HBox(rect, _visible)
00065 {
00066   Point2i pos(0, 0);
00067   Point2i posZero(0,0);
00068 
00069   margin = DEF_MARGIN;
00070   border.SetValues(DEF_BORDER, DEF_BORDER);
00071 
00072   type_box = new HBox( Rectanglei(pos, type_size), true);
00073   type_box->AddWidget(new Label(type_name, Rectanglei(pos, type_size), font));
00074   AddWidget(type_box);
00075 
00076   pos.SetValues(pos.GetX()+type_size.GetX(), pos.GetY());
00077   name_box = new HBox( Rectanglei(pos, name_size), true);
00078   name_lbl = new Label("", Rectanglei(pos, name_size), font);
00079   name_box->AddWidget(name_lbl);
00080   AddWidget(name_box);
00081 
00082   pos.SetValues(pos.GetX()+name_size.GetX(), pos.GetY());
00083   score_box = new HBox( Rectanglei(pos, score_size), true);
00084   score_lbl = new Label("", Rectanglei(pos, score_size), font);
00085   score_box->AddWidget(score_lbl);
00086   AddWidget(score_box);
00087 }
00088 
00089 void ResultBox::SetResult(const std::string& name, int score)
00090 {
00091   char buffer[16];
00092   std::string copy_name(name);
00093 
00094   snprintf(buffer, 16, "%i", score);
00095 
00096   std::string score_str(buffer);
00097 
00098   name_lbl->SetText(copy_name);
00099   score_lbl->SetText(score_str);
00100 
00101   ForceRedraw();
00102 }
00103 
00104 ResultsMenu::ResultsMenu(const std::vector<TeamResults*>* v,
00105                          const char *winner_name)
00106   : Menu("menu/bg_play", vOk)
00107   , results(v)
00108   , index(0)
00109   , max_height(DEF_SIZE+3*DEF_BORDER)
00110   , team_size(360, 40)
00111   , type_size(160, 40)
00112   , name_size(250, 40)
00113   , score_size(60, 40)
00114 {
00115   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml",false);
00116   Point2i pos (0, 0);
00117   Font* big_font = Font::GetInstance(Font::FONT_BIG);
00118 
00119   // Center the boxes!
00120   uint x = 60;
00121   uint y = 60;
00122 
00123   //Team selection
00124   team_box = new HBox(Rectanglei(x, y, total_width, max_height), true);
00125   team_box->SetMargin(DEF_MARGIN);
00126   team_box->SetBorder(Point2i(DEF_BORDER, DEF_BORDER));
00127 
00128   bt_prev_team = new Button(Rectanglei(pos, Point2i(DEF_SIZE, DEF_SIZE)),
00129                             res, "menu/arrow-left");
00130   team_box->AddWidget(bt_prev_team);
00131 
00132   pos.SetValues(pos.GetX()+DEF_SIZE, pos.GetY());
00133 
00134   HBox* tmp_box = new HBox( Rectanglei(pos, team_size), true);
00135   team_logo = new PictureWidget( Rectanglei(0,0,48,48) );
00136   tmp_box->AddWidget(team_logo);
00137 
00138   pos.SetValues(pos.GetX()+team_logo->GetSizeX(),pos.GetY());
00139   team_name = new Label("", Rectanglei(pos, team_size-48), *big_font);
00140   tmp_box->AddWidget(team_name);
00141 
00142   team_box->AddWidget(tmp_box);
00143   pos.SetValues(pos.GetX()+team_size.GetX(), pos.GetY());
00144   bt_next_team = new Button(Rectanglei(pos, Point2i(DEF_SIZE, DEF_SIZE)),
00145                             res, "menu/arrow-right");
00146   team_box->AddWidget(bt_next_team);
00147 
00148   widgets.AddWidget(team_box);
00149 
00150   resource_manager.UnLoadXMLProfile(res);
00151 
00152   //Results
00153   most_violent = new ResultBox(Rectanglei(x, y+int(1.5*max_height), total_width, max_height),
00154                                true, _("Most violent"), *big_font,
00155                                type_size, name_size, score_size);
00156   widgets.AddWidget(most_violent);
00157 
00158   most_usefull = new ResultBox(Rectanglei(x, y+3*max_height, total_width, max_height),
00159                                true, _("Most useful"), *big_font,
00160                                type_size, name_size, score_size);
00161   widgets.AddWidget(most_usefull);
00162 
00163   most_useless = new ResultBox(Rectanglei(x, y+int(4.5*max_height), total_width, max_height),
00164                                true, _("Most useless"), *big_font,
00165                                type_size, name_size, score_size);
00166   widgets.AddWidget(most_useless);
00167 
00168   biggest_traitor = new ResultBox(Rectanglei(x, y+6*max_height, total_width, max_height),
00169                                   true, _("Most sold-out"), *big_font,
00170                                   type_size, name_size, score_size);
00171   widgets.AddWidget(biggest_traitor);
00172 
00173   SetResult(0);
00174 }
00175 
00176 ResultsMenu::~ResultsMenu()
00177 {
00178 }
00179 
00180 void ResultsMenu::SetResult(int i)
00181 {
00182   const Character* player = NULL;
00183   const TeamResults* res = NULL;
00184   std::string name;
00185   
00186   index = i;
00187   if (index < 0) index = results->size()-1;
00188   else if (index>(int)results->size()-1) index = 0;
00189   res = (*results)[index];
00190   assert(res);
00191 
00192   //Team header
00193   name = res->getTeamName();
00194   if (res->getTeamLogo() == NULL) {
00195     team_logo->SetNoSurface();
00196   }  else  {
00197     team_logo->SetSurface( *(res->getTeamLogo()) );
00198   }
00199   printf("Now result %i/%i: team '%s'\n",
00200          index, (int)results->size(), name.c_str());
00201   team_name->SetText(name);
00202   team_box->ForceRedraw();
00203 
00204   //Most violent
00205   player = res->getMostViolent();
00206   if(player)
00207     most_violent->SetResult(player->GetName(), player->GetMostDamage());
00208   else
00209     most_violent->SetResult(_("Nobody!"), 0);
00210 
00211   //Most usefull
00212   player = res->getMostUsefull();
00213   if(player)
00214     most_usefull->SetResult(player->GetName(), player->GetOtherDamage());
00215   else
00216     most_usefull->SetResult(_("Nobody!"), 0);
00217 
00218   //Most usefull
00219   player = res->getMostUseless();
00220   if(player)
00221     most_useless->SetResult(player->GetName(), player->GetOtherDamage());
00222   else
00223     most_useless->SetResult(_("Nobody!"), 0);
00224 
00225   // Biggest sold-out
00226   player = res->getBiggestTraitor();
00227   if(player)
00228     biggest_traitor->SetResult(player->GetName(), player->GetOwnDamage());
00229   else
00230     biggest_traitor->SetResult(_("Nobody!"), 0);
00231 }
00232 
00233 void ResultsMenu::OnClic(const Point2i &mousePosition, int button)
00234 {
00235   if (bt_prev_team->Contains(mousePosition))
00236     SetResult(index-1);
00237   else if ( bt_next_team->Contains(mousePosition))
00238     SetResult(index+1);
00239 }
00240 
00241 void ResultsMenu::Draw(const Point2i &mousePosition)
00242 {
00243 }
00244 

Generated on Mon Jan 1 13:10:58 2007 for Wormux by  doxygen 1.4.7