Changeset 165 for trunk/src/highscores_dialog.cpp
- Timestamp:
- 09/27/2008 05:56:06 PM (4 years ago)
- File:
-
- 1 moved
-
trunk/src/highscores_dialog.cpp (moved) (moved from trunk/src/HighScoreDialog.cpp) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/highscores_dialog.cpp
r82 r165 1 // $Header$2 1 /*************************************************************************** 3 * Copyright (C) 2006 by Guy Rutenberg *2 * Copyright (C) 2006-2008 by Guy Rutenberg * 4 3 * guyrutenberg@gmail.com * 5 4 * * … … 20 19 ***************************************************************************/ 21 20 22 #include <wx/wx.h>23 #include <wx/dialog.h>24 21 #include <wx/button.h> 25 22 #include <wx/sizer.h> 26 #include <wx/listctrl.h>27 23 28 #include "ObjectsID.h" 29 #include "HighScoreDialog.h" 24 #include "highscores_dialog.h" 30 25 31 26 #include "Icon.h" 32 27 33 28 using namespace std; 29 using namespace highscores_dialog; 34 30 35 High ScoreDialog::HighScoreDialog(wxWindow* parent,wxWindowID id,HighScoreTableDB *highscoredb) :36 wxDialog(parent, id, wxT("High-ScoreTable"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)31 HighscoresDialog::HighscoresDialog(wxWindow* parent,configuration::Configuration* config, int highlight_rank) : 32 wxDialog(parent, wxID_ANY, wxT("Highscores Table"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) 37 33 { 34 this->highlight_rank = highlight_rank; 35 m_config = config; 38 36 39 37 SetIcon(wxIcon(ICON)); 40 38 39 createControls(); 40 loadData(); 41 doLayout(); 42 connectEventTable(); 43 } 41 44 42 list<string> table; 45 void HighscoresDialog::createControls() 46 { 47 highscoreslist = new wxListCtrl(this,wxID_ANY,wxDefaultPosition,wxSize(400,400),wxLC_REPORT); 43 48 44 table = highscoredb->GetHighScoreTable();49 wxListItem itemCol; 45 50 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 68 void HighscoresDialog::loadData() 69 { 70 const configuration::HighscoresList *list = m_config->getHighscores(); 71 72 configuration::HighscoresList::const_iterator it; 47 73 wxString buf; 48 74 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); 49 81 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 106 void HighscoresDialog::doLayout() 107 { 108 wxBoxSizer *top_sizer = new wxBoxSizer( wxVERTICAL ); 54 109 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), 63 114 0, //no streching 64 115 wxALL, //we want border around everything 65 116 10); 66 117 67 ///////////////////////////////////////68 ////Enter content into highscoretable118 SetAutoLayout(true); 119 SetSizer(top_sizer); 69 120 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); 91 123 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(); 113 125 } 114 126 127 128 void HighscoresDialog::connectEventTable() 129 { 130 Connect(wxID_CLOSE, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(HighscoresDialog::onClose)); 131 } 132 133 void HighscoresDialog::onClose(wxCommandEvent& event) 134 { 135 Close(); 136 } 137
Note: See TracChangeset
for help on using the changeset viewer.
