00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <dialogs/SettingsSelectDialog.h>
00022 #include <dialogs/SettingsSubSelectDialog.h>
00023 #include <dialogs/MsgBoxDialog.h>
00024 #include <common/Logger.h>
00025 #include <GLW/GLWWindowManager.h>
00026 #include <GLW/GLWOptionEntry.h>
00027 #include <client/ClientParams.h>
00028 #include <client/ClientMain.h>
00029
00030 SettingsSelectDialog *SettingsSelectDialog::instance_ = 0;
00031
00032 SettingsSelectDialog *SettingsSelectDialog::instance()
00033 {
00034 if (!instance_)
00035 {
00036 instance_ = new SettingsSelectDialog;
00037 }
00038 return instance_;
00039 }
00040
00041 SettingsSelectDialog::SettingsSelectDialog() :
00042 GLWWindow("", 700.0f, 540.0f, 0, "")
00043 {
00044 GLWPanel *controlPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00045
00046
00047 GLWOptionEntry::createEntry(
00048 controls_, controlPanel, options_.getNoMaxPlayersEntry());
00049 GLWOptionEntry::createEntry(
00050 controls_, controlPanel, options_.getTeamsEntry());
00051 GLWOptionEntry::createEntry(
00052 controls_, controlPanel, options_.getTurnTypeEntry());
00053 GLWOptionEntry::createEntry(
00054 controls_, controlPanel, options_.getModEntry());
00055
00056
00057
00058 controlPanel->setGridWidth(2);
00059 controlPanel->setLayout(GLWPanel::LayoutGrid);
00060
00061 GLWPanel *topPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, true, true);
00062 topPanel->addWidget(controlPanel);
00063 GLWButton *advancedButton = new GLWTextButton(LANG_RESOURCE("ADVANCED_OPTIONS", "Advanced Options"),
00064 0.0f, 0.0f, 200.0f, this,
00065 GLWButton::ButtonFlagCenterX);
00066 advancedId_ = advancedButton->getId();
00067 topPanel->addWidget(advancedButton, 0, AlignRight | SpaceAll, 10.0f);
00068 topPanel->setLayout(GLWPanel::LayoutVerticle);
00069 addWidget(topPanel, 0, SpaceAll, 10.0f);
00070
00071 GLWPanel *buttonPanel = new GLWPanel(0.0f, 0.0f, 0.0f, 0.0f, false, false);
00072 GLWButton *cancelButton = new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 0.0f, 0.0f, 105, this,
00073 GLWButton::ButtonFlagCancel | GLWButton::ButtonFlagCenterX);
00074 cancelId_ = cancelButton->getId();
00075 buttonPanel->addWidget(cancelButton, 0, SpaceRight, 10.0f);
00076 GLWButton *okButton = new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 0.0f, 0.0f, 55, this,
00077 GLWButton::ButtonFlagOk | GLWButton::ButtonFlagCenterX);
00078 okId_ = okButton->getId();
00079 buttonPanel->addWidget(okButton);
00080 buttonPanel->setLayout(GLWPanel::LayoutHorizontal);
00081 addWidget(buttonPanel, 0, AlignRight | SpaceLeft | SpaceRight | SpaceBottom, 10.0f);
00082
00083 setLayout(GLWPanel::LayoutVerticle);
00084 layout();
00085 }
00086
00087 SettingsSelectDialog::~SettingsSelectDialog()
00088 {
00089 }
00090
00091 void SettingsSelectDialog::display()
00092 {
00093 std::string singlecustom = S3D::getSettingsFile("singlecustom.xml");
00094 if (S3D::fileExists(singlecustom))
00095 {
00096 if (!options_.readOptionsFromFile(singlecustom))
00097 {
00098 MsgBoxDialog::instance()->show(
00099 LANG_RESOURCE("FAILED_T0_LOAD_OPTIONS", "Failed to load custom options"));
00100 }
00101 }
00102 else
00103 {
00104 Logger::log(S3D::formatStringBuffer("Single custom file not found \"%s\"",
00105 singlecustom.c_str()));
00106 }
00107
00108 GLWOptionEntry::updateControls(controls_);
00109 }
00110
00111 void SettingsSelectDialog::buttonDown(unsigned int id)
00112 {
00113 if (id == advancedId_)
00114 {
00115 GLWOptionEntry::updateEntries(controls_);
00116
00117 GLWWindowManager::instance()->showWindow(
00118 SettingsSubSelectDialog::instance()->getId());
00119 }
00120 else if (id == okId_)
00121 {
00122 GLWWindowManager::instance()->hideWindow(id_);
00123
00124 GLWOptionEntry::updateEntries(controls_);
00125 options_.getNoMinPlayersEntry().setValue(options_.getNoMaxPlayers());
00126
00127 std::string singlecustom = S3D::getSettingsFile("singlecustom.xml");
00128 options_.writeOptionsToFile(singlecustom);
00129
00130 ClientParams::instance()->reset();
00131 ClientParams::instance()->setStartCustom(true);
00132 ClientMain::startClient();
00133 }
00134 else if (id == cancelId_)
00135 {
00136 GLWWindowManager::instance()->hideWindow(id_);
00137 }
00138 }