K3dMenu.cpp

Go to the documentation of this file.
00001 
00012 /***************************************************************************
00013  *   Copyright (C) 2007 by Jan Koci   *
00014  *   honza.koci@email.cz   *
00015  *   http://kengine.sourceforge.net/tutorial/
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  *   This program is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00025  *   GNU General Public License for more details.                          *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU General Public License     *
00028  *   along with this program; if not, write to the                         *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00031  ***************************************************************************/
00032 
00033 // Load all files from a given directory
00034 // C example
00035 // http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=245&rl=1
00036 // http://forge.novell.com/modules/xfref_library/detail.php?reference_id=47
00037 
00038 
00039 #include "K3dMenu.h"
00040 #include "../System/K3dScene.h"
00041 
00042 K3dMenu::K3dMenu(K3dGameData *_pGameData): 
00043         K3dDir(_pGameData),
00044         K3dGui(_pGameData)
00045 {
00046         m_pGameData = _pGameData;
00047 }
00048 
00049 K3dMenu::~K3dMenu()
00050 {
00051 }
00052 
00053 /*
00055 void K3dMenu::OpenTestDir()
00056 {
00057         if (!OpenDirectory(K_STR_MAPS_TEST))
00058         {
00059                 cerr << "Error: void K3dMenu::OpenTestDir() -- The directory " << K_STR_MAPS_TEST << " doesn`t exists !!!"  << endl;
00060         }
00061 }
00062 */
00063 
00067 bool K3dMenu::ButtonIsPressed(const int _iButtonId)
00068 {
00069         if(_iButtonId < 0)
00070         {
00071                 cerr << "Error:: bool K3dMenu::ButtonIsPressed() -- ButtonId is negative !!! " << endl;
00072                 return false;
00073         }
00074         K3dGuiButton *pButton = GetGuiButton(_iButtonId);
00075 
00076         
00077 
00078         if(pButton)
00079         {
00080                 return pButton->isPressed();
00081         }
00082         else
00083         {
00084                 cerr << "Error:: bool K3dMenu::ButtonIsPressed() -- Pointer to pButton doesn`t allocated !!! " << endl;
00085         }
00086         return false;
00087 }
00088 
00092 void K3dMenu::ShowFileListBox(const int _iListModelId, const char *_strPath)
00093 {
00094         if(_iListModelId < 0)
00095         {
00096                 cerr << "Error:: void K3dMenu::ShowFileListBox() -- _iListBoxId is negative !!! " << endl;
00097                 return;
00098         }
00099         K3dGuiListModel *pListModel = GetGuiListModel(_iListModelId);
00100         if(pListModel)
00101         {
00102                 // Delete previous elements from list model
00103                 pListModel->DeleteElements();
00104                 K3dString strFilename = m_pGameData->GetPath(K_PATH_APP) + _strPath;
00105                 // Open directory
00106                 if(OpenDirectory(strFilename.GetString().c_str()))
00107                 {
00108                         TStringArray tStrArray = GetDirFileArray();
00109                         for(unsigned int i=0; i<tStrArray.size(); i++)
00110                         {
00111                                 K3dString strFile = tStrArray[i];
00112                                 // Return string front of sign "."
00113                                 K3dString strName;
00114                                 strName.GetStrTok(strFile, ".");
00115                                 if(strName != "")
00116                                 {
00117                                         // Add file name to the list model element
00118                                         pListModel->AddElement(strName.GetString());
00119                                 }
00120                         }
00121                 }
00122                 else
00123                 {
00124                         cerr << "Error:: void K3dMenu::ShowFileListBox() -- Path " << _strPath << " doesn`t exists.." << endl;
00125                 }
00126         }
00127         else
00128         {
00129                 cerr << "Error:: bool K3dMenu::ButtonIsPressed() -- Pointer to pButton doesn`t allocated !!! " << endl;
00130         }
00131 }
00132 
00134 bool K3dMenu::LoadMapFromListBox(const int _iListBoxId, const char * _strPath)
00135 {
00136         K3dGuiListBox *pListBox = GetGuiListBox(_iListBoxId);
00137         // Get selected list model index
00138         int iSlctd = pListBox->getSelected();
00139         // If selected any list model
00140         if(iSlctd >= 0)
00141         {
00142                 // Get string from selected model
00143                 string strFileName = pListBox->getListModel()->getElementAt(iSlctd);
00144                 // Add lua extencio
00145                 strFileName += K_STR_DOT_LUA;
00146                 // Add path
00147                 string strPath = _strPath;
00148                 strPath += "/";
00149                 strPath += strFileName;
00150                 K3dString strLoad = strPath;
00151                 K3dScene *pScene = m_pGameData->GetScene();
00152                 if(pScene)
00153                 {
00154                         pScene->LoadNewScript( strLoad.GetString( ).c_str());
00155                 }
00156                 return true;
00157         }
00158         
00159         return false;
00160         
00161 }
00162 
00163 

Generated on Thu Aug 16 23:53:27 2007 for K3dEngine by  doxygen 1.5.0