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, "Player Selection",
48 wxDefaultPosition
, wxSize(320, 200),
49 wxDIALOG_MODAL
| wxDEFAULT_DIALOG_STYLE
),
55 wxStaticText
* msg
= new wxStaticText(this, -1, "Please select a name from the list");
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, "", wxDefaultPosition
, wxDefaultSize
, 0);
73 m_OK
= new wxButton(this, wxID_OK
, "OK");
74 m_cancel
= new wxButton(this, wxID_CANCEL
, "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
);
130 PlayerSelectionDialog::~PlayerSelectionDialog()
134 void PlayerSelectionDialog::OnSize(wxSizeEvent
& WXUNUSED(event
))
139 const wxString
& PlayerSelectionDialog::GetPlayersName()
148 void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent
& event
)
151 EndModal(wxID_CANCEL
);
154 void PlayerSelectionDialog::SelectCallback(wxCommandEvent
& event
)
156 if (event
.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED
)
158 // if (event.IsSelection())
159 m_textField
->SetValue(event
.GetString());
163 void PlayerSelectionDialog::ButtonCallback(wxCommandEvent
& event
)
165 if (event
.GetId() == wxID_OK
)
167 wxString name
= m_textField
->GetValue();
168 if (!name
.IsNull() && name
.Length() > 0)
170 if (name
.Contains('@'))
172 wxMessageBox("Names should not contain the '@' character", "Forty Thieves");
182 wxMessageBox("Please enter your name", "Forty Thieves");
188 EndModal(wxID_CANCEL
);