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
)
42 PlayerSelectionDialog::PlayerSelectionDialog(
46 wxDialog(parent
, -1, "Player Selection",
47 wxDefaultPosition
, wxSize(250, 200),
48 wxDIALOG_MODAL
| wxDEFAULT_DIALOG_STYLE
),
54 wxStaticText
* msg
= new wxStaticText(this, -1, "Please select a name from the list");
56 wxListBox
* list
= new wxListBox(
58 wxDefaultPosition
, wxDefaultSize
,
66 wxString* players = 0;
67 m_scoreFile->GetPlayerList(&players, numPlayers);
68 for (int i = 0; i < numPlayers; i++)
70 list->Append(players[i]);
75 m_textField
= new wxTextCtrl(this, -1, "", wxDefaultPosition
, wxDefaultSize
, 0);
77 m_OK
= new wxButton(this, wxID_OK
, "OK");
78 m_cancel
= new wxButton(this, wxID_CANCEL
, "Cancel");
80 wxLayoutConstraints
* layout
;
82 // Constrain the msg at the top of the window
83 layout
= new wxLayoutConstraints
;
84 layout
->left
.SameAs (this, wxLeft
, 10);
85 layout
->top
.SameAs (this, wxTop
, 10);
86 layout
->height
.AsIs();
88 msg
->SetConstraints(layout
);
90 // Constrain the OK button
91 layout
= new wxLayoutConstraints
;
92 layout
->left
.SameAs (this, wxLeft
, 10);
93 layout
->bottom
.SameAs (this, wxBottom
, 10);
94 layout
->height
.AsIs();
96 m_OK
->SetConstraints(layout
);
98 // Constrain the OK button
99 layout
= new wxLayoutConstraints
;
100 layout
->left
.RightOf (m_OK
, 10);
101 layout
->bottom
.SameAs (this, wxBottom
, 10);
102 layout
->height
.AsIs();
103 layout
->width
.AsIs();
104 m_cancel
->SetConstraints(layout
);
106 // Constrain the Name text entry field
107 layout
= new wxLayoutConstraints
;
108 layout
->left
.SameAs (this, wxLeft
, 10);
109 layout
->right
.SameAs (this, wxRight
, 10);
110 layout
->bottom
.SameAs (m_OK
, wxTop
, 10);
111 layout
->height
.AsIs();
112 m_textField
->SetConstraints(layout
);
114 // Constrain the list of players
115 layout
= new wxLayoutConstraints
;
116 layout
->left
.SameAs (this, wxLeft
, 10);
117 layout
->right
.SameAs (this, wxRight
, 10);
118 layout
->top
.Below (msg
, 10);
119 layout
->bottom
.SameAs (m_textField
, wxTop
, 10);
120 list
->SetConstraints(layout
);
122 wxString prevPlayer
= m_scoreFile
->GetPreviousPlayer();
123 if (prevPlayer
.Length() > 0)
125 list
->SetStringSelection(prevPlayer
);
126 m_textField
->SetValue(prevPlayer
);
132 PlayerSelectionDialog::~PlayerSelectionDialog()
136 void PlayerSelectionDialog::OnSize(wxSizeEvent
& event
)
141 const wxString
& PlayerSelectionDialog::GetPlayersName()
150 bool PlayerSelectionDialog::OnClose()
153 // NB don't return TRUE otherwise delete is called
159 void PlayerSelectionDialog::SelectCallback(wxCommandEvent
& event
)
161 if (event
.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED
)
164 if (event
.IsSelection())
166 m_textField
->SetValue(event
.GetString());
170 void PlayerSelectionDialog::ButtonCallback(wxCommandEvent
& event
)
172 if (event
.GetId() == wxID_OK
)
174 wxString name
= m_textField
->GetValue();
175 if (!name
.IsNull() && name
.Length() > 0)
177 if (name
.Contains('@'))
179 wxMessageBox("Names should not contain the '@' character", "Forty Thieves");
189 wxMessageBox("Please enter your name", "Forty Thieves");