SaveDialog.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/SaveDialog.h>
00022 #include <GLW/GLWTextButton.h>
00023 #include <GLW/GLWLabel.h>
00024 #include <GLW/GLWWindowManager.h>
00025 #include <lang/LangResource.h>
00026 #include <client/ScorchedClient.h>
00027 #include <client/ClientSave.h>
00028 #include <common/ChannelManager.h>
00029 #include <common/Defines.h>
00030 #include <time.h>
00031 
00032 SaveDialog *SaveDialog::instance_ = 0;
00033 
00034 SaveDialog *SaveDialog::instance()
00035 {
00036         if (!instance_)
00037         {
00038                 instance_ = new SaveDialog;
00039         }
00040         return instance_;
00041 }
00042 
00043 SaveDialog::SaveDialog() : 
00044         GLWWindow("Save", 210.0f, 80.0f, 0,
00045                 "Allows the player to save the game.")
00046 {
00047         textBox_ = new GLWTextBox(0.0f, 0.0f, 250.0f);
00048         addWidget(textBox_,
00049                 0, SpaceLeft | SpaceRight | SpaceTop, 10.0f);
00050 
00051         GLWPanel *buttonPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00052         
00053         GLWButton *cancelButton = new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 95, 10, 105, this, 
00054                 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX);
00055         cancelId_ = cancelButton->getId();
00056         buttonPanel->addWidget(cancelButton, 0, SpaceRight, 10.0f);
00057         
00058         GLWButton *okButton = new GLWTextButton(LANG_RESOURCE("SAVE", "Save"), 10, 45, 105, this, 
00059                 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX);
00060         okId_ = okButton->getId();
00061         buttonPanel->addWidget(okButton);
00062         
00063         
00064         buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
00065         addWidget(buttonPanel, 0, SpaceAll | AlignRight, 10.0f);
00066 
00067         setLayout(GLWPanel::LayoutVerticle);
00068         layout();
00069 }
00070 
00071 SaveDialog::~SaveDialog()
00072 {
00073 
00074 }
00075 
00076 void SaveDialog::display()
00077 {
00078         GLWWindow::display();
00079 
00080         std::string text = S3D::formatStringBuffer("saved-%i", time(0));
00081         textBox_->setText(LANG_STRING(text));
00082 }
00083 
00084 void SaveDialog::buttonDown(unsigned int id)
00085 {
00086         if (id == okId_)
00087         {
00088                 if (textBox_->getText()[0])
00089                 {
00090                         std::string saveFile = S3D::formatStringBuffer("%s.s3d", textBox_->getText().c_str());
00091                         if (ClientSave::saveClient(S3D::getSaveFile(saveFile.c_str())))
00092                         {
00093                                 ChannelText text("info", 
00094                                         LANG_RESOURCE_1("SAVED_AS", "Saved as \"{0}\"", saveFile));
00095                                 ChannelManager::showText(ScorchedClient::instance()->getContext(), text);
00096                         }
00097                         else
00098                         {
00099                                 ChannelText text("info", LANG_RESOURCE("SAVE_FAILED", "Save failed"));
00100                                 ChannelManager::showText(ScorchedClient::instance()->getContext(), text);
00101                         }
00102                         GLWWindowManager::instance()->hideWindow(id_);
00103                 }
00104         }
00105         else if (id == cancelId_)
00106         {
00107                 GLWWindowManager::instance()->hideWindow(id_);
00108         }
00109 }
00110 

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