Main Page Namespace List Class Hierarchy Alphabetical List Data Structures File List Namespace Members Data Fields Globals

# ExCMenu.cpp

Go to the documentation of this file.

    00001 /*
    00002  * ExNihilo 3D Engine
    00003  *
    00004  *  This program is free software; you can redistribute it and/or modify
    00005  *  it under the terms of the GNU General Public License as published by
    00006  *  the Free Software Foundation; either version 2 of the License, or
    00007  *  (at your option) any later version.
    00008  *
    00009  *  This program is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012  *  GNU Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU General Public License
    00015  *  along with this program; if not, write to the Free Software
    00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    00017  *
    00018  * Please read AUTHORS file !!!
    00019  *
    00020  * $Id: ExCMenu.cpp,v 1.6 2002/11/24 11:59:01 data Exp $
    00021  *
    00022  */
    00023
    00024 #include "ExCMenu.h"
    00025
    00026 ExCMenu::ExCMenu(void)
    00027 {
    00028 Guard(ExCMenu::ExCMenu(void))
    00029         SetName("ExCMenu");
    00030         SetType(typeid(this).name());
    00031         m_CurrentItem=-1;
    00032 UnGuard
    00033 }
    00034
    00035 ExCMenu::~ExCMenu(void)
    00036 {
    00037 Guard(ExCMenu::~ExCMenu(void))
    00038 UnGuard
    00039 }
    00040
    00041 void ExCMenu::Draw(void)
    00042 {
    00043 Guard(void ExCMenu::Draw(void))
    00044         ExNihilo::DrawCadre(350,10,300,60+30*m_VecMenuItem.size(),0.2f,0.0f,0.6f,0.9f);
    00045         ExNihilo::WriteToScreen24(400,50,1,1,1,m_MenuTitle);
    00046         for(unsigned int i=0;i<m_VecMenuItem.size();i++)
    00047         {
    00048                 if(i==m_CurrentItem)
    00049                 {
    00050                         ExNihilo::WriteToScreen24(400,100+(i*25),1,0,0,m_VecMenuItem.at(i).m_string);
    00051                 }else
    00052                 {
    00053                         ExNihilo::WriteToScreen24(400,100+(i*25),1,1,1,m_VecMenuItem.at(i).m_string);
    00054                 }
    00055         }
    00056
    00057 UnGuard
    00058 }
    00059
    00060 bool ExCMenu::LoadFile(std::string FileName)
    00061 {
    00062 Guard(ExCMenu::LoadFile(std::string FileName))
    00063     char                        buffer[255],b[255];
    00064         std::string buffstring;
    00065         std::ifstream fin;
    00066         #ifdef UNIX_SRC
    00067                 sprintf(buffer, PREFIX "/ExNihilo/Data/Menu/%s", FileName.data());
    00068         #else
    00069                 sprintf(buffer, "../Data/Menu/%s", FileName.data());
    00070         #endif
    00071         MenuItem Menuitem;
    00072         fin.open(buffer,std::ios::in);
    00073         if(fin.is_open())
    00074         {
    00075                 try
    00076                 {
    00077                         //read header
    00078                         memset(b,0,255);
    00079                         fin.getline(b,256,'\n');
    00080                         try
    00081                         {
    00082                                 buffstring=ExNihilo::ExtracValueFromSring(b,"<MenuHeader>","<#MenuHeader>");
    00083                                 m_MenuTitle=ExNihilo::ExtracValueFromSring(b,"<title>","<#title>");
    00084                                 m_MenuType=ExNihilo::ExtracValueFromSring(b,"<type>","<#type>");
    00085                         }catch(ExCExpStringNotFound){}
    00086                         //read items
    00087                         do
    00088                         {
    00089                                 memset(b,0,255);
    00090                                 fin.getline(b,256,'\n');
    00091                                 try
    00092                                 {
    00093                                         buffstring=ExNihilo::ExtracValueFromSring(b,"<MenuItem>","<#MenuItem>");
    00094                                         Menuitem.m_string=ExNihilo::ExtracValueFromSring(buffstring,"<string>","<#string>");
    00095                                         Menuitem.m_Action.m_Action=ExNihilo::ExtractIntValueFromSring(buffstring,"<action>","<#action>");
    00096                                         Menuitem.m_Action.m_Param=ExNihilo::ExtracValueFromSring(buffstring,"<param>","<#param>");
    00097                                         m_VecMenuItem.push_back(Menuitem);
    00098                                 }catch(ExCExpStringNotFound){}
    00099
    00100                         }while(!fin.eof());
    00101                         fin.close();
    00102                 }catch(...){throw ExCExpFileReadError();}
    00103         }else throw   ExCExpFileNotFound();
    00104         m_CurrentItem=0;
    00105         return true;
    00106 UnGuard
    00107 }
    00108
    00109 void ExCMenu::NextItem(void)
    00110 {
    00111 Guard(void ExCMenu::NextItem(void))
    00112         m_CurrentItem++;
    00113         if(m_CurrentItem>=m_VecMenuItem.size())m_CurrentItem=0;
    00114 UnGuard
    00115 }
    00116
    00117 void ExCMenu::PreviousItem(void)
    00118 {
    00119 Guard(void ExCMenu::PreviousItem(void))
    00120         m_CurrentItem--;
    00121         if(m_CurrentItem<0)m_CurrentItem=m_VecMenuItem.size()-1;
    00122 UnGuard
    00123 }
    00124
    00125 MenuItem ExCMenu::GetItem(int item)
    00126 {
    00127 Guard(MenuItem ExCMenu::GetItem(int item))
    00128         return m_VecMenuItem.at(item);
    00129 UnGuard
    00130 }
    00131
    00132 MenuItem ExCMenu::GetCurrentItem(void)
    00133 {
    00134 Guard(MenuItem ExCMenu::GetCurrentItem(void))
    00135         return GetItem(m_CurrentItem);
    00136 UnGuard
    00137 }
    00138
    00139 ExCAction ExCMenu::GetCurrentItemAction(void)
    00140 {
    00141 Guard(ExCAction ExCMenu::GetCurrentItemAction(void))
    00142         return GetCurrentItem().m_Action;
    00143 UnGuard
    00144 }