]>
Commit | Line | Data |
---|---|---|
63cafd27 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: playerdg.cpp | |
3 | // Purpose: Forty Thieves patience game | |
4 | // Author: Chris Breeze | |
5 | // Modified by: | |
6 | // Created: 21/07/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1993-1998 Chris Breeze | |
9 | // Licence: wxWindows licence | |
10 | //--------------------------------------------------------------------------- | |
11 | // Last modified: 22nd July 1998 - ported to wxWindows 2.0 | |
12 | ///////////////////////////////////////////////////////////////////////////// | |
13 | ||
14 | #ifdef __GNUG__ | |
15 | #pragma implementation | |
16 | #pragma interface | |
17 | #endif | |
18 | ||
19 | // For compilers that support precompilation, includes "wx/wx.h". | |
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifdef __BORLANDC__ | |
23 | #pragma hdrstop | |
24 | #endif | |
25 | ||
26 | #ifndef WX_PRECOMP | |
27 | #include "wx/wx.h" | |
28 | #endif | |
29 | ||
30 | #include "scorefil.h" | |
31 | #include "playerdg.h" | |
32 | ||
33 | const int ID_LISTBOX = 101; | |
34 | ||
35 | BEGIN_EVENT_TABLE(PlayerSelectionDialog, wxDialog) | |
36 | EVT_SIZE(PlayerSelectionDialog::OnSize) | |
37 | EVT_BUTTON(wxID_OK, PlayerSelectionDialog::ButtonCallback) | |
38 | EVT_BUTTON(wxID_CANCEL, PlayerSelectionDialog::ButtonCallback) | |
39 | EVT_LISTBOX(ID_LISTBOX, PlayerSelectionDialog::SelectCallback) | |
e3065973 | 40 | EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow) |
63cafd27 JS |
41 | END_EVENT_TABLE() |
42 | ||
43 | PlayerSelectionDialog::PlayerSelectionDialog( | |
44 | wxWindow* parent, | |
45 | ScoreFile* file | |
46 | ) : | |
e0b5519a JS |
47 | wxDialog(parent, wxID_ANY, _T("Player Selection"), |
48 | wxDefaultPosition, wxDefaultSize, | |
63cafd27 JS |
49 | wxDIALOG_MODAL | wxDEFAULT_DIALOG_STYLE), |
50 | m_scoreFile(file) | |
51 | { | |
e0b5519a | 52 | wxStaticText* msg = new wxStaticText(this, wxID_ANY, _T("Please select a name or type a new one:")); |
63cafd27 JS |
53 | |
54 | wxListBox* list = new wxListBox( | |
55 | this, ID_LISTBOX, | |
56 | wxDefaultPosition, wxDefaultSize, | |
57 | 0, 0, | |
58 | wxLB_SINGLE | |
59 | ); | |
7b5408ea | 60 | |
54ff4a70 RR |
61 | wxArrayString players; |
62 | m_scoreFile->GetPlayerList(players); | |
cb43b372 | 63 | for (unsigned int i = 0; i < players.Count(); i++) |
63cafd27 JS |
64 | { |
65 | list->Append(players[i]); | |
66 | } | |
63cafd27 | 67 | |
e0b5519a | 68 | m_textField = new wxTextCtrl(this, wxID_ANY, _T(""), wxDefaultPosition, wxDefaultSize, 0); |
63cafd27 | 69 | |
f37c24e0 MB |
70 | m_OK = new wxButton(this, wxID_OK, _T("OK")); |
71 | m_cancel = new wxButton(this, wxID_CANCEL, _T("Cancel")); | |
63cafd27 | 72 | |
e0b5519a JS |
73 | wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL ); |
74 | button_sizer->Add( m_OK, 0, wxALL, 10 ); | |
75 | button_sizer->Add( m_cancel, 0, wxALL, 10 ); | |
63cafd27 | 76 | |
e0b5519a JS |
77 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); |
78 | topsizer->Add( msg, 0, wxALL , 10 ); | |
79 | topsizer->Add( list, 1, wxEXPAND | wxLEFT | wxRIGHT, 10 ); | |
80 | topsizer->Add( m_textField, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10 ); | |
81 | topsizer->Add( button_sizer, 0, wxALIGN_LEFT ); | |
5cdeff75 | 82 | |
e0b5519a JS |
83 | SetSizer( topsizer ); |
84 | ||
85 | topsizer->SetSizeHints( this ); | |
82ea63e6 RR |
86 | |
87 | CentreOnParent(); | |
63cafd27 JS |
88 | } |
89 | ||
90 | PlayerSelectionDialog::~PlayerSelectionDialog() | |
91 | { | |
92 | } | |
93 | ||
cb43b372 | 94 | void PlayerSelectionDialog::OnSize(wxSizeEvent& WXUNUSED(event)) |
63cafd27 JS |
95 | { |
96 | Layout(); | |
97 | } | |
98 | ||
99 | const wxString& PlayerSelectionDialog::GetPlayersName() | |
100 | { | |
7b5408ea | 101 | /* |
63cafd27 | 102 | m_player = ""; |
e0b5519a | 103 | Show(true); |
7b5408ea | 104 | */ |
63cafd27 JS |
105 | return m_player; |
106 | } | |
107 | ||
babd36de | 108 | void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
63cafd27 | 109 | { |
f37c24e0 | 110 | m_player = _T(""); |
e3065973 | 111 | EndModal(wxID_CANCEL); |
63cafd27 JS |
112 | } |
113 | ||
114 | void PlayerSelectionDialog::SelectCallback(wxCommandEvent& event) | |
115 | { | |
116 | if (event.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED) | |
117 | { | |
3502e687 | 118 | // if (event.IsSelection()) |
63cafd27 JS |
119 | m_textField->SetValue(event.GetString()); |
120 | } | |
121 | } | |
122 | ||
123 | void PlayerSelectionDialog::ButtonCallback(wxCommandEvent& event) | |
124 | { | |
125 | if (event.GetId() == wxID_OK) | |
126 | { | |
127 | wxString name = m_textField->GetValue(); | |
128 | if (!name.IsNull() && name.Length() > 0) | |
129 | { | |
f37c24e0 | 130 | if (name.Contains(_T('@'))) |
63cafd27 | 131 | { |
f37c24e0 | 132 | wxMessageBox(_T("Names should not contain the '@' character"), _T("Forty Thieves")); |
63cafd27 JS |
133 | } |
134 | else | |
135 | { | |
136 | m_player = name; | |
cba2db0c | 137 | EndModal(wxID_OK); |
63cafd27 JS |
138 | } |
139 | } | |
140 | else | |
141 | { | |
f37c24e0 | 142 | wxMessageBox(_T("Please enter your name"), _T("Forty Thieves")); |
63cafd27 JS |
143 | } |
144 | } | |
145 | else | |
146 | { | |
f37c24e0 | 147 | m_player = _T(""); |
cba2db0c | 148 | EndModal(wxID_CANCEL); |
63cafd27 JS |
149 | } |
150 | } |