00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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