]>
git.saurik.com Git - wxWidgets.git/blob - demos/forty/playerdg.cpp
82cf4da6e8c85f0ac02d9b76875cbac4293ec2d0
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
26 const int ID_LISTBOX
= 101;
28 BEGIN_EVENT_TABLE(PlayerSelectionDialog
, wxDialog
)
29 EVT_SIZE(PlayerSelectionDialog::OnSize
)
30 EVT_BUTTON(wxID_OK
, PlayerSelectionDialog::ButtonCallback
)
31 EVT_BUTTON(wxID_CANCEL
, PlayerSelectionDialog::ButtonCallback
)
32 EVT_LISTBOX(ID_LISTBOX
, PlayerSelectionDialog::SelectCallback
)
33 EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow
)
36 PlayerSelectionDialog::PlayerSelectionDialog(
40 wxDialog(parent
, wxID_ANY
, wxT("Player Selection"), wxDefaultPosition
),
43 wxStaticText
* msg
= new wxStaticText(this, wxID_ANY
, wxT("Please select a name or type a new one:"));
45 wxListBox
* list
= new wxListBox(
47 wxDefaultPosition
, wxSize(-1, 150),
52 wxArrayString players
;
53 m_scoreFile
->GetPlayerList(players
);
54 for (unsigned int i
= 0; i
< players
.Count(); i
++)
56 list
->Append(players
[i
]);
59 m_textField
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
);
61 m_OK
= new wxButton(this, wxID_OK
);
62 m_cancel
= new wxButton(this, wxID_CANCEL
);
64 wxBoxSizer
*button_sizer
= new wxBoxSizer( wxHORIZONTAL
);
65 button_sizer
->Add( m_OK
, 0, wxALL
, 10 );
66 button_sizer
->Add( m_cancel
, 0, wxALL
, 10 );
68 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
69 topsizer
->Add( msg
, 0, wxALL
, 10 );
70 topsizer
->Add( list
, 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10 );
71 topsizer
->Add( m_textField
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxTOP
, 10 );
72 topsizer
->Add( button_sizer
, 0, wxALIGN_LEFT
);
76 topsizer
->SetSizeHints( this );
83 void PlayerSelectionDialog::OnSize(wxSizeEvent
& WXUNUSED(event
))
88 const wxString
& PlayerSelectionDialog::GetPlayersName()
91 m_player = wxEmptyString;
97 void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
99 m_player
= wxEmptyString
;
100 EndModal(wxID_CANCEL
);
103 void PlayerSelectionDialog::SelectCallback(wxCommandEvent
& event
)
105 if (event
.GetEventType() == wxEVT_LISTBOX
)
107 // if (event.IsSelection())
108 m_textField
->SetValue(event
.GetString());
112 void PlayerSelectionDialog::ButtonCallback(wxCommandEvent
& event
)
114 if (event
.GetId() == wxID_OK
)
116 wxString name
= m_textField
->GetValue();
119 if (name
.Contains(wxT('@')))
121 wxMessageBox(wxT("Names should not contain the '@' character"), wxT("Forty Thieves"));
131 wxMessageBox(wxT("Please enter your name"), wxT("Forty Thieves"));
136 m_player
= wxEmptyString
;
137 EndModal(wxID_CANCEL
);