SettingsSubSelectDialog.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/SettingsSubSelectDialog.h>
00022 #include <dialogs/SettingsSelectDialog.h>
00023 #include <dialogs/MsgBoxDialog.h>
00024 #include <landscapedef/LandscapeDefinitionsBase.h>
00025 #include <GLW/GLWWindowManager.h>
00026 #include <GLW/GLWOptionEntry.h>
00027 #include <GLW/GLWTabContainer.h>
00028 #include <GLW/GLWSpacer.h>
00029 #include <GLW/GLWTranslate.h>
00030 #include <GLW/GLWFont.h>
00031 #include <graph/TextureStore.h>
00032 #include <client/ClientParams.h>
00033 #include <client/ClientMain.h>
00034 
00035 SettingsSubSelectDialogListItem::SettingsSubSelectDialogListItem(
00036         const char *icon, const char *name, const char *description,
00037         bool selected) :
00038         name_(name), 
00039         selected_(0.0f, 0.0f, selected), 
00040         tip_(ToolTip::ToolTipHelp, LANG_STRING(name), LANG_STRING(description)),
00041         icon_(0.0f, 0.0f, 40.0f, 40.0f)
00042 {
00043         if (S3D::fileExists(icon))
00044         {
00045                 GLTexture *texture = TextureStore::instance()->loadTexture(icon);
00046                 icon_.setTexture(texture);
00047         }
00048 }
00049 
00050 SettingsSubSelectDialogListItem::~SettingsSubSelectDialogListItem()
00051 {
00052 }
00053 
00054 void SettingsSubSelectDialogListItem::draw(float x, float y, float w)
00055 {
00056         icon_.setX(x + 2.0f);
00057         icon_.setY(y + 2.0f);
00058         icon_.draw();
00059 
00060         GLWToolTip::instance()->addToolTip(&tip_, 
00061                 GLWTranslate::getPosX() + x, 
00062                 GLWTranslate::getPosY() + y, w, 50.0f);
00063 
00064         GLWFont::instance()->getGameFont()->drawWidth(
00065                 w - 50.0f,
00066                 GLWFont::widgetFontColor, 
00067                 12.0f, x + 75.0f, y + 17.0f, 0.0f, 
00068                 name_);
00069 
00070         selected_.setX(x + 50.0f);
00071         selected_.setY(y + 13.0f);
00072         selected_.draw();
00073 }
00074 
00075 SettingsSubSelectDialog *SettingsSubSelectDialog::instance_ = 0;
00076 
00077 SettingsSubSelectDialog *SettingsSubSelectDialog::instance()
00078 {
00079         if (!instance_)
00080         {
00081                 instance_ = new SettingsSubSelectDialog;
00082         }
00083         return instance_;
00084 }
00085 
00086 SettingsSubSelectDialog::SettingsSubSelectDialog() : 
00087         GLWWindow("", 700.0f, 540.0f, 0, "")
00088 {
00089         // All the tabs are auto-layed out using a layout manager
00090         // except for the land tab where a panel on the land tab is layed out
00091         // and the rest are placed manually
00092         //
00093         // Create Tabs
00094         GLWTabContainer *tabPanel = new GLWTabContainer(0.0f, 0.0f, 0.0f, 0.0f);
00095         mainTab_ = (GLWTab *)
00096                 tabPanel->addWidget(new GLWTab("Main", LANG_RESOURCE("MAIN_TAB", "Main"), 10, 40, 520, 315));
00097         mainTab_->setGridWidth(2);
00098         mainTab_->setLayout(GLWPanel::LayoutGrid);
00099         ecoTab_ = (GLWTab *)
00100                 tabPanel->addWidget(new GLWTab("Eco", LANG_RESOURCE("ECONOMY_TAB", "Eco"), 10, 40, 520, 315));
00101         ecoTab_->setGridWidth(2);
00102         ecoTab_->setLayout(GLWPanel::LayoutGrid);
00103         scoreTab_ = (GLWTab *)
00104                 tabPanel->addWidget(new GLWTab("Score", LANG_RESOURCE("SCORE_TAB", "Score"), 10, 40, 520, 315));
00105         scoreTab_->setGridWidth(2);
00106         scoreTab_->setLayout(GLWPanel::LayoutGrid);
00107         envTab_ = (GLWTab *)
00108                 tabPanel->addWidget(new GLWTab("Env", LANG_RESOURCE("ENVIRONMENT_TAB", "Env"), 10, 40, 520, 315));
00109         envTab_->setGridWidth(2);
00110         envTab_->setLayout(GLWPanel::LayoutGrid);
00111         landTab_ = (GLWTab *)
00112                 tabPanel->addWidget(new GLWTab("Land", LANG_RESOURCE("LANDSCAPE_TAB", "Land"), 10, 40, 520, 315));
00113 
00114         GLWPanel *landSettingsPanel = new GLWPanel(10.0f, 10.0f, 200.0f, 40.0f, false, false);
00115         landTab_->addWidget(landSettingsPanel);
00116         landSettingsPanel->setGridWidth(2);
00117         landSettingsPanel->setLayout(GLWPanel::LayoutGrid);
00118         addWidget(tabPanel, 0, SpaceAll, 10.0f);
00119 
00120         OptionsGame &optionsGame = SettingsSelectDialog::instance()->getOptions();
00121 
00122         // Add Options
00123         GLWOptionEntry::createEntry(
00124                 controls_, mainTab_, optionsGame.getTeamBallanceEntry());
00125         GLWOptionEntry::createEntry(
00126                 controls_, mainTab_, optionsGame.getNoRoundsEntry());
00127         GLWOptionEntry::createEntry(
00128                 controls_, mainTab_, optionsGame.getNoMaxRoundTurnsEntry());
00129         GLWOptionEntry::createEntry(
00130                 controls_, mainTab_, optionsGame.getStartTimeEntry());  
00131         GLWOptionEntry::createEntry(
00132                 controls_, mainTab_, optionsGame.getShotTimeEntry());   
00133         GLWOptionEntry::createEntry(
00134                 controls_, mainTab_, optionsGame.getBuyingTimeEntry()); 
00135         mainTab_->addWidget(new GLWSpacer(0.0f, 20.0f));
00136 
00137         GLWOptionEntry::createEntry(
00138                 controls_, ecoTab_, optionsGame.getBuyOnRoundEntry());
00139         GLWOptionEntry::createEntry(
00140                 controls_, ecoTab_, optionsGame.getStartMoneyEntry());
00141         GLWOptionEntry::createEntry(
00142                 controls_, ecoTab_, optionsGame.getInterestEntry());
00143         GLWOptionEntry::createEntry(
00144                 controls_, ecoTab_, optionsGame.getMoneyPerRoundEntry());
00145         GLWOptionEntry::createEntry(
00146                 controls_, ecoTab_, optionsGame.getEconomyEntry());
00147         GLWOptionEntry::createEntry(
00148                 controls_, ecoTab_, optionsGame.getMoneyWonPerAssistPointEntry());
00149         GLWOptionEntry::createEntry(
00150                 controls_, ecoTab_, optionsGame.getMoneyWonPerKillPointEntry());
00151         GLWOptionEntry::createEntry(
00152                 controls_, ecoTab_, optionsGame.getMoneyWonPerMultiKillPointEntry());
00153         GLWOptionEntry::createEntry(
00154                 controls_, ecoTab_, optionsGame.getMoneyWonPerHitPointEntry());
00155         GLWOptionEntry::createEntry(
00156                 controls_, ecoTab_, optionsGame.getMoneyWonForRoundEntry());
00157         GLWOptionEntry::createEntry(
00158                 controls_, ecoTab_, optionsGame.getMoneyWonForLivesEntry());
00159         GLWOptionEntry::createEntry(
00160                 controls_, ecoTab_, optionsGame.getMoneyPerHealthPointEntry());
00161         GLWOptionEntry::createEntry(
00162                 controls_, ecoTab_, optionsGame.getGiveAllWeaponsEntry());
00163         ecoTab_->addWidget(new GLWSpacer(0.0f, 10.0f));
00164 
00165         GLWOptionEntry::createEntry(
00166                 controls_, scoreTab_, optionsGame.getScoreWonForRoundEntry());
00167         GLWOptionEntry::createEntry(
00168                 controls_, scoreTab_, optionsGame.getScoreWonForLivesEntry());
00169         GLWOptionEntry::createEntry(
00170                 controls_, scoreTab_, optionsGame.getScorePerKillEntry());
00171         GLWOptionEntry::createEntry(
00172                 controls_, scoreTab_, optionsGame.getScorePerAssistEntry());
00173         GLWOptionEntry::createEntry(
00174                 controls_, scoreTab_, optionsGame.getScorePerMoneyEntry());
00175         scoreTab_->addWidget(new GLWSpacer(0.0f, 20.0f));
00176 
00177         GLWOptionEntry::createEntry(
00178                 controls_, envTab_, optionsGame.getWindForceEntry());
00179         GLWOptionEntry::createEntry(
00180                 controls_, envTab_, optionsGame.getWindTypeEntry());
00181         GLWOptionEntry::createEntry(
00182                 controls_, envTab_, optionsGame.getWallTypeEntry());
00183         GLWOptionEntry::createEntry(
00184                 controls_, envTab_, optionsGame.getWeapScaleEntry());
00185         GLWOptionEntry::createEntry(
00186                 controls_, envTab_, optionsGame.getStartArmsLevelEntry());
00187         GLWOptionEntry::createEntry(
00188                 controls_, envTab_, optionsGame.getEndArmsLevelEntry());
00189         GLWOptionEntry::createEntry(
00190                 controls_, envTab_, optionsGame.getMinFallingDistanceEntry());
00191         GLWOptionEntry::createEntry(
00192                 controls_, envTab_, optionsGame.getMaxClimbingDistanceEntry());
00193         GLWOptionEntry::createEntry(
00194                 controls_, envTab_, optionsGame.getResignModeEntry());
00195         GLWOptionEntry::createEntry(
00196                 controls_, envTab_, optionsGame.getMovementRestrictionEntry());
00197         GLWOptionEntry::createEntry(
00198                 controls_, envTab_, optionsGame.getPlayerLivesEntry());
00199         GLWOptionEntry::createEntry(
00200                 controls_, envTab_, optionsGame.getDelayedDefenseActivationEntry());
00201         envTab_->addWidget(new GLWSpacer(0.0f, 10.0f));
00202 
00203         GLWOptionEntry::createEntry(
00204                 controls_, landSettingsPanel, optionsGame.getCycleMapsEntry());
00205         // End Add Options
00206 
00207         // Create buttons
00208         GLWPanel *buttonPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00209         GLWButton *cancelButton = new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 0.0f, 0.0f, 105, this, 
00210                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX);
00211         cancelId_ = cancelButton->getId();
00212         buttonPanel->addWidget(cancelButton, 0, SpaceRight, 10.0f);
00213         GLWButton *okButton = new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 0.0f, 0.0f, 55, this, 
00214                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX);
00215         okId_ = okButton->getId();
00216         buttonPanel->addWidget(okButton);
00217         buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
00218         addWidget(buttonPanel, 0, AlignRight | SpaceLeft | SpaceRight | SpaceBottom, 10.0f);
00219 
00220         // Layout
00221         setLayout(GLWPanel::LayoutVerticle);
00222         layout();
00223         landSettingsPanel->layout();
00224 
00225         // Add manualy placed land controls
00226         landList_ = new GLWIconList((landTab_->getW() - 280.0f) / 2.0f, 70.0f, 
00227                 280.0f, landTab_->getH() - 80.0f,
00228                 50.0f, GLWIconList::eNoDrawSelected);
00229         landTab_->addWidget(landList_);
00230         selectAllId_ = landTab_->addWidget(new GLWTextButton(
00231                 LANG_RESOURCE("SELECT_ALL", "Select All"), 70.0f, 40.0f, 180, this,
00232                 GLWButton::ButtonFlagCenterX))->getId();
00233         selectNoneId_ = landTab_->addWidget(new GLWTextButton(
00234                 LANG_RESOURCE("SELECT_NONE", "Select None"), 270.0f, 40.0f, 180, this,
00235                 GLWButton::ButtonFlagCenterX))->getId();
00236         landSettingsPanel->setX((landTab_->getW() - landSettingsPanel->getW()) / 2.0f);
00237 }
00238 
00239 SettingsSubSelectDialog::~SettingsSubSelectDialog()
00240 {
00241 }
00242 
00243 void SettingsSubSelectDialog::selected(unsigned int id, int position)
00244 {
00245         GLWIconListItem *item = landList_->getItems()[position];
00246         SettingsSubSelectDialogListItem *landItem = 
00247                 (SettingsSubSelectDialogListItem *) item;
00248         landItem->setSelected(!landItem->getSelected());
00249 }
00250 
00251 void SettingsSubSelectDialog::chosen(unsigned int id, int position)
00252 {
00253 }
00254 
00255 void SettingsSubSelectDialog::displayLand()
00256 {
00257         OptionsGame &optionsGame = 
00258                 SettingsSelectDialog::instance()->getOptions();
00259 
00260         LandscapeDefinitionsBase landscapeDefinitions;
00261         landscapeDefinitions.readLandscapeDefinitions();
00262         landList_->clear();
00263         landList_->setHandler(0);
00264 
00265         std::list<LandscapeDefinitionsEntry> &defns =
00266                 landscapeDefinitions.getAllLandscapes();
00267         std::list<LandscapeDefinitionsEntry>::iterator itor;
00268         for (itor = defns.begin();
00269                  itor != defns.end();
00270                  itor++)
00271         {
00272                 LandscapeDefinitionsEntry &dfn = *itor;
00273 
00274                 std::string fileName = S3D::getDataFile(S3D::formatStringBuffer("data/landscapes/%s", dfn.picture.c_str()));
00275                 if (!::S3D::fileExists(fileName))
00276                 {
00277                         fileName = S3D::getDataFile("data/landscapes/picture-none.bmp");
00278                 }
00279                 bool enabled = landscapeDefinitions.landscapeEnabled(
00280                         optionsGame, dfn.name.c_str());
00281 
00282                 SettingsSubSelectDialogListItem *listItem =
00283                         new SettingsSubSelectDialogListItem(
00284                                 fileName.c_str(), dfn.name.c_str(), 
00285                                 dfn.description.c_str(), enabled);
00286                 landList_->addItem(listItem);
00287         }
00288         landList_->setHandler(this);
00289 }
00290 
00291 void SettingsSubSelectDialog::display()
00292 {
00293         // START MOD SET
00294         OptionsGame &optionsGame = 
00295                 SettingsSelectDialog::instance()->getOptions();
00296         S3D::setDataFileMod(optionsGame.getMod());
00297         displayLand();
00298         S3D::setDataFileMod("none");
00299         // END MOD SET
00300 
00301         GLWOptionEntry::updateControls(controls_);
00302         mainTab_->setDepressed();
00303 }
00304 
00305 void SettingsSubSelectDialog::buttonDown(unsigned int id)
00306 {
00307         if (id == okId_)
00308         {
00309                 // Update all settings
00310                 GLWOptionEntry::updateEntries(controls_);
00311 
00312                 // Update landscape settings
00313                 OptionsGame &optionsGame = 
00314                         SettingsSelectDialog::instance()->getOptions();
00315                 std::string landscapesString;
00316                 std::vector<GLWIconListItem *> &landItems = 
00317                         landList_->getItems();
00318                 std::vector<GLWIconListItem *>::iterator itor;
00319                 for (itor = landItems.begin();
00320                         itor != landItems.end();
00321                         itor++)
00322                 {
00323                         SettingsSubSelectDialogListItem *landItem = 
00324                                 (SettingsSubSelectDialogListItem *) *itor;
00325                         if (landItem->getSelected())
00326                         {
00327                                 if (!landscapesString.empty()) landscapesString += ":";
00328                                 landscapesString += landItem->getName();
00329                         }
00330                 }
00331                 optionsGame.getLandscapesEntry().setValue(landscapesString.c_str());
00332 
00333                 // Hide Window
00334                 GLWWindowManager::instance()->hideWindow(id_);
00335         }
00336         else if (id == cancelId_)
00337         {
00338                 GLWWindowManager::instance()->hideWindow(id_);
00339         }
00340         else if (id == selectAllId_ || id == selectNoneId_)
00341         {
00342                 std::vector<GLWIconListItem *> &landItems = 
00343                         landList_->getItems();
00344                 std::vector<GLWIconListItem *>::iterator itor;
00345                 for (itor = landItems.begin();
00346                         itor != landItems.end();
00347                         itor++)
00348                 {
00349                         SettingsSubSelectDialogListItem *landItem = 
00350                                 (SettingsSubSelectDialogListItem *) *itor;
00351                         landItem->setSelected(id == selectAllId_);
00352                 }
00353         }
00354 }

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