Changeset 167


Ignore:
Timestamp:
10/03/2008 07:39:43 AM (3 years ago)
Author:
guyru
Message:
  • Add "Clear", "Configure" buttons to Highscores Dialog, add ability to resize the Highscores list and clear it.

Fix the date formatting when submitting to Highscores list.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/MainFrame.cpp

    r166 r167  
    541541 
    542542        if (settings_dialog->ShowModal()!=wxID_OK) { 
     543                delete settings_dialog; 
    543544                return; 
    544545        } 
     
    10171018        date = now.FormatDate().mb_str(); 
    10181019        date += " "; 
    1019         date += now.FormatISOTime().SubString(0,5).mb_str(); 
     1020        date += now.FormatISOTime().SubString(0,4).mb_str(); 
    10201021 
    10211022        int rank = m_config->submitHighscore(score, name, date); 
  • trunk/src/configuration.cpp

    r163 r167  
    2121#include <iostream> 
    2222#include <cstdlib> // used in the back-compatibility code 
     23#include <sstream> 
    2324#include "configuration.h" 
    2425#include "../config.h" 
     
    103104        string date,hour,name; 
    104105        HighscoreItem temp_item; 
     106 
     107        temp_chr = file->get(); 
     108        file->unget(); 
     109 
    105110        while(file->good()) { 
    106111                temp_chr = file->get(); 
     
    323328                return 0; 
    324329        } 
     330        save(); 
    325331        return place; 
    326332} 
     
    331337        return ptr; 
    332338} 
     339 
     340void Configuration::clearHighscores() 
     341{ 
     342        m_highscores.clear(); 
     343        save(); 
     344} 
     345 
     346void 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  
    7575 
    7676        const HighscoresList* getHighscores() const; 
     77 
     78        void clearHighscores(); 
     79 
     80        void setHighscoresSize(int size); 
    7781private: 
    7882        /** 
  • trunk/src/highscores_dialog.cpp

    r166 r167  
    6868void HighscoresDialog::loadData() 
    6969{ 
     70        highscoreslist->DeleteAllItems(); 
    7071        const configuration::HighscoresList *list = m_config->getHighscores(); 
    7172 
     
    110111        top_sizer->Add(highscoreslist, 1, wxALL, 10);  
    111112 
    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         
    119124        SetSizer(top_sizer); 
    120  
    121         top_sizer->Fit(this); 
    122125        top_sizer->SetSizeHints(this); 
    123  
    124         Layout(); 
    125126} 
    126127 
     
    129130{ 
    130131        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} 
    133136void HighscoresDialog::onClose(wxCommandEvent& event) 
    134137{ 
     
    136139} 
    137140 
     141void 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 
     152void 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 
     167HighscoresSettingsDialog::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 
     176void 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 
     198void 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  
    2525#include <wx/dialog.h> 
    2626#include <wx/listctrl.h> 
     27#include <wx/spinctrl.h> 
    2728 
    2829namespace highscores_dialog { 
     
    3435 
    3536        void onClose(wxCommandEvent& event);     
     37        void onClear(wxCommandEvent& event);     
     38        void onConfigure(wxCommandEvent& event);         
    3639private: 
    3740        void createControls(); 
     
    4649}; 
    4750 
     51 
     52class HighscoresSettingsDialog : public wxDialog 
     53{ 
     54public: 
     55        HighscoresSettingsDialog(wxWindow* parent, configuration::Configuration* config); 
     56 
     57        void onOk(wxCommandEvent& event); 
     58private: 
     59        void doLayout(); 
     60        wxSpinCtrl *spin_ctrl; 
     61 
     62        configuration::Configuration* m_config; 
     63}; 
     64 
     65 
     66enum { 
     67        ID_CONFIGURE, 
     68}; 
     69 
    4870} 
    4971 
Note: See TracChangeset for help on using the changeset viewer.