]> git.saurik.com Git - wxWidgets.git/blob - demos/forty/playerdg.cpp
removed wxIsLoggingEnabled() as it could create the log target as an unwanted side...
[wxWidgets.git] / demos / forty / playerdg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: playerdg.cpp
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
5 // Modified by:
6 // Created: 21/07/97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WX_PRECOMP
20 #include "wx/wx.h"
21 #endif
22
23 #include "scorefil.h"
24 #include "playerdg.h"
25
26 const int ID_LISTBOX = 101;
27
28 BEGIN_EVENT_TABLE(PlayerSelectionDialog, wxDialog)
29 EVT_SIZE(PlayerSelectionDialog::OnSize)
30 EVT_BUTTON(wxID_OK, PlayerSelectionDialog::ButtonCallback)
31 EVT_BUTTON(wxID_CANCEL, PlayerSelectionDialog::ButtonCallback)
32 EVT_LISTBOX(ID_LISTBOX, PlayerSelectionDialog::SelectCallback)
33 EVT_CLOSE(PlayerSelectionDialog::OnCloseWindow)
34 END_EVENT_TABLE()
35
36 PlayerSelectionDialog::PlayerSelectionDialog(
37 wxWindow* parent,
38 ScoreFile* file
39 ) :
40 wxDialog(parent, wxID_ANY, _T("Player Selection"), wxDefaultPosition),
41 m_scoreFile(file)
42 {
43 wxStaticText* msg = new wxStaticText(this, wxID_ANY, _T("Please select a name or type a new one:"));
44
45 wxListBox* list = new wxListBox(
46 this, ID_LISTBOX,
47 wxDefaultPosition, wxDefaultSize,
48 0, 0,
49 wxLB_SINGLE
50 );
51
52 wxArrayString players;
53 m_scoreFile->GetPlayerList(players);
54 for (unsigned int i = 0; i < players.Count(); i++)
55 {
56 list->Append(players[i]);
57 }
58
59 m_textField = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize);
60
61 m_OK = new wxButton(this, wxID_OK);
62 m_cancel = new wxButton(this, wxID_CANCEL);
63
64 wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
65 button_sizer->Add( m_OK, 0, wxALL, 10 );
66 button_sizer->Add( m_cancel, 0, wxALL, 10 );
67
68 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
69 topsizer->Add( msg, 0, wxALL , 10 );
70 topsizer->Add( list, 1, wxEXPAND | wxLEFT | wxRIGHT, 10 );
71 topsizer->Add( m_textField, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10 );
72 topsizer->Add( button_sizer, 0, wxALIGN_LEFT );
73
74 SetSizer( topsizer );
75
76 topsizer->SetSizeHints( this );
77
78 CentreOnParent();
79 }
80
81 void PlayerSelectionDialog::OnSize(wxSizeEvent& WXUNUSED(event))
82 {
83 Layout();
84 }
85
86 const wxString& PlayerSelectionDialog::GetPlayersName()
87 {
88 /*
89 m_player = wxEmptyString;
90 Show(true);
91 */
92 return m_player;
93 }
94
95 void PlayerSelectionDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
96 {
97 m_player = wxEmptyString;
98 EndModal(wxID_CANCEL);
99 }
100
101 void PlayerSelectionDialog::SelectCallback(wxCommandEvent& event)
102 {
103 if (event.GetEventType() == wxEVT_COMMAND_LISTBOX_SELECTED)
104 {
105 // if (event.IsSelection())
106 m_textField->SetValue(event.GetString());
107 }
108 }
109
110 void PlayerSelectionDialog::ButtonCallback(wxCommandEvent& event)
111 {
112 if (event.GetId() == wxID_OK)
113 {
114 wxString name = m_textField->GetValue();
115 if (!name.IsNull() && name.Length() > 0)
116 {
117 if (name.Contains(_T('@')))
118 {
119 wxMessageBox(_T("Names should not contain the '@' character"), _T("Forty Thieves"));
120 }
121 else
122 {
123 m_player = name;
124 EndModal(wxID_OK);
125 }
126 }
127 else
128 {
129 wxMessageBox(_T("Please enter your name"), _T("Forty Thieves"));
130 }
131 }
132 else
133 {
134 m_player = wxEmptyString;
135 EndModal(wxID_CANCEL);
136 }
137 }