1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
31 const int ID_LISTBOX
= 101;
33 BEGIN_EVENT_TABLE(PlayerSelectionDialog
, wxDialog
)
34 EVT_SIZE(PlayerSelectionDialog::OnSize
)
35 EVT_BUTTON(wxID_OK
, PlayerSelectionDialog::ButtonCallback
)
36 EVT_BUTTON(wxID_CANCEL
, PlayerSelectionDialog::ButtonCallback
)
37 EVT_LISTBOX(ID_LISTBOX
, PlayerSelectionDialog::SelectCallback
)
38 EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow
)
41 PlayerSelectionDialog::PlayerSelectionDialog(
45 wxDialog(parent
, wxID_ANY
, _T("Player Selection"), wxDefaultPosition
),
48 wxStaticText
* msg
= new wxStaticText(this, wxID_ANY
, _T("Please select a name or type a new one:"));
50 wxListBox
* list
= new wxListBox(
52 wxDefaultPosition
, wxDefaultSize
,
57 wxArrayString players
;
58 m_scoreFile
->GetPlayerList(players
);
59 for (unsigned int i
= 0; i
< players
.Count(); i
++)
61 list
->Append(players
[i
]);
64 m_textField
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
);
66 m_OK
= new wxButton(this, wxID_OK
, _T("OK"));
67 m_cancel
= new wxButton(this, wxID_CANCEL
, _T("Cancel"));
69 wxBoxSizer
*button_sizer
= new wxBoxSizer( wxHORIZONTAL
);
70 button_sizer
->Add( m_OK
, 0, wxALL
, 10 );
71 button_sizer
->Add( m_cancel
, 0, wxALL
, 10 );
73 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
74 topsizer
->Add( msg
, 0, wxALL
, 10 );
75 topsizer
->Add( list
, 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10 );
76 topsizer
->Add( m_textField
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxTOP
, 10 );
77 topsizer
->Add( button_sizer
, 0, wxALIGN_LEFT
);
81 topsizer
->SetSizeHints( this );
86 PlayerSelectionDialog::~PlayerSelectionDialog()
90 void PlayerSelectionDialog::OnSize(wxSizeEvent
& WXUNUSED(event
))
95 const wxString
& PlayerSelectionDialog::GetPlayersName()
98 m_player = wxEmptyString;
104 void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
106 m_player
= wxEmptyString
;
107 EndModal(wxID_CANCEL
);
110 void PlayerSelectionDialog::SelectCallback(wxCommandEvent
& event
)
112 if (event
.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED
)
114 // if (event.IsSelection())
115 m_textField
->SetValue(event
.GetString());
119 void PlayerSelectionDialog::ButtonCallback(wxCommandEvent
& event
)
121 if (event
.GetId() == wxID_OK
)
123 wxString name
= m_textField
->GetValue();
124 if (!name
.IsNull() && name
.Length() > 0)
126 if (name
.Contains(_T('@')))
128 wxMessageBox(_T("Names should not contain the '@' character"), _T("Forty Thieves"));
138 wxMessageBox(_T("Please enter your name"), _T("Forty Thieves"));
143 m_player
= wxEmptyString
;
144 EndModal(wxID_CANCEL
);