StartDialog.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/StartDialog.h>
00022 #include <dialogs/ModSelectDialog.h>
00023 #include <dialogs/ModSubSelectDialog.h>
00024 #include <dialogs/SaveSelectDialog.h>
00025 #include <dialogs/NetworkSelectDialog.h>
00026 #include <dialogs/SettingsSelectDialog.h>
00027 #include <dialogs/SettingsSubSelectDialog.h>
00028 #include <client/ScorchedClient.h>
00029 #include <client/ClientParams.h>
00030 #include <client/ClientMain.h>
00031 #include <engine/GameState.h>
00032 #include <engine/MainLoop.h>
00033 #include <GLW/GLWColors.h>
00034 #include <GLW/GLWFont.h>
00035 #include <GLW/GLWTranslate.h>
00036 #include <GLW/GLWWindowManager.h>
00037 #include <lang/LangResource.h>
00038 
00039 StartDialog *StartDialog::instance_ = 0;
00040 
00041 StartDialog *StartDialog::instance()
00042 {
00043         if (!instance_)
00044         {
00045                 instance_ = new StartDialog;
00046         }
00047         return instance_;
00048 }
00049 
00050 StartDialog::StartDialog() : 
00051         GLWWindow("", 10.0f, 10.0f, 640.0f, 480.0f, eNoTitle),
00052         selected_(-1)
00053 {
00054         OptionDefinition defs[] = 
00055         {
00056                 LANG_RESOURCE("TUTORIAL", "Tutorial"), "- Start the tutorial to learn how to play.", 50.0f, 60.0f, 0.0f,
00057                 LANG_RESOURCE("LOCAL_GAME", "Local Game"), "- Play a game against the computer or other local players.", 50.0f, 100.0f, 0.0f,
00058                 LANG_RESOURCE("Network Game", "Network Game"), "- Play an online game against remote players.", 50.0f, 140.0f, 0.0f,
00059                 LANG_RESOURCE("LOAD SAVE", "Load Save"), "- Continue playing a saved game.", 50.0f, 180.0f, 0.0f,
00060                 LANG_RESOURCE("HELP", "Help"), "- View the online help.", 50.0f, 250.0f, 0.0f,
00061                 LANG_RESOURCE("DONATE", "Donate"), "- Show support for Scorched3D.", 50.0f, 290.0f, 0.0f,
00062                 LANG_RESOURCE("QUIT", "Quit"), "- Exit the game.", 50.0f, 360.0f, 0.0f
00063         };
00064         for (int i=0; i<sizeof(defs) / sizeof(OptionDefinition); i++)
00065         {
00066                 definitions_.push_back(defs[i]);
00067         }
00068 }
00069 
00070 StartDialog::~StartDialog()
00071 {
00072 }
00073 
00074 void StartDialog::draw()
00075 {
00076         int mouseX = ScorchedClient::instance()->getGameState().getMouseX();
00077         int mouseY = ScorchedClient::instance()->getGameState().getMouseY();
00078         
00079         GLState state(GLState::DEPTH_OFF);
00080 
00081         selected_ = -1;
00082         float size = 18.0f;
00083         float smallSize = 14.0f;
00084         Vector white(0.8f, 0.8f, 0.8f);
00085         for (int i=0; i<(int) definitions_.size(); i++)
00086         {
00087                 OptionDefinition &definition = definitions_[i];
00088 
00089                 // Draw shadow
00090                 GLWFont::instance()->getNormalShadowFont()->draw(
00091                         GLWColors::black, size, 
00092                         definition.x - 2, h_ - definition.y + 2, 0.0f,
00093                         definition.option);
00094 
00095                 // Check if option is selected
00096                 Vector *color = &white;
00097                 if (inBox(
00098                         mouseX - GLWTranslate::getPosX(), 
00099                         mouseY - GLWTranslate::getPosY(), 
00100                         definition.x, (h_ - definition.y), 
00101                         definition.width, 20.0f))
00102                 {
00103                         color = &GLWColors::white;
00104                         selected_ = i;
00105                 }
00106 
00107                 // Draw Option
00108                 GLWFont::instance()->getNormalFont()->draw(
00109                         *color, size, 
00110                         definition.x, h_ - definition.y, 0.0f,
00111                         definition.option);
00112                 definition.width = 
00113                         GLWFont::instance()->getNormalFont()->getWidth(
00114                         size, definition.option);
00115 
00116                 // Draw Description
00117                 if (selected_ == i)
00118                 {
00119                         GLWFont::instance()->getNormalShadowFont()->draw(
00120                                 GLWColors::black, smallSize, 
00121                                 definition.x + 200.0f - 1.5f, h_ - definition.y + 1.5f, 0.0f,
00122                                 definition.description);
00123 
00124                         GLWFont::instance()->getNormalFont()->draw(
00125                                 *color, smallSize, 
00126                                 definition.x + 200.0f, h_ - definition.y, 0.0f,
00127                                 definition.description);
00128                 }
00129         }
00130 }
00131 
00132 void StartDialog::mouseDown(int button, float x, float y, bool &skipRest)
00133 {
00134         if (selected_ != -1)
00135         {
00136                 skipRest = true;
00137 
00138                 // Make sure all other options are hidden
00139                 GLWWindowManager::instance()->hideWindow(
00140                         ModSelectDialog::instance()->getId());
00141                 GLWWindowManager::instance()->hideWindow(
00142                         ModSubSelectDialog::instance()->getId());
00143                 GLWWindowManager::instance()->hideWindow(
00144                         SaveSelectDialog::instance()->getId()); 
00145                 GLWWindowManager::instance()->hideWindow(
00146                         NetworkSelectDialog::instance()->getId());      
00147                 GLWWindowManager::instance()->hideWindow(
00148                         SettingsSelectDialog::instance()->getId());     
00149                 GLWWindowManager::instance()->hideWindow(
00150                         SettingsSubSelectDialog::instance()->getId());  
00151         }
00152 
00153         switch (selected_)
00154         {
00155         case 0:
00156                 {
00157                 std::string targetFilePath = S3D::getDataFile("data/singletutorial.xml");
00158                 ClientParams::instance()->reset();
00159                 ClientParams::instance()->setClientFile(targetFilePath.c_str());
00160                 ClientMain::startClient();
00161                 }
00162                 break;
00163         case 1:
00164                 GLWWindowManager::instance()->showWindow(
00165                         ModSelectDialog::instance()->getId());
00166                 break;
00167         case 2:
00168                 GLWWindowManager::instance()->showWindow(
00169                         NetworkSelectDialog::instance()->getId());
00170                 break;
00171         case 3:
00172                 GLWWindowManager::instance()->showWindow(
00173                         SaveSelectDialog::instance()->getId());
00174                 break;
00175         case 4:
00176                 {
00177                 S3D::showURL("http://www.scorched3d.co.uk/wiki");
00178                 }
00179                 break;
00180         case 5:
00181                 {
00182                 const char *exec = 
00183                         "\"https://www.paypal.com/xclick/business=donations%40"
00184                         "scorched3d.co.uk&item_name=Scorched3D&no_note=1&tax=0&currency_code=GBP\"";
00185                 S3D::showURL(exec);
00186                 }
00187                 break;
00188         case 6:
00189                 ScorchedClient::instance()->getMainLoop().exitLoop();
00190                 break;
00191         }
00192 }

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