Changeset 165 for trunk/src


Ignore:
Timestamp:
09/27/2008 05:56:06 PM (4 years ago)
Author:
guyru
Message:

new highscore dialog

Location:
trunk/src
Files:
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/MainFrame.cpp

    r164 r165  
    3131#include "wxDynamicBitmap.h" 
    3232#include "ObjectsID.h" 
    33 #include "HighScoreDialog.h" 
     33#include "highscores_dialog.h" 
    3434#include "dice_theme_dialog.h" 
    3535#include "About.h" 
     
    527527void MainFrame::OnShowHighscore(wxCommandEvent& event) 
    528528{ 
    529         HighScoreDialog *dialog = new HighScoreDialog(this,wxID_ANY,m_highscoredb); 
     529        highscores_dialog::HighscoresDialog *dialog = new highscores_dialog::HighscoresDialog(this,m_config); 
     530 
    530531        dialog->ShowModal(); 
     532 
     533        delete dialog; 
    531534} 
    532535 
  • trunk/src/Makefile.am

    r164 r165  
    88        dice_theme_dialog.cpp \ 
    99        MainFrame.cpp \ 
    10         HighScoreDialog.cpp \ 
     10        highscores_dialog.cpp \ 
     11        highscores_dialog.h \ 
    1112        HighScoreTableDB.cpp \ 
    1213        icon.xpm \ 
     
    5051        dice_theme_dialog.h \ 
    5152        HighScoreTableDB.h \ 
    52         HighScoreDialog.h \ 
    5353        Icon.h \ 
    5454        icon32.ico \ 
  • trunk/src/highscores_dialog.cpp

    r82 r165  
    1 // $Header$ 
    21/*************************************************************************** 
    3  *   Copyright (C) 2006 by Guy Rutenberg   * 
     2 *   Copyright (C) 2006-2008 by Guy Rutenberg   * 
    43 *   guyrutenberg@gmail.com   * 
    54 *                                                                         * 
     
    2019 ***************************************************************************/ 
    2120 
    22 #include <wx/wx.h> 
    23 #include <wx/dialog.h> 
    2421#include <wx/button.h> 
    2522#include <wx/sizer.h> 
    26 #include <wx/listctrl.h> 
    2723 
    28 #include "ObjectsID.h" 
    29 #include "HighScoreDialog.h" 
     24#include "highscores_dialog.h" 
    3025 
    3126#include "Icon.h" 
    3227 
    3328using namespace std; 
     29using namespace highscores_dialog; 
    3430 
    35 HighScoreDialog::HighScoreDialog(wxWindow* parent,wxWindowID id,HighScoreTableDB *highscoredb) : 
    36         wxDialog(parent, id, wxT("High-Score Table"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) 
     31HighscoresDialog::HighscoresDialog(wxWindow* parent,configuration::Configuration* config, int highlight_rank) : 
     32        wxDialog(parent, wxID_ANY, wxT("Highscores Table"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) 
    3733{ 
     34        this->highlight_rank = highlight_rank; 
     35        m_config = config; 
    3836 
    3937        SetIcon(wxIcon(ICON)); 
    4038 
     39        createControls(); 
     40        loadData(); 
     41        doLayout(); 
     42        connectEventTable(); 
     43} 
    4144 
    42         list<string> table; 
     45void HighscoresDialog::createControls() 
     46{ 
     47        highscoreslist = new wxListCtrl(this,wxID_ANY,wxDefaultPosition,wxSize(400,400),wxLC_REPORT); 
    4348 
    44         table = highscoredb->GetHighScoreTable();        
     49        wxListItem itemCol; 
    4550 
    46         list<string>::iterator lip = table.begin(); 
     51        itemCol.SetText(wxT("Rank")); 
     52        itemCol.SetImage(-1); 
     53        highscoreslist->InsertColumn(0, itemCol); 
     54 
     55        itemCol.SetText(wxT("Name")); 
     56        itemCol.SetImage(-1); 
     57        highscoreslist->InsertColumn(1, itemCol); 
     58 
     59        itemCol.SetText(wxT("Score")); 
     60        itemCol.SetImage(-1); 
     61        highscoreslist->InsertColumn(2, itemCol); 
     62 
     63        itemCol.SetText(wxT("Date")); 
     64        itemCol.SetImage(-1); 
     65        highscoreslist->InsertColumn(3, itemCol); 
     66} 
     67 
     68void HighscoresDialog::loadData() 
     69{ 
     70        const configuration::HighscoresList *list = m_config->getHighscores(); 
     71 
     72        configuration::HighscoresList::const_iterator it; 
    4773        wxString buf; 
    4874 
     75        int i = 0; 
     76        for (it = list->begin(); it!=list->end(); it++, i++) { 
     77                // rank 
     78                buf.Clear(); 
     79                buf<<(i+1); 
     80                highscoreslist->InsertItem(i,buf,-1); 
    4981 
    50         //Now create the dialog 
    51         //Create The top-level sizer 
    52         wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); 
    53         wxListCtrl *highscorelist = new wxListCtrl(this,wxID_ANY,wxDefaultPosition,wxSize(400,400),wxLC_REPORT); 
     82                // name 
     83                buf = wxString(it->name.c_str(),wxConvUTF8); 
     84                highscoreslist->SetItem(i,1,buf); 
     85 
     86                // score 
     87                buf.Clear(); 
     88                buf<< it->score; 
     89                highscoreslist->SetItem(i,2,buf); 
     90 
     91                // date 
     92                buf = wxString(it->date.c_str(),wxConvUTF8); 
     93                highscoreslist->SetItem(i,3,buf); 
     94        } 
     95 
     96        if (highlight_rank) { 
     97                highscoreslist->SetItemTextColour(highlight_rank-1,*wxRED); 
     98        } 
     99 
     100        highscoreslist->SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER ); 
     101        highscoreslist->SetColumnWidth(1, wxLIST_AUTOSIZE ); 
     102        highscoreslist->SetColumnWidth(2, wxLIST_AUTOSIZE_USEHEADER ); 
     103        highscoreslist->SetColumnWidth(3, wxLIST_AUTOSIZE ); 
     104} 
     105 
     106void HighscoresDialog::doLayout() 
     107{ 
     108        wxBoxSizer *top_sizer = new wxBoxSizer( wxVERTICAL ); 
    54109         
    55         topSizer->Add( 
    56                 highscorelist, 
    57                 0, 
    58                 wxALL, 
    59                 10); 
    60                  
    61         topSizer->Add( 
    62                 new wxButton(this,wxID_OK), 
     110        top_sizer->Add(highscoreslist, 1, wxALL, 10);  
     111 
     112        top_sizer->Add( 
     113                new wxButton(this,wxID_CLOSE), 
    63114                0, //no streching 
    64115                wxALL, //we want border around everything 
    65116                10); 
    66117         
    67         /////////////////////////////////////// 
    68         ////Enter content into highscoretable 
     118        SetAutoLayout(true); 
     119        SetSizer(top_sizer); 
    69120 
    70         //create the columns 
    71         wxListItem itemCol; 
    72         itemCol.SetText(wxT("Place")); 
    73         itemCol.SetImage(-1); 
    74         highscorelist->InsertColumn(0, itemCol); 
    75         itemCol.SetText(wxT("Name")); 
    76         itemCol.SetImage(-1); 
    77         highscorelist->InsertColumn(1, itemCol); 
    78         itemCol.SetText(wxT("Date")); 
    79         itemCol.SetImage(-1); 
    80         highscorelist->InsertColumn(2, itemCol); 
    81         itemCol.SetText(wxT("Score")); 
    82         itemCol.SetImage(-1); 
    83         highscorelist->InsertColumn(3, itemCol); 
    84          
    85         int i =0; 
    86         while(lip != table.end()) { 
    87                 if (i%4){ 
    88                         buf = wxString(lip->c_str(),wxConvUTF8); 
    89                         highscorelist->SetItem(i/4,i%4,buf); 
    90                         lip++; 
     121        top_sizer->Fit(this); 
     122        top_sizer->SetSizeHints(this); 
    91123 
    92                 } else {  
    93                         buf.Clear(); 
    94                         buf << (i/4+1); 
    95                         highscorelist->InsertItem(i/4,buf,-1); 
    96                 } 
    97                 i++; 
    98         } 
    99          
    100  
    101         //size the collumns 
    102         highscorelist->SetColumnWidth(0, wxLIST_AUTOSIZE_USEHEADER ); 
    103         highscorelist->SetColumnWidth(1, wxLIST_AUTOSIZE ); 
    104         highscorelist->SetColumnWidth(2, wxLIST_AUTOSIZE ); 
    105         highscorelist->SetColumnWidth(3, wxLIST_AUTOSIZE_USEHEADER ); 
    106  
    107          
    108  
    109         SetSizer( topSizer ); // use the sizer for layout 
    110         topSizer->Fit( this );          // fit the dialog to the contents 
    111         topSizer->SetSizeHints( this ); // set hints to honor min size 
    112  
     124        Layout(); 
    113125} 
    114126 
     127 
     128void HighscoresDialog::connectEventTable() 
     129{ 
     130        Connect(wxID_CLOSE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(HighscoresDialog::onClose)); 
     131} 
     132 
     133void HighscoresDialog::onClose(wxCommandEvent& event) 
     134{ 
     135        Close(); 
     136} 
     137 
  • trunk/src/highscores_dialog.h

    r82 r165  
    1 // $Header$ 
    21/*************************************************************************** 
    3  *   Copyright (C) 2006 by Guy Rutenberg   * 
     2 *   Copyright (C) 2006-2008 by Guy Rutenberg   * 
    43 *   guyrutenberg@gmail.com   * 
    54 *                                                                         * 
     
    1918 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
    2019 ***************************************************************************/ 
    21 #ifndef HIGHSCOREDIALOG_INC 
    22 #define HIGHSCOREDIALOG_INC 
     20#ifndef OPENYAHTZEE_HIGHSCORES_DIALOG_INC 
     21#define OPENYAHTZEE_HIGHSCORES_DIALOG_INC 
    2322 
    24 #include "HighScoreTableDB.h" 
     23#include "configuration.h" 
     24#include <wx/wx.h> 
     25#include <wx/dialog.h> 
     26#include <wx/listctrl.h> 
    2527 
    26 class HighScoreDialog : public wxDialog 
     28namespace highscores_dialog { 
     29 
     30class HighscoresDialog : public wxDialog 
    2731{ 
    2832public: 
    29         HighScoreDialog(wxWindow* parent,wxWindowID id,HighScoreTableDB* highscoredb); 
     33        HighscoresDialog(wxWindow* parent,configuration::Configuration* config, int highlight_rank = 0); 
    3034 
     35        void onClose(wxCommandEvent& event);     
    3136private: 
     37        void createControls(); 
     38        void loadData( ); 
     39        void doLayout(); 
     40        void connectEventTable(); 
    3241 
     42        int highlight_rank; 
     43        configuration::Configuration* m_config; 
     44 
     45        wxListCtrl *highscoreslist; 
    3346}; 
     47 
     48} 
    3449 
    3550 
Note: See TracChangeset for help on using the changeset viewer.