- Timestamp:
- 09/27/2008 05:56:06 PM (4 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
- 2 moved
-
MainFrame.cpp (modified) (2 diffs)
-
Makefile.am (modified) (2 diffs)
-
highscores_dialog.cpp (moved) (moved from trunk/src/HighScoreDialog.cpp) (2 diffs)
-
highscores_dialog.h (moved) (moved from trunk/src/HighScoreDialog.h) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/MainFrame.cpp
r164 r165 31 31 #include "wxDynamicBitmap.h" 32 32 #include "ObjectsID.h" 33 #include " HighScoreDialog.h"33 #include "highscores_dialog.h" 34 34 #include "dice_theme_dialog.h" 35 35 #include "About.h" … … 527 527 void MainFrame::OnShowHighscore(wxCommandEvent& event) 528 528 { 529 HighScoreDialog *dialog = new HighScoreDialog(this,wxID_ANY,m_highscoredb); 529 highscores_dialog::HighscoresDialog *dialog = new highscores_dialog::HighscoresDialog(this,m_config); 530 530 531 dialog->ShowModal(); 532 533 delete dialog; 531 534 } 532 535 -
trunk/src/Makefile.am
r164 r165 8 8 dice_theme_dialog.cpp \ 9 9 MainFrame.cpp \ 10 HighScoreDialog.cpp \ 10 highscores_dialog.cpp \ 11 highscores_dialog.h \ 11 12 HighScoreTableDB.cpp \ 12 13 icon.xpm \ … … 50 51 dice_theme_dialog.h \ 51 52 HighScoreTableDB.h \ 52 HighScoreDialog.h \53 53 Icon.h \ 54 54 icon32.ico \ -
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 -
trunk/src/highscores_dialog.h
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 * * … … 19 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 20 19 ***************************************************************************/ 21 #ifndef HIGHSCOREDIALOG_INC22 #define HIGHSCOREDIALOG_INC20 #ifndef OPENYAHTZEE_HIGHSCORES_DIALOG_INC 21 #define OPENYAHTZEE_HIGHSCORES_DIALOG_INC 23 22 24 #include "HighScoreTableDB.h" 23 #include "configuration.h" 24 #include <wx/wx.h> 25 #include <wx/dialog.h> 26 #include <wx/listctrl.h> 25 27 26 class HighScoreDialog : public wxDialog 28 namespace highscores_dialog { 29 30 class HighscoresDialog : public wxDialog 27 31 { 28 32 public: 29 High ScoreDialog(wxWindow* parent,wxWindowID id,HighScoreTableDB* highscoredb);33 HighscoresDialog(wxWindow* parent,configuration::Configuration* config, int highlight_rank = 0); 30 34 35 void onClose(wxCommandEvent& event); 31 36 private: 37 void createControls(); 38 void loadData( ); 39 void doLayout(); 40 void connectEventTable(); 32 41 42 int highlight_rank; 43 configuration::Configuration* m_config; 44 45 wxListCtrl *highscoreslist; 33 46 }; 47 48 } 34 49 35 50
Note: See TracChangeset
for help on using the changeset viewer.
