1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
4 // This file is part of Scorched3D.
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #include <dialogs/SettingsSelectDialog.h>
22 #include <dialogs/SettingsSubSelectDialog.h>
23 #include <dialogs/MsgBoxDialog.h>
24 #include <common/Logger.h>
25 #include <GLW/GLWWindowManager.h>
26 #include <GLW/GLWOptionEntry.h>
27 #include <client/ClientParams.h>
28 #include <client/ClientMain.h>
30 SettingsSelectDialog
*SettingsSelectDialog::instance_
= 0;
32 SettingsSelectDialog
*SettingsSelectDialog::instance()
36 instance_
= new SettingsSelectDialog
;
41 SettingsSelectDialog::SettingsSelectDialog() :
42 GLWWindow("", 700.0f
, 540.0f
, 0, "")
44 GLWPanel
*controlPanel
= new GLWPanel(0.0f
, 0.0f
, 0.0f
, 0.0f
, false, false);
47 GLWOptionEntry::createEntry(
48 controls_
, controlPanel
, options_
.getNoMaxPlayersEntry());
49 GLWOptionEntry::createEntry(
50 controls_
, controlPanel
, options_
.getTeamsEntry());
51 GLWOptionEntry::createEntry(
52 controls_
, controlPanel
, options_
.getTurnTypeEntry());
53 GLWOptionEntry::createEntry(
54 controls_
, controlPanel
, options_
.getModEntry());
57 // Gotta love layout...oooo
58 controlPanel
->setGridWidth(2);
59 controlPanel
->setLayout(GLWPanel::LayoutGrid
);
61 GLWPanel
*topPanel
= new GLWPanel(0.0f
, 0.0f
, 0.0f
, 0.0f
, true, true);
62 topPanel
->addWidget(controlPanel
);
63 GLWButton
*advancedButton
= new GLWTextButton(LANG_RESOURCE("ADVANCED_OPTIONS", "Advanced Options"),
64 0.0f
, 0.0f
, 200.0f
, this,
65 GLWButton::ButtonFlagCenterX
);
66 advancedId_
= advancedButton
->getId();
67 topPanel
->addWidget(advancedButton
, 0, AlignRight
| SpaceAll
, 10.0f
);
68 topPanel
->setLayout(GLWPanel::LayoutVerticle
);
69 addWidget(topPanel
, 0, SpaceAll
, 10.0f
);
71 GLWPanel
*buttonPanel
= new GLWPanel(0.0f
, 0.0f
, 0.0f
, 0.0f
, false, false);
72 GLWButton
*cancelButton
= new GLWTextButton(LANG_RESOURCE("CANCEL", "Cancel"), 0.0f
, 0.0f
, 105, this,
73 GLWButton::ButtonFlagCancel
| GLWButton::ButtonFlagCenterX
);
74 cancelId_
= cancelButton
->getId();
75 buttonPanel
->addWidget(cancelButton
, 0, SpaceRight
, 10.0f
);
76 GLWButton
*okButton
= new GLWTextButton(LANG_RESOURCE("OK", "Ok"), 0.0f
, 0.0f
, 55, this,
77 GLWButton::ButtonFlagOk
| GLWButton::ButtonFlagCenterX
);
78 okId_
= okButton
->getId();
79 buttonPanel
->addWidget(okButton
);
80 buttonPanel
->setLayout(GLWPanel::LayoutHorizontal
);
81 addWidget(buttonPanel
, 0, AlignRight
| SpaceLeft
| SpaceRight
| SpaceBottom
, 10.0f
);
83 setLayout(GLWPanel::LayoutVerticle
);
87 SettingsSelectDialog::~SettingsSelectDialog()
91 void SettingsSelectDialog::display()
93 std::string singlecustom
= S3D::getSettingsFile("singlecustom.xml");
94 if (S3D::fileExists(singlecustom
))
96 if (!options_
.readOptionsFromFile(singlecustom
))
98 MsgBoxDialog::instance()->show(
99 LANG_RESOURCE("FAILED_T0_LOAD_OPTIONS", "Failed to load custom options"));
104 Logger::log(S3D::formatStringBuffer("Single custom file not found \"%s\"",
105 singlecustom
.c_str()));
108 GLWOptionEntry::updateControls(controls_
);
111 void SettingsSelectDialog::buttonDown(unsigned int id
)
113 if (id
== advancedId_
)
115 GLWOptionEntry::updateEntries(controls_
);
117 GLWWindowManager::instance()->showWindow(
118 SettingsSubSelectDialog::instance()->getId());
120 else if (id
== okId_
)
122 GLWWindowManager::instance()->hideWindow(id_
);
124 GLWOptionEntry::updateEntries(controls_
);
125 options_
.getNoMinPlayersEntry().setValue(options_
.getNoMaxPlayers());
127 std::string singlecustom
= S3D::getSettingsFile("singlecustom.xml");
128 options_
.writeOptionsToFile(singlecustom
);
130 ClientParams::instance()->reset();
131 ClientParams::instance()->setStartCustom(true);
132 ClientMain::startClient();
134 else if (id
== cancelId_
)
136 GLWWindowManager::instance()->hideWindow(id_
);