SettingsDialog.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2003
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 <wxdialogs/DisplayDialog.h>
00022 #include <wxdialogs/MainDialog.h>
00023 #include <wxdialogs/OptionEntrySetter.h>
00024 #include <landscapedef/LandscapeDefinitionsBase.h>
00025 #include <tankai/TankAINames.h>
00026 #include <common/OptionsGame.h>
00027 #include <common/Defines.h>
00028 #include <wx/wx.h>
00029 #include <wx/image.h>
00030 #include <wx/utils.h>
00031 #include <wx/notebook.h>
00032 #include <wx/textctrl.h>
00033 
00034 extern char scorched3dAppName[128];
00035 
00036 class SettingsFrame: public wxDialog
00037 {
00038 public:
00039         SettingsFrame(bool server, OptionsGame &context);
00040 
00041         virtual bool TransferDataToWindow();
00042         virtual bool TransferDataFromWindow();
00043 
00044 protected:
00045         OptionsGame &context_;
00046         wxNotebook *book_;
00047         wxPanel *mainPanel_;
00048         wxPanel *ecoPanel_;
00049         wxPanel *envPanel_;
00050         wxPanel *landPanel_;
00051         wxPanel *playersPanel_;
00052         wxPanel *motdPanel_;
00053 
00054         std::list<OptionEntrySetter> setters_;
00055 
00056         void setupPlayers();
00057         void onMaxPlayerChange(wxCommandEvent &event);
00058         void onSelectAll(wxCommandEvent &event);
00059         void onDeselectAll(wxCommandEvent &event);
00060 
00061 private:
00062         DECLARE_EVENT_TABLE()
00063 
00064         LandscapeDefinitionsBase landscapeDefinitions;
00065         TankAINames tankAIStore;
00066 
00067         wxTextCtrl *IDC_MOTD_CTRL;
00068         wxButton *IDC_SELECTALL_CTRL;
00069         wxButton *IDC_DESELECTALL_CTRL;
00070         wxCheckBox *IDC_CYCLEMAPS_CTRL;
00071         wxCheckBox **landscapes;
00072         wxComboBox *IDC_SERVER_MIN_PLAYERS_CTRL;
00073         wxComboBox *IDC_SERVER_MAX_PLAYERS_CTRL;
00074         wxComboBox *IDC_SERVER_REMOVEBOT_PLAYERS_CTRL;
00075         wxComboBox **IDC_COMBO_PTYPE_CTRL;
00076         wxTextCtrl *IDC_EDIT3_CTRL;
00077         wxCheckBox *IDC_SERVER_RESIDUAL_CTRL;
00078 
00079         void createMainPanel(bool server);
00080         void createEcoPanel();
00081         void createEnvPanel();
00082         void createMotdPanel();
00083         void createLandPanel();
00084         void createPlayersPanel();
00085 };
00086 
00087 enum
00088 {
00089         IDC_SERVER_MAX_PLAYERS = 500,
00090         IDC_SELECTALL,
00091         IDC_DESELECTALL
00092 };
00093 
00094 BEGIN_EVENT_TABLE(SettingsFrame, wxDialog)
00095         EVT_TEXT(IDC_SERVER_MAX_PLAYERS,  SettingsFrame::onMaxPlayerChange)
00096         EVT_BUTTON(IDC_SELECTALL,  SettingsFrame::onSelectAll)
00097         EVT_BUTTON(IDC_DESELECTALL,  SettingsFrame::onDeselectAll)
00098 END_EVENT_TABLE()
00099 
00100 void SettingsFrame::createMainPanel(bool server)
00101 {
00102         mainPanel_ = new wxPanel(book_, -1);
00103         book_->AddPage(mainPanel_, wxT("Main"));
00104         wxSizer *mainPanelSizer = new wxBoxSizer(wxVERTICAL);
00105         wxSizer *sizer = new wxFlexGridSizer(2, 2);
00106         mainPanelSizer->Add(sizer, 0, wxALL | wxALIGN_CENTER, 10);
00107 
00108         setters_.push_back(
00109                 OptionEntrySetterUtil::createOtherSetter(
00110                         mainPanel_, sizer, context_.getTeamBallanceEntry()));
00111         setters_.push_back(
00112                 OptionEntrySetterUtil::createOtherSetter(
00113                         mainPanel_, sizer, context_.getTeamsEntry()));
00114         setters_.push_back(
00115                 OptionEntrySetterUtil::createOtherSetter(
00116                         mainPanel_, sizer, context_.getNoRoundsEntry()));
00117         setters_.push_back(
00118                 OptionEntrySetterUtil::createOtherSetter(
00119                         mainPanel_, sizer, context_.getNoMaxRoundTurnsEntry()));
00120         setters_.push_back(
00121                 OptionEntrySetterUtil::createOtherSetter(
00122                         mainPanel_, sizer, context_.getTurnTypeEntry()));       
00123         setters_.push_back(
00124                 OptionEntrySetterUtil::createOtherSetter(
00125                         mainPanel_, sizer, context_.getKeepAliveTimeoutTimeEntry()));   
00126         setters_.push_back(
00127                 OptionEntrySetterUtil::createOtherSetter(
00128                         mainPanel_, sizer, context_.getStartTimeEntry()));      
00129         setters_.push_back(
00130                 OptionEntrySetterUtil::createOtherSetter(
00131                         mainPanel_, sizer, context_.getShotTimeEntry()));       
00132         setters_.push_back(
00133                 OptionEntrySetterUtil::createOtherSetter(
00134                         mainPanel_, sizer, context_.getBuyingTimeEntry()));     
00135         setters_.push_back(
00136                 OptionEntrySetterUtil::createOtherSetter(
00137                         mainPanel_, sizer, context_.getIdleKickTimeEntry()));   
00138         setters_.push_back(
00139                 OptionEntrySetterUtil::createOtherSetter(
00140                         mainPanel_, sizer, context_.getIdleShotKickTimeEntry()));       
00141         setters_.push_back(
00142                 OptionEntrySetterUtil::createOtherSetter(
00143                         mainPanel_, sizer, context_.getModDownloadSpeedEntry()));       
00144 
00145         if (server) // Server only
00146         {
00147                 setters_.push_back(
00148                         OptionEntrySetterUtil::createOtherSetter(
00149                                 mainPanel_, sizer, context_.getServerPasswordEntry())); 
00150         }
00151 
00152         mainPanel_->SetAutoLayout(TRUE);
00153         mainPanel_->SetSizer(mainPanelSizer);
00154 }
00155 
00156 void SettingsFrame::createEcoPanel()
00157 {
00158         ecoPanel_ = new wxPanel(book_, -1);
00159         wxSizer *ecoPanelSizer = new wxBoxSizer(wxVERTICAL);
00160         wxSizer *sizer = new wxFlexGridSizer(2, 2);
00161         ecoPanelSizer->Add(sizer, 0, wxALL | wxALIGN_CENTER, 10);
00162 
00163         setters_.push_back(
00164                 OptionEntrySetterUtil::createOtherSetter(
00165                         ecoPanel_, sizer, context_.getBuyOnRoundEntry()));
00166         setters_.push_back(
00167                 OptionEntrySetterUtil::createOtherSetter(
00168                         ecoPanel_, sizer, context_.getEconomyEntry()));
00169         setters_.push_back(
00170                 OptionEntrySetterUtil::createOtherSetter(
00171                         ecoPanel_, sizer, context_.getMoneyWonPerAssistPointEntry()));
00172         setters_.push_back(
00173                 OptionEntrySetterUtil::createOtherSetter(
00174                         ecoPanel_, sizer, context_.getMoneyWonPerKillPointEntry()));
00175         setters_.push_back(
00176                 OptionEntrySetterUtil::createOtherSetter(
00177                         ecoPanel_, sizer, context_.getMoneyWonPerMultiKillPointEntry()));
00178         setters_.push_back(
00179                 OptionEntrySetterUtil::createOtherSetter(
00180                         ecoPanel_, sizer, context_.getMoneyWonPerHitPointEntry()));
00181         setters_.push_back(
00182                 OptionEntrySetterUtil::createOtherSetter(
00183                         ecoPanel_, sizer, context_.getStartMoneyEntry()));
00184         setters_.push_back(
00185                 OptionEntrySetterUtil::createOtherSetter(
00186                         ecoPanel_, sizer, context_.getMoneyWonForRoundEntry()));
00187         setters_.push_back(
00188                 OptionEntrySetterUtil::createOtherSetter(
00189                         ecoPanel_, sizer, context_.getMoneyPerRoundEntry()));
00190         setters_.push_back(
00191                 OptionEntrySetterUtil::createOtherSetter(
00192                         ecoPanel_, sizer, context_.getInterestEntry()));
00193         setters_.push_back(
00194                 OptionEntrySetterUtil::createOtherSetter(
00195                         ecoPanel_, sizer, context_.getScoreWonForRoundEntry()));
00196         setters_.push_back(
00197                 OptionEntrySetterUtil::createOtherSetter(
00198                         ecoPanel_, sizer, context_.getScoreWonForLivesEntry()));
00199         setters_.push_back(
00200                 OptionEntrySetterUtil::createOtherSetter(
00201                         ecoPanel_, sizer, context_.getMoneyWonForLivesEntry()));
00202         setters_.push_back(
00203                 OptionEntrySetterUtil::createOtherSetter(
00204                         ecoPanel_, sizer, context_.getScorePerKillEntry()));
00205         setters_.push_back(
00206                 OptionEntrySetterUtil::createOtherSetter(
00207                         ecoPanel_, sizer, context_.getScorePerAssistEntry()));
00208         setters_.push_back(
00209                 OptionEntrySetterUtil::createOtherSetter(
00210                         ecoPanel_, sizer, context_.getScorePerMoneyEntry()));
00211         setters_.push_back(
00212                 OptionEntrySetterUtil::createOtherSetter(
00213                         ecoPanel_, sizer, context_.getMoneyPerHealthPointEntry()));
00214         setters_.push_back(
00215                 OptionEntrySetterUtil::createOtherSetter(
00216                         ecoPanel_, sizer, context_.getGiveAllWeaponsEntry()));
00217 
00218         book_->AddPage(ecoPanel_, wxT("Eco"));
00219         ecoPanel_->SetAutoLayout(TRUE);
00220         ecoPanel_->SetSizer(ecoPanelSizer);
00221 }
00222 
00223 void SettingsFrame::createEnvPanel()
00224 {
00225         envPanel_ = new wxPanel(book_, -1);
00226         wxSizer *envPanelSizer = new wxBoxSizer(wxVERTICAL);
00227         wxSizer *sizer = new wxFlexGridSizer(2, 2);
00228         envPanelSizer->Add(sizer, 0, wxALL | wxALIGN_CENTER, 10);
00229 
00230         setters_.push_back(
00231                 OptionEntrySetterUtil::createOtherSetter(
00232                         envPanel_, sizer, context_.getWindForceEntry()));
00233         setters_.push_back(
00234                 OptionEntrySetterUtil::createOtherSetter(
00235                         envPanel_, sizer, context_.getWindTypeEntry()));
00236         setters_.push_back(
00237                 OptionEntrySetterUtil::createOtherSetter(
00238                         envPanel_, sizer, context_.getWallTypeEntry()));
00239         setters_.push_back(
00240                 OptionEntrySetterUtil::createOtherSetter(
00241                         envPanel_, sizer, context_.getWeapScaleEntry()));
00242         setters_.push_back(
00243                 OptionEntrySetterUtil::createOtherSetter(
00244                         envPanel_, sizer, context_.getStartArmsLevelEntry()));
00245         setters_.push_back(
00246                 OptionEntrySetterUtil::createOtherSetter(
00247                         envPanel_, sizer, context_.getEndArmsLevelEntry()));
00248         setters_.push_back(
00249                 OptionEntrySetterUtil::createOtherSetter(
00250                         envPanel_, sizer, context_.getMinFallingDistanceEntry()));
00251         setters_.push_back(
00252                 OptionEntrySetterUtil::createOtherSetter(
00253                         envPanel_, sizer, context_.getMaxClimbingDistanceEntry()));
00254         setters_.push_back(
00255                 OptionEntrySetterUtil::createOtherSetter(
00256                         envPanel_, sizer, context_.getResignModeEntry()));
00257         setters_.push_back(
00258                 OptionEntrySetterUtil::createOtherSetter(
00259                         envPanel_, sizer, context_.getMovementRestrictionEntry()));
00260         setters_.push_back(
00261                 OptionEntrySetterUtil::createOtherSetter(
00262                         envPanel_, sizer, context_.getPlayerLivesEntry()));
00263         setters_.push_back(
00264                 OptionEntrySetterUtil::createOtherSetter(
00265                         envPanel_, sizer, context_.getDelayedDefenseActivationEntry()));
00266 
00267         book_->AddPage(envPanel_, wxT("Env"));
00268         envPanel_->SetAutoLayout(TRUE);
00269         envPanel_->SetSizer(envPanelSizer);
00270 }
00271 
00272 void SettingsFrame::createMotdPanel()
00273 {
00274         motdPanel_ = new wxPanel(book_, -1);
00275         wxSizer *motdPanelSizer = new wxBoxSizer(wxVERTICAL);
00276 
00277         IDC_MOTD_CTRL = new wxTextCtrl(motdPanel_, -1, wxT(""), 
00278                 wxDefaultPosition, wxSize(380, 100), wxTE_MULTILINE);
00279         motdPanelSizer->Add(IDC_MOTD_CTRL, 1, wxGROW | wxALL, 10);
00280 
00281         book_->AddPage(motdPanel_, wxT("MOTD"));
00282         motdPanel_->SetAutoLayout(TRUE);
00283         motdPanel_->SetSizer(motdPanelSizer);
00284 }
00285 
00286 void SettingsFrame::createLandPanel()
00287 {
00288         landPanel_ = new wxPanel(book_, -1);
00289         wxSizer *landPanelSizer = new wxBoxSizer(wxVERTICAL);
00290 
00291         landscapes = new wxCheckBox*[landscapeDefinitions.getAllLandscapes().size()];
00292 
00293         wxScrolledWindow *scrolledWindow = new wxScrolledWindow(landPanel_, -1, 
00294                 wxDefaultPosition, wxSize(225, 200));
00295 
00296         wxSizer *sizer = new wxFlexGridSizer(3, 3);
00297         int i = 0;
00298         std::list<LandscapeDefinitionsEntry> &defns =
00299                 landscapeDefinitions.getAllLandscapes();
00300         std::list<LandscapeDefinitionsEntry>::iterator itor;
00301         for (itor = defns.begin();
00302                  itor != defns.end();
00303                  itor++, i++)
00304         {
00305                 LandscapeDefinitionsEntry &dfn = *itor;
00306                 wxBoxSizer *boxSizer = new wxBoxSizer(wxVERTICAL);
00307 
00308                 std::string fileName = S3D::getDataFile(S3D::formatStringBuffer("data/landscapes/%s", dfn.picture.c_str()));
00309                 if (!::wxFileExists(convertString(fileName)))
00310                 {
00311                         fileName = S3D::getDataFile("data/landscapes/picture-none.bmp");
00312                 }
00313 
00314                 wxImage image;
00315                 if (image.LoadFile(convertString(fileName), wxBITMAP_TYPE_BMP))
00316                 {
00317                         wxBitmap bitmap(image);
00318                         wxStaticBitmap *staticBmp = new wxStaticBitmap(scrolledWindow, -1, bitmap);
00319                         staticBmp->SetToolTip(wxString(dfn.description.c_str(), wxConvUTF8));
00320                         boxSizer->Add(staticBmp, 0, wxALL, 2);
00321                 }
00322 
00323                 landscapes[i] = new wxCheckBox(scrolledWindow, -1, wxString(dfn.name.c_str(), wxConvUTF8));
00324                 boxSizer->Add(landscapes[i]);
00325 
00326                 sizer->Add(boxSizer, 0, wxALL, 5);
00327         }
00328 
00329         scrolledWindow->SetAutoLayout(TRUE);
00330         scrolledWindow->SetSizer(sizer);
00331         wxSize minSize = sizer->CalcMin();
00332         scrolledWindow->SetScrollbars(10, 10, 
00333                 (minSize.GetWidth() + 10) / 10, (minSize.GetHeight() + 10) / 10);
00334         landPanelSizer->Add(scrolledWindow, 1, wxGROW | wxALL, 10);
00335 
00336         IDC_CYCLEMAPS_CTRL = new wxCheckBox(landPanel_, -1, wxT("Linearly cycle maps"));
00337         landPanelSizer->Add(IDC_CYCLEMAPS_CTRL, 0, wxALIGN_CENTER);
00338 
00339         wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
00340         IDC_SELECTALL_CTRL = new wxButton(landPanel_, IDC_SELECTALL, wxT("Select All"));
00341         IDC_DESELECTALL_CTRL = new wxButton(landPanel_, IDC_DESELECTALL, wxT("Deselect All"));
00342         buttonSizer->Add(IDC_SELECTALL_CTRL, 0, wxALL, 10);
00343         buttonSizer->Add(IDC_DESELECTALL_CTRL, 0, wxALL, 10);
00344         landPanelSizer->Add(buttonSizer, 0, wxALIGN_CENTER);
00345 
00346         book_->AddPage(landPanel_, wxT("Land"));
00347         landPanel_->SetAutoLayout(TRUE);
00348 #if wxCHECK_VERSION(2,6,0)
00349         landPanel_->SetSizer(landPanelSizer);
00350 #else
00351 #if wxCHECK_VERSION(2,5,0)
00352 #else
00353         landPanel_->SetSizer(landPanelSizer);
00354 #endif
00355 #endif
00356 }
00357 
00358 void SettingsFrame::createPlayersPanel()
00359 {
00360         IDC_COMBO_PTYPE_CTRL = new wxComboBox*[24];
00361 
00362         playersPanel_ = new wxPanel(book_, -1);
00363         wxSizer *playersPanelSizer = new wxBoxSizer(wxVERTICAL);
00364 
00365         wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
00366         playersPanelSizer->Add(buttonSizer, 0, wxALIGN_CENTER | wxTOP, 10);
00367 
00368         buttonSizer->Add(new wxStaticText(playersPanel_, -1,
00369                 wxT("Min Players :")), 0, wxALIGN_CENTER | wxRIGHT | wxLEFT, 5);
00370         buttonSizer->Add(IDC_SERVER_MIN_PLAYERS_CTRL = 
00371                 new wxComboBox(playersPanel_, -1,
00372                 wxT(""),
00373                 wxDefaultPosition, wxSize(70, -1),
00374                 0, 0, wxCB_READONLY), 0, wxALIGN_CENTER);
00375         buttonSizer->Add(new wxStaticText(playersPanel_, -1,
00376                 wxT("Max Players :")), 0, wxALIGN_CENTER | wxRIGHT | wxLEFT, 5);
00377         buttonSizer->Add(IDC_SERVER_MAX_PLAYERS_CTRL = 
00378                 new wxComboBox(playersPanel_, IDC_SERVER_MAX_PLAYERS,
00379                 wxT(""),
00380                 wxDefaultPosition, wxSize(70, -1),
00381                 0, 0, wxCB_READONLY), 0, wxALIGN_CENTER);       
00382 
00383         wxBoxSizer *buttonSizer2 = new wxBoxSizer(wxHORIZONTAL);
00384         playersPanelSizer->Add(buttonSizer2, 0, wxALIGN_CENTER | wxTOP, 10);
00385         buttonSizer2->Add(new wxStaticText(playersPanel_, -1,
00386                 wxT("Remove bots after players :")), 0, wxALIGN_CENTER | wxRIGHT | wxLEFT, 5);
00387         buttonSizer2->Add(IDC_SERVER_REMOVEBOT_PLAYERS_CTRL = 
00388                 new wxComboBox(playersPanel_, -1,
00389                 wxT(""),
00390                 wxDefaultPosition, wxDefaultSize,
00391                 0, 0, wxCB_READONLY), 0, wxALIGN_CENTER);
00392 
00393         IDC_SERVER_RESIDUAL_CTRL = new wxCheckBox(playersPanel_, -1, 
00394                 wxT("Players are persistent for game"));
00395         playersPanelSizer->Add(IDC_SERVER_RESIDUAL_CTRL, 0, wxALIGN_CENTER | wxTOP, 10);
00396                 
00397         wxSizer *sizer = new wxGridSizer(3, 3);
00398         playersPanelSizer->Add(sizer, 0, wxALL | wxALIGN_CENTER, 10);
00399 
00400         for (int i=0; i<24; i++)
00401         {
00402                 char buffer[256];
00403                 sprintf(buffer, "%i", (i+1));
00404         
00405                 wxBoxSizer *playerSizer = new wxBoxSizer(wxHORIZONTAL);
00406                 playerSizer->Add(new wxStaticText(playersPanel_, -1, wxString(buffer, wxConvUTF8)));
00407                 playerSizer->Add(IDC_COMBO_PTYPE_CTRL[i] = 
00408                         new wxComboBox(playersPanel_, -1,
00409                         wxT(""),
00410                         wxDefaultPosition, wxSize(70, -1),
00411                         0, 0, wxCB_READONLY));
00412                 sizer->Add(playerSizer, 0, wxALIGN_RIGHT | wxALL, 2);
00413         }
00414 
00415         wxBoxSizer *botSizer = new wxBoxSizer(wxHORIZONTAL);
00416         playersPanelSizer->Add(botSizer, 0, wxALIGN_CENTER | wxALL, 10);
00417         botSizer->Add(new wxStaticText(playersPanel_, -1,
00418                 wxT("Bot Name Prefix :")), 0, wxALIGN_CENTER | wxRIGHT | wxLEFT, 5);
00419         botSizer->Add(IDC_EDIT3_CTRL = 
00420                 new wxTextCtrl(playersPanel_, -1,
00421                 wxT(""),
00422                 wxDefaultPosition, wxSize(100, -1)), 
00423                 0, wxALIGN_CENTER);
00424 
00425         book_->AddPage(playersPanel_, wxT("Players"));
00426         playersPanel_->SetAutoLayout(TRUE);
00427         playersPanel_->SetSizer(playersPanelSizer);
00428 }
00429 
00430 SettingsFrame::SettingsFrame(bool server, OptionsGame &context) :
00431         wxDialog(getMainDialog(), -1, wxString(scorched3dAppName,wxConvUTF8),
00432                 wxDefaultPosition, wxDefaultSize),
00433         context_(context), playersPanel_(0)
00434 {
00435 #ifdef _WIN32
00436         // Set the frame's icon
00437         wxIcon icon(convertString(S3D::getDataFile("data/windows/tank2.ico")), wxBITMAP_TYPE_ICO);
00438         SetIcon(icon);
00439 #endif
00440 
00441         // Create the positioning sizer
00442         wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
00443 
00444         // Create all the display controls
00445         book_ = new wxNotebook(this, -1);
00446 #if wxCHECK_VERSION(2,6,0)
00447         wxBoxSizer *nbs = new wxBoxSizer(wxVERTICAL);
00448         nbs->Add(book_);
00449 #else
00450         wxNotebookSizer *nbs = new wxNotebookSizer(book_);
00451 #endif
00452 
00453         // Re-read just in case a new mod has been loaded
00454         DIALOG_ASSERT(landscapeDefinitions.readLandscapeDefinitions());
00455         tankAIStore.clearAIs();
00456         DIALOG_ASSERT(tankAIStore.loadAIs());
00457 
00458         createMainPanel(server);
00459         createEcoPanel();
00460         createEnvPanel();
00461         if (server) createPlayersPanel();
00462         createMotdPanel();
00463         createLandPanel();
00464 
00465         topsizer->Add(nbs, 0, wxALL, 10);
00466 
00467         // Ok and cancel boxes
00468         wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
00469         wxButton *cancelButton = new wxButton(this, wxID_CANCEL, wxT("&Cancel"));
00470         wxButton *okButton = new wxButton(this, wxID_OK, wxT("&Ok"));
00471         buttonSizer->Add(cancelButton, 0, wxALL, 10);
00472         buttonSizer->Add(okButton, 0, wxALL, 10);
00473         topsizer->Add(buttonSizer, 0, wxALIGN_RIGHT);
00474         okButton->SetDefault();
00475                 
00476         // use the sizer for layout
00477         SetSizer(topsizer); 
00478         topsizer->SetSizeHints(this); // set size hints to honour minimum size
00479 
00480         CentreOnScreen();
00481 }
00482 
00483 void SettingsFrame::onSelectAll(wxCommandEvent &event)
00484 {
00485         std::list<LandscapeDefinitionsEntry> &defns =
00486                 landscapeDefinitions.getAllLandscapes();
00487         std::list<LandscapeDefinitionsEntry>::iterator itor = 
00488                 defns.begin();
00489         for (int i = 0; i<(int) defns.size(); i++, itor++)
00490         {
00491                 landscapes[i]->SetValue(true);
00492         }
00493 }
00494 
00495 void SettingsFrame::onDeselectAll(wxCommandEvent &event)
00496 {
00497         std::list<LandscapeDefinitionsEntry> &defns =
00498                 landscapeDefinitions.getAllLandscapes();
00499         std::list<LandscapeDefinitionsEntry>::iterator itor =
00500                 defns.begin();  
00501         for (int i = 0; i<(int) defns.size(); i++, itor++)
00502         {           
00503                 landscapes[i]->SetValue(false);
00504         }
00505 }
00506 
00507 void SettingsFrame::onMaxPlayerChange(wxCommandEvent &event)
00508 {
00509         setupPlayers();
00510 }
00511 
00512 void SettingsFrame::setupPlayers()
00513 {
00514         int maxPlayers = 10;
00515         sscanf(IDC_SERVER_MAX_PLAYERS_CTRL->GetValue().mb_str(wxConvUTF8), "%i", &maxPlayers);
00516         context_.getNoMaxPlayersEntry().setValue(maxPlayers);
00517 
00518         for (int i=0; i<24; i++)
00519         {
00520                 IDC_COMBO_PTYPE_CTRL[i]->Enable((i < context_.getNoMaxPlayers()));
00521         }
00522 }
00523 
00524 bool SettingsFrame::TransferDataToWindow()
00525 {
00526         // Player tab
00527         if (playersPanel_)
00528         {
00529                 IDC_EDIT3_CTRL->
00530                         SetValue(wxString(context_.getBotNamePrefix(), wxConvUTF8));
00531                 IDC_EDIT3_CTRL->SetToolTip(
00532                         wxString("The text prefixed onto any player that is a bot.", wxConvUTF8));
00533 
00534                 // Min max players are rounds combos
00535                 char buffer[25];
00536                 int i;
00537                 for (i=24; i>=0; i--)
00538                 {
00539                         char string[20];
00540                         snprintf(string, 20, "%i", i);
00541 
00542                         if (i > 1)
00543                         {
00544                                 IDC_SERVER_MIN_PLAYERS_CTRL->Append(wxString(string, wxConvUTF8));
00545                                 IDC_SERVER_REMOVEBOT_PLAYERS_CTRL->Append(wxString(string, wxConvUTF8));
00546                         }
00547                         IDC_SERVER_MAX_PLAYERS_CTRL->Append(wxString(string, wxConvUTF8));
00548                 }
00549                 IDC_SERVER_REMOVEBOT_PLAYERS_CTRL->Append(wxT("0"));
00550 
00551                 snprintf(buffer, 25, "%i", context_.getNoMinPlayers());
00552                 IDC_SERVER_MIN_PLAYERS_CTRL->SetValue(wxString(buffer, wxConvUTF8));
00553                 IDC_SERVER_MIN_PLAYERS_CTRL->SetToolTip(
00554                         wxString("The number of players that must be on the server before a game starts.", wxConvUTF8));
00555 
00556                 snprintf(buffer, 25, "%i", context_.getNoMaxPlayers());
00557                 IDC_SERVER_MAX_PLAYERS_CTRL->SetValue(wxString(buffer, wxConvUTF8));
00558                 IDC_SERVER_MAX_PLAYERS_CTRL->SetToolTip(
00559                         wxString("The maximum number of players that can be on the server.", wxConvUTF8));
00560 
00561                 snprintf(buffer, 25, "%i", context_.getRemoveBotsAtPlayers());
00562                 IDC_SERVER_REMOVEBOT_PLAYERS_CTRL->SetValue(wxString(buffer, wxConvUTF8));
00563                 IDC_SERVER_REMOVEBOT_PLAYERS_CTRL->SetToolTip(
00564                         wxString("The number of players to allow before remvoing bots.", wxConvUTF8));
00565 
00566                 IDC_SERVER_RESIDUAL_CTRL->SetValue(context_.getResidualPlayers());
00567                 IDC_SERVER_RESIDUAL_CTRL->SetToolTip(
00568                         wxString("Players re-connect with the same money and weapons.", wxConvUTF8));
00569 
00570                 // Reload the AIs in case a new mod has been loaded
00571                 std::list<std::string> &ais = tankAIStore.getAis();
00572                 for (int i=0; i<24; i++)
00573                 {
00574                         std::list<std::string>::iterator itor;
00575                         for (itor = ais.begin();
00576                                 itor != ais.end();
00577                                 itor++)
00578                         {
00579                                 IDC_COMBO_PTYPE_CTRL[i]->Append(
00580                                         wxString((*itor).c_str(), wxConvUTF8));
00581                         }
00582                         IDC_COMBO_PTYPE_CTRL[i]->SetValue(
00583                                 wxString(context_.getPlayerType(i).getValue(), wxConvUTF8));
00584                 }
00585                 setupPlayers();
00586         }
00587 
00588         // Land 
00589         {
00590                 std::list<LandscapeDefinitionsEntry> &defns =
00591                         landscapeDefinitions.getAllLandscapes();
00592                 std::list<LandscapeDefinitionsEntry>::iterator itor = 
00593                         defns.begin();
00594                 for (int i = 0; i<(int) defns.size(); i++, itor++)
00595                 {
00596                         landscapes[i]->SetValue(
00597                                 landscapeDefinitions.landscapeEnabled(
00598                                         context_,
00599                                         (*itor).name.c_str()));
00600                 }
00601                 IDC_CYCLEMAPS_CTRL->SetValue(context_.getCycleMaps());
00602                 IDC_CYCLEMAPS_CTRL->SetToolTip(
00603                         wxString(context_.getCycleMapsEntry().getDescription(), wxConvUTF8));
00604         }
00605 
00606         // MOTD
00607         {
00608                 IDC_MOTD_CTRL->SetValue(
00609                         wxString(context_.getMOTD(), wxConvUTF8));
00610                 IDC_MOTD_CTRL->SetToolTip(
00611                         wxString("The Message Of The Day.", wxConvUTF8));
00612         }
00613 
00614         OptionEntrySetterUtil::updateControls(setters_);
00615 
00616         return true;
00617 }
00618 
00619 bool SettingsFrame::TransferDataFromWindow()
00620 {
00621         // Players
00622         if (playersPanel_)
00623         {
00624                 context_.getBotNamePrefixEntry().setValue(
00625                         std::string(IDC_EDIT3_CTRL->GetValue().mb_str(wxConvUTF8)));
00626 
00627                 // Read min + max players
00628                 int minPlayers = 2;
00629                 sscanf(IDC_SERVER_MIN_PLAYERS_CTRL->GetValue().mb_str(wxConvUTF8), 
00630                         "%i", &minPlayers);
00631                 int maxPlayers = 10;
00632                 sscanf(IDC_SERVER_MAX_PLAYERS_CTRL->GetValue().mb_str(wxConvUTF8), 
00633                         "%i", &maxPlayers);
00634                 int maxBotPlayers = 10;
00635                 sscanf(IDC_SERVER_REMOVEBOT_PLAYERS_CTRL->GetValue().mb_str(wxConvUTF8), 
00636                         "%i", &maxBotPlayers);
00637 
00638                 context_.getRemoveBotsAtPlayersEntry().setValue(maxBotPlayers);
00639                 context_.getNoMinPlayersEntry().setValue(minPlayers);
00640                 context_.getNoMaxPlayersEntry().setValue(maxPlayers);
00641 
00642                 context_.getResidualPlayersEntry().setValue(
00643                                 IDC_SERVER_RESIDUAL_CTRL->GetValue());
00644 
00645                 for (int i=0; i<24; i++)
00646                 {
00647                         context_.getPlayerType(i).setValue( 
00648                                 std::string(IDC_COMBO_PTYPE_CTRL[i]->GetValue().mb_str(wxConvUTF8)));
00649                 }
00650         }
00651 
00652         // Land
00653         {
00654                 std::string landscapesString;
00655                 std::list<LandscapeDefinitionsEntry> &defns =
00656                         landscapeDefinitions.getAllLandscapes();
00657                 std::list<LandscapeDefinitionsEntry>::iterator itor = 
00658                         defns.begin();
00659                 for (int i = 0; i<(int) defns.size(); i++, itor++)
00660                 {
00661                         if (landscapes[i]->GetValue())
00662                         {
00663                                 if (!landscapesString.empty()) landscapesString += ":";
00664                                 landscapesString += (*itor).name.c_str();
00665                         }
00666                 }
00667                 context_.getLandscapesEntry().setValue(landscapesString.c_str());
00668                 context_.getCycleMapsEntry().setValue(
00669                         IDC_CYCLEMAPS_CTRL->GetValue());
00670         }
00671 
00672         // MOTD
00673         {
00674                 context_.getMOTDEntry().setValue(
00675                         std::string(IDC_MOTD_CTRL->GetValue().mb_str(wxConvUTF8)));
00676         }
00677 
00678         OptionEntrySetterUtil::updateEntries(setters_);
00679 
00680         return true;
00681 }
00682 
00683 bool showSettingsDialog(bool server, OptionsGame &context)
00684 {
00685         // Set the current mod
00686         std::string modValue = S3D::getDataFileMod();
00687         S3D::setDataFileMod(context.getMod());
00688 
00689         // Show the settings
00690         SettingsFrame frame(server, context);
00691         bool result = (frame.ShowModal() == wxID_OK);
00692 
00693         // Reset the mod
00694         S3D::setDataFileMod(modValue.c_str());
00695 
00696         return result;
00697 }

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