Back to index

supertuxkart  0.5+dfsg1
credits_menu.cpp
Go to the documentation of this file.
00001 //  $Id: credits_menu.cpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 Joerg Henrichs
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 #include <fstream>
00020 #include <stdexcept>
00021 #include <iostream>
00022 
00023 #include "credits_menu.hpp"
00024 #include "file_manager.hpp"
00025 #include "translation.hpp"
00026 #include "widget_manager.hpp"
00027 #include "menu_manager.hpp"
00028 #if defined(WIN32) && !defined(__CYGWIN__)
00029 #  define strdup _strdup
00030 #endif
00031 
00032 enum WidgetTokens
00033 {
00034     WTOK_CREDITS,
00035     WTOK_QUIT
00036 };
00037 
00038 
00039 CreditsMenu::CreditsMenu()
00040 {
00041     std::string filename;
00042     std::string line;
00043     std::string credits_text;
00044 
00045     filename = file_manager->getConfigFile("CREDITS");
00046     std::ifstream file(filename.c_str());
00047 
00048     if( file.is_open() )
00049     {
00050         while( !file.eof() )
00051         {
00052             getline(file, line);
00053             credits_text.append(line);
00054             credits_text.push_back('\n');
00055         }   // while
00056         file.close();
00057     }
00058     else
00059     {
00060         printf("Couldn't load '%s'\n",filename.c_str());
00061         credits_text.append("CREDIT file was not installed properly!!\n");
00062         credits_text.append("Please check 'data/CREDITS'!!");
00063     }
00064 
00065 
00066     widget_manager->addTextWgt( WTOK_CREDITS, 100, 93, "" );
00067     widget_manager->setWgtTextSize( WTOK_CREDITS, WGT_FNT_SML );
00068     //FIXME: maybe I should make scroll names more consistent
00069     widget_manager->activateWgt( WTOK_CREDITS );
00070     widget_manager->enableWgtScroll( WTOK_CREDITS );
00071     widget_manager->setWgtYScrollPos( WTOK_CREDITS, WGT_SCROLL_START_BOTTOM );
00072     widget_manager->setWgtYScrollSpeed( WTOK_CREDITS, -80 );
00073     widget_manager->breakLine();
00074 
00075     widget_manager->addTextButtonWgt( WTOK_QUIT, 40, 7,
00076         _("Go back to the main menu"));
00077 
00078     widget_manager->layout( WGT_AREA_TOP );
00079 
00080     //This is done after layout so the widget doesn't gets resized.
00081     widget_manager->setWgtText( WTOK_CREDITS, credits_text );
00082 }   // CreditsMenu
00083 
00084 //-----------------------------------------------------------------------------
00085 CreditsMenu::~CreditsMenu()
00086 {
00087     widget_manager->reset() ;
00088 }   // ~CreditsMenu
00089 
00090 //-----------------------------------------------------------------------------
00091 void CreditsMenu::select()
00092 {
00093     switch( widget_manager->getSelectedWgt() )
00094     {
00095         case WTOK_QUIT:
00096             menu_manager->popMenu();
00097             break;
00098     }
00099 }
00100 /* EOF */