Changeset 167
- Timestamp:
- 10/03/2008 07:39:43 AM (3 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
-
MainFrame.cpp (modified) (2 diffs)
-
configuration.cpp (modified) (4 diffs)
-
configuration.h (modified) (1 diff)
-
highscores_dialog.cpp (modified) (4 diffs)
-
highscores_dialog.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/MainFrame.cpp
r166 r167 541 541 542 542 if (settings_dialog->ShowModal()!=wxID_OK) { 543 delete settings_dialog; 543 544 return; 544 545 } … … 1017 1018 date = now.FormatDate().mb_str(); 1018 1019 date += " "; 1019 date += now.FormatISOTime().SubString(0, 5).mb_str();1020 date += now.FormatISOTime().SubString(0,4).mb_str(); 1020 1021 1021 1022 int rank = m_config->submitHighscore(score, name, date); -
trunk/src/configuration.cpp
r163 r167 21 21 #include <iostream> 22 22 #include <cstdlib> // used in the back-compatibility code 23 #include <sstream> 23 24 #include "configuration.h" 24 25 #include "../config.h" … … 103 104 string date,hour,name; 104 105 HighscoreItem temp_item; 106 107 temp_chr = file->get(); 108 file->unget(); 109 105 110 while(file->good()) { 106 111 temp_chr = file->get(); … … 323 328 return 0; 324 329 } 330 save(); 325 331 return place; 326 332 } … … 331 337 return ptr; 332 338 } 339 340 void Configuration::clearHighscores() 341 { 342 m_highscores.clear(); 343 save(); 344 } 345 346 void Configuration::setHighscoresSize(int size) 347 { 348 349 std::ostringstream o; 350 o << size; 351 m_settings["highscore-list-size"] = o.str(); 352 353 while (m_highscores.size()>size) { 354 m_highscores.pop_back(); 355 } 356 357 save(); 358 } -
trunk/src/configuration.h
r161 r167 75 75 76 76 const HighscoresList* getHighscores() const; 77 78 void clearHighscores(); 79 80 void setHighscoresSize(int size); 77 81 private: 78 82 /** -
trunk/src/highscores_dialog.cpp
r166 r167 68 68 void HighscoresDialog::loadData() 69 69 { 70 highscoreslist->DeleteAllItems(); 70 71 const configuration::HighscoresList *list = m_config->getHighscores(); 71 72 … … 110 111 top_sizer->Add(highscoreslist, 1, wxALL, 10); 111 112 112 top_sizer->Add( 113 new wxButton(this,wxID_CLOSE), 114 0, //no streching 115 wxALL, //we want border around everything 116 10); 117 118 SetAutoLayout(true); 113 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL ); 114 115 wxSizerFlags flags = wxSizerFlags().Border(wxALL & ~wxLEFT, 10); 116 117 button_sizer->AddStretchSpacer(); 118 button_sizer->Add(new wxButton(this,wxID_CLEAR),flags); 119 button_sizer->Add(new wxButton(this,ID_CONFIGURE,wxT("Configure")),flags); 120 button_sizer->Add( new wxButton(this,wxID_CLOSE), flags); 121 122 top_sizer->Add(button_sizer,0,wxEXPAND); 123 119 124 SetSizer(top_sizer); 120 121 top_sizer->Fit(this);122 125 top_sizer->SetSizeHints(this); 123 124 Layout();125 126 } 126 127 … … 129 130 { 130 131 Connect(wxID_CLOSE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(HighscoresDialog::onClose)); 131 } 132 132 133 Connect(wxID_CLEAR, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(HighscoresDialog::onClear)); 134 Connect(ID_CONFIGURE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(HighscoresDialog::onConfigure)); 135 } 133 136 void HighscoresDialog::onClose(wxCommandEvent& event) 134 137 { … … 136 139 } 137 140 141 void HighscoresDialog::onConfigure(wxCommandEvent& event) 142 { 143 HighscoresSettingsDialog *dialog = new HighscoresSettingsDialog(this, m_config); 144 145 if (dialog->ShowModal() == wxID_OK) { 146 loadData(); 147 } 148 149 delete dialog; 150 } 151 152 void HighscoresDialog::onClear(wxCommandEvent& event) 153 { 154 int answer = wxMessageBox( 155 wxT("Are you sure you want to clear the Highscores table?\nThis action cannot be reversed."), 156 wxT("Are You Sure?"), 157 wxYES | wxNO, 158 this); 159 160 if (answer == wxYES) { 161 m_config->clearHighscores(); 162 loadData(); 163 } 164 } 165 166 167 HighscoresSettingsDialog::HighscoresSettingsDialog(wxWindow* parent, configuration::Configuration* config) : 168 wxDialog(parent, wxID_ANY, wxT("Highscores Table Settings"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) 169 { 170 this->m_config = config; 171 doLayout(); 172 173 Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(HighscoresSettingsDialog::onOk)); 174 } 175 176 void HighscoresSettingsDialog::doLayout() 177 { 178 wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL); 179 180 wxBoxSizer* size_sizer = new wxBoxSizer(wxHORIZONTAL); 181 182 size_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("High score table size:")), wxSizerFlags().Border(wxALL,10)); 183 184 int size = atoi(m_config->get("highscore-list-size").c_str()); 185 spin_ctrl = new wxSpinCtrl(this, wxID_ANY); 186 spin_ctrl->SetRange(10,200); 187 spin_ctrl->SetValue(size); 188 189 size_sizer->Add(spin_ctrl,wxSizerFlags().Border(wxALL & ~wxLEFT,10)); 190 191 top_sizer->Add(size_sizer); 192 top_sizer->Add(CreateButtonSizer(wxOK|wxCANCEL), 1, wxBOTTOM, 10); 193 194 SetSizer(top_sizer); 195 top_sizer->SetSizeHints(this); 196 } 197 198 void HighscoresSettingsDialog::onOk(wxCommandEvent& event) { 199 int size = spin_ctrl->GetValue(); 200 m_config->setHighscoresSize(size); 201 event.Skip(); 202 } -
trunk/src/highscores_dialog.h
r165 r167 25 25 #include <wx/dialog.h> 26 26 #include <wx/listctrl.h> 27 #include <wx/spinctrl.h> 27 28 28 29 namespace highscores_dialog { … … 34 35 35 36 void onClose(wxCommandEvent& event); 37 void onClear(wxCommandEvent& event); 38 void onConfigure(wxCommandEvent& event); 36 39 private: 37 40 void createControls(); … … 46 49 }; 47 50 51 52 class HighscoresSettingsDialog : public wxDialog 53 { 54 public: 55 HighscoresSettingsDialog(wxWindow* parent, configuration::Configuration* config); 56 57 void onOk(wxCommandEvent& event); 58 private: 59 void doLayout(); 60 wxSpinCtrl *spin_ctrl; 61 62 configuration::Configuration* m_config; 63 }; 64 65 66 enum { 67 ID_CONFIGURE, 68 }; 69 48 70 } 49 71
Note: See TracChangeset
for help on using the changeset viewer.
