src/menu/credits_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  * Credits Menu
00020  *****************************************************************************/
00021 
00022 #include "credits_menu.h"
00023 //-----------------------------------------------------------------------------
00024 #include <sstream>
00025 #include <iostream>
00026 #include "../game/config.h"
00027 #include "../include/app.h"
00028 //-----------------------------------------------------------------------------
00029 
00030 class Author
00031 {
00032 public:
00033   std::string name;
00034   std::string nickname;
00035   std::string email;
00036   std::string country;
00037   std::string description;
00038 
00039   bool Feed (const xmlpp::Node *node);
00040   std::string PrettyString(bool with_email);
00041 };
00042 
00043 //-----------------------------------------------------------------------------
00044 
00045 bool Author::Feed (const xmlpp::Node *node)
00046 {
00047    if (!XmlReader::ReadString(node, "name", name)) return false;
00048    if (!XmlReader::ReadString(node, "description", description)) return false;
00049    return true;
00050 }
00051 
00052 //-----------------------------------------------------------------------------
00053 
00054 std::string Author::PrettyString(bool with_email)
00055 {
00056    std::ostringstream ss;
00057    ss << "* " << name;
00058    if (with_email)
00059    {
00060      ss << " <" << email << ">";
00061    }
00062    if (!nickname.empty())
00063    {
00064      ss << " aka " << nickname;
00065    }
00066    if (!country.empty())
00067    {
00068      ss << "from " << country;
00069    }
00070    ss << ": " << description;
00071    return ss.str();
00072 }
00073 
00074 //-----------------------------------------------------------------------------
00075 //-----------------------------------------------------------------------------
00076 
00077 CreditsMenu::CreditsMenu()  :
00078   Menu("menu/bg_network", vOk)
00079 {
00080   int title_height = AppWormux::GetInstance()->video.window.GetHeight() * 110 / 600;
00081   ListBox * lbox_authors = new ListBox( Rectanglei( 30, title_height,
00082                                                     AppWormux::GetInstance()->video.window.GetWidth()-60,
00083                                                     AppWormux::GetInstance()->video.window.GetHeight()-60-title_height),
00084                                         false);
00085 
00086   widgets.AddWidget(lbox_authors);
00087 
00088   PrepareAuthorsList(lbox_authors);
00089 }
00090 
00091 CreditsMenu::~CreditsMenu()
00092 {
00093 }
00094 
00095 void CreditsMenu::__sig_ok()
00096 {
00097   // Nothing to do
00098 }
00099 void CreditsMenu::__sig_cancel()
00100 {
00101   // Nothing to do
00102 }
00103 
00104 
00105 void CreditsMenu::PrepareAuthorsList(ListBox * lbox_authors)
00106 {
00107   std::string filename = Config::GetInstance()->GetDataDir() + PATH_SEPARATOR + "authors.xml";
00108   XmlReader doc;
00109   if(!doc.Load(filename))
00110   {
00111     // Error: do something ...
00112     return;
00113   }
00114 
00115   xmlpp::Node::NodeList sections = doc.GetRoot()->get_children("section");
00116   xmlpp::Node::NodeList::iterator
00117     section=sections.begin(),
00118     end_section=sections.end();
00119 
00120   for (; section != end_section; ++section)
00121   {
00122     xmlpp::Node::NodeList authors = (**section).get_children("author");
00123     xmlpp::Node::NodeList::iterator
00124       node=authors.begin(),
00125       end=authors.end();
00126     std::string title;
00127     xmlpp::Element *elem = dynamic_cast<xmlpp::Element*>(*section);
00128     if (!elem)
00129     {
00130         std::cerr << "cast error" << std::endl;
00131         continue;
00132     }
00133     if (!XmlReader::ReadStringAttr(elem, "title", title)) continue;
00134 
00135     std::cout << "=== " << title << " ===" << std::endl;
00136 
00137     lbox_authors->AddItem (false, "=== "+title+" ===", title);
00138 
00139     for (; node != end; ++node)
00140     {
00141         Author author;
00142         if (author.Feed(*node))
00143         {
00144           std::cout << author.PrettyString(false) << std::endl;
00145           lbox_authors->AddItem (false, author.PrettyString(false), author.name);
00146         }
00147     }
00148     std::cout << std::endl;
00149   }
00150 
00151 }
00152 
00153 void CreditsMenu::Draw(const Point2i& mousePosition)
00154 {
00155 }
00156 
00157 void CreditsMenu::OnClic(const Point2i &mousePosition, int button)
00158 {
00159   widgets.Clic(mousePosition, button);
00160 }
00161 
00162 //-----------------------------------------------------------------------------

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