ModSubSelectDialog.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/ModSubSelectDialog.h>
00022 #include <dialogs/ModSelectDialog.h>
00023 #include <GLW/GLWTextButton.h>
00024 #include <GLW/GLWLabel.h>
00025 #include <GLW/GLWWindowManager.h>
00026 #include <GLW/GLWFont.h>
00027 #include <GLW/GLWTranslate.h>
00028 #include <client/ClientParams.h>
00029 #include <client/ClientMain.h>
00030 #include <graph/TextureStore.h>
00031 #include <engine/ModDirs.h>
00032 #include <common/Defines.h>
00033 
00034 GLWIconListSubModItem::GLWIconListSubModItem(ModInfo::MenuEntry &modInfoEntry) :
00035         modInfoEntry_(modInfoEntry), 
00036         tip_(ToolTip::ToolTipHelp, 
00037                 LANG_STRING(modInfoEntry.shortdescription), 
00038                 LANG_STRING(modInfoEntry.description)),
00039         icon_(0.0f, 0.0f, 40.0f, 40.0f)
00040 {
00041         if (S3D::fileExists(modInfoEntry_.icon.c_str()))
00042         {
00043                 GLTexture *texture = TextureStore::instance()->loadTexture(
00044                         modInfoEntry_.icon.c_str());
00045                 icon_.setTexture(texture);
00046         }
00047 }
00048 
00049 GLWIconListSubModItem::~GLWIconListSubModItem()
00050 {
00051 }
00052 
00053 void GLWIconListSubModItem::draw(float x, float y, float w)
00054 {
00055         icon_.setX(x + 2.0f);
00056         icon_.setY(y + 2.0f);
00057         icon_.draw();
00058 
00059         GLWToolTip::instance()->addToolTip(&tip_, 
00060                 GLWTranslate::getPosX() + x, 
00061                 GLWTranslate::getPosY() + y, w, 50.0f);
00062 
00063         GLWFont::instance()->getGameFont()->drawWidth(
00064                 w - 50.0f,
00065                 GLWFont::widgetFontColor, 
00066                 10.0f, x + 50.0f, y + 18.0f, 0.0f, 
00067                 modInfoEntry_.shortdescription.c_str());
00068 }
00069 
00070 ModSubSelectDialog *ModSubSelectDialog::instance_ = 0;
00071 
00072 ModSubSelectDialog *ModSubSelectDialog::instance()
00073 {
00074         if (!instance_)
00075         {
00076                 instance_ = new ModSubSelectDialog;
00077         }
00078         return instance_;
00079 }
00080 
00081 ModSubSelectDialog::ModSubSelectDialog() : 
00082         GLWWindow("", 300.0f, 410.0f, 0, ""),
00083         modInfo_("None")
00084 {
00085         iconList_ = new GLWIconList(10.0f, 40.0f, 280.0f, 360.0f, 50.0f);
00086         addWidget(iconList_);
00087 
00088         okId_ = addWidget(new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 235, 10, 55, this, 
00089                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX))->getId();
00090         cancelId_ = addWidget(new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 120, 10, 105, this, 
00091                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX))->getId();
00092 
00093         iconList_->setHandler(this);
00094 }
00095 
00096 ModSubSelectDialog::~ModSubSelectDialog()
00097 {
00098 
00099 }
00100 
00101 void ModSubSelectDialog::setModInfo(ModInfo &modInfo)
00102 {
00103         modInfo_ = modInfo;
00104 }
00105 
00106 void ModSubSelectDialog::display()
00107 {
00108         iconList_->clear();
00109 
00110         std::list<ModInfo::MenuEntry>::iterator itor;
00111         for (itor = modInfo_.getMenuEntries().begin();
00112                 itor != modInfo_.getMenuEntries().end();
00113                 itor++)
00114         {
00115                 ModInfo::MenuEntry &entry = (*itor);
00116                 GLWIconListSubModItem *item = new GLWIconListSubModItem(entry);
00117                 iconList_->addItem(item);
00118         }
00119 }
00120 
00121 void ModSubSelectDialog::selected(unsigned int id, int position)
00122 {
00123 }
00124 
00125 void ModSubSelectDialog::chosen(unsigned int id, int position)
00126 {
00127         buttonDown(okId_);
00128 }
00129 
00130 void ModSubSelectDialog::buttonDown(unsigned int id)
00131 {
00132         if (id == okId_)
00133         {
00134                 GLWWindowManager::instance()->hideWindow(
00135                         ModSelectDialog::instance()->getId());
00136                 GLWWindowManager::instance()->hideWindow(id_);
00137 
00138                 GLWIconListSubModItem *selected = 
00139                         (GLWIconListSubModItem *) iconList_->getSelected();
00140                 if (selected)
00141                 {
00142                         const char *targetFilePath = selected->getModInfoEntry().gamefile.c_str();
00143                         ClientParams::instance()->reset();
00144                         ClientParams::instance()->setClientFile(targetFilePath);
00145                         ClientMain::startClient();
00146                 }
00147         }
00148         else if (id == cancelId_)
00149         {
00150                 GLWWindowManager::instance()->hideWindow(id_);
00151         }
00152 }

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