]>
git.saurik.com Git - wxWidgets.git/blob - demos/forty/playerdg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
7 // Copyright: (c) 1993-1998 Chris Breeze
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
25 const int ID_LISTBOX
= 101;
27 BEGIN_EVENT_TABLE(PlayerSelectionDialog
, wxDialog
)
28 EVT_SIZE(PlayerSelectionDialog::OnSize
)
29 EVT_BUTTON(wxID_OK
, PlayerSelectionDialog::ButtonCallback
)
30 EVT_BUTTON(wxID_CANCEL
, PlayerSelectionDialog::ButtonCallback
)
31 EVT_LISTBOX(ID_LISTBOX
, PlayerSelectionDialog::SelectCallback
)
32 EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow
)
35 PlayerSelectionDialog::PlayerSelectionDialog(
39 wxDialog(parent
, wxID_ANY
, wxT("Player Selection"), wxDefaultPosition
),
42 wxStaticText
* msg
= new wxStaticText(this, wxID_ANY
, wxT("Please select a name or type a new one:"));
44 wxListBox
* list
= new wxListBox(
46 wxDefaultPosition
, wxSize(-1, 150),
51 wxArrayString players
;
52 m_scoreFile
->GetPlayerList(players
);
53 for (unsigned int i
= 0; i
< players
.Count(); i
++)
55 list
->Append(players
[i
]);
58 m_textField
= new wxTextCtrl(this, wxID_ANY
, wxEmptyString
, wxDefaultPosition
, wxDefaultSize
);
60 m_OK
= new wxButton(this, wxID_OK
);
61 m_cancel
= new wxButton(this, wxID_CANCEL
);
63 wxBoxSizer
*button_sizer
= new wxBoxSizer( wxHORIZONTAL
);
64 button_sizer
->Add( m_OK
, 0, wxALL
, 10 );
65 button_sizer
->Add( m_cancel
, 0, wxALL
, 10 );
67 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
68 topsizer
->Add( msg
, 0, wxALL
, 10 );
69 topsizer
->Add( list
, 1, wxEXPAND
| wxLEFT
| wxRIGHT
, 10 );
70 topsizer
->Add( m_textField
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxTOP
, 10 );
71 topsizer
->Add( button_sizer
, 0, wxALIGN_LEFT
);
75 topsizer
->SetSizeHints( this );
82 void PlayerSelectionDialog::OnSize(wxSizeEvent
& WXUNUSED(event
))
87 const wxString
& PlayerSelectionDialog::GetPlayersName()
90 m_player = wxEmptyString;
96 void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
98 m_player
= wxEmptyString
;
99 EndModal(wxID_CANCEL
);
102 void PlayerSelectionDialog::SelectCallback(wxCommandEvent
& event
)
104 if (event
.GetEventType() == wxEVT_LISTBOX
)
106 // if (event.IsSelection())
107 m_textField
->SetValue(event
.GetString());
111 void PlayerSelectionDialog::ButtonCallback(wxCommandEvent
& event
)
113 if (event
.GetId() == wxID_OK
)
115 wxString name
= m_textField
->GetValue();
118 if (name
.Contains(wxT('@')))
120 wxMessageBox(wxT("Names should not contain the '@' character"), wxT("Forty Thieves"));
130 wxMessageBox(wxT("Please enter your name"), wxT("Forty Thieves"));
135 m_player
= wxEmptyString
;
136 EndModal(wxID_CANCEL
);