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