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
)
40 EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow
)
43 PlayerSelectionDialog::PlayerSelectionDialog(
47 wxDialog(parent
, -1, _T("Player Selection"),
48 wxDefaultPosition
, wxSize(320, 200),
49 wxDIALOG_MODAL
| wxDEFAULT_DIALOG_STYLE
),
55 wxStaticText
* msg
= new wxStaticText(this, -1, _T("Please select a name or type a new one:"));
57 wxListBox
* list
= new wxListBox(
59 wxDefaultPosition
, wxDefaultSize
,
64 wxArrayString players
;
65 m_scoreFile
->GetPlayerList(players
);
66 for (unsigned int i
= 0; i
< players
.Count(); i
++)
68 list
->Append(players
[i
]);
71 m_textField
= new wxTextCtrl(this, -1, _T(""), wxDefaultPosition
, wxDefaultSize
, 0);
73 m_OK
= new wxButton(this, wxID_OK
, _T("OK"));
74 m_cancel
= new wxButton(this, wxID_CANCEL
, _T("Cancel"));
76 wxLayoutConstraints
* layout
;
78 // Constrain the msg at the top of the window
79 layout
= new wxLayoutConstraints
;
80 layout
->left
.SameAs (this, wxLeft
, 10);
81 layout
->top
.SameAs (this, wxTop
, 10);
82 layout
->height
.AsIs();
84 msg
->SetConstraints(layout
);
86 // Constrain the OK button
87 layout
= new wxLayoutConstraints
;
88 layout
->left
.SameAs (this, wxLeft
, 10);
89 layout
->bottom
.SameAs (this, wxBottom
, 10);
90 layout
->height
.AsIs();
92 m_OK
->SetConstraints(layout
);
94 // Constrain the OK button
95 layout
= new wxLayoutConstraints
;
96 layout
->left
.RightOf (m_OK
, 10);
97 layout
->bottom
.SameAs (this, wxBottom
, 10);
98 layout
->height
.AsIs();
100 m_cancel
->SetConstraints(layout
);
102 // Constrain the Name text entry field
103 layout
= new wxLayoutConstraints
;
104 layout
->left
.SameAs (this, wxLeft
, 10);
105 layout
->right
.SameAs (this, wxRight
, 10);
106 layout
->bottom
.SameAs (m_OK
, wxTop
, 10);
107 layout
->height
.AsIs();
108 m_textField
->SetConstraints(layout
);
110 // Constrain the list of players
111 layout
= new wxLayoutConstraints
;
112 layout
->left
.SameAs (this, wxLeft
, 10);
113 layout
->right
.SameAs (this, wxRight
, 10);
114 layout
->top
.Below (msg
, 10);
115 layout
->bottom
.SameAs (m_textField
, wxTop
, 10);
116 list
->SetConstraints(layout
);
118 wxString prevPlayer
= m_scoreFile
->GetPreviousPlayer();
119 if ((prevPlayer
.Length() > 0) && (list
->FindString(prevPlayer
) != -1))
121 list
->SetStringSelection(prevPlayer
);
122 m_textField
->SetValue(prevPlayer
);
125 m_textField
->SetFocus();
132 PlayerSelectionDialog::~PlayerSelectionDialog()
136 void PlayerSelectionDialog::OnSize(wxSizeEvent
& WXUNUSED(event
))
141 const wxString
& PlayerSelectionDialog::GetPlayersName()
150 void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent
& event
)
153 EndModal(wxID_CANCEL
);
156 void PlayerSelectionDialog::SelectCallback(wxCommandEvent
& event
)
158 if (event
.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED
)
160 // 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(_T('@')))
174 wxMessageBox(_T("Names should not contain the '@' character"), _T("Forty Thieves"));
184 wxMessageBox(_T("Please enter your name"), _T("Forty Thieves"));
190 EndModal(wxID_CANCEL
);