ModSelectDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D 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 Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <dialogs/ModSelectDialog.h>
00022 #include <dialogs/ModSubSelectDialog.h>
00023 #include <dialogs/SettingsSelectDialog.h>
00024 #include <GLW/GLWTextButton.h>
00025 #include <GLW/GLWLabel.h>
00026 #include <GLW/GLWWindowManager.h>
00027 #include <GLW/GLWFont.h>
00028 #include <GLW/GLWTranslate.h>
00029 #include <graph/TextureStore.h>
00030 #include <engine/ModDirs.h>
00031 #include <common/Defines.h>
00032 
00033 GLWIconListModItem::GLWIconListModItem(ModInfo &modInfo) :
00034         modInfo_(modInfo), 
00035         tip_(ToolTip::ToolTipHelp, 
00036                 LANG_STRING(modInfo.getShortDescription()), 
00037                 LANG_STRING(modInfo.getDescription())),
00038         icon_(0.0f, 0.0f, 40.0f, 40.0f)
00039 {
00040         if (S3D::fileExists(modInfo_.getIcon()))
00041         {
00042                 GLTexture *texture = TextureStore::instance()->loadTexture(
00043                         modInfo_.getIcon());
00044                 icon_.setTexture(texture);
00045         }
00046 }
00047 
00048 GLWIconListModItem::~GLWIconListModItem()
00049 {
00050 }
00051 
00052 void GLWIconListModItem::draw(float x, float y, float w)
00053 {
00054         icon_.setX(x + 2.0f);
00055         icon_.setY(y + 2.0f);
00056         icon_.draw();
00057 
00058         GLWToolTip::instance()->addToolTip(&tip_, 
00059                 GLWTranslate::getPosX() + x, 
00060                 GLWTranslate::getPosY() + y, w, 50.0f);
00061 
00062         GLWFont::instance()->getGameFont()->drawWidth(
00063                 w - 50.0f,
00064                 GLWFont::widgetFontColor, 
00065                 10.0f, x + 50.0f, y + 18.0f, 0.0f, 
00066                 modInfo_.getShortDescription());
00067 }
00068 
00069 ModSelectDialog *ModSelectDialog::instance_ = 0;
00070 
00071 ModSelectDialog *ModSelectDialog::instance()
00072 {
00073         if (!instance_)
00074         {
00075                 instance_ = new ModSelectDialog;
00076         }
00077         return instance_;
00078 }
00079 
00080 ModSelectDialog::ModSelectDialog() : 
00081         GLWWindow("", 300.0f, 410.0f, 0, "")
00082 {
00083         iconList_ = new GLWIconList(10.0f, 40.0f, 280.0f, 360.0f, 50.0f);
00084         addWidget(iconList_);
00085 
00086         okId_ = addWidget(new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this, 
00087                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX))->getId();
00088         cancelId_ = addWidget(new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 120, 10, 105, this, 
00089                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX))->getId();
00090 
00091         iconList_->setHandler(this);
00092 }
00093 
00094 ModSelectDialog::~ModSelectDialog()
00095 {
00096 
00097 }
00098 
00099 void ModSelectDialog::display()
00100 {
00101         iconList_->clear();
00102 
00103         ModDirs modDirs;
00104         if (!modDirs.loadModDirs())
00105         {
00106                 S3D::dialogExit("ModSelectDialog", "Failed to load mod dirs");  
00107         }
00108 
00109         std::list<ModInfo>::iterator itor;
00110         for (itor = modDirs.getDirs().begin();
00111                 itor != modDirs.getDirs().end();
00112                 itor++)
00113         {
00114                 ModInfo &info = (*itor);
00115                 if (!info.getMenuEntries().empty())
00116                 {
00117                         GLWIconListModItem *item = new GLWIconListModItem(info);
00118                         iconList_->addItem(item);
00119                 }
00120         }
00121 
00122         // Add the info that represents a custom game
00123         {
00124                 ModInfo customInfo("Custom");
00125                 customInfo.parse(S3D::getDataFile("data/custominfo.xml"));
00126                 GLWIconListModItem *item = new GLWIconListModItem(customInfo);
00127                 iconList_->addItem(item);
00128         }
00129 }
00130 
00131 void ModSelectDialog::selected(unsigned int id, int position)
00132 {
00133 }
00134 
00135 void ModSelectDialog::chosen(unsigned int id, int position)
00136 {
00137         buttonDown(okId_);
00138 }
00139 
00140 void ModSelectDialog::buttonDown(unsigned int id)
00141 {
00142         if (id == okId_)
00143         {
00144                 GLWIconListModItem *selected = 
00145                         (GLWIconListModItem *) iconList_->getSelected();
00146                 if (selected)
00147                 {
00148                         if (0 == strcmp("Custom", selected->getModInfo().getName()))
00149                         {
00150                                 GLWWindowManager::instance()->showWindow(
00151                                         SettingsSelectDialog::instance()->getId());
00152                         }
00153                         else
00154                         {
00155                                 ModSubSelectDialog::instance()->setModInfo(selected->getModInfo());
00156                                 GLWWindowManager::instance()->showWindow(
00157                                         ModSubSelectDialog::instance()->getId());
00158                         }
00159                 }
00160         }
00161         else if (id == cancelId_)
00162         {
00163                 GLWWindowManager::instance()->hideWindow(id_);
00164         }
00165 }

Generated on Mon Feb 16 15:14:37 2009 for Scorched3D by  doxygen 1.5.3