1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 //---------------------------------------------------------------------------
11 // Last modified: 22nd July 1998 - ported to wxWindows 2.0
12 /////////////////////////////////////////////////////////////////////////////
15 #pragma implementation
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
33 const int ID_LISTBOX
= 101;
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
)
40 EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow
)
43 PlayerSelectionDialog::PlayerSelectionDialog(
47 wxDialog(parent
, wxID_ANY
, _T("Player Selection"),
48 wxDefaultPosition
, wxDefaultSize
,
49 wxDIALOG_MODAL
| wxDEFAULT_DIALOG_STYLE
),
52 wxStaticText
* msg
= new wxStaticText(this, wxID_ANY
, _T("Please select a name or type a new one:"));
54 wxListBox
* list
= new wxListBox(
56 wxDefaultPosition
, wxDefaultSize
,
61 wxArrayString players
;
62 m_scoreFile
->GetPlayerList(players
);
63 for (unsigned int i
= 0; i
< players
.Count(); i
++)
65 list
->Append(players
[i
]);
68 m_textField
= new wxTextCtrl(this, wxID_ANY
, _T(""), wxDefaultPosition
, wxDefaultSize
, 0);
70 m_OK
= new wxButton(this, wxID_OK
, _T("OK"));
71 m_cancel
= new wxButton(this, wxID_CANCEL
, _T("Cancel"));
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 );
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
);
85 topsizer
->SetSizeHints( this );
90 PlayerSelectionDialog::~PlayerSelectionDialog()
94 void PlayerSelectionDialog::OnSize(wxSizeEvent
& WXUNUSED(event
))
99 const wxString
& PlayerSelectionDialog::GetPlayersName()
108 void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
111 EndModal(wxID_CANCEL
);
114 void PlayerSelectionDialog::SelectCallback(wxCommandEvent
& event
)
116 if (event
.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED
)
118 // if (event.IsSelection())
119 m_textField
->SetValue(event
.GetString());
123 void PlayerSelectionDialog::ButtonCallback(wxCommandEvent
& event
)
125 if (event
.GetId() == wxID_OK
)
127 wxString name
= m_textField
->GetValue();
128 if (!name
.IsNull() && name
.Length() > 0)
130 if (name
.Contains(_T('@')))
132 wxMessageBox(_T("Names should not contain the '@' character"), _T("Forty Thieves"));
142 wxMessageBox(_T("Please enter your name"), _T("Forty Thieves"));
148 EndModal(wxID_CANCEL
);