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(320, 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
,
63 wxArrayString players
;
64 m_scoreFile
->GetPlayerList(players
);
65 for (unsigned int i
= 0; i
< players
.Count(); i
++)
67 list
->Append(players
[i
]);
70 m_textField
= new wxTextCtrl(this, -1, "", wxDefaultPosition
, wxDefaultSize
, 0);
72 m_OK
= new wxButton(this, wxID_OK
, "OK");
73 m_cancel
= new wxButton(this, wxID_CANCEL
, "Cancel");
75 wxLayoutConstraints
* layout
;
77 // Constrain the msg at the top of the window
78 layout
= new wxLayoutConstraints
;
79 layout
->left
.SameAs (this, wxLeft
, 10);
80 layout
->top
.SameAs (this, wxTop
, 10);
81 layout
->height
.AsIs();
83 msg
->SetConstraints(layout
);
85 // Constrain the OK button
86 layout
= new wxLayoutConstraints
;
87 layout
->left
.SameAs (this, wxLeft
, 10);
88 layout
->bottom
.SameAs (this, wxBottom
, 10);
89 layout
->height
.AsIs();
91 m_OK
->SetConstraints(layout
);
93 // Constrain the OK button
94 layout
= new wxLayoutConstraints
;
95 layout
->left
.RightOf (m_OK
, 10);
96 layout
->bottom
.SameAs (this, wxBottom
, 10);
97 layout
->height
.AsIs();
99 m_cancel
->SetConstraints(layout
);
101 // Constrain the Name text entry field
102 layout
= new wxLayoutConstraints
;
103 layout
->left
.SameAs (this, wxLeft
, 10);
104 layout
->right
.SameAs (this, wxRight
, 10);
105 layout
->bottom
.SameAs (m_OK
, wxTop
, 10);
106 layout
->height
.AsIs();
107 m_textField
->SetConstraints(layout
);
109 // Constrain the list of players
110 layout
= new wxLayoutConstraints
;
111 layout
->left
.SameAs (this, wxLeft
, 10);
112 layout
->right
.SameAs (this, wxRight
, 10);
113 layout
->top
.Below (msg
, 10);
114 layout
->bottom
.SameAs (m_textField
, wxTop
, 10);
115 list
->SetConstraints(layout
);
117 wxString prevPlayer
= m_scoreFile
->GetPreviousPlayer();
118 if (prevPlayer
.Length() > 0)
120 list
->SetStringSelection(prevPlayer
);
121 m_textField
->SetValue(prevPlayer
);
127 PlayerSelectionDialog::~PlayerSelectionDialog()
131 void PlayerSelectionDialog::OnSize(wxSizeEvent
& WXUNUSED(event
))
136 const wxString
& PlayerSelectionDialog::GetPlayersName()
145 bool PlayerSelectionDialog::OnClose()
148 // NB don't return TRUE otherwise delete is called
154 void PlayerSelectionDialog::SelectCallback(wxCommandEvent
& event
)
156 if (event
.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED
)
159 if (event
.IsSelection())
161 m_textField
->SetValue(event
.GetString());
165 void PlayerSelectionDialog::ButtonCallback(wxCommandEvent
& event
)
167 if (event
.GetId() == wxID_OK
)
169 wxString name
= m_textField
->GetValue();
170 if (!name
.IsNull() && name
.Length() > 0)
172 if (name
.Contains('@'))
174 wxMessageBox("Names should not contain the '@' character", "Forty Thieves");
184 wxMessageBox("Please enter your name", "Forty Thieves");